You are on page 1of 21

Electrical Engineering in Context Smart Devices

Robots and Communications 1st Edition by


Roman Kuc ISBN 1285179188 9781285179186
Download solution manual at:
https://testbankpack.com/p/solution-manual-for-electrical-engineering-in-context-
smart-devices-robots-and-communications-1st-edition-by-roman-kuc-isbn-
1285179188-9781285179186/

Chapter 8

Digital Signal Processing

8.1 Problems
Problem 8.1 (MA digital filter from description) Write the difference equation and draw the block
diagram of the digital filter that computes the average of the current and past two samples of input
sequence xi .
(ans: Difference equation:
xi + xi−1 +
yi =
xi−2
Block diagram: 3

X + 1/3 y
i i

Problem 8.2 (Difference equation from MA digital filter structure) Write the difference equation of
the digital filter shown in Figure 8.1.
(ans:
yi = xi + 3xi−1 + 2xi−2 + xi−3
)

© 2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
Problem 8.3 (AR digital filter from description) Write the difference equation and draw the block
diagram of the digital filter whose current output is the sum of twice the current input and half the
previous output.
(ans: Difference equation:
yi = 0.5yi−1 + 2xi

87

© 2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
88 CHAPTER 8. DIGITAL SIGNAL PROCESSING

xi yi

δ
3

δ
2

Figure 8.1: MA filter for Problem 8.2.

Block diagram:
X 2 + y
i i

1/2

Problem 8.4 (First-order AR digital filter with positive feedback coefficient) Draw the digital filter
structure and compute the unit-sample response hi for 0 ≤ i ≤ 3 of the digital filter defined by the
difference equation
yi = 0.9yi−1 + xi
What value of i produces hi < 0.01?

(ans: Block diagram:

X + y
i i

0.9

The unit-sample response hi equals yi when xi = di and assuming zero initial conditions (hi = 0 for
i < 0).
i=0
=0 =1
z}|{ z}|{
h0 = 0.9 h −1 + d 0 = 1

© 2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
8.1. PROBLEMS 89

i=1
=1 =0
z}|{ z}|{
h1 = 0.9 h 0 + d 1 = 0.9
i=2
=0.9 =0
z}|{ z}|{
h2 = 0.9 h 1 + d 2 = 0.81
i=3
=0.81 =0
z}|{ z}|{
h3 = 0.9 h 2 + d 3 = 0.729
In general, hi = 0.9i . Solving for i gives
log(hi )
i=
log(0.9)

Then, using logarithms to the base 10 gives

log10 (0.01) −2
imin > = = 43.7
log10 (0.9) −0.0458
Hence, imin = 44.
)

Problem 8.5 (Difference equation from AR filter structure) Write the difference equation of the dig-
ital filter shown in Figure 8.2.

xi yi

δ
1.5

δ
-0.4

δ
-0.3

Figure 8.2: AR filter for Problem 8.5.

(ans:
yi = 1.5yi−1 − 0.4yi−2 − 0.3yi−3
)

© 2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
90 CHAPTER 8. DIGITAL SIGNAL PROCESSING

Problem 8.6 (Second-order AR system) Assuming zero initial conditions, compute the unit-sample
response hi for 0 ≤ i ≤ 2 for the difference equation
yi = 2r cos(ωo )yi−1 − r 2 yi−2 + xi

where r = 0.9 and ωo = π/10.

(ans: Simplify the difference equation by computing the coefficient values, as

yi = ai yi−1 + a2 yi−2 + xi
where
a1 = 2r cos(ωo ) = 2(0.9) cos(π/10) = 1.712
a2 = −r2 = −0.81
gives
yi = 1.712yi−1 − 0.81yi−2 + xi
The unit-sample response hi equals yi when xi = di and assuming zero initial conditions (hi = 0 for
i < 0).
i=0
=0 =0 =1
z}|{ z}|{ z}|{
h0 = 1.712 h −1 −0.81 h −2 + d 0 = 1

i=1
=1 =0 =0
z}|{ z}|{ z}|{
h1 = 1.712 h 0 −0.81 h −1 + d 1 = 1.712

i=2
=1.712 =1 =0

z}|{ z}|{ z}|{


h2 = 1.712 h 1 −0.81 h 0 + d 1 = 2.121

Problem 8.7 (ARMA filter from difference equation) Draw two ARMA digital filters that correspond
to the difference equation
yi = 2r cos(ωo )yi−1 − r 2 yi−2 + xi − r cos(ωo )xi−1

for r = 0.9 and ωo = π/10. The first structure is configured as an initial MA filter that connects to an
AR filter. The second structure is configured as an initial AR filter that connects to an MA filter.

(ans: Simplify the difference equation by computing the coefficient values, as

yi = ai yi−1 + a2 yi−2 + b0 xi + b1 xi−1

© 2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
8.1. PROBLEMS 91
where
a1 = 2r cos(ωo ) = 2(0.9) cos(π/10) = 1.712
a2 = −r2 = −0.81
b0 = 1
b1 = −r cos(ωo ) = −0.9 cos(π/10) = −0.856
gives
yi = 1.712yi−1 − 0.81yi−2 + xi − 0.856xi−1
The direct and efficient block diagrams of the ARMA filter with MA followed by AR:
X
i + + y
i

δ δ
−0.856 1.712

−0.81

X
i + y
i

δ δ
−0.856 1.712

−0.81

The direct and efficient block diagrams of the ARMA filter with AR followed by MA:
X
i + + y
i

δ δ
1.712 −0.856

−0.81

X
i + +
y
i

δ
1.712 −0.856

−0.81

© 2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
92 CHAPTER 8. DIGITAL SIGNAL PROCESSING

Problem 8.8 (ARMA filter from difference equation) Draw two ARMA digital filters that correspond
to the difference equation

yi = 2 cos(ωo )yi−1 − yi−2 + sin(ωo )xi−1

for r = 0.9 and ωo = π/10. The first structure is configured as an initial MA filter that connects to an
AR filter. The second structure is configured as an initial AR filter that connects to an MA filter.
(ans: Simplify the difference equation by computing the coefficient values, as

yi = ai yi−1 + a2 yi−2 + b0 xi + b1 xi−1

where

a1 = 2r cos(ωo ) = 2(0.9) cos(π/10) = 1.712

a2 = −1

b0 = 0

b1 = − sin(ωo ) = − sin(π/10) = −0.309


gives

yi = 1.712yi−1 − yi−2 − 0.309xi−1

The block diagram of the ARMA filter with MA followed by AR:

X
i + y
i

δ δ
−0.309 1.712

−1

The direct and efficient block diagrams of the ARMA filter with AR followed by MA:

© 2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
8.1. PROBLEMS 93

X
i +

δ δ
y
1.712 −0.309
i

−1

X
i +

δ
1.712 −0.309
i

−1

Problem 8.9 (Difference equation from ARMA filter block diagram) Write the difference equation
of the digital filter shown in Figure 8.3.
xi yi

δ δ
1.2

δ δ
-0.5

Figure 8.3: ARMA filter for Problem 8.9.

(ans:
yi = 1.2yi−1 − 0.5yi−2 + xi−2
)

Problem 8.10 (Difference equation from efficient ARMA filter block diagram) Write the difference
equation of the digital filter shown in Figure 8.4.
(ans:
yi = 1.2yi−1 − 0.5yi−2 + xi + 1.2xi−1 − 0.5xi−2
)

© 2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
94 CHAPTER 8. DIGITAL SIGNAL PROCESSING

xi yi

δ
1.2 1.2

δ
-0.5 -0.5

Figure 8.4: ARMA filter for Problem 8.10.

Problem 8.11 (Verification of cosine sequence generator) Verify Example ?? that the difference equa-
tion
yi = 2 cos(ωo )yi−1 − yi−2 + xi − cos(ωo )xi−1
has unit-sample response
hi = cos(ωo i) for 0 ≤ i ≤ 2
for ωo = π/8. Assume zero initial conditions and compare hi with cos(ωo i) for 0 ≤ i ≤ 2.
(ans: Simplify the difference equation by computing the coefficient values, as

yi = ai yi−1 + a2 yi−2 + xi
where
a1 = 2 cos(π/8) = 1.848
a2 = −1
b0 = 1
b1 = − cos(π/8) = −0.924
gives
yi = 1.848yi−1 − yi−2 + xi − 0.924xi−1
The unit-sample response hi equals yi when xi = di and assuming zero initial conditions (hi = 0 for
i < 0).
i=0
=0 =0 =1 =0
z}|{ z}|{ z}|{ z}|{
h0 = 1.848 h −1 − h −2 + d 0 −0.924 d −1 = 1

Verification:

cos(0) = 1

i=1
=1 =0 =0 =1
z}|{ z}|{ z}|{ z}|{
h1 = 1.848 h 0 − h −1 + d 1 −0.924 d 0 = 0.924

Verification:

cos(π/8) = 0.924

© 2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
8.1. PROBLEMS 95

i=2
=0.924 =1 =0 =0
z}|{ z}|{ z}|{ z}|{
h2 = 1.848 h 1 − h 0 + d 2 −0.924 d 1 = 0.708

Verification: n

cos(2π/8) = cos(π/4) = 0.707 (agreement with 3-place precision computations)

Problem 8.12 (Sine sequence generator) Verify that the difference equation

yi = 2 cos(ωo )yi−1 − yi−2 + sin(ωo )xi−1


has unit-sample response
hi = sin(ωo i) for 0 ≤ i ≤ 2
for ωo = π/8. Assume zero initial conditions and compare hi with sin(ωo i) for 0 ≤ i ≤ 2.
(ans: Simplify the difference equation by computing the coefficient values, as

yi = ai yi−1 + a2 yi−2 + xi
where
a1 = 2 cos(π/8) = 1.848
a2 = −1
b0 = 0
b1 = sin(π/8) = 0.383
gives
yi = 1.848yi−1 − yi−2 + +0.383xi−1
The unit-sample response hi equals yi when xi = di and assuming zero initial conditions (hi = 0 for
i < 0).
i=0
=0 =0 =0
z}|{ z}|{ z}|{
h0 = 1.848 h −1 − h −2 +0.383 d −1 = 0

Verification:

sin(0) = 0

i=1
=0 =0 =1
z}|{ z}|{ z}|{
h1 = 1.848 h 0 − h −1 +0.383 d 0 = 0.383

© 2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
96 CHAPTER 8. DIGITAL SIGNAL PROCESSING

Verification:

sin(π/8) = 0.383

i=2
=0.383 =0 =0
z}|{ z}|{ z}|{
h2 = 1.848 h 1 − h 0 +0.383 d 1 = 0.708

Verification:

sin(π/4) = 0.707 (agreement with 3-place precision)

© 2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
8.2. MATLAB PROJECTS 97

8.2 Matlab Projects


Project 8.1 (MA digital filter) Using Example 16.39 as a guide, compose a Matlab script to implement
a general MA digital filter. Verify your program by computing 10 samples of the unit-sample response
(recall xi = di ) of a five-sample averager defined by

4
yi = hj xi−j for 0 ≤ i ≤ 9
j=0

(ans: MA filter function.


function y = f_MA_filter(x,h)
mem = zeros(size(h)); % assign and initialize memory array
ny = length(x)+ length(h)-1; % length of output
y = zeros(1,ny); % assign output array
for i = 1:length(x)
mem(2:length(mem)) = mem(1:length(mem)-1); % shift memory
mem(1) = x(i); % x(i) -> first mem value
y(i) = sum(h.*mem); % sum of inner product
end
for i = length(x)+1:ny
mem(2:length(mem)) = mem(1:length(mem)-1); % shift memory
mem(1) = 0; % 0 -> first mem value
y(i) = sum(h.*mem); % sum of inner product
end
Matlab script.
x = [ 1 zeros(1,9) ]; % define unit-sample sequence
ix = 0:length(x)-1;
h = [ 1 1 1 1 1]/5; % define coefficients for 5-sample averager
ih = 0:length(h)-1;
y = f_MA_filter(x,h); % filter
iy =0:length(y)-1;
subplot(3,1,1),stem(ix,x)
title(’unit-sample sequence’); xlabel(’i’); ylabel(’x_i’)
subplot(3,1,2),stem(ih,h)
title(’coefficient sequence’); xlabel(’i’); ylabel(’h_i’)
subplot(3,1,3),stem(iy(1:10),y(1:10))
title(’ten samples of unit-sample response’); xlabel(’i’); ylabel(’y_i’)
unit−sample sequence
1

0.5
i
x

0
0 1 2 3 4 5 6 7 8 9
i
coefficient sequence
0.2

0.15

0.1
i
h

0.05

0
0 0.5 1 1.5 2 2.5 3 3.5 4
i
ten samples of unit−sample response
0.2

0.15

0.1
i
y

0.05

0
0 1 2 3 4 5 6 7 8 9
i

© 2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
98 CHAPTER 8. DIGITAL SIGNAL PROCESSING

Project 8.2 (MA filter implementing a linear interpolation) The unit-sample response of a three-sample
MA digital filter that acts as linear interpolator is given by

h0 = 0.5, h1 = 1, h2 = 0.5, hi = 0, otherwise


Compose a Matlab script extending Example 16.39 to show that this MA filter linearly interpolates
the values between specified sequence values. First, generate si = sin(ωo i) for ωo = 2π/32 and
0 ≤ i ≤ 64. The system input xi = si for even i, and xi = 0 for odd i. Using subplot(3,1,n),stem(.),
plot xi , yi and the error ϵi = si − yi+1 for 0 ≤ i ≤ 64.
(ans:
i = 0:64; % define i interval
omega = 2*pi/32; % define omega
s = sin(omega.*i); % generate signal
is = 0:length(s)-1;
x= zeros(size(s)); % start with zeros
for i=2:2:length(s)
x(i) = s(i); % define even values
end
subplot(3,1,1),stem(is,x)
title(’input sequence’); xlabel(’i’); ylabel(’x_i’)
h = [.5 1 .5]; % interpolation coefficients
y = f_MA_filter(x,h); % filter
iy =0:length(y)-1;
subplot(3,1,2),stem(iy,y)
title(’output sequence’); xlabel(’i’); ylabel(’y_i’)
eps = zeros(size(s)); % declare error
for i=1:length(s)
eps(i) = s(i) - y(i+1); % error with delayed output
end
subplot(3,1,3),stem(is,eps)
title(’error sequence’); xlabel(’i’); ylabel(’\epsilon_i’)

input sequence
1

0.5

0
i
x

−0.5

−1
0 10 20 30 40 50 60 70
i
output sequence
1

0.5

0
i
y

−0.5

−1
0 10 20 30 40 50 60 70
i
error sequence
0.1

0.05

0
εi

−0.05

−0.1
0 10 20 30 40 50 60 70
i

© 2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
8.2. MATLAB PROJECTS 99

Project 8.3 (MA matched filter) Using Example 16.39 as a guide, compose a Matlab script to com-
pute the output of a MA filter whose filter coefficient sequence hi equals the input sequence xi in time-
reversed order. For example, if x0 = 1, x1 = 2, and x2 = 3, then h0 = 3, h1 = 2, and h2 = 1. Such
a filter is called a matched filter. The output sequence of a matched filter is symmetric about the time
point at which the entire signal sequence is in the MA filter (about i = 2).
Demonstrate this matched filter operation by specifying your favorite set of five values - not all equal
and some less than zero - for hi for 0 ≤ i ≤ 4 and compute the output. The matched filter is the basis
for the matched processor for detecting data signals in the presence of noise, described in Chapter 10.
(ans:
x = 1:5; % define signal sequence
h = 5:-1:1;
ny = length(x) + length(h) - 1; % define matched filter coef sequence
xp= [x zeros(1,length(h)-1)]; % define signal sequence for plotting
hp= [h zeros(1,length(x)-1)]; % define matched filter coef sequence for plotting
i = 0:length(hp)-1;
subplot(3,1,1),stem(i,xp)
title(’input sequence’); xlabel(’i’); ylabel(’x_i’)
subplot(3,1,2),stem(i,hp)
title(’matched-filter corefficient sequence’); xlabel(’i’); ylabel(’h_i’)
y = f_MA_filter(x,h); % filter
subplot(3,1,3),stem(i,y)
title(’output sequence’); xlabel(’i’); ylabel(’y_i’)

input sequence
6

4
xi

0
0 1 2 3 4 5 6 7 8
i
matched−filter corefficeint
sequence
6

4
hi

0
0 1 2 3 4 5 6 7 8
i
output
sequence
60

40
yi

20

0
0 1 2 3 4 5 6 7 8
i

© 2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
100 CHAPTER 8. DIGITAL SIGNAL PROCESSING

Project 8.4 (Cascading MA filters) Compose a Matlab script that cascades two MA filters with the
output of the first forming the input to the second. Verify your program by computing the unit-sample
response of the cascaded connection of two identical three-sample linear interpolators.
(ans: The output of the second MA filter is the convolution of the interpolation filter unit-sample re-
sponse convolved with itself.

x = [ 1 zeros(1,9) ]; % define unit-sample sequence


ix = 0:length(x)-1;
subplot(3,1,1),stem(ix,x)
title(’unit-sample sequence’); xlabel(’i’); ylabel(’x_i’)
h = [.5 1 .5]; % interpolation coefficients
y1 = f_MA_filter(x,h); % first MA filter
iy1 = 0:length(y1)-1;
subplot(3,1,2),stem(iy1,y1)
title(’first MA filter output sequence’); xlabel(’i’); ylabel(’y1_i’)
y2 = f_MA_filter(y1,h); % second MA filter
iy2 = 0:length(y2)-1;
subplot(3,1,3),stem(iy2,y2)
title(’second MA filter output sequence’); xlabel(’i’); ylabel(’y2_i’)

unit−sample
sequence
1

0.5
xi

0
0 1 2 3 4 5 6 7 8 9
i
first MA filter output
sequence
1
y1i

0.5

0
0 2 4 6 8 10
12 i
second MA filter output
1.5 sequence

1
y2i

0.5

0
0 2 4 6 8 10 12
14
i

© 2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
8.2. MATLAB PROJECTS 101

Project 8.5 (AR digital filter) Using Example 16.40 as a guide, compose a Matlab script to implement
a general AR digital filter. Verify your program by computing hi for 0 ≤ i ≤ 50 for the first-order AR
filters following coefficients.

1. a = −0.9

2. a = 1

3. a = 1.1

4. a = 10

(ans: This problem displays four plots per figure and uses axis command. The solution for the problem
when all y values are equal is given.

AR function:
function y = f_AR_filter(x,a,ny)
nx = length(x);
mem = zeros(size(a)); % assign and initialize memory array
nm = length(mem); % memory size
y = zeros(1,ny); % assign output array
for i = 1:nx
y(i) = sum(a.*mem) + x(i); % sum of inner product + input
mem(2:nm) = mem(1:nm-1); % shift memory
mem(1) = y(i); % y(i) -> first mem value
end
for i = nx+1:ny % response when input exhausted
y(i) = sum(a.*mem); % sum of inner product
mem(2:nm) = mem(1:nm-1); % shift memory
mem(1) = y(i); % y(i) -> first mem value
end

Matlab script
clear
x = 1; % define input-sample sequence
ny = 51; % output sequence size
a = -0.9; % first-order coefficient
y = f_AR_filter(x,a,ny);
subplot(2,2,1),stem(y) % plot output (unit-sample response)
axis([0 51 1.1*min(y) 1.1*max(y)])
str =[’a= ’ num2str(a)];
title(str); xlabel(’i’); ylabel(’y_i’)
a = 1; % first-order coefficient
y = f_AR_filter(x,a,ny);
subplot(2,2,2),stem(y) % plot output (unit-sample response)
axis([0 50 1.1*min(0,min(y)) 1.1*max(y)]) % solves problem when all y vals are equal
str =[’a= ’ num2str(a)];
title(str); xlabel(’i’); ylabel(’y_i’)
a = 1.1; % first-order coefficient
y = f_AR_filter(x,a,ny);
subplot(2,2,3),stem(y) % plot output (unit-sample response)
axis([0 51 1.1*min(y) 1.1*max(y)])
str =[’a= ’ num2str(a)];
title(str); xlabel(’i’); ylabel(’y_i’)
a = 10; % first-order coefficient
y = f_AR_filter(x,a,ny);

© 2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
102 CHAPTER 8. DIGITAL SIGNAL PROCESSING

subplot(2,2,4),stem(y) % plot output (unit-sample response)


axis([0 51 1.1*min(y) 1.1*max(y)])
str =[’a= ’ num2str(a)];
title(str); xlabel(’i’); ylabel(’y_i’)
a= −0.9 a= 1
1 1

0.5 0.8

0.6
yi

yi
0
0.4
−0.5
0.2

0
0 10 20 30 40 50 0 10 20 30 40 50
i 49
i
a= 1.1 x 10 a= 10

120 10

100
8
80
6
i

yi
y

60
4
40

20 2

0 10 20 30 40 50 0 10 20 30 40 50
i i

© 2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
8.2. MATLAB PROJECTS 103

Project 8.6 (Cascading first-order AR digital filters) Compose a Matlab script that cascades two AR
filters with the output of the first forming the input to the second. to the unit-sample response of the
cascaded connection of two identical first-order AR systems with a = 0.95.
(ans: Matlab script that plots index and output values to start plot at i = 0.
clear
x = 1; % define input-sample sequence
ny = 101; % output sequence size
i = 0:ny-1; % define i index
a = 0.95; % first-order coefficient
y1 = f_AR_filter(x,a,ny);
subplot(2,1,1),stem(i,y1) % plot output (unit-sample response)
axis([0 ny-1 1.1 *min(y1) 1.1*max(y1)])
str =[’Output of first AR filter with a= ’ num2str(a)];
title(str); xlabel(’i’); ylabel(’y1_i’)
y2 = f_AR_filter(y1,a,ny);
subplot(2,1,2),stem(i,y2) % plot output (unit-sample response)
axis([0 ny-1 1.1 *min(y2) 1.1*max(y2)])
str =[’Output of second AR filter with a= ’ num2str(a)];
title(str); xlabel(’i’); ylabel(’y2_i’)

Output of first AR filter with a= 0.95

0.8

0.6
i
y1

0.4

0.2

0 10 20 30 40 50 60 70 80 90 100
i

Output of second AR filter with a= 0.95


8
7
6
5
i
y2

4
3
2
1
0 10 20 30 40 50 60 70 80 90 100
i

© 2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
104 CHAPTER 8. DIGITAL SIGNAL PROCESSING

Project 8.7 (Second-order AR digital filter) Compose a Matlab script to compute and plot in one fig-
ure the hi for 0 ≤ i ≤ 50 for the second-order AR filters having the following coefficients.
1. r = 0.9, ω = π/8
2. r = 1.1, ω = π/8
3. r = 0.9, ω = 0
(ans: A second-order filter is implemented by defining the a coefficient array with two elements that is
applied to that f_AR_filter function.
clear
x = 1; % define input sequence
ny = 51; % output sequence size
i = 0:ny-1; % define i index

r = 0.9; % radius (damping) term


omega = pi/8; % frequency
a = [2*r*cos(omega) -rˆ2]; % second-order feedback coefficient array
y = f_AR_filter(x,a,ny);
subplot(3,1,1),stem(i,y) % plot output
str =[’Output of second-order AR filter with r= ’ num2str(r) ’ and \omega = ’ num2str(omega)];
title(str); xlabel(’i’); ylabel(’y1_i’)
axis([0 50 1.1*min(y) 1.1*max(y)])

r = 1.1; % radius (damping) term


omega = pi/8; % frequency
a = [2*r*cos(omega) -rˆ2]; % second-order feedback coefficient array
y = f_AR_filter(x,a,ny);
subplot(3,1,2),stem(i,y) % plot output
str =[’Output of second-order AR filter with r= ’ num2str(r) ’ and \omega = ’ num2str(omega)];
title(str); xlabel(’i’); ylabel(’y2_i’)
axis([0 50 1.1*min(y) 1.1*max(y)])

r = 0.9; % radius (damping) term


omega = 0; % frequency
a = [2*r*cos(omega) -rˆ2]; % second-order feedback coefficient array
y = f_AR_filter(x,a,ny);
subplot(3,1,3),stem(i,y) % plot output
str =[’Output of second-order AR filter with r= ’ num2str(r) ’ and \omega = ’ num2str(omega)];
title(str); xlabel(’i’); ylabel(’y3_i’)
axis([0 50 1.1*min(y) 1.1*max(y)])

Output of second−order AR filter with r= 0.9 and ω = 0.3927


2

1
y1i

0
0 5 10 15 20 25 30 35 40 45 50
i
Output of second−order AR filter with r= 1.1 and ω = 0.3927
300
200
100
y2i

0
−100

0 5 10 15 20 25 30 35 40 45 50
i
Output of second−order AR filter with r= 0.9 and ω = 0
4
3
y3i

2
1

0 5 10 15 20 25 30 35 40 45 50
i

© 2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
8.2. MATLAB PROJECTS 105

Project 8.8 (Second-order ARMA filter) Using Example 16.41 as a guide, compose Matlab code to
implement an ARMA system that has
hi = sin(ωo i) for 0 ≤ i ≤ 64
for ωo = π/8. Hint: the difference equation is
yi = 2 cos(ωo )yi−1 − yi−2 + sin(ωo )xi−1 for 0 ≤ i ≤ 64
Using subplot(3,1,n),stem(.), plot hi computed directly from the sine function, yi , and the error hi − yi .
(ans:
x = 1; % define input-sample sequence
ny = 65; % output sequence size
i = 0:ny-1; % define i index
omega = pi/8; % radian frequency

h = sin(omega.*i);
subplot(3,1,1);stem(i,h) % plot sine sequence
str =[’sine sequence with \omega = ’ num2str(omega)];
title(str); xlabel(’i’); ylabel(’h_i’)
axis([0 64 1.1*min(y) 1.1*max(y)])

b = [0 sin(omega)]; % second-order MA filter coefficient array


y1 = f_MA_filter(x,b); % MA component - feeds into AR filter
a = [2*cos(omega) -1]; % second-order feedback coefficient array
y = f_AR_filter(y1,a,ny); % AR filter
subplot(3,1,2);stem(i,y) % plot ARMA output (unit-sample response)
str =[’Output of second-order ARMA filter with r=1 and \omega = ’ num2str(omega)];
title(str); xlabel(’i’); ylabel(’y_i’)
axis([0 64 1.1*min(y) 1.1*max(y)])

err = h-y; % compute error


subplot(3,1,3);stem(i,err) % plot error
str =[’error sequence’];
title(str); xlabel(’i’); ylabel(’\epsilon_i’)
axis([0 64 1.1*min(err) 1.1*max(err)])
sine sequence with ω = 0.3927
1
0.5
0
hi

−0.5
−1
0 10 20 30 40 50 60
i
Output of second−order ARMA filter with r=1 and ω = 0.3927
1
0.5
0
yi

−0.5
−1
0 10 20 30 40 50 60
i
−15 error sequence
x 10
2
1
εi

0
−1
−2
0 10 20 30 40 50 60
i

© 2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.
106 CHAPTER 8. DIGITAL SIGNAL PROCESSING

© 2015 Cengage Learning. All Rights Reserved. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part.

You might also like