Filter design
Consider a sinusoid constructed from summing a 30 Hz cosine and 60 Hz sine wave.
$$x(t) = \cos(2\pi30t) + \sin(2\pi60t)$$
We are going to filter this signal using a 60 Hz notch filter to eliminate the higher frequency content.
We will do this three different ways:
Using transfer function models
In Simulink
Using the filter design app
Transfer function approach
Recall the transfer function given in Exam 2.
$$G(s) = \dfrac{s^2+3600}{s^2+120s+3600}$$
Follow these steps in MATLAB
Construct $x(t)$ above in MATLAB using a time vector of frequency 1 kHz and running from 0 to 0.5 seconds.
Create the above transfer function in MATLAB using the
tf
command.Convert this continuous time model to a discrete time model using the
c2d
command; be sure to specify the correct sampling timeTs
. The transfer function is for rad/s while in discrete time MATLAB uses Hz.Extract the numerator and denominator coefficients from the converted model and pass those to the
filtfilt
command to filterx
. Call this outputy
.Plot both
x
andy
on the same graph.
Here is some starter code:
t = ___;
x = ___;
gain = 1;
p7num = gain* ___;
p7den = ___;
p7tf = tf(p7num, p7den);
dt_tf = c2d(p7tf, ___);
y = filtfilt(dt_tf.Numerator{:}, dt_tf.Denominator{:}, ___);
.
.
.
Questions:
How can we get the output to be similar in magnitude to the input?
Does the output seem time shifted? How could we take care of this?
Look up the
grpdelay
command. It might be useful for your project.
Simulink approach
Perform the same exercise in Simulink. Here is a starter diagram:

Remember ...
Phase shift the sine block to get a cosine wave.
Sine block is in rad/s
The square box above is a gain slider. You can use a standard gain.
You would need to modify the scope block to increase number of accepted inputs; but you probbaly want to output the variable to MATLAB workspace for making subplots.
Use the filter design app
This section requires the use of the Signal Processing Toolbox. To start the filter designer tool run filterDesigner
command from the MATLAB command window.
>> filterDesigner
Then, create a filter with the following specifications:

Next
From the
File
menu export this filter as a MATLAB function (give an appropriate name of your choosing). Save it as a.m
file.Call this function to create a
1x1 df2
filter object in your MATLAB workspace.Use the created filter object from your Workspace to filter your
x
variable and save the result toy
. For this use our old friend thefilter
command (see: the Tips section).Plot both of them on the same figure as before.
Compare the outputs of the first method and this one. What is different?
To turn in ...
Generate a single figure with three subplots consisting of figures from each of the three methods above. For example
subplot(1, 3, 1)
.
.
.
title("Output using TF method")
.
.
subplot(1, 3, 3)
.
.
title("Output from filter designer")
Answer questions above.