Let's suppose that I want to generate sine and cosine look up tables for some reason. I have sampling frequency fs=855 kHz. Sine and cosine frequency is f=200 kHz. Based on that fs divided by f is equal to fs/f=4.275. It's not an integer value. In this particular case whatever number of samples I put into look up table I face phase discontinuity when I have to reset samples counter that is entry to my lookup table.
How can I solve this issue?
Let me explain what I want to do. My goal is simple SDR (software defined radio) based on STM32F407 microcontroller and R820T TV tuner.
The R820T provides IF signal that has central frequency roughly $f_{c} = 4.5 \textrm{ MHz}$. The STM32F407 has CPU clock frequency equal to $168 \textrm{ MHz}$ and it supports floating point computing. Bandwidth from the R820T is too large (roughly $6 \textrm{ MHz}$) for handle with ADC of STM32F407. I designed analog IF amplifier that has narrow bandwidth equal to $B = 400 \textrm{ kHz}$ with $-60 \textrm{ dB}$ gain drop. It looks reasonable for STM32F407 because I can sample it with lower sampling frequency. I mean that my IF signal can be bandpass sampling.
I calculated minimal sampling frequency $f_{s} = 855 \textrm{ kHz}$. It's without aliasing or very small aliasing ($-60 \textrm{ dB}$ overlapping). After sampling I have new $f_{c}$ equal to around $200 \textrm{ kHz}$. Next obvious step is multiplication each sample by sine and cosine (that's why I need $200 \textrm{ kHz}$ sine and cosine look-up tables).
The last operation is low pass filtering with IIR filters (non linear phase but for small bandwidth is not such bad) and I have I and Q signals. Sampling frequency $f_{s} = 855 \textrm{ kHz}$ is still really large so I decimate it by factor $8$ and the final $f_{s} = \frac{855 \textrm{ kHz}}{8} = 106.9 \textrm{ kHz}$. With I and Q signals I can do some math to create both AM and FM demodulation. To be honest my receiver hardly works so I have to put lots of effort to improve it and proper look-up tables is one issue.
I wrote simple code in Matlab for testing look-up tables:
clear; fs = 855e3; ts = 1/fs; f = 200e3; p = 2*pi()/171; sin_arr = sin(p * (0:170)); cos_arr = cos(p * (0:170)); k = 0; step = 40; N = 30; y_sin = zeros(1, N); y_cos = zeros(1, N); for i=1:N y_sin(i) = sin_arr(k+1); y_cos(i) = cos_arr(k+1); k = mod(k+step, 171); end x = 0:N-1; plot(x, y_sin, '-o', x, y_cos, '-o'); x_ = 0:10*N-1; y_sin_ = sin(2*pi()*f*x_*ts/10); y_cos_ = cos(2*pi()*f*x_*ts/10); plot(x_, y_sin_, '--', x_, y_cos_, '--', 10*x, y_sin, 'o', 10*x, y_cos, 'o'); It would be really efficient algorithm in C.
Dotted lines are sine and cosine with sampling frequency $10 f_{s}$ (just for clarification) and dots comes from look-up tables.