Sei sulla pagina 1di 3

NEWCASTLE UNIVERSITY

SCHOOL OF MECHANICAL & SYSTEMS ENGINEERING


MEC3015
Mod.Ref.

Instrumentation and Drives


Mod.Title

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

1/ 2 0.707 at a phase lag of 45.


MEC3015
Departmental Ref.

Nov 2012
Revise Date

P J Cumpson
Lecturer

Page 1 of 3

MATLAB BODE Function


eout
1
1. First define the numerator and denominator polynomial coefficients for the first

order low-pass transfer function shown on the right in descending powers of s.


ein s 1
From the MATLAB Command window you can do this is done as follows:
>num = [0 1]
>den = [1 1]
2. Next we define the assign the transfer function first using the tf command as follows:
>first = tf(num,den) which should then display
1
----s+1
3. Now we enter the Bode function, using
>bode(first) which should then plot the magnitude and phase relationships as a function of frequency.
4. Position the mouse cursor on the Magnitude plot, and right click. You may need to open the plot
browser. Select Properties to change the scale of the Magnitude from dB to absolute, and also turn
the grid on.
5. Determine the magnitude and phase at 1 rad/s, i.e. the filter cut-off frequency. Compare this with what
you obtained from the Simulink exercise.
6. Increase the cut-off frequency to that of the RC filter, by amending the coefficient of s accordingly.
Run the Bode routine again, and compare the plot with that obtained from the Simulink graph.
7. You should now be able to increase the order of the transfer function to that of a second order low-pass
filter as follows:
> wn = 1, zeta = 2
>num = [0 0 wn^2]
>den = [1 2*zeta*wn wn^2]
8. Now assign the transfer function
>second=tf(num,den) - MATLAB should display it in the form

1
------------s^2 + 4 s + 1

9. Run the Bode function


>bode(second)
10. Use the plot hold function to allow plots to be overwritten on top of each other, as follows:
>hold on
11. Observe how the Bode plots change by progressively decreasing the coefficient of the s term on the
denominator from 4 to 2, 0.5, 0.2, 0.1, 0.05. What conclusions can you draw from this? [When you
have all plots on the one graph, switch the magnitude units to absolute to observe the difference.]
12. Now attempt to repeat the above steps from 7-11, using a second order high-pass filter.
13. Try cascading higher order filters

MEC3015
Departmental Ref.

Nov 2012
Revise Date

P J Cumpson
Lecturer

Page 2 of 3

Another way to plot Magnitude-Phase relationships using MATLAB


The frequency-magnitude of any filter can easily be modelled in MATLAB, by using the following
procedure. At the MATLAB prompt
1. First define the numerator and denominator of the desired transfer function, taking care to ensure the
coefficients for powers of s are in descending order e.g. the high pass filter above is defined
>>num = [1 0]
>>den = [1 1]
(where num and den are assigned num = s, and den = s+1)
2. Next define the transfer function
>> sys=tf(num,den)
(where the transfer function is assigned by 'sys')
3. It is now necessary to define the maximum and minimum frequency range, in radians/s.
>>freq={0.01 100}

note use of braces {} to define a range of values.

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)

(where 'w' is the frequency in radians per second)


5. Obtain the log-linear response
>>semilogx(w,mag(:))
(it is necessary to include '(:)' because 'mag' is a matrix)
6. The figure can be labelled using
>>xlabel('Frequency (rad/s)')
>>ylabel('Amplitude ratio')
>>grid on
(more information can be obtained using 'help plot')
The phase relationship can be obtained using semilogx(w,phase(:)).Try using the above procedure to
evaluate first order low and high-pass filters with larger cut-off frequencies.
Using the function bode(sys,freq) plots the magnitude/phase relationship in decibels and degrees
respectively.
MEC3015
Departmental Ref.

Nov 2012
Revise Date

P J Cumpson
Lecturer

Page 3 of 3

Potrebbero piacerti anche