Worksheet 11#

To accompany Unit 5.4: Models of Discrete-Time Systems#

Colophon#

This worksheet can be downloaded as a PDF file. We will step through this worksheet in class.

An annotatable copy of the notes for this presentation will be distributed before the second class meeting as Worksheet 17 in the Week 9: Classroom Activities section of the Canvas site. I will also distribute a copy to your personal Worksheets section of the OneNote Class Notebook so that you can add your own notes using OneNote.

You are expected to have at least watched the video presentation of Models of Discrete-Time Systems of the notes before coming to class. If you haven’t watch it afterwards!

After class, the lecture recording and the annotated version of the worksheets will be made available through Canvas.

Agenda#

  • Discrete Time Systems (Notes)

  • Transfer Functions in the Z-Domain (Notes)

Discrete Time Systems#

In the lecture that introduced the z-transform we talked about the representation of a discrete-time (DT) system by the model shown below:

Model of a DT system

In this session, we want to explore the contents of the central block.

Example 5#

Karris Example 9.10:

The difference equation describing the input-output relationship of a DT system with zero initial conditions, is:

y[n]0.5y[n1]+0.125y[n2]=x[n]+x[n1]

Compute:

  1. The transfer function H(z)

  2. The DT impulse response h[n]

  3. The response y[n] when the input x[n] is the DT unit step u0[n]

5.1. The transfer function#

H(z)=Y(z)U(z)=...?


















Solution example5.1.pdf

5.2. The DT impulse response#

Start with:

H(z)z=z+1z20.5z+0.125


















Solution example5.2.pdf

MATLAB Solution#
clear all
cd matlab
pwd
format compact
ans =

    '/Users/eechris/code/src/github.com/cpjobling/eg-247-textbook/dt_systems/4/matlab'

See dtm_ex1_2.mlx. (Also available as dtm_ex1_2.m.)

The difference equation describing the input-output relationship of the DT system with zero initial conditions, is:

y[n]0.5y[n1]+0.125y[n2]=x[n]+x[n1]
Transfer function#

Numerator z2+z

Nz = [1 1 0];

Denominator z20.5z+0.125

Dz = [1 -0.5 0.125];
Poles and residues#
[r,p,k] = residue(Nz,Dz)
Impulse Response#
Hz = tf(Nz,Dz,-1)
hn = impulse(Hz, 15);
Plot the response#
stem([0:15], hn)
grid
title('Example 5 - Part 2')
xlabel('n')
ylabel('Impulse response h[n]')
Response as stepwise continuous y(t)#
impulse(Hz,15)
grid
title('Example 5 - Part 2 - As Analogue Signal')
xlabel('nTs [s]')
ylabel('Impulse response h(t)')

5.3. The DT step response#

Y(z)=H(z)X(z)
u0[n]zz1
Y(z)=H(z)U0(z)=z2+zz2+0.5z+0.125.zz1=z(z2+z)(z2+0.5z+0.125)(z1)
Y(z)z=z2+z(z2+0.5z+0.125)(z1)

Solved by inverse Z-transform.



















Solution example5.3.pdf

MATLAB Solution#

See dtm_ex1_3.mlx. (Also available as dtm_ex1_3.m.)

open dtm_ex1_3
Results#

Results

Converting Continuous Time Systems to Discrete Time Systems#

Continuous System Equivalents#

  • There is no digital system that uniquely represents a continuous system

  • This is because as we are sampling, we only have knowledge of signals being processed at the sampling instants, and need to reconstruct the inter-sample behaviour.

  • In practice, only a small number of transformations are used.

  • The derivation of these is beyond the scope of this module, but here we’ll demonstrate the ones that MATLAB provides in a function called c2d

MATLAB c2d function#

Let’s see what the help function says:

help c2d

Example: Digital Butterworth Filter#

  • Design a 2nd-order butterworth low-pass anti-aliasing filter with transfer function H(s) for use in sampling music.

  • The cut-off frequency ωc=20 kHz and the filter should have an attenuation of at least 80 dB in the stop band.

  • Choose a suitable sampling frequency for the audio signal and give the transfer function H(z) and an algorithm to implement h[n]

Solution#

See digi_butter.mlx.

First determine the cut-off frequency ωc

ωc=2πfc=2×π×20×103rad/s
wc = 2*pi*20e3
wc =
   1.2566e+05
ωc=125.66×103rad/s

From the lecture on filters, we know the 2nd-order butterworth filter has transfer function:

H(s)=Y(s)U(s)=ωc2s2+ωc2s+ωc2

Substituting for ωc=125.6637×103 this is …?

Hs = tf(wc^2,[1 wc*sqrt(2), wc^2])
Hs =
 
           1.579e10
  ---------------------------
  s^2 + 1.777e05 s + 1.579e10
 
Continuous-time transfer function.
H(s)=15.79×109s2+177.7×103s+15.79×109

Bode plot#

MATLAB:

bode(Hs,{1e4,1e8})
grid
../../_images/7c115db16a49a4871123f9c5bd05c7d9d2901d3911ea580f7d4e32221666db99.png

Sampling Frequency#

From the bode diagram, the frequency roll-off is -40 dB/decade for frequencies ωωc. So, |H(jω)|=80 dB is approximately 2 decades above ωc.

w_stop = 100*wc
w_stop =
   1.2566e+07

To avoid aliasing, we should choose a sampling frequency twice this = ?

ωs=2×12.6×106 rad/s.

ws = 2 * w_stop
ws =
   2.5133e+07

So

ωs=25.133×106 rad/s.

Sampling frequency (fs) in Hz = ?

fs=ωs/(2π)Hz
fs = ws/(2*pi)
fs =
     4000000

Sampling time Ts=?

Ts=1/fss

Ts = 1/fs
Ts =
   2.5000e-07

Digital Butterworth#

zero-order-hold equivalent

Hz = c2d(Hs, Ts)
Hz =
 
  0.0004862 z + 0.0004791
  -----------------------
  z^2 - 1.956 z + 0.9565
 
Sample time: 2.5e-07 seconds
Discrete-time transfer function.

Step response#

step(Hz)
../../_images/36dd14d95bc8eb5b20beced1efdc5e2ddf7de07896b3662b3cf2c79cd063adc2.png

Algorithm#

From final result:

H(z)=Y(z)U(z)=486.2×106z+479.1×106z21.956z+0.9665

Dividing top and bottom by z2

H(z)=Y(z)U(z)=486.2×106z1+479.1×106z211.956z1+0.9665z2

expanding out …

Y(z)1.956z1Y(z)+0.9665z2Y(z)=486.2×106z1U(z)+479.1×106z2U(z)

Inverse z-transform gives …

y[n]1.956y[n1]+0.9665y[n2]=486.2×106u[n1]+479.1×106u[n2]

in algorithmic form (compute y[n] from past values of u and y) …

y[n]=1.956y[n1]0.9665y[n2]+486.2×106u[n1]+...479.1×106u[n2]

Block Diagram of the digital BW filter#

digital filter

Convert to code#

To implement:

y[n]=1.956y[n1]0.9665y[n2]+486.2×106u[n1]+479.1×106u[n2]
/* Initialize */
Ts = 0.25e-06; /* more probably some fraction of clock speed */
ynm1 = 0; ynm2 = 0; unm1 = 0; unm2 = 0;
while (true) {
    un = read_adc;
    yn = 1.956*ynm1 - 0.9665*ynm2 + 479.1e-6*unm1 + 476.5e-6*unm2;
    write_dac(yn);
    /* store past values */
    ynm2 = ynm1; ynm1 = yn;
    unm2 = unm1; unm1 = un;
    wait(Ts);
}