Lecture 12 - Discrete Time Systems (Notes)
Lecture 12 - Discrete Time Systems (Notes)
URL: www.ee.ic.ac.uk/pcheung/teaching/DE2_EE/
E-mail: [email protected]
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{.}
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{‧}
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
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
𝑥[𝑛] 𝑥[𝑛] 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.
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
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
We can computer the frequency response of this simple 4-tap FIR or moving
average filter with the following transfer function:
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:
n
0 1 2 3
For the 7-days moving average filter, the impulse response is:
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: ("$
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:
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.
𝑦 𝑛 = 𝛼𝑦 𝑛 − 1 + (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 ]
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)
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.