- 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
figure;
plot([-N/2:N/2-1]*fsMHz/N,fftshift(abs(x1F))) ; % sub-carriers from [-128:127]
xlabel('frequency, MHz')
ylabel('amplitude')
title('frequency response of complex sinusoidal signal');

[1]

With an$N$point fft() and sampling frequency of $f_s$, the observable spectrum from $\left[-\frac{f_s}{2},\ \ +\frac{f_s}{2}\right) \leftrightarrow [-64,\ 63]$ is split to $\frac{f_s}{N}$ sub-carriers.

Additionally, the signal at the output of fft() is from $\left[0,\ \ +f_s\right) \leftrightarrow [0,\ 127]$. As the frequencies from $\left[+\frac{f_s}{2},\ \ +f_s\right) \leftrightarrow [64,\ 127]$ get aliased to $\left[-\frac{f_s}{2},\ \ 0\right) \leftrightarrow [-64,\ -1]$, 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
figure;
plot([-512:511]*30/1024,fftshift(abs(hF))) ;
xlabel('frequency, MHz')
ylabel('amplitude')
title('frequency response of sinc filter');

[2]

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

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/