banner



How To Comput And Draw The Fourir Transformation In Matlab

Fundamental focus : Learn how to plot FFT of sine wave and cosine wave using Matlab. Understand FFTshift. Plot 1-sided, double-sided and normalized spectrum.

Introduction

Numerous texts are available to explain the basics of Discrete Fourier Transform and its very efficient implementation – Fast Fourier Transform (FFT).  Oft we are confronted with the need to generate simple, standard signals (sine, cosine, Gaussian pulse, squarewave, isolated rectangular pulse, exponential disuse, chirp signal) for simulation purpose. I intend to bear witness (in a series of articles) how these basic signals can be generated in Matlab and how to correspond them in frequency domain using FFT. If you are inclined towards Python programming, visit here.

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=10 Hz sine moving ridge whose minimum and maximum amplitudes are -1V and +1V respectively. At present that you take determined the frequency of the sinewave, the next step is to make up one's mind the sampling rate. Matlab is a software that processes everything in digital. In order to generate/plot a smooth sine moving ridge, the sampling rate must be far college than the prescribed minimum required sampling rate which is at least twice the frequency f – as per Nyquist Shannon Theorem. A oversampling cistron of 30 is chosen here – this is to plot a smooth continuous-like sine wave (If this is non the requirement, reduce the oversampling factor to desired level). Thus the sampling rate becomes f_s=30 \times f=300 Hz. If a phase shift is desired for the sine wave, specify information technology besides.

          f=x; %frequency of sine wave overSampRate=30; %oversampling charge per unit fs=overSampRate*f; %sampling frequency stage = 1/3*pi; %desired stage shift in radians nCyl = 5; %to generate five cycles of sine wave  t=0:i/fs:nCyl*1/f; %time base  10=sin(2*pi*f*t+phase); %replace with cos if a cosine wave is desired plot(t,x); title(['Sine Wave f=', num2str(f), 'Hz']); xlabel('Time(s)'); ylabel('Amplitude');        
Sine Wave in Matlab

Representing in Frequency Domain

Representing the given signal in frequency domain is done via Fast Fourier Transform (FFT) which implements Detached Fourier Transform (DFT) in an efficient mode. Commonly, 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 tin can also be chosen as adjacent ability of 2 of the length of the bespeak.

Unlike representations of FFT:

Since FFT is only a numeric ciphering of N-indicate DFT, there are many ways to plot the issue.

i. Plotting raw values of DFT:

The x-centrality runs from 0 to N-1 – representing N sample values. Since the DFT values are complex, the magnitude of the DFT abs(X) is plotted on the y-axis. From this plot we cannot identify the frequency of the sinusoid that was generated.

          NFFT=1024; %NFFT-point DFT       X=fft(x,NFFT); %compute DFT using FFT         nVals=0:NFFT-1; %DFT Sample points        plot(nVals,abs(X));       title('Double Sided FFT - without FFTShift');         xlabel('Sample points (N-point DFT)')         ylabel('DFT Values');        
how to plot FFT in Matlab

2. FFT plot – plotting raw values against Normalized Frequency centrality:

In the next version of plot, the frequency axis (10-axis) is normalized to unity. But divide the sample index on the ten-axis by the length N of the FFT. This normalizes the x-axis with respect to the sampling rate f_s. Still, we cannot figure out the frequency of the sinusoid from the plot.

          NFFT=1024; %NFFT-point DFT       X=fft(10,NFFT); %compute DFT using FFT         nVals=(0:NFFT-one)/NFFT; %Normalized DFT Sample points          plot(nVals,abs(X));       title('Double Sided FFT - without FFTShift');         xlabel('Normalized Frequency')        ylabel('DFT Values');        
Normalized FFT how to plot FFT in Matlab

iii. FFT plot – plotting raw values confronting normalized frequency (positive & negative frequencies):

As you lot know, in the frequency domain, the values take upwardly 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 alphabetize 0 has to be centered at the middle of the array. This is done by using FFTshift function in Matlab. The ten-axis runs from -0.5 to 0.5 where the end points are the normalized 'folding frequencies' with respect to the sampling rate f_s.

          NFFT=1024; %NFFT-bespeak DFT       X=fftshift(fft(x,NFFT)); %compute DFT using FFT       fVals=(-NFFT/two:NFFT/2-1)/NFFT; %DFT Sample points         plot(fVals,abs(X));       championship('Double Sided FFT - with FFTShift');        xlabel('Normalized Frequency')        ylabel('DFT Values');        
Normalized FFT 2 how to plot FFT in Matlab

4. FFT plot – Absolute frequency on the x-axis Vs Magnitude on Y-axis:

Here, the normalized frequency axis is just multiplied by the sampling charge per unit. From the plot below we can ascertain that the accented value of FFT peaks at 10Hz and -10Hz . Thus the frequency of the generated sinusoid is 10 Hz. The minor side-lobes next to the peak values at 10Hz and -10Hz are due to spectral leakage.

          NFFT=1024;       X=fftshift(fft(x,NFFT));          fVals=fs*(-NFFT/2:NFFT/2-1)/NFFT;         plot(fVals,abs(10),'b');       title('Double Sided FFT - with FFTShift');        xlabel('Frequency (Hz)')          ylabel('|DFT Values|');        
FFT plot absolute Frequency axis how to plot FFT in Matlab

five. Power Spectrum – Absolute frequency on the x-axis Vs Power on Y-axis:

The following is the most important representation of FFT. It plots the ability of each frequency component on the y-centrality and the frequency on the x-axis. The power can be plotted in linear scale or in log scale. The power of each frequency component is calculated as
P_x(f)=X(f)X^{*}(f)
Where X(f) is the frequency domain representation of the point x(t). In Matlab, the power has to be calculated with proper scaling terms (since the length of the indicate and transform length of FFT may differ from example to case).

          NFFT=1024; Fifty=length(10);          X=fftshift(fft(ten,NFFT));          Px=X.*conj(X)/(NFFT*L); %Ability of each freq components        fVals=fs*(-NFFT/2:NFFT/2-1)/NFFT;         plot(fVals,Px,'b');       title('Power Spectral Density');          xlabel('Frequency (Hz)')          ylabel('Power');        
Power Spectral Density using FFT how to plot in Matlab

If you wish to verify the total power of the signal from time domain and frequency domain plots, follow this link.
Plotting the power spectral density (PSD) plot with y-centrality on log scale, produces the almost encountered type of PSD plot in signal processing.

          NFFT=1024;       L=length(x);          Ten=fftshift(fft(x,NFFT));          Px=10.*conj(X)/(NFFT*Fifty); %Power of each freq components        fVals=fs*(-NFFT/2:NFFT/2-one)/NFFT;         plot(fVals,x*log10(Px),'b');         title('Power Spectral Density');          xlabel('Frequency (Hz)')          ylabel('Power');        

6. Ability Spectrum – One-Sided frequencies

In this type of plot, the negative frequency part of ten-axis is omitted. Merely 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 f_s/2.

          Fifty=length(x);         NFFT=1024;        X=fft(ten,NFFT);        Px=X.*conj(X)/(NFFT*L); %Power of each freq components        fVals=fs*(0:NFFT/ii-1)/NFFT;       plot(fVals,Px(ane:NFFT/2),'b','LineSmoothing','on','LineWidth',ane);          title('One Sided Ability Spectral Density');        xlabel('Frequency (Hz)')          ylabel('PSD');        
One sided Power Spectral Density how to plot FFT in Matlab

Charge per unit this article: Poor Below average Average Good Excellent (112 votes, average: iv.66 out of 5)

For further reading

[1] Power spectral density – MIT opencourse ware↗

Topics in this affiliate

Books past the author

Source: https://www.gaussianwaves.com/2014/07/how-to-plot-fft-using-matlab-fft-of-basic-signals-sine-and-cosine-waves/

Posted by: saltzimen1990.blogspot.com

0 Response to "How To Comput And Draw The Fourir Transformation In Matlab"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel