Return value of fft function and details of the bins

24 views (last 30 days)
HI, I am a new to matlab and fft() .
Could you please help me in understudying the return value(data structure) of fft function in terms of the frequency bins. I was not able to find a proper explanation of bins .
regards Mahesh

Answers (2)

Wesley Ooms
Wesley Ooms on 14 Jan 2014
Edited: Wesley Ooms on 3 Feb 2014
The bins are slightly different between even and odd number of sample points. I use the following:
f = ceil(-N/2:N/2-1)/dt/N ; % frequency points
where N is the number of sample points and dt sample time. You can check this with for example a multisinus with its frequency an integer number uf the base frequency and without a window:
N = 11112 ; % number of samples
dt = 1e-4 ; % sample time
t = dt*(0:N-1) ; % time points
f = [-N/2:-1 ~odd(N):N/2]/dt/N; % frequency points
freqs = f(f>100&f<1000) ; % frequencys in the signal
its = 1:length(freqs) ; % iterations
phase = its.^2*pi/1e3 ; % phase of frequencys in the signal (schroeder phase)
a = 0 ; % DC offset
for i=its
a=a+cos(2*pi*freqs(i)*t+phase(i));
end
b=fftshift(fft(a));
subplot(311),plot(t,a ,'-')
subplot(312),plot(f,abs (b),'.')
subplot(313),plot(f,angle(b),'.')

Matt J
Matt J on 14 Jan 2014
Edited: Matt J on 14 Jan 2014
If you are sampling time at intervals T seconds, the frequency samples will be (k-1)/(N*T) Hz, where k=1,...,N and X(k) is the output of your fft.
  2 Comments
Mahesh
Mahesh on 14 Jan 2014
Thanks Matt. I have some more doubts . If I am taking samples with 512 samples per second . and do fft for a one second signal . fft will return me 512 bins.Could you please let me know whether my understanding is correct .
returned bins will contain 1/2 the details of frequency components with maximum 1/2 the sampling frequency . first 256 bins will contain real part of the frequency component . Next 256 will contain the imaginary part ? My confusion is how this will be ordered in the bin
Matt J
Matt J on 14 Jan 2014
Edited: Matt J on 14 Jan 2014
Yes, the fft will return 512 bins spaced apart by 1 Hz. The first half of the samples will correspond to positive frequencies in the continuous Fourier domain and the second half of the samples will be negative frequencies.
If you apply fftshift() to the output of fft then the samples will be re-ordered so that negative frequencies are on the left. The corresponding continuous space frequency sample axis will then be,
frequencyAxis= ((0:N-1) -ceil((N-1)/2))*Fs/N;
i.e., with DC at frequencyAxis(257).

Sign in to comment.

Categories

Find more on Fourier Analysis and Filtering in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!