FFT Matlab
FFT Matlab
FFT Matlab
Introduction
Numerous texts are available to explain the basics of Discrete Fourier
Transform and its very efficient implementation Fast Fourier
Transform (FFT). Often we are confronted with the need to generate
simple, standard signals (sine, cosine, Gaussian pulse, squarewave,
isolated rectangular pulse, exponential decay, chirp signal) for
simulation purpose. I intend to show (in a series of articles) how these
basic signals can be generated in Matlab and how torepresent them in
frequency domain using FFT.
http://www.gaussianwaves.com/2014/07/how-to-plot-fft-using-matlab-fft-of-basic-signals-sine-and-cosine-waves/ 1/21
9/3/2017 How to plot FFT using Matlab FFT of basic signals : Sine and Cosine waves GaussianWaves
Sine Wave
In order to generate a sine wave in Matlab, the first step is to fix the
frequency f of the sine wave. For example, I intend to generate a
f = 10H z sine wave whose minimum and maximum amplitudes are
it too.
http://www.gaussianwaves.com/2014/07/how-to-plot-fft-using-matlab-fft-of-basic-signals-sine-and-cosine-waves/ 2/21
9/3/2017 How to plot FFT using Matlab FFT of basic signals : Sine and Cosine waves GaussianWaves
Representing in Frequency
Domain
Representing the given signal in frequency domain is done via Fast
Fourier Transform (FFT) which implements Discrete Fourier Transform
(DFT) in an efficient manner. Usually, power spectrum is desired for
analysis in frequency domain. In a power spectrum, power of each
frequency component of the given signal is plotted against their
respective frequency. The command FFT(x,N) computes the N -point
DFT. The number of points N in the DFT computation is taken as
power of 2 for facilitating efficient computation with FFT.A value of
N = 1024 is chosen here. It can also be chosen as next power of 2 of the
length of the signal.
Different representations of
FFT:
Since FFT is just a numeric computation of N -point DFT, there are many
ways to plot the result.
http://www.gaussianwaves.com/2014/07/how-to-plot-fft-using-matlab-fft-of-basic-signals-sine-and-cosine-waves/ 3/21
9/3/2017 How to plot FFT using Matlab FFT of basic signals : Sine and Cosine waves GaussianWaves
http://www.gaussianwaves.com/2014/07/how-to-plot-fft-using-matlab-fft-of-basic-signals-sine-and-cosine-waves/ 4/21
9/3/2017 How to plot FFT using Matlab FFT of basic signals : Sine and Cosine waves GaussianWaves
As you know, in the frequency domain, the values take up both positive
and negative frequency axis. In order to plot the DFT values on a
frequency axis with both positive and negative values, the DFT value at
sample index 0 has to be centered at the middle of the array. This is done
by using F F T shif t function in Matlab. The x-axis runs from 0.5 to
0.5 where the end points are the normalized folding frequencies with
respect to the sampling rate fs .
http://www.gaussianwaves.com/2014/07/how-to-plot-fft-using-matlab-fft-of-basic-signals-sine-and-cosine-waves/ 5/21
9/3/2017 How to plot FFT using Matlab FFT of basic signals : Sine and Cosine waves GaussianWaves
1 NFFT=1024;
2 X=fftshift(fft(x,NFFT));
3 fVals=fs*(-NFFT/2:NFFT/2-1)/NFFT;
4 plot(fVals,abs(X),'b');
5 title('Double Sided FFT - with FFTShift');
6 xlabel('Frequency (Hz)')
7 ylabel('|DFT Values|');
http://www.gaussianwaves.com/2014/07/how-to-plot-fft-using-matlab-fft-of-basic-signals-sine-and-cosine-waves/ 6/21
9/3/2017 How to plot FFT using Matlab FFT of basic signals : Sine and Cosine waves GaussianWaves
1 NFFT=1024;
2 L=length(x);
3 X=fftshift(fft(x,NFFT));
4 Px=X.*conj(X)/(NFFT*L); %Power of each freq components
5 fVals=fs*(-NFFT/2:NFFT/2-1)/NFFT;
6 plot(fVals,Px,'b');
7 title('Power Spectral Density');
8 xlabel('Frequency (Hz)')
9 ylabel('Power');
http://www.gaussianwaves.com/2014/07/how-to-plot-fft-using-matlab-fft-of-basic-signals-sine-and-cosine-waves/ 7/21
9/3/2017 How to plot FFT using Matlab FFT of basic signals : Sine and Cosine waves GaussianWaves
If you wish to verify the total power of the signal from time domain and
frequency domain plots, follow this link.
Plotting the PSD plot with y-axis on log scale produces the most
encountered type of PSD plot in signal processing.
1 NFFT=1024;
2 L=length(x);
3 X=fftshift(fft(x,NFFT));
4 Px=X.*conj(X)/(NFFT*L); %Power of each freq components
5 fVals=fs*(-NFFT/2:NFFT/2-1)/NFFT;
6 plot(fVals,10*log10(Px),'b');
7 title('Power Spectral Density');
8 xlabel('Frequency (Hz)')
9 ylabel('Power');
http://www.gaussianwaves.com/2014/07/how-to-plot-fft-using-matlab-fft-of-basic-signals-sine-and-cosine-waves/ 8/21
9/3/2017 How to plot FFT using Matlab FFT of basic signals : Sine and Cosine waves GaussianWaves
In this type of plot, the negative frequency part of x-axis is omitted. Only
the FFT values corresponding to 0 to N /2) sample points of N -point
DFT are plotted. Correspondingly, the normalized frequency axis runs
between 0 to 0.5. The absolute frequency (x-axis) runs from 0 to fs /2.
1 L=length(x);
2 NFFT=1024;
3 X=fft(x,NFFT);
4 Px=X.*conj(X)/(NFFT*L); %Power of each freq components
5 fVals=fs*(0:NFFT/2-1)/NFFT;
6 plot(fVals,Px(1:NFFT/2),'b','LineSmoothing','on','LineWidth',1);
7 title('One Sided Power Spectral Density');
8 xlabel('Frequency (Hz)')
9 ylabel('PSD');
http://www.gaussianwaves.com/2014/07/how-to-plot-fft-using-matlab-fft-of-basic-signals-sine-and-cosine-waves/ 9/21
9/3/2017 How to plot FFT using Matlab FFT of basic signals : Sine and Cosine waves GaussianWaves
Recommended Signal
Processing Books
http://www.gaussianwaves.com/2014/07/how-to-plot-fft-using-matlab-fft-of-basic-signals-sine-and-cosine-waves/ 10/21
9/3/2017 How to plot FFT using Matlab FFT of basic signals : Sine and Cosine waves GaussianWaves
Share this:
More
Previous Post
Generating Multiple Sequences of correlated random variables
Next Post
http://www.gaussianwaves.com/2014/07/how-to-plot-fft-using-matlab-fft-of-basic-signals-sine-and-cosine-waves/ 11/21
9/3/2017 How to plot FFT using Matlab FFT of basic signals : Sine and Cosine waves GaussianWaves
Mathuranathan
<a
href="https://plus.google.com/11629100648437716455
3?rel=author" rel="author">Mathuranathan
Viswanathan</a> - Founder and Author @
gaussianwaves.com which has garnered worldwide
readership. He is a masters in communication
engineering and has 9 years of technical expertise in
channel modeling and has worked in various
technologies ranging from read channel design for
hard drives, GSM/EDGE/GPRS, OFDM, MIMO, 3GPP
PHY layer and DSL. He also specializes in tutoring on
various subjects like signal processing, random
process, digital communication etc.., <a
href="https://sg.linkedin.com/pub/mathuranathan-
viswanathan/5/723/b2a"> LinkedIn Profile</a>
L AT E ST A RT I C L E S M AT L A B C O D E S S I G N A L P RO C E S S I N G T I P S &
TRICKS
F F T F O U R I E R A N A LYS I S F O U R I E R T R A N S F O R M M AT L A B C O D E
P OW E R S P E C T R A L D E N S I T Y PSD TIPS & TRICKS
9 Comments Gaussianwaves
1 Login
Sort by Best
Recommend Share
LOG IN WITH
OR SIGN UP WITH DISQUS ?
Name
http://www.gaussianwaves.com/2014/07/how-to-plot-fft-using-matlab-fft-of-basic-signals-sine-and-cosine-waves/ 12/21
9/3/2017 How to plot FFT using Matlab FFT of basic signals : Sine and Cosine waves GaussianWaves
Hi all; this article for a sine wave signal. what can i do if the signal is still sine wave
with five cycles where each cycle amplitude is less than the previous cycle until the
wave is decay at a specific time, and if the x value is represented by a vector which
contain the data ( I mean x is not represented by equation). My question how i can
implemented fft for my signal.
Thanks in advance
Reply Share
Just assign the signal contents to the variable x and the call the FFT routine
as mentioned in the post
X=fft(x,NFFT); %x is your signal,
you can use any of the different representations to plot the FFT output.
Reply Share
I need to do fft to obtain the frequency content of my signal and calculate the
energy to obtain the transmission coefficient, but I have a lot of problems since I
don't know exatly what is the correct way to obtain everything with a correct scale
and units.
for the frequencies, I expect to get a fundamental at around 8 KHz and the
harmonics (2nd and third).
Reply Share
In the above example when I gave the number of cycles as 10, then it is giving a
spectrum which has a higher amplitude. This seems so strange to me because the
http://www.gaussianwaves.com/2014/07/how-to-plot-fft-using-matlab-fft-of-basic-signals-sine-and-cosine-waves/ 13/21
9/3/2017 How to plot FFT using Matlab FFT of basic signals : Sine and Cosine waves GaussianWaves
spectrum which has a higher amplitude. This seems so strange to me because the
number of cycles is just a visualisation parameter and that should not chance the
appearance of the spectrum.
Rgds
Reply Share
ALSO ON GAUSSIANWAVES
Log in with:
NEW RELEASE
http://www.gaussianwaves.com/2014/07/how-to-plot-fft-using-matlab-fft-of-basic-signals-sine-and-cosine-waves/ 15/21
9/3/2017 How to plot FFT using Matlab FFT of basic signals : Sine and Cosine waves GaussianWaves
SEARCH QUESTIONS
SEARCH ARTICLES
Search... Go
Enter your email address to subscribe to this blog and receive notifications of new posts
by email.
Email Address
Subscribe
http://www.gaussianwaves.com/2014/07/how-to-plot-fft-using-matlab-fft-of-basic-signals-sine-and-cosine-waves/ 16/21
9/3/2017 How to plot FFT using Matlab FFT of basic signals : Sine and Cosine waves GaussianWaves
RECENTLY SUBMITTED
CATEGORIES
8-PSK
Book reviews
BPSK
Channel Coding
Channel Modelling
http://www.gaussianwaves.com/2014/07/how-to-plot-fft-using-matlab-fft-of-basic-signals-sine-and-cosine-waves/ 17/21
9/3/2017 How to plot FFT using Matlab FFT of basic signals : Sine and Cosine waves GaussianWaves
Constellations
Correlative Coding
Digital Modulations
DPSK
Estimation Theory
Free Books
GMSK
Hamming Codes
Interleaver
Introduction
Latest Articles
Line Coding
M-PSK
M-QAM
Matlab Codes
MIMO systems
OFDM
Probability
Pulse Shaping
Python
http://www.gaussianwaves.com/2014/07/how-to-plot-fft-using-matlab-fft-of-basic-signals-sine-and-cosine-waves/ 18/21
9/3/2017 How to plot FFT using Matlab FFT of basic signals : Sine and Cosine waves GaussianWaves
QPSK
Quiz
Random Process
Shannon Theorem
Signal Processing
Source Coding
Spread Spectrum
Tutorials
VLSI
FOLLOW
http://www.gaussianwaves.com/2014/07/how-to-plot-fft-using-matlab-fft-of-basic-signals-sine-and-cosine-waves/ 19/21
9/3/2017 How to plot FFT using Matlab FFT of basic signals : Sine and Cosine waves GaussianWaves
Digital Communicatio
6,514 likes
GaussianWaves
Follow
TAGS
Matrix Fourier Analysis Fourier transform gray code M-QAM Matlab Code
Matlab Codes matrix algebra Maximum Likelihood Estimation Minimum Variance Unbiased
Estimator MLE Multi-carrier Modulation OFDM Orthogonal Frequency Division Multiplexing
oversampling positive definite Power spectral Density PSD Pulse Shaping Random
Process Random Variables Rayleigh Sampling Theorem Score Shannon Capacity Signal
Processing Spread Spectrum Tips & Tricks
GaussianWaves
Gaussianwaves.com - Signal Processing Simplified
http://www.gaussianwaves.com/2014/07/how-to-plot-fft-using-matlab-fft-of-basic-signals-sine-and-cosine-waves/ 20/21
9/3/2017 How to plot FFT using Matlab FFT of basic signals : Sine and Cosine waves GaussianWaves
http://www.gaussianwaves.com/2014/07/how-to-plot-fft-using-matlab-fft-of-basic-signals-sine-and-cosine-waves/ 21/21