Você está na página 1de 4

Purdue University Northwest: ECE 448

Computer assignment #2:


Matlab Review
Dr. Khair Al Shamaileh

Due date: September 5, 2017


Purdue University Calumet ECE 448
1

Purpose
The purpose of this experiment is to learn how to use the Fourier transform routine fft in MATLAB.
Discussion
MATLAB uses the discrete Fourier transform (DFT) and inverse discrete Fourier transform (IDFT). The
discrete Fourier spectrum for a sequence g(nt) is given as:
N 1
j 2
G k g (nt ) exp( kn) (2.162 in textbook)
n 0 N

where;
k Frequency index providing f = kf
n Time index providing t = nt
t Time separation between points
f Frequency separation between points
N Number of discrete points in g(nt)

The inverse discrete Fourier transform to recover g(nt) is:

1 k N 1
j 2
g (nt )
N
G
k 0
k exp
N
kn

(2.163 in textbook)

There are certain limitations when applying the DFT to obtain a Fourier transform. DFT assumes the waveform
being transformed periodic with a period T. In order to represent a waveform electronically we have to
represent N discrete points. After the transformation, we get N frequencies. Each frequency is an integer
multiple of 1/T. We can scale the waveform such that T = Nt. As such, for N frequencies, f = 1/Nt. In
essence, when we scale the time waveform, we also scale the frequencies.

In this assignment, we learn to learn how to scale the frequencies in the spectrum. Sometimes, the frequency
spacing is insufficient to adequately represent a Fourier transform. We know that the Fourier transform applies
to non-periodic continuous signals with a period that approaches infinity. We can approximate this condition
by inserting zeros into the waveform thereby increasing N and decreasing f so that the spectrum appears
almost continuous. fft routine in MATLAB calculates the two-sided spectrum containing positive and negative
frequencies (you can use fftshift to get a two-sided spectrum with zero in the center). However, we choose to
work with a limited number of positive frequencies. We use the positive approximation for the continuous
spectrum for the function g(t) where the frequency index k is restricted 0 k (N/21). We use the positive
approximation for the continuous spectrum of g(t) by considering fft(g)t instead of fft(g). We can apply these
principles to the rectangular pulse of amplitude A and width . The rectangular pulse Arect(t/) has the transform
Asinc(/2). We expect to get this shape for our first spectrum.
Purdue University Calumet ECE 448
2

Task I: Procedure
Create a MATLAB script file having the name LASTNAME_LAB2_part1.m.
Carry out the following sequence of steps in the script file LASTNAME_LAB2_part1.m.

Run the subroutine below to display the spectrum of a unit amplitude rectangular function having a width
100 with 100 zeros before and after the signal.

clc
clear all
close all Fast Fourier Transform of signal g(t)
100
% Rectangular function generation
sig = ones(1,100); % = pulse width = 100 80
trail = zeros(1,100);
precede = zeros(1,100);
g = [precede sig trail]; 60
fft(g)

% Number of points in g(t)


N = length(g); 40

% Fourier transform of g(t)


20
z=fft(g);
stem(0:(N/21),abs(z(1:N/2)));
xlabel('Index number k'); 0
ylabel('fft(g)'); 0 50 100 150
title('Fast Fourier Transform of signal g(t)'); Index number k

The spectrum shows a horizontal scale as a function of the index k. We conclude that T = 300 as t = 1
and N = 300. The constant A = 100, which complies with the Fourier transformation (assuming A=1).
Modify the preceding program so that points in the pulse are separated by t=0.1ms and plot the positive
spectrum versus frequency. (The constant value should be 0.01).
Modify the program so that precede and trail zeros are 450 each while maintaining a separation of 0.1ms
and determine the period T. Plot the spectrum versus frequency up to the 15th harmonic.
Purdue University Calumet ECE 448
3

Task II: Questions and computations


Create a MATLAB script file having the name LASTNAME_LAB2_part2.m.
Carry out the following sequence of steps in the script file LASTNAME_LAB2_part2.m.

Using the fft function in MATLAB, plot the magnitude spectrum versus frequency for the signal
g(t) = exp(10t)u(t) for 0 t 1 with t = 0.01. Determine the number of points in the signal. Use 450
zeros for precede and trail and determine the period T.
Separately, plot the continuous magnitude transform given by:
1
G f 1 e10 j 2 f
10 j 2 f

Utilize the same separation in frequencies.


Using the fft function in MATLAB, plot the magnitude spectrum versus frequency for the signal:

g(t) = sinc(t).
Assume t = 0.01, and use 450 zeros for precede and trail and determine the period T.
Task III: Submission
Upload two pdf files, one per task, onto Blackboard Learn. Use the MATLAB commands
publish(LASTNAME_LAB2_part1,pdf) and publish(LASTNAME_LAB2_part2,pdf) to generate
the required pdf files.