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: Fourier series coefficient in Simulink
b. Example: square wave signal reconstruction in Simulink
c. Assignment 6: exponential Fourier series coefficients in Simulink
7. Fourier Transform
a. Example: Fourier transform of a rectangular function
b. Assignment 7: Fourier transform
8. Audio Signals in MATLAB
a. Example: audio signal plotting in MATLAB
b. Assignment 8: convolution and the Fourier analysis
9. Filters in LTI Systems
a. Example: lowpass filtering of a noisy EKG signal
b. Assignment 9: Lowpass, Highpass, and Bandstop Filters
10. First Order RC Lowpass Filters
a. Example: frequency response of the first order LPF
b. Assignment 10: RC Lowpass Filters
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
10. First Order RC Lowpass Filters
The frequency response of the first order lowpass filters (LPFs) is generally represented as:
H  j  
b0
a0  a1 ( j )
(10-1)
where b0=1, a0=1, and a1=1/ωc. Therefore, the impulse response can be calculated using the
inverse Fourier transform as:
h(t )  c e ct u (t )
(10-2)
The frequency ‘ωc’ is called the ‘corner frequency’ that is essentially the frequency at which the
frequency response magnitude equals 1
2 . Typically the frequency response magnitude is
indicated in decibels (dB) unit which is defined as:

1
H  j  dB  20 log 10  H  j    20 log 10 

2
 1    c 




(10-3)
Therefore, at the corner frequency (ω=ωc), the frequency response magnitude is approximately
-3dB.
Example: frequency response of the first order LPF
The frequency response of the LPF can be displayed using both magnitude and phase plots.
The following MATLAB code plots the magnitude and phase of the first order LPF in the
frequency range of -5 to 5 rad/s for ωc =1. Figure 10-2 shows the resulting plots.
clc; clear; close all;
omega = [-5 : 0.1 : 5]; %Frequency vector
omega_c = 1;
%----------------Frequency response----------------Hjw = 1./(1 + j*omega/omega_c); %Frequency response
Hjw_mag_dB = 20*log10(abs(Hjw)); %Frequency response magnitude in dB
Hjw_phase = phase(Hjw); %Frequency response phase
figure;
subplot(2,1,1);plot(omega,Hjw_mag_dB,'LineWidth',2);
xlabel('\omega(rad/sec)')
ylabel('|H(j\omega)|_d_B')
subplot(2,1,2); plot(omega,Hjw_phase,'LineWidth',2)
xlabel('\omega(rad/sec)')
ylabel('\langleH(j\omega)')
Figure 10-1. MATLAB code to plot the magnitude and phase of the frequency response in
Equation (10-1)
Figure 10-2. Magnitude and phase of the frequency response of the first order LPF for ωc =1.
The first order lowpass filter (LPF) can be implemented using the basic circuit elements R
and C. Figure 10-3 shows the first order LPF using a resistor (R) and a capacitor (C).
Figure 10-3. RC lowpass filter
The frequency response of the above circuit can be calculated as the ratio of the output voltage to
the input voltage. Since resistor R is represented by ‘R’ and capacitor C is represented by
‘ 1 ( jC) ’ in the frequency domain, the frequency response is calculated as
H  j  
VO
1 /( jC )
1


Vi R  1 /( jC ) 1  jRC
which is a type of the first order lowpass filter defined in Equation (10-1).
(10-4)
Assignment 10: RC Lowpass Filters
The goal of this assignment is to simulate an RC lowpss filter to analyze its behavior and
investigate its frequency response and characteristics.
I. Using MATLAB Simulink create a new model and add a sine wave source block, a first
order transfer function, a scope to monitor both inputs and outputs of the transfer function
using a MUX block as follows:
Suppose that the letter “s” in the transfer function represents the term “jω” of a first order
filter frequency response. Therefore in the initial model configuration the frequency
response is assumed to be:
1
1
1
H ( s) 
 H ( j ) 

s 1
j  1 j  1  1
Here, we would like to modify H(jω) so that it represent the following RC circuit transfer
function:
Therefore, H(jω) should be changed into:
1
H ( j ) 
j   c   1
a. Express ωc based on the resistor and capacitor values, R and C.
b. Determine the frequency response H(jω) for the RC circuit given R=10KΩ and
C=1μF.
c. Regarding your derived H(jω) for the RC circuit in part b, determine and modify the
parameters of the transfer function in the Simulink model by double clicking on its
block.
d. Set the frequency of the input sine wave to 10 rad/sec and the sample time to 0.0001.
Run the simulation and report what scope displays. Make sure that the scope displays
the output for the entire time interval by unchecking the “Limit data points to last”
checkbox in the “Data history” tab of the “Scope parameters”. What is the ratio of the
output amplitude to the input amplitude?
e. Repeat part d for the source frequency of 1000 rad/sec.
f. In the Simulink RC model, manually set the source frequency to different values
changing from 20 to 300 rad/sec, in increments of 20 rad/sec, run the simulation for
each frequency and estimate the ratio of the output amplitude to the input amplitude
by visual inspection of the scope. Include all the selected frequencies with the
corresponding output-to-input amplitude-ratios in a table in your report, and use an
Excel spreadsheet or Matlab to plot amplitude-ratios with respect to the selected
frequencies. From your table or plot, determine the corner frequency of the RC filter.
g. Regarding the concept of the corner frequency, suggest a method to estimate an
unknown capacitor’s capacitance using a resistor, function generator, and a scope.
II. Using MATLAB Simulink create a new model and add two sine wave source blocks, a
sum block to add both sine waves, a first order transfer function, and a scope to monitor
both inputs and outputs of the transfer function using a MUX block as follows:
Set the frequency parameters of the “Source Wave 1” and “Source Wave 2” to 5 rad/sec
and 1000 rad/sec, respectively. Also the amplitude of “Source Wave 2” is set to 0.2 while
leaving that of the first source to be 1. For both sources, the sample time is set to 0.0001.
The simulation stop time is set to 5 sec and the frequency response of the RC model is
1
supposed to be: H ( j ) 
. Run the simulation and look at your output wave
j (0.01)  1
displayed by the scope. Explain your observations and the related reasons. Include the
scope output in your report. Make sure that the scope displays the output for the entire
time interval by unchecking the “Limit data points to last” checkbox in the “Data history”
tab of the “Scope parameters”.
III. Write a MATLAB program (in an m-file) to plot the theoretical “magnitude (in dB)” and
“phase (in radians)” of H(jω) of the RC filter determined above in part ‘I-c’ with respect
to ω in the range of [-500 500] rad/sec with the step-size of 5 rad/sec. Write your
program such that the output changes when the resistor and capacitor values alters.
a. Validate your plot with Figure 3.30 of the course textbook.
b. Modify your code to plot the frequency response magnitude in actual values (not in
dB). On the magnitude plot, find the theoretical magnitude at all the selected
frequencies within the range of 20 to 300 rad/sec (including ω=100 rad/sec as
mentioned in part ‘I-f’) and compare it with your results of part ‘I-f’. Tabulate your
comparisons and include the relative error (in percent) between the theoretical and
obtained values.
c. Plot the frequency response “magnitude” and “phase” given C=10μF and the same
resistor. Compare your plots with the previous results and explain your observations
and the related reasons.