Lab 10: An Introduction to Using the FFT
Function in MATLAB (TLDR Version)
For all check-boxes where work is required, please include any relevant
explanations, plots, and code.
1) Pre-lab (10 points)
To-Do’s:
□ Watch videos on FFT & DFT (recommended)
a) https://www.youtube.com/watch?v=dM1y6ZfQkDU
b) https://www.youtube.com/watch?v=V_dxWuWw8yM
c) https://www.youtube.com/watch?v=h6QJLx22zrE
□ Rewrite 1 () as a sum of sinusoids (5 pts):
□ Rewrite 2 () as a sum of sinusoids (5 pts):
2) Warmup (40 points)
2.1
□ Create a time vector tt of 1.5 sec and let fs be 1000 samples/sec.
□ Define a vector xx for the signal below using tt and fs:
□ Run the FFT on xx by using >> XX = fft(xx);
□ Plot the ‘magnitude spectrum’, i.e. plot abs(XX) .
□ Identify the ‘bin’ or index that corresponds to the leftmost peak.
1
□ Show the frequency of () is 50 Hz using the script:
>> f = bin*fs/length(XX);
□ Show the phase of () is /4 by running the script:
>> phase = angle(XX(bin+1))/pi;
□ Show the amplitude of () is 1 by running the script:
>> A = 2*abs(XX(bin+1))/length(XX);
2.2
□ Define vectors xx1 and xx2 using tt and fs from 2.1, given:
□ Run the FFT on xx1 and xx2.
□ Plot the magnitude spectrum of xx1 and xx2.
□ Identify the indices where peaks occur for each signal.
□ Calculate the frequencies, phases, and amplitudes of the components
of xx1 and xx2. Verify that these match your prelab.
2.3
□ Define a vector xx using the same tt and fs that will construct:
□ Run the FFT on xx by using >> XX = fft(xx);
□ Plot the ‘magnitude spectrum’, i.e. plot abs(XX) .
□ Find the index of the maximum of the left-hand peak.
□ Calculate the frequency using >> f = bin*fs/length(XX);
□ Comment on how this calculated frequency matches 50.5 Hz.
2.4
□ Watch the video on Zero Padding (recommended)
https://www.youtube.com/watch?v=7yYJZfc5q-I
□ Pad the signal in 2.3 with 15,000 zeros and run the FFT.
□ Calculate the frequency and compare to results from 2.3.
2
□ Repeat with 25k, 50k, and 100k zeros and describe the effect on the
accuracy of the frequency calculation.
2.5
□ Watch the video on DFT Windowing (recommended)
https://www.youtube.com/watch?v=PYd-pzaZpYE
□ Implement the Hann window on the signal from 2.3 (shown below)
using the previously defined tt and fs.
□ Pad xx with a large number of zeros. The exact number is your
choice.
□ Run the FFT on xx.
□ Plot the magnitude spectrum of XX. Use subplot() to compare the
magnitude spectrum with windowing and without.
□ Describe the effect of windowing on the magnitude spectrum.
3) Exercise (Rest-of-Lab) (50 points)
□ Download via Canvas the ECG signals 101am, 105am, 107am, and
110cm.
□ Load each .mat file into MATLAB. Each signal is 1 hour in length.
□ Write a function, or script, utilizing the FFT that will take in an ECG
signal and return a vector containing measurements of the average
heart rate. These measurements are to be taken 2 minutes at a time,
with overlap of 10 seconds.
□ For each signal, provide a plot showing the average heart rate over
the hour duration.