166 Solutions Manual for Real Time Embedded Systems, 2 Edition
Chapter 15 Solutions
Solution 18.1, Consider the following digital filter, yn)=(x(n)-x(n-2))/2
Part a) Using the Z-transform, we derive general expressions forthe gain and phase of the filter.
L 5
Phase arg(H()) = are) for 2= els
Part b) ALDC 2, 0 gain-O and phase~O At 60 Hz2~1, so gain~1 and the phase~0
Solution 152. Design 2 one pole high Q, fixed-point digital high pss filter. Let f,=100 Hz
Part a) Show the pole/zero plot of the filter
et jndepten 09
(e=09) 1-098 rieaeostm
Part c) ‘yln) -0.9y(n-1) = x(n) -x(n-1)
y(n)= x(n) - x(n) + 0 9y(n-1)
Gain ae Svea) =
got, '
He) Ciz09) =19 1.0526 So, we scale the x terms by 0.95
¥(ny" 0.95x(n) - 0.95x(n-1) + 0. 9y(ne1)
ar Shows fd on vern ft er
‘¥(0)™ (19x(n) « 19x(n-1) + 18y(n-1)}/20
Solution 153. Consier the use ofthe Z-transform inthe design and analysis of dial filters,
Past a) The definition ofthe Z-vansform
X(2)= J) x(n)
Part b) We use the Z-ransform on a median filter because this iter is nonlinear
Part c) Use the Z-ransform to determine the DC gain and phase ofthe following digital filter
¥10) =x(0)-x(0-2}¢ (01)
2
1-
Ma = 2
1-2"
‘We can use L*Hospital’s Ld to calculate the DC gain.
2:
Solution 15.4, Design a 10 Hz digital low pass filter with a sampling
rate of 1000Hz Make the gain at DC equal to one, and the gain at
10Hz 0 707. A simple low pass filter with adjustable cutoff is
y(n) =(x(n)-x(n-k) Vk +y(n-1)
to get the cutoff at about 10 Hz we need the first notch at about 20 Hz
(One half the sampling rate will be SOO Hz. The gain versus frequency
is plotted below. This analysis shows that ak=45 yields a 10 Hz gain at
about 0.7. The first notch is 1000/45, which equals 222 Ha
Part a) Show the pole/zero plot of your filter. Same as section 15.7,
with 44 zeros placed at 45 equally spaced positions, except at 2=1Jonathan W. Valvano 167
10 Hz Low pass filter
g
6
0 40 20 30 40
frequency
art) Show the H(2) wansform
H@)=(1-2 7451-2")
Part c) Show the floating-point version of the digital filter.
y(n) =(xtn)-x(-45))/45 +y(0-1)
Part d) Show the fixed-point version of the digital filter.
y(n) *(x(n)-x(n-45))/45 +y(r-1)
Solution 15.5. To get notches at 60 120, place zeros at 45° and 490° To get high Q, place poles near the zeros.
21 = cos(45)+ j sin(45)= 0 70714)*0 7071
12," c0s(45)- j sin(45) = 0 7071-j40 7071
237 cos(90) + j sin(90)
7470190), i
pi 0.9%2, = 0.63644)90 6364
2% 0.922 =0.63645*0 6364
240
-120
Pas? +222 n+
~0V22" +172? 082240729
ay NemmyNen2yXenz) (2? Ver Xe? +)
= PiMe= Pale PsKE—P,) ON Iz+ OBIE” +05)
N22" +1 712 ~0 siz? +0.7292"
Taking te inverse transform of H(), yields the iter
(0) = x0) -1 A142x(nr1) +2x{0-2)-} 8142x(0-3) #4) 2728 (0-11 Thy (0-2) #1.1455y(l) -0-7293(0-2)
Solving H(2) for 2-1, gives the gain at DC
Iev242-¥2+1 4-2
yet eveeet ta
MO Toons i7i-o8ni+0n9 3439-1702
To get DC gun of, we mutply x terms by 08712175
Yo} OBEN) 2a2hate) 21 MDh2) 1232103) “087124
wr 2tsBycet Tigi) #1 18ssyi)-0 NG)
Rewriting as a fixed-point filter, we get
Ho) = Fda) 282) btn 2) 1232143) #8712404)
+12728y(n-1)}-171 00y(n-2) +11455y(n-1) -7290y(n-2)10000-
= 1.1478
Solution 15.6. Same approach as Solution 15.4. k=45
Jonathan W. Valvano168 Solutions Manual for Real Time Embedded Systems, 2™ Edition
Solution 15.7. The general form this HPF filter is a constant term minus a LPF
et
‘yka)= xtn 92 x(n —i) = x(nem)-x(n-m-l)-x(nyfkeix(arkye+y(n-1)
arta) Consider the case with m=2, ke4 Itis a FIR, because there are no previous y tems
(0) = x(0-2) -(x(n}x(nel}ix(n-2)44n-3))4
Part b) Derive the H(2) transform of this filer. The averaging filter is
High Pass Fitter
eee
Solution 158.
Part a) We need t calelate the slew rate ofthe input AV/at = 2a B cos(2xf, where the maximum slew rate is
2efB ‘The maximum voltage error is BV = Vide * Bt = nf Bt
Patt b) The largest component of latency occurs while the software ran wit nterrups disabled
1) Redo the amount of ime te est uns with nts abled
‘Extra Question 15.9. The sampling rate of a real-time data acquisition system is 1000 Hz Assume there are large
ampltode noise components above 1000 Hz. There is also a large amplitude noise component at 125 Ha
Part ) Without changing the sampling rate, how do you remove aliasing?
Pat b) Show pole-zro plot for the design of a high-Q 125-Hz digital reject filter. Just draw the positions of the
poles and zeros. You do not have to caleulate the H(z) or show the filter equation
Extra Solution 159
Part a) Alasing is prevented using an analog $00 Hz LPF, the euto is selected at f
Part b) Put the zeros at 125-Hz and poles near it (ut inside)
fosoriz
00K;
-s00H2|Jonathan W. Valvano 169
Extra Question 15.10. The sampling rate ofa real-time data acquisition system is 2000 Ha Assume thee ae large
amplitude noise components above 2000 Hz. Ther is also a large amplitude noise component at 750 He.
Parta) Without changing the sampling rat, how do you remove aliasing? Put as much detail nto the space
provided
Part b) Show polezero plot forthe design of a high-Q 750-Hz digital reject filter. Just draw the positions ofthe
poles and zeros. You do not have to calculate the H(2) or show the filter equation
Extra Solution 15.10
Part) Aliasing is prevented using an analog 1000 Hz LPF, the eutoffis selected at f,
ar by Purthe ares at 750 and poles near tout ise)
oor
Extra Question 15.11. The goal of this problem isto implement the following, digital filter. The sampling rate is
1000H, and the ADC is a 12-bit signed -5 to +5V range converter. .
y(n) = 0.125x(n) + 0.75x(0-3) ~ 0.625y(n-2)
art a) Show the C code to implement this fixed-point equation that implements this filte. No Sloating point is
allowed. Choose integer constants that give an exact implementation with the smallest possible single denominator
‘Assume the input samples are 12-bit signed numbers (-2048 to +2047)
Part b) Calculate the DC gain of this filter
Extra Solution 15.11
The fixed-point equation that implements this ier The +4 implement rounding
¥) = (x) + 6x(0-3) Syn 2448
‘We willie 16-bit signed match because 12°2047 is less than 32767
Part)
Shore x{dls // zie aoe eat
short y(3]7 // filter outpaes
short iter (enort acs) |
Bia) = £1217 x12) = x(2)s (21 = x10} x10) = cater
yla) = yids yt) = yore
Sto) = tata) erniay = Seyea) + 4) /85
Feturn y10}7
,
Part) Calculate the DC gain ofthis fier
Yy=hl25x-+ 0.75 0.625y
¥ + 0.628y= 0.1254 + 0.75
1425 = 0.875.
DC gtinisyix = 0875/1625 = (718)(1348) = 7113 =0.538
Extra Question 15.12. The goal ofthis problem is to implement the following digital filter. The sampling rate is
1000, and the ADC isa 12-bit signed -5 to +5V range converter
y(n) = 0.375x(n) + 0.628x(n-2)- 0.5y(n-1)
Part a) Show the C code to implement this fixed-point equation that implements this filter. No floating point is
allowed. Choose integer constants that give an exact implementation with the smallest possible single denominator
‘Assume the input samples are 12-bit signed numbers (-2048 to +2047)
Part b) Calculate the DC gain ofthis filter
Jonathan W.Valvano170 Solutions Manual for Real Time Embedded Systems, 2" Edition
Extra Solution 15.12,
‘The fixed-point equation that implement this filter. The +4 implements rounding
y(n) = x(n) + Sx(n-2)— dy(n-1)=48
‘We will use 16-bit signed match because 12*2047 is less than 32767
Part)
short x(3}7 // 12-bit ADC data
short yi // filter output
short Fitter (shore data) {
(2) = x(a] eA) = x10}; x10) = datay
y= (3*x[0] 4 5*x(2) - ary + 4)/87
_ eee HO
Part b) Calculate the DC gain ofthis fier
y= 0378x + 0.625x— 05y
+ 05Sy= 0.375% + 0.6254
15y
DC gain is yx = 1/1.5"2/3 =0.667
Extra Question 15.13. Why do we place poles and zeros either onthe x-axis or as complex conjugate pais inthe 2-
plene?
Extra Solution 18.13 So the iter cooficients (and the filter output wil be real sumbers
Extra Question 15.14 Consider the discrete derivative y(n)=(x(n)-x(n-1))/At, where At is 1/f,,
Parta) Determine the H(2) transfer function fortis equation.
‘Part b) Draw a pole-2er plat ofthis funtion.
Past.c) Draw its gain versus frequency response assuming f=1000H2
Extra Solution 15.14. So the filter coefficients (and the filter output) will be real numbers.
arta) aking the transform ¥(2)=(X(2}-2°X¢2)/st, He2Y@VX(2) =(-2 Vt
Part b) Zero.azl poe at =0
Je pole at ==0 erecta
‘ingle zero at ==1 oe
eqwney te
a bought this new
spray, but Iean't get
Games "rid ofmy but
IW