0% found this document useful (0 votes)
14 views18 pages

212 EEE312 LabSheet 05

This document outlines Lab Sheet 5 focused on the Discrete Fourier Transform (DFT) and its implementation using MATLAB. It includes theoretical background, practical sessions for DFT and Fast Fourier Transform (FFT), and examples demonstrating their application in analyzing and synthesizing discrete-time signals. The lab also covers homework assignments related to signal processing concepts and practical applications of DFT and FFT.

Uploaded by

md al amin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views18 pages

212 EEE312 LabSheet 05

This document outlines Lab Sheet 5 focused on the Discrete Fourier Transform (DFT) and its implementation using MATLAB. It includes theoretical background, practical sessions for DFT and Fast Fourier Transform (FFT), and examples demonstrating their application in analyzing and synthesizing discrete-time signals. The lab also covers homework assignments related to signal processing concepts and practical applications of DFT and FFT.

Uploaded by

md al amin
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Lab Sheet 5

Discrete Fourier Transform (DFT) using MATLAB

1.​ A fundamental knowledge on MATLAB


2.​ A theoretical knowledge on DFT and FFT.

1.​ investigate the Discrete Fourier Transform


2.​ learn how to implement the operation using MATLAB
3.​ learn how to analyze discrete-time signal using DFT
4.​ learn how to synthesize discrete-time signal using IDFT
5.​ analyze some real life problems involving DFT.

1.​ Lab Session 5.1: DFT and it’s MATLAB Implementation


2.​ Lab Session 5.2: FFT and it’s MATLAB Implementation
3.​ Lab Session 5.3: Practical Applications of DFT
4.​ In Lab Evaluation
5.​ Home work

Lab Session 5.1:DFT and it’s MATLAB Implementation


Theoretical Background
DFT:The Discrete Fourier Transform of an N-point sequence is given by

where . Note that the DFT is also an N-point sequence, that is, it is not
defined outside

1 | Page
Prepared by BKM Mizanur Rahman, updated by MK Masukur Rahman, Dept of EEE, UIU
IDFT: The inverse discrete Fourier transform (IDFT) of an N-point DFT is given
by (once again is not defined outside )

In MATLAB, an efficient implementation of the both transforms, DFT and IDFT,


would be to use a matrix-vector multiplication for each of the relations in (1) and (2).If
and are arranged as row vectors x and X, respectively, then from (1) and (2)
we have

​ (3)

​ (4)

where and are a DFT matrix and its conjugate, respectively. The following
MATLAB functions implement the above equations.
Custom Functions

2 | Page
Prepared by BKM Mizanur Rahman, updated by MK Masukur Rahman, Dept of EEE, UIU
Example 5.1:
Let x(n) be a 4-point sequence defined as, x = [1, 0.5, 0.2, 0.1] for 0 ≤n ≤ 3, zero
otherwise.

Compute 4-point DFT of x(n)


Solution:
MATLAB Code:

Output:
magX =
1.8000 0.8944 0.6000 0.8944
phaX =
0 -26.5651 -0.0000 26.5651
Figure:

MATLAB Implementation of Inverse Discrete Fourier Transform:


Example 5.2: find the inverse DFT X(k) in above example.
Solution:
MATLAB Code:

3 | Page
Prepared by BKM Mizanur Rahman, updated by MK Masukur Rahman, Dept of EEE, UIU
Output:

ans =

1.0000 - 0.0000i 0.5000 + 0.0000i 0.2000 + 0.0000i 0.1000 + 0.0000i


Which is same as x = [1, 0.5, 0.2, 0.1];

Zero Padding in DFT:


Example 5.3: Apply the zero-padding operation, which is a technique that allows us to
sample at dense (or finer) frequencies, to get an 8-point sequence and then compute its
DFT by using the following MATLAB commands.
Solution:
MATLAB Code:

Output:
At Command window:

Figure:

4 | Page
Prepared by BKM Mizanur Rahman, updated by MK Masukur Rahman, Dept of EEE, UIU
Can you see that DFT (magnitude) is symmetric about middle point (excluding first
point)?
You have noticed similarity in frequency response between original and zero padding
versions. Now try again with a new value of x=[ 1, 1, 1, 1] and see the difference again.

Example 5.4:
For the sequence , use the following MATLAB commands
to determine the 30-point DFT of .
Solution:
MATLAB Code:

Output:
Figure:

5 | Page
Prepared by BKM Mizanur Rahman, updated by MK Masukur Rahman, Dept of EEE, UIU
Circular folding: If an N-point sequence is folded, the result x(-n) would not be an
N-point sequence, and it would not be possible to compute DFT. Therefore we use the
modulo-N operation on the argument (-n) and define folding by,

This is called circular folding.


The DFT of a circular folding is given by,

Example 5.5:
Let

(a)​ Determine and plot


(b)​Determine DFT of the circularly shifted sequence.
Solution:
(a) MATLAB Code:

Output:

6 | Page
Prepared by BKM Mizanur Rahman, updated by MK Masukur Rahman, Dept of EEE, UIU
Solution:
(b) MATLAB Code:

Output:

7 | Page
Prepared by BKM Mizanur Rahman, updated by MK Masukur Rahman, Dept of EEE, UIU
What changes do you observe in frequency domain due to circular folding
operation?

Lab Session 5.2:FFT and it’s MATLAB Implementation

8 | Page
Prepared by BKM Mizanur Rahman, updated by MK Masukur Rahman, Dept of EEE, UIU
The DFT introduced previously is the only tramsform that is discrete in both the time and
the frequency domains, and is defined for finite-duration sequences. Although it is a
computable transform, the straightforward implementation of it is very inefficient,
especially when the sequence length N is large. In 1965 Cooley and Tukey showed a
procedure to substantially reduce the amount of computations involved in the DFT. This
led to the explosion of application of the DFT, including in digital signal processing area.
Furthermore, is also led to the development of other efficient algorithms. All these
efficient algorithms are collectively known as Fast Fourier Transform (FFT) algorithms.
In an efficiently designed algorithm the number of computations should ne constant per
data sample, and therefore the total number of computations should be linear with respect
to N. The number of DFT computations for an N-point sequence depends quadratically on
N, which will be denoted by the notation

​ (1)

FFT algorithms can reduce the quadratic dependence on N of the DFT. Theoretically, the
number of computations used in the FFT algorithms could be as small as, depending on
the radix used in the alogorithm,

​ (2)

MATLAB provides a function called fft to compute the DFT of a vector x. It is


invoked by x = fft(x, N), which computes the N-point DFT. If the length of x is less
than N, then x is padded with zeros. If the argument N is omitted, then the length of the
DFT is the length of x. If x is a matrix, then fft(x,N) computes the N-point of each
column of x.
This fft function is written in machine language and not using MATLAB commands
(i.e., it is not available as a .m file). Therefore it executes very fast. It is written as a
mixed-radix algorithm. If N is a power of two, then a high-speed redix-2 FFT algorithm is
employed. If N is not a power of two, then N is decomposed into prime factors and a
slower mixed-radix FFT algorithm is used. Finally, if N is a prime number, then the fft
function is reduced to the raw DFT algorithm.
The IDFT is computed using the ifft function, having same characteristics as fft.
Example 5.6:
Determine the execution time of the DFT & FFT as N varies from 10 to 512, invoke the
following commands and then save the plot.
Solution:
MATLAB Code:

9 | Page
Prepared by BKM Mizanur Rahman, updated by MK Masukur Rahman, Dept of EEE, UIU
Output:

Can you see the difference in time requirements?


Lab Session 5.3:FFT and Practical Applications
FFT of a signal can be computed as follows:

10 | Page
Prepared by BKM Mizanur Rahman, updated by MK Masukur Rahman, Dept of EEE, UIU
Original frequency of sinusoid can be found from FFT as follows:

Here, fo = fF * f /(N-1)
fo = original freq,
fF = (index of freq in FFT) – 1, (excluding 1st element, DC value)
f = sampling frequency;
N = number of samples (in time series or its FFT)

Example 5.7: FFT of Noisy Data


Sample the sinusoid x(t) = cos(2πf0t) with f0 = 8 Hz at S = 64 Hz for 4 s to obtain a
256-point sampled signal x[n]. Also generate 256 samples of a uniformly distributed
noise sequence s[n] with zero mean.
(a)​ Display the first 32 samples of x[n]. Can you identify the period from the
plot? Compute and plot the DFT of x[n]. Does the spectrum match your
expectations?
(b)​ Generate the noisy signal y[n] = x[n] + s[n] and display the first 32 samples
of y[n]. Do you detect any periodicity in the data? Compute and plot the
DFT of the noisy signal y[n]. Can you identify the frequency and magnitude
11 | Page
Prepared by BKM Mizanur Rahman, updated by MK Masukur Rahman, Dept of EEE, UIU
of the periodic component from the spectrum? Do they match your
expectations?
(c)​ Generate the noisy signal z[n] = x[n]s[n] (by element-wise multiplication)
and display the first 32 samples of z[n]. Do you detect any periodicity in the
data? Compute and plot the DFT of the noisy signal z[n]. Can you identify
the frequency the periodic component from the spectrum?

Used Custom function:


Collect custom functions Randist and dtplot from server-7

MATLAB Code:

Output:
Figure-1:

12 | Page
Prepared by BKM Mizanur Rahman, updated by MK Masukur Rahman, Dept of EEE, UIU
Figure-2:

Figure-3:

13 | Page
Prepared by BKM Mizanur Rahman, updated by MK Masukur Rahman, Dept of EEE, UIU
Comment on the above three figures.
Can you reconstruct the original signal from the noisy one by manipulating the fourier
transform?
Try yourself first, then consider the following code:

Example 5.8: Filtering a Noisy ECG Signal


During recording, an electrocardiogram (ECG) signal, sampled at 300 Hz, gets
contaminated by 60-Hz hum. Two beats of the original and contaminated signal (600
samples) are provided at server-7 ecgo.mat and ecg.mat. Load these signals into
MATLAB (for example, use the command load ecgo). In an effort to remove the 60-Hz
hum, use the DFT as a filter to implement the following steps
(a)​ Compute 600-point DFT of the contaminated ECG signal
(b)​ Compute the DFT indices that correspond to the 60-Hz signal.
(c)​ Zero out the DFT components corresponding the 60-Hz signal.
(d)​ Take the IDFT to obtain the filtered ECG and display the original and
filtered signal.
(e)​ Display the DFT of the original and filtered ECG signal and comment on
the differences.
(f)​ Is the DFT effective in removing the 60-Hz interference?
14 | Page
Prepared by BKM Mizanur Rahman, updated by MK Masukur Rahman, Dept of EEE, UIU
Solution:
MATLAB code:

Home Task: Reconstruct the noise-free ECG signal from the noisy-ECG signal.

Example 5.9: Finding frequency components of a signal buried in a noisy time


domain signal
A common use of Fourier transforms is to find the frequency components of a signal
buried in a noisy time domain signal. Consider data sampled at 1000 Hz. Form a signal
containing a 50 Hz sinusoid of amplitude 0.7 and 120 Hz sinusoid of amplitude 1 and
corrupt it with some zero-mean random noise, Plot the Signal Corrupted with Zero-Mean
Random Noise.
Solution:
15 | Page
Prepared by BKM Mizanur Rahman, updated by MK Masukur Rahman, Dept of EEE, UIU
MATLAB code:

Comment: It is difficult to identify the frequency components by looking at the original


signal. Converting to the frequency domain, the discrete Fourier transform of the noisy
signal y is found by taking the fast Fourier transform (FFT):

Extension of example 5.10 :Plotting after taking fft

16 | Page
Prepared by BKM Mizanur Rahman, updated by MK Masukur Rahman, Dept of EEE, UIU
Output:

Comment: The main reason the amplitudes are not exactly at 0.7 and 1 is because of
the noise. Several executions of this code (including recomputation of y) will produce
different approximations to 0.7 and 1. The other reason is that you have a finite length
signal. Increasing L from 1000 to 10000 in the example above will produce much better
approximations on average.

Home Task: Reconstruct the noise-free signal from the noisy signal.

In Lab Evaluation:
ILE 5.1 A 12-point sequence x(n) is defined as

Determine the DFT of x(n). Plot it’s magnitude and phase

17 | Page
Prepared by BKM Mizanur Rahman, updated by MK Masukur Rahman, Dept of EEE, UIU
ILE 5.2
Let

(a)​ Determine and plot


(b)​Determine DFT of the circularly shifted sequence.

Home Work
HW5.1 Correlation is an effective method of detecting signals buried in noise. Noise are
essentially uncorrelated.This means that, if we correlate a noisy signal with itself, the
correlation will be only due to the signal only.This will exhibit a sharp peak at n=0.
Generate two noisy signals by adding noise to a 20Hz sinusoid sampled at Ts=0.01 sec for
1 seconds.
(a)​ Verify the presence of the signal by ploting correlation of the two noisy signals.
(b)​Can you see the presence of periodicity in correlation plot? Where it coming from?
(c)​ Plot FFT spectrum of the correlation.
(d)​Can you see the original sinusoid frequency in the FFT?
HW5.2 During transmission, a message signal gets contaminated by a low-frequency signal and
high-frequency noise. The message can be decoded only by displaying it in the time
domain. The contaminated signal x[n] is provided at server-7 as mystery1.mat.
Load this signal into Matlab (use the command load mystery1). In an effort to decode the
message,try the following procedure and determine what the decoded message says.
(a)​ Display the contaminated signal. Can you “read” the message?
(b)​Display the DFT of the signal to identify the range of the message spectrum.
(c)​ First zero out the DFT component corresponding to the low-frequency
contamination and obtain its IDFT y[n].
(d)​Next, zero out the DFT component corresponding to the high-frequency
contamination and obtain its IDFT y[n].
(e)​ Take the IDFT to obtain the filtered signal and display it to decode the message.

18 | Page
Prepared by BKM Mizanur Rahman, updated by MK Masukur Rahman, Dept of EEE, UIU

You might also like