(5 votes, average: 4.00 out of 5)

# Interpreting the output of fft() operation in Matlab

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

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

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

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.

achuse December 1, 2012 at 10:20 pm

good one

Vinay November 12, 2012 at 9:26 am

Hello Krishna
If the subcarrier spacing is 15KHz, and I want to map data to two sets of subcarries. center frequencies of two sets of data are separated by bandwidth of choice, as a part of a large IFFT.(Example: two sets of data (N1 qpsk symbols,N2 qpsk symbols) should be mapped onto the subcarriers of an IFFT of size N. After taking IFFT and plotting the power spectrum, the data sets occupying bandwith (of B1 and B2MHz,) need to be separated by a bandwidth of B3MHz (say 900 subcarriers))

Thank you.

Krishna Sankar November 18, 2012 at 7:10 am

@Vinay: Hoping that the post on understanding an OFDM transmission will be of help.
http://www.dsplog.com/2008/02/03/understanding-an-ofdm-transmission/

jaspreet November 1, 2012 at 10:41 am

sir i want to reduce subcarriers 52 to 26 ……………………. what is the value of cyclic prefix plz reply

Krishna Sankar November 2, 2012 at 7:05 am

@jaspreet: The duration of the cyclic prefix is not dependent on the number of subcarriers. Rather it is dependent on the expected length of the channel impulse response (cyclic prefix should ideally be more than the channel duration).

urvik September 26, 2012 at 12:56 pm

Hello Sir,
I want to generate simple ofdm signal using matlab simulation. How can i do that.?Can you provide the code specification?

Krishna Sankar October 1, 2012 at 6:24 am
HariJo December 28, 2011 at 7:14 pm

Hi Krishna,

I am trying to generate a real unipolar ofdm signal using 16 qam, 52 subcarriers and fft-size 64 to begin with. The way to generate unipolar ofdm is to modulate only odd subcarriers and the way to have real output from IFFT is to make the input vector have Hermitian symmetry. However, i am confused with the indices that matlab uses to designate subcarriers and the actual subcarriers. I want to simulate the BER performance of real unipolar OFDM in awgn channel. Can you please help? thanks.

Krishna Sankar December 29, 2011 at 5:44 am

@HariJo: To get a real output from the ifft, make the input conjugate symmetric. For example, playing with the Matlab code provided in
http://www.dsplog.com/2008/06/10/ofdm-bpsk-bit-error/

clear all
nFFT = 64; % fft size
nDSC = 52; % number of data subcarriers
nBitPerSym = 52; % number of bits per OFDM symbol (same as the number of subcarriers for BPSK)
nSym = 1; % number of symbols
% Transmitter
ipBit = rand(1,nBitPerSym*nSym) > 0.5; % random 1′s and 0′s
ipMod = 2*ipBit-1; % BPSK modulation 0 –> -1, 1 –> +1
ipMod = reshape(ipMod,nBitPerSym,nSym).’; % grouping into multiple symbolsa
xF_symm = [zeros(nSym,6) ipMod(:,[1:nBitPerSym/2]) zeros(nSym,1) ipMod(:,[nBitPerSym/2:-1:1]) zeros(nSym,5)] ;
xt_symm = (nFFT/sqrt(nDSC))*ifft(fftshift(xF_symm.’)).’;

saru December 22, 2011 at 9:41 am

hi,
i wanna know why fft/ifft is important in ofdm .does it play any signifinace role in ofdm

Krishna Sankar January 3, 2012 at 4:43 am

@saru: Hmm… in OFDM, we wish to send a group of complex sinewaves with each sine having different weights, and the frequency of the sine waves are integer multiplies of each other. Does it sound similar to what fft/ifft does?

samba April 23, 2011 at 6:49 am

Hi sir

can you explain how we do the channel estimation in ofdm 802.11
like in order to find the timing sync using cross correlation and auto correlation

In some papers they used something like
cross correlation of received signal with short preamble and divided it by auto correlation of short preamble , can you explain what exactly happens with this ?

Krishna Sankar May 26, 2011 at 5:48 am

@samba: In 802.11, the specification allows for a long training field (LTF) which is known a priori at the receiver.
The model is Y = HX + N,
where X is known at the receiver
N is the noise,
H is the channel

The noisy estimate of channel is H’ = Y/X

teddy April 7, 2011 at 3:54 pm

Hi krishna,

Are FFT size and sub-carrier number the same in OFDM? I was reading a paper and I was confused when I read 1201 occupied sub-carriers for 2048 FFT size. what does that mean?

Krishna Sankar May 24, 2011 at 5:42 am

@teddy: FFT size and subcarrier number need not be the same. The text you mentioned means that out of 2048 available subcarriers, only 1201 are used.

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.

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,

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.

Ashok July 24, 2009 at 10:56 am

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

Krishna Sankar July 28, 2009 at 4:16 am

@Ashok: Thanks, I corrected it

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.

Krishna Sankar 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?

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;

Krishna Sankar 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.
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 7, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.808366060256958, "perplexity": 2367.978210973157}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2018-43/segments/1539583512434.71/warc/CC-MAIN-20181019191802-20181019213302-00494.warc.gz"}