1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 5 out of 5)
Loading ... Loading ...
Print Print

Interpreting the output of fft() operation in Matlab

by Krishna Sankar on June 17, 2007

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');

fft_complex_cosine

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
figure;
plot([-512:511]*30/1024,fftshift(abs(hF))) ;
xlabel('frequency, MHz')
ylabel('amplitude')
title('frequency response of sinc filter');

fft_sinc

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

Related posts

  1. Polyphase filters for interpolation
  2. Zero-order hold and first-order hold based interpolation
  3. Transmit pulse shaping filter – rectangular and sinc (Nyquist)
  4. Example of Cascaded Integrator Comb filter in Matlab
  5. Raised cosine filter for transmit pulse shaping

D id you like this article? Make sure that you do not miss a new article by subscribing to RSS feed OR subscribing to e-mail newsletter. Note: Subscribing via e-mail entitles you to download the free e-Book on BER of BPSK/QPSK/16QAM/16PSK in AWGN.

{ 11 comments… read them below or add one }

1 harikrishni July 30, 2008 at 2:34 pm

I want to do program of radix4 ( loop) pls help me

Reply

2 Krishna Pillai August 1, 2008 at 12:33 pm

@harikrishni: May I point you to the article by Richard Lyons on Computing Large DFTs Using Small FFTs will be helpful.
URI: http://www.dsprelated.com/showarticle/63.php

Reply

3 Leyo Joseph April 13, 2009 at 8:08 pm

Hi
In the FFT example of SINC function, could you please explain how the 30MHz sampling is implemented in the following line?
hT = sinc([-20:20]/3); % consider sample at 30MHz sampling;

Reply

4 Krishna Pillai April 16, 2009 at 5:49 am

@Leyo: The concept of time between the samples in Matlab is notional. It can be anyvalue. I just chose to use 30MHz so as to show the spectral plots from -15MHz to +15MHz [-fs/2 to fs/2).
I had chosen as 300MHz, the spectral plot will have changed to -150MHz to +150MHz.

Hope this helps.

Reply

5 anisha July 6, 2009 at 7:04 pm

Hi
I need a small help in plotting frequency spectrum of signal. I have plotted the frequency spectrum of signal using fft in matlab but the plot shows 2 spectrum. Could you please explain why.

Reply

6 Krishna Pillai July 6, 2009 at 7:31 pm

@anisha: If its a real signal, then we have spectrum at +ve and -ve components. For eg, if we try to plot the spectrum of cos(wt), we will see spectrum at -w and +w. Does that answer your query?

Reply

7 Ashok July 24, 2009 at 10:56 am

A small typo in line 6 :)
instead of xt I think it is x1T
Thanks

Reply

8 Krishna Pillai July 28, 2009 at 4:16 am

@Ashok: Thanks, I corrected it :)

Reply

9 jahanzaib October 23, 2009 at 3:46 pm

hi Krishna
i need to ask some basic questions
when we talk about ifft period,i.e 128,256…..are that subcarriers we are talking about?
how we define subcarriers spacings in matlab?
I could not really understand how to visualize an OFDM symbol in both time and frequency domain together,

Reply

10 Krishna Sankar October 27, 2009 at 5:35 am

@jahanzaib: My replies:
There are two aspects to consider –
fs – the sampling frequency of the ifft or fft
N – number of points
If we have an N point ifft running at sampling frequency of fs, then the subcarrier spacing is fs/N.
Typically in OFDM specifications, we the ifft size is equal to the maximum number of subcarriers which may be used. However, we do not use all the avaliable subcarriers.

Reply

11 Assad Akhlaq December 31, 2009 at 12:49 am

Hi Krishna
i hope tht you are fine and doing good. i want to ask that why the output of fft i.e x1F is only at the 10th subcarrier?.

Thanking you in anticipation.

Reply

Leave a Comment

Previous post:

Next post: