You are on page 1of 5

Computer laboratory 2

Signals and Systems 2013-2014

January 7, 2014

1 Goal
Advanced problems related to Signals and systems are often too complex to solve by
hand. These problems can be solved using software like MATLAB. The goal of the next
two computer laboratories is to introduce you to MATLAB. In the first laboratory, you
will get familiar with the MATLAB-syntax and you will perform some simple mathematical operations. In the second laboratory, you will solve some problems related to
Signals and Systems using MATLAB.

2 Organization and Rules


Participation to both computer laboratories is necessary to pass the course Signals &
Systems. Both labs consist of a set of exercises that should be made during the computer
lab. At the end of the session, the answers are discussed with the teaching-assistant.
The assistant will assign the points not only based on the results you show
but also on your understanding of the answers. Therefore, in order to get
full points, you have to able to explain your results.
You are allowed to work and discuss the exercises in groups of two. To familiarize
yourself with the MATLAB-syntax, it is recommended to do all the exercises on your own
computer. It is important that you attend the session in which you enrolled
at Nestor to ensure that there are enough computers available!
The first session will be graded sufficient or insufficient. You are only allowed to
attend the second session if you made the first lab sufficient. If you cannot finish all the
exercises, you have to discuss with your teaching assistant how you can pass the lab.
The second lab will be graded. This grade will contribute for 10% to your final grade.

3 Tips and Tricks


If you dont understand how a command works, you can use the help. For example, if
you need help use the function abs() simply type

help abs

If you need some general information about MATLAB, type


1

help general

4 Exercises
1. In this exercise, you are going to use MATLAB to do a heart rate analysis from
an ECG. To measure the heart rate, we need to calculate the Fourier-transform
from this signal. To calculate the Fourier-transform, we can use the function
[w,F]=fouriertrans(t,f,N). This function can be found on Nestor. Use
help fouriertrans to get information on how to use this function.
Download the file signals.mat from Nestor and load this file into your workspace.
sig2 and sig3 are two ECG signals with a time domain given in sig1. The figure
below shows the result from plot(sig1,sig2) which shows an ECG.

a) Plot the signal sig2. Choose the period in such a way that the graph shows
three periods.
b) (2 points) Determine the heart rate that is measured in sig2 in two ways:
Count the number of R R intervals and determine the heart rate by
hand.
Determine the Fourier-transform from sig2. Use N = 218 . Plot the
Fourier-transform and determine the heart rate.
Conclude that the heart rate calculated from both methods is (approximately)
the same.

c) (1 point) The signal sig3 contains the heart rate from a pregnant women.
As a consequence, there are two hart rates present in this signal. Determine
the heart rate from the baby. You can assume that the baby has a heart rate
between 120 and 160 beats per minute.
2. Within MATLAB, we can analyse LTI-systems using their transferfunctions. For
example, we define a transferfunction
G(s) =

1
s2 + 3s + 1

(1)

We can define this function in matlab with


1
2

s=tf('s');
G=1/(s2+3*s+1);

%Define s as a transferfunction variable


%This is our transferfunction

To determine the impulse and step response we can use


1
2
3

impulse(G);
[h,t]=impulse(G);
step(G);

%Plot the impulse response from G


%Save the impulse reponse from G in a variable
%Plot the step response from G

If we want to plot the modulus and the argument for different frequencies we can
use
1
2

3
4

w=0:.1:10;
resp=freqresp(G,w);
domain w
plot(w,abs(resp(:)));
plot(w,angle(resp(:)));

%Define a random frequencydomain


%Determine the frequency response on the ...
%Plot the modulus from the frequency response
%Plot the argument from the frequency response

With the previous code we can analyse the LTI system. Next, we are going to
simulate the output from our system if we apply an input function.
1
2
3

t=0:.01:20;
%Define a time interval
u=exp(t)+sin(t*2)/5
%Define the input function
[y,tt]=lsim(G,u,t);
%Simulate and save our output function y ...
with timedomain tt. (lsim assumes that the initial system is in ...
rest)
plot(t,u,'r',tt,y,'b') %Plot the input and output in one graph

For this exercise, you are going to analyse a system with a transferfunction given
by
1

G(s) =
(2)
s2 + 3s + 2

a) (1 point) Plot the modulus values from the frequency response. How does
this system responds on input-signals with a high frequency? How does this
system responds on input-signals with a low frequency?
b) (1 point) Plot the argument values from the frequency response. How does
this systems shifts input-signals with a high frequency? How does this system
shifts input-signals with a low frequency?
c) (1 point) Simulate the output-signal y for an input u(t) = cos(3t) for t =
[0, 50]. Plot both u(t) and y(t) in one graph. Explain both the amplitudechange and the frequency-shift with the answers from a and b. Why is the
shift smaller than you would expect?
3. In this exercise we are going to use MATLAB to remove noise from a sound clip.
There are different types of filters available to remove noise. Often used filters are a
low-pass filter(only low frequencies can pass through), a high-pass filter (only high
frequencies can pass through) or a band-pass filter (only frequencies in a specific
domain cann pass through).
You can find the file vogel.mat on Nestor. This file contains the whispering of a
bird. Unfortunately, the clip also contains the low sound of a gong and an annoying
high beep. To listen to the clip, use the command
1
2
3
4

N=16384
load vogel.mat;
sound(vogeltje,N);
plot(tVogeltje,vogeltje);

a) Plot the Fourier-transform from vogel.mat. Which peaks are the result from
the bird, the beep and the gong?
A common used low-pass filter is the Butterworth filter. This filter is defined
by the transferfunction
G(s) =

1
( as + 1)(( as )2 +

s
a

+ 1)

(3)

With parameter a it is possible to tune the filter.


b) Use a modulus plot from the frequency response to explain why we call a
system defined by this transferfunction a low-pass filter. Use a = 100 and
w = 0 : 500.
c) (1 point) Use MATLAB to find a suitable value for a to remove the high
beep.
A high-pass filter can be defined by a system with trasferfunction
G(s) =

1
( sb

1)(( sb )2

b
s

+ 1)

(4)

d) Use a modulus plot from the frequency response to explain why we call a
system defined by this transferfunction a high-pass filter.
e) (1 point) Use MATLAB to find a suitable value for b to remove the low gong.
Because we only want to keep the sound of the bird, we need to remove both
the high and low frequencies. We can create this filter by multiplying both
transferfunctions.
f) (1 point) Create a filter that removes both high and low frequencies and plot
the frequency response.
g) (1 point) Simulate your new filter on the sound clip. You may need to apply
the filter multiple times. Plot the Fourier-transform from the filtered clip.

You might also like