You are on page 1of 15

Giacinto Gelli DSP Course 1 / 15

Digital Signal Processing a.y. 2007-2008


Matlab Laboratory # 2
ARMA systems
Giacinto Gelli
gelli@unina.it
ARMA systems in the time-domain
Giacinto Gelli DSP Course 2 / 15
Solving the difference equation command y = filter(b,a,x).
Initial-rest conditions are assumed the Matlab system is always
causal.
b and a must be row vectors for compatibility with other commands (see
zplane in particular).
y is of the same length of x does not account for time-dispersion
property of convolution (add zeros instead).
The command does not allow one to explicitly dene the time-axis
the output is dened in the same time instants of the input.
Impulse response h[n] and step response g[n]
Giacinto Gelli DSP Course 3 / 15
Method # 1: Dene x[n] = [n] or x[n] = u[n] and evaluate the outputs
h[n] and g[n] using the command filter.
Exercise: nd the impulse/step response of the ARMA systems
y[n] y[n 1] + 0.9y[n 2] = x[n]. Plot the results. Discuss
stability and causality.
Method # 2: use the commands h = impz(b,a) and g = stepz(b,a)
(SP Toolbox) (causal responses are found!).
Exercise: rework the previous exercise with impz and stepz and
compare the results.
Note: in recent implementations of the SP Toolbox the command stepz has
been deleted. A workaround is to recall the relation existing between h[n] and
g[n], i.e., g[n] =

n
k=
h[k], which can be implemented in Matlab using
the command cumsum.
ARMA systems in the Z-domain
Giacinto Gelli DSP Course 4 / 15
Two basic equivalent forms for the transfer function H(z) of ARMA systems:
H(z) =
M

k=0
b
k
z
k
N

k=0
a
k
z
k
. .
polynomial form
=
_
b
0
a
0
_
M

k=1
(1 c
k
z
1
)
N

k=1
(1 d
k
z
1
)
. .
factorized form
The roots {c
k
} of the numerator are the zeros of the system.
The roots {d
k
} of the denominator are the poles of the system.
k = b
0
/a
0
is the gain of the system for z = .
To pass from one form to the other we use the Matlab commands roots and
poly.
From polynomial to factorized form
Giacinto Gelli DSP Course 5 / 15
Arrange the coefcients b
0
, b
1
, . . . , b
M
and a
0
, a
1
, . . . , a
N
in vectors b and
a, respectively.
Evaluate the roots and the gain with the Matlab commands c = roots(b);
d = roots(a); k=b(1)/a(1).
Exercise: put the following H(z) in factorized form
H(z) =
2+3z
1
+4z
2
1+3z
1
+3z
2
+z
3
You should end up with
H(z) = 2
[1(0.7500+j1.1990)z
1
] [1(0.7500j1.1990)z
1
]
(1+z
1
)
3
Note: (possible) poles/zeros in z = 0 can be evaluated by the command
roots if we add zeros to the shortest between b and a in order to make them
the same length.
From factorized to polynomial form
Giacinto Gelli DSP Course 6 / 15
Use the command poly that evaluates the coefcients of a polynomials
starting from its roots.
Since this polynomial is dened up to a scaling factor, the command poly
implicitly assumes that a
0
or b
0
is equal to one.
Since k = b
0
/a
0
, if we let arbitrarily a
0
= 1, we get k = b
0
.
The following Matlab commands are required: b = k*poly(c); a =
poly(d).
Exercise: rework the previous example starting from k, c, d and obtaining b
and a.
Exercise: write two Matlab functions [k,c,d] = poly2fact(b,a) and
[b,a] = fact2poly(b,a) that implement the previous conversions and
test it by calling them in cascade.
Pole-zero diagram
Giacinto Gelli DSP Course 7 / 15
The pole-zero diagram of an ARMA system can be evaluated and displayed
using the command zplane(b,a).
Important! b and a must be row vectors (use help zplane for details).
Exercise: write a Matlab script that plots the pole-zero diagram of the system
described by the following LCC difference equation:
y[n] y[n 1] + 0.9 y[n 2] = x[n]
Discuss the possible ROCs associated to the pole-zero diagrams. Write the
analytical expression of the stable and causal impulse response h[n] and
compare with the one obtained in Matlab with impz. Discuss the results.
Exercise: rework the previous exercise with reference to the equation
y[n] +
1
4
y[n 1]
3
8
y[n 2] = x[n] + 2x[n 1] + x[n 2]
Partial fraction expansion (1/2)
Giacinto Gelli DSP Course 8 / 15
The partial fraction expansion of H(z) with simple poles and M N is:
H(z) =
MN

r=0
B
r
z
r
+
N

k=1
A
k
1 d
k
z
1
If multiple poles are present, to any pole d
i
of multiplicity s it corresponds a
sum of s terms like:
s

m=1
C
m
(1 d
i
z
1
)
m
The partial fraction expansion can be obtained with the Matlab command
residuez (SP Toolbox), which can help in the analytical calculation of the
partial fraction expansion.
Partial fraction expansion (2/2)
Giacinto Gelli DSP Course 9 / 15
The command residuez calculates the poles d
k
and the coefcients B
r
, A
k
e C
m
of the partial fraction expansion.
The syntax is [r,p,k] = residuez(b,a), where
b (of length M +1) and a (of length N +1) are the coefcients of H(z)
(as before);
the vector p (of length N) contains the poles; if a pole with multiplicity s
is present, it appears s times in vector p;
the vector r (of length N) contains the coefcients A
k
and C
m
of the
corresponding poles in p:
the vector k (of length M N + 1) contains the coefcients B
r
If we use the command with the syntax [b,a] = residuez(r,p,k), it
performs the reverse operation (useful for checking).
Exercise
Giacinto Gelli DSP Course 10 / 15
Consider the following transfer function of a causal ARMA system:
H(z) =
1 + 2z
1
+ z
2
1
3
2
z
1
+
1
2
z
2
(a) Use zplane to observe the pole-zero diagram. Do you expect the
system to be stable?
(b) Determine with residuez the partial fraction expansion of H(z) and
compare with the result obtained by hand.
(c) On the basis of the partial fraction expansion, write down the expression
of the impulse response h[n]. Compare with the result obtained using
impz.
(d) Discuss stability on the basis of h[n].
The frequency response (1/2)
Giacinto Gelli DSP Course 11 / 15
If the ROC of H(z) includes the unit circle (i.e., the system is stable) the
frequency response of an ARMA system can be obtained by evaluating H(z)
for z = e
j
:
H(e
j
) = H(z)|
z=e
j
=
M

k=0
b
k
e
jk
N

k=0
a
k
e
jk
In Matlab we use the command freqz to evaluate (and possibly plot) H(e
j
).
The frequency response (2/2)
Giacinto Gelli DSP Course 12 / 15
The syntax of freqz is [H,w] = freqz(b,a,L):
for a given L (default value 512) it gives in H the L complex values of
H(e
j
), evaluated for L equispaced values of (0, ), which are
collected in vector w;
use plot(w,abs(H)) and plot(w,angle(H)) to plot the result.
When the system is real, the whole spectrum can be extrapolated from
(0) by Hermitian symmetry. If we want the spectrum in the interval
(0, 2), we can use the modied syntax [H,w] =
freqz(b,a,L,whole).
With freqz(b,a) we obtain directly the amplitude (in dB) and phase
(degrees) in (0, ) and for L = 512.
Exercise
Giacinto Gelli DSP Course 13 / 15
Consider the causal and stable system described by
y[n] y[n 1] + 0.9 y[n 2] = x[n]
(a) Using the pole-zero diagram, make predictions about the frequency
response of the system (LPF? HPF? BPF?)
(b) Verify your predictions by evaluating and plotting the frequency response
in (0, 2).
(c) Evaluate the speed of response of the system (both analytically and with
Matlab).
A Matlab contradiction :-)
Giacinto Gelli DSP Course 14 / 15
The command freqz evaluates the frequency response by calculating H(z)
on the unit circle, hence it assumes that the system be stable. This
assumption can be in contrast with that of the commands filter, impz, and
stepz, all of which assume instead that the system be casual.
Exercise: consider
y[n] 1.6971y[n 1] + 1.4400y[n 2] = x[n]
(a) Using the pole-zero diagram, establish the different ROCs and discuss
the properties of the different systems involved.
(b) Which one of the systems is implemented by filter, impz, and
stepz?
(c) The system implemented by filter is stable? If not, how do you
interpret the frequency response evaluated by freqz?
My rst lter design: notch lter
Giacinto Gelli DSP Course 15 / 15
By placing zeros on the complex plane, design a stable and causal system
that is able to perfectly suppress from the signal x[n] = s[n] + d[n] a
sinusoidal signal d[n] = cos(2
0
n), with
0
= 1/8 (notch lter).
Test it by generating and ltering a segment of L = 100 samples of d[n].
Make a plot of the frequency response of the system. Do you think the notch
lter will signicantly distort the signal s[n]?
Improve you project by adding poles (where?) in order to atten the
frequency response away from the zeros, so that the desired signal s[n]
undergos less (amplitude) distortion.

You might also like