MATLAB Answers

DFT using matlab function

4 views (last 30 days)
In case a off-nominal signal is processed using nominal frequency based fft algorithm, the peak value of the magnitude of fft is still at the frequency index or bin pertaining to the nominal value (though the amplitude is different and the side lobes also have an amplitude which is not seen when the signal has a nominal value of frequency). Why does the frequency index not change even though the frequency is no longer the nominal value. How can i visualize this in matlab using the fft function.


Sign in to comment.

Accepted Answer

David Goodmanson
David Goodmanson on 21 Feb 2020
Hi mk,
"Why does the frequency index not change even though the frequency is no longer the nominal value "
When you do an fft, the frequency array is predetermined by the properties of the time array. For an N-point fft and array spacings of delt and delf, the golden rule for ffts is
delt*delf = 1/N.
regardless of the properties of the signal. In the following code, delf = 1 so the frequency array represents exact integral frequencies. The example uses a cosine wave with f0 = 10. The total time record is 1 sec and you can see exactly 10 cycles in the time plot. In the frequency plot, fftshift is used to put f = 0 at the center of the plot. There are two peaks exactly at +-10Hz with amplitude 1/2, illustrating that
cos(2*pi*f0*t) = ( exp(i*2*pi*f0*t) + exp(-i*2*pi*f0*t) )/2.
and no frequency content anywhere else.
Now change f0 to 10.2 Hz and run it again. The frequency grid is incapable of exactly representing 10.2 Hz so it gives a reduced peak at 10 Hz, with frequency content spilling over into other frequencies.
N = 1e4;
delt = 1e-4 % total time record = 1 sec
delf = 1/(N*delt); % delf = 1;
% or you could do what is commonly done
% Fs = 1e4; sampling rate
% delt = 1/Fs;
% delf = Fs/N;
t = (0:N-1)*delt;
f = (-N/2:N/2-1)*delf; % freq grid for fftshift
f0 = 10;
y = cos(2*pi*t*f0);
plot(t,y); grid on
z = fftshift(fft(y)/N); % ordinarily z is complex, real in this case
plot(f,z,'o-'); grid on

  1 Comment

mir  khadim
mir khadim on 22 Feb 2020
i agree with what you are saying, since it depends on the frequency grid that i create to visualize my spectrum, i see the maximum value occuring always at the fundamental bin. But i have another confusion here, given as follows:
I was going through some research papers describing Ip-DFT (interpolated DFT) algorithm, and they mentioned the following sentence "peak value of the continious spectrum of the fundamental tone of a signal is located between two consecutive DFT bins and the signal frequency can be expressed as follows " given as , where is the frequency of the main or fundamental tone of the signal, is the frequency resolution (what you have called as delf) and δ is the difference between the peak value of the continious spectrum and the peak value of the DFT magnitude (the value of δ is zero when the frequency of the main tone is an integral multiple of the sampling frequency). Is there a way i can visualize this so called δ using the fft function.

Sign in to comment.

More Answers (0)

Sign in to answer this question.