Presentation is loading. Please wait.

Presentation is loading. Please wait.

MATLAB Session 5 ES 156 Signals and Systems 2007 HSEAS Prepared by Frank Tompkins.

Similar presentations


Presentation on theme: "MATLAB Session 5 ES 156 Signals and Systems 2007 HSEAS Prepared by Frank Tompkins."— Presentation transcript:

1 MATLAB Session 5 ES 156 Signals and Systems 2007 HSEAS Prepared by Frank Tompkins

2 Outline Fourier transforms in MATLAB –DTFT computation Two methods An example Digital filtering in MATLAB –FIR and IIR

3 Fourier Transform Fourier Transforms –Continuous Time Fourier Transform (CTFT) –Discrete Time Fourier Transform (DTFT)

4 Fourier Transform Computation How to compute transforms on a computer? CTFT is continuous, so that’s out Can we compute DTFT?

5 DTFT Computation Infinite length discrete time signals –DTFT defined on continuous frequency interval of length 2  ; 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

6 DTFT Computation (method 1) Given finite length N signal, extend it to infinity by padding with zeros to make X[n] –DTFT X(e j  ) has period 2  –Instead of storing X(e j  ) for every possible , we can store N evenly spaced values of  –Then, define X[k] = X(e j2  k  ) –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

7 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], a k –Define X[k] = a k 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)

8 Example: DTFT of rectangular signal Rectangular signal

9 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))

10 Example: DTFT of rectangular signal

11 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))

12 fftshift() By default, MATLAB’s fft() command outputs X(e j2  k  ) for 0 <= 2  k/N < 2  To get the output into the standard range of –  to , use the fftshift() command: my_xform = fftshift(fft(my_signal));

13 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)

14 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);


Download ppt "MATLAB Session 5 ES 156 Signals and Systems 2007 HSEAS Prepared by Frank Tompkins."

Similar presentations


Ads by Google