- DSP log - http://www.dsplog.com -

Interpreting the output of fft() operation in Matlab

Posted By Krishna Sankar On June 17, 2007 @ 11:32 am In DSP | 26 Comments

It might be interesting to interpret the output of the fft() function in Matlab. Consider the following simple examples.

fsMHz = 20; % sampling frequency
fcMHz = 1.5625; % signal frequency
N = 128; % fft size
% generating the time domain signal
x1T = exp(j*2*pi*fcMHz*[0:N-1]/fsMHz);
x1F = fft(x1T,N); % 128 pt FFT
plot([-N/2:N/2-1]*fsMHz/N,fftshift(abs(x1F))) ; % sub-carriers from [-128:127]
xlabel('frequency, MHz')
title('frequency response of complex sinusoidal signal');

fft_complex_cosine [1]

With anpoint fft() and sampling frequency of , the observable spectrum from is split to sub-carriers.

Additionally, the signal at the output of fft() is from . As the frequencies from get aliased to , the operator fftshift() is used when plotting the spectrum.

In the example above, with a sampling frequency of 20MHz, the spectrum from [-10MHz, +10MHz) is divided into 128 sub-carriers with spaced apart by 20MHz/128 = 156.25kHz. The generated signal x1T of frequency 1.5625MHz corresponds to the information on the 10th sub-carrier, which can also be generated in the frequency domain.

% generating the frequency domain signal with subcarrier indices [-N/2:-1 dc 1:N/2-1]
x2F = [zeros(1,N/2) 0 zeros(1,9) 1 zeros(1,N/2-10-1)]; % valid frequency on 10th subcarrier, rest all zeros
x2T = N*ifft(fftshift(x2F)); % time domain signal using ifft()
% comparing the signals
diff = x2T – x1T;
err = diff*diff’/length(diff)

Plotting the frequency response of a filter

Consider a filter with the a sinc() shaped impulse response. The Matlab code for plotting the frequency response is as follows:

% impulse response of a sinc() filter
hT = sinc([-20:20]/3); % consider sample at 30MHz sampling;
hF = fft(hT,1024); % 128 pt FFT
plot([-512:511]*30/1024,fftshift(abs(hF))) ;
xlabel('frequency, MHz')
title('frequency response of sinc filter');

fft_sinc [2]

Hopefully, the post provides some insights on the query raised in the comp.dsp thread [3].

Article printed from DSP log: http://www.dsplog.com

URL to article: http://www.dsplog.com/2007/06/17/interpreting-the-output-of-fft-operation-in-matlab/

URLs in this post:

[1] Image: http://www.flickr.com/photos/8649381@N03/560585801/

[2] Image: http://www.flickr.com/photos/8649381@N03/565359839/

[3] comp.dsp thread: http://groups.google.com/group/comp.dsp/browse_thread/thread/9314be1f0ca8ed62/24ffc77dabef23ef?lnk=gst&q=interpreting+fft()&rnum=1#24ffc77dabef23ef

[4] click here to SUBSCRIBE : http://www.feedburner.com/fb/a/emailverifySubmit?feedId=1348583&loc=en_US

Copyright © 2007-2012 dspLog.com. All rights reserved. This article may not be reused in any fashion without written permission from http://www.dspLog.com.