# EE 341 Lab 4: Using the FFT for Frequency Analysis and Sound Transformations

\$30.00

## Description

In this lab, we will learn how to do frequency analysis of a discrete-time signal on a
computer, and investigate the effect of different frequency-domain transformations.
When using a digital computer, frequency analysis of a signal (or sequence) means
using a Fast Fourier Transform (FFT), which is an efficient implementation of a
discrete Fourier Transform (DFT), which is a discrete-frequency version of the
discrete-time Fourier transform (DTFT). In this lab, you will use the MATLAB
command fft to implement the DFT of different signals. Use the help feature in
MATLAB to learn the syntax of the fft function.
For the FFT, the length N is constrained to be a power of 2. You can specify the
length of the FFT that you want to use. If the FFT length is longer than your signal,
then the function will add zeros to the end of the signal.
1. Computing and plotting DFTs with MATLAB
Recall that in discrete-time, there is only a 2p range of unique frequencies, so the
DTFT is periodic with period 2p (or 1 if we are using normalized frequency). The
DFT is a sampled version of the DTFT of a windowed signal, with samples at integer
multiples of 2p/N where N is the length of the DFT (and the time signal window). The
DFT outputs a sequence for k=0,…,N-1 where the sample k corresponds to frequency
k2p/N. We typically plot the DTFT over the range [-p,p) in radians or [-0.5,0.5) in
normalized frequency. You can take advantage of periodicity of the DFT X[k] to get
the negative frequencies (X[-k]=X[N-k]), which is done for you with the the
fftshift function.
Suppose we want to find the Fourier Transform X_fft of signal x using N = 1024
samples in the frequency domain:
N = 1024;
X_fft = fftshift(fft(x, N));
This will give a DFT centered around w=0.
In general, a DTFT (and hence an FFT) of a sequence will be a complex function so
you will need to look at the magnitude and phase separately. The MATLAB
commands abs and angle are useful for obtaining the magnitude and phase of a
complex valued sequence. Often magnitude is plotted on a log scale.
Now, let’s say you did some processing in the frequency domain, and now want to
convert Y_fft to the time domain, we would call ifft as such:
y_ifft = ifft(fftshift(Y_fft), N)
y = real(y_ifft);
A call to function real is needed because numerical round-off errors in fft and ifft can
introduce a very small nonzero imaginary component to the output y_ifft. In general,
the time domain signals we analyze will be real-valued, so we need to remove the
insignificant imaginary part. (If the imaginary part is not small, then you probably
have an error somewhere.)
The FFT only has values at discrete frequencies, but continuous frequency plots (i.e.
using plot) are often used since they look like the DTFT or CTFT that you are
ultimately interested in. To plot the DTFT based on the DFT, you will need to convert
the discrete sample times to continuous frequencies for the x-axis: k à k2p/N in
radians or k à k/N in normalized frequency. To plot the CTFT based on the DFT,
use k à kFs/N in Hz where Fs is the sampling frequency.
Find the DFT and plot the log magnitude and phase of the corresponding DTFT for
the following signals:
x1[n]=(-0.9)n
u[n] x2[n]=(0.9)n
u[n] x3[n]=(0.5)
n
u[n]
IN-LAB CHECK-OFF: Show the TA your plots for the different signals. Be sure to
label the frequency axis.
WRITTEN REPORT: Turn in the plots for the different signals. Specify the window
length N and explain why the DFTs look different in terms of Fourier Transform
properties.
2. FFT of a Periodic Signal
Plot the magnitude of the FFT of the following signal before and after the fftshift
for the cases where f=0.25 and f=0.5. Generate a 2-part stem plot for each signal
(unshifted DFT and shifted DFT) using a normalized frequency scale. Discuss why
the frequency peak locations make sense. For the case where f=0.26, plot the
magnitude after the fftshift for three different length signals side by side (N=32,
N=128, and N=512), increasing the length of the FFT accordingly. Then plot the
magnitude of the results of a 512 point FFT with the original N=128 length signal.
Explain any differences you observe.
Read in the short flute sound. Generate a plot showing the log magnitude of the DFT
for this signal with a frequency axis scaled according to the sampling frequency that
you read with the signal (as for a CTFT). Determine what note is being played.
IN-LAB CHECK-OFF: Show the TA your plots for the different cosines and explain
the results.
WRITTEN REPORT: Turn in the plots for the cosine with frequency f=0.26 for the
3 window lengths and explain why the DFTs look different. Include the flute DFT
plot, specify what length FFT you used and why, and explain how you determined the
note that is being played.
3. Frequency Shifting
Recall that multiplying by a complex exponential in time (or a cosine, which is
comprised of complex exponentials) results in a frequency shift. For each of the
following sequences, let and . Use the built-in sinc function in
MATLAB. Plot the magnitude and phase plots (using plot), where the magnitude and
phase plots are over the range -0.5 ≤ f ≤ 0.5 (normalized frequency), i.e. use
fftshift).
a) .
b) .
x n fn n [ ] 1 cos(2 ) 0 127 =+ ; p £ £
1f = . 0 15 0 255 £ £ n
1 1 xn f n [ ] sinc( ( 32)) = –
2 1 [ ] sinc( ( 32))( 1)n xn fn = – –
c) where .
WRITTEN REPORT: Turn in plots of the magnitude and plots for (a)-(c). State
what type of signals each corresponds to (low pass, high pass, etc.) and what the
(normalized) cut-off frequencies are for each. Explain why the DTFTs do not have a
flat frequency response in the passband.
• In-lab group demonstrations (due during the eighth or ninth week of class)
o Part 1: Display the frequency response plots for the TA and explain
the differences between the signals.
o Part 2: Show the TA the FFT plots for the cosine signal.
• Written report:
o Part 1: Turn in the frequency plots and discussion of differences.
o Part 2: Turn in the frequency domain plots for the cosine with
frequency f=0.26 and explain why the DFTs look different. Include the
flute DFT plot, specify what length FFT you used and why, and
explain how you determined the note that is being played.
o Part 3: Display the frequency domain plots for (a)-(c) for the TA. State
what type of signals each corresponds to (low pass, high pass, etc.) and
what the cut-off frequencies are for each. Explain why the filters do
not have a flat frequency response in the passband.
• Individual files to be turned in via Canvas (due the day before your lab during
the week of Feb 20-23)
o Written report
o Matlab code
31 2 x n f n fn [ ] sinc( ( 32)) cos(2 ) = – p 2f = . 0 2