0% found this document useful (0 votes)
78 views

Laboratories ELG 3125A Fall 2017: School of Electrical Engineering and Computer Science

The document provides information about the ELG 3125 Fall 2017 laboratories at the University of Ottawa. It outlines 10 labs that cover topics such as displaying and manipulating signals, sinusoidal signals, linear time-invariant systems, Fourier series, frequency content of signals, filtering, and transfer functions. The labs involve both simulation and analysis using MATLAB. Students complete lab reports and demos to be evaluated.

Uploaded by

LIGHT
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
78 views

Laboratories ELG 3125A Fall 2017: School of Electrical Engineering and Computer Science

The document provides information about the ELG 3125 Fall 2017 laboratories at the University of Ottawa. It outlines 10 labs that cover topics such as displaying and manipulating signals, sinusoidal signals, linear time-invariant systems, Fourier series, frequency content of signals, filtering, and transfer functions. The labs involve both simulation and analysis using MATLAB. Students complete lab reports and demos to be evaluated.

Uploaded by

LIGHT
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

UNIVERSITY OF OTTAWA

School of Electrical Engineering and Computer Science

Laboratories ELG 3125A

Fall 2017
SCHOOL OF ELECTRICAL ENGINEERING AND COMPUTER SCIENCE

Laboratories ELG 3125 Fall 2017

 Martin Bouchard, University of Ottawa


800 King Edward, Ottawa, Canada
Table of contents
Information regarding the laboratories 4 

Lab 1 Displaying and manipulating signals 6 

Lab 2 Sinusoidal signals, complex exponentials, and manipulation of audio signals 8 

Lab 3 LTI systems described by differential equations, difference equations, and convolution sums 11 

Lab 4 Combination of LTI systems 13 

Lab 5 Fourier series: synthesis of a triangular wave 15 

Lab 6 Frequency content of continuous time signals, frequency response of continuous time LTI systems, and

amplitude modulation 17 

Lab 7 Frequency content of discrete time signals, frequency response of discrete time LTI systems, and frequency

selective filtering 20 

Lab 8 A filtering application: signal de-noising 23 

Lab 9 First and second order systems, in continuous time and in discrete time 25 

Lab 10 Transfer functions of continuous time LTI systems 27 


Information

Information regarding the laboratories

Lab reports
Lab reports are to be handed in through the VirtualCampus environment. A penalty of 20% per day is applicable
for late reports.

Each lab report should contain:

• for each question or item found in the lab description:

o a brief description of what you are requested to do, and (when applicable) a brief analysis of the
results

o figures of results (with appropriate titles, axis, scales, etc. for the figures)

• an appendix with a printed version of your Matlab source code (if necessary, a teaching assistant (TA)
can contact you to obtain a softcopy of your code)

Cases of plagiarism can be reported to the faculty and can be subject to sanctions sometimes affecting more than
just this course.

Demos
During each lab session, a TA will request teams to run the code of the previous laboratory and show the results.
During the demo, the TA will ask questions about the previous laboratory and the results.

Evaluation
For each lab, the relative weight of the lab report will be the same as the relative weight of the lab demo. Also,
each lab will be given the same weight overall.

Teams
The labs (demos, reports) are to be produced by teams of two students, and teams of one student can be accepted
only on an exceptional basis.

4
Matlab tutorials
The first labs are fairly simple and allow the students to become familiar with the use of Matlab for signal
processing. Moreover, the first lab session will be used to cover some parts of the following Matlab tutorial:

Introduction to Matlab, by R. Youmaran and M. Bouchard (available from the VirtualCampus environment)

There are also other Matlab tutorials available, here are a few:

Tutorial by Sigmon
http://www.math.toronto.edu/mpugh/primer.pdf
http://web.mit.edu/6.777/www/downloads/primer.pdf

Tutorial by Bonnie Heck


http://users.ece.gatech.edu/~bonnie/book/TUTORIAL/tutorial.pdf

and several other tutorials can be found on the web.

There are also several books available on this topic, such as:

"Introduction to Matlab 7", D. Etter, D. Kuncicky, H. Moore, Prentice Hall, 2004

"Concise Introduction to Matlab", W.J. Palm, McGraw-Hill, 2008

5
1
Lab

Lab 1 Displaying and manipulating signals

The objective of this lab is essentially to become familiar with the Matlab environment, to learn to properly display
signals in Matlab, and to learn to manipulate and combine signals in Matlab.

Displaying signals
In this part you will need to:

 generate continuous time signals, for example:


dt=0.001; % small time increment, simulates a continuous time signal
t=0:dt:10; % duration of signal, continuous time
f0=1; % frequency of a sine signal, in Hz (cycles/sec.)
x=sin(2*pi*f0*t); % generation of the sine signal, in continuous time

 generate discrete time signals, for example:


n=0:1:100; % duration of signal, discrete time
f0=0.05; % frequency of a sine signal, in cycles/sample
x=sin(2*pi*f0*n); % generation of the sine signal, in discrete time

 display the different signals with the compulsory use of the following functions: figure, grid, title, xlabel,
ylabel, hold, legend, subplot, plot (for continuous time signals), and stem (for discrete time signals). In particular
you need to show that you know how to:

o plot several figures in the same window

o plot several signals (or curves) in the same figure, each signal with a different color and a different
style.

For each function (ex. grid, title, etc.), you can either consult the Matlab help, or simply type "help function_name"
in the Matlab command window to obtain a text version of the help corresponding to the function..

6
Manipulation and combination of signals
The addition of two signals of the same length is very simple in Matlab, for example if the values of the signals
x1[n ] and x2 [n ] are found in vectors x1 and x2, the signals can be added by:

y=x1+x2;

A right-shift operation is also easy to simulate in Matlab, by inserting zeros at the start of the signal. For example,
to produce x1[n ]  x[n  5] from x[n ] , the following can be done:

x1=[zeros(1,5),x];

You need to generate the signal y[ n]  x1[ n]  x2 [ n  80] 0  n  160 with x1[n]  sin(2 0.1 n) 0  n  160 and
x2 [ n]  sin(2 0.2 n) 0  n  160 . Display the resulting signal. Note: the insertion of zeros to generate x2 [ n  80] will
make the resulting signal longer, and you will need to truncate it (at the end) to keep only the interval 0  n  160
.

Note also that the function size displays the size of a variable in Matlab, and it allows to explain and understand
several problems that can occur when Matlab refuses to perform the requested operations because of conflicts
in the dimensions of the variables.

7
2
Lab

Lab 2 Sinusoidal signals, complex exponentials, and


manipulation of audio signals

The objectives of this lab are to learn to read, listen to, and write audio files from Matlab, and to experiment with
the properties of sinusoidal signals and complex exponentials in continuous time and discrete time.

Reading and writing audio files


Using the function audioread and audiowrite, it is possible to read and write audio files using the non-compressed
WAV format (linear PCM format, such as in a classical audio CDs). The function sound also allows to listen to a
signal directly from Matlab. Note also that a WAV file can also of course be played using audio applications such
as Windows MediaPlayer, WinAmp, etc.

Note: please bring headphones to the lab (e.g. MP3 player headphones) to avoid disturbing the class when playing
a sound file.

In the section, you have to:

 with the function sound, listen in Matlab to the signal y[ n]  sin(2 0.1 n)  sin(2 0.2 n ) 0  n  16000 . Use
a sampling rate of 8000 samples/sec. Warning: if the signal has amplitudes greater than 1.0 or lower than
-1.0, it needs to be multiplied (or scaled) by a factor so that the resulting signal has an amplitude between
-1.0 and 1.0. Otherwise the signal will be clipped, i.e. amplitude values outside of the range -1.0 to 1.0 will
have a clipped or saturated value of -1.0 or 1.0, and of course this changes the sound of the signal to be
played (added distortion).

 write the y[n] signal to a WAV file. Use a sampling rate of 8000 samples/sec. As in the previous
paragraph, it is necessary here that the amplitude of the signal be found in the interval -1.0 to 1.0 to avoid
a saturation effect and added distortion.

 read in Matlab the WAV file generated in the previous step. The read signal will be called z[ n ] .

 verify by displaying and listening to z[ n ] that it is indeed the same as the original signal (except for a
possible scale factor).

8
Sinusoidal signals and periodicity
By generating sinusoidal signals, for example as in Lab #1, illustrate and verify the following properties by
displaying the result:

1. sinusoidal signals sin(0t ) in continuous time are always periodic, whether the angular frequency 0 (in
rad./sec.) is a fraction of  , an integer, or some irrational number (ex. 2 ). Also, the resulting period is
2
always T  .
0

2. sinusoidal signals sin(0 n ) in discrete time are not always periodic, they are periodic only if 0 has the
m
form 0  2 where m and N are integers without common factors. In that case, the resulting period
N
2
is not N  as in continuous time, the resulting period is instead N .
0

3. as opposed to sinusoidal signals sin(0 t ) in continuous time, there are periodic sinusoidal signals sin(0 n )
m
in discrete time (with 0  2 , m and N integers) which have the same period but are distinct, for
N
example using different values of m and a constant value for N

4. as opposed to sinusoidal signals sin(0 t ) in continuous time, for sinusoidal signals sin(0 n ) in discrete
time if we add a multiple of 2 to the angular frequency 0 , we obtain the same resulting signal

5. this also means that as opposed to sinusoidal signals sin(0 t ) in continuous time, for sinusoidal signals
sin(0 n ) in discrete time, if we increase the angular frequency 0 this will not necessarily reduce the
resulting period N (if the signal is periodic), or this will not necessarily increase the rate of oscillations in
the signal (if the signal is not periodic). In fact, in discrete time, frequencies 0 near  are the "high
frequencies", i.e. the ones generating the fastest changes in the signal, and frequencies 0 near 0 are the
"low frequencies", i.e. the ones generating the slowest changes in the signal.

6. adding two periodic sinusoidal signals in continuous time or in discrete time will produce a resulting
sinusoidal signal whose resulting period will be the lowest common multiple (LCM) of the two original
periods.

7. but when the two original periods have no LCM (no common multiple, except at infinity), then the
resulting signal will not be periodic ! (or we can say that the resulting period is infinite, which is
mathematically equivalent)

8. in discrete time, adding a periodic sinusoidal signal with a non-periodic sinusoidal signal will produce a
non-periodic sinusoidal signal

9
Complex exponential signals
For signals like sin(0t ) or cos(0t ) , the concept of a negative frequency is not too useful, since a negative
frequency can always be converted to a positive frequency: sin( 0t )   sin(0t ) , cos( 0t )  cos(0t ) . However,
in the case of complex exponential signals e j0t (or e j0 n in discrete time), negative frequencies lead to distinct
signals. To visualize this and illustrate the difference between a positive frequency and a negative frequency for a
signal e j0t , you can use code based on the following:
dt=0.01;
t = 0:dt:3;
f0=1; % frequency in Hz
z=exp(j*2*pi*f0*t);
plot3(t,real(z),imag(z));
view(+37.5,30);
grid on;
xlabel('sec');

 Compare the difference between a positive frequency and a negative frequency in the signal e j0t

 Verify that the real part of e j0t leads to cos(0t ) and that the imaginary part of e j0t leads to sin(0t )

10
3
Lab

Lab 3 LTI systems described by differential equations,


difference equations, and convolution sums

The objective of this laboratory is to learn to simulate LTI systems in continuous time and discrete time,
represented by differential equations, difference equations, or impulse responses.

Differential equations with constant coefficients


Several continuous time LTI systems are represented or modeled by a differential equation with constant
coefficients.

For the following continuous time LTI system:

d 2 y (t ) dy (t )
5  6 y (t )  x (t ) system initially at rest
dt 2 dt

1. find and plot using Matlab the impulse response h(t ) of the system, using the function impulse(b,a,t) where
b and a correspond to the coefficients in the differential equation (i.e. b=[0 0 1] and a=[ 1, 5, 6]). Compare
your result with the theoretical result (by also plotting the theoretical result).

2. For an input signal defined as:

 
x (t )  1  e 3t u(t )

compute the output y(t ) of that system, using the function lsim(b,a,x,t). Use a time range long enough
to see the y(t ) signal stabilize.

Difference equation with constant coefficients

Several discrete time LTI systems are represented or modeled by a difference equation with constant coefficients.

For the following discrete time LTI system:

11
5 1
y n  y  n  1  y  n  2  x n  system initially at rest
6 6

1. find and plot using Matlab the impulse response h[n ] of the system, using the function impz(b,a,n), where
b and a correspond to the coefficients in the difference equation (i.e. b=[1 0 0] and a=[ 1, -5/6, 1/6]).
Compare your result with the theoretical result (by also plotting the theoretical result).

2. For an input signal defined as:

 
x[n ]  1  (0.9) n u[n ]

compute the output y[n] of that system, using the function filter. Use a time range long enough to
see the y[n] signal stabilize.

Computation of a convolution sum


First obtain a discrete time input signal x[n ] by reading the file "Audio1.wav" from the course's web site. This
signal has a duration (length) of 190912 samples, with a sampling frequency of 16000 samples/sec. Visualize the
resulting signal and listen to it.

It is required to compute the convolution sum between this signal x[ n ] and the following impulse response h[ n ]
:

h[n ]  0.1   0.99 


n
0  n  1000


In other words, we are looking for the output y n   x n  * h n    h[k ]x[n  k ] when the discrete time LTI
k 
system described by the impulse response h[ n ] has x[ n ] as its input signal.

1. From the size of x[ n ] and h[ n ] , what will be the size of y[n] ?

2. Use the function conv to compute y[n] . Observe the size of the result y[n] , plot the result y[n] and
listen to the result y[n] . What do you observe when directly comparing with x[n ] ? Does it sound
different ? The discrete time LTI system described by h[n ] performs some filtering effect on the original
signal x[n ] . A lot more effects or filtering types are possible, depending on h[n ] . We will come back to
this later in the course.

3. Now use the function filter to compute y[n] , where the parameter b in the function filter corresponds to
h[ n ] and the parameter a is set to 1.0. Like the function conv, the function filter also computes the result
of a discrete time convolution in this case, but not over the same interval of output y[n] values. Explain
the difference.

12
4
Lab

Lab 4 Combination of LTI systems

The objective of this lab is to experiment with some notions of LTI systems and impulse responses.

Equivalent impulse response


A LTI discrete-time system has an input x[n ] and an output y[n] :

5 1
y n  y  n  1  y  n  2  x n  system initially at rest
6 6

The output y[n] of this first system then becomes the input of a second system:

9 1
z n  z  n  1  z  n  2  y  n  system initially at rest
20 20

Compute and display the impulse response of the equivalent system between x[n ] and z[n ] .

LTI systems stability


Show by experiment if the following LTI systems are stable or not:

d 2 y (t ) dy (t )
2
5  4 y (t )  x (t ) system initially at rest
dt dt

d 2 y (t ) dy (t )
2
5  4 y (t )  x (t ) system initially at rest
dt dt

1
y n  y  n  2  x  n  system initially at rest
4

3
y n   y n  1  y  n  2  x  n  system initially at rest
2

Note: This can be achieved through the impulse responses and/or by applying input signals to the different
systems.

13
Inverse systems
Show by experiment which of the systems listed below (a, b, or c) is the inverse of the following LTI discrete
time system:

5 1
y n  y  n  1  y  n  2  x n  system initially at rest
6 6

1 5
a) y n   x n   x n  1  x n  2 system initially at rest
6 6

5 1
b) y n   x n   x n  1  x n  2 system initially at rest
6 6

1 5
c) y  n   y  n  1  y  n  2  x  n  system initially at rest
6 6

Note: it is suggested to use the impulse responses to achieve this.

In addition, show theoretically (using the frequency response) that the chosen inverse system is indeed the inverse
of the LTI system.

Verification of an inverse system with an audio signal


In the previous lab, the file "Audio1.wav" was applied to a discrete time LTI system whose impulse response was
given by:

h[n ]  0.1   0.99 


n
0  n  1000

Now, the following system is the inverse of that previous system:

99
y  n   10 x  n   x n  1 system initially at rest
10

Verify this

- using the impulse responses of the two systems

- by applying the output of the first system (as obtained in the previous lab) to the input of the inverse system.
The output of the inverse system should then be quasi-identical to the original signal in "Audio1.wav". Visualize
the resulting signals and listen to the resulting signals.

14
5
Lab

Lab 5 Fourier series: synthesis of a triangular wave

The main objective of this lab is to become more familiar with the meaning of the Fourier series coefficients and
some of their properties.

Continuous time Fourier series


For the following continuous time triangular wave periodic signal, shown below over an interval a bit larger than
one period:

the coefficients of the Fourier series are:

2 sin( k / 2)  jk /2
ak  e k 0
j ( k ) 2
1
a0 
2

The synthesis or reconstruction of signal x(t ) from a sum of complex exponentials (or from cosines) weighted
by the Fourier series coefficients can be written by:
 
x (t )   ak e jk0t  a0  2 ak cos  k0t  ak  .
k  k 1

15
If instead of using an infinite amount of terms, the summation is truncated to N a terms (with N a odd
here), we then obtain the following approximation:

( N a 1) 2 ( N a 1) 2
x (t )  xˆ (t )   ak e jk0t  a0  2  ak cos  k0t  ak 
k  ( N a 1) 2 k 1

Write a Matlab script which allows to visualize the approximation xˆ (t ) obtained for N a  7 , N a  21 ,
N a  201 , i.e. as a growing but finite number of complex exponentials (or cosines) are used. Your
observations should allow to verify that it is only for N a   that the synthesized signal would become
completely equal to the signal x(t ) .

Discrete time Fourier series


For the following discrete time triangular wave periodic signal, shown below over the interval 7  n  7 :

the Fourier series coefficients are:

a0  0.5, a1  a1  -0.20944, a2  a2  0, a3  a 3  -0.03056, a4  a4  0, a5  -0.02

For the discrete time Fourier series, the coefficients are periodic (with period N  10 here). The synthesis or
reconstruction of signal x[n ] from a sum of complex exponentials (or cosines) weighted by the coefficients of
the Fourier series can be written as:
2 5 2 9 2
jk n jk n jk n
x[n ]   ak e N   ak e 10   ak e 10 .
k  N  k 4 k 0

Write a Matlab script which allows to perform a synthesis of x[n ] from the sum of complex exponential signals,
and verify that unlike in the previous case (for continuous time Fourier series coefficients) here it is not required
to use an infinite amount of exponentials, i.e. N  10 exponentials are enough.

16
6
Lab

Lab 6 Frequency content of continuous time signals, frequency


response of continuous time LTI systems, and amplitude
modulation

The objectives of this lab are to show how to find the frequency content of continuous time signals, to show
how to compute the frequency response of a continuous time LTI system described by a differential equation,
and to illustrate the effect of amplitude modulation.

Frequency content of a continuous time signal


For a given continuous time signal x(t ) found in the interval 0  t  T (for example a measured signal), it is
possible to approximately compute the frequency content (i.e. the continuous time Fourier transform X ( j) ) at
some specific frequencies, by making use again of the Matlab function fft(x), where x corresponds to values of
x(t ) sampled over the interval 0  t  T . It is sometimes only an approximation because the signal x(t ) is
represented by its samples in Matlab (or in any digital system), and in some cases the samples of x(t ) can not
preserve all the information found in the continuous time signal x(t ) (this is related to the sampling theorem,
also to be covered in this course).

The following code allows to visualize the frequency content of a continuous time signal x(t ) in the interval
0  t  T , whose samples are in vector x:

% code, Fourier transform, for x(t) duration T sec., samples spaced by "dt"
Xw=fft(x,max(1001,length(x)))*dt; % minimum of 1001 values computed,
% to provide impression of continuous transform
Xw =fftshift(Xw);
Nfft=length(Xw);
k=-(Nfft-1)/2:1:(Nfft-1)/2; % with Nfft assumed odd here in this code
w=k*2*pi/Nfft/dt;
figure(1)
subplot(2,1,1)
plot(w,abs(Xw));
title('magnitude Fourier transf.')
xlabel('rad./sec.')
subplot(2,1,2)
plot(w,angle(Xw));
title('phase Fourier transf.')
xlabel('rad./sec.')

17
sin 0  t  5  
To verify the use of this code, build the signal x (t )  with 0  5 rad./sec. and 0  t  10 , for
  t  5
example with the following code:
dt=0.05;
t=0:dt:10;
wo=5;
x=sinc((wo/pi)*(t-5))*(wo/pi); % = sin(wo(t-5))/(pi*(t-5))

Verify that the code from the previous page produces a result corresponding to the Fourier transform of x(t ) .
In the Fourier transform shown, why are there ripples and why is the transition not instantaneous ? (hint: this is
not due to the code or to the use of the function fft).

Frequency response of a continuous time LTI system described by a differential equation


The frequency response of a continuous time LTI system described by a differential equation with constant
coefficients can be computed in Matlab with the function [h,w]=freqs(b,a).

Consider the following differential equation:

d 3 y (t ) d 2 y (t ) dy (t )
a3 3
 a2 2
 a1  a0 y (t )  b0 x(t ) initially at rest
dt dt dt

with the following values:

b0  121868727358.1180

a3  1 a2  6209.9310 a1  48890434.5196 a0  121868727358.1180

Plotting the result of the function freqs, verify that this differential equation corresponds to a low-pass filter, with
a cutoff frequency of 1 kHz.

Amplitude modulation
Now knowing how to compute the frequency content of a continuous time signal (of finite length) and knowing
how to compute the frequency response of a continuous time LTI system, it becomes simple to illustrate (and
listen to) the concept of amplitude modulation (AM modulation).

In this section you are requested to:

 read and listen to the file "Audio1_LP.wav" available from the course's web site. This file come from a
continuous time signal that was sampled at 16000 samples/sec. Consider the signal read in
"Audio1_LP.wav" as a continuous time signal x(t ) (in its sampled version, with a spacing dt = 1/16 kHz
between samples). Plot the Fourier transform of x(t ) ( X ( j) ), with the appropriate scales.

 perform an amplitude modulation by multiplying the signal x(t ) with a carrier having a frequency of 4
kHz. Use the same dt and the same length as x(t ) for the carrier signal. The result is the modulated signal
y(t ) . You must listen to the modulated signal y(t ) and plot its Fourier transform.

18
 perform a coherent demodulation by multiplying the modulated signal y(t ) with the same carrier signal
at 4 kHz (with the same phase), and then by applying the low-pass filter with 1kHz cutoff frequency
presented in a previous section. To perform the continuous time filtering, the function out=lsim(b,a,in,t)
should be used (and not the functions filter or conv). The resulting demodulated signal is z(t ) . You must
listen to the demodulated signal z(t ) and plot its Fourier transform. Compare the signal z(t ) with the
original x(t ) signal.

19
7
Lab

Lab 7 Frequency content of discrete time signals, frequency


response of discrete time LTI systems, and frequency selective
filtering

The objectives of this lab are to show how to compute the frequency content of discrete time signals (periodic
and non periodic), to show how to compute the frequency response of discrete time LTI systems described by
difference equations, and to illustrate the effect of a frequency selective filtering.

Frequency content of a periodic discrete time signal


For a periodic discrete time signal, where the values of x[n ] 0  n  N  1 are known over a period, it is possible
to compute numerically the frequency content (i.e. in this case the Fourier series coefficients) with the Matlab
function fft(x), where x corresponds to the values of x[n ] over one period. The function fft uses a fast Fourier
Transform, whose theory will not be covered in the course ELG 3125.

The following code allows to visualize the frequency content of a signal x[ n ] whose values are in vector x:

%code, Fourier series for x[n] with period N


N=length(x);
ak=1/N*fft(x);
ak=fftshift(ak);
k=-(N-1)/2:1:(N-1)/2; % N odd assumed here in this code
w=k*2*pi/N;
figure(1)
subplot(2,1,1)
stem(w,abs(ak));
title('magnitude ak coeffs.')
xlabel('rad./sample')
subplot(2,1,2)
stem(w,angle(ak));
title('phase ak coeffs.')
xlabel('rad/sample')

Build a signal x[n ] of length 21 samples with slow variations in it and another signal x[n ] of length 21 samples
but having fast variations in it. Observe the frequency content (in particular the magnitude of the Fourier series
coefficients) in each case. Verify that slow variations in the signal correspond to low frequency content, and that
fast variations in the signal correspond to high frequency content.

20
Frequency content of a non-periodic discrete time signal
The case of a non-periodic discrete time signal will now be considered. It is the most common case in practice
for digital signal processing. For non-periodic signals having a finite duration (or length) in the interval
0  n  N  1 (for example it could be a measured signal), it is possible to evaluate the discrete time Fourier
transform X (e j ) at some frequencies by using again the Matlab function fft. In this case, the code becomes:

%code for Fourier transform, x[n] non-periodic


Xw=fft(x,max(1001,length(x))); % minimum of 1001 values computed,
% to provide impression of continuous transform
Xw=fftshift(Xw);
Nfft=length(Xw);
k=-(Nfft-1)/2:1:(Nfft-1)/2; % with Nfft odd here in this code
w=k*2*pi/Nfft;
figure(1)
subplot(2,1,1)
plot(w,abs(Xw));
title('magnitude Fourier transf.')
xlabel('rad./sample')
subplot(2,1,2)
plot(w,angle(Xw));
title('phase Fourier transf.')
xlabel('rad./sample')

Use the signals of length 21 from the previous section (the previous cases with slow variations in one signal and
fast variations in the other signal). But this time consider the signals as being finite length non-periodic signals,
and observe their frequency content (in particular the magnitude of the Fourier transform) with the code above.
What are the similarities and the differences, compared to what you had observed in the previous sections ?

Frequency response of discrete time LTI systems described by a difference equation


The frequency response of the discrete time LTI system described by a difference equation with constant
coefficients can be computed in Matlab with the function [h,w]=freqz(b,a); . With these new tools (this one and
the one from the previous section), let's revisit the case of the audio file "Audio1.wav" which was applied to the
input of a discrete time LTI system whose impulse response is given by:

h[n ]  0.1   0.99 


n
0  n  1000

In terms of difference equations, it could be shown that this system with h[n ] is equivalent to the following:

y n   0.99 y  n  1  0.1x n  system initially at rest

The only difference is that the impulse response of the difference equation theoretically goes from 0  n   , and
not from 0  n  1000 , but from a practical perspective they are the same because h[n ] has a fast decay.

In this section, you are asked to revisit the case where the audio signal from the file "Audio1.wav" was applied at
the input of the system with impulse response h[n ] , but this time observing the frequency behavior of the signals
and the system. This will allow to show clearly that the system with impulse response h[n ] is in fact a frequency
selective filter. Therefore you must:

21
 show the frequency content of the input signal (file "Audio1.wav", with the approach described for non-
periodic discrete time signals)

 show the frequency response of the system described by the difference equation

 show the frequency content of the signal at the output of the system (again using the approach described
for non-periodic discrete time signals).

Observing the frequency content of signals is a lot more intuitive than comparing the time domain signals,
partially because in the frequency domain the output of the system is simply the product of the input and the
frequency response of the system: Y (e j )  X (e j ) H (e j ) . What type of filter is H (e j ) ?

22
8
Lab

Lab 8 A filtering application: signal de-noising


The objective of this lab is to illustrate frequency selective filtering for a de-noising application: interference
reduction in an audio signal.

A noisy audio signal was obtained by adding two types of noise to an original audio signal. To illustrate this clearly,
we can compare the frequency content of the audio signal before and after the addition of noise. The following
figure shows the frequency content (Fourier transform magnitude) of the original audio signal, with no noise:

The following figure then shows the frequency content of the noisy signal:

Comparing the two previous signals, the two different types of added noise can be clearly seen:

23
 a "tonal" noise (pure sinusoid) added approximately at frequency   0.22 (and   0.22 ) rad./sample

 a "narrowband" noise added approximately between frequencies 1.9    2.2 (and 2.2    1.9 )
rad./sample.

The resulting noisy file is available on the course's web site: "noisy_audio.wav". It is an audio file sampled at
16000 samples/sec. In this audio file, the effect of each added noise is clearly audible, and the original audio signal
is also audible.

In this lab, you have to design two stopband filters to eliminate the frequency content where the noise is located.
Doing this, we will also lose the original audio content at those frequencies, but this is not critical since it only
represents a fraction of the original audio content. In other words, after applying your filters to the noisy signal,
you could for example obtain a de-noised signal with a frequency content that would look like this:

For the design of stopband filters, there are several options possible, but in this lab the use of the Matlab function
ellip should be enough.

Verify that you succeed in removing the noise, by observing the resulting frequency content after filtering, and
by listening to the resulting file.

24
9
Lab

Lab 9 First and second order systems, in continuous time and in


discrete time

The objective of this lab is to become familiar with characteristics of first and second order continuous time and
discrete time systems, by verifying several basic concepts.

First order continuous time system


dy (t )
For the following causal first order continuous time system:   y (t )  x (t )  0
dt
 with the frequency response, verify that it is a low pass filter with a cutoff frequency (-3dB) at
c  1
 verify (graphically) the approximation of the frequency response (amplitude in dB and phase) by
straight lines
 verify if there are oscillations in the impulse response h(t ) and the step response s(t ) ( s(t ) can be
obtained by the function step(b,a))
 in terms of rise time:
o verify the effect of the time constant  on the impulse response h(t )
o verify the effect of the time constant  on the step response s(t )

Second order continuous time system


For the following causal second order continuous time system:
d 2 y (t ) dy (t )
2
 2n  n 2 y (t )  n 2 x (t )  0 n  0
dt dt

 with the frequency response, verify that this is a low pass filter with a cutoff frequency (-3dB) at n
(approximately)
 verify (graphically) the approximation of the frequency response (amplitude in dB and phase) by
straight lines
 verify the resonance phenomenon (i.e. gain greater than 0dB) that occurs in the frequency response
(magnitude) when   1  0.707
2
 verify if there are oscillations in the impulse response h(t ) and in the step response s(t ) .
 in terms of overshoot and stabilization time:

25
o verify the effect of the natural frequency n and the damping factor  on the impulse
response h(t ) . Consider the under-damping, over-damping, and critical damping cases.
o verify the effect of the natural frequency n and the damping factor  on the step response
s(t ) . Consider the under-damping, over-damping, and critical damping cases.

First order discrete time system


For the causal first order discrete time system: y  n   ay  n  1  x  n  1  a  1
 in the impulse response h[n ] , what happens if a  1 ? What is the consequence of this ?
 in the frequency response, verify that the system with 1  a  1 can be either a low-pass filter or a
high-pass filter. Describe the effect of a .
 verify if there are oscillations or sign changes observed in the impulse response h[n ] and in the step
response s[n ] ( s[n ] can be obtained by the function stepz(b,a)). If so, under which conditions do
oscillations occur ?
 in terms of rise time:
o verify the effect of a on the impulse response h[n ]
o verify the effect of a on the step response s[n ]

Second order discrete time system


For the causal second order discrete time system:
y n  2r cos y n  1  r 2 y n  2  x n 0 r 1 0  
 in the impulse response h[n ] , what happens if r  1 ? What is the consequence of this ? What
happens if r  1 ?
 in the frequency response, verify that the system with 0  r  1 behaves like a resonator, i.e. a
bandpass filter of order 2. Verify the effect of  and r .
 verify if there are oscillations or sign changes observed in the impulse response h[n ] and in the step
response s[n ]
 in terms of overshoot and stabilization time:
o verify the effect of  and r on the impulse response h[n ]
o verify the effect of  and r on the step response s[n ]

26
10
Lab

Lab 10 Transfer functions of continuous time LTI systems

The objective of this lab is to become more familiar with the concept of transfer functions for continuous time
LTI systems.

Region of convergence and Matlab functions


Transfer functions are often described in terms of poles and zeros. For a continuous time LTI system described
by the transfer function:

bM s M  bM 1s M 1    b1s  b0
H ( s) 
a N s N  a N 1s N 1    a1s  a0

we have M zeroes and N poles.

1 1
For the following system with 2 poles and no zero: H ( s)  
( s  1)( s  2) s 2  s  2

 use the function zplane to plot the zeros and the poles of H ( s) . The function zplane shows the zeros and
the poles in the s-plane. Note that the function roots also allows to compute the roots of a polynomial
(e.g. numerator or denominator of H ( s) ), when required.

1 1
 theoretically, how many ROC are there corresponding to H ( s )   2 ? From those
( s  1)( s  2) s  s  2
ROCs, how many are for stable systems ? From those ROCs, how many are for causal systems ?

 use the function impulse(b,a,0:0.01:10) to find the impulse response h(t ) corresponding to H ( s) . Is the
system described by impulse(b,a,0:0.01:10) stable ? Is it causal ? From the different ROCs of H ( s) , what
can be concluded regarding which ROC is considered by the function impulse?

 use the function freqs(b,a) to find the frequency response H ( j) corresponding to H ( s) . Is the system
described by freqs(b,a) stable (by definition) ? From the different ROCs of H ( s) , what can be concluded
regarding which ROC is considered by the function freqs?

27
Effect of poles on time response
For a transfer function and a ROC corresponding to a causal and stable system H ( s) (poles in the left half-plane
in the s-plane, and ROC to the right of all poles), the position of the poles has a direct effect on the overshoot,
the rise time and/or the stabilization time in h(t ) and s(t ) . To illustrate this, consider the second order causal
and stable following system described by two complex conjugate poles p    j and p*    j (   0 ,   0
):

( 2   2 ) ( 2   2 )
H ( s)   ROC : Re s  
( s  p )( s  p * ) s 2  2 s  ( 2   2 )

Observe and describe the effect of the pole position (for different values of  and  ) in terms of overshoot,
stabilization time and/or rise time in the impulse response h(t ) and the step response s(t ) of H ( s) . Describe
also the effect of the pole position (  and  ) on the frequency response H ( j) (magnitude).

Side comment: Does the position of the zeroes (when there are some) also have an effect on the overshoot, the
rise time and/or the stabilization time ? One way to look at it is to consider the partial fractions expansion of
H ( s) . The poles are not modified by this expansion and the previous reasoning regarding the poles still holds.
The zeroes have an effect on the coefficients of the partial fractions, in other words it is at the level of the
weighting of the different terms in the partial fractions expansion that the zeroes have an effect. By giving more
or less emphasis to different terms in the partial fractions, the zeroes can indirectly have an effect on the time
response (overshoot, rise time, stabilization time, etc.). But their effect is not as direct as the effect of the poles.

Classical analog filters: Butterworth, Chebyshev Type I and II, and elliptic
The following functions allow to design classical analog filters (with continuous time h(t ) impulse responses) of
the following types: Butterworth, Chebyshev I, Chebyshev II and elliptic. The functions below return the
coefficients of the transfer function H ( s) , for a filter order 8, with a cutoff frequency of 1 rad./sec., 1dB of
maximum ripple in the passband (when applicable), and 60 dB minimum of attenuation in the stopband (when
applicable):
[b,a]=butter(8,1,'s');
[b,a]=cheby1(8,1,1,'s');
[b,a]=cheby2(8,60,1,'s');
[b,a]=ellip(8,1,60,1,'s');

 Compare the position of the zeros and poles for the different types of filters.

 Compare the shape of the impulse response produced by the different types of filters (e.g. stabilization
time).

 Compare the shape of the frequency response (magnitude) produced by the different types of filters
(presence of ripple or not in the different bands, width of transition between passband and stopband).

Minimal phase systems and inversion of systems


For a LTI system H ( s) to be causal and stable, its poles have to be in the left half-plane of the s-plane, with a
ROC to the right of all poles. However, if it is desired to inverse the system H ( s) with an inverse system H I ( s )
which must also be causal and stable, then it is also required that the zeroes of H ( s) be in the left half-plane of
the s-plane. This is because of the fact that in the inverse system H I ( s ) , the zeros of H ( s) become poles, and

28
the poles of H ( s) become zeros, since H I ( s )  1 H ( s ) . Therefore the position of the zeroes of H ( s) becomes
critical if H ( s) is to be inverted. A causal and stable system H ( s) with all its zeroes in the left half-plane of the s-
plane is called a minimal phase system.

Determine which one of the 3 following systems H ( s) is a minimal phase system, and verify that it is the only
system which leads to an inverse system H I ( s ) which is causal and stable:

s 2  3s  2
H (s) 
s 2  3s  4

s 2  3s  2
H (s) 
s 2  3s  4

s 2  1s  2
H (s) 
s 2  3s  4

Note that looking at the frequency response with freqs we get the impression that all the inverse filters are fine
(i.e. causal and stable), but looking at the impulse response with impulse we clearly see that H I ( s ) is not always a
stable and causal system.

29

You might also like