[PDF] [PDF] Introduction A Simple Example

a positive frequency spectrum for a given signal and another peak of amplitude 1 at +4 Hz): plot the frequency spectrum using the MATLAB fft command



Previous PDF Next PDF





[PDF] Evaluating Fourier Transforms with MATLAB - CSUN

Using MATLAB to Plot the Fourier Transform of a Time Function The aperiodic pulse shown Say we want to find the amplitude spectrum of the two-frequency  



[PDF] Documentation of FFT function extracted from Matlab Version 711

NFFT = 2^nextpow2(L); Next power of 2 from length of y Y = fft(y,NFFT)/L; f = Fs/2*linspace(0,1,NFFT/2+1); Plot single−sided amplitude spectrum plot(f 



[PDF] Fast Fourier Transform and MATLAB Implementation

MATLAB Implementation by Speech or audio signal: A sound amplitude that varies in time 3 Discrete non periodic signal > continues periodic spectrum



[PDF] The Fundamentals of FFT-Based Signal Analysis and Measurement

impulse response, coherence, amplitude spectrum, and phase spectrum FFTs and the Power Spectrum are useful for measuring the frequency content of 



[PDF] Introduction A Simple Example

a positive frequency spectrum for a given signal and another peak of amplitude 1 at +4 Hz): plot the frequency spectrum using the MATLAB fft command



[PDF] MATLAB Lecture 7 Signal Processing in MATLAB

23 avr 2007 · before showing how Fourier transforms can be used to filter noise from signals 7 2 Waveform and Amplitude Spectrum Suppose we sample a 



[PDF] Fourier representation of signals (MATLAB tutorial)

19 February 2020 MATLAB tutorial series (Part 1 1) Example 1 2: plot magnitude and phase spectrum of the following signal –10 –5 0 5 10 15 20 0 0 5 1



[PDF] FFT, energy, and energy spectral density computations in MATLAB

Our goal in this section is to use MATLAB to plot the amplitude spectrum, energy spectral density, and numerically estimate the total energy Eg First, let's sample



[PDF] Time-frequency analysis of nonstationary signals - Benesco

0 6 0 8 1 fft(f) Amplitude spectrum Phase of frequency components 8 20 80 Frequency (Hz) -pi -pi/2 0 pi/2 pi Phase MATLAB 8 Hz with pi phase



[PDF] Overview of ocean wave statistics - UPCommons

This is logical; the spectrum is proportional to the square amplitude, In the present study, the FFT algorithm of MATLAB has been used, which implements the

[PDF] amr elrawi oracle

[PDF] amsmath fonts

[PDF] amy antm cycle 3 skinny

[PDF] amy denver beloved

[PDF] amy season 3 antm

[PDF] amznprime sg si ng

[PDF] amznprime sg singapore

[PDF] an abstract class can be final

[PDF] an abstract class may extend another class

[PDF] an abstract method cannot be modified by

[PDF] an abstract method cannot be overridden

[PDF] an abstract method cannot have

[PDF] an acid catalysed ester hydrolysis follows rate law

[PDF] an activity of the soul in accordance with a rational principle

[PDF] an activity of the soul in accordance with perfect virtue

Introduction

In this tutorial, we will discuss how to use the fft (Fast Fourier Transform) command within MATLAB. The fft command is in itself pretty simple, but takes a little bit of getting used to in order to be used effectively. When we represent a signal within matlab, we usually use two vectors, one for the x data, and one for the y data. The fft command only operates on the y-data (converting the y-data from the time domain into the frequency domain), so it's up to the user to determine what the x-data in the frequency domain will be! This tutorial will show you how to define your x-axis so that your fft results are meaningful. In addition, it will show you how to obtain a two-sided spectrum as well as a positive frequency spectrum for a given signal.

A Simple Example

1. Let's start off with a simple cosine wave, written in the following manner:

2. Next, let's generate this curve within matlab using the following commands:

3. fo = 4; %frequency of the sine wave

4. Fs = 100; %sampling rate

5. Ts = 1/Fs; %sampling time interval

6. t = 0:Ts:1-Ts; %sampling period

7. n = length(t); %number of samples

8. y = 2*sin(2*pi*fo*t); %the sine curve

9.

10. %plot the cosine curve in the time domain

11. sinePlot = figure;

12. plot(t,y)

13. xlabel('time (seconds)')

14. ylabel('y(t)')

15. title('Sample Sine Wave')

16. grid

Here's what we get:

17. When we take the fft of this curve, we would ideally expect to get the following spectrum in the

frequency domain (based on fourier theory, we expect to see one peak of amplitude 1 at -4 Hz, and another peak of amplitude 1 at +4 Hz): 1.

Using Matlab's FFT Command

So now that we know what to expect, let's use MATLAB's built in fft command to try to recreate the frequency spectrum: %plot the frequency spectrum using the MATLAB fft command matlabFFT = figure; %create a new figure YfreqDomain = fft(y); %take the fft of our sin wave, y(t) stem(abs(YfreqDomain)); %use abs command to get the magnitude %similary, we would use angle command to get the phase plot! %we'll discuss phase in another post though! xlabel('Sample Number') ylabel('Amplitude') title('Using the Matlab fft command') grid axis([0,100,0,120]) This doesn't quite look like what we predicted above. If you notice, there are a couple of things that are missing. The x-axis gives us no information on the frequency. How can we tell that the peaks are in the right place?

The amplitude is all the way up to 100

The spectrum is not centered around zero

A Custom Function for fft to Obtain a Two-Sided Spectrum

Here is a helpful function that will simplify the process of plotting a two-sided spectrum. Copy this

code into an m-file and save it. function [X,freq]=centeredFFT(x,Fs) %this is a custom function that helps in plotting the two-sided spectrum %x is the signal that is to be transformed %Fs is the sampling rate

N=length(x);

%this part of the code generates that frequency axis if mod(N,2)==0 k=-N/2:N/2-1; % N even else k=-(N-1)/2:(N-1)/2; % N odd end

T=N/Fs;

freq=k/T; %the frequency axis %takes the fft of the signal, and adjusts the amplitude accordingly

X=fft(x)/N; % normalize the data

X=fftshift(X); %shifts the fft data so that it is centered

This is a relatively simple function to use. The function outputs the correct frequency range and the

transformed signal. It takes in as input the signal to be transformed, and the sampling rate. Let's use the sine wave from above and do a quick example (Remember to set the Matlab directory to the location where you saved the previous m-file). Now, copy and paste these commands into the Matlab command prompt. [YfreqDomain,frequencyRange] = centeredFFT(y,Fs); centeredFFT = figure; %remember to take the abs of YfreqDomain to get the magnitude! stem(frequencyRange,abs(YfreqDomain)); xlabel('Freq (Hz)') ylabel('Amplitude') title('Using the centeredFFT function') grid axis([-6,6,0,1.5])

Here's what you should see:

As you can see, this plot is basically identical to what we would expect! We get peaks at both -4 Hz and +4 Hz, and the amplitude of the peaks are 1.

Redundant Information in the FFT

As you can see from the plots above, the information within the frequency spectrum is entirely symmetric. Thus, we only need one side of the spectrum. In general, the positive side of the spectrum is used, while the negative side is ignored. So let's adjust out function above so that we only get the positive frequencies. A Custom Function for fft to Obtain only the Positive Frequencies The following function is a modification of the above function, and will help you plot only the positive frequencies of the spectrum. function [X,freq]=positiveFFT(x,Fs)

N=length(x); %get the number of points

k=0:N-1; %create a vector from 0 to N-1

T=N/Fs; %get the frequency interval

freq=k/T; %create the frequency range

X=fft(x)/N; % normalize the data

%only want the first half of the FFT, since it is redundant cutOff = ceil(N/2); %take only the first half of the spectrum

X = X(1:cutOff);

freq = freq(1:cutOff); Once again, let's use the same sine wave and put it through this function. Copy and paste the following code into the Matlab command prompt. [YfreqDomain,frequencyRange] = positiveFFT(y,Fs); positiveFFT = figure; stem(frequencyRange,abs(YfreqDomain)); xlabel('Freq (Hz)') ylabel('Amplitude') title('Using the positiveFFT function') grid axis([0,20,0,1.5])

Here's what you should get:

These two functions are very useful, and I still use them all the time!

Download source files and Further Reading

You can download the source files here.

Brush up your Fourier by reading about the theory and background at these links: http://www.dspguide.com/ch8.htm

This is the end of the tutorial.

quotesdbs_dbs12.pdfusesText_18