Reputation: 1633
So if my sampling rate is 8000, and I make a sine wave of frequency 1000 like so:
n = 0:255;
fs = 8000;
fa = 50;
x = sin(2*pi*(fa/fs)*n);
resolution = n * (fs/length(n));
stem(resolution, abs(fft(x)));
Everything is fine, and the plot shows the single peak at 1000Hz.
However, if I set a frequency fa = 50
, I get a smoother rise up to the peak, however the peak location is incorrect. It's at 62.5 Hz.
So the obvious solution is reduce the sampling rate, but what if that's not possible, such as in my case?
Upvotes: 0
Views: 1124
Reputation: 1603
I think that the above observation/result makes sense given the choice of your sampling rate fs and block size N of 8000 and 256 respectively. Note that
fs/N = 8000/256 = 31.25
The discrete outputs from the FFT N-point transform can only be associated with frequencies that are multiples of the above
m*fs/N = m*31.25 for m=0,1,2,….,255
There does not exist any m such that m*fs/N is equal to 50, so the closest is the 62.5 (2*31.25).
If you cannot change the sampling rate, then how about the block size, N such that 50=fs/N? If N were chosen to be any multiple of 160 (=8000/50) then you should be fine
n = 0:159; % or any multiple of 160 less one
(You mention the smoother rise up to the peak which is just leakage - it causes any input signal whose frequency is not exactly at a FFT bin centre to leak into all of the other FFT output bins.)
Note that everything is fine for the input signal with a 1000 Hz frequency since 1000=32*31.25 when fs=8000 and N=256 (so m=32).
Upvotes: 4
Reputation: 2431
The maximum value of your discrete Fourier transform is at 62.5Hz. However, if you interpolate, you'll find that the maximum value is at 50 Hz. See http://www.dspguru.com/dsp/howtos/how-to-interpolate-fft-peak for details.
Upvotes: 2