How many periods it is needed for fft to give us a proper estimate over frequency?

72 views (last 30 days)
Dear all,
I have a basic question. Imagine a simple sinusoidal defined as below:
Fs = 150;
t = 0:1/Fs:0.2;
f = 5;
x = sin(2*pi*t*f);
nfft = 1024;
X = fft(x,nfft);
X = X(1:nfft/2);
MX = abs(X);
f = (0:nfft/2-1)*Fs/nfft;
plot(f,MX)
The period of signal(lambda) is 0.2 (f=5). Now, if I change this expression(t = 0:1/Fs:0.2;) any time before plotting, from a half sine (t = 0:1/Fs:0.1;) to 5 repeated periods (t = 0:1/Fs:1;), only after when two full periods are at least used for calculating fft, fft gives us a good estimate(something around 5) of the signal frequency. Why?

Answers (2)

Wayne King
Wayne King on 5 Nov 2013
It's not that simple. You can get a good estimate with just one period depending on the frequency spacing in the DFT.
Fs = 500;
t = 0:1/Fs:0.2-1/Fs;
x = cos(2*pi*5*t);
xdft = fft(x);
xdft = xdft(1:length(x)/2+1);
df = Fs/length(x);
freqvec = 0:df:250;
stem(freqvec,abs(xdft),'markerfacecolor',[0 0 1])

Mona Mahboob Kanafi
Mona Mahboob Kanafi on 6 Nov 2013
Edited: Mona Mahboob Kanafi on 6 Nov 2013
Dear Wayne,
Thanks a lot for your answer. I played with Fs a little bit and even for Fs = 10(twice the highest frequency), it gives a perfect estimation. In fact, I generate this sine wave to find out something about the largest wavelength fft can detect in a signal. My main question is:
I have an image of size X*Y. I apply fft2 and now I need to assign frequencies, i.e. fx and fy to the 2D FFT which are something like this:
fx = df*(-N/2:N/2-1)/N;
fy = df*(-M/2:M/2-1)/M;
This assignment is for the sake of fft. In reality, there must be a limit for the minimum available frequency in the image which corresponds to the maximum available wavelength in the image. And what is the maximum available wavelength in each direction? Is it the size of the image? Is it twice the size of an image or even half of the size of an image?
For instance, in our simple case of sine wave, for a half size wave(t = 0:1/Fs:0.1-1/Fs;), is it so that fft can not detect the lying full sine wave (f = 5) and the maximum wavelength detectable is for f = 10?

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!