1
votes

I am really having a hard time to understand how the fft-function in MATLAB works. According to:

http://www.mathworks.de/help/matlab/math/fast-fourier-transform-fft.html

fs/n is the distance between the sampled points in the Spectrum, where fs is the sampling frequency and n is the length of the signal. The code that they present, does extract the frequencies (although I do not know why), but according to the implementation of fft, that they present:

http://www.mathworks.de/help/matlab/ref/fft.html

the distance between the points in the spectrum should rather be: 1/fs. Because instead of the index j one inserts j*T, where T = 1/fs is the sampling time and then you can calculate the distance between the points, which should not be fs/n.

I would really be grateful if someone could explain me what the distance between the points in the frequency domain is and why this is so:)

[EDIT]
This is not a Matlab-specific problem. It is more a problem about the relationship between the Fourier-Transformation and the Discrete-Fourier-Transformation and the scaling/units of the frequency-axis. A pretty good explanation can be found in this PDF-Document at page 3.

[/EDIT]

1
Are you talking about where f = (0:n-1)*(fs/n) and t = (0:L-1)*T;? Do you realise that there are time and frequency - two different things? I am getting the feeling that you are getting confused with how the plots have been done using f, Fs, and T. - ha9u63ar
Yes, I am talking about f = (0:(n-1))*(fs/n); i.e the frequency range. The Time range is correct, but the frequency range does not make sense to me. If you have a look at the formula for the DFT, which MATLAB used for the implementation, you see in the exponent: - stackMill
(−2πi)/N*(j-1)*(k-1) where j is the index of the sum and the time index in x(j), and k is the index of the Spectrum. Since x was sampled at x(jT), one should use this for the frequency range (in Hertz, if T is in seconds): f = (0:n-1)*(1/fs); - stackMill

1 Answers

2
votes

The distance between the frequency points on the spectrum is fs/n in both cases, and that is the correct value. If we take the code in http://www.mathworks.co.uk/help/matlab/ref/fft.html, we have:

>> Fs = 1000;                    % Sampling frequency
>> T = 1/Fs;                     % Sample time
>> L = 1000;                     % Length of signal
>> t = (0:L-1)*T;                % Time vector
>> NFFT = 2^nextpow2(L); % Next power of 2 from length of y
>> f = Fs/2*linspace(0,1,NFFT/2+1);
>> f(2)-f(1)
ans =  0.97656
>> Fs/NFFT
ans =  0.97656

You can double-check all the other f(n+1)-f(n), they're all the same.