Lab 3
Lab 3
Lab 3
Objectives:
• Learn how to transform a discrete time signal into the frequency domain.
• Learn how to extract useful information from the Discrete Fourier Transform (DFT).
• Learn how to reconstruct a discrete time signal using the inverse DFT (IDFT).
x(t ) CT to DT x[n]
Ts
The diagram illustrates a system that converts a continuous time (CT) signal to a discrete
time (DT) signal. This diagram represents much of what you were doing in Lab #1. This
system samples the input signal, x(t ) , every Ts seconds. The sampling frequency, f s = 1 Ts
, always has to be considered when converting from continuous time to discrete time and vice
versa. We will discuss this in more detail soon.
2. Let's start with an example signal, x(t ) = cos(4π t ) , which is a cosine wave with a frequency
of 2 Hz, as shown below:
1
0.8
0.6
0.4
0.2
x(t)
-0.2
-0.4
-0.6
-0.8
-1
0 0.5 1 1.5 2 2.5 3
t (seconds)
We want to sample this signal with a sampling frequency of f s = 30 Hz. Start a new
MATLAB m-file and place the following code at the top. You can use comments (green text)
as you see fit so that longer m-files don't get confusing.
Save your m-file and then run it by pressing F5. The following plot will be produced:
1
0.8
0.6
0.4
0.2
x[n]
-0.2
-0.4
-0.6
-0.8
-1
0 10 20 30 40 50 60 70 80 90
n
We can see right away that x[n] is a DT version of our input signal. Up to this point in the
course we have looked at some different ways to inspect a signal in terms of its frequency.
We will use the Discrete Fourier Transform (DFT) to view x[n] in the frequency domain.
Enter the following code into your m-file:
When you run the above code you should get the following plot:
60
40
|X[k]|
20
0
-50 -40 -30 -20 -10 0 10 20 30 40 50
k
4
2
∠ X[k]
-2
-4
-50 -40 -30 -20 -10 0 10 20 30 40 50
k
The above plot is probably not what you were expecting! MATLAB provides the Fast
Fourier Transform (FFT) to compute the DFT. Below is brief description of the various
Fourier transforms that can be used for signal processing:
• Continuous Time Fourier Transform (CTFT): Used to transform a CT signal, x(t ) , into
the frequency domain, yielding X ( f ) . Both x(t ) , and X ( f ) are continuous functions.
• Discrete Time Fourier Transform (DTFT): Used to transform a DT signal, x[n] , into
the frequency domain, yielding X ( f ) . While x[n] is discrete, X ( f ) is a continuous
function in f .
• Discrete Fourier Transform (DFT): Conceptually, the DFT is a discrete sampling of
the DTFT.
To make sense of the plot for X [k ] we need to map the values on the k-axis to useful
frequency values in the CTFT. To perform this mapping, use the following formula:
kf s
f = (1)
N
The variable N is the number of points used to compute the DFT (in our code N = 90 ), and
f s is the sampling frequency that we used to create the discrete time signal (in our code
f s = 30 Hz).
Now looking back at our plot of X[k], notice that there are two delta functions sitting at
6 × 30
k = ±6 . Applying equation (1) gives f = = 2 Hz, which is the exact frequency of our
90
original CT signal.
load('x2x3.mat');
[Q2.2] Using the same approach as in Part I, compute the DFT of x2[n] , X 2[k ] .
[Q2.3] x2[n] was created by adding together two sinusoids of different frequencies. What are
the frequencies of the two sinusoids in x 2[n] ? HINT: If a frequency is not a multiple of k, it
exhibits "leakage" into neighbouring frequencies, and your answer will be an estimate. You can
use fractional values of k in equation (1).
[Q2.4] Modify X 2[k ] so that the resulting signal only contains the lowest frequency sinusoid
(or most of it). Plot the resulting X 2[k ] .
[Q2.5] When you loaded the x2[n] from the x2x3.mat file, it also loaded x3[n]. T he signal
x3[n] is the lowest frequency sinusoid in x2[n]. Perform the IDFT on the modified X 2[k ] and
plot the resulting "processed" x2[n] and x[3] both on the same stem plot. You should be able to
get something close to the example below. Note that because you are filtering x2[n], you may
not be able to exactly get x3[n] = x2[n].
1.5
1
x3[n] and modified x2[n]
0.5
-0.5
-1
-1.5
0 10 20 30 40 50 60 70 80 90
n