Southern Methodist University School of Engineering Electrical

Southern Methodist University

School of Engineering

Electrical Engineering Department

EE 2170 Design and Analysis of Signals and Systems

Laboratory Notes

Yasser Ghanbari, Carlos Davila, Scott C. Douglas, and Panos E.

Papamichalis,

©2011, SMU. All Rights Reserved

Spring 2011

Contents

4.

Integral in MATLAB a.

Example: integration in MATLAB b.

Example: convolution of two signals using ‘trapz’ c.

Example: convolution of two signals using ‘conv’ d.

Assignment 4: Convolution

5.

Exponential Fourier Series a.

Exponential Fourier series coefficients b.

Signal reconstruction using the exponential Fourier series coefficients c.

Side note: summation of vectors d.

Assignment 5: exponential Fourier series in MATLAB

6.

Introduction to Simulink a.

Example: trigonometric Fourier series in Simulink b.

Example: signal reconstruction using trigonometric Fourier series coefficients in

Simulink c.

Assignment 6: Double Sideband (DSB) Modulation/Demodulation

7.

Convolution a.

Example: convolution of two signals using ‘conv’ b.

Example: convolution of two signals using ‘trapz’ c.

Assignment 7: Convolution

8.

First Order RC Lowpass Filters a.

Example: frequency response of the first order LPF b.

Assignment 8: RC Lowpass Filters

9.

Filters in LTI Systems a.

Example: lowpass filtering of a noisy EKG signal b.

Assignment 9: Lowpass, Highpass, and Bandstop Filters

10.

Audio Signals a.

Example: audio signal analysis in MATLAB b.

Assignment 10: Notch Filter for Interference Removal

11.

Laplace Transform a.

Example: Laplace transform visualization in MATLAB b.

Assignment 11: Visualizing the Laplace Transform

12.

Image Signals a.

Example: image signal analysis in MATLAB b.

Assignment 12: Image Signal Enhancement and Resizing

5. Exponential Fourier Series

Exponential Fourier series coefficients

The exponential Fourier series coefficients of a periodic signal f ( t ) with the period T is defined as a k

1

T

T f ( t ) e

 jk

0 t dt where

(5-1) a

0

1

T

T f ( t ) dt (5-2)

The above equations can be implemented in MATLAB using trapz . Recall that the typical syntax of ‘ trapz

’ is

E = trapz(t,f) where t is the time vector and f is a vector of the corresponding function (signal) values which must have the same length as the vector t . The above command calculates the integral of the function f(t) . E is clearly the numerical integral result.

Signal reconstruction using the exponential Fourier series coefficients

These coefficients a k

can be used to reconstruct an approximation of the original periodic signal f ( t ) using the following equation: f

ˆ

N

( t )

 k

N 

 

N a k e jk

0 t

(5-4)

In order to implement the above equation, a programming skill is needed which is going to be covered by the next side note.

Side note: summation of vectors

Suppose that the function f ( t )

 n

N 

 

N c n e

 nt u ( t ) is to be implemented in MATLAB. t is a vector of time, N is a given number indicating how many times the summation is repeated, and c n is given for each n . The following code indicates how a for loop may be employed to construct the vector f using the concept of nested vector summation. Please note that this code assumes c n

=sinc( n

π/2),

N =5, and t

[ 0 5 ] . These parameters can change based on reader’s interest.

N = 5; t = 0:0.01:1; f = 0; %initialization c = 0; %initialization for n = -N : N

u = t>=0;

c(n+N+1) = sinc(n*pi/2); %vector index starts from 1 in MATLAB

y = c(n+N+1)*exp(-n*t).*u;

f = f + y; end figure; plot(t,f); xlabel( 't' ); ylabel( 'f(t)' )

Figure 5-1. A MATLAB implementation for the summation of vectors

Figure 5-2. The resulting plot from the MATLAB implementation of Figure 5-1

Assignment 4: exponential Fourier series in MATLAB

At this assignment, we want to implement the Fourier series in MATLAB. The goal is to write a function which calculates the Fourier series coefficients of a given periodic function, and to apply the function to a synthetic and a real signal. Reconstruction of the original signal from its Fourier series coefficients is also considered. a.

Write a MATLAB function, [ a ] = EFS ( x,t,T ,N), which gets the input function x (t) as a vector x , the vector of time positions ( t in sec), the period ( T in sec), and N (number of coefficients) as the input arguments so as to calculate and return the exponential Fourier series coefficients in a vector a : a k

1

T

T f ( t ) e

 jk

0 t dt

Here, a is a vector of length 2 N +1, i.e. k varies from

–N

to N . For integration purposes, use trapz in MATLAB. b.

Write a MATLAB program (in a new m-file) in which the following periodic square wave is defined for one period, in the time interval of [-1 1] with the increments of 0.001, and call your function EFS from part (a), to obtain the Fourier series coefficients in the vector a . Report the resulting coefficients for N=3 (7 values) and N=20 (41 values). Also, plot the magnitude and phase of the coefficients a k

in two subplots for each of N=3 and

N=20 using the stem plot “ stem(1:N,a, 'fill' , '-' , 'markerfacecolor' , 'r' )

” with appropriate labels (you will have two figures each with two subplots for each N). x(t)

1.5 t

-1 0 1 2 3

-1.5

c.

Write a MATLAB function, [ x_hat ]= reconstEFS ( t,T,a,,N ), to reconstruct x ( t ) in the time interval of [-1 1] using the following equation:

N

( t )

 k

N 

N a k e jk

0 t d.

Write a MATLAB program (in a new m-file) in which the same above periodic square wave is defined for one period, in the time interval of [-1 1] with the increments of 0.001, and call your function EFS from part (a), to obtain the Fourier series coefficients in the vector a . Then call your function reconstEFS to calculate

ˆ

N

( t ) for both N=3 and N=20 for the Fourier series obtained in the vector a

Plot x ( t ), x

ˆ

3

( t ), and the plot).

20

( t ) on the same plot-box with different colors (use legend on

Explain your observations. e.

Repeat parts (b) and (c) for the given EKG signal.

First load and plot the recorded signal with respect to the time.

Then estimate and report the period of the recorded signal (by looking at the plot) and the corresponding frequency ( ω

0

) in your program.

Select one period of the recorded signal (as a vector and assign it to a new variable, e.g. x ) and use the selected part of the signal with the corresponding time vector to calculate the Fourier series coefficient (for N=5 and N=50) using the EFS function.

The calculated coefficients are to be employed to reconstruct the whole EKG signal using reconstEFS function for N = 5 and N=50.

Plot x ( t ) and x

ˆ

5

( t ) in the same figure (with the same step size as the recorded signal) and explain your observations.

Plot x ( t ) and

ˆ

50

( t ) in the same figure (with the same step size as the recorded signal) and explain your observations.