MATLAB Session 5

1 / 14

# MATLAB Session 5 - PowerPoint PPT Presentation

MATLAB Session 5. ES 156 Signals and Systems 2007 HSEAS. Prepared by Frank Tompkins. Outline . Fourier transforms in MATLAB DTFT computation Two methods An example Digital filtering in MATLAB FIR and IIR. Fourier Transform. Fourier Transforms Continuous Time Fourier Transform (CTFT)

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.

## PowerPoint Slideshow about 'MATLAB Session 5' - neviah

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

### MATLAB Session 5

ES 156 Signals and Systems 2007

HSEAS

Prepared by Frank Tompkins

Outline
• Fourier transforms in MATLAB
• DTFT computation
• Two methods
• An example
• Digital filtering in MATLAB
• FIR and IIR
Fourier Transform
• Fourier Transforms
• Continuous Time Fourier Transform (CTFT)
• Discrete Time Fourier Transform (DTFT)
Fourier Transform Computation
• How to compute transforms on a computer?
• CTFT is continuous, so that’s out
• Can we compute DTFT?
DTFT Computation
• Infinite length discrete time signals
• DTFT defined on continuous frequency interval of length 2p; not computer friendly
• What do we do?
• Only deal with finite length signals
• Recall: discrete time Fourier series has finitely many coefficients
• So, we can use DTFS coefficients
• More detail on this technique, called Discrete Fourier Transform, or DFT, later in the course
• For now, just how to compute and plot “Fourier transform” in MATLAB
• All the acronyms can be overwhelming, but we’ve seen almost all by now
DTFT Computation (method 1)
• Given finite length N signal, extend it to infinity by padding with zeros to make X[n]
• DTFT X(ejw) has period 2p
• Instead of storing X(ejw) for every possible w, we can store N evenly spaced values of w
• Then, define X[k] = X(ej2pk/N)
• The coefficients X[k] have period N
• MATLAB command fft() computes X[k]
• Side note: FFT (sorry, one more acronym: Fast Fourier Transform) is a popular algorithm that computes transforms quickly – not important now
DTFT Computation (method 2)
• Another perspective
• Treat finite length N signal X[n] as a periodic (infinite length) signal Xp[n] with period N
• Compute the DTFS of Xp[n], ak
• Define X[k] = ak
• Note: X[k] has period N, just like X[n]
• These two approaches are equivalent
• For now, think of DTFT/DFT in whichever way is easier for you (probably method 1)
Example: DTFT of rectangular signal

x=[zeros(1,10) ones(1,7) zeros(1,10)];

y=fft(x);

figure;

subplot(2,1,1);

stem(x);

subplot(2,1,2);

plot(abs(y))

Zero padding - finer scale in Fourier transform

y2=fft(x,64);

y3=fft(x,128);

figure;

subplot(3,1,1);

plot(abs(y))

subplot(3,1,2);

plot(abs(y2))

subplot(3,1,3);

plot(abs(y3))

fftshift()
• By default, MATLAB’s fft() command outputs X(ej2pk/N) for 0 <= 2pk/N < 2p
• To get the output into the standard range of –p to p, use the fftshift() command:

my_xform = fftshift(fft(my_signal));

Filters – FIR vs. IIR
• A discrete time LTI filter can be expressed as a difference equation
• If all a(i)’s are zero except a(1) we call it FIR, otherwise it’s IIR
• MATLAB: z = filter(b,a,x)
Filter example
• Input: x[n] is the rectangular signal from before
• The difference equation describing the filter is

a=[1,-1];

b=1;

z=filter(b,a,x)

figure;

subplot(2,1,1);

stem(x);

subplot(2,1,2)

stem(z);