0% found this document useful (0 votes)
45 views

Lecture 12 - Discrete Time Systems (Notes)

This document provides an overview of discrete time systems and their representation in three forms: block diagrams, difference equations, and transfer functions in the z-domain. It introduces discrete time linear and shift-invariant systems, and their basic building blocks of scaling, addition, and delay. An example of a moving average filter is presented and its representation is shown using a signal flow diagram and difference equation. Finally, it describes how to derive the z-transform representation of a system from its difference equation using the shift property of the z-transform.

Uploaded by

Buddhadev Ghosh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

Lecture 12 - Discrete Time Systems (Notes)

This document provides an overview of discrete time systems and their representation in three forms: block diagrams, difference equations, and transfer functions in the z-domain. It introduces discrete time linear and shift-invariant systems, and their basic building blocks of scaling, addition, and delay. An example of a moving average filter is presented and its representation is shown using a signal flow diagram and difference equation. Finally, it describes how to derive the z-transform representation of a system from its difference equation using the shift property of the z-transform.

Uploaded by

Buddhadev Ghosh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Lecture 12

Discrete Time Systems

Prof Peter YK Cheung

Dyson School of Design Engineering

URL: www.ee.ic.ac.uk/pcheung/teaching/DE2_EE/
E-mail: [email protected]

PYKC 27 Feb 2023 DE2 – Electronics 2 Lecture 12 Slide 1

In this lecture, we will explore discrete systems and how to model them in three
different forms:
1. As block diagrams – this is similar to a circuit schematic. It shows how signals
flows in the system and the operations being performed on the signals.
2. As difference equation – this relates input sample sequence to output sample
sequence.
3. As transfer function in z-domain – this is similar to the transfer function for
Laplace transform. However I will be introduce the z-transform, which is
essential to represent discrete systems.
Linear Discrete time systems
 A discrete time system takes in a sequence of discrete values x[n] at the
input and produces an output sequence y[n] through some internal
operation or transformation T{.}

𝑥[𝑛] T{‧} 𝑦[𝑛] = 𝑇{ 𝑥 𝑛 }


𝑥[𝑛 − 𝑘] 𝑦[𝑛 − 𝑘]
 The system is LINEAR if it obeys the principle of superposition:
𝑦 𝑛 = 𝑇 𝑎! 𝑥! 𝑛 + 𝑎" 𝑥" 𝑛 = 𝑎! 𝑇 𝑥! 𝑛 + 𝑎" 𝑇 𝑥" 𝑛

 The system is shift-invariant if:


𝑇 𝑎! 𝑥1 𝑛 − 𝑘 + 𝑎" 𝑥" 𝑛 − 𝑘 = 𝑦[𝑛 − 𝑘]

PYKC 27 Feb 2023 DE2 – Electronics 2 Lecture 12 Slide 2

Let us first consider a linear discrete time system shown here as T{.}. ({.} is to
indicate that T is an arbitrary system.). The system takes in the input sequence x[n]
and produces the output sequence y[n].

A linear system means it obeys the principle of superposition. Remember from last
year, you have learned this principle in depth. There are two separate property of a
linear system:
1. Response for input (A+B) = Response for input A + Response for input B.
2. If you scale input by a factor K, the output is scaled by the same factor K. For
example, if you double the input (K=2), the output will also double.

The system is also shift invariant. This means if input is delayed by k samples,
i.e. x[n] à x[n-k] , then the output is the same but also delayed by k samples,
i.e. y[n] à y[n-k]. (See next slide.)
Shift-invariant Discrete time systems
 A system is shift-invariant if delaying the input x[n] by k samples results
in the same output y[n], but delayed also by k.
𝑥[𝑛] 𝑦[𝑛] = 𝑇{ 𝑥 𝑛 }
T{‧}
𝑥[𝑛 − 𝑘] 𝑦[𝑛 − 𝑘]
 In this course, we only consider linear shift-invariant discrete systems.

T{‧}

T{‧}

T{‧}

PYKC 27 Feb 2023 DE2 – Electronics 2 Lecture 12 Slide 3

A shift-invariant system means that if you shift an input signal by k samples, the
system response to x[n-k] is simply y[n-k]. It essentially means that the signal can
start any time, the output remains the same but with the same delay as the input.

For this course, we will always assume that the discrete time system is linear, shift-
invariant.
Basic building blocks in a discrete linear system
 Scaling

𝑥[𝑛] 𝑦 𝑛 =𝛼𝑥 𝑛
a
 Adding
𝑥[𝑛] 𝑝 𝑛 = 𝑥 𝑛 + 𝑦[𝑛]
S

y[𝑛]
 Delay (i.e. Dk = time shift by k sample periods)

𝑥[𝑛] 𝑦 𝑛 =𝑥 𝑛−𝑘
Dk

PYKC 27 Feb 2023 DE2 – Electronics 2 Lecture 12 Slide 4

When building a linear discrete time system, we use only THREE operators:
1. Scaling signal by a constant. This is the same as amplifying or attenuating the
signal.
2. Adding – this is obvious.
3. Delay – this is simply delaying the input sample by k sampling clock cycles (i.e. k
clock period, equivalent to t = k Ts, where Ts is the sampling interval (i.e. time
between two samples).

It is amazing that with only these three operators, we can construct fairly complex
discrete time systems implemented on a microcontroller such as the PyBench board
as used in the Lab.
Moving average filter
 Consider the following discrete time system: delay taps

𝑥[𝑛 − 1] 𝑥[𝑛 − 2] 𝑥[𝑛 − 3]

𝑥[𝑛] 𝑥[𝑛] D D D
F{.}
𝑦[𝑛]

0.25

0.25

0.25

0.25
signal flow diagram
difference equation
S
𝑦 𝑛 = 0.25 (x[n] + x[n-1]+x[n-2]+x[n-3])

 This system take the current and the previous 3 input samples, and average
them. This is also known as a moving average filter.

PYKC 27 Feb 2023 DE2 – Electronics 2 Lecture 12 Slide 5

Consider a simple discrete time system which takes the current and three previous
input samples, and calculate the average value:
%
1
𝑦 𝑛 = & 𝑥[𝑛 − 𝑘]
4
"#$
This is known as a moving average filter. Since averaging reduces the effect of fast
changes, this is essentially a lowpass filter.
The slide here shows two different representation of the system.
1. Signal flow diagram – this is similar to a circuit schematic showing how signals
are transferred to various modules. Its graphical nature allows a reader to relate
to the actual physical system easier than using mathematical equations.
2. Difference equation – this is expressed in terms of a formulae defining the
relationship between input samples and output samples.
Note that the input signal x[n] is passed to three sample delay units D, to obtain
x[n-1], x[n-2], x[n-3]. These are called ”taps” of the filter. In this case, there are four
taps to this filter.
Such sample delays can be implemented in an electronic system by:
1. Using an array in a microprocessor or computer to store different x values;
2. Using D-flipflops (D-FFs) in digital hardware in a shift register configuration. In
this case, assuming that all signals are 10-bit wide (from the ADC), then we need
three sets of 10 D-FFs.
Example - COVID cases in UK

PYKC 27 Feb 2023 DE2 – Electronics 2 Lecture 12 Slide 6

Here is a contemporary example of the use of moving average filter. Instead of


averaging over four input values, this shows a 7-day moving average of COVID cases
in the UK. You can clearly see the averaging effect of this lowpass filter!
z-transform and difference equation
 According to Lecture 11 slide 9, if the z-transform of x[n] is X[z]:
!
𝑥 𝑛 → 𝑋[𝑧]
then,
!
𝑥 𝑛−𝑘 → 𝑋[𝑧] 𝑧 "#
 In other words, delaying a signal x[n] by k sample period is equivalent to
multiplying its z-transform X[z] with z-k.
 We can apply this important property of z-transform (known as the shift
property) to the difference equation relating the input sequence to the
output sequence:
Difference equation 𝑦 𝑛 = 0.25 (x[n] + x[n-1] + x[n-2] + x[n-3])

𝑌 𝑧 = 0.25 𝑋 𝑧 + 𝑋 𝑧 𝑧 "$ + 𝑋 𝑧 𝑧 "% + 𝑋 𝑧 𝑧 "&


z-transform equation 𝑌 𝑧 = 0.25(1 + 𝑧 "$ + 𝑧 "% + 𝑧 "& )𝑋 𝑧
 This is the z-domain version of the difference equation in terms of z-k, where
k is delay in unit of sample.
PYKC 27 Feb 2023 DE2 – Electronics 2 Lecture 12 Slide 7

The third method of representing a discrete time system is to use z-transform to


represent the delay operators. Again, I will discuss the mathematical basis of z-
transform in a later lecture. For now all you need to know (and trust) is that delay a
signal x[n] by k sampling periods to give x[n-k] is the same as multiplying the z-
transform of the signal X[z] by the factor z-k.
2
𝑥 𝑛 → 𝑋[𝑧]
2
𝑥 𝑛 − 𝑘 → 𝑋[𝑧] 𝑧 34
Using this fact, we can derive the relationship between Y[z] and X[z] directly from
the difference equation:
𝑦 𝑛 = 0.25 (x[n] + x[n-1]+x[n-2]+x[n-3])
𝑌 𝑧 = 0.25 𝑋 𝑧 + 𝑋 𝑧 𝑧&' 𝑧 + 𝑋 𝑧 𝑧&( 𝑧 + 𝑋 𝑧 𝑧&%

𝑌 𝑧 = 0.25(1 + 𝑧&' + 𝑧&( + 𝑧&% )𝑋 𝑧


Transfer function in the z-domain
 Take the results from the previous slide and re-arrange:
𝑦 𝑛 = 0.25 (x[n] + x[n-1]+x[n-2]+x[n-3])

𝑌 𝑧 = 0.25 𝑋 𝑧 + 𝑋 𝑧 𝑧 "$ + 𝑋 𝑧 𝑧 "% + 𝑋 𝑧 𝑧 "&

𝑌 𝑧 = 0.25(1 + 𝑧 "$ + 𝑧 "% + 𝑧 "& )𝑋 𝑧

𝐻 𝑧 = 𝑌 𝑧 /𝑋[𝑧] = 0.25(1 + 𝑧 #! + 𝑧 #" + 𝑧 #$ )


 As in the case of Laplace transform, in the z-domain,
transfer function H[z] = output Y[z] / input X[z]
 This moving average filter takes the average of the current data sample
x[i], and the previous three samples x[i-1], x[i-2] and x[i-3], to produce the
output y[i].
 The averaging function has a smoothing effect – that is, it performs the
function of a lowpass filter.

PYKC 27 Feb 2023 DE2 – Electronics 2 Lecture 12 Slide 8

From the previous slide, we can compute Y[z]/X[z], and obtain the transfer function
H[z]:
𝐻 𝑧 = 𝑌 𝑧 /𝑋[𝑧] = 0.25(1 + 𝑧&' + 𝑧&( + 𝑧&% )

Moving average filter is a lowpass filter. It has a DC gain of 1 (check this for yourself
and make sure you understand why), and it reduces the amplitude of fast changing
signals – i.e. at higher frequencies.
Take a sequence x[n] = {1.0, 1.0, 1.0, 1.0, 1.1, 0.8, 1.2, 0.9, 1.0, 1.2, 0.9, …}, which is
a discrete signal at 1v, but with random noise added. The noise amplitude (i.e.
deviation from 1.0) is ±0.2v.
Assuming that all x[n] = 0 for n<0,
y[n] = (0.25, 0.5, 0.75, 1.0, 1.025, 0.975, 1.025, 1.0, 1.0, 1.075, 1.0, …..}
It is clear that y[n] is still centred around 1v, but the fluctuation is reduce to 0.025v!
Frequency Response of this filter
 Here is the frequency response of this moving average filter:

Normalised freq 1 is
Sampling freq Fs / 2

PYKC 27 Feb 2023 DE2 – Electronics 2 Lecture 12 Slide 9

We can computer the frequency response of this simple 4-tap FIR or moving
average filter with the following transfer function:

𝐻 𝑧 = 𝑌 𝑧 /𝑋[𝑧] = 0.25(1 + 𝑧&' + 𝑧&( + 𝑧&% )

I deliberately skip the mathematic derivation of the frequency response for such a
filter for now. What is important to note is that the frequency response
demonstrates that averaging four samples is effectively lowpass filtering the signal.
The roll off (rate of attenuation as frequency increases) is very gentle.
The x-axis is the digital frequency expressed in angle increment per sample,
normalized to Fs/2 (Nyquist frequency). For example, if the sampling frequency is
8kHz, the normalized frequency of 1 is at 4kHz.

There is a notch (null response) at 2kHz, when the response of the filter is zero!
Same for frequency of 4kHz. Why? Test it for yourself.
Impulse Response of the moving average filter
 The four-tap moving average filter has an impulse response of:

Impulse response – 4-tap


0.25

n
0 1 2 3

 The reason is that an impulse at n = 0 will has an impact on the output of


¼ on the current sample time, and the three subsequent sample times.

 For the 7-days moving average filter, the impulse response is:

Impulse response – 7-day moving average


1/7

days
0 1 2 3 4 5 6
PYKC 27 Feb 2023 DE2 – Electronics 2 Lecture 12 Slide 10

One important characterization of the 4-tap moving average filter is its impulse
response. Plotted here is the output of the filter to an impulse at n=0. That is, if
the input x[n] is an impulse a n=0, then its effect on the output y[n] is going to last
of four sample periods at n=0, 1, 2, and 3. Since it is averaging, the weighting is 0.25
everywhere.

As will be seen in the next lecture, we can also represent this impulse response as
the “transfer function” of the moving average filter in the z-domain as:
1
𝐻 𝑧 = (1 + 𝑧&' + 𝑧&( + 𝑧&% )
4

If we go back to the COVID cases example, the unit of the x-axis is days (i.e. n = 3
means three days from now), the impulse response for the 7-day moving average
”filter” is as shown in the slide.
General FIR filters
 Instead of using the same coefficient values in the moving average filter,
one could use different coefficients at different delay taps.
 The number of delay taps can be increased to N.
 This will implement a filter function of the form as difference equation:
𝑦 𝑛 = 𝑏' 𝑥 𝑛 + 𝑏$ 𝑥 𝑛 − 1 + 𝑏$ 𝑥 𝑛 − 2 + ⋯ + 𝑏("$ 𝑥 𝑛 − (𝑁 − 1)
 In z-domain form: ("$

𝑌 𝑧 = (𝑏' +𝑏$ 𝑧 "$ + 𝑏% 𝑧 "% + 𝑏& 𝑧 "& + ⋯ + 𝑏("$ 𝑧 " ("$


)𝑋 𝑧 = 𝑋[𝑧] E 𝑏# 𝑧 "#
#)'
("$
𝑌 𝑧
𝐻 𝑧 = = 𝑏' + 𝑏$ 𝑧 "$ + 𝑏% 𝑧 "% + 𝑏& 𝑧 "& + ⋯ + 𝑏("$ 𝑧 " ("$
= E 𝑏# 𝑧 "#
𝑋 𝑧
#)'
 By choosing different coefficients b0, b1, b2 …., bN-1, one can implement
different types of filters: lowpass, bandpass, highpass etc.
 Such a filter will have N terms in the impulse response, where N is the
number of signal taps x[n], … x[n-(N-1)]. Therefore it is also known as a
finite impulse response filter (FIR) of order N.

PYKC 27 Feb 2023 DE2 – Electronics 2 Lecture 12 Slide 11

The moving average filter we used previously only considered 4 input sample values
(we call this a “4-tap” filter, tapping into only 4 signal values). Instead of 4-tap, one
can choose to perform the moving average over K-taps.
What do you expect the effect of using a higher value of K? You will be averaging
over a longer time (sample) window, and therefore this will have a “stronger”
lowpass filtering effect. In other words, the attenuation at high frequency will be
stronger.
If you measure the frequency response of the moving filter, you will find that the
drop in gain as frequency increases goes up with K. Exactly how we can derive the
frequency response of a K-tap moving average filter will be considered at a later
lecture.
Instead of using equal value coefficients on the taps in this filter, we could choose to
use different coefficients. In which case, the filter you implement will have the
difference equation and the transfer function as shown in the slide.

This generalised form of filter is known as FIR or finite impulse response filter. The
name arises because if you apply an impulse at the input x[n] = d[n] to a filter with N
taps, the output response y[n] will last exactly N samples later, which is finite. This
output y[n] for x[n] = unit impulse is known as impulse response of the system.

It can be shown that for an arbitrary signal x[n], its response y[n] will always be
finite – meaning that if x[n] dies down to zero, y[n] will become zero in finite time.
By choosing different values for the coefficients bi, one can implement any type of
filters: lowpass, highpass, bandpass, bandstop etc.
Recursive Filter
 FIR filters derives the current output from current and previous inputs
 Such a filter does not make use of previous outputs – that is, it does not rely
on past information
 Recursive filter or IIR filter is different – it derives the current output from
both input and previous output samples.
 Here is one of the simplest recursive filter:

PYKC 27 Feb 2023 DE2 – Electronics 2 Lecture 12 Slide 12

Let us now consider a completely new class of filter. Here we have a filter that
derives the output from both inputs and past output samples. The simplest form is
the one shown here – known as a first-order recursive filter.

The output contains two components: 1) input x[n] multiplied by a coefficient (1-a);
2) output y[n-1] multiplied by a coefficient a.

This can be represented by the difference equation:

𝑦 𝑛 = 𝛼𝑦 𝑛 − 1 + (1 − 𝛼)𝑥 𝑛

Now takes the z-transform of this difference equation. We get:

𝑌 𝑧 = 𝛼 𝑌 𝑧 𝑧&' + (1 − 𝛼)𝑋 𝑧

From this we can derive the transfer function:


𝑌[𝑧] (1 − 𝛼)
𝐻𝑧 = =
𝑋[𝑧] (1 − 𝛼 𝑧&' )

Recursive filters are also called Infinite Impulse Response (IIR) filters because the
response of the filter to a unit impulse theoretically lasts forever! However, if an IIR
filter is stable, its impulse response will decay to zero. If the impulse response does
not decay to zero, the filter is NOT stable.
Step response of Recursive Filter
 Let us consider the response of this filter to unit step function at the input

x[0:9] = [0 1 1 1 1 1 1 1 1 1]

y[0:9] = [0 0.2 0.36 0.49 0.59 0.67 0.74 0.79 0.83 0.87 ]

PYKC 27 Feb 2023 DE2 – Electronics 2 Lecture 12 Slide 13

Now let us consider what output we get if we apply a unit step function at the input.
The output is known as the step response of this filter.

Shown above are the outputs y in respond to the input going from 0 to 1.

The result is an exponential rise toward 1, the time constant of the rise if effective
a. (Similar to what we have done before on 1st order lowpass filter and RC
network.)
Three Big Ideas
1. A discrete-time system can be represented in three ways:
o Block diagram (see slide 5)

o Difference equation, e.g. 𝑦 𝑛 = 0.25 (x[n] + x[n-1]+x[n-2]+x[n-3])

o Impulse response in the z-domain, e.g. 1


𝐻 𝑧 = (1 + 𝑧 "$ + 𝑧 "% + 𝑧 "& )
4
2. A Finite Impulse Response filter (FIR), as the name implies, is one
where the effect of input signal lasts for fixed number of sampling
periods before reaching zero. However Infinite Impulse Respnse
(IIR) filter in theory has an infinite impulse responses the lasts forever,
but may decay towards zero.
3. An Infinite Impulse Respnse (IIR) filter is much more efficient to
implement than FIR filter. For the same filtering effect, IIR filter has
much lower number of multiplier and add operations than FIR filter.
However, it badly designed IIR filter may be unstable.

PYKC 27 Feb 2023 DE2 – Electronics 2 Lecture 12 Slide 14

Here are the three big ideas in this lecture:

1. Discrete-time systems can be characterized by using block diagram with


multiplier, adder and delay elements;
2. We can use difference equations
3. We can use z-domain representation for the signals, and transfer function for
the system.

FIR filter’s output only depends on current and past inputs.

FIR filter has N taps (order N) and the impulse response is finite. Further, by
choosing the coefficient of the FIR filter (i.e. the tap weighting) we can implement
ANY type of filters: lowpass, highpass, bandpass, bandstop.

IIR filter is recursive meaning that current output depends on both past outputs and
current and past inputs.

IIR filters are much more efficient to implement than their equivalent FIR filters.

You might also like