MEC3015 2012 Filters Tutorial 1
MEC3015 2012 Filters Tutorial 1
FILTERS Tutorial #1
Sheet No.
SIMULINK modelling
Use SIMULINK to create a model of a first-order system. The
output save format of the workspace functions (output and time)
Pulse
Generator
should be changed from Structure to Array. The system time1
constant tau is a variable and should be initialised in the
tau.s+1
Scope
MATLAB Command Window, ie. >tau=1.
T ransfer Fcn
1. Change the pulse generator period to 5s and pulse width to
output
50%. Open the output of the Scope and run the model. Is the
Sine Wave
T o Workspace
behaviour as you would expect? Now set the pulse generator
period = 1 and check the response. Is this consistent and as
time
expected?
Clock
T o Workspace1
2. At the MATLAB Command prompt (>) enter time and notice
how the time period is incremented. At the prompt enter output and observe how the data is displayed as an
array. Now type plot(time,output) notice how the pulse generator output appears trapezoidal in shape. This can
be improved from the pull down menu - Simulation > ConfigurationParameters > maxstep change from auto
to 0.01.
3. Delete the Pulse generator and connect the Sine wave source. Run the model and refresh the Figure 1 plot.
Observe how the TF output lags behind the input, and also how the initial slope of the TF output is 0 note that
the transient response takes some time to decay to zero.
4. Set the model run-time to 20 (from the Simulation drop-down menu choose a stop time of 20). Run the model
again and note that default max-step-size has increased to 0.4. Refresh the plot command. Observe that the
transient has decayed after about 2 cycles, and also that the input/output plots are somewhat jagged due to the
integration step size being 0.4s!
5. In the Simulink window go to the pull-down menu and select Simulation then SimulationParameters. Change
max-step size to 0.01 (you can use the short-cut ket Ctrl-E). Run the model again and run the plot command
again to refresh Figure 1. Note that no Warning message is printed and that this has improved the resolution of
the solver time step enter time at the Command line to observe how the time increment is now 0.01seconds.
6. Use the grid on command (in the MATLAB command window) to turn on the plot major axes grid, and then
select the Tools pull-down menu on the plot and enable the data cursor. Use the cursor to estimate the peak
amplitude of the output - as a ratio this should be approximately 0.7. Measure the period at the zero-crossing
points for the output and the input to estimate the phase lag this should be approximately 45. [Ensure the
measurements are made away from the transient]
7. Increase the Sine function frequency to 10 rad/s, and run the model again, and refresh the plot. To be able to
estimate the phase lag it will be necessary to reduce the model run time to 4 seconds to allow a reasonable
estimate of the output amplitude and phase lag (should now be 0.1 and 90 respectively).
8. Vary the Sine function frequency as follows 0.2, 0.5, 1, 2, 5, 10 rad/s. You will find it easier to do this by
assigning a variable name to frequency, i.e. omega (double-click on the sine-wave source block, and type omega
in as the frequency instead of a number, then set omega=0.2 in the MATLAB command window). For each of
the frequencies use the above procedure to estimate the amplitude and phase, and sketch them as a function of
frequency - you will have to adjust the model run time to ensure your plot quality. [Note: to retain the grid
amend the command line to plot(time,output); grid on and refresh].
For an RC filter with R=10k and C=15nF, calculate the filter cut-off frequency (in rad/s). Substitute the
corresponding value of tau in the model. Repeat 8 to plot the amplitude and phase you will have to assume an
appropriate frequency range. Confirm that the cut-off frequency is consistent with an amplitude modulation of
Nov 2012
Revise Date
P J Cumpson
Lecturer
Page 1 of 3
1
------------s^2 + 4 s + 1
MEC3015
Departmental Ref.
Nov 2012
Revise Date
P J Cumpson
Lecturer
Page 2 of 3
4. Obtain the frequency response of the function using BODE, and put the output into the form of a
vector, as follows
>>[mag,phase,w]=bode(sys,freq)
Nov 2012
Revise Date
P J Cumpson
Lecturer
Page 3 of 3