Solutions Introduction to Signal Processing



Comments



Description

INTRODUCTION TOSignal Processing Solutions Manual Sophocles J. Orfanidis Department of Electrical & Computer Engineering Rutgers University, Piscataway, NJ 08855 [email protected] Copyright © 2010 by Sophocles J. Orfanidis Web page: www.ece.rutgers.edu/~orfanidi/i2sp Chapter 1 Problems Problem 1.1 The Nyquist interval is [−f s /2, f s /2]= [−4, 4] Hz. The 6 Hz frequency of the wheel lies outside it, therefore, it will be aliased with f − f s = 6 − 8 = −2 Hz. Thus, the wheel will appear to be turning at 2 Hz in the opposite direction. If f s = 12, the Nyquist interval is [−6, 6]. Points on the wheel will appear to be moving up and down, with either positive or negative sense of rotation. For the other two sampling frequencies, the Nyquist interval is [−8, 8] or [−12, 12] Hz, and therefore, the original 6 Hz frequency lies in it and no aliasing will be perceived. Problem 1.2 The three terms of the signal correspond to frequencies f 1 = 1, f 2 = 4, and f 3 = 6 Hz. Of these, f 2 and f 3 lie outside the Nyquist interval [−2.5, 2.5]. Therefore, they will be aliased with f 2 −f s = 4 −5 = −1 and f 3 −f s = 6 −5 = 1 and the aliased signal will be: x a (t)= 10sin(2πt)+10sin(2π(−1)t)+5sin(2πt)= 5sin(2πt) To show that they have the same sample values, we set t = nT, with T = 1/f s = 1/5 sec. Then, x(nT)= 10sin(2πn/5)+10sin(8πn/5)+5sin(12πn/5) But, sin(8πn/5)= sin(2πn −2πn/5)= −sin(2πn/5) and sin(12πn/5)= sin(2πn +2πn/5)= sin(2πn/5) Thus, x(nT) = 10sin(2πn/5)−10sin(2πn/5)+5sin(2πn/5) = 5sin(2πn/5)= x a (nT). If f s = 10 Hz, then the Nyquist interval is [−5, 5] Hz and only f 3 lies outside it. It will be aliased with f 3 −f s = 6 −10 = −4 resulting in the aliased signal: x a (t)= 10sin(2πt)+10sin(8πt)+5sin(2π(−4)t)= 10sin(2πt)+5sin(8πt) Problem 1.3 Using the trig identity 2sinαsinβ = cos(α−β)−cos(α+β), we find: x(t) = cos(5πt)+4sin(2πt)sin(3πt)= cos(5πt)+2[cos(πt)−cos(5πt)] = 2cos(πt)−cos(5πt) The frequencies in the signal are f 1 = 0.5 and f 2 = 2.5 kHz. The Nyquist interval is [−1.5, 1.5] kHz, and f 2 lies outside it. Thus, it will be aliased with f 2a = 2.5 − 3 = −0.5 giving rise to the signal: 1 x a (t)= 2cos(2πf 1 t)−cos(2πf 2a t)= 2cos(πt)−cos(−πt)= cos(πt) A class of signals aliased with x(t) and x a (t) is obtained by replacing f 1 and f 2 by their shifted versions: f 1 +mf s , f 2 +nf s resulting in: x mn (t)= 2cos(πt +6πmt)−cos(πt −6πnt) Problem 1.4 Using a trig identity, we write x(t)= cos(8πt)+cos(10πt)+cos(2πt). The frequencies con- tained in x(t) are thus, 1 Hz, 4 Hz, and 5 Hz. If the sampling rate is 5 Hz, then the Nyquist interval is [−2.5, 2.5] Hz, and therefore, the 4 Hz and 5 Hz components lie outside it and will be aliased with the frequencies 4 −5 = −1 Hz and 5 −5 = 0 Hz, etc. Problem 1.5 Using trig identities we find: x(t)= sin(6πt) _ 1 +2cos(4πt) _ = sin(6πt)+sin(10πt)+sin(2πt) with frequency content: f 1 = 3, f 2 = 5, f 3 = 1 kHz. The Nyquist interval is [−2, 2] kHz, and the aliased frequencies are: f 1a = f 1 −f s = 3 −4 = −1, f 2a = f 2 −f s = 5 −4 = 1, f 3a = f 3 = 1 Thus, x a (t)= sin(−2πt)+sin(2πt)+sin(2πt)= sin(2πt) Problem 1.6 Use the trigonometric identity 2cos acos b = cos(a +b)+cos(a −b) three times to get x(t) = 2[cos(10πt)+cos(6πt)]cos(12πt) = cos(22πt)+cos(2πt)+cos(18πt)+cos(6πt) The frequencies present in this signal are f 1 = 11, f 2 = 1, f 3 = 9, and f 4 = 3 Hz. With a sampling rate of 10 Hz, only f 1 and f 3 lie outside the Nyquist interval [−5, 5] Hz, and they will be aliased with f 1 −f s = 11 −10 = 1 Hz and f 3 −f s = 9 −10 = −1 Hz. The aliased signal will be: x a (t) = cos(2π(1)t)+cos(2πt)+cos(2π(−1)t)+cos(6πt) = 3cos(2πt)+cos(6πt) To prove the equality of the samples, replace t = nT = n/10, because T = 1/f s = 1/10. Then, x(nT)= cos(22πn/10)+cos(2πn/10)+cos(18πn/10)+cos(6πn/10) But, cos(22πn/10)= cos(2πn+2πn/10)= cos(2πn/10) and similarly, cos(18πn/10)= cos(2πn− 2πn/10)= cos(2πn/10). Therefore, the sample values become 2 x(nT) = cos(2πn/10)+cos(2πn/10)+cos(2πn/10)+cos(6πn/10) = 3cos(2πn/10)+cos(6πn/10)= x a (nT) If f s = 12 Hz, then f 1 and f 3 will lie outside of [−6, 6] and will be aliased with 11 −12 = −1 and 9 −12 = −3. The aliased signal will be: x a (t) = cos(2π(−1)t)+cos(2πt)+cos(2π(−3)t)+cos(6πt) = 2cos(2πt)+2cos(6πt) Problem 1.7 We use the same technique as in the square-wave Example 1.4.6. At a sampling rate of 8 Hz, the signal frequencies of ¦1, 3, 5, 7, 9, 11, 13, 15, . . . ¦ will be aliased with: ¦1, 3, −3, −1, 1, 3, −3, −1, . . . ¦ Therefore only sin(2πt) and sin(6πt) terms will appear in the aliased signal. Thus, we write it in the form: x a (t)= Bsin(2πt)+Csin(6πt) To determine B and C, we demand that x a (t) and x(t) agree at the sampling instants t = nT = n/8, because T = 1/f s = 1/8 sec. Therefore, we demand Bsin(2πn/8)+Csin(6πn/8)= x(n/8) Setting n = 1, 2, we get two equations Bsin(2π/8)+Csin(6π/8)= x(1/8)= 0.5 Bsin(4π/8)+Csin(12π/8)= x(2/8)= 1 ⇒ B 1 √ 2 +C 1 √ 2 = 0.5 B −C = 1 The values for x(1/8) and x(2/8) were obtained by inspecting the triangular waveform. Solving for B and C, we find: B = √ 2 +2 4 , C = √ 2 −2 4 Problem 1.8 For f s = 5 kHz, we have: x a (t)= sin(2πf 1 t) For f s = 10 kHz, we have: x a (t)= 2sin(2πf 1 t)+sin(2πf 2 t) 3 Fig. P1.1 Parts (a,b) of Problem 1.8. Problem 1.9 The audible and inaudible parts are: x(t)= sin(10πt)+sin(20πt) . ¸, . audible +sin(60πt)+sin(90πt) . ¸, . inaudible The frequencies of the four terms and their aliased versions are: f A = 5 f B = 10 f C = 30 f D = 45 ⇒ f Aa = 5 f Ba = 10 f Ca = 30 −40 = −10 f Da = 45 −40 = 5 a. When there is no prefilter the aliased signal at the output of the reconstructor will be: y a (t)= sin(10πt)+sin(20πt)+sin(−20πt)+sin(10πt)= 2sin(10πt) b. When there is a perfect prefilter, the f C , f D components are removed prior to sampling thus, the sampled and reconstructed signal will remain unchanged, that is, the audible part of x(t): y a (t)= sin(10πt)+sin(20πt) c. The attenuations introduced by the practical prefilter shown in Fig. P1.2 are obtained by determining the number of octaves to the frequencies f C , f D and multiplying by the filter’s attenuation of 48 dB/octave: log 2 _ f C f s /2 _ = log 2 _ 30 20 _ = 0.585 ⇒ A C = 48 ×0.585 = 28.08 dB log 2 _ f D f s /2 _ = log 2 _ 45 20 _ = 1.170 ⇒ A D = 48 ×1.170 = 56.16 dB and in absolute units: 4 ¦H C ¦ = 10 −A C /20 = 10 −28.08/20 = 0.0394 ¦H D ¦ = 10 −A D /20 = 10 −56.16/20 = 0.0016 Thus, the resulting reconstructed signal will be: y a (t) = sin(10πt)+sin(20πt)+¦H C ¦ sin(−20πt)+¦H D ¦ sin(10πt) = 1.0016sin(10πt)+0.9606sin(20πt) which agrees closely with the audible part of x(t). 10 30 20 45 48 dB/octave Analog Prefilter kHz f H(f) 0 A B C D Fig. P1.2 Prefilter specifications of Problem 1.9. Problem 1.10 The Fourier series expansion of the periodic function s(t) is: s(t)= ∞ _ m=−∞ c m e 2πjmt/T , c m = 1 T _ T/2 −T/2 s(t)e −2πjmt/T dt But within the basic period [−T/2, T/2], s(t) equals δ(t). Thus, c m = 1 T _ T/2 −T/2 δ(t)e −2πjmt/T dt = 1 T Using the delta function integral representation: _ ∞ −∞ e −2πjft dt = δ(f) we find: S(f) = _ ∞ −∞ s(t)e −2πjft dt = 1 T ∞ _ m=−∞ _ ∞ −∞ s(t)e −2πj(f−mfs)t dt = 1 T ∞ _ m=−∞ δ(f −mf s ) Problem 1.11 This is simply the Fourier series expansion of the periodic function X(f) in the variable f, and x(nT) are the Fourier series expansion coefficients calculated by integrating over one period, that is, over [−f s /2, f s /2]. 5 Problem 1.12 Write x(t)= 0.5e 2πjf0t +0.5e −2πjf0t , with Fourier transform: X(f)= 0.5δ(f −f 0 )+0.5δ(f +f 0 ) Its replication gives the spectrum of the sampled signal: X(f) = 1 T ∞ _ m=−∞ X(f −mf s )= 1 2T ∞ _ m=−∞ _ δ(f −mf s −f 0 )+δ(f −mf s +f 0 ) _ = 1 2T ∞ _ m=−∞ _ δ(f −mf s −f 0 )+δ(f +mf s +f 0 ) _ where in the second term, we changed the summation index from m to −m. Problem 1.13 We have for the complex sinusoid, the Laplace, Fourier, and magnitude spectra: x(t)= e −at e 2πjf0t = e −(a−2πjf0)t , t ≥ 0 X(s)= 1 s +a −2πjf 0 X(f)= 1 a +2πj(f −f 0 ) ⇒ ¦X(f)¦ 2 = 1 a 2 +4π 2 (f −f 0 ) 2 The length-L sampled signal x(nT)= e −(a−2πjf0)nT , n = 0, 1, . . . , L −1 has spectrum: X L (f) = L−1 _ n=0 x(nT)e −2πjfnT = L−1 _ n=0 e −(a+2πj(f−f0))nT = 1 −e −(a+2πj(f−f0))LT 1 −e −(a+2πj(f−f0))T with magnitude spectrum: ¦ X L (f)¦ 2 = 1 −2e −aLT cos _ 2π(f −f 0 )LT _ +e −2aLT 1 −2e −aT cos _ 2π(f −f 0 )T _ +e −2aT In the limit L → ∞, we have e −aLT → 0 and obtain the sampled spectrum of the infinitely long signal: X(f)= ∞ _ n=0 x(nT)e −2πjfnT = 1 1 −e −(a+2πj(f−f0))T with magnitude spectrum: ¦ X(f)¦ 2 = 1 1 −2e −aT cos _ 2π(f −f 0 )T _ +e −2aT The continuous time limit T →0 of X(f) gives rise to the analog spectrum: 6 lim T→0 T X(f)= lim T→0 T 1 −e −(a+2πj(f−f0))T = 1 a +2πj(f −f 0 ) = X(f) Fig. P1.3 shows the required spectra. From the left graph, we see that as f s increases, the sampled spectrum agrees more closely with the analog spectrum within the Nyquist interval. From the right graph, we see that the spectrum of the truncated sampled signal has ripples that follow the general shape of X(f). As L →∞, the sampled spectrum X L (f) will tend to X(f), which is only an approximation of the true spectrum even within the Nyquist interval. Fig. P1.3 Spectra of analog, sampled, and windowed signals of Problem 1.13. In the case of real-valued signals, we will also get the spectral peaks at the negative frequency −f 0 . If f 0 is small, the peaks at :f 0 will influence each other somewhat, but apart from that the same conclusions can be drawn about the sampled signals. Problem 1.14 This is the same as Example 1.5.4. In units of dB per decade, the attenuations due to the signal and filter combine to give: A(f)= αlog 10 _ f f max _ +βlog 10 _ f f max _ = γlog 10 _ f f max _ where γ = α+β. The requirement A(f s −f max )≥ A gives: γlog 10 _ f s −f max f max _ ≥ A ⇒ f s ≥ f max +f max 10 A/γ Problem 1.15 The first replica of X in (f), shifted to f s , will have spectrum: ¦X in (f −f s )¦ = 1 _ 1 + _ 0.1(f −f s ) _ 8 Its value at the passband frequency f pass = f max = 20 kHz will be: 7 ¦X in (f max −f s )¦ = 1 _ 1 + _ 0.1(f max −f s ) _ 8 This must be suppressed by A = 60 dB relative to ¦X in (f max )¦, thus, we require: −10log 10 ¸ ¸ ¸ ¸ ¸ X in (f max −f s ) X in (f max ) ¸ ¸ ¸ ¸ ¸ 2 = A ⇒ 10log 10 _ 1 + _ 0.1(f max −f s ) _ 8 1 +(0.1f max ) 8 _ = 60 which can be solved for f s to give f s = 132.52 kHz. Using the prefilter, we require that its passband attenuation be A pass = 1 dB at f pass = f max = 20 kHz, that is, −10log 10 ¦H(f max )¦ 2 = 10log 10 _ 1 +(f max /f 0 ) 6 _ = A pass which can be solved for f 0 to give f 0 = 25.05 kHz. The prefiltered signal that gets sampled is now ¦X(f)¦ = ¦H(f)X in (f)¦ = 1 _ 1 +(f/f 0 ) 6 1 _ 1 +(0.1f) 8 Its first replica ¦X(f −f s )¦ is required to be suppressed by A = 60 dB at f max −10log 10 ¸ ¸ ¸ ¸ ¸ X(f max −f s ) X(f max ) ¸ ¸ ¸ ¸ ¸ 2 = A, f f s f s -f max f max A |X( f max )| 0 |X( f s -f max )| |X( f max -f s )| = which gives the condition 10log 10 _ 1 + _ (f max −f s )/f 0 _ 6 1 +(f max /f 0 ) 6 · 1 + _ 0.1(f max −f s ) _ 8 1 +(0.1f max ) 8 _ = A (P1.1) It can be solved approximately by ignoring the +1 in the numerators, that is, 10log 10 __ (f max −f s )/f 0 _ 6 1 +(f max /f 0 ) 6 · _ 0.1(f max −f s ) _ 8 1 +(0.1f max ) 8 _ = 60 dB (P1.2) which gives f s = 80.1 kHz. The exact solution of Eq. (P1.1) is f s = 80.0633 kHz. The first factor in Eq. (P1.2) represents the stopband attenuation due to the filter, and the second the attenuation due to the signal. With f s = 80.1 kHz, we have 10log 10 _ 1 + _ (f max −f s )/f 0 _ 6 1 +(f max /f 0 ) 6 _ = A stop = 21.8 dB 10log 10 _ 1 + _ 0.1(f max −f s ) _ 8 1 +(0.1f max ) 8 _ = A−A stop = 38.2 dB Thus, the use of the prefilter enables us to reduce the sampling rate from 132 kHz to 80 kHz. Note also, that for large f, the spectrum ¦X(f)¦ follows the power law ¦X(f)¦ 2 = 1 1 +(f/f 0 ) 6 · 1 1 +(0.1f) 8 ≈ const. f 6 · const. f 8 = const. f 14 giving rise to an effective attenuation 8 −10log 10 ¦X(f)¦ 2 = γlog 10 f +const. where γ = 140 dB/decade, of which 60 dB/decade is due to the filter and 80 dB/decade due to the signal. The approximate method of Example 1.5.4 or Problem 1.14 would have given here f s = f max +10 A/γ f max = 20+20· 10 60/140 = 73.65 kHz, which is fairly close to the more accurate value of 80 kHz. Problem 1.16 The passband condition at f = f max = 20 kHz is: 10log 10 _ 1 +(f max /f 0 ) 2N _ = A pass (P1.3) which can be solved for f 0 in terms of N as follows: f 2N 0 = f 2N max r −1 , where r = 10 Apass/10 The antialiasing condition, replacing Eq. (P1.1), is now 10log 10 _ 1 + _ (f max −f s )/f 0 _ 2N 1 +(f max /f 0 ) 2N · 1 + _ 0.1(f max −f s ) _ 8 1 +(0.1f max ) 8 _ = A or, 1 + _ (f max −f s )/f 0 _ 2N 1 +(f max /f 0 ) 2N · 1 + _ 0.1(f max −f s ) _ 8 1 +(0.1f max ) 8 = 10 A/10 Replacing f 2N 0 by its expression above, we obtain 1 + _ (f max −f s )/f max _ 2N (r −1) r · 1 + _ 0.1(f max −f s ) _ 8 1 +(0.1f max ) 8 = 10 A/10 and solving for N, we have N = ln _ 10 A/10 rR(f s )−1 r −1 _ 2ln _ f s −f max f max _ (P1.4) where R(f s ) is defined by R(f s )= 1 +(0.1f max ) 8 1 + _ 0.1(f max −f s ) _ 8 Eq. (P1.4) gives the minimum prefilter order for a desired suppression level A and rate f s . With f s = 70 kHz, A = 60 dB, A pass = 1 dB, we find r = 10 Apass/10 = 10 0.1 = 1.259, 10 A/10 R(f s )= 657.918 and N = ln(3194.281) 2ln(50/20) = 4.403 ⇒ N = 5 We calculate also f 0 = f max /(r −1) 1/2N = 22.9 kHz. 9 Fig. P1.4 Butterworth order versus sampling rate. Problem 1.17 Figure P1.4 shows a plot of N given by Eq. (P1.4) as a function of f s for different choices of A. Notice the two data points on the A = 60 curve at f s = 70 and f s = 80 kHz that were computed in this and the last example. It is evident from this graph that the complexity of the prefilter increases with A, at any fixed f s ; and that it decreases with f s , for fixed A. Problem 1.18 Using the results of Problem1.14, we solve for the combined attenuation γ of signal and prefilter: A = γlog 10 _ f s −f max f max _ ⇒ where A = 60 dB, f s = 30 kHz and f max = 10 kHz. We find: γ = A log 10 _ f f max _ = 60 log 10 _ 30 −10 10 _ = 200 Because the signal has α = 80 dB/decade, we find the filter’s attenuation: β = γ −α = 200 −80 = 120 dB/decade which translates into a filter order: β = 20N ⇒ N = β/20 = 120/20 = 6 If we increase the sampling rate to 50 kHz, the combined attenuation will be γ = 100, which gives β = 100 −80 = 20 dB/decade and order N = β/20 = 1. Problem 1.19 This problem is the generalization of Prob. 1.15. If we do not use a prefilter, the requirement that the aliased components (of the 1st replica) be suppressed by A dB relative to the signal components can be expressed in the form: 10 ¦X in (f s −f max )¦ 2 ¦X in (f max )¦ 2 = 10 −A/10 Inserting the given expression for ¦X in (f)¦, we get the desired equation for f s in terms of A and f max : 1 +(f max /f a ) 2Na 1 + _ (f s −f max )/f a _ 2Na = 10 −A/10 If we use a Butterworth prefilter of order N: ¦H(f)¦ 2 = 1 1 +(f/f 0 ) 2N then, the 3-dB frequency f 0 is determined by requiring that at the edge of the passband the attenuation be B dB: ¦H(f max )¦ 2 = 1 1 +(f max /f 0 ) 2N = 10 −B/10 The filtered input that gets sampled will now have spectrum X(f)= H(f)X in (f), which gives: ¦X(f)¦ 2 = ¦H(f)¦ 2 ¦X in (f)¦ 2 = 1 1 +(f/f 0 ) 2N · 1 1 +(f/f a ) 2Na The antialiasing condition ¦X(f s −f max )¦ 2 = 10 −A/10 ¦X(f)¦ 2 gives now: 1 1 + _ (f s −f max )/f 0 _ 2N · 1 1 + _ (f s −f max )/f a _ 2Na = 10 −A/10 · 1 1 +(f max /f 0 ) 2N · 1 1 +(f max /f a ) 2Na Using the asymptotic forms of the spectra, valid for large f’s, that is, ¦X in (f)¦ 2 = 1 (f/f a ) 2Na , ¦H(f)¦ 2 = 1 (f/f 0 ) 2N the antialiasing condition would read: (f s −f max ) 2N f 2N 0 · (f s −f max ) 2Na f 2Na a = 10 −A/10 f 2N max f 2N 0 · f 2Na max f 2Na a which simplifies into: _ f s −f max f max _ 2(N+Na) = 10 A/10 or, f s = f max +f max 10 A/20(N+Na) It agrees with the results of Problem 1.14, with γ = α+β = 20N a +20N. For any fixed desired value of A, the limit N →∞ gives f s = f max +f max 10 A/20(N+Na) →f max +f max = 2f max In this case, the Butterworth filter resembles more and more a brick-wall filter with cutoff f max . 11 Problem 1.20 The linear relationship between N and A follows from the approximation of Problem 1.19: _ f s −f max f max _ 2(N+Na) = 10 A/10 or, 2(N+N a )log 10 _ f s −f max f max _ = A 10 Problem 1.21 The presence of P(f) is called the aperture effect. The replicas of X(f) embedded in X(f) will still be present, but they will be weighted by P(f). The need for using antialiasing prefilters to avoid overlapping of replicas remains the same. For a pulse of width τ, we have: ¦P(f)¦ = τ ¸ ¸ ¸ ¸ ¸ sin(πfτ) πfτ ¸ ¸ ¸ ¸ ¸ Therefore, the narrower the width τ the flatter the spectrum P(f). If τ < T, then P(f) will be essentially flat within the Nyquist interval, thus, leaving the central replica almost unchanged. Fig. P1.5 shows P(f) relative to the replicas of X(f) for the case τ = T/5. |P(f)| f s 5f s -5f s -f s 0 f Fig. P1.5 Butterworth order versus sampling rate. Problem 1.22 The stopband frequency of the postfilter is: f stop = f s − f c = 6 − 1 = 5 kHz. At this frequency, the attenuation of the staircase DAC is A DAC = −20log 10 ¸ ¸ ¸ ¸ ¸ sin(πf stop /f s ) πf stop /f s ¸ ¸ ¸ ¸ ¸ = 14.4 dB Thus, the stopband attenuation of the postfilter at f = f stop must be: A stop = A−A DAC = 40 −14.4 = 25.6 dB Problem 1.23 Using convolution in the time domain, we get: x a (t) = _ ∞ −∞ h(t −t ¹ )ˆ x(t ¹ ) dt ¹ = _ n x(nT) _ ∞ −∞ h(t −t ¹ )δ(t ¹ −nT) dt ¹ = _ n x(nT)h(t −nT) 12 Working in the frequency domain we have: X a (f)= H(f) X(f)= _ n x(nT) _ e −2πjfnT H(f) _ Using the delay theorem of Fourier transforms, we recognize the term in the bracket as the FT of h(t −nT). Thus, going to the time domain, we get: x a (t)= _ n x(nT)h(t −nT) Problem 1.24 Start with a complex sinusoid x(t)= e 2πjf0t . Its sampled spectrum will be: X(f)= 1 T ∞ _ m=−∞ X(f −mf s )= 1 T ∞ _ m=−∞ δ(f −f 0 −mf s ) The spectrum of the reconstructed analog signal will be then: X rec (f)= H(f) X(f)= 1 T ∞ _ m=−∞ H(f)δ(f −f 0 −mf s )= 1 T ∞ _ m=−∞ H(f 0 +mf s )δ(f −f 0 −mf s ) Taking inverse Fourier transforms, we find: x rec (t)= 1 T ∞ _ m=−∞ H(f 0 +mf s )e 2πj(f0+mfs)t Thus, f m = f 0 +mf s . Writing 1 T H(f m )= A m e jθm , so that A m = 1 T ¦H(f m )¦, θ m = arg H(f m ) we have: x rec (t)= ∞ _ m=−∞ A m e 2πj(f0+mfs)t+jθm Taking imaginary parts, we find for the real sinusoidal case: x rec (t)= ∞ _ m=−∞ A m sin _ 2π(f 0 +mf s )t +θ m _ Assuming ¦f 0 ¦ < f s /2, for the staircase reconstructor we have: 1 T H(f m )= sin(πf m T) πf m T e −jπfmT and because πf m T = πf 0 T +mπ, we have: 1 T H(f m )= sin(πf 0 T) πf m T e −jπf0T Thus, A m = sin(πf 0 T) πf m T , θ m = −πf 0 T For the ideal reconstructor, we have θ m = 0 and A m = 0 except at m= 0 where A 0 = 1, that is, A m = δ m . Thus, x rec (t)= ∞ _ m=−∞ δ m sin _ 2π(f 0 +mf s )t _ = sin(2πf 0 t) 13 Problem 1.25 Take the linear combination of the results of the single sinusoid case of Eq. (1.6.12). 14 Chapter 2 Problems Problem 2.1 The quantized values are: analog value quantized value DAC output 2.9 2 0 0 1 3.1 4 0 1 0 3.7 4 0 1 0 4 4 0 1 0 -2.9 -2 1 1 1 -3.1 -4 1 1 0 -3.7 -4 1 1 0 -4 -4 1 1 0 For the offset binary case, complement the first bit in this table. Problem 2.2 Filling the table, we have n x(n) x Q (n) offset binary 2’s complement 0 0.000 0.000 1 0 0 0 0 0 0 0 1 1.243 1.000 1 0 0 1 0 0 0 1 2 2.409 2.000 1 0 1 0 0 0 1 0 3 3.423 3.000 1 0 1 1 0 0 1 1 4 4.222 4.000 1 1 0 0 0 1 0 0 5 4.755 5.000 1 1 0 1 0 1 0 1 6 4.990 5.000 1 1 0 1 0 1 0 1 7 4.911 5.000 1 1 0 1 0 1 0 1 8 4.524 5.000 1 1 0 1 0 1 0 1 9 3.853 4.000 1 1 0 0 0 1 0 0 10 2.939 3.000 1 0 1 1 0 0 1 1 11 1.841 2.000 1 0 1 0 0 0 1 0 12 0.627 1.000 1 0 0 1 0 0 0 1 13 -0.627 -1.000 0 1 1 1 1 1 1 1 14 -1.841 -2.000 0 1 1 0 1 1 1 0 15 -2.939 -3.000 0 1 0 1 1 1 0 1 16 -3.853 -4.000 0 1 0 0 1 1 0 0 17 -4.524 -5.000 0 0 1 1 1 0 1 1 18 -4.911 -5.000 0 0 1 1 1 0 1 1 19 -4.990 -5.000 0 0 1 1 1 0 1 1 Problem 2.3 With R = 10 volts and e rms ≤ 10 −3 volts, we have using Q = √ 12e rms : 2 B = R Q = R √ 12e rms ≥ 10 √ 12 · 10 −3 which gives 15 B ≥ log 2 _ 10 √ 12 · 10 −3 _ = 11.495 Therefore, B = 12. The actual rms error will be e rms = R 2 B √ 12 = 10 2 12 √ 12 = 0.705 mvolt. The dynamic range will be 6B = 6 · 12 = 72 dB. Problem 2.4 At 44.1 kHz sampling rate, one minute of music has 60 sec containing 60×44100 samples. And, for two stereo channels, 2 × 60 × 44100 samples. If each sample is quantized with 16 bits, the total number of bits will be 2 ×60 ×44100 ×16 bits or, dividing by 8 we get the total number of bytes: 2 ×60 ×44100 ×16 8 bytes Dividing by 1024, we get kbytes and by another 1024, Mbytes: 2 ×60 ×44100 ×16 8 ×1024 ×1024 = 10.09 Mbytes Problem 2.5 Following similar steps as in the previous problem, we have for part (a): (3 ×60 sec)(16 channels)(48000 samples/sec)(20 bits/sample) (8 bits/byte)(1024 2 bytes/Mbyte) = 330 Mbytes that is, practically the entire hard disk of a typical home PC. For part (b), if in each channel we must perform N MAC = 35 operations on each sample, then these operations must be finished during the sampling interval T = 1/f s between samples: N MAC T MAC ≤ T ⇒ T MAC ≤ T N MAC = 1 N MAC f s which gives for the time per MAC: T MAC = 1 35 · 48 kHz = 0.595 · 10 −3 msec = 595 nsec This is plenty of time for today’s DSP chips, which can perform a MAC operation within 30–80 nsec. If a single DSP chip handles all 16 channels, then the total number of MACs that must be performed within the sampling interval T are 16N MAC . This gives: T MAC = 1 16 · 35 · 48 kHz = 595 16 = 37 nsec which is just within the capability of the fastest DSP chips. In practice, a typical professional digital recording system would require the processing and mixing of at least 32 channels. The above results suggest that one use at least two DSPs to multiplex the required operations. 16 Problem 2.6 The mean is m e = _ 0 −Q ep(e) de = 1 Q _ 0 −Q ede = − Q 2 and the variance: σ 2 e = E[(e −m e ) 2 ]= _ 0 −Q (e −m e ) 2 p(e) de = 1 Q _ 0 −Q _ e + Q 2 _ 2 de = Q 2 12 Problem 2.7 Solving Eq. (2.2.10) for L in terms of ΔB, we find: L = _ 2 2ΔB π 2p 2p +1 _ 1 2p+1 (P2.1) With ΔB = 15 and p = 1, 2, 3, we find: L = 1523, 116, 40 The oversampled audio rates will be, with f s = 44.1 kHz: Lf s = 67.164, 5.114, 1.764 MHz Problem 2.8 Using Eq. (P2.1) with ΔB = 7 bits and p = 1, 2, 3, we find: L = 38, 13, 8 The oversampled speech rates will be, with f s = 8 kHz: Lf s = 304, 104, 48 kHz Problem 2.9 Replacing b 1 = 1 −b 1 , we have: x Q = R(b 1 2 −1 +b 2 2 −2 +· · · +b B 2 −B −0.5) = R _ (1 −b 1 )2 −1 +b 2 2 −2 +· · · +b B 2 −B −0.5 _ = R _ −b 1 2 −1 +b 2 2 −2 +· · · +b B 2 −B _ where the first 2 −1 canceled the last −0.5. Problem 2.10 As an example, consider the polynomial of degree M = 3: B(z)= b 0 +b 1 z+b 2 z 2 +b 3 z 3 . Iterating the algorithm for i = 3, 2, 1, 0, we find: p = 0 p = ap +b 3 = b 3 p = ap +b 2 = ab 3 +b 2 p = ap +b 1 = a(ab 3 +b 2 )+b 1 = a 2 b 3 +ab 2 +b 1 p = ap +b 0 = a(a 2 b 3 +ab 2 +b 1 )+b 0 = a 3 b 3 +a 2 b 2 +ab 1 +b 0 = B(a) 17 Problem 2.11 /* pol.c - polynomial evaluator */ double pol(M, b, a) int M; double *b, a; int i; double p = 0; for (i=M; i>=0; i--) p = a * p + b[i]; return p; Problem 2.12 Consider the division of B(z) by (z −a): B(z)= (z −a)Q(z)+R where the quotient polynomial Q(z) must have degree M− 1, and the remainder R must be a constant. Indeed, setting z = a, gives R = b(a). So the objective of the algorithm is to compute R iteratively. Inserting the polynomial expressions we have: b M z M +b M−1 z M−1 +· · · +b 1 z +b 0 = (z −a)(q M−1 z M−1 +q M−2 z M−2 +· · · +q 1 z +q 0 )+R Equating like powers of z, we find: b M = q M−1 b M−1 = q M−2 −aq M−1 b M−2 = q M−3 −aq M−2 · · · b 1 = q 0 −aq 1 b 0 = R−aq 0 ⇒ q M−1 = b M q M−2 = aq M−1 +b M−1 q M−3 = aq M−2 +b M−2 · · · q 0 = aq 1 +b 1 R = aq 0 +b 0 Problem 2.13 For a polynomial of degree M = 3, B(z)= b 1 z +b 2 z 2 +b 3 z 3 , we iterate the algorithm for i = 3, 2, 1: p = 0 p = a(p +b 3 )= ab 3 p = a(p +b 2 )= a(ab 3 +b 2 )= a 2 b 3 +ab 2 p = a(p +b 1 )= a(a 2 b 3 +ab 2 +b 1 )= a 3 b 3 +a 2 b 2 +ab 1 = B(a) 18 natural binary offset binary 2’s C b 1 b 2 b 3 b 4 m x Q = Qm m ¹ x Q = Qm ¹ b 1 b 2 b 3 b 4 — 16 8.0 8 4.0 — 1 1 1 1 15 7.5 7 3.5 0 1 1 1 1 1 1 0 14 7.0 6 3.0 0 1 1 0 1 1 0 1 13 6.5 5 2.5 0 1 0 1 1 1 0 0 12 6.0 4 2.0 0 1 0 0 1 0 1 1 11 5.5 3 1.5 0 0 1 1 1 0 1 0 10 5.0 2 1.0 0 0 1 0 1 0 0 1 9 4.5 1 0.5 0 0 0 1 1 0 0 0 8 4.0 0 0.0 0 0 0 0 0 1 1 1 7 3.5 −1 −0.5 1 1 1 1 0 1 1 0 6 3.0 −2 −1.0 1 1 1 0 0 1 0 1 5 2.5 −3 −1.5 1 1 0 1 0 1 0 0 4 2.0 −4 −2.0 1 1 0 0 0 0 1 1 3 1.5 −5 −2.5 1 0 1 1 0 0 1 0 2 1.0 −6 −3.0 1 0 1 0 0 0 0 1 1 0.5 −7 −3.5 1 0 0 1 0 0 0 0 0 0.0 −8 −4.0 1 0 0 0 Table P2.1 Converter codes for B = 4 bits, R = 8 volts. Problem 2.14 The quantization width is Q = R/2 B = 8/2 4 = 0.5 volts. Table P2.1 shows the quantization levels and their binary codes. To convert x = 1.2 by rounding, we shift it by half the quantization spacing y = x + Q/2 = 1.2 +0.25 = 1.45. The following tables show the successive approximation tests for the natural and offset binary cases. The 2’s complement case is obtained by complementing the MSB of the offset case. test b 1 b 2 b 3 b 4 x Q C = u(y −x Q ) b 1 1 0 0 0 4.0 0 b 2 0 1 0 0 2.0 0 b 3 0 0 1 0 1.0 1 b 4 0 0 1 1 1.5 0 0 0 1 0 1.0 test b 1 b 2 b 3 b 4 x Q C = u(y −x Q ) b 1 1 0 0 0 0.0 1 b 2 1 1 0 0 2.0 0 b 3 1 0 1 0 1.0 1 b 4 1 0 1 1 1.5 0 1 0 1 0 1.0 The natural binary and 2’C cases agree because x lies in the positive range of both quantizers. For x = 5.2, we have y = x +Q/2 = 5.45. The tests are shown below: test b 1 b 2 b 3 b 4 x Q C = u(y −x Q ) b 1 1 0 0 0 4.0 1 b 2 1 1 0 0 6.0 0 b 3 1 0 1 0 5.0 1 b 4 1 0 1 1 5.5 0 1 0 1 0 5.0 test b 1 b 2 b 3 b 4 x Q C = u(y −x Q ) b 1 1 0 0 0 0.0 1 b 2 1 1 0 0 2.0 1 b 3 1 1 1 0 3.0 1 b 4 1 1 1 1 3.5 1 1 1 1 1 3.5 For the 2’C case, the quantizer saturates to its maximum positive value. Finally, for x = −3.2, we have y = −2.95, and the following testing tables: 19 test b 1 b 2 b 3 b 4 x Q C = u(y −x Q ) b 1 1 0 0 0 4.0 0 b 2 0 1 0 0 2.0 0 b 3 0 0 1 0 1.0 0 b 4 0 0 0 1 0.5 0 0 0 0 0 0.0 test b 1 b 2 b 3 b 4 x Q C = u(y −x Q ) b 1 1 0 0 0 0.0 0 b 2 0 1 0 0 −2.0 0 b 3 0 0 1 0 −3.0 1 b 4 0 0 1 1 −2.5 0 0 0 1 0 −3.0 In this case, the natural binary scale saturates to its minimum positive value. Problem 2.15 Similar to the testing tables of Examples 2.4.1 and 2.4.2. Problem 2.16 These versions are straight forward. To implement truncation instead of rounding, replace the statement within adc: y = x + Q/2; by y = x; Problem 2.17 This problem is basically the same as Example 2.4.5. The same program segment of that example applies here for generating the codes and quantized values. Only the full-scale range is different, R = 32 volts. In part (c), the amplitude of the sinusoid A = 20 exceeds the quantizer range R/2 = 16, and therefore both the positive and negative peaks of the sinusoid will saturate to the positive and negative maxima of the quantizer. Problem 2.18 The following C program carries out all the required operations. It uses the routine corr of Appendix A.1 to compute all the sample autocorrelations and cross-correlations. /* exmpl246.c - quantization noise model * * default values: * N=10 bits * R=1024 * L=1000, iseed=10, M=50 */ #include <stdio.h> #include <math.h> #include <stdlib.h> void adc(), corr(); double dac(); 20 double ran(); void main() { int n, i, L, N, M, *b; long iseed; double *x, xq, *e, R, Q, *Ree, *Rex, *Rxx; double normee, normex; double v, pi = 4 * atan(1.0); FILE *fpe, *fpx; FILE *fpRee, *fpRex, *fpRxx; printf("enter N, R = "); scanf("%d %lf", &N, &R); printf("enter L, iseed, M = "); scanf("%d %ld %d", &L, &iseed, &M); fpe = fopen("e", "w"); fpx = fopen("x", "w"); fpRee = fopen("Ree", "w"); fpRex = fopen("Rex", "w"); fpRxx = fopen("Rxx", "w"); b = (int *) calloc(N, sizeof(int)); x = (double *) calloc(L, sizeof(double)); e = (double *) calloc(L, sizeof(double)); Ree = (double *) calloc(M+1, sizeof(double)); Rex = (double *) calloc(M+1, sizeof(double)); Rxx = (double *) calloc(M+1, sizeof(double)); Q = R / (1 << N); for (n=0; n<L; n++) { v = 0.25 * R * (2 * ran(&iseed) - 1); x[n] = 0.25 * R * cos(2 * pi * n / sqrt(131.)) + v; adc(x[n], b, N, R); xq = dac(b, N, R); e[n] = x[n] - xq; fprintf(fpx, "% lf\n", x[n]); fprintf(fpe, "% lf\n", e[n]); } corr(L, e, e, M, Ree); corr(L, e, x, M, Rex); corr(L, x, x, M, Rxx); normee = Ree[0]; normex = sqrt(Ree[0] * Rxx[0]); for (i=0; i<=M; i++) { fprintf(fpRee, "%lf\n", Ree[i]/normee); fprintf(fpRex, "%lf\n", Rex[i]/normex); fprintf(fpRxx, "%lf\n", Rxx[i]/Rxx[0]); } 21 printf("erms = Q/sqrt(12) = %lf\n", Q/sqrt(12.0)); printf("Ree(0) = %lf\n", sqrt(normee)); } Problem 2.19 The mean of v is zero because E[u]= 0.5: E[v]= 0.5R(E[u]−0.5)= 0 The variance of v is related to the variance of u as follows: σ 2 v = E[v 2 ]= (0.5R) 2 E[(u −0.5) 2 ]= (0.5R) 2 σ 2 u = (0.5R) 2 1 12 = R 2 48 Problem 2.20 Inserting x(n)= Acos(2πf 0 n+φ)+v(n) into the definition of the autocorrelation function, we find: R xx (k) = E[x(n +k)x(n)] = A 2 E[cos _ 2πf 0 (n +k)+φ _ cos(2πf 0 n +φ)] +AE[cos _ 2πf 0 (n +k)+φ _ v(n)]+AE[v(n +k)cos(2πf 0 n +φ)] +E[v(n +k)v(n)] assuming φand v(n) are independent random variables, the cross terms will vanish. Indeed, by the independence assumption the expectation value of the product becomes the product of the expectation values: E[v(n +k)cos(2πf 0 n +φ)]= E[v(n +k)]·E[cos(2πf 0 n +φ)]= 0 where the last zero follows either from the zero-mean property of v(n) and/or from the zero mean property of E[cos(2πf 0 n +φ)]= 0. The latter follows from uniformity of φ whose prob- ability density will be: p(φ)= 1/(2π). We have: E[cos(a +φ)]= _ 2π 0 cos(a +φ)p(φ) dφ = 1 2π _ 2π 0 cos(a +φ) dφ = 0 Similarly, we have the property: E[cos(a +φ)cos(b +φ)] = _ 2π 0 cos(a +φ)cos(b +φ)p(φ) dφ = 1 2π _ 2π 0 cos(a +φ)cos(b +φ) dφ = 1 2 cos(a −b) Thus, we find E[cos _ 2πf 0 (n +k)+φ _ cos(2πf 0 n +φ)]= 1 2 cos(2πf 0 (n +k)−2πf 0 n)= 1 2 cos(2πf 0 k) Finally, because v(n) is assumed to be zero-mean white noise, we will have: 22 E[v(n +k)v(n)]= σ 2 v δ(k) It follows that the autocorrelation of the noisy sinusoid will be: R xx (k)= 1 2 A 2 cos(2πf 0 k)+σ 2 v δ(k) At lag k = 0, we have: R xx (0)= 1 2 A 2 +σ 2 v Therefore, the normalized autocorrelation function becomes: ρ xx (k)= R xx (k) R xx (0) = A 2 /2 A 2 /2 +σ 2 v cos(2πf 0 k)+ σ 2 v A 2 /2 +σ 2 v δ(k) Defining the parameter: a = A 2 /2 A 2 /2 +σ 2 v ⇒ 1 −a = σ 2 v A 2 /2 +σ 2 v we finally have: ρ xx (k)= acos(2πf 0 k)+(1 −a)δ(k) Defining the signal to noise ratio as the relative strength of the sinusoid versus the noise in the autocorrelation function, that is, SNR = A 2 /2 σ 2 v we may express the parameter a as: a = SNR SNR+1 ⇒ 1 −a = 1 SNR+1 Problem 2.21 The quantization width of the first ADC will be Q 1 = R 1 /2 B1 . The residual signal formed at the output of the first DAC, x 2 = x−x 1 , is the quantization error, and therefore, it varies of the limits − Q 1 2 ≤ x 2 ≤ Q 1 2 These limits must serve as the full scale range of the second ADC. Thus, we must choose: R 2 = Q 1 = R 1 2 B1 , Q 2 = R 2 2 B2 = R 1 2 B1+B2 The following program segment illustrates the sequence of operations: 23 R2 = R1 / (1 << B1); b1 = (int *) calloc(B1, sizeof(int)); b2 = (int *) calloc(B2, sizeof(int)); for (n=0; n<L; n++) { x = A * cos(2 * pi * f0 * n); adc(x, b1, B1, R1); x1 = dac(b1, B1, R1); x2 = x - x1; adc(x2, b2, B2, R2); } When there is a third B 3 -bit stage, the total number of bits will be B = B 1 +B 2 +B 3 The B 2 -bit output of the second ADC must be passed into a second DAC to get the corresponding analog value and subtracted from the input x − x 1 to get the third error output, which is then quantized to B 3 bits with a full scale range and quantization width: R 3 = Q 2 = R 2 2 B2 , Q 3 = R 3 2 B3 = R 1 2 B1+B2+B3 The following loop shows these operations: R2 = R1 / (1 << B1); R3 = R2 / (1 << B2); b1 = (int *) calloc(B1, sizeof(int)); b2 = (int *) calloc(B2, sizeof(int)); b3 = (int *) calloc(B3, sizeof(int)); for (n=0; n<L; n++) { x = A * cos(2 * pi * f0 * n); adc(x, b1, B1, R1); x1 = dac(b1, B1, R1); adc(x-x1, b2, B2, R2); x2 = dac(b2, B2, R2); x3 = x - x1 - x2; adc(x3, b3, B3, R3); } Problem 2.22 The quantized triangularly-dithered signals were generated by the for-loop given in Example 2.5.1. 24 Chapter 3 Problems Problem 3.1 (a) If the input is doubled the output is not doubled. Thus, the system is not linear. Indeed, the output due to x 1 (n)= 2x(n) will be y 1 (n)= 3x 1 (n)+5 = 6x(n)+5 }= 2(3x(n)+5). The system is, however, time-invariant since it has constant-in-time coefficients. (b) The quadratic term x 2 (n − 1) breaks linearity because it quadruples whenever the input doubles. The term x(2n) will break time-invariance. Indeed, let x D (n)= x(n − D) be a delayed input. The corresponding output y D (n) can be computed from the given I/O equation: y D (n)= x 2 D (n −1)+x D (2n)= x 2 (n −1 −D)+x(2n −D) but, this is not the same as the delayed (shifted) y(n) obtained by replacing n by n −D: y(n −D)= x 2 (n −D−1)+x(2(n −D))= x 2 (n −D−1)+x(2n −2D) Thus, the system is neither linear nor time-invariant. (c) System is time-invariant, but not linear since the output does not double whenever the input doubles. (d) The system is linear, but the term nx(n −3) breaks time-invariance. (e) The time-dependent term n breaks both time invariance and linearity. Problem 3.2 Picking out the coefficients of the x-terms, we find: (a) h = [3, −2, 0, 4] (b) h = [4, 1, 0, −3] (c) h = [1, 0, 0, −1] Problem 3.3 (a,b) These problems are of the general form: y(n)= ay(n −1)+x(n) with a = −0.9 for (a), and a = 0.9 for (b). Setting x(n)= δ(n) we find the difference equation for the impulse response: h(n)= ah(n −1)+δ(n) Iterating forward in time with zero initial condition h(−1)= 0, we obtain the causal solu- tion: h(0)= ah(−1)+δ(0)= a · 0 +1 = 1 h(1)= ah(0)+δ(1)= a · 1 +0 = a h(2)= ah(1)+δ(2)= a · a +0 = a 2 h(3)= ah(2)+δ(3)= a · a 2 +0 = a 3 · · · h(n)= ah(n −1)+δ(n)= a · a n−1 = a n , for n ≥ 1 25 Thus, h(n) will be the geometric series: h = [1, a, a 2 , a 3 , . . . ] (c,d) These problems are similar to y(n)= ay(n −2)+x(n) with a = 0.64 = (0.8) 2 for (c), and a = −0.81 = −(0.9) 2 for (d). The impulse response will satisfy the difference equation: h(n)= ah(n −2)+δ(n) A few iterations (with zero initial conditions) give: h(0)= 1 h(1)= 0 h(2)= ah(0)= a h(3)= ah(1)= 0 h(4)= ah(2)= a 2 h(5)= ah(3)= 0, etc. Thus, all the odd-indexed h(n) are zero: h = [1, 0, a, 0, a 2 , 0, a 3 , 0, a 4 , 0, . . . ] (e) The impulse response satisfies: h(n)= 0.5h(n −1)+4δ(n)+δ(n −1) A few iterations give: h(0)= 4 h(1)= 0.5h(0)+1 = 3 h(2)= 0.5h(1)= 3(0.5) h(3)= 0.5h(2)= 3(0.5) 2 , etc. Thus, h(n)= ⎧ ⎨ ⎩ 4 if n = 0 3(0.5) n−1 if n ≥ 1 Problem 3.4 We have seen that if h(n)= a n u(n), then the I/O difference equation is y(n)= ay(n −1)+x(n) In cases (a) and (b), we apply this result with a = 0.9 and a = −0.9. In cases (c) and (d), we apply this result twice and verify that h(n)= a n u(n)+(−a) n u(n) leads to the difference equation y(n)= a 2 y(n −2)+2x(n) 26 Thus, for (c) we have a = 0.9, a 2 = 0.81, and y(n)= 0.81y(n −2)+2x(n) And, for (d) we have a = 0.9j, a 2 = −0.81, and y(n)= −0.81y(n −2)+2x(n) A systematic and simpler way of solving this type of problem will be presented after we cover z-transforms. Problem 3.5 The impulse response sequence is explicitly: h = [4, 3, 3(0.5), 3(0.5) 2 , 3(0.5) 3 , . . . ] Replacing these values into the convolutional equation, we get: y n = h 0 x n +h 1 x n−1 +h 2 x n−2 +h 3 x n−3 +h 4 x n−4 +· · · = 4x n +3 _ x n−1 +0.5x n−2 +0.5 2 x n−3 +0.5 3 x n−4 +· · · _ It follows that: 0.5y n−1 = 2x n−1 +3 _ 0.5x n−2 +0.5 2 x n−3 +0.5 3 x n−4 · · · _ Subtracting, we have: y n −0.5y n−1 = 4x n +3x n−1 −2x n−1 or, y n = 0.5y n−1 = 4x n +x n−1 Problem 3.6 We may write the given impulse response in the form: h(n)= 5δ(n)+6(0.8) n−1 u(n −1)= [5, 6, 6(0.8), 6(0.8) 2 , . . . ] Proceeding as in the previous problem we have: y n = 5x n +6 _ x n−1 +0.8x n−2 +0.8 2 x n−3 +· · · _ 0.8y n−1 = 4x n−1 +6 _ 0.8x n−2 +0.8 2 x n−3 +· · · _ which gives y n −0.8y n−1 = 5x n +2x n−1 27 Problem 3.7 It is evident from the definition that for n ≥ 2, h(n) satisfies the recursions h(n)= ah(n −1). Instead of manipulating the I/Oconvolutional equation into a difference equation as we did above, let us determine directly the difference equation satisfied by h(n) and from that determine the difference equation for y(n). The given expression for h(n) can be rewritten in the more compact form, which is valid for all n: h(n)= c 0 δ(n)+c 1 a n−1 u(n −1) where the shifted unit-step u(n − 1) vanishes for n = 0 and equals one for all n ≥ 1. Because h(n) satisfies h(n)= ah(n−1) for n ≥ 2, we are led to consider the delayed function h(n−1) and multiply it by a: h(n −1)= c 0 δ(n −1)+c 1 a n−2 u(n −2) and ah(n −1)= ac 0 δ(n −1)+c 1 a n−1 u(n −2) Subtracting, we have h(n)−ah(n −1)= c 0 δ(n)−ac 0 δ(n −1)+c 1 a n−1 _ u(n −1)−u(n −2) _ But the difference u(n−1)−u(n−2)= δ(n−1) as follows fromthe standard result u(n)−u(n− 1)= δ(n), which was essentially derived in Example 3.4.4. Therefore, we have h(n)−ah(n −1)= c 0 δ(n)−ac 0 δ(n −1)+c 1 a n−1 δ(n −1) But note that a n−1 δ(n − 1)= δ(n − 1) because it is nonzero only at n = 1 for which we have a 1−1 δ(0)= a 0 δ(0)= δ(0). Then, h(n)−ah(n −1)= c 0 δ(n)−ac 0 δ(n −1)+c 1 δ(n −1)= c 0 δ(n)+(c 1 −ac 0 )δ(n −1) Or, setting b 0 = c 0 and b 1 = c 1 −ac 0 and solving for h(n) we find h(n)= ah(n −1)+b 0 δ(n)+b 1 δ(n −1) Example 3.4.7 had b 0 = c 0 = 2 and b 1 = c 1 −ac 0 = 4 −2 · 0.5 = 3. Next, we map this difference equation for h(n) into a difference equation for y(n). To do this we start with the convolutional equation and replace h(m) by its difference equation expression, that is, y(n) = _ m h(m)x(n −m) = _ m _ ah(m−1)+b 0 δ(m)+b 1 δ(m−1) _ x(n −m) = a _ m h(m−1)x(n −m)+ _ m _ b 0 δ(m)+b 1 δ(m−1) _ x(n −m) In the second sum, the presence of δ(m) extracts only the m= 0 term, that is, b 0 x(n), whereas the presence of δ(m− 1) extracts only the m = 1 term, that is, b 1 x(n − 1). Moreover, with a change of variables of summation from m to k = m−1 or m = k +1, the a-term is recognized to be ay(n −1); indeed, 28 a _ m h(m−1)x(n −m)= a _ k h(k)x(n −k −1)= ay(n −1) the last equation following from the convolution equation by replacing n by n −1: y(n)= _ k h(k)x(n −k) ⇒ y(n −1)= _ k h(k)x(n −1 −k) We finally find the I/O difference equation for y(n): y(n)= ay(n −1)+b 0 x(n)+b 1 x(n −1) which is exactly the same as that satisfied by h(n). Problem 3.8 First, note that if f n = a n u(n) then for n ≥ 1 (1 −aD)f n = f n −af n−1 = a n −aa n−1 = 0 where D is the delay operator defined by (Df) n = f n−1 . It follows that the first term p n 1 u(n) of h n will be annihilated by (1 −p 1 D), the second term of h n will be annihilated by (1 −p 2 D), etc. Therefore, all the terms in h n will be annihilated by the product (1 −p 1 D)(1 −p 2 D)· · · (1 −p M D)= 1 +a 1 D+a 2 D 2 +· · · +a M D M Problem 3.9 The C i p n i terms are annihilated by the same product as in the previous problem. However, the δ(n) term will contain the delayed terms: a M δ(n −M)+a M−1 δ(n −M+1)+· · · But, if n ≥ M+1, then these terms vanish too. Thus, the difference equation satisfied by h n will be: h n +a 1 h n−1 +· · · +a M h n−M = 0, n ≥ M+1 Problem 3.10 Define the polynomial with roots p 1 , p 2 : 1 +a 1 z −1 +a 2 z −2 = (1 −p 1 z −1 )(1 −p 2 z −1 ) so that a 1 = −(p 1 +p 2 ), a 2 = p 1 p 2 Then, the p n i terms in h n will be annihilated by the delay polynomial: h n +a 1 h n−1 +a 2 h n−2 = (1 +a 1 D+a 2 D 2 )h n = (1 −p 1 D)(1 −p 2 D)h h 29 for n ≥ 2. The coefficients b 0 , b 1 may be found by explicitly calculating the right-hand side of this difference equation using the expression for h n , for n = 0, 1: b 0 = h 0 +a 1 h −1 +a 2 h −2 = h 0 = C 1 +C 2 b 1 = h 1 +a 1 h 0 +a 2 h −1 = h 1 +a 1 h 0 = C 1 p 1 +C 2 p 2 +a 1 (C 1 +C 2 ) Using the expression for a 1 , we find: b 0 = C 1 +C 2 b 1 = C 1 p 1 +C 2 p 2 −(p 1 +p 2 )(C 1 +C 2 )= −(C 1 p 2 +C 2 p 1 ) To summarize, h n will satisfy the difference equation: h n +a 1 h n−1 +a 2 h n−2 = b 0 δ(n)+b 1 δ(n −1) (P3.1) Inserting this into the convolutional equation, we obtain the I/O difference equation: y n +a 1 y n−1 +a 2 y n−2 = b 0 x n +b 1 x n−1 These results can be obtained quickly using z-transforms: H(z)= C 1 1 −p 1 z −1 + C 2 1 −p 2 z −1 = (C 1 +C 2 )−(C 1 p 2 +C 2 p 1 )z −1 (1 −p 1 z −1 )(1 −p 2 z −1 ) which may be rewritten as H(z)= b 0 +b 1 z −1 1 +a 1 z −1 +a 2 z −2 and leads to the desired difference equations for h n and y n . Problem 3.11 Now the difference equation Eq. (P3.1) will be satisfied for n ≥ 3. To determine the coefficients b 0 , b 1 , b 2 , we evaluate the right hand side for n = 0, 1, 2: b 0 = h 0 b 1 = h 1 +a 1 h 0 b 2 = h 2 +a 1 h 1 +a 2 h 0 which give: b 0 = C 0 +C 1 +C 2 b 1 = C 1 p 1 +C 2 p 2 +a 1 (C 0 +C 1 +C 2 )= −(p 1 +p 2 )C 0 −(C 1 p 2 +C 2 p 1 ) b 2 = C 1 p 2 1 +C 2 p 2 2 +a 1 (C 1 p 1 +C 2 p 2 )+a 2 (C 0 +C 1 +C 2 )= C 0 p 1 p 2 In b 2 , the coefficient of C 1 is p 2 1 +a 1 p 1 +a 2 , which is zero because p 1 is a root of the polynomial z 2 +a 1 z +a 2 . Similarly, the coefficient of C 2 is zero. Again, the results can be justified quickly using z-transforms: H(z) = C 0 + C 1 1 −p 1 z −1 + C 2 1 −p 2 z −1 = (C 0 +C 1 +C 2 )− _ C 1 p 2 +C 2 p 1 +C 0 (p 1 +p 2 ) _ z −1 +C 0 p 1 p 2 z −2 (1 −p 1 z −1 )(1 −p 2 z −1 ) 30 Problem 3.12 Define the polynomial with roots p 1 , p 2 , p 3 : 1 +a 1 z −1 +a 2 z −2 +a 3 z −3 = (1 −p 1 z −1 )(1 −p 2 z −1 )(1 −p 3 z −1 ) so that a 1 = −(p 1 +p 2 +p 3 ), a 2 = p 1 p 2 +p 2 p 3 +p 3 p 1 , a 3 = −p 1 p 2 p 3 Then, the p n i terms in h n will be annihilated by the delay polynomial: (1 +a 1 D+a 2 D 2 +a 3 D 3 )h n = (1 −p 1 D)(1 −p 2 D)(1 −p 3 D)h h = 0 for n ≥ 3, or, h n +a 1 h n−1 +a 2 h n−2 +a 3 h n−3 = 0, n ≥ 3 The coefficients b 0 , b 1 , b 2 may be found by explicitly calculating the right-hand side of this dif- ference equation using the expression for h n , for n = 0, 1, 2: b 0 = h 0 b 1 = h 1 +a 1 h 0 b 2 = h 2 +a 1 h 1 +a 2 h 0 or, b 0 = C 1 +C 2 +C 3 b 1 = C 1 p 1 +C 2 p 2 +C 3 p 3 +a 1 (C 1 +C 2 +C 3 ) b 2 = C 1 p 2 1 +C 2 p 2 2 +C 3 p 2 3 +a 1 (C 1 p 1 +C 2 p 2 +C 3 p 3 )+a 2 (C 1 +C 2 +C 3 ) which simplify into: b 0 = C 1 +C 2 +C 3 b 1 = − _ C 1 (p 2 +p 3 )+C 2 (p 3 +p 1 )+C 3 (p 1 +p 2 ) _ b 2 = C 1 p 2 p 3 +C 2 p 3 p 1 +C 3 p 1 p 2 Problem 3.13 For (a), we have with n ≥ 2: (1 −0.5D)(1 −0.8D)= 1 −1.3D+0.4D 2 ⇒ h n −1.3h n−1 +0.4h n−2 = 0 For (b), we have with n ≥ 2: (1 −0.5jD)(1 +0.5jD)= 1 +0.25D 2 ⇒ h n +0.25h n−2 = 0 For (c), we have with n ≥ 3: (1 −0.4D)(1 −0.5D)(1 +0.5D)= 1 −0.4D−0.25D 2 +0.1D 3 ⇒ h n −0.4h n−1 −0.25h n−2 +0.1h n−3 = 0 31 Problem 3.14 From the convolutional I/O equation we get: ¦y(n)¦ = ¦ _ m h(m)x(n −m)¦ ≤ _ m ¦h(m)¦¦x(n −m)¦ ≤ _ m ¦h(m)¦B = AB Problem 3.15 Starting with y(n)= _ m h(m)x(n −m) we obtain at n = 0: y(0)= _ m h(m)x(−m) But, x(m)= sign _ h(−m) _ . Therefore, x(−m)= sign _ h(m) _ . It follows: y(0)= _ m h(m)x(−m)= _ m h(m)sign _ h(m) _ Recognizing that in general xsign(x)= ¦x¦, we find y(0)= _ m ¦h(m)¦ Because x(n) was bounded, y(n) and, hence y(0), must be bounded. If at some m, h(m)= 0, then this term would not contribute to the convolutional sum. Problem 3.16 Working with the convolutional I/O equation, we have: y D (n) = _ m h D (m)x(n −m)= _ m h(m−D)x(n −m) = _ k h(k)x(n −D−k)= y(n −D) where we changed summation variables frommto k = m−D, and evaluated y(n) at n−D, that is, y(n)= _ k h(k)x(n −k) ⇒ y(n −D)= _ k h(k)x(n −D−k) Problem 3.17 We have: _ m h D (m)x A (n −m)= _ m h(m−D)x(n −m+D)= _ k h(k)x(n −k) where we changed variables of summation from m to k = m−D. 32 Problem 3.18 Because ˜ h(n) agrees with h(n) for n ≥ −D, we have: y(n) = ∞ _ m=−∞ h(m)x(n −m) ˜ y(n) = ∞ _ m=−D ˜ h(m)x(n −m)= ∞ _ m=−D h(m)x(n −m) Subtracting, the terms m≥ −D cancel and we get: y(n)−˜ y(n)= −D−1 _ m=−∞ h(m)x(n −m) Assuming x(n) is bounded by A, we have: ¦y(n)−˜ y(n)¦ = ¦ −D−1 _ m=−∞ h(m)x(n −m)¦ ≤ −D−1 _ m=−∞ ¦h(m)¦¦x(n −m)¦ ≤ −D−1 _ m=−∞ ¦h(m)¦A This summation is finite because it is a subsum of the stability condition: −D−1 _ m=−∞ ¦h(m)¦ ≤ ∞ _ m=−∞ ¦h(m)¦ < ∞ In the limit of large D, the number of terms shrinks to zero giving: lim D→∞ −D−1 _ m=−∞ ¦h(m)¦ →0 33 Chapter 4 Problems Problem 4.1 The convolution table is: h\x 1 2 1 1 2 1 1 1 1 1 2 1 1 2 1 1 1 1 1 2 1 1 2 1 1 1 2 2 4 2 2 4 2 2 2 1 1 2 1 1 2 1 1 1 Folding the table, we get y = [1, 3, 5, 7, 7, 6, 7, 6, 4, 3, 1] The first and last three samples are the input and output transients, and the middle 5 samples are the steady-state outputs. The LTI table is: n 0 1 2 3 4 5 6 7 8 9 10 x\h 1 1 2 1 partial output 1 1 1 2 1 x(0)h(n −0) 2 2 2 4 2 x(1)h(n −1) 1 1 1 2 1 x(2)h(n −2) 1 1 1 2 1 x(3)h(n −3) 2 2 2 4 2 x(4)h(n −4) 1 1 1 2 1 x(5)h(n −5) 1 1 1 2 1 x(6)h(n −6) 1 1 1 2 1 x(7)h(n −7) y(n) 1 3 5 7 7 6 7 6 4 3 1 _ m x(m)h(n −m) For the overlap-add method, the input is divided into the following three contiguous blocks: x = [ 1, 2, 1 . ¸, . x0 , 1, 2, 1 . ¸, . x1 , 1, 1, 0 . ¸, . x2 ] where we padded an extra zero at the end to get a length-3 block. Convolving each block separately with h gives: y 0 = h ∗x 0 = [1, 3, 5, 6, 4, 1] y 1 = h ∗x 1 = [1, 3, 5, 6, 4, 1] y 2 = h ∗x 2 = [1, 2, 3, 3, 1, 0] These convolutions can be done by separately folding the three convolution subtables: block 0 block 1 block 2 h\x 1 2 1 1 2 1 1 1 0 1 1 2 1 1 2 1 1 1 0 1 1 2 1 1 2 1 1 1 0 2 2 4 2 2 4 2 2 2 0 1 1 2 1 1 2 1 1 1 0 34 The three subblocks begin at the absolute times n = 0, 3, 6, respectively. It follows from time- invariance that the corresponding output blocks will also begin at the same absolute times. Thus, aligning the output blocks according to their absolute timings and adding them up gives the final result: n 0 1 2 3 4 5 6 7 8 9 10 y 0 1 3 5 6 4 1 y 1 1 3 5 6 4 1 y 2 1 2 3 3 1 y 1 3 5 7 7 6 7 6 4 3 1 In practice this method is implemented efficiently by computing the individual block convolutions using the FFT instead of time-domain convolution. For an FIR filter of order M and an FFT of length N (which is a power of two), the length of each x-block is chosen to be N 1 = N − M. The computational gain of this “fast” convolution method versus the conventional time-domain “slow” method is approximately fast slow = log 2 N M If the input is divided into length-5 subblocks, the last subblock will have length 3: x = [ 1, 2, 1, 1, 2 . ¸, . x0 , 1, 1, 1 . ¸, . x1 ] The convolutions of the subblocks with the filter are: y 0 = h ∗x 0 = [1, 3, 5, 7, 7, 5, 5, 2] y 1 = h ∗x 1 = [1, 2, 4, 4, 3, 1] Aligning them at multiples of n = 5, we have: n 0 1 2 3 4 5 6 7 8 9 10 y 0 1 3 5 7 7 5 5 2 y 1 1 2 4 4 3 1 y 1 3 5 7 7 6 7 6 4 3 1 Problem 4.2 The convolution table is: h\x 2 2 0 1 -1 0 1 2 2 4 4 0 2 -2 0 2 4 -2 -4 -4 0 -2 2 0 -2 -4 -1 -2 -2 0 -1 1 0 -1 -2 1 2 2 0 1 -1 0 1 2 Folding the table, we get y = [4, 0, −6, 2, −2, 1, 4, 1, −5, −1, 2] The first and last three samples are the input and output transients, and the middle 5 samples are the steady-state outputs. The LTI table is: 35 n 0 1 2 3 4 5 6 7 8 9 10 x\h 2 -2 -1 1 partial output 2 4 -4 -2 2 x(0)h(n −0) 2 4 -4 -2 2 x(1)h(n −1) 0 0 0 0 0 x(2)h(n −2) 1 2 -2 -1 1 x(3)h(n −3) -1 -2 2 1 -1 x(4)h(n −4) 0 0 0 0 0 x(5)h(n −5) 1 2 -2 -1 1 x(6)h(n −6) 2 4 -4 -2 2 x(7)h(n −7) y(n) 4 0 -6 2 -2 1 4 1 -5 -1 2 _ m x(m)h(n −m) For the overlap-add method, the input is divided into the following three contiguous blocks: x = [ 2, 2, 0 . ¸, . x0 , 1, −1, 0 . ¸, . x1 , 1, 2, 0 . ¸, . x2 ] where we padded an extra zero at the end to get a length-3 block. Convolving each block separately with h gives: y 0 = h ∗x 0 = [4, 0, −6, 0, 2] y 1 = h ∗x 1 = [2, −4, 1, 2, −1, 0] y 2 = h ∗x 2 = [2, −2, −5, −1, 2] These convolutions can be done by separately folding the three convolution subtables: block 0 block 1 block 2 h\x 2 2 0 1 -1 0 1 2 2 4 4 0 2 -2 0 2 4 -2 -4 -4 0 -2 2 0 -2 -4 -1 -2 -2 0 -1 1 0 -1 -2 1 2 2 0 1 -1 0 1 2 Aligning the output subblocks at multiples of n = 3, we get: n 0 1 2 3 4 5 6 7 8 9 10 y 0 4 0 -6 0 2 1 y 1 2 -4 1 2 -1 0 y 2 2 2 -5 -1 2 y 4 0 -6 2 -2 1 4 1 -5 -1 2 If the input is divided into length-5 subblocks, the last subblock will have length 3: x = [ 2, 2, 0, 1, −1 . ¸, . x0 , 0, 1, 2 . ¸, . x1 ] The convolutions of the subblocks with the filter are: y 0 = h ∗x 0 = [4, 0, −6, 2, −2, 1, 2, −1] y 1 = h ∗x 1 = [0, 2, 2, −5, −1, 2] Aligning them at multiples of n = 5, we have: 36 n 0 1 2 3 4 5 6 7 8 9 10 y 0 4 0 -6 2 -2 1 2 -1 y 1 0 2 2 -5 -1 2 y 4 0 -6 2 -2 1 4 1 -5 -1 2 Problem 4.3 Figure P4.1 shows the filter, input, and computed output signals. 0 3 6 10 13 16 20 23 26 0 1 1 2 3 4 3 6 10 13 16 20 23 26 n n h(n) x(n) y(n) on steady off Fig. P4.1 h(n), x(n), and y(n) signals of Problem 4.3. For the direct form, the indices of h m and x n−m are restricted to lie within their respective ranges: 3 ≤ m≤ 6 10 ≤ n −m≤ 20 (P4.1) Solving the second with respect to n, we have: 10 +m≤ n ≤ 20 +m Using the first of Eq. (P4.1), we extend the range to: 10 +3 ≤ 10 +m≤ n ≤ 20 +m≤ 20 +6 ⇒ 13 ≤ n ≤ 26 This is the range of index n of the output y n . To find the limits of summation over m, we change the sign of the second of Eq. (P4.1) and solve for m: −20 ≤ m−n ≤ −10 ⇒ n −20 ≤ m≤ n −10 Thus, the inequalities in Eq. (P4.1) are equivalent to 3 ≤ m≤ 6 n −20 ≤ m≤ n −10 ⇒ max(3, n −20)≤ m≤ min(6, n −10) The final expression for the direct form will be: 37 y n = min(6,n−10) _ m=max(3,n−20) h m x n−m , for 13 ≤ n ≤ 26 The transition from the input-on transients to the steady state takes place at time 6 = n −10 or n = 16 at which the upper limit switches from n −10 to 6. Similarly, the transition from steady state to the input-off transients occurs at 3 = n − 20 or n = 23 when the lower limit switches from 3 to n −10. In summary, the three ranges are: input-on: 13 ≤ n ≤ 15 y n = n−10 _ m=3 h m x n−m steady-state: 16 ≤ n ≤ 23 y n = 6 _ m=3 h m x n−m input-off: 24 ≤ n ≤ 26 y n = 6 _ m=n−20 h m x n−m In particular, if the filter and input signals are unity over the ranges (P4.1), the output can be expressed compactly as: y n = min(6,n−10) _ m=max(3,n−20) 1 · 1 = min(6, n −10)−max(3, n −20)+1 (P4.2) for 13 ≤ n ≤ 26. Or, more explicitly: input-on: 13 ≤ n ≤ 15 y n = n −10 −3 +1 = n −12 steady-state: 16 ≤ n ≤ 23 y n = 6 −3 +1 = 4 input-off: 24 ≤ n ≤ 26 y n = 6 −(n −20)+1 = 27 −n With numerical values: y = ¦1, 2, 3, 4, 4, 4, 4, 4, 4, 4, 4, 3, 2, 1¦ The first and last M = 3 samples are the input on/off transients. The middle samples are the steady samples. Note that because the input is constant, the steady-state DC output can be predicted in advance from the DC gain: y DC = _ m h m = 1 +1 +1 +1 = 4 Note also that because the filter is delayed by 3 samples, the output will not begin to come out until 3 time instants after the input begins, that is at n = 13. Also, the input is cutoff at n = 20 but this is not felt by the filter until 3 instants later, that is, at n = 23. For the LTI form, Eq. (P4.1) is replaced by 10 ≤ m≤ 20 3 ≤ n −m≤ 6 This leads to the same range for the output index n, but to the summation limits: 38 y n = min(20,n−3) _ m=max(10,n−6) x m h n−m , for 13 ≤ n ≤ 26 For part (b), we have: y n = min(20,n−3) _ m=max(10,n−6) 1 · 1 = min(10, n −6)−max(20, n −3)+1 (P4.3) Note that Eq. (P4.3) is equivalent to Eq. (P4.2). Problem 4.4 Because both the input and filter are causal and have infinite duration, we use the formula: y(n)= n _ m=0 h(m)x(n −m)= n _ m=0 a m u(m)u(n −m) or, y(n)= n _ m=0 a m = 1 −a n+1 1 −a The steady-state response is the large-n limit of this formula; that is, y(n)−→ 1 1 −a for n −→∞ If x(n)= (−1) n u(n), we have y(n)= n _ m=0 a m (−1) n−m = (−1) n n _ m=0 (−a) m = (−1) n 1 −(−a) n+1 1 +a Problem 4.5 Consider the IIR filter h(n)= a n u(n), where 0 < a < 1. The square pulse x(n)= u(n)−u(n−L) of duration L is applied as input. Using the time-domain convolution formula determine a closed- form expression for the output signal y(n) for the two time ranges: 0 ≤ n ≤ L − 1 and n ≥ L. Because the filter is infinite (M = ∞), Eq. (4.1.16) becomes: y(n)= n _ m=max(0,n−L+1) h(m)x(n −m), 0 ≤ n < ∞ Inserting the given signals for h(n) and x(n), we find: y(n)= n _ m=max(0,n−L+1) a m · 1 Using the geometric series identity M2 _ m=M1 a m = a M1 −a M2+1 1 −a we find: 39 y(n)= a max(0,n−L+1) −a n+1 1 −a In particular, for 0 ≤ n ≤ L −1, we have max(0, n −L +1)= 0, and y(n)= 1 −a n+1 1 −a (input-on transients and steady state) whereas for n ≥ L, we have max(0, n −L +1)= n −L +1, and y(n)= a n−L+1 −a n+1 1 −a = a n−L+1 1 −a L 1 −a = a n−L+1 y(L −1), (input-off) Thus, after the input is turned off, the output decays exponentially to zero. Problem 4.6 From the previous problem, we have at n = 0, y(0)−ay(−1)= 1 −a 0+1 1 −a −a · 0 = 1 = x(0) Then, for 1 ≤ n ≤ L −1, we have x(n)= 1 and y(n)−ay(n −1)= 1 −a n+1 1 −a −a 1 −a n 1 −a = 1 −a n+1 −a +a n+1 1 −a = 1 = x(n) Finally, for n ≥ L, we have x(n)= 0 and y(n)−ay(n −1)= a n−L+1 y L−1 −aa n−1−L+1 y L−1 = 0 = x(n) Problem 4.7 For example, the LTI form is obtained by interchanging the roles played by x and h and their lengths L and M+1. The following routine is an implementation of Eq. (4.1.19): /* convlti.c - convolution in LTI form */ #include <stdlib.h> defines max( ) and min( ) void convlti(M, h, L, x, y) double *h, *x, *y; h=filter, x=input block, y=output block int M, L; M=filter order, L=input length { int n, m; for (n = 0; n < L+M; n++) for (y[n] = 0, m = max(0, n-M); m <= min(n, L-1); m++) y[n] += x[m] * h[n-m]; } 40 Problem 4.8 The following C program computes the output signals of the two filters (a) and (b) of Example 4.1.8: /* convex.c - convolution example 4.1.8 */ #include <stdio.h> #include <stdlib.h> #include <math.h> #define Ma 14 #define Mb 5 void conv(); void main() { int K = 50, L = 200, n; double *x, *ya, *yb; double ha[Ma+1], hb[Mb+1] = {0.2, -1, 2, -2, 1, -0.2}; x = (double *) calloc(L, sizeof(double)); ya = (double *) calloc(L+Ma, sizeof(double)); Ex. 4.1.8 (a) yb = (double *) calloc(L+Mb, sizeof(double)); Ex. 4.1.8.(b) for (n=0; n<=Ma; n++) define filter (a) ha[n] = 0.25 * pow(0.75, n); for (n=0; n<L; n++) define input if (n%K < K/2) x[n] = 1; else x[n] = 0; conv(Ma, ha, L, x, ya); compute outputs conv(Mb, hb, L, x, yb); for (n=0; n<L+Ma; n++) printf("%lf\n", ya[n]); printf("\n\n"); for (n=0; n<L+Mb; n++) printf("%lf\n", yb[n]); } Problem 4.9 A complete such program is included below. /* blkfilt.c - FIR filtering by block convolution */ #include <stdio.h> #include <stdlib.h> #define MAX 64 memory allocation size 41 void blockcon(); void main(int argc, char **argv) { FILE *fph; filter file double *h, *x, *y, *ytemp; int M, N, L, i; M = filter order, L = blocksize int max = MAX, dmax = MAX; initial allocation & increment if (argc != 3) { fprintf(stderr, "usage: blkfilt hfile L <xfile >yfile\n"); exit(0); } if ((fph = fopen(argv[1], "r")) == NULL) { fprintf(stderr, "can’t open filter file: %s\n", argv[1]); exit(0); } L = atoi(argv[2]); block length h = (double *) calloc(max + 1, sizeof(double)); for (M=0;; M++) { read h if (M == max) { if necessary, reallocate h max += dmax; h = (double *) realloc((char *) h, (max + 1) * sizeof(double)); } if (fscanf(fph, "%lf", h + M) == EOF) break; } M--; M is filter order if (L < M) { fprintf(stderr, "blocksize L must be at least %d\n", M); exit(0); } h = (double *) realloc((char *) h, (M + 1) * sizeof(double)); final allocation x = (double *) calloc(L, sizeof(double)); allocate input block y = (double *) calloc(L + M, sizeof(double)); allocate output block ytemp = (double *) calloc(M, sizeof(double)); initialized to zero start filtering: for (;;) { read input block for (N=0; N<L; N++) N=L except for last if (scanf("%lf", x+N) == EOF) goto last; blockcon(M, h, L, x, y, ytemp); process block for (i=0; i<L; i++) write output block printf("%lf\n", y[i]); } last: process last block blockcon(M, h, N, x, y, ytemp); last block has N<=L 42 for (i=0; i<N+M; i++) write entire y block printf("%lf\n", y[i]); } The dimension of the filter array h is determined on the fly by reading the file of filter coeffi- cients. Because the length of this file is not known in advance, the program keeps reallocating the length of h in increments of MAX coefficients until the final length is determined and the final reallocation is made. The filtering portion of the program is identical to the program segment discussed at the end of Section 4.1.10. The program can receive its input from stdin with the user entering the input samples one at a time. However, only after a group of L samples has been entered followed by a <CR> (carriage return), will the program output the first group of L outputs. Then, the next group of L input samples is entered and the programoutputs the corresponding group of L outputs, and so on. At the end, one must enter a <CTRL-Z> (for MSDOS) in order for the programto process the input-off transients. Problem 4.10 A complete such program is included below. /* firfilt.c - FIR filtering by sample-by-sample processing */ #include <stdlib.h> #include <stdio.h> #define MAX 64 initial allocation size double fir(); void main(int argc, char **argv) { FILE *fph; filter file double *h, *w, x, y; filter, states, input, output samples int M, i; int max = MAX, dmax = MAX; allocation for h and increment if (argc != 2) { fprintf(stderr, "usage: firfilt hfile <xfile >yfile\n"); exit(0); } if ((fph = fopen(argv[1], "r")) == NULL) { fprintf(stderr, "can’t open filter file: %s\n", argv[1]); exit(0); } h = (double *) calloc(max + 1, sizeof(double)); preliminary allocation for (M=0;; M++) { read h if (M == max) { reallocate h, if necessary max += dmax; h = (double *) realloc((char *) h, (max + 1) * sizeof(double)); } if (fscanf(fph, "%lf", h + M) == EOF) break; 43 } M--; M is filter order h = (double *) realloc((char *) h, (M + 1) * sizeof(double)); final allocation w = (double *) calloc(M + 1, sizeof(double)); start filtering: while(scanf("%lf", &x) != EOF) { keep reading input samples y = fir(M, h, w, x); compute output sample printf("%lf\n", y); write output sample } for (i=0; i<M; i++) { input-off transients y = fir(M, h, w, 0.0); printf("%lf\n", y); } } As in the case of blkfilt.c, the dimension of the filter array h is determined on the fly by reading the file of filter coefficients. The program keeps reallocating the length of h in increments of MAX coefficients until the final length is determined and the final reallocation is made. The filtering portion of the program is identical to the program segment discussed in Section 4.2.3. The program can receive its input from stdin with the user entering the input one sample at a time. After each input is entered followed by a <CR>, the program computes and outputs the corresponding output sample. (One can also enter a few input samples at a time, followed by a <CR>, and the program will produce the corresponding outputs.) At the end, one must enter a <CTRL-Z> (for MSDOS) in order for the program to process the input-off transients. Problem 4.11 A complete such program is included below. /* cfirfilt.c - FIR filtering using circular delay-line buffer */ #include <stdlib.h> #include <stdio.h> #define MAX 64 initial allocation size double cfir(); void main(int argc, char **argv) { FILE *fph; filter file double *h, *w, *p; filter, states, circular pointer double x, y; input and output samples int M, i; int max = MAX, dmax = MAX; allocation for h and increment if (argc != 2) { fprintf(stderr, "usage: cfirfilt hfile <xfile >yfile\n"); exit(0); } 44 if ((fph = fopen(argv[1], "r")) == NULL) { fprintf(stderr, "can’t open filter file: %s\n", argv[1]); exit(0); } h = (double *) calloc(max + 1, sizeof(double)); preliminary allocation for (M=0;; M++) { read h if (M == max) { reallocate h, if necessary max += dmax; h = (double *) realloc((char *) h, (max + 1) * sizeof(double)); } if (fscanf(fph, "%lf", h + M) == EOF) break; } M--; M is filter order h = (double *) realloc((char *) h, (M + 1) * sizeof(double)); w = (double *) calloc(M + 1, sizeof(double)); p = w; initialize p start filtering: while(scanf("%lf", &x) != EOF) { keep reading input samples y = cfir(M, h, w, &p, x); compute output sample printf("%lf\n", y); write output sample } for (i=0; i<M; i++) { input-off transients y = cfir(M, h, w, &p, 0); printf("%lf\n", y); } } It is identical to firfilt.c, except it uses the circular version cfir instead of fir to do the fil- tering. In addition, the circular pointer p is defined and initialized by the program. This program must be compiled and linked with cfir.c and wrap.c. The version using the routine cfir1 is identical. The following version is based on the routine cfir2 and uses the circular pointer index q instead of the pointer p. It must be linked with the routines cfir2 and wrap2. /* cfirfil2.c - FIR filtering using circular delay-line buffer */ #include <stdlib.h> #include <stdio.h> #define MAX 64 initial allocation size double cfir2(); void main(int argc, char **argv) { FILE *fph; filter file double *h, *w; filter, states, circular pointer double x, y; input and output samples int M, i, q; circular pointer index int max = MAX, dmax = MAX; allocation for h and increment 45 if (argc != 2) { fprintf(stderr, "usage: cfirfil2 hfile <xfile >yfile\n"); exit(0); } if ((fph = fopen(argv[1], "r")) == NULL) { fprintf(stderr, "can’t open filter file: %s\n", argv[1]); exit(0); } h = (double *) calloc(max + 1, sizeof(double)); preliminary allocation for (M=0;; M++) { read h if (M == max) { reallocate h, if necessary max += dmax; h = (double *) realloc((char *) h, (max + 1) * sizeof(double)); } if (fscanf(fph, "%lf", h + M) == EOF) break; } M--; M is filter order h = (double *) realloc((char *) h, (M + 1) * sizeof(double)); w = (double *) calloc(M + 1, sizeof(double)); q = 0; initialize q start filtering: while(scanf("%lf", &x) != EOF) { keep reading input samples y = cfir2(M, h, w, &q, x); compute output sample printf("%lf\n", y); write output sample } for (i=0; i<M; i++) { input-off transients y = cfir2(M, h, w, &q, 0); printf("%lf\n", y); } } Problem 4.12 The following C program is an implementation: /* cdelfilt.c - Implementation of delay using circular buffer */ #include <stdlib.h> #include <stdio.h> double cdelay(); double tap(); void main(int argc, char **argv) { double *w, *p; linear buffer & circular pointer double x, y; input and output samples int D, i, j; 46 if (argc != 3) { fprintf(stderr, "usage: cdelfilt i D <xfile >yfile\n"); exit(0); } i = atoi(argv[1]); D = atoi(argv[2]); if (i>D) { fprintf(stderr, "i must be in the range {0, 1, ..., D}\n"); exit(0); } w = (double *) calloc(D + 1, sizeof(double)); p = w; initialize p while(scanf("%lf", &x) != EOF) { keep reading input samples *p = x; store in circular buffer y = tap(D, w, p, i); y(n) = x(n-i) = i-th delay cdelay(D, w, &p); update delay line printf("%lf\n", y); write output sample } for (j=0; j<i; j++) { input-off transients *p = 0; zero input y = tap(D, w, p, i); cdelay(D, w, &p); printf("%lf\n", y); } } Problem 4.13 Consider a 3d order filter with internal states w i (n)= x(n − i), i = 0, 1, 2, 3. They are delayed replicas of each other: w 3 (n) = w 2 (n −1) w 2 (n) = w 1 (n −1) w 1 (n) = w 0 (n −1) w 0 (n) = x(n) Thus, the current states are obtained from the previous ones by shifting the previous contents of the delay line and reading x(n) into w 0 (n). Once this shift is done, the filter’s output is computed by the dot product: y(n)= h 0 w 0 (n)+h 1 w 1 (n)+h 2 w 2 (n)+h 3 w 3 (n) The following routine firalt.c implements this alternative procedure: /* firalt.c - Alternative version of FIR filter in direct form */ double firalt(M, h, w, x) Usage: y=firalt(M, h, w, x); double *h, *w, x; h=filter, w=state, x=input int M; M=filter order { 47 int i; double y; y=output sample for (i=M; i>=1; i--) update states from previous call w[i] = w[i-1]; done in reverse order w[0] = x; read current input sample x for (y=0, i=0; i<=M; i++) y += h[i] * w[i]; process current output sample return y; } Note that the previous state vector is updated first into its current value, the current input is read into w 0 , and only then is the output y computed. Upon exit, the states are left at their current values and not updated. They will be updated by the next call. The vector w must be initialized to zero prior to the first call, just like the fir.c case. Problem 4.14 Introduce the internal states: w 0 (n) = x(n) w 1 (n) = x(n −1)= w 0 (n −1) w 2 (n) = x(n −2)= w 1 (n −1) w 3 (n) = x(n −3)= w 2 (n −1) Then, the I/O equation together with the state-updating equations will read: w 0 (n)= x(n) y(n)= w 0 (n)+w 1 (n)+2w 2 (n)+w 3 (n) and w 3 (n +1) = w 2 (n) w 2 (n +1) = w 1 (n) w 1 (n +1) = w 0 (n) This leads to the following sample processing algorithm and block diagram: x y w 0 z -1 z -1 z -1 w 1 w 2 w 3 2 for each input sample x do: w 0 = x y = w 0 +w 1 +2w 2 +w 3 w 3 = w 2 w 2 = w 1 w 1 = w 0 The sample processing algorithm generates the following output samples: 48 n x w 0 w 1 w 2 w 3 y = w 0 +w 1 +2w 2 +w 3 0 1 1 0 0 0 1 1 2 2 1 0 0 3 2 1 1 2 1 0 5 3 1 1 1 2 1 7 4 2 2 1 1 2 7 5 1 1 2 1 1 6 6 1 1 1 2 1 7 7 1 1 1 1 2 6 8 0 0 1 1 1 4 9 0 0 0 1 1 3 10 0 0 0 0 1 1 The first three outputs correspond to the input-on transients (the internal delay registers are still filling up). The period 3 ≤ n ≤ 7 corresponds to steady state (all delays are filled). The last three outputs, in general the last M outputs for an M-th order FIR filter, are the input-off (x = 0) transients (the delays gradually empty out their contents). A C routine and main program implementing this algorithm are given below: #include <stdio.h> #include <malloc.h> declares calloc() double x[8] = {1,2,1,1,2,1,1,1}; double filter2(); void main() { int n; double y, *w; w = (double *) calloc(4, sizeof(double)); allocates & initializes w to zero for (n=0; n<8; n++) { input-on transients & steady-state y = filter2(x[n], w); printf("%lf\n", y); } for (n=8; n<11; n++) { input-off transients y = filter2(0.0, w); printf("%lf\n", y); } } double filter2(x, w) usage: y = filter2(x, w); double x, *w; { double y; w[0] = x; read input sample y = w[0] + w[1] + 2 * w[2] + w[3]; compute output sample w[3] = w[2]; update internal states w[2] = w[1]; w[1] = w[0]; 49 return y; } Problem 4.15 We define the state-variables w i (n), i = 0, 1, 2, 3 as follows: w 0 (n) = x(n) w 1 (n) = x(n −1)= w 0 (n −1) w 2 (n) = x(n −2)= w 1 (n −1) w 3 (n) = x(n −3)= w 2 (n −1) Then, the I/O equation y(n)= x(n)−x(n − 3) together with the state-updating equations will read: w 0 (n)= x(n) y(n)= w 0 (n)−w 3 (n) and w 3 (n +1) = w 2 (n) w 2 (n +1) = w 1 (n) w 1 (n +1) = w 0 (n) Note that the output y(n) at time n and the next internal states at time n + 1 are computable from the knowledge of the present input x(n) and the present states at time n. This leads to the following sample processing algorithm and block diagram realization: x y w 0 z -1 z -1 z -1 w 1 w 2 w 3 -1 for each input sample x do: w 0 = x y = w 0 −w 3 w 3 = w 2 w 2 = w 1 w 1 = w 0 The sample processing algorithmcan be applied to the given input samples to generate the output samples: n x w 0 w 1 w 2 w 3 y = w 0 −w 3 0 1 1 0 0 0 1 1 1 1 1 0 0 1 2 2 2 1 1 0 2 3 2 2 2 1 1 1 4 4 4 2 2 1 3 Problem 4.16 We define the internal state: w 1 (n)= y(n −1) 50 Then, the difference equation y(n)= 0.8y(n − 1)+x(n) and the state updating equation will read: y(n)= 0.8w 1 (n)+x(n) and w 1 (n +1)= y(n) This leads to the following sample processing algorithm and block diagram realization: x 0.8 y y z -1 w 1 for each input sample x do: y = 0.8w 1 +x w 1 = y The table of computations is: n x w 1 y = 0.8w 1 +x 0 1 0.0000 1.0000 1 1 1.0000 1.8000 2 2 1.8000 3.4400 3 2 3.4400 4.7520 4 4 4.7520 7.8016 Problem 4.17 We define the internal states: w 1 (n) = y(n −1) w 2 (n) = y(n −2)= w 1 (n −1) ⇒ w 1 (n +1) = y(n) w 2 (n +1) = y(n −1)= w 1 (n) The difference equation y(n)= 0.25y(n −2)+x(n) and state updating equations become: y(n)= 0.25w 2 (n)+x(n) and w 2 (n +1) = w 1 (n) w 1 (n +1) = y(n) This leads to the following sample processing algorithm and block diagram realization: x 0.25 y y z -1 z -1 w 2 w 1 for each input sample x do: y = 0.25w 2 +x w 2 = w 1 w 1 = y General versions of such routines will be considered in Chapter 7. The sample processing algo- rithm can be cranked on the given input samples to generate the output: n x y = 0.25w 2 +x w 1 w 2 0 1 1 0 0 1 1 1 1 0 2 2 2.25 1 1 3 2 2.25 2.25 1 4 4 4.5625 2.25 2.25 51 Notice how the computed y becomes the next w 1 and w 1 shifts into w 2 . Problem 4.18 The impulse response is read off from the coefficients of the I/O equation: h = [1, 0, −1, 2] The LTI form is implemented by the following table: n 0 1 2 3 4 5 6 7 8 9 10 x\h 1 0 -1 2 partial output 1 1 0 -1 2 x(0)h(n −0) 1 1 0 -1 2 x(1)h(n −1) 2 2 0 -2 4 x(2)h(n −2) 2 2 0 -2 4 x(3)h(n −3) 2 2 0 -2 4 x(4)h(n −4) 2 2 0 -2 4 x(5)h(n −5) 1 1 0 -1 2 x(6)h(n −6) 1 1 0 -1 2 x(7)h(n −7) y(n) 1 1 1 3 2 4 3 3 3 1 2 _ m x(m)h(n −m) For the overlap-add method, the input is divided into the following length-4 contiguous blocks: x = [ 1, 1, 2, 2 . ¸, . x0 , 2, 2, 1, 1 . ¸, . x1 , ] Convolving each block separately with h gives: y 0 = h ∗x 0 = [1, 1, 1, 3, 0, 2, 4] y 1 = h ∗x 1 = [2, 2, −1, 3, 3, 1, 2] These convolutions can be done by separately folding the two convolution subtables: block 0 block 1 h\x 1 1 2 2 2 2 1 1 1 1 2 2 2 2 2 1 1 0 0 0 0 0 0 0 0 0 -1 -1 -1 -2 -2 -2 -2 -1 -1 2 2 2 4 4 4 4 2 2 The two subblocks begin at the absolute times n = 0, 4, respectively. It follows from time- invariance that the corresponding output blocks will also begin at the same absolute times. Thus, aligning the output blocks according to their absolute timings and adding them up gives the final result: n 0 1 2 3 4 5 6 7 8 9 10 y 0 1 1 1 3 0 2 4 y 1 2 2 -1 3 3 1 2 y 1 1 1 3 2 4 3 3 3 1 2 52 The block diagram and sample processing algorithm are: x y w 0 z -1 z -1 z -1 w 1 w 2 w 3 2 -1 for each input sample x do: w 0 = x y = w 0 −w 2 +2w 3 w 3 = w 2 w 2 = w 1 w 1 = w 0 The corresponding circular-buffer version will be: for each input sample x do: s 0 = ∗p = x s 2 = tap(3, w, p, 2) s 3 = tap(3, w, p, 3) y = s 0 −s 2 +2s 3 cdelay(3, w, &p) where tap-1 is not needed, but tap-2 and tap-3 are. Tap-0 s 0 is the content of the current location pointed to by p, which receives the input sample x. After y is computed, the call to cdelay circularly decrements the pointer p. Problem 4.19 Figure P4.2 shows the contents of the registers w = [w 0 , w 1 , w 1 ] at successive time instants. Each time the circular pointer p = p in points to the w-register that receives the current input, whereas the pointer p out points to the w-register containing the current output, that is, y(n)= x(n −2). Therefore, p out is shifted clockwise by 2 with respect to p in : p out = p in +2 (modulo 3) As p in gets decremented circularly, so does p out . If p in points to w[q in ] and p out to w[q out ], then p in = w+q in p out = w+q out where q out = (q in +2)%3 Thus, the input and output circular indices take on the sequence of values: q in = 0, 2, 1, 0, 2, 1, 0, 2, 1, 0, 2 q out = 2, 1, 0, 2, 1, 0, 2, 1, 0, 2, 1 The following table lists the contents of w for both the linear and circular buffer implementa- tions. In the linear case, w 0 , w 1 and w 2 are simply the input signal delayed by i = 0, 1, 2 units. In the circular case, the down-arrow indicates the w-register receiving the current input, that is, w[q in ], whereas the up-arrow indicates the corresponding output sample, that is, w[q out ]. In the circular case, only one w-register changes value at each time instant. 53 p in w 0 w 1 w 2 p out 0 0 n=0 p in p out p in p out p in p out p in p out 0 n=1 p in p out p in p out p in p out n=2 p in p out p in p out p in p out n=3 n=4 n=5 n=6 n=7 n=8 n=9 n=10 8 8 8 7 7 7 6 6 6 5 5 5 4 4 4 3 3 3 2 2 2 1 1 1 0 0 0 0 0 0 Fig. P4.2 Circular delay-line buffer contents. linear circular n x w 0 w 1 w 2 w 0 w 1 w 2 q in q out y 0 8 8 0 0 8↓ 0 0↑ 0 2 0 1 7 7 8 0 8 0↑ 7↓ 2 1 0 2 6 6 7 8 8↑ 6↓ 7 1 0 8 3 5 5 6 7 5↓ 6 7↑ 0 2 7 4 4 4 5 6 5 6↑ 4↓ 2 1 6 5 3 3 4 5 5↑ 3↓ 4 1 0 5 6 2 2 3 4 2↓ 3 4↑ 0 2 4 7 1 1 2 3 2 3↑ 1↓ 2 1 3 8 0 0 1 2 2↑ 0↓ 1 1 0 2 9 0 0 0 1 0↓ 0 1↑ 0 2 1 10 0 0 0 0 0 0↑ 0↓ 2 1 0 Problem 4.20 The transposed form is obtained by the following rules: 1. Exchange input with output. 2. Reverse all signal flows. 4. Replace all adders by nodes. 3. Replace all nodes by adders. For example, in Fig. 4.2.7, the output adder will be replaced by a node with the signals flowing in reversed directions, and the nodes at the inputs of the delays will be replaced by adders, and x(n) will be exchanged with y(n). The resulting block diagram is shown in Fig. P4.3. We can draw it reversed, as in Fig. 4.3.1. 54 x(n) y(n) v 1 (n) v 2 (n) v 3 (n) z -1 z -1 z -1 h 0 h 1 h 2 h 3 Fig. P4.3 Transposed direct form realization. Let v 1 (n), v 2 (n), and v 3 (n) be the contents of the three delays at time n. They can be thought of as the internal states of the realization. Because of the intervening adders between the delays, the v i (n) are no longer the delayed versions of each other. Rather, each is a delayed version of its input. These inputs will become the contents of the delays at the next time instant. Therefore, the I/O equations describing the filter are in this case: y(n)= v 1 (n)+h 0 x(n) and v 1 (n +1) = v 2 (n)+h 1 x(n) v 2 (n +1) = v 3 (n)+h 2 x(n) v 3 (n +1) = h 3 x(n) This system is equivalent to the original I/O equation (4.2.6). Indeed, down-shifting v 1 (n + 1), we have v 1 (n)= v 2 (n −1)+h 1 x(n −1) Therefore, y(n)= h 0 x(n)+v 1 (n)= h 0 x(n)+ _ h 1 x(n −1)+v 2 (n −1) _ Similarly, down-shifting v 2 (n+1) twice, that is, v 2 (n−1)= v 3 (n−2)+h 2 x(n−2), and v 3 (n+1) three times, that is, v 3 (n −2)= h 3 x(n −3), we get y(n) = h 0 x(n)+h 1 x(n −1)+v 2 (n −1) = h 0 x(n)+h 1 x(n −1)+ _ h 2 x(n −2)+v 3 (n −2) _ = h 0 x(n)+h 1 x(n −1)+h 2 x(n −2)+h 3 x(n −3) which is equivalent to Eq. (4.2.6). The I/O system leads then to the following sample by sample processing algorithm: 55 for each input sample x do: y = v 1 +h 0 x v 1 = v 2 +h 1 x v 2 = v 3 +h 2 x v 3 = h 3 x For Example 4.2.1, Table P4.1 shows the contents of the v i registers at each time instant. The v i are initialized to zero. The v 1 and v 2 entries in each row are obtained by forming v 2 +h 1 x and v 3 + h 2 x of the previous row. The v 3 column is the delayed (down-shifted) version of the h 3 x column. The final result is the same as in Example 4.2.1. n x h 0 x h 1 x h 2 x h 3 x v 1 v 2 v 3 y = v 1 +h 0 x 0 1 1 2 −1 1 0 0 0 1 1 1 1 2 −1 1 2 −1 1 3 2 2 2 4 −2 2 1 0 1 3 3 1 1 2 −1 1 4 −1 2 5 4 2 2 4 −2 2 1 1 1 3 5 2 2 4 −2 2 5 −1 2 7 6 1 1 2 −1 1 3 0 2 4 7 1 1 2 −1 1 2 1 1 3 8 0 0 0 0 0 3 0 1 3 9 0 0 0 0 0 0 1 0 0 10 0 0 0 0 0 1 0 0 1 Table P4.1 Computations in Problem 4.20. Problem 4.21 The generalization of the transposed algorithm to order M is straightforward: for each input sample x do: for i = 0, 1, . . . , M−1 do: v i = v i+1 +h i x v M = h M x y = v 0 where for indexing convenience we introduced v 0 (n)= y(n)= v 1 (n)+h 0 x(n). The following C routine firtr.c is an implementation: /* firtr.c - FIR filter in transposed direct form */ double firtr(M, h, v, x) Usage: y=firtr(M, h, v, x); double *h, *v, x; h=filter, v=state, x=input int M; M=filter order { int i; 56 for (i=0; i<=M-1; i++) v[i] = v[i+1] + h[i] * x; output & update states v[M] = h[M] * x; last state return v[0]; y = v 0 = v 1 +h 0 x } The following stand-alone C program firfiltr.c is the corresponding version of firfilt.c. The only difference is that it uses the routine firtr.c instead of fir.c: /* firfiltr.c - FIR filtering in transposed form */ #include <stdlib.h> #include <stdio.h> #define MAX 64 initial allocation size double firtr(); void main(int argc, char **argv) { FILE *fph; filter file double *h, *v, x, y; filter array, input, output samples int M, i; int max = MAX, dmax = MAX; allocation for h and increment if (argc != 2) { fprintf(stderr, "usage: firfilt hfile <xfile >yfile\n"); exit(0); } if ((fph = fopen(argv[1], "r")) == NULL) { fprintf(stderr, "can’t open filter file: %s\n", argv[1]); exit(0); } h = (double *) calloc(max + 1, sizeof(double)); preliminary allocation for (M=0;; M++) { read h if (M == max) { reallocate h, if necessary max += dmax; h = (double *) realloc((char *) h, (max + 1) * sizeof(double)); } if (fscanf(fph, "%lf", h + M) == EOF) break; } M--; M is filter order h = (double *) realloc((char *) h, (M + 1) * sizeof(double)); final allocation v = (double *) calloc((M + 1), sizeof(double)); while(scanf("%lf", &x) != EOF) { keep reading input samples y = firtr(M, h, v, x); compute output sample printf("%lf\n", y); write output sample } for (i=0; i<M; i++) { input-off transients 57 y = firtr(M, h, v, 0.0); compute output sample printf("%lf\n", y); } } Transposed forms are convenient in some applications, such as in the implementation of FIR decimators and interpolators in multirate applications. MATLAB uses this form to implement its built-in filtering routines. 58 Chapter 5 Problems Problem 5.1 The linearity property follows from: ∞ _ n=−∞ [a 1 x 1 (n)+a 2 x 2 (n)]z −n = a 1 ∞ _ n=−∞ x 1 (n)z −n +a 2 ∞ _ n=−∞ x 2 (n)z −n The delay property follows from: X D (z) = ∞ _ n=−∞ x D (n)z −n = ∞ _ n=−∞ x(n −D)z −n = = ∞ _ k=−∞ x(k)z −(k+D) = z −D ∞ _ k=−∞ x(k)z −k = z −D X(z) where we changed summation index from n to k = n − D, so that n = k + D. The convolution property follows from the linearity and delay properties. Writing y(n) in terms of the delayed replicas of x(n), we have: y(n)= ∞ _ m=−∞ h(m)x(n −m)= ∞ _ m=−∞ h(m)x m (n) Taking z-transforms of both sides and using the linearity and delay properties, we get: Y(z)= ∞ _ m=−∞ h(m)X m (z)= ∞ _ m=−∞ h(m)z −m X(z)= _ ∞ _ m=−∞ h(m)z −m _ X(z) or, Y(z)= H(z)X(z) Problem 5.2 a. From the delay property of z-transforms, X(z)= z −5 Δ(z), where Δ(z)= 1 is the z- transform of δ(n). Thus, X(z)= z −5 . The ROC is the entire z-plane with the exception of the point z = 0. b. Similarly, X(z)= z 5 Δ(z)= z 5 , but now the ROC must only exclude the point at infinity z = ∞. c. The unit-step has z-transform: U(z)= 1/(1 −z −1 ). Thus, X(z)= z −5 U(z)= z −5 1 −z −1 with ROC ¦z¦ > 1. d. We may work with the definition: X(z) = ∞ _ n=−∞ u(−n +5)z −n = 5 _ n=−∞ 1 · z −n = z −5 +z −4 +z −3 +z −2 +z −1 +1 +z +z 2 +z 3 +· · · = z −5 _ 1 +z +z 2 +z 3 +· · · _ = z −5 1 −z = z −5 U(z −1 ) 59 The convergence of the series requires the ROC ¦z¦ < 1. Alternatively, we recognize that x(n) is the delayed version of u(−n), that is, x(n)= u(−n +5)= u(−(n −5)). Using the general property that g(n) Z −→G(z) ⇒ g(−n) Z −→G(z −1 ) we find X(z)= z −5 U(z −1 ). Problem 5.3 a. Using the general result: a n u(n)−→ 1/(1 − az −1 ), ROC ¦z¦ > ¦a¦, we obtain: X(z)= 1/(1 −(−0.5)z −1 )= 1/(1 +0.5z −1 ), with ROC ¦z¦ > ¦ −0.5¦ = 0.5. b. Method 1: Let w(n)= u(n)−u(n − 10) with z-transform W(z). Using the linearity and delay properties, we have W(z)= U(z)−z −10 U(z)= (1 −z −10 )U(z)= 1 −z −10 1 −z −1 Using the modulation property of z-transforms, we have a n w(n)−→W(z/a)= 1 −(z/a) −10 1 −(z/a) −1 = 1 −a 10 z −10 1 −az −1 With a = −0.5, we have X(z)= (1 −(−0.5) 10 z −10 )/(1 +0.5z −1 ). ROC is the whole z-plane minus the point z = 0. Method 2: We recognize that x(n) is the finite sequence x(n)= [1, a, a 2 , a 3 , a 4 , a 5 , a 6 , a 7 , a 8 , a 9 , 0, 0, 0, · · · ] and use the definition of z-transforms: X(z)= 1 +az −1 +a 2 z −2 +· · · +a 9 z −9 = 1 −a 10 z −10 1 −az −1 where in the last step we used the finite geometric series: 1 +x +x 2 +· · · +x m = 1 −x m+1 1 −x , with x = az −1 and m= 9 c. X(z)= 1 1 −0.5z −1 + 1 1 +0.5z −1 = 2 (1 −0.5z −1 )(1 +0.5z −1 ) = 2 1 −0.25z −2 , ROC ¦z¦ > 0.5. Problem 5.4 Using Euler, 2cos θ = e jθ +e −jθ , with θ = πn/2 and also the fact that e jπ/2 = j and e −jπ/2 = −j, we rewrite 2(0.8) n cos(πn/2) = (0.8) n [e jπn/2 +e −jπn/2 ] = (0.8) n [j n +(−j) n ]= (0.8j) n +(−0.8j) n Thus, the signals in questions (a) and (b) are the same. Their z-transform is 60 X(z)= 1 1 −0.8jz −1 + 1 1 +0.8jz −1 = 2 (1 −0.8jz −1 )(1 +0.8jz −1 ) = 2 1 +0.64z −2 ROC is ¦z¦ > ¦0.8j¦ = 0.8. An alternative method is to list a few of the signal values and then use the infinite geometric series to sum them up, that is, with a = 0.8: x(n)= 2[1, 0, −a 2 , 0, a 4 , 0, −a 6 , 0, a 8 , 0, −a 10 , 0, · · · ] we obtain X(z)= 2[1 −a 2 z −2 +a 4 z −4 −a 6 z −6 +a 8 z −8 −a 10 z −10 +· · · ]= 2 1 +a 2 z −2 where we applied the infinite geometric series 1 +x +x 2 +x 3 +· · · = 1 1 −x with x = −a 2 z −2 . Convergence of the geometric series requires that ¦x¦ < 1 or ¦ −a 2 z −2 ¦ < 1 or ¦z¦ > ¦a¦ or in our case ¦z¦ > 0.8. Problem 5.5 The three signals in parts (a,b,c) all have the same z-transform, namely, X(z)= 1 1 −0.25z −1 + 1 1 −4z −1 = 2 −4.25z −1 1 −4.25z −1 +z −2 They differ only in their region of convergence: In case (a), both terms are causal, therefore ¦z¦ > 0.25 and ¦z¦ > 4. Thus, ROC is ¦z¦ > 4. In case (b), the first term requires ¦z¦ > 0.25 while the second ¦z¦ < 4. Combining, we find ROC 0.25 < ¦z¦ < 4. In case (c), both terms are anticausal, thus, ¦z¦ < 0.25 and ¦z¦ < 4. Thus, ROC is ¦z¦ < 0.25. The signal in (d) is unstable from both sides of the time axis. The first term in the z-transform expansion X(z)= − −1 _ n=−∞ (0.25) n z −n + ∞ _ n=0 4 n z −n would require ROC ¦z¦ < 0.25 and the second ¦z¦ > 4. The intersection of the two ROC sets is empty, that is, there is no set of z’s for which the z-transform would converge. Problem 5.6 Method 1: List the values of x(n) and sum the geometric series: x(n) = [1, 0, −1, 0, 1, 0, −1, 0, 1, 0, −1, 0, . . . ] X(z) = 1 −z −2 +z −4 −z −6 +z −8 −· · · = 1 +x +x 2 +x 3 +x 4 +· · · ¸ ¸ x=−z −2 = 1 1 −x ¸ ¸ ¸ ¸ x=−z −2 = 1 1 +z −2 where convergence of the geometric series requires: 61 ¦x¦ < 1 ⇒ ¦ −z −2 ¦ < 1 ⇒ ¦z¦ > 1 Method 2: Use Euler’s formula to split x(n) as the sum of two terms of the form a n u(n): x(n)= cos(πn/2)u(n)= 1 2 _ e πjn/2 +e −πjn/2 _ u(n)= 1 2 [j n +(−j) n ]u(n) where we used e πj/2 = j. Taking z-transforms, we find: X(z)= 1/2 1 −jz −1 + 1/2 1 +jz −1 = 1 (1 −jz −1 )(1 +jz −1 ) = 1 1 +z −2 where we applied the result a n u(n) Z −→ 1 1 −az −1 for a = j and a = −j. Method 3: Recognize that x(n) is periodic with period 4. Defining the length-4 sequence g = [1, 0, −1, 0], we see that x(n) will be the periodic replication of g(n): x = [g, g, g, . . . ] or, x(n)= g(n)+g(n −4)+g(n −8)+g(n −12)+· · · Taking z-transforms of both sides gives X(z)= G(z)+z −4 G(z)+z 8 G(z)+· · · = _ 1 +z −4 +z −8 +z −12 +· · · _ G(z) Summing up the series and using G(z)= 1 −z −2 , we get: X(z)= G(z) 1 −z −4 = 1 −z −2 1 −z −4 = 1 −z −2 (1 −z −2 )(1 +z −2 ) = 1 1 +z −2 Problem 5.7 Whenever X(z) is a polynomial, the best method to invert is to just pick out the coefficients of the polynomial. For (a), we have: X(z) = (1 −4z −2 )(1 +3z −1 )= 1 +3z −1 −4z −2 −12z −3 ⇒ x(n) = [1, 3, −4, −12] For (b), the signal is non-zero only at n = −3, 0, 2: x(n)= 5δ(n)+3δ(n +3)+2δ(n −2) 62 Problem 5.8 a. Carry out a partial fraction expansion: X(z)= 3(1 +0.3z −1 ) 1 −0.81z −2 = 3(1 +0.3z −1 ) (1 −0.9z −1 )(1 +0.9z −1 ) = A 1 −0.9z −1 + B 1 +0.9z −1 where A = _ 3(1 +0.3z −1 ) 1 +0.9z −1 _ z=0.9 = 2, B = _ 3(1 +0.3z −1 ) 1 −0.9z −1 _ z=−0.9 = 1 The first ROC is ¦z¦ > ¦0.9¦ = ¦ −0.9¦, thus both terms will be inverted causally: x(n)= A(0.9) n u(n)+B(−0.9) n u(n) As expected, the answer is stable because the ROC contains the unit circle. The second ROC is ¦z¦ < ¦0.9¦ = ¦ −0.9¦, thus both terms will be inverted anticausally: x(n)= −A(0.9) n u(−n −1)−B(−0.9) n u(−n −1) The answer is unstable, because the ROC does not contain the unit circle. b. Ordinary partial fraction expansion is not valid in this case because the degree of the numerator is the same as the degree of the denominator. However, we may still have an expansion of the form: X(z) = 6 −3z −1 −2z −2 1 −0.25z −2 = 6 −3z −1 −2z −2 (1 −0.5z −1 )(1 +0.5z −1 ) = A+ B 1 −0.5z −1 + C 1 +0.5z −1 where B and C are determined in the usual manner and A is determined by evaluating X(z) at z = 0: A = _ 6 −3z −1 −2z −2 1 −0.25z −2 _ z=0 = _ 6z 2 −3z −2 z 2 −0.25 _ z=0 = −2 −0.25 = 8 B = _ 6 −3z −1 −2z −2 1 +0.5z −1 _ z=0.5 = −4, C = _ 6 −3z −1 −2z −2 1 −0.5z −1 _ z=−0.5 = 2 For the first ROC, ¦z¦ > 0.5, the last two terms will be inverted causally: x(n)= Aδ(n)+B(0.5) n u(n)+C(−0.5) n u(n) For the second ROC, ¦z¦ < 0.5, the two terms will be inverted anticausally: x(n)= Aδ(n)−B(0.5) n u(−n −1)−C(−0.5) n u(−n −1) As expected, only the first inverse is stable because its ROC contains the unit circle. 63 c. The degree of the numerator is strictly greater than the degree of the denominator. The simplest approach in such cases is to use the “remove/restore” method, that is, ignore the numerator completely, do a partial fraction on the denominator, get its inverse z- transform, and finally restore the effect of the numerator. To show these steps, write X(z) = 6 +z −5 1 −0.64z −2 = (6 +z −5 )· _ 1 1 −0.64z −2 _ ≡ (6 +z −5 )W(z)= 6W(z)+z −5 W(z) In the time-domain, we have then x(n)= 6w(n)+w(n −5) Thus, the problem is reduced to the problem of finding w(n). Doing a partial fraction expansion on W(z), we find W(z)= 1 1 −0.64z −2 = 1 (1 −0.8z −1 )(1 +0.8z −1 ) = A 1 −0.8z −1 + B 1 +0.8z −1 where A = B = 0.5. For the ROC ¦z¦ > 0.8, the two terms are inverted causally: w(n)= A(0.8) n u(n)+B(−0.8) n u(n) Inserting in x(n)= 6w(n)+w(n −5), we find x(n) = 6A(0.8) n u(n)+6B(−0.8) n u(n)+A(0.8) n−5 u(n −5) +B(−0.8) n−5 u(n −5) Note that the last two terms are active only for n ≥ 5. For the ROC ¦z¦ < 0.8, we have the anticausal/unstable answer: w(n)= −A(0.8) n u(−n −1)−B(−0.8) n u(−n −1) which gives for x(n): x(n) = −6A(0.8) n u(−n −1)−6B(−0.8) n u(−n −1) −A(0.8) n−5 u(−n +4)−B(−0.8) n−5 u(−n +4) The u(−n+4) was obtained as u(−(n−5)−1). Note also that the last two terms are now active for −n + 4 ≥ 0 or n ≤ 4, that is, x(n) has a slightly causal part extending to the right up to n = 4. This happened because the strictly anticausal signal w(n) was delayed (shifted to the right) by 5 time units by the term w(n −5). d. The minor new feature of this problem is that the poles are complex-valued. When the poles are complex, they come in conjugate pairs. In this case, the corresponding residues are complex conjugates, too. Thus, only half of the residues need be computed: X(z) = 10 +z −2 1 +0.25z −2 = 10 +z −2 (1 −0.5jz −1 )(1 +0.5jz −1 ) = A+ B 1 −0.5jz −1 + B ∗ 1 +0.5jz −1 64 Again, the A-term is needed because the degrees of numerator and denominator polyno- mials are equal. We find A = _ 10 +z −2 10.25z −2 _ z=0 = _ 10z 2 +1 z 2 +0.25 _ z=0 = 1 0.25 = 4 B = _ 10 +z −2 1 +0.5jz −1 _ z=0.5j = 3 We only needed to calculate B, and use B ∗ for the conjugate pole. For the causal case, we have x(n)= Aδ(n)+B(0.5j) n u(n)+B ∗ (−0.5j) n u(n) Now, because the last two terms are complex conjugates of each other, we may use the general identity 2Re(z)= z +z ∗ to write B(0.5j) n u(n)+B ∗ (−0.5j) n u(n)= 2Re[B(0.5j) n u(n)]= 6(0.5) n Re[j n ]u(n) But, Re[j n ]= Re[e jπn/2 ]= cos(πn/2) Thus, B(0.5j) n u(n)+B ∗ (−0.5j) n u(n)= 6(0.5) n cos(πn/2)u(n) and the final result is x(n)= 4δ(n)+6(0.5) n cos(πn/2)u(n) For the anticausal case, we obtain the anticausal version of the second term, namely, x(n)= 4δ(n)−6(0.5) n cos(πn/2)u(−n −1) e. The partial fraction expansion is: X(z)= 6 −2z −1 −z −2 (1 −z −1 )(1 −0.25z −2 ) = 4 1 −z −1 + 1 1 −0.5z −1 + 1 1 +0.5z −1 Because ROC is ¦z¦ > 1 > 0.5, all terms are inverted causally to give: x(n)= 4u(n)+(0.5) n u(n)+(−0.5) n u(n) The answer is marginally stable because the pole z = 1 is on the unit circle. f. The PF expansion gives: X(z) = −4 + 1 1 +4z −2 = −4 + 1 (1 −2jz −1 )(1 +2jz −1 ) = −4 + 1/2 1 −2jz −1 + 1/2 1 +2jz −1 The two regions of convergence are: ¦z¦ > 2 and ¦z¦ < 2 65 They correspond to the causal and anticausal inverses: x 1 (n) = −4δ(n)+0.5(2j) n u(n)+0.5(−2j) n u(n) x 2 (n) = −4δ(n)−0.5(2j) n u(−n −1)+0.5(−2j) n u(−n −1) Using Euler’s formula, we may write: 0.5 _ (2j) n +(−2j) n ] = 2 n 1 2 [j n +(−j) n ]= 2 n 1 2 [e jπn/2 +e −jπn/2 ] = 2 n cos(πn/2) Thus, we can rewrite: x 1 (n) = −4δ(n)+2 n cos(πn/2)u(n) x 2 (n) = −4δ(n)−2 n cos(πn/2)u(−n −1) Only x 2 (n) is stable because its ROC contains the unit circle, or, because in the second termn is effectively negative and causes it to decay exponentially for large negative n, that is, writing n = −¦n¦, we have: 2 n cos(πn/2)u(−n −1)= 2 −¦n¦ cos(πn/2)u(−n −1)→0 as n →−∞ g. The PF expansion is in this case: X(z)= 4 −0.6z −1 +0.2z −2 (1 −0.5z −1 )(1 +0.4z −1 ) = A+ B 1 −0.5z −1 + C 1 +0.4z −1 where A = _ 4 −0.6z −1 +0.2z −2 (1 −0.5z −1 )(1 +0.4z −1 ) _ z=0 = 0.2 −0.5 · 0.4 = −1 B = _ 4 −0.6z −1 +0.2z −2 1 +0.4z −1 _ z=0.5 = 2 C = _ 4 −0.6z −1 +0.2z −2 1 −0.5z −1 _ z=−0.4 = 3 The three ROC’s are: ¦z¦ > 0.5, 0.5 > ¦z¦ > 0.4, 0.4 > ¦z¦ The corresponding inverses are: x 1 (n) = Aδ(n)+B(0.5) n u(n)+C(−0.4) n u(n) x 2 (n) = Aδ(n)−B(0.5) n u(−n −1)+C(−0.4) n u(n) x 3 (n) = Aδ(n)−B(0.5) n u(−n −1)−C(−0.4) n u(−n −1) Only x 1 (n) is stable. Its ROC contains the unit circle. The B-term in x 2 (n) and both the B and C terms of x 3 (n) diverge exponentially for large negative n. 66 Problem 5.9 Consider the z-transform pair: x a (n)= a n u(n) X a (z)= 1 1 −az −1 Applying the derivative operator ∂/∂a to the pair, derive the z-transform of the sequence x(n)= na n u(n). Noting that ∂ ∂a x a (n)= na n−1 u(n) we get ∂ ∂a X a (z)= ∂ ∂a _ 1 1 −az −1 _ = z −1 (1 −az −1 ) 2 Thus, na n−1 u(n) Z −→ z −1 (1 −az −1 ) 2 Multiplying by a, we get: na n u(n) Z −→ az −1 (1 −az −1 ) 2 Problem 5.10 We note that each application of D brings down a factor of n: D(a n ) = a ∂ ∂a (a n )= ana n−1 = na n D 2 (a n ) = D(D(a n ))= D(na n )= nD(a n )= n(na n )= n 2 a n D 3 (a n ) = D(D 2 (a n ))= D(n 2 a n )= n 2 D(a n )= n 2 (na n )= n 3 a n · · · D k (a n ) = n k a n Thus, in the z-domain: n k a n u(n) Z −→ _ a ∂ ∂a _ k _ 1 1 −az −1 _ In particular, for k = 1, we have: _ a ∂ ∂a __ 1 1 −az −1 _ = az −1 (1 −az −1 ) 2 Therefore, na n u(n) Z −→ az −1 (1 −az −1 ) 2 67 which agrees with the previous problem. For k = 2, we apply D again to get: _ a ∂ ∂a _ 2 _ 1 1 −az −1 _ = _ a ∂ ∂a _ _ az −1 (1 −az −1 ) 2 _ = az −1 _ 1 (1 −az) 2 + 2az −1 (1 −az −1 ) 3 _ = az −1 (1 +az −1 ) (1 −az −1 ) 3 Therefore, n 2 a n u(n) Z −→ az −1 (1 +az −1 ) (1 −az −1 ) 3 Adding the results of the k = 1 and k = 2 cases, we also get: n(n +1)a n u(n) Z −→ 2az −1 (1 −az −1 ) 3 For the cases k = 3, 4, we find after some tedious algebra: n 3 a n u(n) Z −→ az −1 (1 +4az −1 +a 2 z −2 ) (1 −az −1 ) 4 n 4 a n u(n) Z −→ az −1 (1 +11az −1 +11a 2 z −2 +a 3 z −3 ) (1 −az −1 ) 5 Problem 5.11 Defining the square pulses g 1 (n) = u(n)−u(n −L) g 2 (n) = g 1 (n +L −1)= u(n +L −1)−u(n −1) and using the z-transform u(n) Z −→U(z)= 1 1 −z −1 we find the z-transforms: G 1 (z) = U(z)−z −L U(z)= 1 −z −L 1 −z −1 G 2 (z) = U(z)z L−1 −z −1 U(z)= 1 −z −L 1 −z −1 z L−1 Therefore, the right-hand-side of the desired z-transform is the product: X(z)= 1 L _ 1 −z −L 1 −z −1 _ 2 z L−1 = 1 L G 1 (z)G 2 (z) Thus, in the time domain we have the convolution: x(n)= 1 L g 1 (n)∗g 2 (n)= 1 L _ m g 1 (m)g 2 (n −m) 68 Because g 1 (n) is non-zero only over 0 ≤ n ≤ L −1 and g 2 (n) over −(L −1)≤ n ≤ 0, we obtain the restrictions on the convolution summation indices: 0 ≤ m≤ L −1 −(L −1) ≤ n −m≤ 0 By adding them, we obtain the overall range of the index n of x(n), that is, −(L −1)≤ n ≤ L −1 For any n in this range, we obtain the range of the summation in m: 0 ≤ m≤ L −1 0 ≤ m−n ≤ L −1 ⇒ n ≤ m≤ n +L −1 which combine into the single inequality: max(0, n)≤ m≤ min(L −1, n +L −1) The convolution sum becomes then: x(n)= 1 L min(L−1,n+L−1) _ m=max(0,n) g 1 (m)g 2 (n −m), −(L −1)≤ n ≤ L −1 Because over this range, both g 1 (n) and g 2 (n) are unity, we obtain: x(n)= 1 L min(L−1,n+L−1) _ m=max(0,n) 1 · 1 = 1 L _ max(L −1, n +L −1)−min(0, n)+1 _ By checking separately the ranges −(L − 1)≤ n ≤ 0 and 0 ≤ n ≤ L − 1, it is easily verified that the above expression is equivalent to: x(n)= 1 L _ max(L −1, n +L −1)−min(0, n)+1 _ = 1 − ¦n¦ L , −(L −1)≤ n ≤ L −1 At all other n, including the end-points n = :L, x(n) is zero. Problem 5.12 Start with the result a n u(n) Z −→ 1 1 −az −1 and apply it for a = Re jω0 and a ∗ = Re −jω0 : R n e jω0n u(n) Z −→ 1 1 −Re jω0 z −1 R n e −jω0n u(n) Z −→ 1 1 −Re −jω0 z −1 The cosine and sine signals are obtained from the above as the following linear combinations: R n cos(ω 0 n)u(n) = R n 1 2 _ e jω0n u(n)+e −jω0n u(n) _ R n sin(ω 0 n)u(n) = R n 1 2j _ e jω0n u(n)−e −jω0n u(n) _ 69 Therefore, the corresponding linear combinations of z-transforms will be: R n cos(ω 0 n)u(n) Z −→ 1 2 _ 1 1 −Re jω0 z −1 + 1 1 −Re −jω0 z −1 _ R n sin(ω 0 n)u(n) Z −→ 1 2j _ 1 1 −Re jω0 z −1 − 1 1 −Re −jω0 z −1 _ which simplify into: R n cos(ω 0 n)u(n) Z −→ 1 −Rcos ω 0 z −1 1 −2Rcos ω 0 z −1 +R 2 z −2 R n sin(ω 0 n)u(n) Z −→ Rsinω 0 z −1 1 −2Rcos ω 0 z −1 +R 2 z −2 Problem 5.13 Define the z-transform of one period: A(z)= a 0 +a 1 z −1 +a 2 z −2 +a 3 z −3 Then, the z-transform of the periodic signal is recognized as the sum of the delayed replicas of A(z), that is, X(z) = a 0 +a 1 z −1 +a 2 z −2 +a 3 z −3 +a 0 z −4 +a 1 z −5 +a 2 z −6 +a 3 z −7 +a 0 z −8 +a 1 z −9 +a 2 z −10 +a 3 z −11 +· · · = (a 0 +a 1 z −1 +a 2 z −2 +a 3 z −3 )+z −4 (a 0 +a 1 z −1 +a 2 z −2 +a 3 z −3 ) +z −8 (a 0 +a 1 z −1 +a 2 z −2 +a 3 z −3 )+· · · = A(z)+z −4 A(z)+z −8 A(z)+· · · = (1 +z −4 +z −8 +· · · )A(z)= A(z) 1 −z −4 = a 0 +a 1 z −1 +a 2 z −2 +a 3 z −3 1 −z −4 where the convergence of the geometric series requires the ROC ¦z¦ > 1. Problem 5.14 Factoring the denominator 1 −z −4 , we obtain the PF expansion: X(z) = a 0 +a 1 z −1 +a 2 z −2 +a 3 z −3 1 −z −4 = a 0 +a 1 z −1 +a 2 z −2 +a 3 z −3 (1 −z −1 )(1 +z)(1 −jz −1 )(1 +jz −1 ) = A 1 −z −1 + B 1 +z −1 + C 1 −jz −1 + C ∗ 1 +jz −1 where the coefficients C and C ∗ are conjugates because they correspond to the conjugate poles :j (this follows from the fact that the denominator has real coefficients.) The PFE coefficients are determined as follows: 70 A = _ a 0 +a 1 z −1 +a 2 z −2 +a 3 z −3 (1 +z)(1 −jz −1 )(1 +jz −1 ) _ z=1 = a 0 +a 1 +a 2 +a 3 4 B = _ a 0 +a 1 z −1 +a 2 z −2 +a 3 z −3 (1 −z −1 )(1 −jz −1 )(1 +jz −1 ) _ z=−1 = a 0 −a 1 +a 2 −a 3 4 C = _ a 0 +a 1 z −1 +a 2 z −2 +a 3 z −3 (1 −z −1 )(1 +z)(1 +jz −1 ) _ z=j = (a 0 −a 2 )−j(a 1 −a 3 ) 4 ≡ C R −jC I Taking (causal) inverse z-transforms of the PF expansion, we obtain for n ≥ 0: x(n) = A+B(−1) n +Cj n +C ∗ (−j) n = A+B(−1) n +Ce jπn/2 +C ∗ e −jπn/2 = A+B(−1) n +2Re _ Ce jπn/2 _ = A+B(−1) n +2Re _ (C R −jC I )e jπn/2 _ = A+B(−1) n +2C R cos(πn/2)+2C I sin(πn/2) So that finally: x(n) = a 0 +a 1 +a 2 +a 3 4 + a 0 −a 1 +a 2 −a 3 4 (−1) n + a 0 −a 2 2 cos(πn/2)+ a 1 −a 3 2 sin(πn/2) Setting n = 0, 1, 2, 3, we can verify the first four values ¦a 0 , a 1 , a 2 , a 3 ¦. Problem 5.15 Summing the geometric series, we have: X(z)= 1 −z −2 +z −4 −z −6 +z −8 −· · · = 1 1 +z −2 Alternatively, we have: X(z)= 1−z −2 +z −4 −z −6 +z −8 −· · · = 1−z −2 (1−z −2 +z −4 −z −6 +z −8 −· · · )= 1−z −2 X(z) which gives (1 +z −2 )X(z)= 1 ⇒ X(z)= 1 1 +z −2 The inverse z-transform is causal and can be obtained from the PFE: X(z)= 1 1 +z −2 = 0.5 1 −jz −1 + 0.5 1 +jz −1 which gives: x(n)= _ 0.5j n +0.5(−j) n _ u(n)= cos(πn/2)u(n) 71 Problem 5.16 In all cases, we expand in the appropriate geometric series and pick out the coefficients of the expansion. a. The z-transform and its inverse are: X(z) = 1 1 +z −4 = 1 −z −4 +z −8 −z −12 +z −16 −· · · x(n) = [1, 0, 0, 0, −1, 0, 0, 0, 1, 0, 0, 0, −1, 0, 0, 0, 1, . . . ] b. The z-transform and its inverse are: X(z) = 1 1 −z −4 = 1 +z −4 +z −8 +z −12 +z −16 +· · · x(n) = [1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, . . . ] c. The z-transform and its inverse are: X(z) = 1 1 +z −8 = 1 −z −8 +z −16 −z −24 +· · · x(n) = [1, 0, 0, 0, 0, 0, 0, 0, −1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, −1, . . . ] d. The z-transform and its inverse are: X(z) = 1 1 −z −8 = 1 +z −8 +z −16 +z −24 +· · · x(n) = [1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, . . . ] Problem 5.17 For case (a), the roots of the denominator are the solutions of 1 +z −4 = 0 or, z 4 = −1. They are obtained as follows: z 4 = −1 = e jπ = e jπ+2jπk ⇒ z = e (jπ+2jπk)/4 , k = 0, 1, 2, 3 that is, the four numbers z = e jπ/4 , e 3jπ/4 , e 5jπ/4 , e 7jπ/4 which are the conjugate pairs: z = e :jπ/4 , e :3jπ/4 Thus, the z-transform factors as follows and has the PF expansion: X(z) = 1 1 +z −3 = 1 (1 −e jπ/4 z −1 )(1 −e −jπ/4 z −1 )(1 −e 3jπ/4 z −1 )(1 −e −3jπ/4 z −1 ) = A 1 −e jπ/4 z −1 + A ∗ 1 −e −jπ/4 z −1 + B 1 −e 3jπ/4 z −1 + B ∗ 1 −e −3jπ/4 z −1 where the coefficients are: 72 A = _ 1 (1 −e −jπ/4 z −1 )(1 −e 3jπ/4 z −1 )(1 −e −3jπ/4 z −1 ) _ z=e πj/4 = 1 4 B = _ 1 (1 −e jπ/4 z −1 )(1 −e −jπ/4 z −1 )(1 −e −3jπ/4 z −1 ) _ z=e 3πj/4 = 1 4 Thus, we find the causal inverse for n ≥ 0: x(n) = 1 4 e jπn/4 + 1 4 e −jπn/4 + 1 4 e 3jπn/4 + 1 4 e −jπn/4 = 1 2 cos(πn/4)+ 1 2 cos(3πn/4) Cases (b,c,d) are done in a similar fashion. See the solution of Problem 5.19 for the denominator zeros. Problem 5.18 Let Q(z) and R(z) be the quotient and remainder polynomials of the division of N(z) by D(z). Then, Q(z) will have degree L −M, R(z) degree M−1. Thus, N(z)= Q(z)D(z)+R(z) It follows that: H(z)= N(z) D(z) = Q(z)D(z)+R(z) D(z) = Q(z)+ R(z) D(z) Because the degree of R(z) is strictly less than the degree of D(z), the term R(z)/D(z) will admit a PF expansion of the form: R(z) D(z) = M _ i=1 A i 1 −p i z −1 where p i are the M zeros of D(z) or the poles of H(z). Any truly complex poles will come in conjugate pairs, that is, of the type: A i 1 −p i z −1 + A ∗ i 1 −p ∗ i z −1 which can be assembled into the 2nd order section: A i 1 −p i z −1 + A ∗ i 1 −p ∗ i z −1 = (A i +A ∗ i )−(A i p ∗ i +A ∗ i p i )z −1 1 −(p i +p ∗ i )z −1 +p i p ∗ i z −2 where the numerator and denominator coefficients are all real. 73 Problem 5.19 The roots of the polynomial 1 − z −D are the solutions of the equation z D = 1, that is, the D-th roots of unity. To find them, replace 1 by e 2πjk = 1, where k is an integer, and take D-th roots of both sides: z D = 1 = e 2πjk ⇒ z k = e j2πk/D , k = 0, 1, . . . D−1 They lie on the unit circle at the angles ω k = 2πk/D, k = 0, 1, . . . , D−1 obtained by dividing the circle into Dequal parts. The product of the 1st order zero factors must make up the polynomial 1 −z −D : D−1 k=0 (1 −z k z −1 )= 1 −z −D This identity follows from a theorem of algebra that states that if two polynomials have the same set of roots and unity constant coefficient, then they must be identically equal to each other. For the other case, we have the solutions of 1+z −D = 0 or z D = −1. Now, we replace −1 = e πj = e jπ+j2πk with any integer k, and find the roots z D = −1 = e jπ(2k+1) ⇒ z k = e jπ(2k+1)/D , k = 0, 1, . . . , D−1 They also lie on the unit circle at D equal divisions, but they are shifted as a whole with respect to the standard D-th roots of unity by a rotation angle of π/D. Fig. P5.1 shows the two cases for D = 8. z 8 = 1 z 8 = -1 Fig. P5.1 Roots of 1 −z −8 and 1 +z −8 . Problem 5.20 The roots of 1 −az −D are the solutions of the equation z D = a = ae j2πk ⇒ z k = a 1/D e j2πk/D , k = 0, 1, . . . , D−1 They all lie on a circle of radius a 1/D at the D-th root of unity angles. Similarly, the roots of 1 +az −D , lie on the same circle, but at the shifted D-th root of unity angles. Problem 5.21 Let y(n)= a n x(n). Its z-transform is: Y(z)= _ n y(n)z −n = _ n a n x(n)z −n = _ n x(n)(z/a) −n 74 Comparing with X(z)= _ n x(n)z −n we see that Y(z)= X(z/a) Since the spectrum X(ω) is obtained by replacing z = e jω , the scaled z will be z/a = e jω /e jω0 = e j(ω−ω0) Thus, the relationship Y(e jω )= X(e j(ω−ω0) ) may be written as Y(ω)= X(ω−ω 0 ) Alternatively, we may work directly with the definition of the DTFT: Y(ω)= _ n y(n)e −jωn = _ n e jω0n x(n)e −jωn = _ n x(n)e −j(ω−ω0)n = X(ω−ω 0 ) Problem 5.22 We use the identity 1 2π _ π −π e jω(n−m) dω= δ(n −m) for n, m integers. Indeed, for n = m the left hand side is unity. And, for n }= m, we have: 1 2π _ π −π e jω(n−m) dω= cos _ π(n −m) _ −cos _ −π(n −m) _ 2πj(n −m) = 0 Inserting the definition of the DTFT into the inversion formula, we get 1 2π _ π −π X(ω)e jωn dω= 1 2π _ π −π _ _ m x(m)e −jωm _ e jωn dω = _ m x(m) 1 2π _ π −π e jω(n−m) dω= _ m x(m)δ(n −m) = x(n) where we interchanged the series with the integral (this step is justified by assuming that the series is convergent, that is, the unit circle lies in the ROC or that the signal x(n) is strictly stable). Problem 5.23 We may assume in general that x(n) is complex-valued. Then, we have: X(ω) = _ n x(n)e −jωn X ∗ (ω) = _ n x ∗ (n)e jωn 75 Using the inverse DTFT formula, it follows that 1 2π _ π −π X(ω)X ∗ (ω) dω= 1 2π _ π −π X(ω) _ _ n x ∗ (n)e jωn _ dω = _ n x ∗ (n) _ 1 2π _ π −π X(ω)e jωn dω _ = _ n x ∗ (n)x(n) Problem 5.24 For a real-valued signal x(n), we have: X(ω) = _ n x(n)e −jωn X ∗ (ω) = _ n x(n)e jωn X ∗ (−ω) = _ n x(n)e −jωn where in the third equation, we replaced ω by −ω. Comparing the first and third equations, we obtain: X ∗ (−ω)= X(ω) Writing X(ω) in its polar form, e.g., X(ω)= ¦X(ω)¦e j arg X(ω) , the hermitian property reads: _ ¦X(−ω)¦e j arg X(−ω) _ ∗ = ¦X(ω)¦e j arg X(ω) or, ¦X(−ω)¦e −j arg X(−ω) = ¦X(ω)¦e j arg X(ω) Equating magnitudes and phases, we get the conditions: ¦X(−ω)¦ = ¦X(ω)¦ , arg X(−ω)= −arg X(ω) that is, the magnitude spectrum is even in ω and the phase spectrum is odd. 76 Chapter 6 Problems Problem 6.1 a. From Y(z)= −0.8z −1 Y(z)+X(z) it follows: H(z)= 1 1 +0.8z −1 ⇒ H(ω)= 1 1 +0.8e −jω The causal inverse z-transform of H(z) is h(n)= (−0.8) n u(n). There is only one pole at z = −0.8, that is, near the “high frequency” part of the unit circle. Thus, the filter will tend to enhance high frequencies, i.e., it will behave as a high pass filter: = pole z-plane -0.8 1 π ω 0 5 0.55 |H(ω)| Block diagram realization and the sample-by-sample processing algorithm: x -0.8 y y z -1 w 1 for each input sample x do: y = −0.8w 1 +x w 1 = y b. Change −0.8 to 0.8 in the above problem. Now the pole at z = 0.8 is in the “low frequency” part of the unit circle and the filter is acting as a low pass filter. c. The I/O equation Y(z)= 0.8z −1 Y(z)+X(z)+z −1 X(z) gives H(z)= 1 +z −1 1 −0.8z −1 = A+ B 1 −0.8z −1 ⇒ h(n)= Aδ(n)+B(0.8) n u(n) where A = _ 1 +z −1 1 −0.8z −1 _ z=0 = −1.25, B = _ 1 +z −1 _ z=0.8 = 2.25 The filter enhances lowfrequencies for two reasons: first, it has a pole in the lowfrequency range, z = 0.8, and it has a zero in the high frequency range, z = −1. Its frequency response will be H(ω)= 1 +e −jω 1 −0.8e −jω 77 z-plane 0.8 -1 = poles = zeros π ω 0 10 exact zero |H(ω)| The canonical form realization and its sample processing algorithm are: x 0.8 y w 0 z -1 w 1 for each input sample x do: w 0 = 0.8w 1 +x y = w 0 +w 1 w 1 = w 0 The direct form realization and its sample processing algorithm are: x 0.8 y z -1 z -1 v 1 w 1 for each input sample x do: y = 0.8w 1 +x +v 1 v 1 = x w 1 = y d. The I/O equation Y(z)= 0.8z −1 Y(z)+X(z)−0.5z −1 X(z) gives H(z)= 1 −0.5z −1 1 −0.8z −1 = A+ B 1 −0.8z −1 ⇒ h(n)= Aδ(n)+B(0.8) n u(n) where A = _ 1 −0.5z −1 1 −0.8z −1 _ z=0 = 0.625, B = _ 1 −0.5z −1 _ z=0.8 = 0.375 The filter has a zero at z = 0.5 and a pole at z = 0.8 — both in the low frequency range. Thus, their effect will be to cancel each other, and whichever is closest to the unit circle ultimately wins. Here, the pole is nearer. Thus, the filter will tend to act as a lowpass filter. Indeed, its response at ω = 0 or z = 1 is (1 −0.5)/(1 −0.8)= 2.5, whereas its response at ω= π or z = −1 is (1 +0.5)/(1 +0.8)= 0.833. z-plane 0.8 0.5 = poles = zeros π ω 0 2.5 0.833 |H(ω)| The canonical form realization and its sample processing algorithm are: 78 x 0.8 -0.5 y w 0 z -1 w 1 for each input sample x do: w 0 = 0.8w 1 +x y = w 0 −0.5w 1 w 1 = w 0 The direct form realization and its sample processing algorithm are: x 0.8 -0.5 y z -1 z -1 v 1 w 1 for each input sample x do: y = 0.8w 1 +x −0.5v 1 v 1 = x w 1 = y e. Y(z)= 0.8z −1 Y(z)+X(z)+0.25z −2 X(z) ⇒ H(z)= 1 +0.25z −2 1 −0.8z −1 . Using the “remove/restore numerator” method of problem (2h), we find h(n)= (0.8) n u(n)+0.25(0.8) n−2 u(n −2) The filter has two conjugate zeros at midrange, z = :0.5j = 0.5e :jπ/2 , and a lowfrequency pole at z = 0.8. Thus, the filter will enhance low frequencies and suppress midrange frequencies: z-plane 0.8 0.5j -0.5j = poles = zeros π ω 0 |H(ω)| The canonical form realization and its sample processing algorithm are: x 0.8 0.25 y w 0 z -1 z -1 w 1 w 2 for each input sample x do: w 0 = 0.8w 1 +x y = w 0 +0.25w 2 w 2 = w 1 w 1 = w 0 The direct form realization and its sample processing algorithm are: 79 x 0.8 0.25 y z -1 z -1 z -1 v 1 v 2 w 1 for each input sample x do: y = x +0.25v 2 +0.8w 1 v 2 = v 1 v 1 = x w 1 = y f. Y(z)= 0.9z −1 Y(z)−0.2z −2 Y(z)+X(z)+z −1 X(z)−6z −2 X(z), which implies H(z)= 1 +z −1 −6z −2 1 −0.9z −1 +0.2z −2 Factor numerator and denominator and expand in partial fractions: H(z)= (1 +3z −1 )(1 −2z −1 ) (1 −0.4z −1 )(1 −0.5z −1 ) = A+ B 1 −0.4z −1 + C 1 −0.5z −1 where A = _ (1 +3z −1 )(1 −2z −1 ) (1 −0.4z −1 )(1 −0.5z −1 ) _ z=0 = −30 B = _ (1 +3z −1 )(1 −2z −1 ) 1 −0.5z −1 _ z=0.4 = 136 C = _ (1 +3z −1 )(1 −2z −1 ) 1 −0.4z −1 _ z=0.5 = −105 Thus, h(n)= Aδ(n)+B(0.4) n u(n)+C(0.5) n u(n). The two zeros at z = −3 and z = 2 are too far from the unit circle to have any significant effect on the magnitude response. The two poles at z = 0.4, 0.5 are both in the low frequency range. Thus, the filter will be a low pass filter. The value of the magnitude response at ω= 0 or z = 1 is ¦1+1−6¦/¦1−0.5¦¦1− 0.4¦ = 13.33, whereas its value at ω= πor z = −1 is ¦1−1−6¦/¦1+0.5¦¦1+0.4¦ = 2.86. z-plane 0.5 0.4 -3 2 = poles = zeros π ω 0 13.33 2.86 |H(ω)| The canonical form realization and its sample processing algorithm are: 80 x 0.9 -6 -0.2 y w 0 z -1 z -1 w 1 w 2 for each input sample x do: w 0 = x +0.9w 1 −0.2w 2 y = w 0 +w 1 −6w 2 w 2 = w 1 w 1 = w 0 The direct form realization and its sample processing algorithm are: x 0.9 -6 -0.2 y z -1 z -1 z -1 z -1 v 1 v 2 w 1 w 2 for each input sample x do: y = x +v 1 −6v 2 +0.9w 1 −0.2w 2 v 2 = v 1 v 1 = x w 2 = w 1 w 1 = y Problem 6.2 a. Setting x(n)= u(n) in the I/O difference equation, we find y(n)= u(n)+6u(n −1)+11u(n −2)+6u(n −3) The 4th term is active only for n ≥ 3, the 3d term is active only n ≥ 2, and the 2nd term only for n ≥ 2. Thus, evaluating at a few n’s we find: y(n)= [1, 7, 18, 24, 24, 24, 24, . . . ] The first 3 outputs are the initial transients, the remaining constant values are the steady part. Note that when you send in a unit step, the output always settles to a constant value (for a stable filter). That constant value can be easily precalculated as H(1). In the present case, H(1)= 1 +6 +11 +6 = 24. For the alternating step, we have: Y(z) = 1 +6z −1 +11z −2 +6z −3 1 +z −1 = 1 +5z −1 +6z −2 y(n) = [1, 5, 6, 0, 0, 0, · · · ] There is a pole zero cancellation: the filter has a zero at z = −1, cutting off the high- frequency input. b. Noting that the input z-transform is X(z)= 1/(1 −z −1 ), we find Y(z)= H(z)X(z)= 1 −z −4 1 −z −1 = 1 +z −1 +z −2 +z −3 where we used the finite geometric series. Inverting, we get 81 y(n)= [1, 1, 1, 1, 0, 0, 0, 0, . . . ] The first four samples are the transients, the remaining zeros are the steady state. In the steady-state, the filter cuts off the unit step from going through because the filter has a zero at z = 1. The pole of the input canceled the zero of the filter. For the alternating step: Y(z)= 1 −z −4 1 +z −1 = 1 −z −1 +z −2 −z −3 ⇒ y(n)= [1, −1, 1, −1, 0, 0, 0, · · · ] Again, the filter has a high frequency zero at z = −1, cutting off the high frequency input. Problem 6.3 For filter (a), we have: Y(z) = 1 (1 −z −1 )(1 −0.25z −2 ) = 1 (1 −z −1 )(1 −0.5z −1 )(1 +0.5z −1 ) = A 1 −z −1 + B 1 −0.5z −1 + C 1 +0.5z −1 y(n) = Au(n)+B(0.5) n u(n)+C(−0.5) n u(n) where A = H(1)= 4/3, B = −0.5, C = 1/6. The A-term is the steady part. For the alternating step, we have: Y(z) = 1 (1 +z −1 )(1 −0.25z −2 ) = 1 (1 +z −1 )(1 −0.5z −1 )(1 +0.5z −1 ) = A 1 +z −1 + B 1 −0.5z −1 + C 1 +0.5z −1 y(n) = A(−1) n u(n)+B(0.5) n u(n)+C(−0.5) n u(n) where A = H(−1)= 4/3, B = 1/6, C = −0.5. The A-term is the steady part. For (b), we have: Y(z) = 1 (1 −z −1 )(1 +0.25z −2 ) = 1 (1 −z −1 )(1 −0.5jz −1 )(1 +0.5jz −1 ) = A 1 −z −1 + B 1 −0.5jz −1 + B ∗ 1 +0.5jz −1 y(n) = Au(n)+B(0.5j) n u(n)+B ∗ (−0.5j) n u(n) where A = H(1)= 4/5 and B = _ 1 (1 −z −1 )(1 +0.5jz −1 ) _ z=0.5j = 0.1 −0.2j And, for the alternating step: Y(z) = 1 (1 +z −1 )(1 +0.25z −2 ) = 1 (1 +z −1 )(1 −0.5jz −1 )(1 +0.5jz −1 ) = A 1 +z −1 + B 1 −0.5jz −1 + B ∗ 1 +0.5jz −1 y(n) = A(−1) n u(n)+B(0.5j) n u(n)+B ∗ (−0.5j) n u(n) 82 where A = H(−1)= 4/5 and B = _ 1 (1 +z −1 )(1 +0.5jz −1 ) _ z=0.5j = 0.1 +0.2j Problem 6.4 For a unit-step input and the filter (a) of Problem 6.1, we have: Y(z) = H(z)X(z)= 1 (1 +0.8z −1 )(1 −z −1 ) = A 1 +0.8z −1 + B 1 −z −1 y(n) = A(−0.8) n u(n)+Bu(n) where A = 1/2.25, B = H(1)= 1/1.8. The B-term represents the steady part. For filter (b): Y(z) = H(z)X(z)= 1 (1 −0.8z −1 )(1 −z −1 ) = A 1 −0.8z −1 + B 1 −z −1 y(n) = A(0.8) n u(n)+Bu(n) where A = −4, B = H(1)= 5. The B-term represents the steady part. For filter (c): Y(z) = 1 +z −1 (1 −z −1 )(1 −0.8z −1 ) = A 1 −z −1 + B 1 −0.8z −1 y(n) = Au(n)+B(0.8) n u(n) with A = H(1)= 10, B = −9. For filter (d): Y(z) = 1 −0.5z −1 (1 −z −1 )(1 −0.8z −1 ) = A 1 −z −1 + B 1 −0.8z −1 y(n) = Au(n)+B(0.8) n u(n) with A = H(1)= 2.5, B = −1.5. For filter (e): Y(z) = 1 +0.25z −2 (1 −z −1 )(1 −0.8z −1 ) = A+ B 1 −z −1 + C 1 −0.8z −1 y(n) = Aδ(n)+Bu(n)+C(0.8) n u(n) where A = Y(0)= 0.3125, B = H(1)= 6.25, C = −5.5625. The B-term is the steady part. For filter (f): Y(z) = 1 +z −1 −6z −2 (1 −z −1 )(1 −0.4z −1 )(1 −0.5z −1 ) = A 1 −z −1 + B 1 −0.4z −1 + C 1 −0.5z −1 y(n) = Au(n)+B(0.4) n u(n)+C(0.5) n u(n) For the alternating step and filter (a) of Problem 6.1, we have: Y(z) = 1 (1 +0.8z −1 )(1 +z −1 ) = A 1 +0.8z −1 + B 1 +z −1 y(n) = A(−0.8) n u(n)+B(−1) n u(n) 83 where A = −4, B = H(−1)= 5. The B-term represents the steady part. For filter (b): Y(z) = 1 (1 −0.8z −1 )(1 +z −1 ) = A 1 −0.8z −1 + B 1 +z −1 y(n) = A(0.8) n u(n)+B(−1) n u(n) where A = 1/2.25, B = H(−1)= 1/1.8. The B-term represents the steady part. For filter (c): Y(z) = 1 +z −1 (1 +z −1 )(1 −0.8z −1 ) = 1 1 −0.8z −1 y(n) = (0.8) n u(n) The high frequency zero at z = −1 of the filter canceled the high frequency input signal. The output is only transient — it decays to zero exponentially. For filter (d): Y(z) = 1 −0.5z −1 (1 +z −1 )(1 −0.8z −1 ) = A 1 +z −1 + B 1 −0.8z −1 y(n) = A(−1) n u(n)+B(0.8) n u(n) For filter (e): Y(z) = 1 +0.25z −2 (1 +z −1 )(1 −0.8z −1 ) = A+ B 1 +z −1 + C 1 −0.8z −1 y(n) = Aδ(n)+B(−1) n u(n)+C(0.8) n u(n) The B-term is the steady part. For filter (f): Y(z) = 1 +z −1 −6z −2 (1 +z −1 )(1 −0.4z −1 )(1 −0.5z −1 ) = A 1 +z −1 + B 1 −0.4z −1 + C 1 −0.5z −1 y(n) = A(−1) n u(n)+B(0.4) n u(n)+C(0.5) n u(n) For question (c), the input z-transform is X(z)= 1/(1−0.5z −1 ). Thus, applied to Problem 6.1(d) gives: Y(z) = 1 −0.5z −1 (1 −0.5z −1 )(1 −0.8z −1 ) = 1 1 −0.8z −1 y(n) = (0.8) n u(n) The filter zero canceled the signal pole. For question (d), we have x(n)= (0.5) n cos(πn/2)u(n) Z −→ X(z)= 1/(1 +0.25z −2 ). Thus, Y(z) = 1 +0.25z −2 (1 +0.25z −2 )(1 −0.8z −1 ) = 1 1 −0.8z −1 y(n) = (0.8) n u(n) Again, the signal poles were canceled by the filter zeros. For question (e), the input has X(z)= 1/(1 −2z −1 ). Therefore, 84 Y(z) = (1 +3z −1 )(1 −2z −1 ) (1 −2z −1 )(1 −0.4z −1 )(1 −0.5z −1 ) = 1 +3z −1 (1 −0.4z −1 )(1 −0.5z −1 ) = A 1 −0.4z −1 + B 1 −0.5z −1 y(n) = A(0.4) n u(n)+B(0.5) n u(n) The unstable input was canceled by a filter zero to give a stable output. Problem 6.5 Filter (a): H(z)= z −5 with I/O equation Y(z)= H(z)X(z)= z −5 X(z) and in the time domain y(n)= x(n − 5). H(ω)= e −5jω and ¦H(ω)¦ = 1, i.e., flat in ω. Block diagram realization and sample-by-sample processing algorithm: x y z -1 z -1 z -1 z -1 z -1 w 1 w 2 w 5 w 3 w 4 for each input sample x do: y = w 5 w 5 = w 4 w 4 = w 3 w 3 = w 2 w 2 = w 1 w 1 = x Filter (b): H(z)= z −5 U(z)= z −5 /(1 −z −1 ) and the I/O equation gives Y(z)= H(z)X(z)= z −5 X(z) 1 −z −1 ⇒ (1 −z −1 )Y(z)= z −5 X(z) ⇒ Y(z)= z −1 Y(z)+z −5 X(z) ⇒ y(n)= y(n −1)+x(n −5) Its frequency response is H(ω)= e −5jω 1 −e −jω ⇒ ¦H(ω)¦ = 1 2¦ sin(ω/2)¦ The pole at z = 1 or ω= 0 dominates the frequency response. The filter acts as a lowpass filter (it is actually an accumulator with delay). 85 z-plane 1 = poles π ω 0 0.5 |H(ω)| The canonical form realization and its sample processing algorithm are: x y w 0 z -1 z -1 z -1 z -1 z -1 w 1 w 2 w 5 w 3 w 4 for each input sample x do: w 0 = x +w 1 y = w 5 w 5 = w 4 w 4 = w 3 w 3 = w 2 w 2 = w 1 w 1 = w 0 The direct form realization and its sample processing algorithm are: x y z -1 z -1 z -1 z -1 z -1 z -1 v 1 w 1 v 2 v 5 v 3 v 4 for each input sample x do: y = w 1 +v 5 w 1 = y v 5 = v 4 v 4 = v 3 v 3 = v 2 v 2 = v 1 v 1 = x Filter (c): H(z)= 1/(1 −0.8z −1 ) and the I/O equation becomes: Y(z)= H(z)X(z)= X(z) 1 −0.8z −1 ⇒ (1 −0.8z −1 )Y(z)= X(z) ⇒ Y(z)= 0.8z −1 Y(z)+X(z) 86 and in the time domain y(n)= 0.8y(n −1)+x(n) The rest is as in problem (3d). Filter (d): H(z)= 1/(1 +0.8z −1 ) and the I/O equation becomes: Y(z)= H(z)X(z)= X(z) 1 +0.8z −1 ⇒ (1 +0.8z −1 )Y(z)= X(z) ⇒ Y(z)= −0.8z −1 Y(z)+X(z) ⇒ y(n)= −0.8y(n −1)+x(n) The rest is as in problem (3c). Filter (e): With a = −0.8, the impulse response is finite: h(n)= [1, a, a 2 , a 3 , a 4 , a 5 , a 6 , a 7 , 0, 0, 0, · · · ] Its z-transform is H(z)= 1 +az −1 +a 2 z −2 +a 3 z −3 +a 4 z −4 +a 5 z −5 +a 6 z −6 +a 7 z −7 = 1 −a 8 z −8 1 −az −1 The point z = a is not really a pole of H(z) because it is canceled by a numerator zero — H(z) has seven zeros. To find them, solve the equation z 8 = a 8 and exclude the solution z = a, that is, z = ae 2πjk/8 = −0.8e 2πjk/8 = 0.8e jπ e 2πjk/8 , k = 1, 2, 3, 4, 5, 6, 7 They are shown below z-plane = zeros z=a=-0.8 1 The I/O equation in the time domain is y(n)= x(n)+ax(n −1)+a 2 x(n −2)+· · · +a 7 x(n −7) Sample-by-sample processing algorithm and block diagram realization: for each input sample x do: y = x +aw 1 +a 2 w 2 +a 3 w 3 +a 4 w 4 +a 5 w 5 +a 6 w 6 +a 7 w 7 w 7 = w 6 w 6 = w 5 w 5 = w 4 w 4 = w 3 w 3 = w 2 w 2 = w 1 w 1 = x 87 x y a 0 a 1 w 1 a 2 w 2 a 3 w 3 a 4 w 4 a 5 w 5 a 6 w 6 a 7 w 7 z -1 z -1 z -1 z -1 z -1 z -1 z -1 Filter (f): H(z)= 1 1 −0.8z −1 + 1 1 +0.8z −1 = 2 1 −0.64z −2 Y(z) = H(z)X(z)= 2X(z) 1 −0.64z −2 ⇒ Y(z)= 0.64z −2 Y(z)+2X(z) y(n) = 0.64y(n −2)+2x(n) There is a low frequency pole at z = 0.8 and a high frequency pole at z = −0.8. Thus, the filter will emphasize both the low and high frequencies: z-plane 0.8 -0.8 = poles π π/2 ω 0 |H(ω)| The direct form realization and its sample processing algorithm are: x 0.64 y y z -1 z -1 w 2 w 1 2 for each input sample x do: y = 2x +0.64w 2 w 2 = w 1 w 1 = y Filters (g,h): h(n) = 2(0.8) n cos(πn/2)u(n)= (0.8) n 2Re[j n ]u(n) = (0.8j) n u(n)+(−0.8j) n u(n) H(z) = 1 1 −0.8jz −1 + 1 1 +0.8jz −1 = 2 1 +0.64z −2 Y(z) = H(z)X(z)= 2X(z) 1 +0.64z −2 ⇒ Y(z)= −0.64z −2 Y(z)+2X(z) y(n) = −0.64y(n −2)+2x(n) 88 There is a conjugate pair of poles at midfrequency, z = :0.8j = 0.8e :π/2 . Thus, the filter will emphasize mid frequencies: z-plane 0.8j -0.8j = poles π π/2 ω 0 |H(ω)| The direct form realization and its sample processing algorithm are: x -0.64 y y z -1 z -1 w 2 w 1 2 for each input sample x do: y = 2x −0.64w 2 w 2 = w 1 w 1 = y Problem 6.6 Taking z-transforms, we find: H(z)= 1 +0.5z −8 +0.5 2 z −16 +0.5 3 z −24 +· · · = 1 1 −0.5z −8 where convergence requires ¦z¦ 8 > 0.5, or, ¦z¦ > (0.5) 1/8 . The block diagram and sample pro- cessing algorithm are: x 0.5 y z -8 w 8 w 0 for each input sample x do: y = w 0 = x +0.5w 8 delay(8, w) where the call to delay updates the 9-dimensional state vector of the eightfold delay w = [w 0 , w 1 , . . . , w 8 ]. Problem 6.7 Because z = e jω , we can deduce the transfer function from H(ω): H(z)= −0.5 +z −8 1 −0.5z −8 It can be written in a form that can be expanded in powers of z −8 : H(z)= −0.5 + 0.75z −8 1 −0.5z −8 = −0.5 +0.75z −8 _ 1 +0.5z −8 +0.5 2 z −16 +0.5 3 z −24 +· · · _ 89 Thus, the impulse response will be h = [−0.5, 0, 0, 0, 0, 0, 0, 0, 0.75, 0, 0, 0, 0, 0, 0, 0, 0.75(0.5), 0, 0, 0, 0, 0, 0, 0, 0.75(0.5) 2 , . . . ] It is depicted below: -0.5 0 0.75 0.75/2 0.75/4 n h(n) ... Problem 6.8 a. The impulse response h(n) satisfies the difference equation: h(n)= h(n −1)+h(n −2)+δ(n −1) (P6.1) Indeed, for n ≥ 2 the δ(n − 1) term is absent and each h(n) is the sum of the previous two. The sequence is properly initialized at n = 0, 1: h(0) = h(−1)+h(−2)+δ(−1)= 0 +0 +0 = 0 h(1) = h(0)+h(−1)+δ(0)= 0 +0 +1 = 1 Next, we take z-transforms of both sides of Eq. (P6.1) to get H(z): H(z)= z −1 H(z)+z −2 H(z)+z −1 because the z-transform of δ(n −1) is z −1 . Solving for H(z): H(z)= z −1 1 −z −1 −z −2 b. The poles of H(z) are the roots of 1 −z −1 −z −2 = 0 or z 2 −z −1 = 0 ⇒ z = 1 : √ 5 2 Denoting the first one by φ, the other one will be: φ = 1 + √ 5 2 , − 1 φ = 1 − √ 5 2 Indeed, we have − 1 φ = − 2 1 + √ 5 = − 2(1 − √ 5) (1 + √ 5)(1 − √ 5) = − 2(1 − √ 5) 1 −5 = 1 − √ 5 2 Performing a partial fraction expansion on H(z), we get: H(z)= z −1 1 −z −1 −z −2 = z −1 (1 −φz −1 )(1 +φ −1 z −1 ) = A 1 −φz −1 + B 1 +φ −1 z −1 90 where A = _ z −1 1 +φ −1 z −1 _ z=φ = φ −1 1 +φ −2 = 1 √ 5 B = _ z −1 1 −φz −1 _ z=−φ −1 = − φ 1 +φ 2 = − 1 √ 5 Taking the causal inverse z-transform, we obtain a closed-form solution for the nth Fi- bonacci number: h(n)= Aφ n +B(−φ) −n , n ≥ 0 It is unstable because φ is greater than 1 (note, φ = 1.618). c. For large n, the exponentially increasing term φ n dominates the expression. Therefore, the ratio of two successive Fibonacci numbers will tend to: h(n +1) h(n) → Aφ n+1 Aφ n = φ This can also be seen from the difference equation of h(n). For n ≥ 1, we have h(n +1)= h(n)+h(n −1) Dividing by h(n −1), we have: h(n +1) h(n −1) = h(n) h(n −1) +1 or, h(n +1) h(n) · h(n) h(n −1) = h(n) h(n −1) +1 If we denote the ratio r(n)= h(n +1)/h(n), we may write this as: r(n)r(n −1)= r(n −1)+1 The limiting value r(n)→r will satisfy the limiting equation: r 2 = r +1 which is the same as that satisfied by φ. Thus, r = φ because they are the positive solutions. d. The sequence y(n) satisfies the recursion y(n)= y(n − 1)+y(n − 2) for n ≥ 3. Indeed, using the property φ 2 = φ+1 and successively multiplying it by powers of φ, we get y(3) = φ 2 = φ+1 = y(2)+y(1) y(4) = φ 3 = φ 2 +φ = y(3)+y(2) y(5) = φ 4 = φ 3 +φ 2 = y(4)+y(3) · · · 91 The z-transform of y(n) will be the once-delayed z-transform of the geometric series, that is, Y(z)= z −1 1 −φz −1 Thinking of Y(z) as the output of H(z) for a particular input X(z), we have Y(z)= H(z)X(z), which may be solved for X(z): X(z)= Y(z) H(z) = z −1 1 −φz −1 z −1 (1 −φz −1 )(1 +φ −1 z −1 ) = 1 +φ −1 z −1 which gives the sequence: x(n)= δ(n)+φ −1 δ(n −1) or x = [1, φ −1 , 0, 0, 0, 0. . . ] Problem 6.9 As in the previous problem, the impulse response satisfies the difference equation: h(n)= 2h(n −1)+h(n −2)+δ(n −1) with zero initial conditions. That is, the two start-up values are: h(0) = 2h(−1)+h(−2)+δ(−1)= 0 +0 +0 = 0 h(1) = 2h(0)+h(−1)+δ(0)= 0 +0 +1 = 1 Taking z-transforms, we find H(z): H(z)= 2z −1 H(z)+z −2 H(z)+z −1 ⇒ H(z)= z −1 1 −2z −1 −z −2 The roots of the denominator polynomial are the solutions of z 2 = 2z +1 ⇒ z = 1 : √ 2 = ¦θ, −θ −1 ¦ The PF expansion is then H(z)= z −1 1 −2z −1 −z −2 = z −1 (1 −θz −1 )(1 +θ −1 z −1 ) = A 1 −θz −1 + B 1 +θ −1 z −1 where A = −B = θ θ 2 +1 = 1 2 √ 2 Thus, the nth Pell number will be: h(n)= Aθ n +B(−θ) −n , n ≥ 0 Because the exponentially diverging term θ n dominates the sum, the ratio of two successive numbers will converge to 92 h(n +1) h(n) → Aθ n+1 Aθ n = θ The y(n) sequence has z-transform Y(z)= z −1 1 −θz −1 = z −1 (1 −θz −1 )(1 +θ −1 z −1 ) · (1 +θ −1 z −1 )= H(z)(1 +θ −1 z −1 ) and therefore, it may be thought of as the output when the input is: X(z)= 1 +θ −1 z −1 or, x(n)= δ(n)+θ −1 δ(n −1) ⇒ x = [1, θ −1 , 0, 0, 0, 0. . . ] Problem 6.10 The input and output z-transforms are: X 1 (z)= 1 1 −0.5z −1 , Y 1 (z)= 1 1 −0.5z −1 + 1 1 −0.4z −1 = 2(1 −0.45z −1 ) (1 −0.5z −1 )(1 −0.4z −1 ) It follows that transfer function is: H(z)= Y 1 (z) X 1 (z) = 2(1 −0.45z −1 ) 1 −0.4z −1 Therefore, the second output, having z-transform Y 2 (z)= 1 1 −0.4z −1 will be produced by X 2 (z)= Y 2 (z) H(z) = 0.5 1 −0.45z −1 ⇒ x 2 (n)= 0.5(0.45) n u(n) Problem 6.11 The input and output z-transforms are: X 1 (z) = 1 1 −az −1 Y 1 (z) = 1 1 −az −1 + 1 1 −bz −1 = 2 −(a +b)z −1 ) (1 −az −1 )(1 −bz −1 ) = 2(1 −cz −1 ) (1 −az −1 )(1 −bz −1 ) where c = (a +b)/2. Therefore, the transfer function is H(z)= Y 1 (z) X 1 (z) = 2(1 −cz −1 ) 1 −bz −1 If the input x 2 (n)= c n u(n) is applied it will have z-transform X 2 (z)= 1/(1 − cz −1 ) and will cause the output: Y 2 (z)= H(z)X 2 (z)= 2(1 −cz −1 ) 1 −bz −1 · 1 1 −cz −1 = 2 1 −bz −1 and in the time domain: y 2 (n)= 2b n u(n) 93 Problem 6.12 The input and output z-transforms are: X(z) = 1 1 −0.7z −1 Y(z) = 1 1 −0.7z −1 + 1 1 −0.5z −1 = 2(1 −0.6z −1 ) (1 −0.7z −1 )(1 −0.5z −1 ) Therefore the transfer function will be: H(z)= Y(z) X(z) = 2(1 −0.6z −1 ) 1 −0.5z −1 Expanding in partial fractions, we have: H(z)= 2(1 −0.6z −1 ) 1 −0.5z −1 = 2.4 − 0.4 1 −0.5z −1 which has the causal inverse: h(n)= 2.4δ(n)−0.4(0.5) n u(n) Problem 6.13 The normalized peak and width frequencies are: ω 0 = 2πf 0 f s = 2π250 5000 = 0.1π [rads/sample] Δω= 2πΔf f s = 2π20 5000 = 0.008π [rads/sample] Therefore, the Q-factor of the filter will be: Q = ω 0 Δω = 0.1π 0.008π = 12.5 We take the filter poles to be at locations: p = Re jω0 , p ∗ = Re −jω0 The pole radius R may be determined from the approximate relationship Δω= 2(1 −R) which gives: R = 1 − 1 2 Δω= 1 − 1 2 0.008π = 0.9874 The denominator polynomial will be: 1 +a 1 z −1 +a 2 z −2 = (1 −pz −1 )(1 −p ∗ z −1 )= 1 −(p +p ∗ )z −1 +p ∗ pz −2 which gives: a 1 = −(p +p ∗ )= −2Rcos ω 0 = −2 · 0.9874 · cos(0.1π)= −1.8781 a 2 = p ∗ p = R 2 = 0.9750 94 Therefore, the designed filter will be: H(z)= 1 1 −1.8781z −1 +0.9750z −2 The time constant of the resonator is given in terms of the maximum pole radius (there is only one radius here): n eff = ln lnR = ln(0.01) ln(0.9874) = 363.18 The approximate expression is obtained by replacing R in terms of Δω: n eff = ln lnR = ln ln(1 −Δω/2) = ln −Δω/2 = − 2ln Δω where we used the small-x approximation ln(1 − x)= −x. The approximate numerical value of the time constant will be: n eff = − 2ln Δω = − 2ln(0.01) 0.008π = 366.47 which compares well with the exact value. Problem 6.14 The -level time constant of a filter is (in sampling instants): n eff = ln lnρ where ρ = max i ¦p i ¦ is the maximum pole radius. In seconds, the time constant is: τ = n eff T = ln lnρ T where T = 1/f s is the interval between samples. It follows that the 1 and 2 level time constants will be τ 1 = ln 1 lnρ T, τ 2 = ln 2 lnρ T And therefore, τ 1 = ln 1 ln 2 τ 2 In particular, for the 60 versus 40 dB time constants, the scale factor is: ln 1 ln 2 = ln(0.001) ln(0.01) = 3 2 = 1.5 Problem 6.15 Using the approximate expression of Problem 6.13 and = 0.001, we have: τ = n eff T = − 2ln Δω T = − 2ln 2πΔfT T = − ln πΔf which gives: τ = − ln πΔf − ln(0.001) πΔf = 2.2 Δf 95 Problem 6.16 The periodic impulse response may be thought of as the sumof the delayed replicas of one period, that is, h(n)= g(n)+g(n −8)+g(n −16)+· · · where g(n)= [1, 2, 3, 4, 0, 0, 0, 0] is the basic period of length 8. Taking z-transforms we obtain: H(z)= G(z)+z −8 G(z)+z −16 G(z)+· · · = (1 +z −8 +z −16 +· · · )G(z) where G(z)= 1 +2z −1 +3z −2 +4z −3 . Using the geometric series on the first factor we obtain: H(z)= G(z) 1 −z −8 = 1 +2z −1 +3z −2 +4z −3 1 −z −8 The direct and canonical realizations are shown in Fig. P6.1. Note that in the canonical realization the total number of delays is 8, but the last 5 are lumped together into a fivefold delay z −5 . The sample processing algorithm for the canonical case is: x y 2 3 4 z -1 z -1 z -1 x y 2 3 4 w 0 w 1 w 2 w 3 w 4 z -1 z -1 z -1 z -1 w 5 w 6 w 7 w 8 z -1 z -1 z -1 z -1 z -1 z -1 z -1 z -1 z -1 z -1 z -1 z -1 Fig. P6.1 Filter realizations of Problem 6.16. for each input x do: w 0 = x +w 8 y = w 0 +2w 1 +3w 2 +4w 3 delay(8, w) where the call to delay(8, w) implements the updating of the delay line, that is, w 8 = w 7 , w 7 = w 6 , . . . , w 1 = w 0 . Problem 6.17 The solution is similar to that of Problem 6.16. Here, the repetition period is 4 and we have: h(n)= g(n)+g(n −4)+g(n −8)+g(n −12)+· · · 96 where g(n)= [0, 1, 2, 3]. In the z-domain, we have: H(z)= G(z)+z −4 G(z)+z −8 G(z)+· · · = (1 +z −4 +z −8 +· · · )G(z)= G(z) 1 −z −4 where G(z)= z −1 +2z −2 +3z −3 . Thus, H(z)= z −1 +2z −2 +3z −3 1 −z −4 The direct and canonical realizations are shown in Fig. P6.2. x y 2 3 z -1 z -1 z -1 x y 2 3 w 0 w 1 w 2 w 3 w 4 z -1 z -1 z -1 z -1 z -1 z -1 z -1 z -1 Fig. P6.2 Direct and canonical realizations of Problem 6.17. The sample processing algorithm for the canonical case is: for each input x do: w 0 = x +w 4 y = w 1 +2w 2 +3w 3 delay(4, w) where the call to delay(4, w) implements the updating of the delay line, that is, w 4 = w 3 , w 3 = w 2 , . . . , w 1 = w 0 . The cascade realization is obtained by factoring the numerator and denominator into (up to) 2nd order polynomials: H(z)= z −1 +2z −2 +3z −3 1 −z −4 = _ z −1 1 −z −2 __ 1 +2z −1 +3z −2 1 +z −2 _ ≡ H 0 (z)H 1 (z) The block diagram is shown in Fig. P6.3. The corresponding sample processing algorithm is: for each input x do: w 0 = x +w 2 x 1 = w 1 w 2 = w 1 w 1 = w 0 v 0 = x 1 −v 2 y = v 0 +2v 1 +3v 3 v 2 = v 1 v 1 = v 0 Using partial fractions, we may write: 97 x w 0 w 1 w 2 z -1 z -1 x 1 y 3 -1 2 v 0 v 1 v 2 z -1 z -1 H 0 (z) H 1 (z) Fig. P6.3 Cascade realization of Problem 6.17. H(z) = z −1 +2z −2 +3z −3 1 −z −4 = z −1 +2z −2 +3z −3 (1 −z −1 )(1 +z −1 )(1 −jz −1 )(1 +jz −1 ) = A 1 −z −1 + B 1 +z −1 + C−jD 1 −jz −1 + C+jD 1 +jz −1 where the PFE coefficients C:jD are conjugates. The numerical values are: A = _ z −1 +2z −2 +3z −3 (1 +z −1 )(1 −jz −1 )(1 +jz −1 ) _ z=1 = 1.5 B = _ z −1 +2z −2 +3z −3 (1 −z −1 )(1 −jz −1 )(1 +jz −1 ) _ z=−1 = −0.5 C−jD = _ z −1 +2z −2 +3z −3 (1 −z −1 )(1 +z −1 )(1 +jz −1 ) _ z=j = −0.5 +j0.5 Taking (causal) inverse z-transforms, we find for n ≥ 0: h(n) = A+B(−1) n +(C−jD)j n +(C+jD)(−j) n = A+B(−1) n +2Re _ (C−jD)e jπn/2 _ = A+B(−1) n +2Ccos(πn/2)+2Dsin(πn/2) = 1.5 −0.5(−1) n −cos(πn/2)−sin(πn/2) Evaluating at the first couple of periods, we find: h(n)= [0, 1, 2, 3, 0, 1, 2, 3, . . . ] Problem 6.18 Expand the denominator in powers of z −7 and pick out the coefficients of the powers of z −1 . We have: H(z)= 1 +z −1 +z −2 +z −3 1 −z −7 = (1 +z −1 +z −2 +z −3 )(1 +z −7 +z −14 +· · · ) The powers of z −7 cause the period-7 replication of the basic period G(z)= 1 +z −1 +z −2 +z −3 : h(n)= [1, 1, 1, 1, 0, 0, 0 . ¸, . , 1, 1, 1, 1, 0, 0, 0 . ¸, . , 1, 1, 1, 1, 0, 0, 0 . ¸, . , . . . ] 98 x y w 0 w 1 w 2 w 3 w 4 z -1 z -1 z -1 z -1 w 5 w 6 w 7 z -1 z -1 z -1 Fig. P6.4 Canonical realizations of Problem 6.18. The canonical realization is shown in Fig. P6.4. The sample processing algorithm is: for each input x do: w 0 = x +w 7 y = w 0 +w 1 +w 2 +w 3 delay(7, w) where the call to delay implements the delay-line updates w 7 = w 6 , w 6 = w 5 , . . . , w 1 = w 0 . The output due to the input x = [3, 2, 1] may be obtained by using the LTI form of convolution, that is, summing up the delayed replicas of the impulse response, scaled by the input samples: x 0 h n = [3, 3, 3, 3, 0, 0, 0, 3, 3, 3, 3, 0, 0, 0, 3, 3, 3, 3, 0, 0, 0, . . . ] x 0 h n−1 = [0, 2, 2, 2, 2, 0, 0, 0, 2, 2, 2, 2, 0, 0, 0, 2, 2, 2, 2, 0, 0, . . . ] x 0 h n−2 = [0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, . . . ] y n = [3, 5, 6, 6, 3, 1, 0, 3, 5, 6, 6, 3, 1, 0, 3, 5, 6, 6, 3, 1, 0, . . . ] Thus, the output also has period 7. The same conclusion can be reached working with z-transforms. We have for the output z-transform: Y(z)= H(z)X(z) = (1 +z −1 +z −2 +z −3 )(3 +2z −1 +z −2 ) 1 −z −7 = 3 +5z −1 +6z −2 +6z −3 +3z −4 +z −5 1 −z −7 The expansion of the denominator in powers of z −7 will cause the period-7 replication of the numerator. Problem 6.19 The expansion of the denominator, will cause the period-2 replication of the numerator. Because the numerator has length 4, its period-2 replicas will overlap with each other and must be added together: 99 H(z)= 1 +z −1 +z −2 +z −3 1 −z −2 = (1 +z −1 +z −2 +z −3 )(1 +z −2 +z −4 +· · · ) or, in the time domain: h =[1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, . . . ] +[0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, . . . ] +[0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, . . . ]+· · · =[1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, . . . ] The canonical realization and sample processing algorithm are: x y w 0 w 1 w 2 w 3 z -1 z -1 z -1 for each input x do: w 0 = x +w 2 y = w 0 +w 1 +w 2 +w 3 w 3 = w 2 w 2 = w 1 w 1 = w 0 Problem 6.20 Writing the sample processing algorithm in terms of the time index n, we have w 0 (n) = x(n)+w 1 (n) y(n) = w 0 (n)+w 2 (n) w 2 (n +1) = w 1 (n) w 1 (n +1) = w 0 (n) or, in the z-domain W 0 (z) = X(z)+W 1 (z) Y(z) = W 0 (z)+W 2 (z) zW 2 (z) = W 1 (z) zW 1 (z) = W 0 (z) Eliminating W 0 (z), W 1 (z), W 2 (z) in favor of Y(z) and X(z), we obtain: W 1 (z)= z −1 W 0 (z), W 2 (z)= z −1 W 1 (z)= z −2 W 0 (z) W 0 (z)= X(z)+z −1 W 0 (z) ⇒ W 0 (z)= X(z) 1 −z −1 Y(z)= W 0 (z)+z −2 W 0 (z)= (1 +z −2 )W 0 (z)= (1 +z −2 ) X(z) 1 −z −1 100 which gives: H(z)= Y(z) X(z) = 1 +z −2 1 −z −1 Multiplying numerator and denominator by 1 +z −1 , we get: H(z)= (1 +z −2 )(1 +z −1 ) (1 −z −1 )(1 +z −1 ) = 1 +z −1 +z −2 +z −3 1 −z −2 which is the same as that of Problem 6.19. Problem 6.21 The number of harmonics fitting within the Nyquist interval are: f s f 1 = 240 60 = 4 Therefore, the harmonics will lie at the fourth roots of unity around the unit circle: ω k = kω 1 = 2πk 4 , k = 0, 1, 2, 3 The numerator polynomial 1 − z −4 will have e jω k as roots. Putting the poles just behind the zeros, we get the desired multinotch filter: H(z)= 1 −z −4 1 −az −4 where 0 < a < 1 must be chosen to be very near 1. Problem 6.22 The zeros are at the 16th roots of unity, that is, z k = e jω k = e 2πjk/16 , k = 0, 1, . . . , 15 The poles are just behind the zeros at the same angles: p k = a 1/16 e jω k = a 1/16 e 2πjk/16 , k = 0, 1, . . . , 15 The zeros and poles are shown in Fig. P6.5. If a is very near 1, the magnitude response will vanish at the harmonics ω k = kω 1 = 2πk/16, and be essentially flat between zeros. Fig. P6.6 shows a sketch of ¦H(ω)¦. The impulse response is obtained by expanding H(z) into powers of z −16 . We have with A = 1/a and B = 1 −A = 1 −1/a: H(z)= 1 −z −16 1 −az −16 = A+ B 1 −az −16 = A+B(1 +az −16 +a 2 z −32 +· · · ) Thus, the causal impulse response will be h(n): h(n)= ⎧ ⎪ ⎪ ⎪ ⎨ ⎪ ⎪ ⎪ ⎩ A+B = 1, if n = 0 Ba n/16 , if n is a non-zero multiple of 16 0, otherwise 101 z-plane = zeros = zeros 1 Fig. P6.5 Pole/zero pattern of Problem 6.22. ω 1 ω 1 = 2π/16 ω 2ω 1 3ω 1 4ω 1 15ω 1 16ω 1 =2π 0 ... |H(ω)| Fig. P6.6 Magnitude response of Problem 6.22. The canonical realization and sample processing algorithm are: y x a -1 w 0 w 16 z -16 for each input x do: w 0 = x +w 16 y = w 0 −aw 16 delay(16, w) where the call to delay updates the 17-dimensional delay line. Problem 6.23 H(z)= −0.3 + 0.6 1 −0.5z −1 . It follows that h(n)= −0.3δ(n)+0.6(0.5) n u(n). Problem 6.24 The gain factor 1 − a normalizes the magnitude response to unity at DC. The direct form I/O difference equation is obtained from: H(z)= Y(z) X(z) = 1 −a 1 −az −1 ⇒ (1 −az −1 )Y(z)= (1 −a)X(z) or, Y(z)= az −1 Y(z)+(1 −a)X(z)= X(z)+a(z −1 Y(z)−X(z)) and in the time domain: 102 y(n)= x(n)+a(y(n −1)−x(n)) A realization based on this expression, as well as the canonical realization, are shown in Fig. 6.24. The corresponding sample processing algorithm will be: for each input x do: y = x +a(w 1 −x) w 1 = y y x a w 1 z -1 y x a 1−a w 1 w 0 z -1 − + Fig. P6.7 Realizations of Problem 6.24. Problem 6.25 The filter poles are at z = 2, −0.5. Thus, H(z)= 3 −3z −1 −z −2 1 −1.5z −1 −z −2 = 3 −3z −1 −z −2 (1 −2z −1 )(1 +0.5z −1 ) Expanding in partial fractions, we have: H(z)= 3 −3z −1 −z −2 (1 −2z −1 )(1 +0.5z −1 ) = A+ B 1 −2z −1 + C 1 +0.5z −1 where A = _ 3 −3z −1 −z −2 1 −1.5z −1 −z −2 _ z=0 = 1 B = _ 3 −3z −1 −z −2 1 +0.5z −1 _ z=2 = 1 C = _ 3 −3z −1 −z −2 1 −2z −1 _ z=−0.5 = 1 The three possible ROCs and corresponding inverses are: ¦z¦ > 2 , h(n)= Aδ(n)+B2 n u(n)+C(−0.5) n u(n) 2 > ¦z¦ > 0.5, h(n)= Aδ(n)−B2 n u(−n −1)+C(−0.5) n u(n) ¦z¦ < 0.5, h(n)= Aδ(n)−B2 n u(−n −1)−C(−0.5) n u(−n −1) Only the second one is stable. Its ROC contains the unit circle. 103 Problem 6.26 The transfer function is obtained fromthe I/Odifference equation by taking z-transforms of both sides and solving for the ratio Y(z)/X(z): Y(z)= 2.5z −1 Y(z)−z −2 Y(z)+3X(z)+3z −2 X(z) ⇒ H(z)= Y(z) X(z) = 3(1 +z −2 ) 1 −2.5z −1 +z −2 Factoring the denominator into its poles and expanding in partial fractions, we get: H(z)= 3(1 +z −2 ) 1 −2.5z −1 +z −2 = 3(1 +z −2 ) (1 −2z −1 )(1 −0.5z −1 ) = A+ B 1 −2z −1 C 1 −0.5z −1 where A = _ 3(1 +z −2 ) 1 −2.5z −1 +z −2 _ z=0 = 3 B = _ 3(1 +z −2 ) 1 −0.5z −1 _ z=2 = 5 C = _ 3(1 +z −2 ) 1 −2z −1 _ z=0.5 = −5 Thus, the ROCs and corresponding inverses are: ¦z¦ > 2 , h(n)= Aδ(n)+B2 n u(n)+C0.5 n u(n) 2 > ¦z¦ > 0.5, h(n)= Aδ(n)−B2 n u(−n −1)+C0.5 n u(n) ¦z¦ < 0.5, h(n)= Aδ(n)−B2 n u(−n −1)−C0.5 n u(−n −1) The z-transform of the signal g(n) is: g(n)= cos(πn/2)u(n) Z −→G(z)= 1 1 +z −2 Therefore, the z-transform of the input x(n) will be: x(n)= g(n)−2g(n −1) Z −→X(z)= G(z)−2z −1 G(z)= (1 −2z −1 )G(z)= 1 −2z −1 1 +z −2 Thus, the output z-transform will be: Y(z)= H(z)X(z)= 3(1 +z −2 ) (1 −2z −1 )(1 −0.5z −1 ) · 1 −2z −1 1 +z −2 = 3 1 −0.5z −1 Inverting causally, we find: y(n)= 3(0.5) n u(n) Problem 6.27 Using the inverse DTFT formula of Eq. (6.3.5), we have: y(n)= 1 2π _ π −π H(ω)X(ω)e jωn dω Similarly, for the input signal, assuming its spectrum is restricted to be only over the range [−ω c , ω c ]: 104 x(n)= 1 2π _ ωc −ωc X(ω)e jωn dω Using d(ω)= D, the definition of H(ω) over one Nyquist interval will be: H(ω)= ⎧ ⎨ ⎩ Ge −jDω , for 0 ≤ ¦ω¦ ≤ ω c 0, for ω c < ¦ω¦ ≤ π where G is its passband gain. Thus, the integration range for y(n) also collapses to [−ω c , ω c ], giving: y(n)= 1 2π _ ωc −ωc Ge −jDω X(ω)e jωn dω= G 1 2π _ ωc −ωc X(ω)e jω(n−D) dω Comparing this with the expression of x(n), we recognize that y(n)= Gx(n −D) Problem 6.28 The PF expansion of H(z) is of the form: H(z)= N(z) M i=1 (1 −p i z −1 ) = M _ i=1 A i 1 −p i z −1 where the i-th coefficient is obtained by deleting the factor (1 − p i z −1 ) from the left-hand side and evaluating the remainder at z = p i , that is, A i = ⎡ ⎢ ⎢ ⎢ ⎣ N(z) j}=i (1 −p j z −1 ) ⎤ ⎥ ⎥ ⎥ ⎦ z=p i = N(p i ) j}=i (1 −p j p −1 i ) Taking causal inverse z-transforms, we find for h(n): h(n)= M _ i=1 A i p n i u(n) Problem 6.29 The z-transforms of the causal and anticausal sinusoidal inputs are the same up to a negative sign: e jω0n u(n) Z −→ 1 1 −e jω0 z −1 e jω0n u(−n −1) Z −→− 1 1 −e jω0 z −1 with ROCs ¦z¦ > 1 and ¦z¦ < 1, respectively. The output z-transform will be Y(z)= H(z)X(z). Thus, in the two cases: 105 Y(z)= : N(z) (1 −e jω0 z −1 ) M i=1 (1 −p i z −1 ) The partial fraction expansion leads to Y(z)= : C 1 −e jω0 z −1 : M _ i=1 B i 1 −p i z −1 where C = H(ω 0 ), as we sawin Eq. (6.3.10), and B i are obtained by deleting the factor (1−p i z −1 ) and evaluating the rest at z = p i : B i = ⎡ ⎢ ⎢ ⎢ ⎣ N(z) (1 −e jω0 z −1 ) j}=i (1 −p j z −1 ) ⎤ ⎥ ⎥ ⎥ ⎦ z=p i = N(p i ) (1 −e jω0 p −1 i ) M j}=i (1 −p j p −1 i ) Comparing with the result of the previous problem, we have: B i = A i 1 −e jω0 p −1 i To get the inverse z-transform y(n), we must assume a particular ROC. For the causal case, we take the ROC to be ¦z¦ > 1, so that all the PFE terms will be inverted causally. For the anticausal case, we take the filter part to be causal and the input anticausal, that is, the ROC will be the annular region between the maximum pole and the unit circle: max i ¦p i ¦ < ¦z¦ < 1 In this case the C term will be inverted anticausally and the B i terms causally. These choices for the ROCs, give: y(n) = H(ω 0 )e jω0n u(n)+ M _ i=1 B i p n i u(n) y(n) = H(ω 0 )e jω0n u(−n −1)− M _ i=1 B i p n i u(n) Adding up the right-sided and left-sided sinusoidal inputs gives rise to the double-sided input: e jω0n u(n)+e jω0n u(−n −1)= e jω0n _ u(n)+u(−n −1) _ = e jω0n , −∞< n < ∞ where, we used the property u(n)+u(−n − 1)= 1 for all n. It follows from the linearity of the filter that the corresponding output will be the sum of the two outputs obtained above. This gives: y(n) = H(ω 0 )e jω0n u(n)+ M _ i=1 B i p n i u(n)+H(ω 0 )e jω0n u(−n −1)− M _ i=1 B i p n i u(n) = H(ω 0 )e jω0n u(n)+H(ω 0 )e jω0n u(−n −1) = H(ω 0 )e jω0n which is recognized as the standard steady-state sinusoidal response of the filter. 106 Problem 6.30 The PF expansion of H(z) gives: H(z)= 3 −5z −1 +z −2 (1 −0.5z −1 )(1 −2z −1 ) = 1 + 1 1 −0.5z −1 + 1 1 −2z −1 The stable ROC containing the unit circle will be 0.5 < ¦z¦ < 2. Therefore, the 0.5-pole term will be inverted causally and the 2-pole anticausally: h(n)= δ(n)+0.5 n u(n)−2 n u(−n −1) The truncated impulse response agrees with h(n) for n ≥ −D and is zero otherwise, that is: ` h(n)= ⎧ ⎪ ⎪ ⎪ ⎨ ⎪ ⎪ ⎪ ⎩ δ(n)+0.5 n , n ≥ 0 −2 n , −D ≤ n ≤ −1 0, n ≤ −D−1 The corresponding z-transform is by definition: ` H(z)= ∞ _ n=0 [δ(n)+0.5 n ]z −n − −1 _ n=−D 2 n z −n The last term can be summed by changing summation variables from n to m= −n: −1 _ n=−D 2 n z −n = D _ m=1 2 −m z m = 2 −1 z(1 −2 −D z D ) 1 −2 −1 z = − 1 −2 −D z D 1 −2z −1 where we used the finite geometric series: D _ m=1 x m = x +x 2 +· · · x D = x(1 +x +x 2 +· · · x D−1 )= x(1 −x D ) 1 −x Thus, ` H(z)= 1 + 1 1 −0.5z −1 + 1 −2 −D z D 1 −2z −1 Comparing with the exact H(z) we have: ` H(z)= H(z)− 2 −D z D 1 −2z −1 or, the error transfer function: H(z)− ` H(z)= 2 −D z D 1 −2z −1 The given input has z-transform: x(n)= δ(n)−2δ(n −1) Z −→X(z)= 1 −2z −1 The error output will be E(z)= Y(z)− ` Y(z)= H(z)X(z)− ` H(z)X(z)= _ H(z)− ` H(z) _ X(z) or, E(z)= 2 −D z D 1 −2z −1 · (1 −2z −1 )= 2 −D z D and in the time domain: e(n)= 2 −D δ(n +D) By choosing D large enough, the factor 2 −D can be made as small as desired. 107 Chapter 7 Problems Problem 7.1 Expanding the denominator in powers of z −5 will replicate the numerator periodically with period 5. But because the numerator itself has length 5, the replicas will not overlap, and we will get the repetition of the numerator coefficients: h = [0, 1, 2, 3, 4 . ¸, . , 0, 1, 2, 3, 4 . ¸, . , 0, 1, 2, 3, 4 . ¸, . , . . . ] The direct and canonical realizations are shown in Fig. P7.1. x y x y z -1 z -1 z -1 z -1 z -1 z -1 2 3 4 z -1 z -1 z -1 w 5 w 0 w 1 w 2 w 3 w 4 w 5 w 0 w 1 w 2 w 3 w 4 v 0 v 1 v 2 v 3 v 4 z -1 2 3 4 z -1 z -1 z -1 z -1 Fig. P7.1 Direct and canonical realizations of Problem 7.1. The sample processing algorithms are expressed with the help of the routine delay, which updates the filter’s internal state vectors. for each input x do: v 0 = x w 0 = w 5 +v 1 +2v 2 +3v 3 +4v 4 y = w 0 delay(4, v) delay(5, w) for each input x do: w 0 = x +w 5 y = w 1 +2w 2 +3w 3 +4w 4 delay(5, w) where v = [v 0 , v 1 , v 2 , v 4 ], w = [w 0 , w 1 , w 2 , w 3 , w 4 .w 5 ] are the 5- and 6-dimensional state vec- tors needed for the numerator and denominator polynomials. The calls to the delay routines update the delay line, e.g., the call delay(5, w) is equivalent to the shifts: w 5 = w 4 , w 4 = w 3 , w 3 = w 2 , w 2 = w 1 , w 1 = w 0 . Factoring the denominator as 1−z −5 = (1−z −1 )(1+z −1 +z −2 +z −3 +z −4 ), we get the cascaded transfer functions: H(z)= z −1 +2z −2 +3z −3 +4z −4 1 −z −5 = z −1 1 −z −1 · 1 +2z −1 +3z −2 +4z −3 1 +z −1 +z −2 +z −3 +z −4 Figure P7.2 shows the cascade of these two filters, with each filter realized in its canonical form. The corresponding sample processing algorithm is as follows: 108 x 1 y 2 -1 -1 -1 -1 3 4 z -1 z -1 w 0 w 1 w 2 z -1 w 3 z -1 w 4 x z -1 v 0 v 1 Fig. P7.2 Cascade realization of Problem 7.1. for each input x do: v 0 = x +v 1 x 1 = v 1 delay(1, v) w 0 = x 1 −w 1 −w 2 −w 3 −w 4 y = w 0 +2w 1 +3w 2 +4w 3 delay(4, w) where v = [v 0 , v 1 ], w = [w 0 , w 1 , w 2 , w 3 , w 4 ] are the internal state vectors for the two filter sections. Problem 7.2 In the z-domain, the input to H 1 (z) is X(z)−Y(z). Therefore, its output will be H 1 (z) _ Y(z) −X(z) _ . The input and output of H 2 (z) will be then : H 1 (z) _ Y(z)−X(z) _ −Y(z)−→H 2 (z) _ H 1 (z) _ Y(z)−X(z) _ −Y(z) _ Adding the noise component E(z) to the output of H 2 (z) will generate Y(z), resulting in: Y(z)= H 2 (z) _ H 1 (z) _ Y(z)−X(z) _ −Y(z) _ +E(z) Moving the Y-dependent terms to the left, we get: _ 1 +H 2 (z)+H 1 (z)H 2 (z) _ Y(z)= H 1 (z)H 2 (z)X(z)+E(z) and solving for Y(z): Y(z)= H 1 (z)H 2 (z) 1 +H 2 (z)+H 1 (z)H 2 (z) X(z)+ 1 1 +H 2 (z)+H 1 (z)H 2 (z) E(z) Thus, the desired transfer functions are identified to be: H x (z) = H 1 (z)H 2 (z) 1 +H 2 (z)+H 1 (z)H 2 (z) H e (z) = 1 1 +H 2 (z)+H 1 (z)H 2 (z) 109 The conditions that H x (z) be a plain delay and H e (z) a double differentiator, gives the two equations: H 1 (z)H 2 (z) 1 +H 2 (z)+H 1 (z)H 2 (z) = z −1 1 1 +H 2 (z)+H 1 (z)H 2 (z) = (1 −z −1 ) 2 which can be solved for H 1 (z) and H 2 (z) giving: H 1 (z) = 1 1 −z −1 H 2 (z) = z −1 1 −z −1 They are both integrators. The presence of z −1 in the numerator of H 2 (z) is necessary to make the overall closed loop computable. See also Problems 12.24 and 12.25. Problem 7.3 Multiplying the numerator factors, we get the transfer function: H(z)= z −1 (1 +2z −2 )(1 +3z −2 ) 1 −z −6 = z −1 +5z −3 +6z −5 1 −z −6 The direct and canonical realizations are shown in Fig. P7.3. x y x y z -1 z -1 z -1 z -1 z -1 w 5 w 6 w 0 w 1 w 2 w 3 w 4 z -1 z -1 z -1 z -1 z -1 z -1 w 5 w 6 w 0 w 1 w 2 w 3 w 4 z -1 z -1 z -1 z -1 z -1 v 5 v 0 v 1 v 2 v 3 v 4 z -1 5 6 5 6 Fig. P7.3 Direct and canonical realizations of Problem 7.3. The sample processing algorithms are expressed with the help of the routine delay, which updates the filter’s internal state vectors. for each input x do: v 0 = x w 0 = v 1 +5v 3 +6v 5 +w 6 y = w 0 delay(5, v) delay(6, w) for each input x do: w 0 = x +w 6 y = w 1 +5w 3 +6w 5 delay(6, w) 110 where v = [v 0 , v 1 , v 2 , v 4 , v 5 ], w = [w 0 , w 1 , w 2 , w 3 .w 4 , w 5 , w 6 ] are the 6- and 7-dimensional state vectors needed for the numerator and denominator polynomials. The calls to the delay routines update the delay line, e.g., the call delay(6, w) is equivalent to the shifts: w 6 = w 5 , w 5 = w 4 , w 4 = w 3 , w 3 = w 2 , w 2 = w 1 , w 1 = w 0 . Factoring the denominator as 1 −z −6 = (1 −z −2 )(1 +z −2 +z −4 )= (1 −z −2 )(1 +z −1 +z −2 )(1 −z −1 +z −2 ) we get the cascade transfer function: H(z)= z −1 1 −z −2 · 1 +2z −2 1 +z −1 +z −2 · 1 +3z −2 1 −z −1 +z −2 Figure P7.4 shows the cascade of these three filters, with each filter realized in its canonical form. z -1 z -1 u 0 u 1 u 2 x x 1 x 2 y z -1 z -1 v 0 v 1 v 2 2 -1 -1 z -1 z -1 w 0 w 1 w 2 3 -1 Fig. P7.4 Cascade realization of Problem 7.3. The corresponding sample processing algorithm is as follows: for each input x do: u 0 = x +u 2 x 1 = u 1 delay(2, u) v 0 = x 1 −v 1 −v 2 x 2 = v 0 +2v 2 delay(2, v) w 0 = x 2 +w 1 −w 2 y = w 0 +3w 2 delay(2, w) where u = [u 0 , u 1 , u 2 ], v = [v 0 , v 1 , v 2 ], w = [w 0 , w 1 , w 2 ], are the internal state vectors for the three filter sections. To determine the impulse response, we note that the numerator corresponds to the length-6 signal b = [0, 1, 0, 5, 0, 6]. Expanding the denominator in powers of z −6 will replicate the numerator periodically with period 6. But because the numerator itself has length 6, the replicas will not overlap, and we will get the repetition of the numerator coefficients: h = [0, 1, 0, 3, 0, 5 . ¸, . , 0, 1, 0, 3, 0, 5 . ¸, . , 0, 1, 0, 3, 0, 5 . ¸, . , . . . ] Problem 7.4 The z-domain versions of the time domain difference equations are: v(n) = x(n)+v(n −1) y(n) = v(n)+v(n −2)+v(n −4) ⇒ V(z) = X(z)+z −1 V(z) Y(z) = V(z)+z −2 V(z)+z −4 V(z) 111 Eliminating V(z) in favor of Y(z), X(z), gives: V(z)= X(z) 1 −z −1 , Y(z)= (1 +z −2 +z −4 )V(z)= 1 +z −2 +z −4 1 −z −1 X(z) Therefore, the transfer function is: H(z)= 1 +z −2 +z −4 1 −z −1 = 1 +z −1 +z −2 1 −z −1 · (1 −z −1 +z −2 ) where we factored the numerator as 1 +z −2 +z −4 = (1 +z −1 +z −2 )(1 −z −1 +z −2 ) The direct, canonical, and cascade realizations are shown in Fig. P7.5. x y z -1 z -1 z -1 w 0 w 1 w 2 w 3 w 4 z -1 x y z -1 w 0 w 1 z -1 z -1 z -1 v 0 v 1 v 2 v 3 v 4 z -1 x x 1 z -1 z -1 v 0 v 1 v 2 y z -1 z -1 w 0 w 1 w 2 -1 Fig. P7.5 Direct, canonical, and cascade realizations of Problem 7.4. The direct and canonical sample processing algorithms are: for each input x do: v 0 = x w 0 = v 0 +v 2 +v 4 +w 1 y = w 0 delay(4, v) delay(1, w) for each input x do: w 0 = x +w 1 y = w 0 +w 2 +w 4 delay(4, w) And for the cascade realization: 112 for each input x do: v 0 = x +v 1 x 1 = v 0 +v 1 +v 2 delay(2, v) w 0 = x 1 y = w 0 −w 1 +w 2 delay(2, w) Problem 7.5 Factoring the denominator, we may write the transfer function as: H(z)= 2 −3z −1 1 −0.5z −2 · 1 +z −2 1 +0.5z −2 = 2 −3z −1 +2z −2 −3z −3 1 −0.25z −4 The direct and canonical realizations are shown in Fig. P7.6. Their sample processing algorithms are: for each input x do: v 0 = x w 0 = 2v 0 −3v 1 +2v 2 −3v 3 +0.25w 4 y = w 0 delay(3, v) delay(4, w) for each input x do: w 0 = x +0.25w 4 y = 2w 0 −3w 1 +2w 2 −3w 3 delay(4, w) x y z -1 z -1 z -1 w 0 w 1 w 2 w 3 w 4 z -1 x y z -1 z -1 z -1 v 0 v 1 v 2 v 3 z -1 z -1 z -1 w 0 w 1 w 2 w 3 w 4 z -1 2 2 -3 -3 2 2 -3 -3 0.25 0.25 Fig. P7.6 Direct and canonical realizations of Problem 7.5. The cascade realization is shown in Fig. P7.7. Its sample processing algorithm is: for each input x do: v 0 = x +0.5v 2 x 1 = 2v 0 −3v 1 delay(2, v) w 0 = x 1 −0.5w 2 y = w 0 +w 2 delay(2, w) 113 x z -1 z -1 v 0 v 1 x 1 v 2 2 -3 0.5 y z -1 z -1 w 0 w 1 w 2 -0.5 Fig. P7.7 Cascade realization of Problem 7.5. Problem 7.6 The direct and canonical realizations are shown in Fig. P7.8. Their sample processing algorithms are: for each input x do: v 0 = x w 0 = v 0 −2.25v 2 +0.0625w 4 y = w 0 delay(2, v) delay(4, w) for each input x do: w 0 = x +0.0625w 4 y = w 0 −2.25w 2 delay(4, w) x y z -1 z -1 z -1 w 0 w 1 w 2 w 3 w 4 z -1 x y z -1 z -1 v 0 v 1 v 2 z -1 z -1 z -1 w 0 w 1 w 2 w 3 w 4 z -1 -2.25 -2.25 0.0625 0.0625 Fig. P7.8 Direct and canonical realizations of Problem 7.6. The cascade realization is shown in Fig. P7.9. Its sample processing algorithm is: for each input x do: v 0 = x −0.25v 2 x 1 = v 0 −2.25v 2 delay(2, v) y = w 0 = x 1 +0.25w 2 delay(2, w) Expanding H(z) in partial fractions, we have: H(z)= 2.5 1 −0.5jz −1 + 2.5 1 +0.5jz −1 + 2 1 −0.5z −1 + 2 1 +0.5z −1 114 x z -1 z -1 v 0 v 1 x 1 v 2 -2.25 -0.25 y z -1 z -1 w 0 w 1 w 2 0.25 Fig. P7.9 Cascade realization of Problem 7.6. The four poles z = :0.5, :0.5j, define only two ROCs, namely, the causal case ¦z¦ > 0.5 and the anticausal one ¦z¦ < 0.5. For example, in the causal case, the impulse response will be: h(n)= 2.5(0.5j) n u(n)+2.5(−0.5j) n u(n)+2(0.5) n u(n)+2(−0.5) n u(n) Writing j n +(−j) n = e jπn/2 +e −jπn/2 = 2cos(πn/2), we have: h(n)= 5(0.5) n cos(2πn/2)+2(0.5) n u(n)+2(−0.5) n u(n) Problem 7.7 The direct and canonical realizations are shown in Fig. P7.10. Their sample processing algorithms are: for each input x do: v 0 = x y = w 0 = v 0 −2v 2 +v 4 +0.4096w 4 delay(4, v) delay(4, w) for each input x do: w 0 = x +0.4096w 4 y = w 0 −2w 2 +w 4 delay(4, w) x y z -1 z -1 z -1 w 0 w 1 w 2 w 3 w 4 z -1 x y z -1 z -1 v 0 v 1 v 2 v 3 v 4 z -1 z -1 w 0 w 1 w 2 w 4 z -1 w 3 z -1 z -1 z -1 -2 -2 0.4096 0.4096 Fig. P7.10 Direct and canonical realizations of Problem 7.7. The cascade realization is shown in Fig. P7.11. It corresponds the factorization: H(z)= 1 −2z −2 +z −4 1 −0.4096z −4 = 1 −z −2 1 −0.64z −2 · 1 −z −2 1 +0.64z −2 115 Note that the numerator could also have been factored as: 1 −2z −2 +z −4 = (1 −z −2 ) 2 = (1 −z −1 ) 2 (1 +z −1 ) 2 = (1 −2z −1 +z −2 )(1 +2z −1 +z −2 ) But the chosen one has the simplest coefficients. Its sample processing algorithm is: for each input x do: v 0 = x +0.64v 2 x 1 = v 0 −v 2 delay(2, v) w 0 = x 1 −0.64w 2 y = w 0 −w 2 delay(2, w) x z -1 z -1 v 0 v 1 x 1 v 2 -1 0.64 z -1 z -1 w 0 w 1 w 2 -1 -0.64 y Fig. P7.11 Cascade realization of Problem 7.7. Problem 7.8 The given difference equations describe the canonical realization form of the filter: H(z)= −0.75 +z −10 1 −0.75z −10 Its block diagram realization and sample processing algorithm are given below: x z -10 w 0 w 10 0.75 -0.75 y for each input sample x do: w 0 = x +0.75w 10 y = −0.75w 0 +w 10 delay(10, w) The C version of the algorithm is as follows: double reverb(x, w) double x, w[11]; { int i; double y; w[0] = x + 0.75 * w[10]; y = - 0.75 * w[0] + w[10]; 116 for (i=10; i>=1; i--) w[i] = w[i-1]; return y; } From the transfer function, we obtain the frequency response: H(ω)= −0.75 +e −10jω 1 −0.75e −10jω = 1 −0.75e 10jω 1 −0.75e −10jω e −10jω = (1 −0.75e −10jω ) ∗ (1 −0.75e −10jω ) e −10jω Noting that the ratio of two conjugate complex numbers has unit magnitude, it follows that H(ω) will have unit magnitude. Problem 7.9 The given sample processing algorithm corresponds to the canonical realization of the filter: H(z)= 1 +z −3 1 −0.64z −4 Factoring the numerator in the form: 1 +z −4 = (1 +z −1 )(1 −z −1 +z −2 ) we obtain the cascade factors: H(z)= 1 +z −3 1 −0.64z −4 = 1 +z −1 1 −0.8z −2 · 1 −z −1 +z −2 1 +0.8z −2 The cascade realization is shown in Fig. P7.12. Its sample processing algorithm is: for each input x do: v 0 = x +0.8v 2 x 1 = v 0 +v 1 delay(2, v) w 0 = x 1 −0.8w 2 y = w 0 −w 1 +w 2 delay(2, w) x z -1 z -1 v 0 v 1 x 1 v 2 0.8 z -1 z -1 w 0 w 1 w 2 -0.8 -1 y Fig. P7.12 Cascade realization of Problem 7.9. 117 Problem 7.10 The first filter is an FIR filter with transfer function and impulse response: H(z)= (1 +z −2 ) 3 = 1 +3z −2 +3z −4 +z −6 ⇒ h = [1, 0, 3, 0, 3, 0, 1] The causal impulse response of the third filter is obtained by the remove restore method, that is, h(n)= w(n)−w(n −4), where w(n)= (0.9) n u(n)] The first filter has zeros at z = :j, each being a triple zero. The second filter has poles at z = :0.9j, and the third filter has zeros at the fourth roots of unity, i.e., z = :1, :j, and a pole at z = 0.9. The pole/zero plots of the three filters are shown in Fig. P7.13 together with the corresponding sketches of the magnitude responses ¦H(ω)¦ over the right half of the Nyquist interval 0 ≤ ω≤ π. = zeros = poles j -j -0.9j -j 0.9j j 0.9 1 -1 π ω |H(ω)| |H(ω)| |H(ω)| ω ω π π Fig. P7.13 Pole/zero patterns of Problem 7.10. Problem 7.11 Multiplying the transfer function factors, we obtain: H(z)= (1 − √ 2z −1 +z −2 )(1 + √ 2z −1 +z −2 ) (1 +0.81z −2 )(1 −0.81z −2 ) = 1 +z −4 1 −0.6561z −4 Therefore, the zeros will be at the roots of 1 +z −4 = 0, that is, z 4 = −1 ⇒ z = e jπ(2k+1)/4 , k = 0, 1, 2, 3 that is, the 4th roots of unity rotated by 45 o . The poles are at z = :0.9m, :0.9j. Fig. P7.14 shows the pole/zero locations and the corresponding magnitude response. The direct and canonical realizations are shown in Fig. P7.15. Their sample processing algorithms are: 118 = zeros = poles -0.9j 0.9j 0.9 -0.9 |H(ω)| ω π Fig. P7.14 Pole/zero plot of Problem 7.11. for each input x do: v 0 = x y = w 0 = v 0 +v 4 +0.6561w 4 delay(4, v) delay(4, w) for each input x do: w 0 = x +0.6561w 4 y = w 0 +w 4 delay(4, w) x y z -1 z -1 z -1 w 0 w 1 w 2 w 3 w 4 z -1 x y z -1 z -1 v 0 v 1 v 2 v 3 v 4 z -1 z -1 w 0 w 1 w 2 w 4 z -1 w 3 z -1 z -1 z -1 0.6561 0.6561 Fig. P7.15 Direct and canonical realizations of Problem 7.11. The cascade realization is shown in Fig. P7.16. Its sample processing algorithm is: for each input x do: v 0 = x −0.81v 2 x 1 = v 0 − √ 2v 1 +v 2 delay(2, v) w 0 = x 1 +0.81w 2 y = w 0 + √ 2w 1 +w 2 delay(2, w) Problem 7.12 The zeros are at the roots of 1 +16z −4 = 0, that is, 119 x z -1 z -1 v 0 v 1 x 1 v 2 -0.81 z -1 z -1 w 0 w 1 w 2 0.81 y - 2 2 Fig. P7.16 Cascade realization of Problem 7.11. z 4 = −16 ⇒ z = 2e jπ(2k+1)/4 , k = 0, 1, 2, 3 that is, the 4th roots of unity rotated by 45 o and scaled in magnitude by a factor of 2. Similarly, the poles are at: z 4 = − 1 16 ⇒ z = 0.5e jπ(2k+1)/4 , k = 0, 1, 2, 3 Fig. P7.17 shows the pole/zero locations. = zeros = poles |H(ω)| ω π unit circle 1 Fig. P7.17 Pole/zero plot of Problem 7.12. The magnitude response is constant in ω. Indeed, setting c = 1/16, we have: H(ω)= c +e −4jω 1 +ce −4jω = e −4jω (1 +ce 4jω ) 1 +ce −4jω = e −4jω (1 +ce −4jω ) ∗ (1 +ce −4jω ) The ratio of the two conjugate factors will have unity magnitude, giving ¦H(ω)¦ = ¦e −4jω ¦ · ¸ ¸ ¸ ¸ ¸ (1 +ce −4jω ) ∗ (1 +ce −4jω ) ¸ ¸ ¸ ¸ ¸ = 1 · 1 = 1 To get the cascade form, we may factor the numerator and denominator using the identity: 1 +a 4 z −4 = (1 − √ 2az −1 +a 2 z −2 )(1 + √ 2az −1 +a 2 z −2 ) Thus the numerator becomes: 1 16 +z −4 = 1 16 (1 +2 4 z −4 )= 1 16 (1 −2 √ 2z −1 +4z −2 )(1 +2 √ 2z −1 +4z −2 ) 120 Noting that 1/16 = 0.0625, the transfer function is then: H(z)= 0.0625 +z −4 1 +0.0625z −4 = 0.0625 · 1 −2 √ 2z −1 +4z −2 1 −0.5 √ 2z −1 +0.25z −2 · 1 +2 √ 2z −1 +4z −2 1 +0.5 √ 2z −1 +0.25z −2 The direct and canonical realizations are shown in Fig. P7.18. Their sample processing algorithms are: for each input x do: v 0 = x y = w 0 = 0.0625v 0 +v 4 −0.0625w 4 delay(4, v) delay(4, w) for each input x do: w 0 = x −0.0625w 4 y = 0.0625w 0 +w 4 delay(4, w) x y z -1 z -1 z -1 w 0 w 1 w 2 w 3 w 4 z -1 x y z -1 z -1 v 0 v 1 v 2 v 3 v 4 z -1 z -1 w 0 w 1 w 2 w 4 z -1 w 3 z -1 z -1 z -1 -0.0625 -0.0625 0.0625 0.0625 Fig. P7.18 Direct and canonical realizations of Problem 7.12. The cascade realization is shown in Fig. P7.19. Its sample processing algorithm is: for each input x do: v 0 = 0.0625x +0.5 √ 2v 1 −0.25v 2 x 1 = v 0 −2 √ 2v 1 +4v 2 delay(2, v) w 0 = x 1 −0.5 √ 2w 1 −0.25w 2 y = w 0 +2 √ 2w 1 +4w 2 delay(2, w) Finally, the impulse response may be obtained by writing: H(z)= c +z −4 1 +cz −4 = c + (1 −c 2 )z −4 1 +cz −4 = c +(1 −c 2 ) _ z −4 −cz −8 +c 2 z −12 −c 3 z −16 +· · · _ Extracting the coefficients of z −1 , we find: h(n)= ⎧ ⎪ ⎪ ⎪ ⎪ ⎪ ⎨ ⎪ ⎪ ⎪ ⎪ ⎪ ⎩ c if n = 0 −(1 −c 2 )c (n−4)/4 if n is an even multiple of 4 (1 −c 2 )c (n−4)/4 if n is an odd multiple of 4 0 otherwise 121 x 0.0625 w 0 w 1 w 2 y z -1 z -1 v 0 v 1 x 1 v 2 -0.25 4 -2 2 0.5 2 z -1 z -1 -0.25 4 2 2 -0.5 2 Fig. P7.19 Cascade realization of Problem 7.12. Problem 7.13 The following program implements this computer experiment: /* iirfilt.c - IIR filtering experiments */ #include <stdio.h> #include <stdlib.h> void cas2can(); double dir(), can(), cas(); void main() { int i, j, K, M; double x, ydir, ycan, ycas; double *vdir, *wdir, *wcan, **W; double **A, **B, *a, *b; FILE *fpx; fpx = fopen("x.dat", "r"); /* input data */ printf("no. sections K = "); scanf("%d", &K); M=2*K; wdir = (double *) calloc(M+1, sizeof(double)); vdir = (double *) calloc(M+1, sizeof(double)); wcan = (double *) calloc(M+1, sizeof(double)); a = (double *) calloc(M+1, sizeof(double)); b = (double *) calloc(M+1, sizeof(double)); A = (double **) calloc(K, sizeof(double *)); B = (double **) calloc(K, sizeof(double *)); W = (double **) calloc(K, sizeof(double *)); for (i=0; i<K; i++) { A[i] = (double *) calloc(3, sizeof(double)); B[i] = (double *) calloc(3, sizeof(double)); W[i] = (double *) calloc(3, sizeof(double)); } for(i=0; i<K; i++) { 122 printf("enter A[%d] = ", i); for(j=0; j<3; j++) scanf("%lf", A[i]+j); } for(i=0; i<K; i++) { printf("enter B[%d] = ", i); for(j=0; j<3; j++) scanf("%lf", B[i]+j); } cas2can(K, A, a); cas2can(K, B, b); printf("\n\n"); while(fscanf(fpx, "%lf", &x) != EOF) { ydir = dir(M, a, M, b, vdir, wdir, x); ycan = can(M, a, M, b, wcan, x); ycas = cas(K, A, B, W, x); printf("% .6f % .6f % .6f % .6f\n", x, ydir, ycan, ycas); } printf("\n a, b = \n"); /* direct form coefficients */ for (i=0;i<=M;i++) printf("% .6lf % .6lf\n", a[i], b[i]); } The program must be linked with the routines cas2can, dir, can, cas, and also conv required by cas2can and sos required by cas. The number of sections K and the corresponding rows of the matrices A and B are entered interactively. For example, the user input for the given transfer functions will be (starting with K = 4): 4 1 -0.373 0 1 -1.122 0.712 1 -0.891 0.360 1 -0.780 0.190 0.313 0.313 0 0.147 0.294 0.147 0.117 0.234 0.117 0.103 0.206 0.103 These inputs may also be saved in a file, say, input.dat, and piped into the program by iirfilt < input.dat The input signal x n to be filtered is assumed to be in the file x.dat. The program stops filtering as soon as the end-of-file of x.dat is encountered. The first 10 of the input and output samples are shown below: 123 x(n) y dir (n) y can (n) y cas (n) 1.000000 0.000554 0.000554 0.000554 1.000000 0.006191 0.006191 0.006191 1.000000 0.032979 0.032979 0.032979 1.000000 0.112201 0.112201 0.112201 1.000000 0.275606 0.275606 0.275606 1.000000 0.524036 0.524036 0.524036 1.000000 0.807624 0.807624 0.807624 1.000000 1.043772 1.043772 1.043772 1.000000 1.164600 1.164600 1.164600 1.000000 1.157457 1.157457 1.157457 The outputs computed by dir, can, and cas are of course the same. Fig. P7.20 shows the full output, plotted together with the input. The impulse response h(n), 0 ≤ n < 50 can be computed by running this program on a file x.dat containing 1 followed by 49 zeros. It is shown also in Fig. P7.20. The first 10 impulse response samples computed by the three realizations are shown below: x(n) h dir (n) h can (n) h cas (n) 1.000000 0.000554 0.000554 0.000554 0.000000 0.005637 0.005637 0.005637 0.000000 0.026788 0.026788 0.026788 0.000000 0.079222 0.079222 0.079222 0.000000 0.163405 0.163405 0.163405 0.000000 0.248430 0.248430 0.248430 0.000000 0.283588 0.283588 0.283588 0.000000 0.236148 0.236148 0.236148 0.000000 0.120828 0.120828 0.120828 0.000000 −0.007142 −0.007142 −0.007142 The given filter is an example of a lowpass Butterworth filter and the normalization gains in each section have been chosen to give unity gain at DC. Therefore, the steady-state DC response will be H(ω) ¸ ¸ ω=0 = H(z) ¸ ¸ z=1 = 1 This can be observed in the output which rises up to 1 before it dies out to zero. Calling cas2can on the matrices A and B gives the direct form denominator and numerator coefficients: a b 1.000000 0.000554 −3.166000 0.003881 4.873631 0.011644 −4.465987 0.019407 2.592519 0.019407 −0.941724 0.011644 0.196860 0.003881 −0.018165 0.000554 0.000000 0.000000 124 Fig. P7.20 Input, output, and impulse response of Problem 7.13. Problem 7.14 An example of such program is given below. It is patterned after firfilt.c of Problem 4.10. The program reads and allocates the filter coefficient arrays. The last while loop performs the actual filtering: /* canfilt.c - IIR filtering in canonical form */ #include <stdlib.h> #include <stdio.h> #define MAX 64 initial allocation size double can(); void main(int argc, char **argv) { FILE *fpa, *fpb; coefficient files double *a, *b, *w, x, y; coeffs., state, input, output int L, M, K, i; int max = MAX, dmax = MAX; initial allocation and increment if (argc != 3) { fprintf(stderr, "Usage: canfilt a.dat b.dat <x.dat >y.dat\n"); exit(0); } if ((fpa = fopen(argv[1], "r")) == NULL) { fprintf(stderr, "Can’t open filter file: %s\n", argv[1]); exit(0); } if ((fpb = fopen(argv[2], "r")) == NULL) { fprintf(stderr, "Can’t open filter file: %s\n", argv[2]); exit(0); } a = (double *) calloc(max + 1, sizeof(double)); for (M=0;; M++) { if (M == max) { 125 max += dmax; a = (double *) realloc((char *) a, (max + 1) * sizeof(double)); } if (fscanf(fpa, "%lf", a + M) == EOF) break; } M--; a = (double *) realloc((char *) a, (M + 1) * sizeof(double)); b = (double *) calloc(max + 1, sizeof(double)); for (L=0;; L++) { if (L == max) { max += dmax; b = (double *) realloc((char *) b, (max + 1) * sizeof(double)); } if (fscanf(fpb, "%lf", b + L) == EOF) break; } L--; b = (double *) realloc((char *) b, (L + 1) * sizeof(double)); K = (L <= M) ? M : L; w = (double *) calloc((K + 1), sizeof(double)); while(scanf("%lf", &x) != EOF) { process input samples y = can(M, a, L, b, w, x); printf("%lf\n", y); } } Problem 7.15 An example of such programis given below. The programreads and allocates the filter coefficient matrices A and B. To facilitate the initial allocation of A, a temporary array a is used to read the rows of A.dat in a concatenated form, and then it reshapes it into the K×3 matrix A. The last while loop performs the actual filtering: /* casfilt.c - IIR filtering in cascade form */ #include <stdlib.h> #include <stdio.h> #define MAX 64 initial allocation size double cas(); void main(int argc, char **argv) { FILE *fpa, *fpb; coefficient files double **A, **B, **W, x, y; double *a; temporary coefficient array int M, K, i, j, m; int max = MAX, dmax = MAX; allocation and increment if (argc != 3) { fprintf(stderr, "Usage: casfilt A.dat B.dat <x.dat >y.dat\n"); exit(0); } 126 if ((fpa = fopen(argv[1], "r")) == NULL) { fprintf(stderr, "Can’t open filter file: %s\n", argv[1]); exit(0); } if ((fpb = fopen(argv[2], "r")) == NULL) { fprintf(stderr, "Can’t open filter file: %s\n", argv[2]); exit(0); } a = (double *) calloc(max + 1, sizeof(double)); for (M=0;; M++) { if (M == max) { max += dmax; a = (double *) realloc((char *) a, (max + 1) * sizeof(double)); } if (fscanf(fpa, "%lf", a + M) == EOF) break; } a = (double *) realloc((char *) a, (M + 1) * sizeof(double)); if (M%3 != 0) { fprintf(stderr, "all rows of A must be 3-dimensional"); exit(0); } else K = M / 3; A = (double **) calloc(K, sizeof(double *)); B = (double **) calloc(K, sizeof(double *)); W = (double **) calloc(K, sizeof(double *)); for (i=0; i<K; i++) { A[i] = (double *) calloc(3, sizeof(double)); B[i] = (double *) calloc(3, sizeof(double)); W[i] = (double *) calloc(3, sizeof(double)); } for(i=0; i<K; i++) for(j=0; j<3; j++) A[i][j] = a[3*i + j]; for(i=0; i<K; i++) for(j=0; j<3; j++) fscanf(fpb, "%lf", B[i] + j); while(scanf("%lf", &x) != EOF) { process input samples y = cas(K, A, B, W, x); printf("%lf\n", y); } } The MATLAB version casfilt.m is given below. It calls cas.m N times, where N is the input length: % casfilt.m - IIR filtering in cascade form % % y = casfilt(B, A, x); % 127 % B = Kx3 numerator matrix (K = number of sections) % A = Kx3 denominator matrix % x = row vector input % y = row vector output function y = casfilt(B, A, x) [K, K1] = size(A); [N1, N] = size(x); W = zeros(K,3); for n = 1:N, [y(n), W] = cas(K, B, A, W, x(n)); end Problem 7.16 The two filters are: H 1 (z)= 0.70849 · 1 +z −8 1 −0.0625z −8 , H 2 (z)= 0.98021 · 1 +z −8 1 +0.94z −8 · 1 −0.96z −8 1 −0.98z −8 The scale factors, were chosen such that the magnitude responses are unity at ω= ω 0 = 0.5π/8, that is, ¦H 1 (ω 0 )¦ = ¦H 2 (ω 0 )¦ = 1 The following programimplements this computer experiment. The sample processing algorithms of Examples 7.4.3 and 7.4.4 remain the same, except the input sample x gets multiplied by the corresponding normalization gains: /* combex.c - comb filtering examples */ #include <stdio.h> #include <stdlib.h> #include <math.h> #define A0 1.0 #define A1 0.5 #define A2 0.5 #define A3 0.5 #define G1 0.70849 #define G2 0.98021 void delay(); void main() { int n, N; double s, x, y1, x1, y2; double *w, *v, *u; double pi = 4*atan(1.0), w0, w1, w2, w3; FILE *fps, *fpx, *fpy1, *fpy2; fps = fopen("s.dat", "w"); 128 fpx = fopen("x.dat", "w"); fpy1 = fopen("y1.dat", "w"); fpy2 = fopen("y2.dat", "w"); w = (double *) calloc(9, sizeof(double)); /* filter 1 */ u = (double *) calloc(9, sizeof(double)); /* filter 2, section 1 */ v = (double *) calloc(9, sizeof(double)); /* filter 2, section 2 */ w0 = 0.50 * pi / 8; w1 = 0.75 * pi / 8; w2 = 1.00 * pi / 8; w3 = 3.00 * pi / 8; printf("enter input length N = "); scanf("%d", &N); for (n=0; n<N; n++) { s = A0 * cos(w0*n) + A1 * cos(w1*n); x = s + A2 * cos(w2*n) + A3 * cos(w3*n); w[0] = G1 * x + 0.0625 * w[8]; /* filter 1 */ y1 = w[0] + w[8]; delay(8, w); u[0] = G2 * x - 0.94 * u[8]; /* filter 2 */ x1 = u[0] + u[8]; /* section 1 output */ delay(8, u); v[0] = x1 + 0.98 * v[8]; y2 = v[0] - 0.96 * v[8]; /* section 2 output */ delay(8, v); fprintf(fps, "%.8lf\n", s); fprintf(fpx, "%.8lf\n", x); fprintf(fpy1, "%.8lf\n", y1); fprintf(fpy2, "%.8lf\n", y2); } } Fig. P7.21 shows the desired, noise-free, signal s(n) and the noisy signal x(n), which serves as the input to the comb filters. The corresponding output signals y 1 (n) and y 2 (n) from H 1 (z) and H 2 (z) are shown in Fig. P7.22. The first filter has a short time constant, but does not remove the noise component well. The second filter has a longer time constant, but it removes the noise very well. Problem 7.17 Performing a partial fraction expansion on H 1 (z) and H 2 (z), we find (where the PFE coefficients are given with 5-digit accuracy): H 1 (z) = −11.33584 + 12.04433 1 −0.0625z −8 H 2 (z) = 1.02150 − 0.06191 1 +0.94z −8 + 0.02063 1 −0.98z −8 Expanding in powers of z −8 and extracting coefficients, we find the impulse responses, for 0 ≤ n ≤ 16: 129 Fig. P7.21 Desired and noisy inputs of Problem 7.16. Fig. P7.22 Outputs of comb filters 1 and 2 of Problem 7.16. n h 1 (n) h 2 (n) 0 0.70849 0.98021 1 0 0 2 0 0 3 0 0 4 0 0 5 0 0 6 0 0 7 0 0 8 0.75277 0.07841 9 0 0 10 0 0 11 0 0 12 0 0 13 0 0 14 0 0 15 0 0 16 0.04705 −0.03489 130 The impulse responses of the two filters can be computed by the same program as above, but with changing the input x(n) into an impulse δ(n). The computed impulse responses are shown in Fig. P7.23 Fig. P7.23 Impulse responses of comb filters 1 and 2 of Problem 7.17. Problem 7.18 The following program replaces iirfilt.c of Problem 7.13. For comparison, dir.c is left in the program as before. /* iirfilt.c - IIR filtering experiments - circular buffer versions */ #include <stdio.h> #include <stdlib.h> void cas2can(); double dir(), ccan(), ccas(); void main() { int i, j, K, M; double x, ydir, ycan, ycas; double *vdir, *wdir, *wcan, **W; double **A, **B, *a, *b; double *p, **P; /* circular pointers */ FILE *fpx; fpx = fopen("x.dat", "r"); printf("no. sections K = "); scanf("%d", &K); M=2*K; wdir = (double *) calloc(M+1, sizeof(double)); vdir = (double *) calloc(M+1, sizeof(double)); wcan = (double *) calloc(M+1, sizeof(double)); p = wcan; /* initialize */ 131 a = (double *) calloc(M+1, sizeof(double)); b = (double *) calloc(M+1, sizeof(double)); A = (double **) calloc(K, sizeof(double *)); B = (double **) calloc(K, sizeof(double *)); W = (double **) calloc(K, sizeof(double *)); P = (double **) calloc(K, sizeof(double *)); /* allocate */ for (i=0; i<K; i++) { A[i] = (double *) calloc(3, sizeof(double)); B[i] = (double *) calloc(3, sizeof(double)); W[i] = (double *) calloc(3, sizeof(double)); P[i] = W[i]; /* initialize */ } for(i=0; i<K; i++) { printf("enter A[%d] = ", i); for(j=0; j<3; j++) scanf("%lf", A[i]+j); } for(i=0; i<K; i++) { printf("enter B[%d] = ", i); for(j=0; j<3; j++) scanf("%lf", B[i]+j); } cas2can(K, A, a); cas2can(K, B, b); printf("\n\n"); while(fscanf(fpx, "%lf", &x) != EOF) { ydir = dir(M, a, M, b, vdir, wdir, x); ycan = ccan(M, a, b, wcan, &p, x); ycas = ccas(K, A, B, W, P, x); printf("% .6f % .6f % .6f % .6f\n", x, ydir, ycan, ycas); } printf("a, b = \n"); for (i=0;i<=M;i++) printf("% .6lf % .6lf\n", a[i], b[i]); } One minor difference in ccan is that it assumes the same order M for both vectors a and b; Therefore its usage is: ycan = ccan(M, a, b, wcan, &p, x); whereas the usage of can was: ycan = can(M, a, M, b, wcan, x); Problem 7.19 The canonical realization is shown in Fig. P7.24. The linear and circular buffer versions of the sample processing algorithm are as follows: 132 x 0.5 -2 6 y z -3 s 3 w 3 s 0 w 0 Fig. P7.24 Canonical realization of Problem 7.19. for each input x do: w 0 = x +0.5w 3 y = 6w 0 −2w 3 delay(3, w) for each input x do: s 3 = tap(3, w, p, 3) s 0 = x +0.5s 3 y = 6s 0 −2s 3 ∗p = s 0 cdelay(3, w, &p) The impulse response can be obtained by dividing out the numerator and writing H(z)= 6 −2z −3 1 −0.5z −3 = 4 + 2 1 −0.5z −3 Expanding in powers of z −3 , we have: H(z)= 4 +2 _ 1 +(0.5)z −3 +(0.5) 2 z −6 +(0.5) 3 z −9 +· · · _ which gives the impulse response: h = _ 6, 0, 0, 2(0.5), 0, 0, 2(0.5) 2 , 0, 0, 2(0.5) 3 , 0, 0, . . . _ = [6, 0, 0, 1, 0, 0, 0.5, . . . ] n x w 0 w 1 w 2 w 3 s 0 s 1 s 2 s 3 y = 6s 0 −2s 3 0 1 1 0 0 0 1 0 0 0 6 1 0 1 0 0 0 0 1 0 0 0 2 0 1 0 0 0 0 0 1 0 0 3 0 1 0.5 0 0 0.5 0 0 1 1 4 0 0 0.5 0 0 0 0.5 0 0 0 5 0 0 0.5 0 0 0 0 0.5 0 0 6 0 0 0.5 0.5 2 0 0.5 2 0 0 0.5 0.5 The states s i represent the delay-line outputs: s(n)= ⎡ ⎢ ⎢ ⎢ ⎣ s 0 (n) s 1 (n) s 2 (n) s 3 (n) ⎤ ⎥ ⎥ ⎥ ⎦ = ⎡ ⎢ ⎢ ⎢ ⎣ w(n) w(n −1) w(n −2) w(n −3) ⎤ ⎥ ⎥ ⎥ ⎦ that is, they are the successively delayed versions of w(n), which is the intermediate signal obtained at the output of the input adder. It has z-transform: W(z)= 1 D(z) X(z)= 1 1 −0.5z −3 X(z) 133 For a delta-function input, we have X(z)= 1, giving: W(z)= 1 1 −0.5z −3 = 1 +(0.5)z −3 +(0.5) 2 z −6 +(0.5) 3 z −9 +· · · and in the time domain: w(n)= [1, 0, 0, 0.5, 0, 0, 0.5 2 , 0, 0, . . . ] For the input x = [1, 2, 3], we have: n x w 0 w 1 w 2 w 3 s 0 s 1 s 2 s 3 y = 6s 0 −2s 3 0 1 1 0 0 0 1 0 0 0 6 1 2 1 0 0 2 2 1 0 0 12 2 3 1 0 3 2 3 2 1 0 18 3 0 1 0.5 3 2 0.5 3 2 1 1 4 0 1 0.5 3 2 1 0.5 3 2 2 5 0 1 0.5 3 1.5 1.5 1 0.5 3 3 6 0 1 0.5 0.25 1.5 0.25 1.5 1 0.5 0.5 Problem 7.20 The full precision direct form denominator is: a = [1, a 1 , a 2 , a 3 , a 4 ]= [1, −3.502, 5.024, −3.464, 0.979] (P7.1) The full precision cascade coefficients are: a 0 = [1, a 01 , a 02 ]= [1, −1.8955, 0.9930] a 1 = [1, a 11 , a 12 ]= [1, −1.6065, 0.9859] (P7.2) The poles are at: p 0 = R 0 e jω0 , R 0 = 0.9965, ω 0 = 0.1π p 1 = R 1 e jω1 , R 1 = 0.9929, ω 1 = 0.2π (P7.3) If we round the direct form coefficient vector a to 2-digit accuracy, we obtain: ˆa = [1, ˆ a 1 , ˆ a 2 , ˆ a 3 , ˆ a 4 ]= [1, −3.50, 5.02, −3.46, 0.98] (P7.4) and the corresponding direct form transfer function: ˆ H dir (z)= 1 1 + ˆ a 1 z −1 + ˆ a 2 z −2 + ˆ a 3 z −3 + ˆ a 4 z −4 (P7.5) This filter is unstable. Indeed, its four poles, the roots of the denominator polynomial, are: ˆ p 0 = ˆ R 0 e j ˆ ω0 , ˆ R 0 = 1.0045, ˆ ω 0 = 0.1045π ˆ p 1 = ˆ R 1 e j ˆ ω1 , ˆ R 1 = 0.9860, ˆ ω 1 = 0.1989π (P7.6) and their conjugates. Thus, the p 0 pole has moved outside the unit circle, rendering the filter unstable. The seemingly benign replacement of a by the rounded ˆa has made the direct form realization unusable. The impulse responses of the two filters (7.7.1) and (P7.5) are shown in Fig. P7.25. The latter is blowing up exponentially. 134 Fig. P7.25 Full and 2-digit precision filters. The cascade realization, on the other hand, is more robust, in the sense that if we round its coeffi- cients also to 2-digit accuracy, the filter will remain stable. Indeed, rounding the SOS coefficients (P7.2) to 2-digits gives: ˆa 0 = [1, ˆ a 01 , ˆ a 02 ]= [1, −1.90, 0.99] ˆa 1 = [1, ˆ a 11 , ˆ a 12 ]= [1, −1.61, 0.99] (P7.7) The roots of these sections are: ˆ p 0 = ˆ R 0 e j ˆ ω0 , ˆ R 0 = 0.9950 ˆ ω 0 = 0.0961π ˆ p 1 = ˆ R 1 e j ˆ ω1 , ˆ R 1 = 0.9950, ˆ ω 1 = 0.2000π (P7.8) and their conjugates. They are both inside the unit circle, therefore, the filter remains stable. The corresponding cascade transfer function will be: ˆ H cas (z)= 1 1 + ˆ a 01 z −1 + ˆ a 02 z −2 · 1 1 + ˆ a 11 z −1 + ˆ a 12 z −2 (P7.9) The filters ˆ H dir (z) and ˆ H cas (z) are not equal. Rounding the cascade coefficients to 2-digit ac- curacy is not equivalent to rounding the direct form coefficients, because rounding does not preserve products—the rounded product of two numbers is not equal to the product of the two rounded numbers. Therefore, rounding does not preserve convolution, that is, ˆa = a 0 ∗a 1 ≠ ˆa 0 ∗ˆa 1 Indeed, carrying out the convolution of the two vectors in Eq. (P7.7) gives the following direct form vector, which is not quite the same as that given by Eq. (P7.4): ˆa 0 ∗ˆa 1 = [1, −3.5100, 5.0390, −3.4749, 0.9801] The impulse response and the magnitude response of the cascaded filter (P7.9) are shown in Fig. P7.26, together with the exact magnitude response. The magnitude responses are plotted in dB, that is, 20log 10 ¦H(ω)¦, over 0 ≤ ω ≤ 0.5π, which is the right half of the Nyquist interval. Thus, in the cascade case the rounding operation changed the magnitude response somewhat, but has not affected the stability of the filter. The sensitivity of the direct form and the robustness of the cascade form can be understood ana- lytically in the following way. The zeros of a polynomial are indirect functions of the coefficients 135 Fig. P7.26 Impulse and magnitude responses of 2-digit-precision cascade form. of the polynomial, therefore, small changes in the latter will induce changes in the former. For the direct form, the induced changes in the zeros can be large, thus, causing them to move outside the unit circle. In the cascade form, the induced changes remain small. For example, consider the above fourth order denominator vector a. The relationship of the zeros to the coefficients is established via the polynomial identity: (1 −p 0 z −1 )(1 −p ∗ 0 z −1 )(1 −p 1 z −1 )(1 −p ∗ 1 z −1 )= 1 +a 1 z −1 +a 2 z −2 +a 3 z −3 +a 4 z −4 A small change in the coefficients will induce a small change in the zeros p 0 and p 1 , that is, a →a +da ⇒ p i →p i +dp i , i = 0, 1 To determine dp 0 and dp 1 in terms of da, we take differentials of both sides of the above poly- nomial identity to get: −dp 0 z −1 (1 −p ∗ 0 z −1 )(1 −p 1 z −1 )(1 −p ∗ 1 z −1 ) −(1 −p 0 z −1 )dp ∗ 0 z −1 (1 −p 1 z −1 )(1 −p ∗ 1 z −1 ) −(1 −p 0 z −1 )(1 −p ∗ 0 z −1 )dp 1 z −1 (1 −p ∗ 1 z −1 ) −(1 −p 0 z −1 )(1 −p ∗ 0 z −1 )(1 −p 1 z −1 )dp ∗ 1 z −1 = da 1 z −1 +da 2 z −2 +da 3 z −3 +da 4 z −4 which is still an identity in z. Setting z = p 0 will remove all but the first termin the left-hand-side, giving the relationship: −dp 0 p −1 0 (1 −p ∗ 0 p −1 0 )(1 −p 1 p −1 0 )(1 −p ∗ 1 p −1 0 )= da 1 p −1 0 +da 2 p −2 0 +da 3 p −3 0 +da 4 p −4 0 Multiplying by p 4 0 and solving for dp 0 , we obtain dp 0 = − p 3 0 da 1 +p 2 0 da 2 +p 0 da 3 +da 4 (p 0 −p ∗ 0 )(p 0 −p 1 )(p 0 −p ∗ 1 ) (P7.10) Similarly, setting z = p 1 , we find for dp 1 : dp 1 = − p 3 1 da 1 +p 2 1 da 2 +p 1 da 3 +da 4 (p 1 −p ∗ 0 )(p 1 −p 0 )(p 1 −p ∗ 1 ) (P7.11) 136 Because, the denominator involves the differences between poles, that is, the distances from all the other poles, it follows that if the poles are closely clustered, the induced changes in the poles dp i will be large even if the coefficient changes da i are small. The above sensitivity formulas generalize easily [2,3,246] to the case of an order-M filter a = [1, a 1 , a 2 , . . . , a M ] with M zeros p 1 , p 2 , . . . , p M : dp i = ∂p i ∂a 1 da 1 + ∂p i ∂a 2 da 2 +· · · + ∂p i ∂a M da M where the partial derivatives are: ∂p i ∂a m = − p M−m i M j=1 j≠i (p i −p j ) (P7.12) In the cascade realization, p 0 is associated with the first SOS and p 1 with the second. The depen- dence of p 0 on a 0 and p 1 on a 1 is established through the identities (1 −p 0 z −1 )(1 −p ∗ 0 z −1 ) = 1 +a 01 z −1 +a 02 z −2 (1 −p 1 z −1 )(1 −p ∗ 1 z −1 ) = 1 +a 11 z −1 +a 12 z −2 Using the above procedure of taking differentials of both sides and setting z = p 0 in the first and z = p 1 in the second, we obtain the induced changes in the poles due to small changes in the coefficients of the sections: dp 0 = − p 0 da 01 +da 02 (p 0 −p ∗ 0 ) , dp 1 = − p 1 da 11 +da 12 (p 1 −p ∗ 1 ) (P7.13) The sensitivity of each pole depends only on the SOS it belongs to, not on the other sections. In Eqs. (P7.10) and (P7.11), the sensitivity of each pole is coupled to the other poles, through the denominator factors of the form (p 0 −p 1 ); if p 0 is near p 1 , such factors cause large shifts in the pole locations. Even though the sensitivity formulas (P7.10) and (P7.11) involve differential changes, we may actually apply themto the above example and estimate the pole shifts for the 2-digit case. Writing the rounded ˆa of Eq. (P7.4) in the form ˆa = a +da, we obtain subtracting (P7.4) and (P7.1): da = ˆa −a = [0, da 1 , da 2 , da 3 , da 4 ]= [0, 0.002, −0.004, 0.004, 0.001] Using the numerical values given in Eq. (P7.3), we have p 0 = 0.9965e j0.1π = 0.9477 +j0.3079 p 1 = 0.9929e j0.2π = 0.8033 +j0.5836 With these values of the poles and da i , we can calculate the pole shifts using (P7.10) and (P7.11). We find: dp 0 = 0.0023 +j0.0159, dp 1 = −0.0033 −j0.0066 Therefore, the new pole locations will be: ˆ p 0 = p 0 +dp 0 = 0.9501 +j0.3238 = 1.0037e j0.1046π ˆ p 1 = p 1 +dp 1 = 0.7999 +j0.5770 = 0.9863e j0.1989π which compare well with the actual values of Eq. (P7.6). A similar calculation can be made based on Eq. (P7.13). 137 Problem 7.21 The numerical values of a are shown in the first column of Table P7.1. The second and third columns of this table show the quantized versions of a, rounded to 5- and 4-digit accuracy. a 5-digit ˆa 4-digit ˆa ˆa cas 1.00000000 1.00000000 1.00000000 1.00000000 −5.56573395 −5.56573000 −5.56570000 −5.56570000 13.05062482 13.05062000 13.05060000 13.05046030 −16.49540451 −16.49540000 −16.49540000 −16.49508213 11.84993647 11.84994000 11.84990000 11.84961490 −4.58649943 −4.58650000 −4.58650000 −4.58633537 0.74713457 0.74713000 0.74710000 0.74710016 relative error 3.2580×10 −7 1.6487×10 −6 1.9240×10 −5 Table P7.1 Exact, 5-digit, and 4-digit coefficients. The fourth column of Table P7.1 shows the equivalent direct-form coefficient vector ˆa cas arising from the cascade of the quantized second order section coefficients, rounded to 4-digit accuracy. The rounded a i are: ˆa 0 = [1, −1.8671, 0.9623] ˆa 1 = [1, −1.8468, 0.8992] ˆa 2 = [1, −1.8518, 0.8634] (P7.14) The table also shows the relative error in each case, defined as the ratio relative error = |da| |a| = |ˆa −a| |a| where |a| denotes the length of the vector a. As expected, the error in the 5-digit case is less than that in the 4-digit case. But, the error of the cascade case is larger. However, as we see below, the 4-digit cascade form gives an adequate approximation of the exact filter, whereas both the 5- and 4-digit direct forms fail. This behavior can be traced to the pole sensitivity formula Eq. (P7.12) which can cause large shifts in the poles even though da is small. Table P7.2 shows the poles of the exact and approximate filters, that is, the roots of the denomi- nator polynomials a, 5- and 4-digit ˆa, and of the rounded SOS polynomials ˆa 0 , ˆa 1 , and ˆa 2 . For the 5-digit direct form, the filter remains stable. But, for the 4-digit direct form, one root of ˆa has moved outside the unit circle and the third conjugate pair of roots has been replaced by two real-valued ones, one almost on the unit circle. Thus, the quantized coefficients ˆa correspond to an unstable filter. By contrast, the roots of the 4-digit quantized cascaded form ˆa cas remain inside the unit circle, and in fact they are practically equal to the unquantized ones. Figure P7.27 shows the impulse responses of the exact filter based on a and the 4-digit-precision filter based on ˆa, which is unstable. The impulse responses of the 5-digit case and the 4-digit cascade case based on ˆa cas are shown in Fig. P7.28. The magnitude responses of the full precision, 5-digit direct, and 4-digit cascade cases are shown in Fig. P7.29. Note that the 5-digit direct no longer meets the passband specs; it has a passband ripple of almost 2 dB instead of the required 1 dB. The 4-digit cascade response, on the other hand, meets the specifications. 138 full precision magnitude 0.933557 :j0.301259 0.980962 0.923398 :j0.215739 0.948265 0.925911 :j0.078311 0.929217 5-digit direct magnitude 0.931610 :j0.300414 0.978849 0.927787 :j0.216576 0.952730 0.923469 :j0.079185 0.926857 4-digit direct magnitude 0.967208 :j0.284105 1.008071 0.888774 :j0.266869 0.927976 0.999999 0.999999 0.853736 0.853736 4-digit cascade magnitude 0.933552 :j0.301303 0.980971 0.923396 :j0.215719 0.948258 0.925902 :j0.078152 0.929194 Table P7.2 Filter poles. Fig. P7.27 Impulse responses of full-precision and 4-digit-precision filters. Problem 7.21. Problem 7.22 See the solution of Problem 7.20. Problem 7.23 See the solution of Problem 7.20. 139 Fig. P7.28 Impulse responses of 5-digit direct and 4-digit cascade filters. Problem 7.21. Fig. P7.29 Magnitude responses of exact, 5-digit direct, and 4-digit cascade. Problem 7.21. Problem 7.24 The transfer function is: H(z)= b 0 +b 1 z −1 +b 2 z −2 +b 3 z −3 1 +a 1 z −1 +a 2 z −2 +a 3 z −3 (P7.15) Transposed realizations of FIR filters are obtained by the four transposition rules of exchanging input with output, reversing all flows, replacing nodes by adders, and adders by nodes. These rules can be applied to the canonical or direct realizations of IIR filters. The I/O difference equations describing the time-domain operation of the realization and the corresponding sample processing algorithm can be obtained by introducing as internal states the contents of the three delay registers at time n: v 1 (n), v 2 (n), v 3 (n). For indexing convenience, we also introduce the quantity v 0 (n) which is the overall output obtained at the top adder, that is, v 0 (n)= y(n)= b 0 x(n)+v 1 (n) The output of each delay is the delayed version of the output of the adder below it, for example, v 1 (n)= b 1 x(n −1)−a 1 v 0 (n −1)+v 2 (n −1)= b 1 x(n −1)−a 1 y(n −1)+v 2 (n −1) 140 or, advancing it to the next time instant: v 1 (n +1)= b 1 x(n)−a 1 v 0 (n)+v 2 (n)= b 1 x(n)−a 1 y(n)+v 2 (n) Therefore, the overall I/O system, which includes the updating of the internal states, will be: y(n)= v 0 (n)= b 0 x(n)+v 1 (n) v 1 (n +1)= b 1 x(n)−a 1 y(n)+v 2 (n) v 2 (n +1)= b 2 x(n)−a 2 y(n)+v 3 (n) v 3 (n +1)= b 3 x(n)−a 3 y(n) (P7.16) which leads to the sample processing algorithm: for each input sample x do: y = v 0 = b 0 x +v 1 v 1 = b 1 x −a 1 y +v 2 v 2 = b 2 x −a 2 y +v 3 v 3 = b 3 x −a 3 y Problem 7.25 In the case of a general transfer function of the type of Eq. (7.1.4), we have the sample processing algorithm, where we assumed L = M for simplicity: for each input sample x do: y = v 0 = b 0 x +v 1 for i = 1, 2, . . . , M−1 do: v i = b i x −a i v 0 +v i+1 v M = b M x −a M v 0 (P7.17) The following C function transp.c is an implementation. /* transp.c - IIR filtering in transposed of canonical form */ double transp(M, a, b, v, x) usage: y = transp(M, a, b, v, x); double *a, *b, *v, x; v = internal state vector int M; a,b have same order M { int i; v[0] = b[0] * x + v[1]; output y(n)= v 0 (n) for (i=1; i<=M-1; i++) state updating v[i] = b[i] * x - a[i] * v[0] + v[i+1]; v[M] = b[M] * x - a[M] * v[0]; return v[0]; } Its usage is the same as that of can or dir. The (M+1)-dimensional array v = [v 0 , v 1 , . . . , v M ] must be declared and allocated in the main program, for example, by 141 double *v; v = (double *) calloc(M+1, sizeof(double)); Transposed realizations are not intuitively obvious, but their overall implementation in terms of Eq. (P7.17) has a certain simplicity and elegance. It corresponds to writing the transfer function of the filter in a nested form, which is similar to H¨orner’s rule of evaluating a polynomial. For example, the transfer function (P7.15) can be written as: H(z)= −(a 1 z −1 +a 2 z −2 +a 3 z −3 )H(z)+b 0 +b 1 z −1 +b 2 z −2 +b 3 z −3 which can be written in the nested form: H = b 0 +z −1 _ (b 1 −a 1 H)+z −1 _ (b 2 −a 2 H)+z −1 (b 3 −a 3 H) _ _ Multiplying both sides by the z-transform X(z) of the input x(n), and using Y(z)= H(z)X(z), we obtain the following nested form for the computation of the output, which is basically the transposed form: Y = b 0 X +z −1 _ (b 1 X −a 1 Y)+z −1 _ (b 2 X −a 2 Y)+z −1 (b 3 X −a 3 Y) _ _ The transposed formcan also be used in the cascade realization, where each second order section will be realized in its transposed form. The sample processing algorithm of a 2nd order section is simply: for each input sample x do: y = v 0 = b 0 x +v 1 v 1 = b 1 x −a 1 y +v 2 v 2 = b 2 x −a 2 y which can replace Eq. (7.2.2). Problem 7.26 The following programimplements filtering in the transposed form, calling the routine transp.c of Problem 7.25. It replaces canfilt.c of Problem 7.14. Because transp assumes that a and b have the same length M, this program aborts if the lengths are unequal. /* trspfilt.c - IIR filtering in transposed form */ #include <stdlib.h> #include <stdio.h> #define MAX 64 initial allocation size double transp(); void main(int argc, char **argv) { FILE *fpa, *fpb; coefficient files double *a, *b, *v, x, y; coeffs., state, input, output int M, L, i; int max = MAX, dmax = MAX; initial allocation and increment if (argc != 3) { 142 fprintf(stderr, "Usage: trspfilt a.dat b.dat <x.dat >y.dat\n"); fprintf(stderr, "coefficient vectors a,b must have same length"); exit(0); } if ((fpa = fopen(argv[1], "r")) == NULL) { fprintf(stderr, "Can’t open filter file: %s\n", argv[1]); exit(0); } if ((fpb = fopen(argv[2], "r")) == NULL) { fprintf(stderr, "Can’t open filter file: %s\n", argv[2]); exit(0); } a = (double *) calloc(max + 1, sizeof(double)); for (M=0;; M++) { if (M == max) { max += dmax; a = (double *) realloc((char *) a, (max + 1) * sizeof(double)); } if (fscanf(fpa, "%lf", a + M) == EOF) break; } M--; a = (double *) realloc((char *) a, (M + 1) * sizeof(double)); b = (double *) calloc(max + 1, sizeof(double)); for (L=0;; L++) { if (L == max) { max += dmax; b = (double *) realloc((char *) b, (max + 1) * sizeof(double)); } if (fscanf(fpb, "%lf", b + L) == EOF) break; } L--; b = (double *) realloc((char *) b, (L + 1) * sizeof(double)); if (M != L) { fprintf(stderr, "coefficient vectors a,b must have same length"); exit(0); } v = (double *) calloc(M + 1, sizeof(double)); while(scanf("%lf", &x) != EOF) { process input samples y = transp(M, a, b, v, x); printf("%lf\n", y); } } Problem 7.27 The transfer function is: H(z)= 9 −4z −2 +4z −4 1 +0.84z −2 +0.25z −4 = 3 −4z −1 +2z −2 1 −0.4z −1 +0.5z −2 · 3 +4z −1 +2z −2 1 +0.4z −1 +0.5z −2 The transpose of the canonical form is shown in Fig. P7.30. The I/O difference equations are: 143 y(n)= 9x(n)+v 1 (n) v 1 (n +1)= v 2 (n) v 2 (n +1)= −4x(n)−0.84y(n)+v 3 (n) v 3 (n +1)= v 4 (n) v 4 (n +1)= 4x(n)−0.25y(n) and the corresponding sample processing algorithm: for each input sample x do: y = 9x +v 1 v 1 = v 2 v 2 = −4x −0.84y +v 3 v 3 = v 4 v 4 = 4x −0.25y The cascade form with both 2nd order sections realized in their transposed form is shown in Fig. P7.31. The I/O difference equations are in this case: x 1 (n)= 3x(n)+v 01 (n) v 01 (n +1)= −4x(n)+0.4x 1 (n)+v 02 (n) v 02 (n +1)= 2x(n)−0.5x 1 (n) y(n)= 3x 1 (n)+v 11 (n) v 11 (n +1)= 4x 1 (n)−0.4y(n)+v 12 (n) v 12 (n +1)= 2x 1 (n)−0.5y(n) The sample processing algorithm will be: for each input sample x do: x 1 = 3x +v 01 v 01 = −4x +0.4x 1 +v 02 v 02 = 2x −0.5x 1 y = 3x 1 +v 11 v 11 = 4x 1 −0.4y +v 12 v 12 = 2x 1 −0.5y Problem 7.28 The overall, closed-loop, transfer function of the feedback system can be worked out easily using z-transforms. The general approach to analyzing this, and any other, block diagram is to assign names to all signal lines that do not already have names and then set up the various adder and filtering equations. Consider case A, with signal names assigned as in Fig. P7.32 Then, the adder and filtering equa- tions are in the time and z domains: 144 v 1 (n) v 0 (n) z -1 x(n) 9 -0.84 -0.25 -4 4 y(n) v 2 (n) z -1 v 3 (n) z -1 v 4 (n) z -1 Fig. P7.30 Transposed of canonical form. x(n) x 1 (n) v 01 (n) v 00 (n) v 02 (n) z -1 z -1 3 0.4 -0.5 -4 2 y(n) v 11 (n) v 10 (n) v 12 (n) z -1 z -1 3 -0.4 -0.5 4 2 Fig. P7.31 Cascade form with transposed sections. x(n) e(n) f(n) g(n) y(n) z -1 H 1 (z) H 2 (z) Fig. P7.32 Case A of Problem 7.28 e(n) = x(n)+f(n) g(n) = e(n −1) y(n) = h 1 (n)∗g(n) f(n) = h 2 (n)∗y(n) ⇒ E(z) = X(z)+F(z) G(z) = z −1 E(z) Y(z) = H 1 (z)G(z) F(z) = H 2 (z)Y(z) 145 Eliminating F(z) and E(z) in favor of X(z) and Y(z) gives: Y(z)= z −1 H 1 (z)E(z)= z −1 H 1 (z) _ X(z)+F(z) _ = z −1 H 1 (z) _ X(z)+H 2 (z)Y(z) _ and _ 1 −z −1 H 1 (z)H 2 (z) _ Y(z)= z −1 H 1 (z)X(z) Solving for the closed-loop transfer function H(z)= Y(z)/X(z), we find: H(z)= z −1 H 1 (z) 1 −z −1 H 1 (z)H 2 (z) Case B has the same transfer function H(z). Cases C and D have: H(z)= H 1 (z) 1 −z −1 H 1 (z)H 2 (z) Problem 7.29 The overall transfer function of this system can be computed using the results of Problem 7.28 and the individual transfer functions: H 1 (z)= 1 +z −1 1 −0.5z −1 , H 2 (z)= z −1 0.4(1 −z −1 ) 1 −0.4z −1 H(z)= H 1 (z) 1 −H 1 (z)H 2 (z) = 1 +z −1 1 −0.5z −1 1 − 1 +z −1 1 −0.5z −1 · 0.4(1 −z −1 )z −1 1 −0.4z −1 which gives H(z)= 1 +0.6z −1 −0.4z −2 1 −1.3z −1 +0.2z −2 +0.4z −3 In case A, we assign internal state variables as shown in Fig. P7.33. The difference equations and sample processing algorithm, written in the right computational order, are: e(n) = x(n)+f(n −1) w(n) = 0.5w(n −1)+e(n) y(n) = w(n)+w(n −1) v(n) = 0.4v(n −1)+y(n) f(n) = 0.4v(n)−0.4v(n −1) for each input sample x do: e = x +f 1 w 0 = 0.5w 1 +e y = w 0 +w 1 v 0 = 0.4v 1 +y f 0 = 0.4(v 0 −v 1 ) f 1 = f 0 (update delays) w 1 = w 0 v 1 = v 0 Notice how the extra delay factor z −1 in H 2 (z) delays the output f(n) and allows the start of the computational cycle with e(n)= x(n)+f(n−1). The output f(n) is computed last. If this delay were not there, we would have e(n)= x(n)+f(n), which is not possible because f(n) is not yet 146 x(n) e(n) w(n) w 0 f 0 v 0 w 1 v 1 f 1 v(n) w(n-1) v(n-1) f(n) f(n-1) y(n) 0.5 z -1 0.4 z -1 z -1 -0.4 0.4 Fig. P7.33 Case A of Problem 7.29. computed. In case B, shown in Fig. P7.34, the overall transfer function remains the same. The change causes a re-ordering of the computational cycle. The difference equations and corresponding sample processing algorithm are now: v(n) = 0.4v(n −1)+y(n −1) f(n) = 0.4v(n)−0.4v(n −1) e(n) = x(n)+f(n) w(n) = 0.5w(n −1)+e(n) y(n) = w(n)+w(n −1) for each input sample x do: v 0 = 0.4v 1 +y 1 f = 0.4(v 0 −v 1 ) e = x +f w 0 = 0.5w 1 +e y = w 0 +w 1 y 1 = y (update delays) w 1 = w 0 v 1 = v 0 x(n) e(n) f(n) w(n) w 0 v 0 w 1 v 1 y 1 v(n) w(n-1) v(n-1) y(n-1) y(n) 0.5 z -1 0.4 z -1 -0.4 0.4 z -1 Fig. P7.34 Case B of Problem 7.29. Now, the start of the computational cycle is v(n)= 0.4v(n−1)+y(n−1), where both quantities 147 v(n − 1) and y(n − 1) are available from the previous time step. Note that y(n) is computed last and then put into the feedback delay to be used in the next time step. Problem 7.30 The filter G(z) can be implemented by the input/output sample processing algorithm of its canonical form: for each x do: y = 0.2x +0.8w 1 w 1 = y where w 1 is its internal state, that is, w 1 (n)= y(n − 1) in the difference equation: y(n)= 0.2x(n)+0.8y(n − 1). Fig. P7.35 shows the three cases with explicitly assigned signal labels. Identifying the proper input and output to the filter G(z) and using the above sample processing algorithm, we obtain the implementation of the three cases: for each x do: u = 0.2v 4 +0.8w 1 w 1 = u y = v 0 = x +u delay(4, v) for each x do: y = x +v 4 v 0 = 0.2y +0.8w 1 w 1 = v 0 delay(4, v) for each x do: y = u 0 = x +v 2 v 0 = 0.2u 2 +0.8w 1 w 1 = v 0 delay(2, v), delay(2, u) z -4 G(z) z -4 G(z) z -2 z -2 G(z) (a) (b) (c) x u v 0 v 4 y x x v 0 v 0 u 0 u 2 v 4 v 2 y y Fig. P7.35 Feedback systems of Problem 7.30. 148 Chapter 8 Problems Problem 8.1 The transfer function is obtained by the period-3 repetition of the sequence b(n)= [0, 1, 2], that is, in the time- and z-domains: h(n) = b(n)+b(n −3)+b(n −6)+· · · H(z) = B(z)+z −3 B(z)+z −6 B(z)+· · · = B(z) 1 −z −3 = z −1 +2z −2 1 −z −3 The direct and canonical realizations are shown in Fig. P8.1. Their sample processing algorithms are: for each input x do: v 0 = x y = w 0 = v 1 +2v 2 +w 3 delay(2, v) delay(3, w) for each input x do: w 0 = x +w 3 y = w 1 +2w 2 delay(3, w) x y x y z -1 z -1 z -1 z -1 z -1 z -1 w 0 w 0 w 1 w 1 w 2 w 2 w 3 w 3 z -1 z -1 v 0 v 1 v 2 2 2 Fig. P8.1 Direct and canonical realizations of Problem 8.1. For the direct form realization, if the input is a unit impulse so that x = 1 at the first iteration of the algorithm and zero for all other iterations, then the first three iterations will fill the feedback delay buffer w with the desired waveform samples. From then on, the feed-forward part of the algorithm will be zero, giving rise to the following generation algorithm, expressed in its of the linear and circular buffer versions: repeat forever: w 0 = w 3 delay(3, w) repeat forever: ∗p = tap(3, w, p, 3) cdelay(3, w, &p) The following table shows the initialization and steady part of the linear buffer case. The columns v 0 , v 1 , v 2 are the input impulse and its delays: δ(n), δ(n−1), δ(n−2). At each iteration, w 0 is replaced by the value of w 3 and only then is the row of w’s shifted to the right to give the values of w 1 , w 2 , w 3 of the next row. The w-columns are the successively delayed output signals y(n), y(n −1), y(n −2), y(n −3): 149 n v 0 v 1 v 2 w 0 w 1 w 2 w 3 y = w 0 0 1 0 0 0 0 0 0 0 1 0 1 0 1 0 0 0 1 2 0 0 1 2 1 0 0 2 3 0 0 0 0 2 1 0 0 4 0 0 0 1 0 2 1 1 5 0 0 0 2 1 0 2 2 6 0 0 0 0 2 1 0 0 7 0 0 0 1 0 2 1 1 8 0 0 0 2 1 0 2 2 The circular version is given in the following table. The buffer entry that contains the current output sample is shown with an up-arrow symbol and it corresponds to the entry w q defined by the circulating value of q: n q w 0 w 1 w 2 w 3 y 0 0 ↑0 0 0 0 0 1 3 0 0 0 ↑1 1 2 2 0 0 ↑2 1 2 3 1 0 ↑0 2 1 0 n q w 0 w 1 w 2 w 3 y 4 0 ↑1 0 2 1 1 5 3 1 0 2 ↑2 2 6 2 1 0 ↑0 2 0 7 1 1 ↑1 0 2 1 n q w 0 w 1 w 2 w 3 y 8 0 ↑2 1 0 2 2 9 3 2 1 0 ↑0 0 10 2 2 1 ↑1 0 1 11 1 2 ↑2 1 0 2 n q w 0 w 1 w 2 w 3 y 12 0 ↑0 2 1 0 0 13 3 0 2 1 ↑1 1 14 2 0 2 ↑2 1 2 15 1 0 ↑0 2 1 0 The table entries circulate every D(D + 1)= 12 iterations. Thus, entry n = 3 and n = 15 will be the same. We used 15 iterations because they contain one complete cycle of the table entries after the first 3 initializing iterations. Problem 8.2 Expanding the denominator in powers of z −5 , will cause the period-5 replication of the numerator sequence b = [1, 2, 3, −4, −5]. The direct and canonical realizations are shown in Fig. P8.2. Their sample processing algorithms are: for each input x do: v 0 = x w 0 = v 0 +2v 1 +3v 2 −4v 3 −5v 4 +w 5 y = w 0 delay(4, v) delay(5, w) for each input x do: w 0 = x +w 5 y = w 0 +2w 1 +3w 2 −4w 3 −5w 4 delay(5, w) The steady parts of the linear and circular buffer generation algorithms are: repeat forever: w 0 = w 5 delay(5, w) repeat forever: ∗p = tap(5, w, p, 5) cdelay(5, w, &p) 150 x y x y z -1 z -1 z -1 z -1 w 5 w 0 w 1 w 2 w 3 w 4 z -1 z -1 z -1 z -1 z -1 w 5 w 0 w 1 w 2 w 3 w 4 z -1 z -1 z -1 z -1 v 0 v 1 v 2 v 3 v 4 z -1 -5 -5 -4 -4 2 2 3 3 Fig. P8.2 Direct and canonical realizations of Problem 8.2. The following table shows the initialization and steady parts of the linear buffer case: n v 0 v 1 v 2 v 3 v 4 w 0 w 1 w 2 w 3 w 4 w 5 y 0 1 0 0 0 0 1 0 0 0 0 0 1 1 0 1 0 0 0 2 1 0 0 0 0 2 2 0 0 1 0 0 3 2 1 0 0 0 3 3 0 0 0 1 0 −4 3 2 1 0 0 −4 4 0 0 0 0 1 −5 −4 3 2 1 0 −5 5 0 0 0 0 0 1 −5 −4 3 2 1 1 6 0 0 0 0 0 2 1 −5 −4 3 2 2 7 0 0 0 0 0 3 2 1 −5 −4 3 3 8 0 0 0 0 0 −4 3 2 1 −5 −4 −4 9 0 0 0 0 0 −5 −4 3 2 1 −5 −5 10 0 0 0 0 0 1 −5 −4 3 2 1 1 11 0 0 0 0 0 2 1 −5 −4 3 2 2 12 0 0 0 0 0 3 2 1 −5 −4 3 3 13 0 0 0 0 0 −4 3 2 1 −5 −4 −4 14 0 0 0 0 0 −5 −4 3 2 1 −5 −5 The circular version is given in the following table. The buffer entry that contains the current output sample is shown with an up-arrow symbol and it corresponds to the entry w q defined by the circulating value of q: n q w 0 w 1 w 2 w 3 w 4 w 5 y 0 0 1↑ 0 0 0 0 0 1 1 5 1 0 0 0 0 2↑ 2 2 4 1 0 0 0 3↑ 2 3 3 3 1 0 0 −4↑ 3 2 −4 4 2 1 0 −5↑ −4 3 2 −5 5 1 1 1↑ −5 −4 3 2 1 151 n q w 0 w 1 w 2 w 3 w 4 w 5 y 6 0 2↑ 1 −5 −4 3 2 2 7 5 2 1 −5 −4 3 3↑ 3 7 4 2 1 −5 −4 −4↑ 3 −4 9 3 2 1 −5 −5↑ −4 3 −5 10 2 2 1 1↑ −5 −4 3 1 11 1 2 2↑ 1 −5 −4 3 2 n q w 0 w 1 w 2 w 3 w 4 w 5 y 12 0 3↑ 2 1 −5 −4 3 3 13 5 3 2 1 −5 −4 −4↑ −4 14 4 3 2 1 −5 −5↑ −4 −5 15 3 3 2 1 1↑ −5 −4 1 16 2 3 2 2↑ 1 −5 −4 2 17 1 3 3↑ 2 1 −5 −4 3 n q w 0 w 1 w 2 w 3 w 4 w 5 y 18 0 −4↑ 3 2 1 −5 −4 −4 19 5 −4 3 2 1 −5 −5↑ −5 20 4 −4 3 2 1 1↑ −5 1 21 3 −4 3 2 2↑ 1 −5 2 22 2 −4 3 3↑ 2 1 −5 3 23 1 −4 −4↑ 3 2 1 −5 −4 n q w 0 w 1 w 2 w 3 w 4 w 5 y 24 0 −5↑ −4 3 2 1 −5 −5 25 5 −5 −4 3 2 1 1↑ 1 26 4 −5 −4 3 2 2↑ 1 2 27 3 −5 −4 3 3↑ 2 1 3 28 2 −5 −4 −4↑ 3 2 1 −4 29 1 −5 −5↑ −4 3 2 1 −5 n q w 0 w 1 w 2 w 3 w 4 w 5 y 30 0 1↑ −5 −4 3 2 1 1 31 5 1 −5 −4 3 2 2↑ 2 32 4 1 −5 −4 3 3↑ 2 3 33 3 1 −5 −4 −4↑ 3 2 −4 34 2 1 −5 −5↑ −4 3 2 −5 35 1 1 1↑ −5 −4 3 2 1 The table entries circulate every D(D + 1)= 30 iterations. Thus, entry n = 5 and n = 35 will be the same. We used 35 iterations because they contain one complete cycle of the table entries after the first 5 initializing iterations. 152 Problem 8.3 The shift is c = D/d = 8/5 = 1.6. The d = 5 possible values of the offset index q are obtained by iterating Eq. (8.1.36): q 0 = 0 q 1 = q 0 −c = − 8 5 ≡ 8 − 8 5 = 32 5 = 6 2 5 q 2 = q 1 −c = 32 5 − 8 5 = 24 5 = 4 4 5 q 3 = q 2 −c = 24 5 − 8 5 = 16 5 = 3 1 5 q 4 = q 3 −c = 16 5 − 8 5 = 8 5 = 1 3 5 Fig. P8.3 shows the relative locations of the q’s with respect to the circular buffer. The five q-arrows are now at relative angles ω= 2π/5. w 0 q 0 q 4 w 4 w 5 w 6 w 7 w 2 w 3 w 1 q 1 q 3 q 2 b 0 b 7 b 6 b 5 b 4 b 3 b 2 b 1 Fig. P8.3 Successive positions of q when d = 5. Down-truncation gives the following integer values for the q’s and corresponding buffer entries: [q 0 , q 1 , q 2 , q 3 , q 4 ]= [0, 6, 4, 3, 1] _ w[0], w[6], w[4], w[3], w[1] _ = [b 0 , b 2 , b 4 , b 5 , b 7 ] Up-truncation gives: [q 0 , q 1 , q 2 , q 3 , q 4 ]= [0, 7, 5, 4, 2] _ w[0], w[7], w[5], w[4], w[2] _ = [b 0 , b 1 , b 3 , b 4 , b 6 ] Rounding to the nearest integer gives: [q 0 , q 1 , q 2 , q 3 , q 4 ]= [0, 6, 5, 3, 2] _ w[0], w[6], w[5], w[3], w[2] _ = [b 0 , b 2 , b 3 , b 5 , b 6 ] For the linear interpolation case, we have the outputs: 153 q 0 = 0 ⇒ y 0 = w[0]= b 0 6 < q 1 < 7 ⇒ y 1 = w[6]+(q 1 −6)(w[7]−w[6])= 2 5 b 1 + 3 5 b 2 4 < q 2 < 5 ⇒ y 2 = w[4]+(q 2 −4)(w[5]−w[4])= 4 5 b 3 + 1 5 b 4 3 < q 3 < 4 ⇒ y 3 = w[3]+(q 3 −3)(w[4]−w[3])= 1 5 b 4 + 4 5 b 5 1 < q 4 < 2 ⇒ y 4 = w[1]+(q 4 −1)(w[2]−w[1])= 3 5 b 6 + 2 5 b 7 Thus, depending on the output method, the following period-5 subsequences will be produced: [b 0 , b 2 , b 4 , b 5 , b 7 , b 0 , b 2 , b 4 , b 5 , b 7 , . . . ] (truncate down) [b 0 , b 1 , b 3 , b 4 , b 6 , b 0 , b 1 , b 3 , b 4 , b 6 , . . . ] (truncate up) [b 0 , b 2 , b 3 , b 5 , b 6 , b 0 , b 2 , b 3 , b 5 , b 6 , . . . ] (round) [y 0 , y 1 , y 2 , y 3 , y 4 , y 0 , y 1 , y 2 , y 3 , y 4 , . . . ] (interpolation) where the y’s were given above. Problem 8.4 The shift is c = D/d = 8/6 = 4/3. The d = 6 possible values of the offset index q are obtained by iterating Eq. (8.1.36): q 0 = 0 q 1 = q 0 −c = − 4 3 ≡ 8 − 4 3 = 20 3 = 6 2 3 q 2 = q 1 −c = 20 3 − 4 3 = 16 3 = 5 1 3 q 3 = q 2 −c = 16 3 − 4 3 = 12 3 = 4 q 4 = q 3 −c = 12 3 − 4 3 = 8 3 = 2 2 3 q 5 = q 4 −c = 8 3 − 4 3 = 4 3 = 1 1 3 Fig. P8.4 shows the relative locations of the q’s with respect to the circular buffer. The six q-arrows are now at relative angles ω= 2π/6. Down-truncation gives the following integer values for the q’s and corresponding buffer entries: [q 0 , q 1 , q 2 , q 3 , q 4 , q 5 ]= [0, 6, 5, 4, 2, 1] _ w[0], w[6], w[5], w[4], w[2], w[1] _ = [b 0 , b 2 , b 3 , b 4 , b 6 , b 7 ] Up-truncation gives: [q 0 , q 1 , q 2 , q 3 , q 4 , q 5 ]= [0, 7, 6, 4, 3, 2] _ w[0], w[7], w[6], w[4], w[3], w[2] _ = [b 0 , b 1 , b 2 , b 4 , b 5 , b 6 ] 154 w 0 q 0 q 1 q 2 q 3 q 4 q 5 w 4 w 5 w 6 w 7 w 2 w 3 w 1 b 0 b 7 b 6 b 5 b 4 b 3 b 2 b 1 Fig. P8.4 Successive positions of q when d = 6. Rounding to the nearest integer gives: [q 0 , q 1 , q 2 , q 3 , q 4 , q 5 ]= [0, 7, 5, 4, 3, 1] _ w[0], w[7], w[5], w[4], w[3], w[1] _ = [b 0 , b 1 , b 3 , b 4 , b 5 , b 7 ] For the linear interpolation case, we have the outputs: q 0 = 0 ⇒ y 0 = w[0]= b 0 6 < q 1 < 7 ⇒ y 1 = w[6]+(q 1 −6)(w[7]−w[6])= 2 3 b 1 + 1 3 b 2 5 < q 2 < 6 ⇒ y 2 = w[5]+(q 2 −5)(w[6]−w[5])= 1 3 b 2 + 2 3 b 3 q 3 = 4 ⇒ y 3 = w[4]= b 4 2 < q 4 < 3 ⇒ y 4 = w[2]+(q 4 −2)(w[3]−w[2])= 2 3 b 5 + 1 3 b 6 1 < q 5 < 2 ⇒ y 5 = w[1]+(q 5 −1)(w[2]−w[1])= 1 3 b 6 + 2 3 b 7 Thus, depending on the output method, the following period-5 subsequences will be produced: [b 0 , b 2 , b 3 , b 4 , b 6 , b 7 , b 0 , b 2 , b 3 , b 4 , b 6 , b 7 , . . . ] (truncate down) [b 0 , b 1 , b 2 , b 4 , b 5 , b 6 , b 0 , b 1 , b 2 , b 4 , b 5 , b 6 , . . . ] (truncate up) [b 0 , b 1 , b 3 , b 4 , b 5 , b 7 , b 0 , b 1 , b 3 , b 4 , b 5 , b 7 , . . . ] (round) [y 0 , y 1 , y 2 , y 3 , y 4 , y 5 , y 0 , y 1 , y 2 , y 3 , y 4 , y 5 , . . . ] (interpolate) where the y’s are given above. Problem 8.5 This problem is similar to Example 8.1.2. Referring to Fig. 8.1.14, we have for the cases of trun- cating down, up, and rounding: [b 0 , b 3 , b 6 , b 0 , b 3 , b 6 , . . . ]= [1, 4, 7, 1, 4, 7, . . . ] (truncate down) [b 0 , b 2 , b 5 , b 0 , b 2 , b 5 , . . . ]= [1, 3, 6, 1, 3, 6, . . . ] (truncate up) [b 0 , b 3 , b 5 , b 0 , b 3 , b 5 , . . . ]= [1, 4, 6, 1, 4, 6, . . . ] (round) 155 If we interpolate linearly, we get the sequence: y 0 = b 0 = 1 y 1 = 1 3 b 2 + 2 3 b 3 = 1 3 3 + 2 3 4 = 11 3 = 3.667 y 2 = 1 3 b 5 + 2 3 b 6 = 1 3 6 + 2 3 7 = 20 3 = 6.667 so that the period-3 sequence is: [1, 3.667, 6.667, 1, 3.667, 6.667, . . . ] Problem 8.6 This problemis similar to Problem8.3. Inserting the numerical values for the wavetable contents: b = [b 0 , b 1 , b 2 , b 4 , b 5 , b 6 , b 7 ]= [1, 2, 3, 4, 5, 6, 7, 8] we find for the period-5 sequences: [b 0 , b 2 , b 4 , b 5 , b 7 , . . . ]= [1, 3, 4, 5, 7. . . ] (truncate down) [b 0 , b 1 , b 3 , b 4 , b 6 , . . . ]= [1, 2, 3, 5, 7, . . . ] (truncate up) [b 0 , b 2 , b 3 , b 5 , b 6 , . . . ]= [1, 3, 4, 6, 7, . . . ] (round) [y 0 , y 1 , y 2 , y 3 , y 4 , . . . ]= [1, 2.6, 4.2, 5.8, 7.4, . . . ] (interpolation) where y 0 = b 0 = 1 y 1 = 2 5 b 1 + 3 5 b 2 = 2 5 2 + 3 5 3 = 2.6 y 2 = 4 5 b 3 + 1 5 b 4 = 4 5 4 + 1 5 5 = 4.2 y 3 = 1 5 b 4 + 4 5 b 5 = 1 5 5 + 1 5 6 = 5.8 y 4 = 3 5 b 6 + 2 5 b 7 = 3 5 7 + 2 5 8 = 7.4 The case d = 6 is similar to Problem 8.4. Problem 8.7 An example program that exercises the wavetable routines is listed below. It generates three wavetables: sinusoidal, square wave, and trapezoidal. /* wavgenex.c - circular wavetable example */ #include <stdio.h> #include <stdlib.h> #include <math.h> void gdelay2(); double wavgen(); double sine(), square(), trapez(); 156 void main(int argc, char **argv) { int i, n, D; double *w1, q1, *w2, q2, *w3, q3, c, A, F; FILE *fp1, *fp2, *fp3; if (argc != 4) { fprintf(stderr, "usage: wavgenex A, c, D\n"); fprintf(stderr, "A = wavetable amplitude\n"); fprintf(stderr, "c = no. of periods in D samples, F=c/D\n"); fprintf(stderr, "D = wavetable size\n"); exit(0); } A = atof(argv[1]); c = atof(argv[2]); D = atoi(argv[3]); F = c / D; fp1 = fopen("y1.dat", "w"); fp2 = fopen("y2.dat", "w"); fp3 = fopen("y3.dat", "w"); w1 = (double *) calloc(D, sizeof(double)); w2 = (double *) calloc(D, sizeof(double)); w3 = (double *) calloc(D, sizeof(double)); q1 = 0; q2 = 0; q3 = 0; for (i=0; i<D; i++) { /* load wavetables */ w1[q1] = sine(D, i); /* might need the cast w1[(int)q1] */ w2[q2] = square(D/2, i); w3[q3] = trapez(D, 3*D/4, 0, i); gdelay2(D-1, 1.0, &q1); gdelay2(D-1, 1.0, &q2); gdelay2(D-1, 1.0, &q3); } for (n=0; n<D; n++) { fprintf(fp1, "%lf\n", wavgen(D, w1, A, F, &q1)); fprintf(fp2, "%lf\n", wavgen(D, w2, A, F, &q2)); fprintf(fp3, "%lf\n", wavgen(D, w3, A, F, &q3)); } } Problem 8.8 Partial C code for this problem was given in the text, just before Figs. 8.1.20 and 8.1.21. Problem 8.9 The zero patterns and magnitude responses ¦H(ω)¦ of the four filters are shown in Fig. 8.9. The first filter has H(z)= 1 +z −8 . Therefore, its zeros are the solutions of: 157 z 8 = −1 = e jπ e 2πjk ⇒ z k = e jπ/8 e j2πk/8 , k = 0, 1, . . . , 7 That is, the 8th roots of unity rotated by π/8 ≡= 22.5 o . The second filter has H(z)= 1 − z −8 and thus, its zeros are the 8th roots of unity. 2 2 ω 2π 2π |H(ω)| ω 3 2π ω 3 2π ω Fig. P8.5 Comb filters of Problem 8.9. The third and fourth filters can be written as follows, using the finite geometric series: H(z) = 1 −z −8 +z −16 = 1 +z −24 1 +z −8 H(z) = 1 +z −8 +z −16 = 1 −z −24 1 −z −8 The third has roots the 24th roots of unity shifted by π/24 = 7.5 o , but among them the roots of the denominator 1 +z −8 must be excluded. This results in 16 zeros. Similarly, the last filter’s zeros are the 24th roots of unity with the 8th roots of unity excluded. Problem 8.10 Typical C code for generating Fig. 8.2.9 and 8.2.11 is given in the text. For the double chorus case, we have the code segment: for (n=0; n<Ntot; n++) { d1 = D * (0.5 + ranl(Dran, u1, &q1, &iseed1)); /* u1 is 2-dim */ d2 = D * (0.5 + ranl(Dran, u2, &q2, &iseed2)); /* mean = D/2 */ a1 = 1 + ranl(Dran, u3, &q3, &iseed3); /* mean = 1 */ a2 = 1 + ranl(Dran, u4, &q4, &iseed4); x = cos(2 * pi * F * n); /* input x(n) */ xd1 = tapi(D, w, p, d1); /* delay x(n-d1) */ xd2 = tapi(D, w, p, d2); y = (x + a1 * xd1 + a2 * xd2) / 3; /* output */ *p = x; cdelay(D, w, &p); /* update delay */ fprintf(fpx, "%lf\n", x); /* declaration of fpx */ 158 fprintf(fpy, "%lf\n", y); /* is not shown */ fprintf(fpd, "%lf\n", 2*d1/D); fprintf(fpa, "%lf\n", a1); } Typical output is shown in Fig. P8.6. For the recursive flanger, we have the code fragment: Fig. P8.6 Double chorusing of sinusoidal signal. for (n=0; n<Ntot; n++) { d = 0.50 * D * (1 - cos(2 * pi * Fd * n)); x = cos(2 * pi * F * n); yd = tapi(D, w, p, d); y = a * yd + x; /* yd is y(n-d) */ *p = y; cdelay(D, w, &p); fprintf(fpx, "%lf\n", x); fprintf(fpy, "%lf\n", y); fprintf(fpd, "%lf\n", d/D); } Typical output for D = 100 and D = 10 is shown in Fig. P8.7. Problem 8.11 A typical program is as follows: /* reverb.c - plain, allpass, and lowpass reverb */ #include <stdio.h> #include <stdlib.h> #include <math.h> double plain(), allpass(), lowpass(); void main(int argc, char **argv) { double *w1, *p1; double *w2, *p2; 159 Fig. P8.7 Recursive flanger. double *w3, *p3; double v[2] = {0., 0.}; double a[2] = {1, -0.5}; double b[2] = {0.3, 0.15}; double a0 = 0.75; double x, y1, y2, y3, sD; int D, Ntot, M=1, n; FILE *fp1, *fp2, *fp3; fp1 = fopen("y1.dat", "w"); fp2 = fopen("y2.dat", "w"); fp3 = fopen("y3.dat", "w"); if (argc != 3) { fprintf(stderr, "usage: reverb D Ntot"); use D=20, Ntot=100 exit(0); } D = atoi(argv[1]); Ntot = atoi(argv[2]); w1 = (double *) calloc(D+1, sizeof(double)); p1 = w1; w2 = (double *) calloc(D+1, sizeof(double)); p2 = w2; w3 = (double *) calloc(D+1, sizeof(double)); p3 = w3; for (n=0; n<Ntot; n++) { triangular pulse if (n<=5) x=n; else if (n<=10) x = 10-n; else x=0; 160 y1 = plain(D, w1, &p1, a0, x); y2 = allpass(D, w2, &p2, a0, x); y3 = lowpass(D, w3, &p3, M, a, b, v, x); fprintf(fp1, "%lf\n", y1); fprintf(fp2, "%lf\n", y2); fprintf(fp3, "%lf\n", y3); } } Problem 8.12 A typical program is as follows: /* reverb.c - Schroeder’s plain/allpass reverb system */ #define D1 29 #define D2 37 #define D3 44 #define D4 50 #define D5 27 #define D6 31 #define a1 .75 #define a2 .75 #define a3 .75 #define a4 .75 #define a5 .75 #define a6 .75 #include <stdio.h> #include <stdlib.h> #include <math.h> double plain(), allpass(); void main() { double *w1, *p1; double *w2, *p2; double *w3, *p3; double *w4, *p4; double *w5, *p5; double *w6, *p6; double y1, y2, y3, y4, y5, y, x; int Ntot=500, n; FILE *fpy; fpy = fopen("y.dat", "w"); w1 = (double *) calloc(D1+1, sizeof(double)); p1 = w1; w2 = (double *) calloc(D2+1, sizeof(double)); 161 p2 = w2; w3 = (double *) calloc(D3+1, sizeof(double)); p3 = w3; w4 = (double *) calloc(D4+1, sizeof(double)); p4 = w4; w5 = (double *) calloc(D5+1, sizeof(double)); p5 = w5; w6 = (double *) calloc(D6+1, sizeof(double)); p6 = w6; for (n=0; n<Ntot; n++) { if(n==0) impulse x = 1; else x = 0; y1 = plain(D1, w1, &p1, a1, x); y2 = plain(D2, w2, &p2, a2, x); y3 = plain(D3, w3, &p3, a3, x); y4 = plain(D4, w4, &p4, a4, x); y = y1 + 0.9*y2 + 0.8*y3 + 0.7*y4; y5 = allpass(D5, w5, &p5, a5, y); y = allpass(D6, w6, &p6, a6, y5); fprintf(fpy, "%lf\n", y); } } Problem 8.13 The difference equations are: v(n) = y(n −D)−a 1 v(n −1) u(n) = b 0 v(n)+b 1 v(n −1) y(n) = x(n)+u(n) The corresponding circular version of the sample processing algorithm is for each input x do: s D = tap(D, w, p, D) v 0 = s D −a 1 v 1 u = b 0 v 0 +b 1 v 1 v 1 = v 0 y = x +u ∗p = y cdelay(D, w, &p) 162 Problem 8.14 The response to a causal sinusoid will be of the form: e jωn u(n)−→H(ω)e jωn u(n)+ D+1 _ i=1 B i p n i u(n) where B i = A i p i /(p i −e jω ), as shown in Problem 6.29. It follows that the response to a delayed sinusoid will be: e jω(n−L) u(n −L)−→H(ω)e jω(n−L) u(n −L)+ D+1 _ i=1 B i p n−L i u(n −L) Multiplying both sides by the factor e jωL and subtracting from the undelayed result, we find that the response to the finite sinusoid: x(n)= e jωn _ u(n)−u(n −L) _ is y(n)= H(ω)e jωn _ u(n)−u(n −L) _ + D+1 _ i=1 B i p n i _ u(n)−e jωL p −L i u(n −L) _ Problem 8.15 A typical C program that utilizes the routines plain and lowpass is given below: /* reverbex.c - plain and lowpass reverberation of sinusoid */ * * run with: * D=300, L=150, N=300, w=0.2pi, w=pi * */ #include <stdio.h> #include <stdlib.h> #include <math.h> double plain(), lowpass(); void main(int argc, char **argv) { double *w1, *p1; double *w2, *p2; double v[2] = {0., 0.}; double a[2] = {1, -0.5}; double b[2] = {0.3, 0.15}; double a0 = 0.75; double w, x, y1, y2, sD; double pi = 4*atan(1.0); int D, L, N, M=1, n; FILE *fp1, *fp2; 163 fp1 = fopen("ypl.dat", "w"); fp2 = fopen("ylp.dat", "w"); if (argc != 5) { puts("usage: reverbex D L N w\n\n" "D = delay period\n" "L = time to turn off input\n" "N = total duration of input \n" "w = in units of pi \n"); exit(0); } D = atoi(argv[1]); L = atoi(argv[2]); N = atoi(argv[3]); w = atof(argv[4]); in units of pi w1 = (double *) calloc(D+1, sizeof(double)); p1 = w1; w2 = (double *) calloc(D+1, sizeof(double)); p2 = w2; for (n=0; n<N; n++) { if (n < L) sinusoid on for L samples x = cos(pi*w*n); else x = 0; y1 = plain(D, w1, &p1, a0, x); y2 = lowpass(D, w2, &p2, M, a, b, v, x); fprintf(fp1, "%.16lf\n", y1); fprintf(fp2, "%.16lf\n", y2); } } The analytical expression for y(n) can be obtained as follows. Using the MATLAB function lprevb.m given below, we determine the poles p i and residues A i of the transfer function: function [p, A] = lprvb(b, a, D) % returns poles and residues of lowpass reverberator (delay D) % [p, A] = lprvb(b, a, D) % % b=[b(1), b(2)] % a=[1, a(2)] c = [a, zeros(1,D-2), -b]; p=roots(c); for i=1:D+1, A(i) = 1 + a(2) / p(i); for j=1:D+1, if j ~= i, A(i) = A(i) * p(i) / (p(i) - p(j)); end 164 end end Then, the following MATLAB function calculates the residues B i and computes N samples of the output signal y(n): function [y, p, A] = yon(N, L, w, b, a, D) % calculate y(n) for a finite-duration sinusoidal input. [p, A] = lprvb(b, a, D); z = exp(j * w); H = 1 / (1 - z^(-D) * (b(1) + z^(-1)*b(2)) / (1 + a(2)*z^(-1))); for i=1:D+1, B(i) = A(i) * p(i) / (p(i) - z); end for n=0:N-1, if (n<L), y(n+1) = H * z^n; for i=1:D+1, y(n+1) = y(n+1) + B(i) * p(i)^n; end else y(n+1) = 0; for i=1:D+1, y(n+1) = y(n+1) + B(i) * p(i)^n * (1 - z^L / p(i)^L); end end end Problem 8.16 A typical C program is as follows: /* karplus.c - Karplus-Strong String Algorithm */ * * run with: * D=25, Ntot=500, iseed=1234567 * D=50, Ntot=500, iseed=1234567 * /* #include <stdio.h> #include <stdlib.h> #include <math.h> double ran(), lowpass(); void main(int argc, char **argv) { double *w, *p; double v[2] = {0., 0.}; double a[2] = {1, 0.0}; 165 double b[2] = {0.5, 0.5}; double x, y; int D, Ntot, M=1, n; long iseed; FILE *fpy; fpy = fopen("y.dat", "w"); if (argc != 4) { fprintf(stderr, "usage: karplus D Ntot iseed"); exit(0); } D = atoi(argv[1]); Ntot = atoi(argv[2]); iseed = atol(argv[2]); w = (double *) calloc(D+1, sizeof(double)); for (n=0; n<=D; n++) initialize w[n] = ran(&iseed) - 0.5; p = w; for (n=0; n<Ntot; n++) { y = lowpass(D, w, &p, M, a, b, v, 0.0); x=0 fprintf(fpy, "%.16lf\n", y); } } The output signals corresponding to D = 25 and D = 50 are shown in Fig. P8.8. Note how the initial random numbers get smoothed at each D-cycle resulting in a decaying quasi-periodic signal tuned to the frequency f = f s /D. Fig. P8.8 Karplus-Strong string algorithm outputs. Problem 8.17 A block diagram realization is given in Fig. P8.9. The difference equations are the system: 166 w(n) = aw(n −D)+x(n) y(n) = cx(n)+bw(n −D) x y b c a z -D w 0 w D Fig. P8.9 Prototypical delay effect. The sample processing algorithm is in its linear and circular buffer forms: for each input x do: y = cx +bw D w 0 = aw D +x delay(D, w) for each input x do: s D = tap(D, w, p, D) y = cx +bs D ∗p = as D +x cdelay(D, w, &p) Problem 8.18 The block diagrams and sample processing algorithms are essentially given in Section 8.2.4. The C routines are: /* plaindel.c - plain reverberating delay */ double tap(); void cdelay(); double plaindel(D, w, p, a, x) usage: y=plaindel(D,w,&p,a,x); double *w, **p, a, x; p is passed by address int D; { double y; y = tap(D, w, *p, D); D-th tap delay output **p = x + a * y; delay input cdelay(D, w, p); update delay line return y; } /* lpdel.c - lowpass reverberating delay */ double tap(), can(); void cdelay(); double lpdel(D, w, p, M, a, b, v, x) double *w, **p, *a, *b, *v, x; 167 int D; { double y; y = tap(D, w, *p, D); D-th tap delay output **p = x + can(M, a, M, b, v, y); delay input cdelay(D, w, p); update delay line return y; } The routines differ from plain and lowpass in that the filter outputs are taken after the delay z −D , instead of before. Problem 8.19 Typical C code for this problem is: for (n=0; n<Ntot; n++) { if (n<L) /* use if (n<1) for impulse response */ x = 1; else x = 0; x1 = plaindel(D1, w1, &p1, a0, x); /* plain */ x2 = plaindel(D2, w2, &p2, a0, x1); /* x1 = lpdel(D1, w1, &p1, 1, a, b, v1, x); */ /* lowpass */ /* x2 = lpdel(D2, w2, &p2, 1, a, b, v2, x1); */ y = b0 * x + b1 * x1 + b2 * x2; /* output */ fprintf(fpx, "%.16lf\n", x); fprintf(fpy, "%.16lf\n", y); } where the initializations are: double x, x1, x2, y, *w1, *w2, *p1, *p2; double v1[2] = {0., 0.}; /* state of LP filter 1 */ double v2[2] = {0., 0.}; /* state of LP filter 2 */ double a[2] = {1, -0.5}; /* G(z) denominator */ double b[2] = {0.3, 0.15}; /* G(z) numerator */ double b0=1, b1=0.8, b2=0.6 /* feed-forward coefficients */ double a0 = 0.75; /* feedback for plain delay */ w1 = (double *) calloc(D1+1, sizeof(double)); p1 = w1; w2 = (double *) calloc(D2+1, sizeof(double)); p2 = w2; Typical output is as in Fig. P8.10. Problem 8.20 The sample processing routine is as follows. It can easily be generalized to more than two multi- tap delay segments: 168 Fig. P8.10 Multi-delay effects processor outputs. /* mlttap.c - multi-tap delay line */ double tap(); void cdelay(); double mlttap(D1, D2, b, a, w, p, x) int D1, D2; double b[3], a[3], *w, **p, x; { double s[3], y; s[1] = tap(D1+D2, w, *p, D1); s[2] = tap(D1+D2, w, *p, D1+D2); s[0] = x + a[1] * s[1] + a[2] * s[2]; y = b[0] * x + b[1] * s[1] + b[2] * s[2]; **p = s[0]; cdelay(D1+D2, w, p); return y; } Typical output is shown in Fig. P8.11 and is obtained by the code segment: for (n=0; n<Ntot; n++) { if (n < L) /* use L=1 or L=200 */ x = 1; else x = 0; y = mlttap(D1, D2, b, a, w, &p, x); /* p passed by reference */ fprintf(fpx, "%.8lf\n", x); fprintf(fpy, "%.8lf\n", y); } Problem 8.21 From the pole equation, we have: 169 Fig. P8.11 Multi-Tap Delay Line. z D1+D2 = a 1 z D2 +a 2 ⇒ ¦z¦ D1+D2 = ¦a 1 z D2 +a 2 ¦ ≤ ¦a 1 ¦¦z¦ D2 +¦a 2 ¦ (P8.1) If a pole had ¦z¦ ≥ 1, then using the inequality ¦a 1 ¦ +¦a 2 ¦ < 1, we would have: ¦z¦ D1+D2 ≥ ¦z¦ D2 > ¦a 1 ¦¦z¦ D2 +¦a 2 ¦¦z¦ D2 ≥ ¦a 1 ¦¦z¦ D2 +¦a 2 ¦ which contradicts Eq. (P8.1). Thus, all poles must have ¦z¦ < 1. Problem 8.22 Working in the z-domain and denoting by W L (z) and W R (z) the inputs to the delays z −L and z −R , the outputs of these delays will be z −L W L (z) and z −R W R (z). Thus, the I/O equations of the block diagram will be: Y L (z) = c L X L (z)+z −L W L (z) W L (z) = z −L G L (z)W L (z)+b L X L (z)+d R z −R W R (z) Y R (z) = c R X R (z)+z −R W R (z) W R (z) = z −R G L (z)W R (z)+b R X R (z)+d L z −L W L (z) Solving the first and third for the Ws, we get: W L (z)= z L _ Y L (z)−c L X L (z) _ , W R (z)= z R _ Y R (z)−c R X R (z) _ Inserting them into the second and fourth, we get the system: _ 1 −z −L G L (z) __ Y L (z)−c L X L (z) _ −d R z −L _ Y R (z)−c R X R (z) _ = b L z −L X L (z) _ 1 −z −R G R (z) __ Y R (z)−c R X R (z) _ −d L z −R _ Y L (z)−c L X L (z) _ = b R z −R X R (z) Solving for Y L (z), Y R (z) in terms of X L (z), X R (z), we get: Y L (z) = H LL (z)X L (z)+H LR (z)X R (z) Y R (z) = H RL (z)X L (z)+H RR (z)X R (z) 170 where H LL (z) = c L + 1 D(z) _ 1 −z −R G R (z) _ b L z −L H LR (z) = 1 D(z) d R b R z −L z −R H RL (z) = 1 D(z) d L b L z −R z −L H RR (z) = c R + 1 D(z) _ 1 −z −L G L (z) _ b R z −R with D(z)= _ 1 −z −R G R (z) __ 1 −z −L G L (z) _ −d L d R z −L z −R For the special case when the cross couplings are d L }= 0 and d R = 0, we have: D(z)= _ 1 −z −R G R (z) __ 1 −z −L G L (z) _ and therefore, the transfer functions simplify to: H LL (z) = c L + b L z −L 1 −z −L G L (z) H LR (z) = 0 H RL (z) = d L b L z −L z −R _ 1 −z −R G R (z) __ 1 −z −L G L (z) _ H RR (z) = c R + b R z −R 1 −z −R G R (z) The corresponding I/O system is then: Y L (z) = H LL (z)X L (z) Y R (z) = H RL (z)X L (z)+H RR (z)X R (z) which means that the left channel responds only to the left input (it does not receive any cross- feedback from the right channel), but the right channel responds to both the right input and the cross feedback from the left output. If both cross-feedbacks are zero, d L = d R = 0, then the left and right channels decouple completely, responding independently to their respective inputs. For the case G L (z)= a L , G R (z)= a R , the sample processing algorithm is straightforward. Denote the left and right delay-line buffers by w L = [w L0 , w L1 , . . . , w LL ]= (L+1)-dimensional w R = [w R0 , w R1 , . . . , w RR ]= (R+1)-dimensional Let p L and p R be the circular pointers circulating over them, and let the corresponding delay outputs be s L and s R . Then, the computational sample processing algorithm will be: 171 for each input pair ¦x L , x R ¦ do: s L = tap(L, w L , p L , L) s R = tap(R, w R , p R , R) y L = c L x L +s L y R = c R x R +s R ∗p L = b L x L +a L s L +d R s R ∗p R = b R x R +a R s R +d L s L cdelay(L, w L , &p L ) cdelay(R, w R , &p R ) Problem 8.23 The sample processing algorithm is implemented by the C code segment: int L = 30, R = 70; double *wL, *wR, *pL, *pR; wL = (double *) calloc(L+1, sizeof(double)); pL = wL; wR = (double *) calloc(R+1, sizeof(double)); pR = wR; for (n=0; n<Ntot; n++) { if (n < P) xL = 1; else xL = 0; sL = tap(L, wL, pL, L); sR = tap(R, wR, pR, R); yL = cL * xL + sL; yR = cR * xR + sR; /* use xR = 0 */ *pL = bL * xL + aL * sL + dR * sR; *pR = bR * xR + aR * sR + dL * sL; cdelay(L, wL, &pL); cdelay(R, wR, &pR); fprintf(fp1, "%.16lf\n", yL); fprintf(fp2, "%.16lf\n", yR); } Figures P8.12 and P8.13 show typical outputs. The left output does not start until n = L, there- fore, the first right output will begin at n = L +R. That output will be fed back into the left and will come out at n = 2L + R. Similarly, the second left pulse at n = 2L will appear on the right at n = 2L +R, and so on. Problem 8.24 The sample processing algorithm is implemented by the C code segment: if (L > 1) { /* L-point smoother */ h = (double *) calloc(L, sizeof(double)); v = (double *) calloc(L, sizeof(double)); for (n=0; n<L; n++) h[n] = 1.0 / L; 172 Fig. P8.12 Stereo delays, with d L = d R = 0.3. Fig. P8.13 Stereo delays, with d L = 0.3, d R = 0. } for (n=0; n<N; n++) { /* use N = 600 */ if (n < N/3) /* generate input */ x = A1 * cos(w0 * n); /* use w0 = 0.15 * pi */ else if (n < 2*N/3) x = A2 * cos(w0 * n); else x = A3 * cos(w0 * n); c = a * c1 + (1-a) * fabs(x); /* control signal */ c1 = c; /* update delay */ g = f(rho, c/c0); /* gain function */ if (L > 1) G = fir(L-1, h, v, g); /* gain smoothing */ else G = g; /* no smoothing */ y = G * x; /* compressor output */ 173 fprintf(fpx, "%.16lf\n", x); /* save input */ fprintf(fpy, "%.16lf\n", y); /* save output */ fprintf(fpc, "%.16lf\n", c); /* save control */ fprintf(fpg, "%.16lf\n", G); /* save gain */ } where the compressor function is defined by f(x)= x ρ−1 , for x ≥ 1: /* compressor function with 1:rho compressor ratio */ #include <math.h> double f(rho, x) double rho, x; { if (x >= 1) return pow(x, rho-1); else return 1; } The compressing action takes place only above the threshold. For an expander, the gain function is defined as follows, where now ρ > 1, but it takes effect only below the threshold: /* expander gain function with 1:rho expander ratio */ #include <math.h> double f(rho, x) double rho, x; { if (x <= 1) return pow(x, rho-1); else return 1; } Problem 8.25 Increasing the threshold to c 0 will cause both A 1 and A 3 to be attenuated. However, A 3 because it is further from c 0 than in the case of Fig. 8.2.38, it will be attenuated more. Fig. P8.14 shows the results. The noise gate with threshold c 0 = 1.5, will suppress both A 1 and A 3 , but A 3 by much more, for the same reasons explained above. Fig. P8.15 shows the results. Problem 8.26 Assuming the causal sequence ¦x(0), x(1), . . . ¦ is zero-mean white, then the terms in the convo- lutional sum will be mutually uncorrelated and zero-mean: y(n)= h 0 x(n)+h 1 x(n −1)+· · · +h(n)x(0) Thus, the output will have zero mean and its variance will be the sum of the variances of the successive terms: σ 2 y = E[y(n) 2 ]= h 2 0 σ 2 x +h 2 1 σ 2 x +· · · h 2 n σ 2 x = σ 2 x n _ n=0 h 2 m 174 Fig. P8.14 Expander output and gain with increased threshold. Fig. P8.15 Noise gate output and gain with increased threshold. Problem 8.27 Assuming a partial fraction expansion of the form: H(z)= M _ i=1 A i 1 −p i z −1 we have for the impulse response: h n = M _ i=1 A i p n i u(n) It follows that we have the bound: ¦h n ¦ = ¸ ¸ M _ i=1 A i p n i ¸ ¸ ≤ M _ i=1 ¦A i ¦¦p i ¦ n ≤ M _ i=1 ¦A i ¦¦p max ¦ n = C¦p max ¦ n where C = M i=1 ¦A i ¦ and we used the inequality ¦p i ¦ ≤ ¦p max ¦. The NRR inequality follows now by squaring and summing the above inequality for ¦h n ¦ and applying the geometric series on the right-hand side. 175 Problem 8.28 For ideal filter shapes, the NRR is computed most conveniently using its frequency response definition: NRR = σ 2 yv σ 2 v = _ π −π ¦H(ω)¦ 2 dω 2π For a bandpass filter, H(ω) is non-zero only over the interval ω a ≤ ¦ω¦ ≤ ω b , where it is unity. Thus, NRR = σ 2 yv σ 2 v = _ −ωa −ω b 1 · dω 2π + _ ω b ωa 1 · dω 2π = ω b −ω a π Problem 8.29 The following program is an implementation: /* smooth1.c - 1st-order exponential smoother */ #include <stdio.h> #include <math.h> void main(int argc, char **argv) { double a, x, y, w1 = 0; if (argc != 2) { fprintf(stderr, "usage: smooth1 a <x.dat >y.dat\n"); exit(0); } a = atof(argv[1]); fprintf(stderr, "%lf\n", a); while(scanf("%lf", &x) != EOF) { y = a * w1 + (1-a) * x; w1 = y; printf("%lf\n", y); } } Problem 8.30 The mean of x(n) is m x = s = 5. The mean of y(n) is the same because it is preserved through the filter. Indeed, taking means of both sides of y(n)= ay(n −1)+(1 −a)x(n) gives m y = am y +(1 −a)m x ⇒ m y = m x The mean-square values may be determine recursively as follows: If we define s 2 n = 1 n n−1 _ k=0 (x k −m x ) 2 176 then we have the recursion: s 2 n+1 = s 2 n + 1 n +1 _ (x n −m x ) 2 −s 2 n _ initialized with s 2 0 = 0. The following program will calculate the input and output signals and the experimental mean-square values. Any discrepancies are due to the filter transients and they disappear with increasing L: /* smoothex.c - filtering with 1st order smoother */ #include <stdio.h> #include <math.h> double gran(); void main(int argc, char **argv) { int n, L; long iseed; double s=5, x, y, w1, a, m=0, sigma=1; double sx2=0, sy2=0; FILE *fpx, *fpy; if (argc != 4) { puts("\nUsage: smoothex a iseed L"); exit(0); } a = atof(argv[1]); iseed = atol(argv[2]); L = atoi(argv[3]); fpx = fopen("ttx", "w"); fpy = fopen("tty", "w"); for (w1=0, n=0; n<L; n++) { x = s + gran(m, sigma, &iseed); y = (1 - a) * x + a * w1; w1 = y; fprintf(fpx, "%lf\n", x); fprintf(fpy, "%lf\n", y); sx2 += ((x-s)*(x-s) - sx2) / (n+1); sy2 += ((y-s)*(y-s) - sy2) / (n+1); } printf("theoretical 1/NRR = %lf\n", (1+a)/(1-a)); printf("experimental 1/NRR = %lf\n", sx2/sy2); } Problem 8.31 The requirement that the high-frequency signal s(−1) n go through unchanged is that the filter have unity gain at ω= π or z = −1. This requires the value for the constant b: b 1 −az −1 ¸ ¸ ¸ ¸ z=−1 = b 1 +a = 1 ⇒ b = 1 +a 177 Thus the filter transfer function and impulse response will be: H(z)= 1 +a 1 −az −1 , h(n)= (1 +a)a n u(n) The NRR is: NRR = ∞ _ n=0 h(n) 2 = (1 +a) 2 1 1 −a 2 = 1 +a 1 −a Thus, the NRR is magnified if 0 < a < 1. This can be understood in the frequency domain by the Fig. P8.16. π ω 0 1 input noise spectrum output noise spectrum 1+a 1- a ( ( 2 Fig. P8.16 Lowpass filter for extracting high-frequency signal. The magnitude response is normalized to unity at high frequencies, and therefore it must be larger at low frequencies because it is a lowpass filter. Indeed, its values at DC and AC are: ¦H(0)¦ 2 = _ 1 +a 1 −a _ 2 , ¦H(π)¦ 2 = 1 Problem 8.32 For an FIR filter of length N, its frequency response will be: H(ω)= N−1 _ n=0 h n e −jωn The condition that the gain is unity at AC is: H(π)= N−1 _ n=0 h n (−1) n = 1 where we used the fact e jπn = (−1) n . Thus, the NRR must be minimized subject to this AC condition: NRR = N−1 _ n=0 h 2 n = min, subject to N−1 _ n=0 h n (−1) n = 1 This can be solved by Lagrange multipliers or more simply by defining the quantities g n = h n (−1) n . Because g 2 n = h 2 n , the problem reduces to the following minimization problem: 178 NRR = N−1 _ n=0 g 2 n = min, subject to N−1 _ n=0 g n = 1 whose solution was found in Example 8.3.4 to be g n = 1/N, n = 0, 1, . . . , N−1. Thus, the solution of the highpass problem will be: h n = (−1) n g n = 1 N (−1) n , n = 0, 1, . . . , N−1 The Lagrange multiplier method is as follows. Introducing a Lagrange multiplier, say λ, that enforces the constraint, we modify the NRR to be minimized into the effective performance index: J = N−1 _ n=0 h 2 n +2λ _ 1 − N−1 _ n=0 h n (−1) n _ The minimization condition with respect to the unknowns h n are: ∂J ∂h n = 2h n −2λ(−1) n = 0, n = 0, 1, . . . , N−1 This gives h n = λ(−1) n , and the AC constraint then fixes λ to be: N−1 _ n=0 h n (−1) n = λ N−1 _ n=0 (−1) 2n = λN = 1 ⇒ λ = 1 N Problem 8.33 Expand the transfer function into partial fractions: H(z)= G (1 −pz −1 )(1 −p ∗ z −1 ) = A 1 −pz −1 + A ∗ 1 −p ∗ z −1 where A = G 1 −p ∗ /p = Gp p −p ∗ = − jGe jω0 2sinω 0 The corresponding impulse response and NRR will be then h n = Ap n +a ∗ p ∗n , n ≥ 0 NRR = ∞ _ n=0 h 2 n = ∞ _ n=0 _ A 2 p 2n +A ∗2 p ∗2n +2AA ∗ ¦p¦ 2n _ which sums up to NRR = A 2 1 −p 2 + A ∗2 1 −p ∗2 + 2¦A¦ 2 1 −¦p¦ 2 Inserting p = Re jω0 , and A as given above, and replacing G 2 by its normalized value G 2 = (1−R) 2 _ 1−2Rcos(2ω 0 )+R 2 _ gives the desired expression for NRR after some tedious algebra. 179 Problem 8.34 For the first filter, we find the transfer function: H(z)= 0.0730(1 −z −2 ) 1 −1.7633z −1 +0.8541z −2 Its pole radius is R = √ a 2 = √ 0.8541 = 0.9242, which gives the 5% time constant: n eff = ln(0.05) ln(R) = 38 Its NRR can be computed by carrying out a partial fraction expansion of the form: H(z)= B + A 1 −pz −1 + A ∗ 1 −p ∗ z −1 which gives the impulse response: h n = Bδ n +Ap n u n +A ∗ p ∗n u n from which we can calculate the NRR: NRR = ∞ _ n=0 h 2 n = B 2 + ∞ _ n=1 (Ap n +A ∗ p ∗n ) 2 = B 2 + ∞ _ n=1 _ A 2 p 2n +A ∗2 p ∗2n +2¦A¦ 2 ¦p¦ 2n _ = B 2 + A 2 p 2 1 −p 2 + A ∗2 p ∗2 1 −p ∗2 + 2¦A¦ 2 ¦p¦ 2 1 −¦p¦ 2 The parameters B and A are: B = − G ¦p¦ 2 , A = − G(1 −p 2 ) p 2 −¦p¦ 2 The numerical value of NRR is NRR = 1/13.4. For the second filter, we start with n eff from which we may solve for R = (0.05) 1/n eff = 0.9901 where R is related to the 3-dB width by: R 2 = a 2 = 2b −1 = 1 −tan(Δω/2) 1 +tan(Δω/2) which gives Δω= 0.0064π. Then, the design equations give: H(z)= 0.0099(1 −z −2 ) 1 −1.8833z −1 +0.9802z −2 and NRR = 1/101.1. The required graphs are shown in Figs. P8.17 and P8.18. Problem 8.35 For Q = 6, the transfer function is designed using Eqs. (8.2.22) and (8.2.23): H(z)= 0.96953 1 −1.85955z −1 +z −2 1 −1.80289z −1 +0.93906z −2 Its 1% time constant is n eff = 146. For Q = 60, the filter is identical to that of Example 8.3.8. Figures P8.19–P8.21 show the input signal, filter responses, and output signals. 180 Fig. P8.17 Magnitude responses and noisy input of Problem 8.34. Fig. P8.18 Filter outputs of Problem 8.34. Fig. P8.19 Noisy input and desired signal of Problem 8.35. Problem 8.36 The designed filter has the form: 181 Fig. P8.20 Magnitude responses, for Q = 6 and Q = 60. Problem 8.35. Fig. P8.21 Filter outputs, for Q = 6 and Q = 60. Problem 8.35. H(z)= b 1 −z −D 1 −az −D The time constant is computed as: n eff = D ln lna where = 0.01 for the 1% time constant. The filter parameters are in the four cases: Q a b n eff 80 0.961481 0.980741 1172.4 200 0.984414 0.992207 2931.6 400 0.992177 0.996088 5863.7 800 0.996081 0.998040 11727.8 The relevant graphs are shown in Figs. P8.22–P8.26. 182 Fig. P8.22 Desired signal and noisy input. Problem 8.36. Fig. P8.23 Filtered output y(n) when Q = 80. Problem 8.36. Fig. P8.24 Filtered s(n) for Q = 80 and Q = 200. Problem 8.36. Problem 8.37 The following MATLAB m-file designs the 60 Hz notch filter, generates the noisy ECG and filters it, and computes the filter’s magnitude response: 183 Fig. P8.25 Filtered s(n) for Q = 400 and Q = 800. Problem 8.36. Fig. P8.26 Magnitude responses for Q = 80 and Q = 800. Problem 8.36. % ecgex1.m - simulated ECG + 60Hz noise example % % assume 2 beats/sec => 0.5 sec/beat => 500 samples/beat => 1000 samples/sec % f0=60; Q=60; df=f0/Q; % % compute notch filter coefficients % generate length-500 ecg by calling x0=ecg(500); normalize it to 1. % replicate three beats x=[x0,x0,x0] and smooth them with x=sgfilt(0, 5, x); % add 80 percent 60-Hz noise % and filter it yv=filter(B,A,xv) % finally, compute filter’s magnitude response. f0 = 60/1000; Q = 60; df = f0/Q; w0 = 2 * pi * f0; dw = 2 * pi * df; b = 1 / (1+tan(dw/2)); B = b * [1, -2*cos(w0), 1]; A = [1, B(2), 2*b-1]; x0 = ecg(500); x = [x0, x0, x0]; x = sgfilt(0, 5, x); m = max(x); x = x/m; 184 n = 0:1499; xv = x + 0.5 * cos(w0 * n); yv = filter(B, A, xv); w = (0:499)*pi/500; z = exp(-i*w); h = abs((B(1) + B(2)*z + B(3)*z.^2) ./ (1 + A(2)*z + A(3)*z.^2)); Problem 8.38 The following MATLAB m-file designs the 60 Hz comb filter, generates the noisy ECG and filters it, and computes the filter’s magnitude response: % ecgex2.m - simulated ECG + 60Hz square-wave noise example % % assume 1 beats/sec => 1 sec/beat => 600 samples/beat => 600 samples/sec % % compute notch filter coefficients % generate length-600 ecg by calling x0=ecg(600); normalize it to 1. % replicate three beats x=[x0,x0,x0] and smooth them with x=sgfilt(0, 9, x); % add shifted square wave % and filter it yv=filter(B,A,xv) % finally, compute filter’s magnitude response. fs = 600; f0 = 60; df = 0.75; w0 = 2 * pi * f0 / fs; dw = 2 * pi * df / fs; beta = tan(dw * 10 / 4); % D=10 here a = (1 - beta) / (1 + beta); b = (1 + a) / 2; B = b * [1 0 0 0 0 0 0 0 0 0 -1]; % numerator A = [1 0 0 0 0 0 0 0 0 0 -a]; % denominator x0 = ecg(600); x = [x0, x0]; x = sgfilt(0, 9, x); m = max(x); x = x/m; n = 0:1199; v0 = [1 1 1 1 1 -1 -1 -1 -1 -1]; v = v0; % one noise period for k=1:119, % 120 noise periods v = [v, v0]; end v = 2 + v; % noise baseline shift xv = x + 0.5 * v; % noisy ECG yv = filter(B, A, xv); w = (0:500)*pi/500; z = exp(-i*w); h = abs(b * (1 - z.^10) ./ (1 - a * z.^10)); 185 Problem 8.39 Using partial fractions, we expand H(z)= b 1 +z −D 1 −az −D = A+ B 1 −az −D = (A+B)+Baz −D +Bz 2 z −2D +· · · where A = − b a , B = b _ 1 + 1 a _ , A+B = b Thus, the impulse response is h = [b, 0, 0, . . . , 0, Ba, 0, 0, . . . , 0, Ba 2 , 0, 0, . . . , 0, Ba 3 , . . . ] with the nonzero entries separated by D−1 zeros. The sum of the squares is NRR = ∞ _ n=0 h 2 n = b 2 +B 2 ∞ _ m=1 a 2m = b 2 +B 2 a 2 1 −a 2 = b 2 (1 −a 2 )+b 2 a 2 (1 +a −2 ) 1 −a 2 = 2b 2 (1 +a) 1 −a 2 = 2(1 −a) 2 (1 +a) 4(1 −a)(1 +a) = 1 −a 2 In the filter design parameter β = tan(ΔωD/4), the tangent has argument: ΔωD 4 = Δω 4 · 2π ω 1 = πΔω 2ω 1 = π 2Q where we used ω 1 = 2π/D, or D = 2π/ω 1 . Problem 8.40 The following program designs the comb filter, constructs 40 periods of length-50 of the noisy triangular waveform, and filters them using the circular buffer implementation of the canonical realization of the filter: /* combex.c - IIR comb filter with noisy periodic input */ #include <stdio.h> #include <stdlib.h> #include <math.h> double gran(), tap(); void cdelay(), triang(); void main(int argc, char **argv) { int n, i, N, D; long iseed; double a, b, pi=4*atan(1.0), dw = 0.0008 * pi; double *s, *w, *p; double x, y, sD; FILE *fpy, *fps, *fpx; if (argc != 4) { 186 puts("\nUsage: combex D N iseed"); exit(0); } D = atoi(argv[1]); period N = atoi(argv[2]); number of periods iseed = atol(argv[3]); initial seed fpy = fopen("y.dat", "w"); filter output fps = fopen("s.dat", "w"); noise-free input fpx = fopen("x.dat", "w"); noisy input a = (1 - tan(D*dw/4)) / (1 + tan(D*dw/4)); b = (1 - a) / 2; s = (double *) calloc(D, sizeof(double)); triang(D, s); one period of triangular wave w = (double *) calloc(D+1, sizeof(double)); p = w; for (i=0; i<N; i++) generate N periods for (n=0; n<D; n++) { x = s[n] + 0.5 * gran(0., 1., &iseed); sD = tap(D, w, p, D); *p = b * x + a * sD; y = (*p) + sD; cdelay(D, w, &p); fprintf(fps, "%lf\n", s[n]); fprintf(fpx, "%lf\n", x); fprintf(fpy, "%lf\n", y); } } /* -------------------------------------------------------- */ /* triang.c - triangular wave */ void triang(D, s) int D; double *s; { int i; double D4 = D/4.0; for (i = 0; i<D4; i++) s[i] = i / D4; for (i=D4; i<3*D4; i++) s[i] = 1 + (D4 - i) / D4; for (i=3*D4; i<D; i++) s[i] = -1 + (i - 3*D4) / D4; } 187 Problem 8.41 The complementarity properties may be verified for each pair. For example, for filter 2, we have half-order M = 8/2 = 4. Thus, we must verify: H LP (z)+H BP (z)= 1 16 (1 +z −2 ) 2 (−1 +6z −2 −z −4 )+ 1 16 (1 −z −2 ) 4 = z −4 which follows by expanding out the terms. Fig. P8.27 shows the frequency responses in the four cases. The frequency scale is in MHz and extends only up to about 4.5 MHz. For reference, the Nyquist frequency here is f s /2 = 2f sc = 7.159 MHz, so that the subcarrier frequency shown in the figure is only one-quarter of the Nyquist interval. Fig. P8.27 Lowpass/bandpass and highpass/bandstop responses. Problem 8.41. Problem 8.42 See Table P8.1. Note that the circular pointer p points to the buffer entry w[q], whereas the D-th tap output is the content of w[q D ]. At each time instant, the content of w[q] is updated by w[q]= w[q D ]+x, where the scaling by N is done afterwards. Table P8.1 shows the results. The advantage of the circular implementation is that only one entry of w, namely, w[q], is changed at each time instant. This is efficient in hardware implementations and for large values of D. Problem 8.43 The following is a complete Cprogramfor performing signal averaging. The inputs to the program are the period D and the number N of periods to be averaged. The input data are taken from stdin and the averaged period is output to the stdout: /* sigav.c - signal averaging */ #include <stdio.h> #include <stdlib.h> void cdelay(); double tap(); 188 void main(int argc, char **argv) { double x, *w, *p; int D, N, i, k; if (argc != 3) { fprintf(stderr, "usage: sigav D N < x.dat > y.dat\n"); fprintf(stderr, "x.dat must contain N periods of length D\n"); exit(0); } D = atoi(argv[1]); N = atoi(argv[2]); w = (double *) calloc(D+1, sizeof(double)); p = w; for (k=0; k<N; k++) for (i=0; i<D; i++) if (scanf("%lf", &x) != EOF) { /* keep reading input samples */ *p = tap(D, w, p, D) + x / N; cdelay(D, w, &p); } else { fprintf(stderr, "Input must have %d periods of length %d\n", N, D); exit(0); } for (i=0; i<D; i++) printf("%.12lf\n", tap(D, w, p, D-i)); } n x q D q w 0 w 1 w 2 w 3 y = w q /4 0 s 0 3 0 s 0 0 0 0 s 0 /4 1 s 1 2 3 s 0 0 0 s 1 s 1 /4 2 s 2 1 2 s 0 0 s 2 s 1 s 2 /4 3 s 0 0 1 s 0 2s 0 s 2 s 1 2s 0 /4 4 s 1 3 0 2s 1 2s 0 s 2 s 1 2s 1 /4 5 s 2 2 3 2s 1 2s 0 s 2 2s 2 2s 2 /4 6 s 0 1 2 2s 1 2s 0 3s 0 2s 2 3s 0 /4 7 s 1 0 1 2s 1 3s 1 3s 0 2s 2 3s 1 /4 8 s 2 3 0 3s 2 3s 1 3s 0 2s 2 3s 2 /4 9 s 0 2 3 3s 2 3s 1 3s 0 4s 0 s 0 10 s 1 1 2 3s 2 3s 1 4s 1 4s 0 s 1 11 s 2 0 1 3s 2 4s 2 4s 1 4s 0 s 2 12 − − − − 4s 2 4s 1 4s 0 − Table P8.1 Signal averager with circular delay for D = 3, N = 4. 189 Problem 8.44 The following program generates N periods of length D of the noisy signal, and averages these periods using the circular buffer form of the averager. After processing the ND input samples, it writes out the contents of the delay line in reverse order, so that the files y.dat and s.dat will contain the averaged periods and the noise-free period: /* sigavex.c - signal averaging example */ #include <stdio.h> #include <stdlib.h> #include <math.h> double gran(), tap(); void cdelay(); void main(int argc, char **argv) { int n, i, N, D; long iseed; double *s, x, *w, *p; double sD; FILE *fpx, *fpy, *fps; if (argc != 4) { puts("\nUsage: sigavex D N iseed"); exit(0); } D = atoi(argv[1]); period N = atoi(argv[2]); number of periods iseed = atol(argv[3]); noise seed fpx = fopen("x.dat", "w"); fpy = fopen("y.dat", "w"); fps = fopen("s.dat", "w"); s = (double *) calloc(D, sizeof(double)); for (i=0; i<D; i++) if (i < D/2) s[i] = 1; else s[i] = -1; w = (double *) calloc(D+1, sizeof(double)); p = w; for (i=0; i<N; i++) accumulate N periods for (n=0; n<D; n++) { each of length D x = s[n] + gran(0., 1., &iseed); noisy input sD = tap(D, w, p, D); D-th tap of averager *p = sD + x; accumulate x cdelay(D, w, &p); update delay line fprintf(fpx, "%.12lf\n", x); save input sample } for (n=0; n<D; n++) { write averaged period 190 fprintf(fps, "%lf\n", s[n]); fprintf(fpy, "%.12lf\n", tap(D, w, p, D-n)/N); } } Problem 8.45 The following MATLAB function generates the noisy ECG and smoothes it once and twice by Savitzky-Golay filter of length N and smoothing order d: % sgecgex.m - SG filtering of noisy ECG L=500; x0 = ecg(L)’; % generate ECG x = sgfilt(0, 15, x0); mx = max(x); x = x/mx; % unity max rand(’normal’); rand(’seed’, 10033); v = 0.3 * rand(L, 1); % generate noise xv = x + v; % generate noisy ECG N=11; d=2; y1 = sgfilt(d, N, xv); % first pass through SG y2 = sgfilt(d, N, y2); % second pass The filtering twice through the SG filter improves the smoothing operation but introduces longer transients in the filters. The following figures should be compared with the single-pass cases of Figs. 8.3.33 and 8.3.34. Fig. P8.28 Double SG filtering; N = 11, 41 and d = 0. 191 Fig. P8.29 Double SG filtering; N = 11, 41 and d = 2. Fig. P8.30 Double SG filtering; N = 11, 41 and d = 4. 192 Chapter 9 Problems Problem 9.1 Use the formula T R = LT = L/f s to solve for L = f s T R , or in words no. of samples = (no. of samples per second) x (no. of seconds) Thus, L = 8 kHz×128 msec = 1024 samples. The frequency spacing is Δf = f s /N = 8000/256 = 31.25 Hz. If the DFT is done directly, we would require L · N = 1024 · 256 = 262144 mul- tiplications. If the signal is reduced mod-256, then the number of multiplications would be N· N = 256 · 256 = 65536. And if the FFT is used, Nlog 2 N/2 = 256 · 8/2 = 1024. The cost of performing the mod-256 reduction is N(M − 1)= 256 · 3 = 768 additions, where M = L/N = 1024/256 = 4 is the number of segments. This cost may be added to the costs of FFT or reduced DFT. Problem 9.2 The sinusoidal signal is something like x(t)= cos(2πft), where f = 10 kHz. Its spectrum will have peaks at :f. Is there a DFT index k such that the kth DFT frequency f k equals :f? :f = f k = f s N k ⇒ k = :N f f s = :64 10 80 = :8 Thus, we expect to see a peak at k = 8 and another one at k = −8. Because the DFT X(k) is periodic in k with period N and because we always list the indices in the positive range k = 0, 1, · · · , N−1, we shift the negative index by one period N to get the positive index: −k →N−k = 64 −8 = 56 Thus, the second peak will be at k = 56. Problem 9.3 The number of samples in one period is given by: D = f s f = 40 5 = 8 samples Therefore, if k periods are collected , the total signal length will be N = kD = k f s f which gives for k = 16, N = 16 · 8 = 128 samples. If we perform an N-point DFT, then because of the choice of N, the k-th DFT frequency will coincide with f, that is, f k = k f s N = f Thus, we expect to see a peak at the kth DFT bin. We will also get a peak at the negative index −k, which translates mod-N to N−k. In summary, we expect to see peaks at the DFT indices: k = 16 and N−k = 128 −16 = 112 193 Problem 9.4 The expected DFT index will be at k = N f f s = 16 · 18 8 = 36 Because k is greater than N−1 = 15, it may be reduced mod-N down to: k = 36 −2 ×16 = 4 It corresponds to the DFT frequency f k = kf s /N = 4 · 8/16 = 2 kHz. This is frequency within the Nyquist interval that is aliased with f = 18 kHz; indeed, we have f alias = f modf s = 18mod8 = 18 −2 ×8 = 2 kHz The −2 kHz or −18 kHz component will be represented by the DFT index N−k = 16 −4 = 12. Problem 9.5 To be able to resolve a peak, the width of the main lobe of the data window must be equal or smaller than the width of the peak. This gives the condition f s L ≤ Δf ⇒ L ≥ f s Δf or, in our case, L ≥ 8000/20 = 400 samples. The duration of these 400 samples will be T R = LT ≥ L f s = 1 Δf = 1 20 = 50 msec To avoid wrap-around errors in the inverse FFT, the FFT length must be at least L, i.e., N ≥ L = 400. The next power of two is N = 512. We must pad 112 zeros to the end of the length-400 signal before the FFT is taken. Problem 9.6 The following MATLAB function generates the time data and computes the required DTFTs with the help of the function dtft.m, included below, which replaces the C functions dtft.c and dtftr.c: % dtftexp.m - rectangular/hamming windowed sinsuoids L = 200; N = 200; w0 = 0.1*pi; w = (0:N-1) * 0.2 * pi / N; % frequency range n = 0:(L-1); wh = 0.54 - 0.46 * cos(2*pi*n/(L-1)); % Hamming window xrec = cos(w0 * n); xham = wh .* xrec; % windowed data Xrec = abs(dtft(xrec, w)); % DTFT of rectangular data Xham = abs(dtft(xham, w)); % DTFT of Hamming data save xrec.dat xrec /ascii; save xham.dat xham /ascii; save frec.dat Xrec /ascii; save fham.dat Xham /ascii; 194 where % dtft.m - DTFT of a signal at a frequency vector w % % X = dtft(x, w); % % x = row vector of time samples % w = row vector of frequencies in rads/sample % X = row vector of DTFT values % % based on and replaces both dtft.c and dtftr.c function X = dtft(x, w) [L1, L] = size(x); z = exp(-j*w); X = 0; for n = L-1:-1:0, X = x(n+1) + z .* X; end Problem 9.7 The following MATLAB function generates the time data and computes the required DTFTs: % sinexp.m - 3 sinusoids of length L=10 L=10; N=256; f1 = 0.2; f2 = 0.25; f3 = 0.3; n = 0:(L-1); x = cos(2*pi*f1*n) + cos(2*pi*f2*n) + cos(2*pi*f3*n); w = 0.54 - 0.46 * cos(2*pi*n/(L-1)); xham = w.*x; X = abs(fft(x,N)); Xham = abs(fft(xham,N)); For the other cases, use L = 10, 40, 100. Problem 9.8 The following C program generates the length-L time signal and computes its N-point DFT, with L = 10, 20, 100 and N = 256. Instead of the DFT routine dft.c, one could use fft.c. The 32-point DFT is extracted by keeping one out of every 256/32 = 8 points of the 256-point DFT. /* dtftex.c - physical vs. computational resolution example */ #include <stdio.h> #include <cmplx.h> #include <stdlib.h> void dtftr(); 195 main() { int L, N, n, k; double *x, pi = 4 * atan(1.0); double f1 = 0.20, f2 = 0.25, f3 = 0.30; complex *X; FILE *fpdtft; fpdtft= fopen("dtft.dat", "w"); DTFT file printf("enter L, N: "); scanf("%d %d", &L, &N); x = (double *) calloc(L, sizeof(double)); X = (complex *) calloc(N, sizeof(complex)); for (n=0; n<L; n++) x[n] = cos(2*pi*f1*n) + cos(2*pi*f2*n) + cos(2*pi*f3*n); dft(L, x, N, X); N-point DFT for (k=0; k<N; k++) fprintf(fpdtft, "%lf\n", cabs(X[k])); } Problem 9.9 See Example 9.2.1. Problem 9.10 Using the relationship k = Nf/fs, we calculate the group-A and group-B DFT indices: group A k A = 22.3, 24.6, 27.3, 30.1 group B k B = 38.7, 42.8, 47.3 and their rounded versions: group A: k A = 22, 25, 27, 30 group B: k B = 39, 43, 47 Because each keypress generates one tone from group A and one from group B, the DTFT will have peaks at the corresponding pair of DFT indices (and their negatives, that is, N − k A and N−k B .) Problem 9.11 The time signal and its DTFT are shown in Figs. P9.1 and P9.2, both for the rectangular and Hamming windows. 196 Fig. P9.1 Rectangularly and Hamming windowed DTMF sinusoids. Fig. P9.2 Spectra of DTMF sinusoids. Problem 9.12 Acting on x by the 4×8 DFT matrix, we obtain: X = ⎡ ⎢ ⎢ ⎢ ⎣ X(0) X(1) X(2) X(3) ⎤ ⎥ ⎥ ⎥ ⎦ = ⎡ ⎢ ⎢ ⎢ ⎣ 1 1 1 1 1 1 1 1 1 −j −1 j 1 −j −1 j 1 −1 1 −1 1 −1 1 −1 1 j −1 −j 1 j −1 −j ⎤ ⎥ ⎥ ⎥ ⎦ ⎡ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎣ 1 2 2 1 2 1 1 2 ⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎦ = ⎡ ⎢ ⎢ ⎢ ⎣ 12 0 0 0 ⎤ ⎥ ⎥ ⎥ ⎦ The mod-4 wrapped version of x is ˜ x = [3, 3, 3, 3]. Its 4-point DFT is X = ⎡ ⎢ ⎢ ⎢ ⎣ X(0) X(1) X(2) X(3) ⎤ ⎥ ⎥ ⎥ ⎦ = ⎡ ⎢ ⎢ ⎢ ⎣ 1 1 1 1 1 −j −1 j 1 −1 1 −1 1 j −1 −j ⎤ ⎥ ⎥ ⎥ ⎦ ⎡ ⎢ ⎢ ⎢ ⎣ 3 3 3 3 ⎤ ⎥ ⎥ ⎥ ⎦ = ⎡ ⎢ ⎢ ⎢ ⎣ 12 0 0 0 ⎤ ⎥ ⎥ ⎥ ⎦ For the IDFT we use the formula IDFT(X)= [DFT(X ∗ )] ∗ /N: 197 ` x = ⎡ ⎢ ⎢ ⎢ ⎣ ` x(0) ` x(1) ` x(2) ` x(3) ⎤ ⎥ ⎥ ⎥ ⎦ = 1 4 ⎡ ⎢ ⎢ ⎢ ⎣ 1 1 1 1 1 −j −1 j 1 −1 1 −1 1 j −1 −j ⎤ ⎥ ⎥ ⎥ ⎦ ⎡ ⎢ ⎢ ⎢ ⎣ 12 0 0 0 ⎤ ⎥ ⎥ ⎥ ⎦ = ⎡ ⎢ ⎢ ⎢ ⎣ 3 3 3 3 ⎤ ⎥ ⎥ ⎥ ⎦ Problem 9.13 The 8-point FFT is: x = ⎡ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎣ 5 −1 −3 −1 5 −1 −3 −1 ⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎦ 8−FFT −→ X = ⎡ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎣ 0 0 16 0 8 0 16 0 ⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎦ It follows that the FFT spectrum will show peaks at the frequencies: X(ω 2 )= X(ω 6 ) ∗ = X(−ω 2 ) ∗ = 16, X(ω 4 )= 8 Problem 9.14 The IFFT is obtained by conjugating X, computing its FFT, and dividing by 8. The required FFT of X ∗ is: X ∗ = ⎡ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎣ 0 4 4j 4 0 4 −4j 4 ⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎦ 8−FFT −→ ⎡ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎣ 16 8 0 −8 −16 8 0 −8 ⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎦ ⇒ x = ⎡ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎣ 2 1 0 −1 −2 1 0 −1 ⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎦ Using the inverse DFT formula, we express x(n) as a sum of sinusoids: x(n) = 1 8 7 _ k=0 X(k)e jω k n = 1 8 _ 4e jω1n −4je jω2n +4e jω3n +4e jω5n +4je jω6n +4e jω7n _ = 1 2 e jω1n + 1 2j e jω2n + 1 2 e jω3n + 1 2 e −jω3n − 1 2j e −jω2n + 1 2 e −jω1n = cos(ω 1 n)+sin(ω 2 n)+cos(ω 3 n)= cos(πn/4)+sin(πn/2)+cos(3πn/4) which agrees with the above IFFT values at n = 0, 1, . . . , 7. We used the values of the DFT fre- quencies: ω 1 = 2π 8 = π 4 , ω 2 = 2π2 8 = π 2 , ω 3 = 2π3 8 = 3π 4 The DFT frequencies ω 7 , ω 6 , ω 5 are the negatives (modulo-2π) of ω 1 , ω 2 , ω 3 , respectively. 198 Problem 9.15 Figure P9.3 shows the procedure. The (4N)-dimensional time data vector is shuffled once into two (2N)-dimensional subvectors by putting every other one of its entries on top and the remain- ing entries on the bottom. Then, each of the (2N)-dimensional vectors is shuffled again into two N-dimensional subvectors. shuffling N-FFT N-FFT N-FFT N-FFT DFT merging 4N 4N 2N 2N 2N 2N N N N N N N N N W 2N k W 2N k W 4N k Fig. P9.3 Performing large FFTs. The four N-dimensional vectors are then shipped over to the FFT processor, one at a time, and their FFTs are returned into four N-dimensional DFT vectors. These are then merged first into (2N)-point DFTs and then into the desired (4N)-point DFT. The first merging stage require mul- tiplication by the twiddle factors W k 2N , k = 0, 1, . . . , N − 1. The second stage uses the factors W k 4N , k = 0, 1, . . . , 2N − 1. The butterfly operations can be done is small parts, for example, in groups of N operations at a time so that they can be implemented by the DSP hardware. The total cost is the cost of four N-point FFTs, the cost of two N-fold multiplications for the first merging stage, and a (4N)-fold multiplication for the second stage: cost = 4 1 2 Nlog 2 N+2N+2N = 2Nlog 2 N+4N If the (4N)-point FFT could be done in one pass, we would have cost: cost = 1 2 (4N)log 2 (4N)= 2Nlog 2 (4N) It is easily verified that the costs of the two methods are the same. The indirect method is of course much slower because of all the I/O time for shipping data back and forth from secondary storage to the FFT processor. Problem 9.16 The ordinary convolution is y = h ∗x = [1, 3, 4, 6, 7, 6, 4, 3, 1] 199 Reducing this mod-4 gives: ˜ y = [9, 9, 8, 9]. The alternative method is to reduce first x and h mod-4: ˜ h = [2, 2, 1, 2], ˜ x = [2, 1, 1, 1], then, compute their ordinary convolution: ˜ h ∗˜ x = [4, 6, 6, 9, 5, 3, 2], and, finally, reduce that modulo 4 to get ˜ y = [9, 9, 8, 9]. Problem 9.17 Carrying out the 8-point FFT gives: x = ⎡ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎣ 4 2 4 −6 4 2 4 −6 ⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎦ 8−FFT −→ X = ⎡ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎣ 8 0 −16j 0 24 0 16j 0 ⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎦ Taking every other entry of the result gives the 4-point FFT, namely, X = ⎡ ⎢ ⎢ ⎢ ⎣ 8 −16j 24 16j ⎤ ⎥ ⎥ ⎥ ⎦ And, taking every other entry of that gives the 2-point FFT: X = _ 8 24 _ Can we get these results directly? Yes. To do the 4-point FFT, first reduce the signal modulo 4 to get ˜ x = ⎡ ⎢ ⎢ ⎢ ⎣ 8 4 8 −12 ⎤ ⎥ ⎥ ⎥ ⎦ 4−FFT −→ X = ⎡ ⎢ ⎢ ⎢ ⎣ 8 −16j 24 16j ⎤ ⎥ ⎥ ⎥ ⎦ Putting the above 8-point FFT into the 8-point inverse FFT formula gives x(n)= 1 8 7 _ k=0 X(k)e jω k n = 1 8 _ 8e jω0n −16je jω2n +24e jω4n +16je jω6n _ Noting that for an 8-point FFT, ω 0 = 0, ω 2 = π/2, ω 4 = π, and ω 6 = 3π/2 ≡ −π/2, and using Euler’s formula we obtain: x(n)= 1 +4sin( πn 2 )+3cos(πn) which agrees with the given x, for n = 0, 1, · · · , 7. 200 Problem 9.18 Consider the length-7 signal [1 −a, 2 −b, 3, 4, 5, a, b] It should be evident that, for any values of the parameters a and b, its mod-5 reduction is [1, 2, 3, 4, 5]. Problem 9.19 Using the finite geometric series and the definition W N = e −2πj/N , gives 1 N N−1 _ n=0 W kn N = 1 N 1 −W Nk N 1 −W k N = 1 N 1 −e −2πjk 1 −e −2πjk/N If k }= 0, the numerator vanishes but not the denominator. Thus, in this case the answer is zero. If k = 0, we have a ratio of 0/0, but in this case, we can just go back to the series definition and set k = 0. All of the N terms in the sum become unity, giving N/N = 1. In conclusion, the answer is zero if k }= 0, and unity if k = 0. Note, that these arguments break down if k is allowed to go beyond the range 0 ≤ k ≤ N−1, because whenever it is a multiple of N, we would get unity as an answer (and zero otherwise). Problem 9.20 For a general power p, we have: W p pN = _ e −2πj/(pN) _ p = e −2πj/N = W N The DTFT of a length-L signal and its N-point and (pN)-point DFTs are: X(ω)= L−1 _ n=0 x(n)e −jωn X N (k)= L−1 _ n=0 x(n)W kn N X pN (k)= L−1 _ n=0 x(n)W kn pN Replacing k by pk in the third and using part (a), we have: X pN (pk)= L−1 _ n=0 x(n)W pkn pN = L−1 _ n=0 x(n)W kn N = X N (k) Problem 9.21 This follows from the results of Problem 9.20 by setting N = 8 and p = 2, which implies: X 8 (k)= X 16 (2k), k = 0, 1, . . . , 15 A geometrical way to understand this is to recognize that the 8th roots of unity are a subset of the 16th roots of unity and are obtained by taking every other one of the latter. 201 Problem 9.22 Using a trig identity to write the product of sines as a sum of sines, we get the equivalent expres- sion: x(t)= cos(24πt)+2sin(12πt)cos(8πt)= cos(24πt)+sin(20πt)+sin(4πt) The frequencies of the three terms are 12, 10, and 2 kHz. Their aliased versions that lie inside the Nyquist interval [−4, 4] kHz are, respectively, 4, 2, and 2 kHz. Thus, the aliased signal that would be reconstructed by an ideal reconstructor will be: x(t)= cos(8πt)+sin(4πt)+sin(4πt)= cos(8πt)+2sin(4πt) Setting t = nT = n/8, we get the time samples: x(n)= cos(πn)+2sin(πn/2) Evaluating it at n = 0, 1, . . . , 7 gives the values, and their FFT: x = [1, 1, 1, −3, 1, 1, 1, −3] 8−FFT −→ X = [0, 0, −8j, 0, 8, 0, 8j, 0] The same DFT values can be determined without any computation by comparing x(n) with the inverse DFT. Using Euler’s formula, setting ω 4 = π, ω 2 = π/2, ω 6 = −(π/2)mod(2π), and multiplying and dividing by 8, we get: x(n)= e jπn −je jπn/2 +je −jπn/2 = 1 8 _ −8je jω2n +8e jω4n +8je jω6n _ Comparing with the 8-point IDFT, gives the above DFT vector: x(n)= 1 8 7 _ k=0 X(k)e jω k n Problem 9.23 Using Euler’s formula, we write: x(n) = 1 +2sin( πn 4 )−2sin( πn 2 )+2sin( 3πn 4 )+3(−1) n = 1 −je jπn/4 +je −jπn/4 +je jπn/2 −je −jπn/2 −je j3πn/4 +je −j3πn/4 +3e jπn = 1 8 _ 8e jω0n −8je jω1n +8je jω2n −8je jω3n +24e jω4n +8je jω5n −8je jω6n +8je jω7n _ where we reordered the terms according to increasing DFT index. Comparing with the IDFT formula, we get: X = [8, −8j, 8j, −8j, 24, 8j, −8j, 8j] 202 Problem 9.24 Using Euler’s formula, we write x(n) = 0.5e πjn/2 +0.5e −πjn/2 +e πjn/8 +e −πjn/8 = 1 16 _ 8e πjn/2 +8e 3πjn/2 +16e πjn/8 +16e 15πjn/8 _ where, we shifted the negative frequency exponents by adding 2πn to them, e.g., replaced −πn/8 by 2πn −πn/8 = 15πn/8. Now, comparing with the 16-point IDFT formula x(n)= 1 16 15 _ k=0 X(k)e jω k n and noting that π/2 = 8π/16 = ω 4 , 3π/2 = 24π/16 = ω 12 , π/8 = 2π/16 = ω 1 , and 15π/8 = 30π/16 = ω 15 , we may identify the (non-zero) values of X(k) as follows: X(1)= 16, X(4)= 8, X(12)= 8, X(15)= 16, or, X = [0, 16, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 16] Problem 9.25 Arguing in a similar fashion, we find the (non-zero) values of the 32-point DFT: X(2)= 32, X(8)= 16, X(24)= 16, X(30)= 32 Problem 9.26 Write x(n) in its complex sinusoidal form: x(n)= 0.5e jω0n −je jω4n +jω jω12n +1.5e jω8n (P9.1) where ω 0 = 0, ω 4 = 2π4/16 = π/2, ω 12 = −ω 4 mod(2π), ω 8 = 2π8/16 = π are the signal frequencies expressed as 16-point DFT frequencies. The DTFT of each complex sinusoid is given by the shifted spectrum of the rectangular window W(ω) of length-16: X(ω)= 0.5W(ω)−jW(ω−ω 4 )+jW(ω−ω 12 )+1.5W(ω−ω 8 ) where W(ω)= 1 −e −16jω 1 −e −jω = sin(8ω) sin(ω/2) e −15jω/2 The magnitude spectrum ¦X(ω)¦ is plotted versus 0 ≤ ω≤ 2π in Fig. P9.4. The spectral peaks at the signal frequencies are evident. Dividing the Nyquist interval into 16 equal bins, gives the 16-point DFT. It so happens that the zeros of the sidelobes of the W(ω−ω i ) coincide with 16-point DFT fre- quencies. Taking every other 16-DFT point gives the 8-point DFT. The peak values are correctly identified by the 16- and 8-point DFTs because the peak frequencies coincide with DFT frequen- cies. 203 ω π 0 2π |X(ω)| = DTFT = 16-point DFT = 8-point DFT 24 16 8 Fig. P9.4 DTFT, 16-point and 8-point DFTs. The 16-point DFT can be determined from the expression of x(n) by comparing it with 16-point IDFT formula. Multiplying and dividing Eq. (P9.1) by 16, we may extract the DFT coefficients: X = [8, 0, 0, 0, −16j, 0, 0, 0, 24, 0, 0, 0, 16j, 0, 0, 0] Every other entry is the 8-point DFT: X = [8, 0, −16j, 0, 24, 0, 16j, 0] Problem 9.27 We will showthat the product AA ∗ is proportional to the identity matrix. The ij-th matrix element of the product is: (AA ∗ ) ij = N−1 _ n=0 A in A ∗ nj = N−1 _ n=0 W in N W −jn N = N−1 _ n=0 W (i−j)n N where we used the fact that W ∗ N = W −1 N . Using the results of Problem 9.19, we note that the above sum will be zero if i }= j. And, it will be equal to N if i = j. Thus, we can write compactly: (AA ∗ ) ij = N−1 _ n=0 W (i−j)n N = Nδ(i −j) which is equivalent to the matrix relationship AA ∗ = NI where I is the N×N identity matrix. Problem 9.28 Vectorially, the desired equation reads x † x = 1 N X † X where † denotes conjugate transpose. Using X = Ax and the property AA † = A † A = NI N , (I N = N×N identity matrix) of the N×N DFT matrix, we obtain X † X = x † A † Ax = x † NI N x = Nx † x 204 Problem 9.29 First, compute the ordinary linear convolution: y = h ∗x = [2, −1, −2, 2, −2, −1, 2] The mod-4 reduction of this is ` y = [0, −2, 0, 2]. The mod-5 reduction is ` y = [1, 1, −2, 2, −2], the mod-6 reduction is ` y = [4, −1, −2, 2, −2, −1]. Finally, the mod-7 and mod-8 reductions of y leave it unchanged. One minor detail is that in the mod-8 case, the length should be N = 8, thus, strictly speaking ` yis ywith one zero padded at the end, that is, ` y = [2, −1, −2, 2, −2, −1, 2, 0]. The minimal N is N = L y = L x +L h −1 = 4 +4 −1 = 7. Problem 9.30 First, compute the linear convolution of the given signals: y = h ∗x = [2, 1, 1, 1, 2, 1, 1, 1]∗[2, 1, 2, −3, 2, 1, 2, −3] = [4, 4, 7, −1, 8, 7, 11, −2, 4, 2, 1, −1, 0, −1, −3] and wrap it mod-8 to get ˜ y = [8, 6, 8, −2, 8, 6, 8, −2] Then, compute the FFTs of the two signals: ⎡ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎣ 2 1 1 1 2 1 1 1 ⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎦ 8−FFT −→ ⎡ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎣ 10 0 2 0 2 0 2 0 ⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎦ , ⎡ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎣ 2 1 2 −3 2 1 2 −3 ⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎦ 8−FFT −→ ⎡ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎣ 4 0 −8j 0 12 0 8j 0 ⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎦ Multiply them point-wise: ⎡ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎣ 10 0 2 0 2 0 2 0 ⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎦ × ⎡ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎣ 4 0 −8j 0 12 0 8j 0 ⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎦ = ⎡ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎣ 40 0 −16j 0 24 0 16j 0 ⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎦ Divide by N = 8, conjugate every entry, and take an 8-point FFT: ⎡ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎣ 5 0 2j 0 3 0 −2j 0 ⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎦ 8−FFT −→ ⎡ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎣ 8 6 8 −2 8 6 8 −2 ⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎦ 205 Problem 9.31 a. The 8-FFT algorithm gives x = [6, 1, 0, 1, 6, 1, 0, 1] ⇒ X = [16, 0, 12, 0, 8, 0, 12, 0] b. Using x(n)= 1 N N−1 _ k=0 X(k)e jω k n , x(n)= 1 8 _ 16 +12e jπn/2 +8e jπn +12e −jπn/2 _ = 2 +3cos _πn 2 _ +(−1) n c. With arbitrary values of a and b: x = [6 −a, 1, 0, 1, 6, 1, 0, 1, a], x = [6 −a, 1 −b, 0, 1, 6, 1, 0, 1, a, b] d. Reduce x mod-4 to get ˜ x = [12, 2, 0, 2]. Its 4-FFT is easily found to be X = [16, 12, 8, 12]. It can also be obtained by picking every other entry of the 8-point DFT. Problem 9.32 Start with A(k)= N−1 _ n=0 W kn N a(n) and evaluate it at N−k A(N−k)= N−1 _ n=0 W (N−k)n N a(n) Noting that W N N = 1, it can be written as A(N−k)= N−1 _ n=0 W −kn N a(n) On the other hand, because a(n) is real A(k) ∗ = N−1 _ n=0 _ W kn N _ ∗ a(n) But, _ W kn N _ ∗ = W −kn N Thus, A(N−k)= A(k) ∗ 206 Problem 9.33 Using linearity, we have X(k)= A(k)+jB(k) ⇒ X(N−k) ∗ = A(N−k) ∗ −jB(N−k) ∗ Using the results of Problem 9.32, A(N−k) ∗ = A(k) and B(N−k) ∗ = B(k), we obtain X(N− k) ∗ = A(k)−jB(k). Thus, we have the system of equations: X(k) = A(k)+jB(k) X(N−k) ∗ = A(k)−jB(k) which can be solved for A(k) and B(k). Problem 9.34 The expressions for G(k) and H(k) follow from the results of Problem 9.33, except that the di- mension of the FFTs is N/2. The final expressions that construct X(k) are the standard Butterfly operations for merging G(k) and H(k). The additional multiplications to build X(k) from Y(k) are 3N/2, (that is, the divisions by 2 and 2j, and multiplications by W k N ). Thus the total number of multiplications using this method compared to a direct N-point FFT will be 1 2 N 2 log 2 ( N 2 )+ 3N 2 1 2 Nlog 2 N = 1 2 + 2.5 log 2 N If one takes into account the multiplications required for computing the W k powers, then the total becomes N 2 log 2 ( N 2 )+ 4N 2 Nlog 2 N = 1 2 + 1.5 log 2 N Typically, 65% of the standard cost for N = 1024. Problem 9.35 /* fftreal.c - FFT of a real-valued signal */ #include <math.h> #include <cmplx.h> #include <stdlib.h> void fft(); void fftreal(N, x, X) int N; double *x; time data complex *X; FFT array { int n, k, Nhalf=N/2; double pi=4*atan(1.0); 207 complex one, half, halfj, W; complex *Y, temp, Wk, Gk, Hk; one = cmplx(1.0, 0.0); half = cmplx(0.5, 0.0); halfj = cmplx(0.0, -0.5); W = cexp(cmplx(0.0, -2*pi/N)); Y = (complex *) calloc(Nhalf, sizeof(complex)); for (n=0; n<Nhalf; n++) Y[n] = cmplx(x[2*n], x[2*n+1]); fft(Nhalf, Y); for (Wk=one, k=0; k<Nhalf; k++) { Wk = W k if (k==0) temp = conjg(Y[0]); note: Y(0) = Y(N/2) else temp = conjg(Y[Nhalf-k]); Gk = cmul(half, cadd(Y[k], temp)); G(k) Hk = cmul(halfj, csub(Y[k], temp)); H(k) temp = cmul(Wk, Hk); W k H(k) Wk = cmul(W, Wk); next Wk = W k+1 X[k] = cadd(Gk, temp); G(k) + W k H(k) X[k+Nhalf] = csub(Gk, temp); G(k) − W k H(k) } } Problem 9.36 An example will demonstrate the result. For N = 4, we have: x = [x 0 , x 1 , x 2 , x 3 ] ⇒ X(z)= x 0 +x 1 z −1 +x 2 z −2 +x 3 z −3 x R = [x 3 , x 2 , x 1 , x 0 ] ⇒ X R (z)= x 3 +x 2 z −1 +x 1 z −2 +x 0 z −3 It follows that X R (z)= z −3 [x 3 z 3 +x 2 z 2 +x 1 z +x 0 ]= z −3 X(z −1 ) In the time domain, the operation of reflection leads to the z-transform pairs: x(n) Z −→X(z) ⇒ x(−n) Z −→X(z −1 ) The operation of delay on the reflected signal then gives: x R (n)= x(N−1 −n)= x(−(n −N+1)) Z −→z −(N−1) X(z −1 ) The N-point DFT of the reversed signal is obtained by setting z = z k = e 2πjk/N = W −k N . Using the property W N N = 1, we find: X R (k)= z −N+1 k X(z −1 k )= W (N−1)k N X(−k)= W −k N X(N−k) where in the last step, we used X(z −1 k )= X(−ω k )= X(−k)= X(N−k) by the periodicity of the N-point DFT. 208 Problem 9.37 In the definition of y, the reversed signal x R is delayed by N samples, that is, we have x = [x, x R ]= [x, 0, 0, . . . , 0 . ¸, . N zeros ]+[0, 0, . . . , 0 . ¸, . N zeros , x R ] Thus, using linear superposition, the delay property of z-transforms, and the results of Problem 9.36, we have in the z-domain: Y(z)= X(z)+z −N X R (z)= X(z)+z −2N+1 X(z −1 ) where the factor z −N represents the delay of x R by N samples. Replacing z by z k = e jω k , and using the result z 2N k = 1, we get Y k = Y(ω k )= X(ω k )+e jω k X(−ω k )= e jω k /2 _ e −jω k /2 X(ω k )+e jω k /2 X(−ω k ) _ = 2e jω k /2 Re _ e −jω k /2 X(ω k ) _ where we used the hermitian property X(−ω)= X(ω) ∗ . The quantity under the real part is now: e −jω k /2 X(ω k )= e −jω k /2 N−1 _ n=0 x n e −jω k n = N−1 _ n=0 x n e −jω k (n+1/2) Thus, its real part is the cosine transform: Re _ e −jω k /2 X(ω k ) _ = N−1 _ n=0 x n cos _ ω k (n +1/2) _ = C k It follows that Y k = 2e jω k /2 C k = 2e jπk/2N C k Because Y k is the (2N)-point DFT of a real-valued signal, it will satisfy the hermitian property Y 2N−k = Y ∗ k . In terms of C k , we have: Y 2N−k = 2e jπ(2N−k)/2N C 2N−k = 2e jπ e −jπk/2N C 2N−k = −2e −jπk/2N C 2N−k Y ∗ k = 2e −jπk/2N C k Equating the right-hand sides and canceling the common factors gives the symmetry property C 2N−k = −C k , k = 0, 1, . . . , 2N−1 At k = N, it gives C 2N−N = −C N or C N = −C N which implies C N = 0. Next, considering the inverse DFT for Y k , we have: y n = 1 2N 2N−1 _ k=0 Y k e jω k n , n = 0, 1, . . . , 2N−1 But the first N samples of y n are precisely x n . Replacing Y k in terms of C k gives for n = 0, 1, . . . , N−1: x n = 1 2N 2N−1 _ k=0 2e jω k /2 C k e jω k n = 1 N 2N−1 _ k=0 C k e jω k (n+1/2) 209 Next, we split the summation into three terms: x n = 1 N _ C 0 + N−1 _ k=1 C k e jω k (n+1/2) + 2N−1 _ k=N+1 C k e jω k (n+1/2) _ where the second summation starts at k = N+1 because C N = 0. If we change variables from k to m= 2N−k, we can write 2N−1 _ k=N+1 C k e jω k (n+1/2) = N−1 _ m=1 C 2N−m e jω 2N−m (n+1/2) Using the symmetry property C 2N−m = −C m , and the trig identity e jω 2N−m (n+1/2) = e jπ(2N−m)(n+1/2)/N = e 2jπ(n+1/2) e −jπm(n+1/2)/N = −e −jωm(n+1/2) we have (with the two minus signs canceling): N−1 _ m=1 C 2N−m e jω 2N−m (n+1/2) = N−1 _ m=1 C m e −jωm(n+1/2) Thus, the inverse DFT becomes (changing the summation from m back to k): x n = 1 N _ C 0 + N−1 _ k=1 C k e jω k (n+1/2) + N−1 _ k=1 C k e −jω k (n+1/2) _ The two summations now combine with Euler’s formula to give: x n = 1 N _ C 0 +2 N−1 _ k=1 C k cos _ ω k (n +1/2) __ Problem 9.38 By definition, we have X 2N (k)= L−1 _ n=0 x(n)W nk 2N ⇒ X 2N (2k)= L−1 _ n=0 x(n)W 2nk 2N But, W 2nk 2N = exp _ −2πj2nk/2N _ = exp _ −2πjnk/N _ = W nk N . Thus, X 2N (2k)= L−1 _ n=0 x(n)W 2nk 2N = L−1 _ n=0 x(n)W nk N = X N (k) Problem 9.39 Observe that the five length-5 sequences are the mod-5 wrapped versions of the following “linearly shifted” sequences: x 0 x 1 x 2 x 3 x 4 0 0 0 0 0 0 x 0 x 1 x 2 x 3 x 4 0 0 0 0 0 0 x 0 x 1 x 2 x 3 x 4 0 0 0 0 0 0 x 0 x 1 x 2 x 3 x 4 0 0 0 0 0 0 x 0 x 1 x 2 x 3 x 4 0 210 Their z-transforms differ by a simple delay factor, that is, X i (z)= z −i X 0 (z), i = 1, 2, 3, 4 Setting z = z k = e jω k = W −k 5 , we obtain X i (z k )= z −i k X 0 (z k )= W ik 5 X 0 (z k ), i = 1, 2, 3, 4 Problem 9.40 Consider, for example, the first and the third. Their z-transforms are X 1 (z) = x 0 +x 1 z −1 +x 2 z −2 +x 3 z −3 +x 4 z −4 +x 5 z −5 +x 6 z −6 +x 7 z −7 X 3 (z) = x 0 +x 1 z −1 +(x 2 +x 6 )z −2 +(x 3 +x 7 )z −3 +x 4 z −4 +x 5 z −5 Subtracting, we have X 3 (z)−X 1 (z)= x 6 z −2 (1 −z −4 )+x 7 z −3 (1 −z −4 )= (x 6 z −2 +x 7 z −3 )(1 −z −4 ) Evaluating at the 4th roots of unity, z = z k = e 2πjk/4 , we obtain X 3 (z k )−X 1 (z k )= 0, k = 0, 1, 2, 3 Problem 9.41 Using the convolution table, perform the ordinary linear convolution of the given signal and filter to get y = h ∗x = [1, 0, −1, 0, 2, 0, −2, 0, −2, 0, 2, 1, 0, −1, 0, −1, 0, 1, 0, −1, 0, 1] The overlap-save method divides the input signal into segments of length N = 8 that are over- lapping by M = 3 points, as shown below: x = _ 1, 1, 1, 1, 3, (3, 3, 3 _ , 1, 1, _ 1, 2, 2), 2, 2, (1, 1, 1 _ , 1, 0, 0, 0, 0) Convolving these segments with the filter gives: y 0 = [1, −1, −1, 1]∗[1, 1, 1, 1, 3, 3, 3, 3] = [1, 0, −1, 0, 2, 0, −2, 0, −3, 0, 3] y 1 = [1, −1, −1, 1]∗[3, 3, 3, 1, 1, 1, 2, 2] = [3, 0, −3, −2, 0, 2, 1, 0, −3, 0, 2] y 2 = [1, −1, −1, 1]∗[1, 2, 2, 2, 2, 1, 1, 1] = [1, 1, −1, −1, 0, −1, 0, 1, −1, 0, 1] y 3 = [1, −1, −1, 1]∗[1, 1, 1, 1, 0, 0, 0, 0] = [1, 0, −1, 0, −1, 0, 1, 0, 0, 0, 0] Reducing these mod-8 and ignoring their first M = 3 points (indicated by x), we obtain: ˜ y 0 = [x, x, x, 0, 2, 0, −2, 0] ˜ y 1 = [x, x, x, −2, 0, 2, 1, 0] ˜ y 2 = [x, x, x, −1, 0, −1, 0, 1] ˜ y 3 = [x, x, x, 0, −1, 0, 1, 0] Abutting the rest of the points, we get y = [x, x, x, 0, 2, 0, −2, 0][−2, 0, 2, 1, 0][−1, 0, −1, 0, 1][0, −1, 0, 1, 0] With the exception of the first M points, the answer is correct. 211 Problem 9.42 At f s = 8 Hz, there are 8 samples per period. These samples can be evaluated by setting t = nT = n/8 in the expression for x(t). We find: x(n)= 1 4 ¦0, 0.5, 1, 0.5, 0, −0.5, −1, −0.5¦ According to Eq. (9.7.4), the aliased coefficients can be obtained by computing the 8-point DFT of one period and dividing by 8. This DFT can be done quickly by an 8-point FFT by hand, which gives: x = 1 4 ⎡ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎣ 0 0.5 1 0.5 0 −0.5 −1 −0.5 ⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎦ DFT −→ X = 1 4 ⎡ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎣ 0 −j(2 + √ 2) 0 j(2 − √ 2) 0 −j(2 − √ 2) 0 j(2 + √ 2) ⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎦ , b = 1 4 ⎡ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎣ 0 (2 + √ 2)/8j 0 −(2 − √ 2)/8j 0 (2 − √ 2)/8j 0 −(2 + √ 2)/8j ⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎦ The coefficients b 1 and b 7 correspond to frequencies :f 1 = :1 Hz, whereas b 3 and b 5 correspond to :f 2 = :3 Hz. Thus, we find from Eq. (9.7.5) and after using Euler’s formula: x al (t)= 2jb 1 sin(2πf 1 t)+2jb 3 sin(2πf 2 t)= 2 + √ 2 16 sin(2πt)− 2 − √ 2 16 sin(6πt) It can be verified easily that x al and x(t) agree at the sampling instants t = nT = n/8. Problem 9.43 In the overlap-add method, the input blocks have length N−M and are non-overlapping. Thus, if there are K blocks in the total length, we will have: L = (N−M)K (P9.2) In Fig. 9.9.1, the input blocks overlap by M points, but again if there are K segments, the total length will be (N − M)K plus an extra M points at the end. Thus, we have in the overlap-save method: L = (N−M)K +M = (N−M)K which is essentially the same as in Eq. (P9.2) for large L. Thus, in both cases, the total number of segments can be estimated to be: K = L N−M Per segment, we are doing two FFTs and N multiplications, namely, Nlog 2 N+N = N(1 +log 2 N) per segment Thus, for K segments, we have cost: KN(1 +log 2 N)= LN(1 +log 2 N) N−M 212 This is to be compared with the cost of L(M+1) of linear convolution of the entire input array with the filter (here, we treat these MACs as complex-valued.) Thus, the relative cost of the fast versus slow convolution will be: fast slow = LN(1 +log 2 N) N−M L(M+1) = N(1 +log 2 N) (N−M)(M+1) Problem 9.44 An example of such a program is given below: /* ovsave.c - FIR filtering by overlap-save method and FFT */ #include <stdio.h> #include <cmplx.h> #include <stdlib.h> calloc(), realloc() #define MAX 64 initial allocation size void circonv(), complexify(), fft(), ifft(); void main(int argc, char **argv) { FILE *fph; filter file double *h, *x, *xhead; x = length-N block complex *H, *X, *Y; N-point DFTs int M, N, n, i; int max = MAX, dmax = MAX; if (argc != 3) { fprintf(stderr, "usage: fastconv hfile N < xfile > yfile\n"); exit(0); } if ((fph = fopen(argv[1], "r")) == NULL) { fprintf(stderr, "can’t open filter file: %s\n", argv[1]); exit(0); } N = atoi(argv[2]); h = (double *) calloc(max + 1, sizeof(double)); preliminary allocation for (M=0;; M++) { read h if (M == max) { reallocate h, if necessary max += dmax; h = (double *) realloc((char *) h, (max + 1) * sizeof(double)); } if (fscanf(fph, "%lf", h + M) == EOF) break; } M--; M = filter order if (N <= 2*M) { fprintf(stderr, "must have N > 2M = %d", 2*M); exit(0); } 213 h = (double *) realloc((char *) h, (M+1) * sizeof(double)); x = (double *) calloc(N, sizeof(double)); xhead = (double *) calloc(M, sizeof(double)); head/tail of input block H = (complex *) calloc(N, sizeof(complex)); allocate DFT arrays X = (complex *) calloc(N, sizeof(complex)); Y = (complex *) calloc(N, sizeof(complex)); for (n=0; n<N; n++) complexify/extend to length N if (n <= M) H[n] = cmplx(h[n], 0.0); else H[n] = cmplx(0.0, 0.0); fft(N, H); H = FFT(h), done once for (n=0; n<M; n++) xhead[n] = 0; pad M zeros in front of first block for (;;) { keep reading input in blocks x for (n=0; n<M; n++) previous tail is head of present block x x[n] = xhead[n]; for (n=M; n<N; n++) read rest of x from input stream if (scanf("%lf", x + n) == EOF) goto lastblocks; for (n=0; n<M; n++) tail of present block x xhead[n] = x[n + N - M]; will be head of next block complexify(N, x, X); X = cmplx(x, 0) circonv(N, H, X, Y); done by fft for (n=M; n<N; n++) discard first M points, save the rest printf("%lf\n", real(Y[n])); } lastblocks: n = index where EOF occurred for (i=n; i<N; i++) pad rest of x with zeros x[i] = 0; if n <= N-M there is only one last block to consider complexify(N, x, X); otherwise, there are two last blocks circonv(N, H, X, Y); for (i=M; i<N; i++) printf("%lf\n", real(Y[i])); if (n <= N-M) exit(0); exit, if only one last block otherwise, process very last block for (i=0; i<M; i++) if n > N-M, the tail of previous xhead[i] = x[i + N - M]; block will be non-zero for (i=0; i<N; i++) if (i < M) x[i] = xhead[i]; head of very last block 214 else x[i] = 0; rest of block is zero complexify(N, x, X); circonv(N, H, X, Y); for (i=M; i<N; i++) printf("%lf\n", real(Y[i])); } ——————————————————————– void complexify(N, x, X) int N; double *x; complex *X; { int n; for (n=0; n<N; n++) X[n] = cmplx(x[n], 0.0); } ——————————————————————– void circonv(N, H, X, Y) circular convolution via FFT int N; complex *H, *X, *Y; H = FFT(h), must be done previously { int k; fft(N, X); for (k=0; k<N; k++) Y[k] = cmul(H[k], X[k]); ifft(N, Y); } 215 Chapter 10 Problems Problem 10.1 Start with D(ω)= ∞ _ k=−∞ d(k)e −jωk and assume that d(k) is real and even in k. Taking conjugates and replacing ω by −ω, gives D(−ω) ∗ = _ ∞ _ k=−∞ d(k)e jωk _ ∗ = ∞ _ k=−∞ d(k)e −jωk = D(ω) This result uses only the reality of d(k) and is the usual hermitian property for transfer functions of real-valued impulse responses. Because d(k)= d(−k), we can change the summation from k to −k to get: D(ω)= ∞ _ k=−∞ d(k)e −jωk = ∞ _ k=−∞ d(−k)e −jω(−k) = ∞ _ k=−∞ d(k)e −j(−ω)k = D(−ω) Thus, the reality and evenness conditions imply together: D(ω)= D(−ω) ∗ = D(−ω) which states that D(ω) is both real and even in ω. In the antisymmetric case, we have d(−k)= −d(k), and therefore D(ω)= ∞ _ k=−∞ d(k)e −jωk = ∞ _ k=−∞ d(−k)e −jω(−k) = − ∞ _ k=−∞ d(k)e −j(−ω)k = −D(−ω) Together with the reality condition, we get D(ω)= D(−ω) ∗ = −D(−ω) which implies that D(ω) is pure imaginary and odd in ω. Separating the negative- and positive-k terms, we can rewrite D(ω) in the form: D(ω)= d(0)+ ∞ _ k=1 d(k)e −jωk + −1 _ k=−∞ d(k)e −jωk = d(0)+ ∞ _ k=1 d(k)e −jωk + ∞ _ k=1 d(−k)e jωk In the symmetric case, we set d(−k)= d(k) and combine the two sums with Euler’s formula to get: D(ω)= d(0)+2 ∞ _ k=1 d(k)cos(ωk) (symmetric case) For the antisymmetric case, d(0)= 0 because it must satisfy d(−0)= −d(0). Setting d(−k)= −d(k) in the sum, we obtain: D(ω)= −2j ∞ _ k=1 d(k)sin(ωk) (antisymmetric case) 216 Problem 10.2 For the bandpass example, we use the fact that D(ω)= 1 over the passband ω a ≤ ¦ω¦ ≤ ω b to get: d(k) = _ π −π D(ω)e jωk dω 2π = _ −ωa −ω b D(ω)e jωk dω 2π + _ ω b ωa D(ω)e jωk dω 2π = = _ −ωa −ω b e jωk dω 2π + _ ω b ωa e jωk dω 2π = _ e jωk 2πjk _ −ωa −ω b + _ e jωk 2πjk _ ω b ωa = e −jωak −e −jω b k 2πjk + e jω b k −e jωak 2πjk = sin(ω b k)−sin(ω a k) πk Setting ω a = 0, gives the lowpass case, and ω b = π the highpass one. In the latter, we have: d(k)= sin(πk)−sin(ω b k) πk The first term is zero for all non-zero k, and its equal to unity for k = 0. Thus, we may replace it by δ(k): d(k)= δ(k)− sin(ω a k) πk For the differentiator and Hilbert transformer, see the more general cases of Problem 10.3. Problem 10.3 For the lowpass differentiator, we have d(k)= _ π −π D(ω)e jωk dω 2π = _ ωc −ωc jωe jωk dω 2π It can be evaluated either by parts, or by recognizing the integrand as the derivative with respect to k (treating k initially as a real variable and at the end restricting it to integer values.) d(k)= ∂ ∂k _ ωc −ωc e jωk dω 2π = ∂ ∂k _ sin(ω c k) πk _ where the ω-integration gave the standard lowpass filter. Performing the differentiation, we get the required expression for d(k): d(k)= ω c cos(ω c k) πk − sin(ω c k) πk 2 Setting ω c = π gives the full-band differentiator: d(k)= cos(πk) k − sin(πk) πk 2 Because d(k) belongs to the antisymmetric class, it will have d(0)= 0. The second term vanishes for nonzero integer ks. Thus, we have for k }= 0: d(k)= cos(πk) k = (−1) k k (differentiator) The Hilbert transformer case is similar. 217 Problem 10.4 Using the differentiation argument, we have in this case: d(k)= ∂ ∂k _ _ −ωa −ω b e jωk dω 2π + _ ω b ωa e jωk dω 2π _ The integrations give the bandpass filter case. Thus, d(k)= ∂ ∂k _ sin(ω b k)−sin(ω a k) πk _ which becomes the difference of two lowpass differentiators: d(k)= ω b cos(ω b k) πk − sin(ω b k) πk 2 − ω a cos(ω a k) πk + sin(ω a k) πk 2 Problem 10.5 For the first-order differentiator, we have impulse response, transfer function, and frequency response: h = [1, −1] ⇒ H(z)= 1 −z −1 ⇒ H(ω)= 1 −e −jω Thus, the NRR will be NRR = h 2 0 +h 2 1 = 1 +1 = 2 Thus, the noise power doubles at the output. To see how closely it resembles the ideal differen- tiator, we expand the frequency response at low frequencies: H(ω)= 1 −e −jω = 1 −(1 −jω)= jω for small ω For the ideal lowpass differentiator case, the NRR can be computed as: NRR = _ ωc −ωc ¦D(ω)¦ 2 dω 2π = _ ωc −ωc ¦jω¦ 2 dω 2π = ω 3 c 3π Thus, it increases rapidly with ω c . Compared to the full-band maximum NRR obtained with ω c = π, we have NRR max = π 3 /3π = π 2 /3 and therefore, NRR NRR max = _ ω c π _ 3 Problem 10.6 Let E(ω)= D(ω)− D(ω) be the error in the designed filter. Then, we have E(ω)= D(ω)− D(ω)= ∞ _ k=−∞ d(k)e −jωk − M _ k=−M d(k)e −jωk = _ ¦k¦>M d(k)e −jωk because the coefficients d(k) cancel for ¦k¦ ≤ M. Thus, the time-domain coefficients of the error are: e(k)= _ 0 if ¦k¦ ≤ M d(k) if ¦k¦ > M 218 Parseval’s identity applied to e(k) gives then _ π −π ¦E(ω)¦ 2 dω 2π = ∞ _ k=−∞ e 2 (k)= _ ¦k¦>M d 2 (k) or, E M = _ π −π ¦D(ω)− D(ω)¦ 2 dω 2π = _ ¦k¦>M d 2 (k) The right-hand side sumcan be written with the help of Parseval’s identity applied to D(ω) itself: _ ¦k¦>M d 2 (k)= ∞ _ k=−∞ d 2 (k)− _ ¦k¦≤M d 2 (k)= _ π −π ¦D(ω)¦ 2 dω 2π − M _ k=−M d(k) 2 In the limit as M → ∞, the second term in the right-hand side tends to the Parseval limit, thus canceling the first term and resulting in E M →0. Problem 10.7 From Problem 10.3, we have d(k)= (−1) k /k, k }= 0, for the differentiator filter. Using Parseval’s identity we have ∞ _ k=−∞ d 2 (k)= _ π −π ¦D(ω)¦ 2 dω 2π = _ π −π ω 2 dω 2π = π 2 3 But the left-hand side is twice the required sum: ∞ _ k=−∞ d 2 (k)= _ k}=0 1 k 2 = 2 ∞ _ k=1 1 k 2 Thus, 2 ∞ _ k=1 1 k 2 = π 2 3 ⇒ ∞ _ k=1 1 k 2 = π 2 6 For the full-band Hilbert transformer, we have d(k)= 1 −cos(πk) πk = 1 −(−1) k πk , k }= 0 Thus, d(k) is nonzero only for odd k, and is in this case d(k)= 2/πk. Parseval’s identity applied to this filter gives: ∞ _ k=−∞ d 2 (k)= _ π −π ¦D(ω)¦ 2 dω 2π = _ π −π ¦jsign(ω)¦ 2 dω 2π = _ π −π 1 dω 2π = 1 The left-hand side on the other hand becomes: ∞ _ k=−∞ d 2 (k)= 2 ∞ _ k=1 k=odd 4 π 2 k 2 Thus, we obtain 219 2 ∞ _ k=1 k=odd 4 π 2 k 2 = 1 ⇒ ∞ _ k=1 k=odd 1 k 2 = π 2 8 If the sum for all integers k is π 2 /6 and for odd ones π 2 /8, it follows by subtraction that the sum over even integers will be: ∞ _ k=2 k=even 1 k 2 = π 2 6 − π 2 8 = π 2 24 Problem 10.8 The sinusoidal response of D(ω) in its steady-state form is: e jωn D −→D(ω)e jωn = −jsign(ω)e jωn Replacing ω by −ω, and using the odd symmetry property of D(ω), we have: e −jωn D −→D(−ω)e −jωn = jsign(ω)e −jωn But cos(ωn)= [e jωn + e −jωn ]/2. Thus, forming the same linear combination of outputs, we have: cos(ωn) D −→ 1 2 _ −jsign(ω)e jωn +jsign(ω)e −jωn _ = sign(ω)sin(ωn) Similarly, because sin(ωn)= [e jωn −e −jωn ]/2j, we have for the outputs: sin(ωn) D −→ 1 2j _ −jsign(ω)e jωn −jsign(ω)e −jωn _ = −sign(ω)cos(ωn) Problem 10.9 From the definition of D(z), we have: D(z)= M _ k=−M d(k)z −k ⇒ D(z −1 )= M _ k=−M d(k)z k = M _ k=−M d(−k)z −k where in the last step we changed summation from k to −k. In the symmetric/antisymmetric cases, we have d(k)= :d(k). Therefore, D(z −1 )= : M _ k=−M d(k)z −k = : D(z) Fromthe reality of d(k), it follows that the zeros will come in conjugate pairs if they are complex. Thus, if z 0 is a complex zero, then z ∗ 0 is also a zero. From the symmetry or antisymmetry properties, it follows that if z 0 is a zero, then D(z −1 0 )= : D(z 0 )= 0 Thus, 1/z 0 and 1/z ∗ 0 are both zeros. The four zeros ¦z 0 , z ∗ 0 , 1 z 0 , 1 z ∗ 0 ¦ are shown in Fig. P10.1. If z 0 lies on the unit circle then because 1/z ∗ 0 = z 0 , the only other distinct zero is the complex conjugate. 220 z 0 1/z 0 * 1/z 0 z 0 * Fig. P10.1 Pattern of zeros of linear phase filters. In the antisymmetric case, we have in particular for z = :1, D(:1)= M _ k=−M d(k)(:1) k = 0 This follows because d(k) is odd and summed over symmetric limits and because the factor (:1) k is even in k. The same conclusion follows from the frequency response. Using the anti- symmetry property and splitting the sum in two parts, we get: D(ω)= M _ k=−M d(k)e −jωk = M _ k=1 d(k) _ e −jωk −e jωk _ = −2j M _ k=1 d(k)sin(ωk) Setting ω= 0, π, corresponding to z = :1, we have sin(ωk)= 0, and therefore, D(ω) vanishes. Finally, we note that if d(k) is windowed by a window w(k), that is, d ¹ (k)= w(k)w(k), then because the window w(k) is symmetric with respect to the origin, the symmetry/antisymmetry properties of d(k) will be preserved and will imply similar results on the locations of the zeros. Problem 10.10 For the symmetric case, the following must necessarily be zeros: z 0 = 0.5 +0.5j, z ∗ 0 = 0.5 −0.5j, 1 z 0 = 1 −j, 1 z ∗ 0 = 1 +j Thus, the transfer function will be H(z)= _ 1−(0.5+0.5j)z −1 __ 1−(0.5−0.5j)z −1 __ 1−(1−j)z −1 __ 1−(1+j)z −1 _ = 1−3z −1 +4.5z −2 −3z −3 +z −4 In the time domain, we get the length-5 symmetric (about its middle) impulse response: h = [1, −3, 4.5, −3, 1] In the antisymmetric case, we have in addition two zeros at z = :1 contributing a factor (1−z −2 ) to the transfer function. Thus, H(z)= (1 −z −2 )(1 −3z −1 +4.5z −2 −3z −3 +z −4 )= 1 −3z −1 +3.5z −2 −3.5z −4 +3z −5 −z −6 and in the time domain: h = [1, −3, 3.5, 0, −3.5, 3, −1] 221 The frequency response in the symmetric case is obtained by factoring out a factor of z −2 and using Euler’s formula: H(z)= z −2 _ z 2 +z −2 −3(z +z −1 )+4.5 _ ⇒ H(ω)= 2e −2jω _ cos(2ω)−3cos(ω)+4.5 _ For the antisymmetric case, we have: H(z)= z −3 _ (z 3 −z −3 )−3(z 2 −z −2 )+3.5(z −z −1 ) _ ⇒ H(ω)= −2je −3jω _ sin(3ω)−3sin(2ω)+3.5sin(ω) _ Problem 10.11 Proceeding as in the previous problem, we find the transfer function of the symmetric case: H(z)= (1−0.5jz −1 )(1+0.5jz −1 )(1−2jz −1 )(1+2jz −1 )= 1+4.25z −2 +z −4 ⇒ h = [1, 0, 4.25, 0, 1] and for the antisymmetric case: H(z)= (1−z −2 )(1+4.25z −2 +z −4 )= 1+3.25z −2 −3.25z −4 −z −6 ⇒ h = [1, 0, 3.25, 0, −3.25, 0, −1] Problem 10.12 We use the first-order Taylor series approximation: ln(1 :x)= :x Changing to base-10, we have: log 10 (1 :x)= ln(1 :x) ln(10) = :0.4343x It follows that A pass = 20log 10 _ 1 +δ pass 1 −δ pass _ = 20log 10 (1 +δ pass )−20log 10 (1 −δ pass ) = 20 · 0.4343δ pass +20 · 0.4343δ pass = 17.372δ pass Problem 10.13 First, we calculate δ pass and δ stop from Eq. (10.2.5): δ pass = 10 0.1/20 −1 10 0.1/20 +1 = 0.0058, δ stop = 10 −80/20 = 0.0001 Therefore, δ = min(δ pass , δ stop )= δ stop = 0.0001, which in dB is A = −20log 10 δ = A stop = 80. The D and α parameters are computed by: α = 0.1102(A−8.7)= 0.1102(80 −8.7)= 7.857, D = A−7.95 14.36 = 5.017 The transition width is Δf = f stop −f pass = 2 −1.5 = 0.5 kHz; therefore, the filter length will be: N = 1 + Df s Δf = 1 + 5.017 · 10 0.5 = 101.34 ⇒ N = 103 222 Problem 10.14 The transition width is inversely related to the filter length N: Δf = Df s N−1 As in the previous problem, we find D = 5.017. Thus, Δf = Df s N−1 = 5.017 · 10 251 −1 = 0.2007 kHz Problem 10.15 The window’s width factor is D = 5.017 as in the previous problem. Thus, Δf = Df s N−1 = 5.017 · 44.1 129 −1 = 1.729 kHz Conversely, if Δf = 2 kHz, then we may solve for the D-factor and attenuation A: D = A−7.95 14.36 = (N−1) Δf f s = 5.805 ⇒ A = 14.36D+7.95 = 91.31 dB The corresponding ripple will be δ = 10 −A/20 = 10 −91.31/20 = 0.000027 which gives the passband attenuation: A pass = 17.372δ = 0.000472 dB In the 4-times oversampling case, the transition width is required to be: Δf = 24.55 −19.55 = 5 kHz This gives the width factor and attenuation: D = A−7.95 14.36 = (N−1) Δf 4f s = 3.6281 ⇒ A = 14.36D+7.95 = 60.05 dB Problem 10.16 Assuming that an N-tap filter requires approximately N instructions for processing each input sample, the maximum filter length will correspond to the maximum number of instructions that fit within the sampling interval T, that is, N max = T T instr = f instr f s Inserting this into the Kaiser design formula, we find the minimum width (where we used N instead of N−1 in the denominator): Δf = Df s N = Df s 2 f instr 223 Problem 10.17 Using N = f instr /f s for the maximum filter length, we obtain the maximum width parameter D and attenuation A: D = A−7.95 14.36 = N Δf f s = f instr Δf f s 2 = F instr ΔF ⇒ A = 14.36F instr ΔF +7.95 Problem 10.18 The following MATLAB program segment computes the rectangularly and Hamming windowed impulse responses with the help of the MATLAB function dlh.m, and then it computes the cor- responding frequency responses over N F equally spaced frequencies over the right half of the Nyquist interval [0, π] with the help of the function dtft.m: wc = 0.3 * pi; % cutoff frequency N = 81; % filter length w = 0.54 - 0.46 * cos(2 * pi * (0:N-1) / (N-1)); % Hamming window hrec = dlh(1, wc, N); % ideal lowpass filter hham = w .* hrec; % windowed filter NF = 200; % 200 frequencies in rads/sample omega = (0:NF-1) * pi / NF; % over the interval [0, π] Hrec = dtft(hrec, omega); % frequency response Hham = dtft(hham, omega); Problem 10.19 As an example, the following MATLAB programsegment computes the bandpass filter of Example 10.2.2 (alternative design): fs = 20; in kHz fpa = 4; fpb = 6; fsa = 3; fsb = 8; Apass = 0.1; Astop = 80; in dB h = kbp(fs, fpa, fpb, fsa, fsb, Apass, Astop, -1); % s = −1 for alternative design NF = 200; omega = (0:NF-1) * pi / NF; H = dtft(h, omega); Similarly, the highpass filter can be designed by: fs = 20; in kHz fpass = 5; fstop = 4; Apass = 0.1; Astop = 80; in dB h = klh(-1, fs, fpass, fstop, Apass, Astop); % s = −1 for highpass NF = 200; omega = (0:NF-1) * pi / NF; H = dtft(h, omega); 224 Problem 10.20 Use the design MATLAB routine kdiff, with f s = 2 so that ω= 2πf/2 = πf, that is, the f’s are the ω’s in units of π. The filter lengths depend only on the values of Δf and A, they are: Δf A N 0.10 30 33 0.10 60 75 0.05 30 63 0.05 60 147 For example, in the case ω c = 0.4π, Δω= 0.05π, A = 60 dB, we have the MATLAB code: h = kdiff(2, 0.4, 0.05, 60); NF = 200; omega = (0:NF-1) * pi / NF; H = dtft(h, omega); The magnitude responses are shown in Figs. P10.2 and P10.3. Fig. P10.2 Lowpass differentiator with ω c = 0.4π. 225 Fig. P10.3 Lowpass differentiator with ω c = 0.8π. Problem 10.21 For example, in the case ω c = 0.4π, Δω= 0.05π, A = 60 dB, we have the MATLAB segment that computes the Kaiser differentiator and the Savitzky-Golay differentiators of polynomial order d = 3: h = kdiff(2, 0.4, 0.05, 60); % Kaiser differentiator [B, S] = sg(3, N); % Savitzky-Golay smoothing filters F = S’ * S; % polynomial basis matrix G = S * F^(-1); % Savitzky-Golay differentiator filters g = G(:,2)’; % first-order derivative filter NF = 500; omega = (0:NF-1) * pi / NF; H = dtft(h, omega); % frequency responses G = dtft(g, omega); The magnitude responses are shown in Fig. P10.4. Problem 10.22 Use the design MATLAB routine khilb, with f s = 2 so that ω= 2πf/2 = πf, that is, the f’s are the ω’s in units of π. The filter lengths depend only on the values of Δf and A, they are the 226 Fig. P10.4 Comparison of Kaiser and SG differentiators. same as in Problem 10.20. For example, the Hilbert transformer with ω c = 0.8π, Δω = 0.05π, and A = 60 dB, can be designed by the MATLAB segment: h = khilb(2, 0.8, 0.05, 60); NF = 200; omega = (0:NF-1) * pi / NF; H = dtft(h, omega); % frequency responses The magnitude responses are shown in Figs. P10.5 and P10.6. Problem 10.23 The following MATLAB segment computes the Kaiser and Hamming spectra in dB. The Kaiser window parameters are determined by the function kparm2.m: F1 = 0.20; F2 = 0.25; F3 = 0.30; DF = (F2-F1)/3; % units of fs A1 = 1; A2 = 10^(-50/20); A3 = 1; % amplitudes R = 70; % sidelobe level in dB [alpha, L] = kparm2(DF, R); % Kaiser parameters n = (0:L-1); x = A1 * cos(2*pi*F1*n) + A2 * cos(2*pi*F2*n) + A3 * cos(2*pi*F3*n); xk = kwind(alpha, L) .* x; % Kaiser windowed signal xh = (0.54 - 0.46 * cos(2*pi*n/(L-1))) .* x; % Hamming windowed signal NF = 256; omega = (0:NF-1) * pi / NF; Xk = abs(dtft(xk, omega)); % DTFT spectrum Xkmax = max(Xk); Xk = 20 * log10(Xk / Xkmax); % normalized and in dB Xh = abs(dtft(xh, omega)); 227 Fig. P10.5 Lowpass Hilbert transformer with ω c = 0.8π. Xhmax = max(Xh); Xh = 20 * log10(Xh / Xhmax); 228 Fig. P10.6 Full-band Hilbert transformer. 229 Chapter 11 Problems Problem 11.1 Here, we assume that the parameter β = tan(Δω/2) remains positive and less than one, 0 ≤ β ≤ 1. This is guaranteed if the bandwidth is 0 ≤ Δω≤ π/2 in rads/sample, or, 0 ≤ Δf ≤ f s /4 in Hz. This range covers most practical applications. This condition implies that the poles are complex conjugate and have radius R 2 = 1 −β 1 +β ⇒ R = ¸ 1 −β 1 +β (If β > 1, which happens when π/2 < Δω≤ π, then there are two real poles.) It follows that the -level time constant will be n eff = ln lnR Problem 11.2 For small values of Δω, we may use the first-order Taylor expansion tan(x)= x to write approx- imately: β = tan _Δω 2 _ = Δω 2 Then, expanding R to first-order in β and thus to first-order in Δω, we have: R = ¸ 1 −β 1 +β = (1 − 1 2 β)(1 − 1 2 β)= 1 −β = 1 − Δω 2 where we used the Taylor expansions (1 ∓ x) :1/2 = 1 − x/2 and (1 − x/2) 2 = 1 − x. Solving for Δω, we obtain the approximate expression Δω= 2(1 −R). Problem 11.3 For the 3-dB case, the parameter b is the same for both filters. Adding the two transfer functions, we recognize that the two numerators add up to become the denominator: H notch (z)+H peak (z) = b 1 −2cos ω 0 z −1 +z −2 1 −2bcos ω 0 z −1 +(2b −1)z −2 +(1 −b) 1 −z −2 1 −2bcos ω 0 z −1 +(2b −1)z −2 = b(1 −2cos ω 0 z −1 +z −2 )+(1 −b)(1 −z −2 ) 1 −2bcos ω 0 z −1 +(2b −1)z −2 = 1 −2bcos ω 0 z −1 +(2b −1)z −2 1 −2bcos ω 0 z −1 +(2b −1)z −2 = 1 For the magnitude responses squared we may use the equivalent analog expressions to get: ¦H notch (ω)¦ 2 +¦H peak (ω)¦ 2 = ¦H notch (Ω)¦ 2 +¦H peak (Ω)¦ 2 = (Ω 2 −Ω 2 0 ) 2 (Ω 2 −Ω 2 0 ) 2 +α 2 Ω 2 + α 2 Ω 2 (Ω 2 −Ω 2 0 ) 2 +α 2 Ω 2 = 1 230 Problem 11.4 The analog transfer function and magnitude response squared are in the general boost or cut case: H(s)= G 0 (s 2 +Ω 2 0 )+Gαs s 2 +αs +Ω 2 0 ⇒ ¦H(Ω)¦ 2 = G 2 0 (Ω 2 −Ω 2 0 ) 2 +G 2 α 2 Ω 2 (Ω 2 −Ω 2 0 ) 2 +α 2 Ω 2 where α = (1 +Ω 2 0 )β = (1 +Ω 2 0 )tan _ Δω 2 _ ¸ ¸ ¸ _ G 2 B −G 2 0 G 2 −G 2 B ≡ γ ¸ ¸ ¸ _ G 2 B −G 2 0 G 2 −G 2 B where the last step defines the parameter γ, which does not depend on the gains. Normalizing everything to the reference gain G 0 , we have ¦H(Ω)¦ 2 = G 2 0 (Ω 2 −Ω 2 0 ) 2 +g 2 α 2 Ω 2 (Ω 2 −Ω 2 0 ) 2 +α 2 Ω 2 , α = γ ¸ ¸ ¸ _ g 2 B −1 g 2 −g 2 B , where g = G G 0 , g B = G B G 0 Then, we may express the magnitude squared response in the following formthat explicitly shows the gains: ¦H(Ω)¦ 2 = G 2 0 (Ω 2 −Ω 2 0 ) 2 +N(g, g B )γ 2 Ω 2 (Ω 2 −Ω 2 0 ) 2 +D(g, g B )γ 2 Ω 2 where the numerator and denominator gain functions are defined by N(g, g B )= g 2 g 2 B −1 g 2 −g 2 B , D(g, g B )= g 2 B −1 g 2 −g 2 B For the arithmetic, geometric, and harmonic mean choices for g 2 B the functions N and Dsimplify as follows: g 2 B = 1 +g 2 2 , N(g, g B )= g 2 , D(g, g B )= 1, (arithmetic) g 2 B = g, N(g, g B )= g, D(g, g B )= 1 g , (geometric) g 2 B = 2g 2 1 +g 2 , N(g, g B )= 1, D(g, g B )= 1 g 2 , (harmonic) Now, if we consider an equal and opposite boost and cut by, say by A dB (with respect to the reference), then the boost and cut gains will be g = 10 :A/20 . Thus, the substitution g → g −1 changes a boost into an equal and opposite cut, and vice versa. Even though the boost and cut gains are equal and opposite, the bandwidth levels g 2 B may be defined arbitrarily in the two cases. However, if we take them also to be related by the substitution g B → g −1 B , then we can show that the boost and cut filters are inverses to each other. Indeed, under the substitutions ¦g, g B ¦ →¦g −1 , g −1 B ¦, the boost and cut magnitude responses are: ¦H boost (Ω)¦ 2 = G 2 0 (Ω 2 −Ω 2 0 ) 2 +N(g, g B )γ 2 Ω 2 (Ω 2 −Ω 2 0 ) 2 +D(g, g B )γ 2 Ω 2 , ¦H cut (Ω)¦ 2 = G 2 0 (Ω 2 −Ω 2 0 ) 2 +N(g −1 , g −1 B )γ 2 Ω 2 (Ω 2 −Ω 2 0 ) 2 +D(g −1 , g −1 B )γ 2 Ω 2 Under this substitution, the functions N and D interchange roles, that is, one can show easily that N(g −1 , g −1 B )= D(g, g B ) , D(g −1 , g −1 B )= N(g, g B ) 231 Therefore, the boost and cut filters will be: ¦H boost (Ω)¦ 2 = G 2 0 (Ω 2 −Ω 2 0 ) 2 +N(g, g B )γ 2 Ω 2 (Ω 2 −Ω 2 0 ) 2 +D(g, g B )γ 2 Ω 2 , ¦H cut (Ω)¦ 2 = G 2 0 (Ω 2 −Ω 2 0 ) 2 +D(g, g B )γ 2 Ω 2 (Ω 2 −Ω 2 0 ) 2 +N(g, g B )γ 2 Ω 2 Hence, their product will be identically equal to G 4 0 . The geometric-mean and weighted geometric- mean choices for g 2 B are special cases of the substitution ¦g, g B ¦ → ¦g −1 , g −1 B ¦, and therefore, satisfy the desired property. But, any other choice of g B will do, as long as one defines the boost bandwidth to be g B and the cut bandwidth, g −1 B , that is, equal and opposite bandwidth gains in dB. Note, also that the transfer functions themselves are inverses to each other, not just their magnitudes. Indeed, we can write them in the form: H boost (s)= G 0 s 2 +Ω 2 0 +γs _ N(g, g B ) s 2 +Ω 2 0 +γs _ D(g, g B ) , H cut (s)= G 0 s 2 +Ω 2 0 +γs _ N(g −1 , g −1 B ) s 2 +Ω 2 0 +γs _ D(g −1 , g −1 B ) = G 0 s 2 +Ω 2 0 +γs _ D(g, g B ) s 2 +Ω 2 0 +γs _ N(g, g B ) which implies for the analog and the bilinearly transformed digital transfer functions: H cut (s)= G 2 0 H boost (s) ⇒ H cut (z)= G 2 0 H boost (z) Problem 11.5 The following MATLAB code segment designs the three filters (two peaking and one complemen- tary notch), computes their impulse responses, and their magnitude responses: w0 = 0.35*pi; Dw = 0.1*pi; in rads/sample [b1, a1, beta1] = parmeq(0, 1, 1/sqrt(2), w0, Dw); peaking 3-dB width [b2, a2, beta2] = parmeq(0, 1, sqrt(0.1), w0, Dw); peaking 10-dB width [b3, a3, beta3] = parmeq(1, 0, 1/sqrt(2), w0, Dw); notching 3-dB width x = [1, zeros(1, 99)]; unit impulse h1 = filter(b1, a1, x); impulse responses h2 = filter(b2, a2, x); h3 = filter(b3, a3, x); w = (0:199)*pi/200; 200 frequencies over [0, π] H1 = abs(dtft(b1, w) ./ dtft(a1, w)).^2; magnitude responses H2 = abs(dtft(b2, w) ./ dtft(a2, w)).^2; H3 = abs(dtft(b3, w) ./ dtft(a3, w)).^2; The 5-percent time constants can be calculated as in Problem 11.1, with = 0.05. Problem 11.6 For example, the following MATLAB code designs the first four filters of Example 11.4.1 and computes their impulse response, frequency, and phase responses (in degrees): [b1, a1, beta1] = parmeq(1, 10^(9/20), 10^(6/20), 0.35*pi, 0.1*pi); [b2, a2, beta2] = parmeq(1, 10^(9/20), 10^(3/20), 0.35*pi, 0.1*pi); [b3, a3, beta3] = parmeq(1, 10^(-9/20), 10^(-6/20), 0.60*pi, 0.2*pi); [b4, a4, beta4] = parmeq(1, 10^(-9/20), 10^(-3/20), 0.60*pi, 0.2*pi); x = [1, zeros(1, 49)]; length-50 unit impulse 232 h1 = filter(b1, a1, x); impulse responses h2 = filter(b2, a2, x); h3 = filter(b3, a3, x); h4 = filter(b4, a4, x); w = (0:199)*pi/200; H1 = dtft(b1, w) ./ dtft(a1, w); argH1 = angle(H1) * 180 / pi; H2 = dtft(b2, w) ./ dtft(a2, w); argH2 = angle(H2) * 180 / pi; H3 = dtft(b3, w) ./ dtft(a3, w); argH3 = angle(H3) * 180 / pi; H4 = dtft(b4, w) ./ dtft(a4, w); argH4 = angle(H4) * 180 / pi; Figure P11.1 shows the phase responses. Note the rapid variations in the vicinities of the center frequencies. Fig. P11.1 Phase responses of Problem 11.6. Problem 11.7 The following MATLAB function lheq.m implements the design of both the lowpass and highpass shelving filters (the parameter s = :1 selects the two cases): % lheq.m - lowpass/highpass first-order shelving EQ filter design % % [b, a, beta] = lheq(s, G0, G, Gc, wc) % % s = 1, −1 = lowpass, highpass % b = [b 0 , b 1 ] = numerator coefficients % a = [1, a 1 ] = denominator coefficients % G 0 , G, Gc = reference, boost/cut, and cutoff gains % wc = cutoff frequency in [rads/sample] % beta = design parameter β function [b, a, beta] = lheq(s, G0, G, Gc, wc) beta = (tan(wc/2))^s * sqrt(abs(Gc^2 - G0^2)) / sqrt(abs(G^2 - Gc^2)); b = [(G0 + G*beta), -s*(G0 - G*beta)] / (1+beta); a = [1, -s*(1-beta)/(1+beta)]; The filters of Examples 11.2.1 and 11.2.2 may be designed by the following MATLAB code, which also shows how to compute the magnitude responses of the two complementary cases: 233 [b1, a1, beta1] = lheq(1, 0, 1, 1/sqrt(2), 0.2*pi); lowpass cases [b2, a2, beta2] = lheq(1, 0, 1, sqrt(0.9), 0.2*pi); [b3, a3, beta3] = lheq(1, 0, 1, 1/sqrt(2), 0.7*pi); [b4, a4, beta4] = lheq(1, 0, 1, sqrt(0.9), 0.7*pi); [b5, a5, beta5] = lheq(-1, 0, 1, 1/sqrt(2), 0.2*pi); highpass cases [b6, a6, beta6] = lheq(-1, 0, 1, sqrt(0.9), 0.2*pi); omega = (0:199)*pi/200; 200 frequencies in [0, π] H1 = abs(dtft(b1, omega)./dtft(a1, omega)).^2; magnitude response squared H5 = abs(dtft(b5, omega)./dtft(a5, omega)).^2; Problem 11.8 The following MATLAB code generates the first pair of comb and notch filters of Example 11.5.1, that is, with unshifted peaks, and computes the corresponding magnitude and phase responses; it also computes the impulse response of the first filter in two ways: (a) using MATLAB’s function filter and (b) the customized function combfilt.m that uses a circular buffer: D = 10; wc = 0.025 * pi; [a1, b1, c1, beta1] = combeq(1, 10^(9/20), 10^(3/20), D, wc, 1); [a2, b2, c2, beta2] = combeq(1, 10^(-12/20), 10^(-3/20), D, wc, 1); omega = (0:399)*2*pi/ 400; 400 frequencies in [0, 2π] num1 = [b1, zeros(1, D-1), -c1]; numerator coefficients den1 = [1, zeros(1, D-1), -a1]; denominator coefficients H1 = dtft(num1, omega) ./ dtft(den1, omega); frequency response magH1 = 20 * log10(abs(H1)); magnitude response angH1 = angle(H1) * 180 / pi; phase response in degrees num2 = [b2, zeros(1, D-1), -c2]; den2 = [1, zeros(1, D-1), -a2]; H2 = dtft(num2, omega) ./ dtft(den2, omega); magH2 = 20 * log10(abs(H2)); angH2 = angle(H2) * 180 / pi; x = [1, zeros(1, 199)]; length-200 unit impulse h1 = filter(num1, den1, x); impulse response w = zeros(1, D+1); (D+1)-dimensional state vector q = 0; circular pointer index for n=0:199, [y1(n+1), w, q] = combfilt(a1, b1, c1, D, w, q, x(n+1)); note: h1=y1 end The phase responses of the comb and notch filters and the impulse response of the comb are shown in Fig. P11.2. The canonical realization and the corresponding circular buffer version of the sample processing algorithm of the transfer function H(z)= b −cz −D 1 −az −D are given below: 234 Fig. P11.2 Phase responses and impulse response of Problem 11.8. for each input sample x do: s D = tap(D, w, p, D) s 0 = x +as D y = bs 0 −cs D ∗p = s 0 cdelay(D, w, &p) x y b a -c z -D s D s 0 The following C function combfilt.c is an implementation: /* combfilt.c - comb filtering with circular buffer */ void cdelay(); double tap(); double combfilt(a, b, c, D, w, p, x) double a, b, c, *w, **p, x; p passed by address as in cfir.c int D; { double s0, sD, y; sD = tap(D, w, *p, D); Dth tap output s0 = x + a * sD; input to D-fold delay y = b * s0 - c * sD; output sample **p = s0; update circular delay line cdelay(D, w, p); return y; } The MATLAB version is the function combfilt.m given below: % combfilt.m - comb filtering with circular buffer % % [y, w, q] = combfilt(a, b, c, D, w, q, x); % % The filter parameters [a, b, c] can be obtained from combeq.m 235 % % It uses cdelay2.m, wrap2.m, tap2.m % based on combfilt.c function [y, w, q] = combfilt(a, b, c, D, w, q, x) sD = tap2(D, w, q, D); s0 = x + a * sD; y = b * s0 - c * sD; w(q+1) = s0; q = cdelay2(D, q); It uses the following routine tap2.m that helps extract the components of the circular internal state vector: % tap2.m - read ith tap of circular delay-line buffer % % si = tap2(D, w, q, i) % % w = (D+1)-dimensional % q = circular index into w % delay amount i = 0, 1, . . . , D % based on tap2.c function si = tap2(D, w, q, i) si = w(rem(q+i, D+1)+1); % s i is delayed output s(n −i) Problem 11.9 In the FIR case of designing a lowpass filter, the limits 1 :δ pass and :δ stop represent the ripples of the (real-valued) frequency response D(ω). These translate to the limits for the magnitude response 1 :δ pass in the passband and [0, δ stop ] in the stopband. In the IIR case, the definitions are motivated by the closed-form expressions of the magnitude response squared in the Butterworth and Chebyshev cases. Problem 11.10 Because Ω stop > Ω pass , and N ≥ N exact , we have the inequality _ Ω stop Ω pass _ 2N > _ Ω stop Ω pass _ 2Nexact = ε 2 stop ε 2 pass ⇒ 1 +ε 2 pass _ Ω stop Ω pass _ 2N > 1 +ε 2 stop Thus, using Eq. (11.6.14) we have: A(Ω stop )= 10log 10 ⎡ ⎣ 1 +ε 2 pass _ Ω stop Ω pass _ 2N ⎤ ⎦ > 10log 10 (1 +ε 2 stop )= A stop Similarly, if we fix Ω 0 by the stopband specification, then we have: _ Ω pass Ω stop _ 2N < _ Ω pass Ω stop _ 2Nexact = ε 2 pass ε 2 stop ⇒ 1 +ε 2 stop _ Ω pass Ω stop _ 2N < 1 +ε 2 pass Then, using Eq. (11.6.15), we have: 236 A(Ω pass )= 10log 10 ⎡ ⎣ 1 +ε 2 stop _ Ω pass Ω stop _ 2N ⎤ ⎦ < 10log 10 (1 +ε 2 pass )= A pass Thus, in either case, the specifications are more than satisfied. Problem 11.11 The call to the MATLAB function lhbutt.m: [A, B, P] = lhbutt(1, 40, 10, 15, 3, 35); produces the following cascade matrices B = ⎡ ⎢ ⎣ 0.5001 0.5001 0 0.3821 2 ×0.3821 0.3821 0.2765 2 ×0.2765 0.2765 ⎤ ⎥ ⎦, A = ⎡ ⎢ ⎣ 1 0.0002 0 1 0.0007 0.5279 1 0.0005 0.1056 ⎤ ⎥ ⎦ Thus, the designed transfer function will be: H(z)= 0.5001(1 +z −1 ) 1 +0.0002z −1 · 0.3821(1 +z −1 ) 2 1 +0.0007z −1 +0.5279z −2 · 0.2765(1 +z −1 ) 2 1 +0.0005z −1 +0.1056z −2 The parameter vector P is: P = [Ω pass , Ω stop , ε pass , ε stop , N exact , N, A stop , Ω 0 , f 0 ] = [1, 2.4142, 0.9976, 56.2252, 4.57, 5, 38.26, 1.0005, 10.0030] where A stop is the actual stopband attenuation realized by the designed filter, and f 0 is the 3- dB cutoff frequency. The apparent discrepancy between the computed 3-dB frequency and the given 3-dB passband specification is accounted for from the fact that the 3-dB frequency Ω 0 or f 0 is defined to be the frequency where the magnitude squared response drops to one-half its DC value; this is almost a 3-dB drop, but not exactly. By hand, the design is as follows. First, we prewarp the physical frequencies: Ω pass = tan _ ω pass 2 _ = tan _ πf pass f s _ = tan _ π10 40 _ = tan(0.25π)= 1 Ω stop = tan _ ω stop 2 _ = tan _ πf stop f s _ = tan _ π15 40 _ = tan(0.375π)= 2.4142 Then, we compute the -parameters: ε pass = _ 10 Apass/10 −1 = _ 10 3/10 −1 = 0.9976, ε stop = _ 10 Astop/10 −1 = _ 10 35/10 −1 = 56.2252 and the exact and up-rounded value of N: N exact = ln(ε stop /ε pass ) ln(Ω stop /Ω pass ) = ln(56.2252/0.9976) ln(2.4142/1.0000) = 4.57, N = 5 Then, we calculate the 3-dB Butterworth parameter Ω 0 and invert it to get the 3-dB frequency f 0 : Ω 0 = Ω pass ε 1/N pass = 1 (0.9976) 1/5 = 1.0005, f 0 = f s π arctan(Ω 0 )= 1.0030 kHz 237 The coefficients of the 2nd-order sections are computed by Eq. (11.6.24). Note that because of the small discrepancy mentioned above, Ω 0 is not exactly equal to unity, and therefore, the a 1 coefficients of all the sections will not be exactly zero. The Butterworth angles are computed by θ i = π 2N (N−1 +2i)= π 10 (4 +2i), i = 1, 2 which gives θ 1 = 0.6π, θ 2 = 0.8π Problem 11.12 The call to lhbutt.m: [A, B, P] = lhbutt(-1, 10, 3, 2, 0.5, 35); produces the following cascade matrices B = _ 0.3414 −2 ×0.3414 0.3414 0.2454 −2 ×0.2454 0.2454 _ , A = _ 1 0.0817 0.4471 1 0.0587 0.0404 _ Thus, the designed transfer function will be: H(z)= 0.3414(1 −z −1 ) 2 1 +0.0817z −1 +0.4471z −2 · 0.2454(1 −z −1 ) 2 1 +0.0587z −1 +0.0404z −2 The parameter vector P is: P = [Ω pass , Ω stop , ε pass , ε stop , N exact , N, A stop , Ω 0 , f 0 ] = [0.7265, 1.3764, 0.3493, 3.0000, 3.37, 4, 13.27, 0.9451, 2.5899] where A stop is the actual stopband attenuation realized by the designed filter, and f 0 is the 3-dB cutoff frequency in kHz. The required closed-form expression for part (c) is: ¦H(ω)¦ 2 = 1 1 + _ cot(ω/2) Ω 0 _ 2N Problem 11.13 The real part of s can be expressed as follows: Re s = 1 2 (s +s ∗ )= z 2 −2cz +1 2(z 2 −1) + z ∗2 −2cz ∗ +1 2(z ∗2 −1) = (z 2 −2cz +1)(z ∗2 −1)+(z ∗2 −2cz ∗ +1)(z 2 −1) 2(z 2 −1)(z 2 −1) ∗ = ¦z¦ 4 −1 −c(z +z ∗ )(¦z¦ 2 −1) ¦z 2 −1¦ 2 = (¦z¦ 2 −1)(¦z¦ 2 −c(z +z ∗ )+1) ¦z 2 −1¦ 2 where in the last step we factored ¦z¦ 4 − 1 = (¦z¦ 2 − 1)(¦z¦ 2 + 1). Because ¦c¦ ≤ 1, the second factor of the numerator is non-negative. Indeed, noting that (z +z ∗ ) is real-valued, we have: ¦c(z +z ∗ )¦ ≤ ¦z +z ∗ ¦ ≤ ¦z¦ +¦z ∗ ¦ = 2¦z¦ ⇒ −2¦z¦ ≤ c(z +z ∗ )≤ 2¦z¦ Adding ¦z¦ 2 +1 to both sides we get the inequality: ¦z¦ 2 −2¦z¦+1 ≤ ¦z¦ 2 −c(z+z ∗ )+1 ≤ ¦z¦ 2 +2¦z¦+1 ⇒ 0 ≤ (¦z¦−1) 2 ≤ ¦z¦ 2 −c(z+z ∗ )+1 ≤ (¦z¦+1) 2 Therefore, the sign of Re s is the same as the sign of the factor (¦z¦ 2 −1), and the desired result follows. 238 Problem 11.14 Using a trig identity, we obtain: ¦ sin(ω 1 +ω 2 )¦ = ¦ sinω 1 cos ω 2 +sinω 2 cos ω 1 ¦ ≤ ¦ sinω 1 ¦¦ cos ω 2 ¦ +¦ sinω 2 ¦¦ cos ω 1 ¦ ≤ ¦ sinω 1 ¦ +¦ sinω 2 ¦ = sinω 1 +sinω 2 where we used the inequalities ¦ cos ω 1 ¦ ≤ 1 and ¦ cos ω 2 ¦ ≤ 1 and the fact that sinω 1 and sinω 2 are non-negative for values of their arguments in the range [0, π]. Thus, the above inequality implies ¦c¦ ≤ 1. Problem 11.15 Here, the Butterworth filter order is given to be N = 3. Thus, there remains only the parameter Ω 0 to be fixed. The normalized passband frequencies are ω pa = 2πf pa f s = 2π2 20 = 0.2π, ω pb = 2πf pb f s = 2π8 20 = 0.8π Because they add up to π, the bilinear transformation parameter c will be zero, as follows from the equation c = sin(ω pa +ω pb ) sinω pa +sinω pb = 0 Thus, the bilinear transformation will be here: s = 1 +z −2 1 −z −2 The analog passband frequency will be: Ω pass = c −cos ω pb sinω pb = −cot ω pb = 1.3764 The ε pass parameter is calculated to be: ε pass = _ 10 Apass/10 −1 = _ 10 0.5/10 −1 = 0.3493 which implies for Ω 0 : Ω 0 = Ω pass ε 1/N pass = 1.3764 0.3493 1/3 = 1.9543 The coefficients of the second- and fourth-order digital filter sections are calculated fromEqs. (11.6.43) and (11.6.41), where the there is only one Butterworth angle, namely, θ 1 = π 2N (N−1 +2)= 2π 3 ⇒ cos θ 1 = −0.5 We find for the second-order section: G 0 = 0.6615, a 01 = 0, a 02 = −0.3230 and the fourth-order section: G 1 = 0.5639, a 11 = 0, a 12 = −0.8325, a 13 = 0, a 14 = 0.4230 resulting in the transfer function: H(z)= 0.6615(1 −z −2 ) 1 −0.3230z −2 · 0.5639(1 −z −2 ) 2 1 −0.8325z −2 +0.4230z −4 The 3-dB frequencies are calculated from Eq. (11.6.44) with c = 0. We find: f 0a = 1.5054 kHz, f 0b = 8.4946 kHz 239 Problem 11.16 We have: 1 1 −2 s Ω 0 cos θ i + s 2 Ω 2 0 = Ω 2 0 Ω 2 0 −2sΩ 0 cos θ i +s 2 = Ω 2 0 Ω 2 0 −2 _ 1 −z −1 1 +z −1 _ Ω 0 cos θ i + _ 1 −z −1 1 +z −1 _ 2 = Ω 2 0 (1 +z −1 ) 2 Ω 2 0 (1 +z −1 ) 2 −2(1 −z −1 )(1 +z −1 )Ω 0 cos θ i +(1 −z −1 ) 2 = Ω 2 0 (1 +z −1 ) 2 Ω 2 0 (1 +2z −1 +z −2 )−2(1 −z −2 )Ω 0 cos θ i +(1 −2z −1 +z −2 ) = Ω 2 0 (1 +z −1 ) 2 (1 −2Ω 0 cos θ i +Ω 2 0 )+2(Ω 2 0 −1)z −1 +(1 +2Ω 0 cos θ i +Ω 2 0 )z −2 = G i (1 +z −1 ) 2 1 +a i1 z −1 +a i2 z −2 where the final result was obtained by dividing numerator and denominator by the factor (1 − 2Ω 0 cos θ i +Ω 2 0 ) in order to make the constant coefficient of the denominator unity. The highpass case is obtained by replacing z −1 by −z −1 , which effectively changes the sign of the a i1 coefficient. The bandpass case can be done in a similar, but more tedious, fashion. Problem 11.17 The right 3-dB frequency is obtained by solving the equation c −cos ω 0b sinω 0b = Ω 0 Using the trig identities cos ω 0b = 1 −tan 2 (ω 0b /2) 1 +tan 2 (ω 0b /2) , sinω 0b = 2tan(ω 0b /2) 1 +tan 2 (ω 0b /2) The above equation reduces to the quadratic equation in the variable t = tan(ω 0b /2): c − 1 −t 2 1 +t 2 2t 1 +t 2 = Ω 0 ⇒ (1 +c)t 2 −2Ω 0 t −(1 −c)= 0 which has positive solution: t = Ω 0 + _ Ω 2 0 +(1 −c)(1 +c) 1 +c implying for the 3-dB frequency tan _ ω 0b 2 _ = tan _ πf 0b f s _ = _ Ω 2 0 +1 −c 2 +Ω 0 1 +c ⇒ f 0b = f s π arctan ⎛ ⎜ ⎝ _ Ω 2 0 +1 −c 2 +Ω 0 1 +c ⎞ ⎟ ⎠ The left 3-dB frequency is obtained by replacing Ω 0 by −Ω 0 in the above solution. 240 Problem 11.18 Matching the stopband specifications exactly means that the stopband frequencies ω sa , ω sb map onto :Ω stop and that at Ω stop the attenuation is exactly A stop . The first requirement implies −Ω stop = c −cos ω sa sinω sa Ω stop = c −cos ω sb sinω sb which can be solve for c and Ω stop : c = sin(ω sa +ω sb ) sinω sa +sinω sb , Ω stop = ¸ ¸ ¸ ¸ c −cos ω sb sinω sb ¸ ¸ ¸ ¸ Given the value of c, we compute next the two candidates for Ω pass : Ω pa = c −cos ω pa sinω pa , Ω pb = c −cos ω pb sinω pb Ideally, we would like have Ω pb = Ω pass and Ω pa = −Ω pass . But this is impossible because c has already been fixed. Because the Butterworth magnitude response is a monotonically decreasing function of Ω, it is enough to choose the widest of the two passbands defined above. Thus, we define: Ω pass = max _ ¦Ω pa ¦, ¦Ω pb ¦ _ Once we have computed Ω pass and Ω stop , we design our Butterworth analog filter; that is, compute N and Ω 0 from N exact = ln(ε stop /ε pass ) ln(Ω stop /Ω pass ) , N = ¦N exact |, Ω 0 = Ω stop ε 1/N stop where the equation for Ω 0 matches the stopband specification exactly. The digital filter coef- ficients are then computed in terms of N and Ω 0 as usual. The following MATLAB function bpbutt2.m implements the above procedure and is an alternative to bpsbutt.m: % bpbutt2.m - bandpass Butterworth digital filter design % % [A, B, P] = bpbutt2(fs, fpa, fpb, fsa, fsb, Apass, Astop) % % alternative to bpsbutt.m % it matches stopbands and uses worst passband. % % design parameters: % P = [Wpass, Wstop, Wpa, Wpb, c, fc, epass, estop, Nex, N, Apass, W0, f0a, f0b]; % A,B are Kx5 matrices of cascade of 4th/2nd order sections function [A, B, P] = bpbutt2(fs, fpa, fpb, fsa, fsb, Apass, Astop) c = sin(2*pi*(fsa + fsb) / fs) / (sin(2*pi*fsa / fs) + sin(2*pi*fsb / fs)); fc = 0.5 * (fs/pi) * acos(c); Wstop = abs((c - cos(2*pi*fsb / fs)) / sin(2*pi*fsb / fs)); Wpa = (c - cos(2*pi*fpa / fs)) / sin(2*pi*fpa / fs); Wpb = (c - cos(2*pi*fpb / fs)) / sin(2*pi*fpb / fs); 241 Wpass = max(abs(Wpa), abs(Wpb)); epass = sqrt(10.0^(Apass/10) - 1); estop = sqrt(10.0^(Astop/10) - 1); Nex = log(estop/epass) / log(Wstop/Wpass); N = ceil(Nex); r = rem(N,2); K = (N - r) / 2; W0 = Wstop * (estop^(-1/N)); Apass = 10 * log10(1 + (Wpass/W0)^(2*N)); f0a = (fs/pi) * atan((sqrt(W0^2 - c^2 + 1) - W0)/(c+1)); f0b = (fs/pi) * atan((sqrt(W0^2 - c^2 + 1) + W0)/(c+1)); P = [Wpass, Wstop, Wpa, Wpb, c, fc, epass, estop, Nex, N, Apass, W0, f0a, f0b]; if r==1, G = W0 / (1 + W0); a1 = -2 * c / (1 + W0); a2 = (1 - W0) / (1 + W0); B(1,:) = G * [1, 0, -1, 0, 0]; A(1,:) = [1, a1, a2, 0, 0]; else B(1,:) = [1, 0, 0, 0, 0]; A(1,:) = [1, 0, 0, 0, 0]; end for i=1:K, th = pi * (N - 1 + 2 * i) / (2 * N); D = 1 - 2 * W0 * cos(th) + W0^2; G = W0^2 / D; a1 = 4 * c * (W0 * cos(th) - 1) / D; a2 = 2 * (2*c^2 + 1 - W0^2) / D; a3 = - 4 * c * (W0 * cos(th) + 1) / D; a4 = (1 + 2 * W0 * cos(th) + W0^2) / D; B(i+1,:) = G * [1, 0, -2, 0, 1]; A(i+1,:) = [1, a1, a2, a3, a4]; end Similarly, the function bpcheb2a.m is an alternative to the bandpass Chebyshev type-2 design function bpcheb2.m: % bpcheb2a.m - alternative bandpass Chebyshev type 2 digital filter design % % [A, B, P] = bpcheb2a(fs, fpa, fpb, fsa, fsb, Apass, Astop) % % alternative to bpcheb2.m % matches stopbands instead of passbands % % design parameters: % P = [Wpass, Wstop, Wpa, Wpb, c, epass, estop, Nex, N, f3a, f3b, a]; % A, B are Kx5 matrices of cascade 4th/2nd order sections function [A, B, P] = bpcheb2a(fs, fpa, fpb, fsa, fsb, Apass, Astop) 242 c = sin(2*pi*(fsa + fsb) / fs) / (sin(2*pi*fsa / fs) + sin(2*pi*fsb / fs)); Wstop = abs((c - cos(2*pi*fsb / fs)) / sin(2*pi*fsb / fs)); Wpa = (c - cos(2*pi*fpa / fs)) / sin(2*pi*fpa / fs); Wpb = (c - cos(2*pi*fpb / fs)) / sin(2*pi*fpb / fs); Wpass = max(abs(Wpa), abs(Wpb)); epass = sqrt(10.0^(Apass/10) - 1); estop = sqrt(10.0^(Astop/10) - 1); Nex = acosh(estop/epass) / acosh(Wstop/Wpass); N = ceil(Nex); r = rem(N,2); K = (N - r) / 2; a = asinh(estop) / N; W3 = Wstop / cosh(acosh(estop)/N); f3a = (fs/pi) * atan((sqrt(W3^2 - c^2 + 1) - W3)/(c+1)); f3b = (fs/pi) * atan((sqrt(W3^2 - c^2 + 1) + W3)/(c+1)); P = [Wpass, Wstop, Wpa, Wpb, c, epass, estop, Nex, N, f3a, f3b, a]; W0 = sinh(a) / Wstop; if r==1, G = 1 / (1 + W0); a1 = -2 * c * W0 / (1 + W0); a2 = -(1 - W0) / (1 + W0); B(1,:) = G * [1, 0, -1, 0, 0]; A(1,:) = [1, a1, a2, 0, 0]; else B(1,:) = [1, 0, 0, 0, 0]; A(1,:) = [1, 0, 0, 0, 0]; end for i=1:K, th = pi * (N - 1 + 2 * i) / (2 * N); Wi = sin(th) / Wstop; % reciprocal of text D = 1 - 2 * W0 * cos(th) + W0^2 + Wi^2; G = (1 + Wi^2) / D; b1 = - 4 * c * Wi^2 / (1 + Wi^2); b2 = 2 * (Wi^2 * (2*c*c+1) - 1) / (1 + Wi^2); a1 = 4 * c * (W0 * cos(th) - W0^2 - Wi^2) / D; a2 = 2 * ((2*c*c + 1)*(W0^2 + Wi^2) - 1) / D; a3 = - 4 * c * (W0 * cos(th) + W0^2 + Wi^2) / D; a4 = (1 + 2 * W0 * cos(th) + W0^2 + Wi^2) / D; B(i+1,:) = G * [1, b1, b2, b1, 1]; A(i+1,:) = [1, a1, a2, a3, a4]; end 243 Problem 11.19 We work with the type-2 design since it has more complicated numerator. The transformation of the analog second-order sections is as follows: 1 +Ω i −2 s 2 1 −2Ω −1 0 cos θ i s +(Ω −2 0 +Ω i −2 )s 2 = (1 +z −1 ) 2 +Ω i −2 (1 −z −1 ) 2 (1 +z −1 ) 2 −2Ω −1 0 cos θ i (1 −z −1 )(1 +z −1 )+(Ω −2 0 +Ω i −2 )(1 −z −1 ) 2 = (1 +Ω i −2 )+2(1 −Ω i −2 )z −1 +(1 +Ω i −2 )z −2 (1 −2Ω −2 0 cos θ i +Ω −2 0 +Ω i −2 )+2(1 −Ω −2 0 −Ω i −2 )z −1 +(1 +2Ω −2 0 cos θ i +Ω −2 0 +Ω i −2 )z −2 = G i (1 +b i1 z −1 +z −2 ) 1 +a i1 z −1 +a i2 z −2 where the final step follows by dividing the numerator by the factor (1 +Ω i −2 ) and the denomi- nator by (1 −2Ω −2 0 cos θ i +Ω −2 0 +Ω i −2 ). Problem 11.20 The s-domain poles are s i = Ω pass sinha cos θ i +jΩ pass cosha sinθ i = Ω 0 cos θ i +jΩ i cosha It follows that ¦s i ¦ 2 = Ω 2 0 cos 2 θ i +Ω i 2 cosh 2 a = Ω 2 0 (1 −sin 2 θ i )+Ω i 2 (1 +sinh 2 a) = Ω 2 0 +Ω i 2 +(Ω 2 0 sin 2 θ i −Ω i 2 sinh 2 a)= Ω 2 0 +Ω i 2 where the last two terms canceled because Ω 0 sinθ i = Ω pass sinhasinθ i = Ω i sinha Problem 11.21 The following C functions sos4.c and cas4.c implement the sample-by-sample processing al- gorithm of the cascade of fourth-order sections: /* sos4.c - IIR filtering by single (canonical) fourth-order section */ double sos4(a, b, w, x) a, b, w are 5-dimensional double *a, *b, *w, x; a[0]= 1 always { double y; w[0] = x - a[1]*w[1] - a[2]*w[2] - a[3]*w[3] - a[4]*w[4]; y = b[0]*w[0] + b[1]*w[1] + b[2]*w[2] + b[3]*w[3] + b[4]*w[4]; w[4] = w[3]; could replace these updates by w[3] = w[2]; the single call to w[2] = w[1]; delay(4, w); w[1] = w[0]; return y; } and 244 /* cas4.c - IIR filtering in cascade of fourth-order sections */ double sos4(); single 4th-order section double cas4(K, A, B, W, x) int K; double **A, **B, **W, x; A, B, W are K×5 matrices { int i; double y; y = x; initial input to first SOS4 for (i=0; i<K; i++) y = sos4(A[i], B[i], W[i], y); output of ith section return y; final output from last SOS4 } The K ×5 matrices A and B are generated by the filter design MATLAB functions, such as bps- butt.m, bpcheb2.m, or bscheb2.m, and can be passed as inputs to the above C functions. This can be done by saving the A and B outputs of the MATLAB functions into ASCII files and then invoking the following filtering routine casfilt4.c which is analogous to casfilt.c of Problem 7.15 and which reads A and B dynamically from the command line: /* casfilt4.c - IIR filtering in cascade of fourth-order sections */ #include <stdlib.h> #include <stdio.h> #define MAX 64 initial allocation size double cas4(); void main(int argc, char **argv) { FILE *fpa, *fpb; coefficient files double **A, **B, **W, x, y; double *a; temporary coefficient array int M, K, i, j, m; int max = MAX, dmax = MAX; allocation and increment if (argc != 3) { fprintf(stderr, "Usage: casfilt4 A.dat B.dat <x.dat >y.dat\n"); exit(0); } if ((fpa = fopen(argv[1], "r")) == NULL) { fprintf(stderr, "Can’t open filter file: %s\n", argv[1]); exit(0); } if ((fpb = fopen(argv[2], "r")) == NULL) { fprintf(stderr, "Can’t open filter file: %s\n", argv[2]); exit(0); } a = (double *) calloc(max + 1, sizeof(double)); 245 for (M=0;; M++) { if (M == max) { max += dmax; a = (double *) realloc((char *) a, (max + 1) * sizeof(double)); } if (fscanf(fpa, "%lf", a + M) == EOF) break; } a = (double *) realloc((char *) a, (M + 1) * sizeof(double)); if (M%5 != 0) { fprintf(stderr, "all rows of A must be 5-dimensional"); exit(0); } else K = M / 5; number of SOS4 A = (double **) calloc(K, sizeof(double *)); allocate K rows B = (double **) calloc(K, sizeof(double *)); W = (double **) calloc(K, sizeof(double *)); states of each SOS4 for (i=0; i<K; i++) { A[i] = (double *) calloc(5, sizeof(double)); each row is 5-dim B[i] = (double *) calloc(5, sizeof(double)); W[i] = (double *) calloc(5, sizeof(double)); } for(i=0; i<K; i++) form A matrix for(j=0; j<5; j++) A[i][j] = a[5*i + j]; for(i=0; i<K; i++) read B matrix for(j=0; j<5; j++) fscanf(fpb, "%lf", B[i] + j); while(scanf("%lf", &x) != EOF) { process input samples y = cas4(K, A, B, W, x); printf("%lf\n", y); } } The MATLAB version of sos4 is as follows: % sos4.m - fourth order section % % [y, w] = sos4(b, a, w, x) % % b = [b0, b1, b2, b3, b4] = 5-dim numerator (row vector) % a = [1, a1, a2, a3, a4] = 5-dim denominator (row vector) % w = [w0, w1, w2, w3, w4] = 5-dim filter state (row vector) % x = scalar input % y = scalar output function [y, w] = sos4(b, a, w, x) w(1) = x - a(2:5) * w(2:5)’; y = b * w’; w = delay(4, w); The MATLAB version of cas4: 246 % cas4.m - cascade of fourth order sections % % [y, W] = cas4(K, B, A, W, x) % % B = Kx5 numerator matrix % A = Kx5 denominator matrix % W = Kx5 state matrix % x = scalar input % y = scalar output function [y, W] = cas4(K, B, A, W, x) y = x; for i = 1:K, [y, W(i,:)] = sos4(B(i,:), A(i,:), W(i,:), y); end The MATLAB version of casfilt4 for filtering of a long input vector is as follows. It is analogous to casfilt.m of Problem 7.15: % casfilt4.m - cascade of fourth-order sections % % y = casfilt4(B, A, x) % % B = Kx5 numerator matrix % A = Kx5 denominator matrix % x = row vector input % y = row vector output function y = casfilt4(B, A, x) [K, K1] = size(A); [N1, N] = size(x); W = zeros(K,5); for n = 1:N, [y(n), W] = cas4(K, B, A, W, x(n)); end Problem 11.22 The following MATLAB code designs the pairs of lowpass, highpass, bandpass, and bandstop Butterworth filters, and shows how to compute the phase response and impulse response of one of the filters (the first bandpass filter): Apass = -10*log10(0.98); stringent case Astop = -10*log10(0.02); [A1, B1, P1] = lhbutt(1, 20, 4, 5, 0.5, 10); lowpass [A2, B2, P2] = lhbutt(1, 20, 4, 5, Apass, Astop); lowpass [A3, B3, P3] = lhbutt(-1, 20, 5, 4, 0.5, 10); highpass [A4, B4, P4] = lhbutt(-1, 20, 5, 4, Apass, Astop); highpass [A5, B5, P5] = bpsbutt(1, 20, 2, 4, 1.5, 4.5, 0.5, 10); bandpass [A6, B6, P6] = bpsbutt(1, 20, 2, 4, 1.5, 4.5, Apass, Astop); bandpass 247 [A7, B7, P7] = bpsbutt(-1, 20, 1.5, 4.5, 2, 4, 0.5, 10); bandstop [A8, B8, P8] = bpsbutt(-1, 20, 1.5, 4.5, 2, 4, Apass, Astop); bandstop om = (0:199) * pi / 200; 200 frequencies in [0, π] a5 = cas2can(A5); bandpass case b5 = cas2can(B5); H5 = dtft(b5, om)./dtft(a5, om); frequency response argH5 = angle(H5) * 180 / pi; phase response (in degrees) x = [1, zeros(1, 99)]; length-100 unit impulse h5 = casfilt4(B5, A5, x); impulse response y5 = filter(b5, a5, x); conventional method. Note, y5=h5 The computed phase and impulse responses are shown in Fig. P11.3. Notice how the phase response is almost linear within its passband. Fig. P11.3 Phase and impulse responses of (the less stringent) bandpass filter of Problem 11.22. Problem 11.23 The following MATLAB code designs the pairs of lowpass, highpass, bandpass, and bandstop Chebyshev filters, and shows how to compute the phase response and impulse response of one of the filters (the first bandpass filter): Apass = -10*log10(0.98); stringent case Astop = -10*log10(0.02); [A1, B1, P1] = lhcheb1(1, 20, 4, 5, 0.5, 10); LP type 1 [A2, B2, P2] = lhcheb1(1, 20, 4, 5, Apass, Astop); LP type 1 [A3, B3, P3] = lhcheb1(-1, 20, 5, 4, 0.5, 10); HP type 1 [A4, B4, P4] = lhcheb1(-1, 20, 5, 4, Apass, Astop); HP type 1 [A5, B5, P5] = lhcheb2(1, 20, 4, 5, 0.5, 10); LP type 2 [A6, B6, P6] = lhcheb2(1, 20, 4, 5, Apass, Astop); LP type 2 [A7, B7, P7] = bpcheb2(20, 2, 4, 1.5, 4.5, 0.5, 10); BP type 2 [A8, B8, P8] = bpcheb2(20, 2, 4, 1.5, 4.5, Apass, Astop); BP type 2 248 [A9, B9, P9] = bscheb2(20, 1.5, 4.5, 2, 4, 0.5, 10); BS type 2 [A10, B10, P10] = bscheb2(20, 1.5, 4.5, 2, 4, Apass, Astop); BS type 2 om = (0:199) * pi / 200; 200 frequencies in [0, π] a7 = cas2can(A7); bandpass case b7 = cas2can(B7); H7 = dtft(b7, om) ./ dtft(a7, om); frequency response argH7 = angle(H7) * 180 / pi; phase response (in degrees) x = [1, zeros(1, 99)]; length-100 unit impulse h7 = casfilt4(B7, A7, x); impulse response y7 = filter(b7, a7, x); conventional method. Note, y7=h7 The computed phase and impulse responses are shown in Fig. P11.4. Note that the Chebyshev phase response is not as linear within its passband. Fig. P11.4 Phase and impulse responses of (the less stringent) bandpass filter of Problem 11.23. 249 Chapter 12 Problems Problem 12.1 The low-rate transfer functions, D i (z) and H i (z)= z −2 D i (z), corresponding to Eq. (12.4.2) will be: D 0 (z) = 1 D 1 (z) = −0.13z 2 +0.30z +0.90 −0.18z −1 D 2 (z) = −0.21z 2 +0.64z +0.64 −0.21z −1 D 3 (z) = −0.18z 2 +0.90z +0.30 −0.13z −1 H 0 (z) = z −2 H 1 (z) = −0.13 +0.30z −1 +0.90z −2 −0.18z −3 H 2 (z) = −0.21 +0.64z −1 +0.64z −2 −0.21z −3 H 3 (z) = −0.18 +0.90z −1 +0.30z −2 −0.13z −3 Setting z = ζ 4 and using Eq. (12.2.15), we obtain the transfer function D(ζ), which is recognized as the double-sided ζ-transform of the sequence d given in Eq. (12.4.1): D(ζ)=D 0 (ζ 4 )+ζ −1 D 1 (ζ 4 )+ζ −2 D 2 (ζ 4 )+ζ −3 D 3 (ζ 4 ) =1 +ζ −1 (−0.13ζ 8 +0.30ζ 4 +0.90 −0.18ζ −4 ) +ζ −2 (−0.21ζ 8 +0.64ζ 4 +0.64 −0.21ζ −4 ) +ζ −3 (−0.18ζ 8 +0.90ζ 4 +0.30 −0.13ζ −4 ) =1 +0.90(ζ +ζ −1 )+0.64(ζ 2 +ζ −2 )+0.30(ζ 3 +ζ −3 ) −0.18(ζ 5 +ζ −5 )−0.21(ζ 6 +ζ −6 )−0.13(ζ 7 +ζ −7 ) Problem 12.2 In this case, L = 2 and we choose M = 2, so that N = 2LM+1 = 9. The ideal impulse response is: d(k ¹ )= sin(πk ¹ /2) πk ¹ /2 , −4 ≤ k ¹ ≤ 4 or, numerically, h = d = [0, −0.21, 0, 0.64, 1, 0.64, 0, −0.21, 0 ] It is depicted in Fig. P12.1. The two polyphase subfilters are defined by Eq. (12.2.10), that is, for i = 0, 1, d i (k)= d(2k +i), −2 ≤ k ≤ 1 They can be extracted from h by taking every second entry, starting with the ith entry: h 0 = d 0 = [0, 0, 1, 0] h 1 = d 1 = [−0.21, 0.64, 0.64, −0.21] 250 0 4 -4 2 -2 1 -1 3 -3 d(k′) k′ 1 0.64 0.64 -0.21 -0.21 L=2, M=2, N=9 Fig. P12.1 Length-9 symmetric impulse response of 2-fold FIR interpolator. The interpolated samples between x(n)= x up (2n) and x(n+1)= x up (2n+2) are calculated from Eqs. (12.2.18). The two subfilters act on the time-advanced (by M = 2) low-rate input samples ¦x(n + 2), x(n + 1), x(n), x(n − 1)¦, or, ¦x up (2n + 4), x up (2n + 2), x up (2n), x up (2n − 2)¦. Equations (12.2.18) can be cast in a compact matrix form: _ y up (2n) y up (2n +1) _ = _ 0 0 1 0 −0.21 0.64 0.64 −0.21 _ ⎡ ⎢ ⎢ ⎢ ⎣ x up (2n +4) x up (2n +2) x up (2n) x up (2n −2) ⎤ ⎥ ⎥ ⎥ ⎦ These filtering equations can also be obtained by superimposing the symmetric impulse response of Fig. P12.1 on each of the contributing low-rate samples ¦x up (2n +4), x up (2n +2), x up (2n), x up (2n −2)¦ and adding up their contributions at each of the intermediate sampling instants 2n +i, i = 0, 1, as shown in Fig. P12.2. x up (2n-2) 2n-2 x up (2n+2) y up (2n+1) 2n+2 x up (2n+4) 2n+4 x up (2n) 2n n′ Fig. P12.2 Superposition of impulse responses. The Hamming windowed version of the filter is obtained by multiplying the full length-9 filter response h by a length-9 Hamming window. The resulting impulse response will be: h = [0, −0.05, 0, 0.55, 1, 0.55, 0, −0.05, 0 ] The corresponding polyphase subfilters are obtained by extracting every second entry: h 0 = [0, 0, 1, 0] h 1 = [−0.05, 0.55, 0.55, −0.05] 251 The interpolation equations will be in this case: _ y up (2n) y up (2n +1) _ = _ 0 0 1 0 −0.05 0.55 0.55 −0.05 _ ⎡ ⎢ ⎢ ⎢ ⎣ x up (2n +4) x up (2n +2) x up (2n) x up (2n −2) ⎤ ⎥ ⎥ ⎥ ⎦ Problem 12.3 For the case of a 3-fold interpolator, we have L = 3 and choose again M = 2, corresponding to filter length N = 2LM+1 = 13. The ideal impulse response is: d(k ¹ )= sin(πk ¹ /3) πk ¹ /3 , −6 ≤ k ¹ ≤ 6 or, numerically, h = d = [0, −0.17, −0.21, 0, 0.41, 0.83, 1, 0.83, 0.41, 0, −0.21, −0.17, 0] where h is the causal version, with time origin at the left of the vector, and d is the symmetric one, with time origin at the middle of the vector. This impulse response is shown in Fig. P12.3. The three polyphase subfilters are defined by Eq. (12.2.10), that is, for i = 0, 1, 2, d i (k)= d(3k +i), −2 ≤ k ≤ 1 They can be extracted from h by taking every third entry, starting with the ith entry: h 0 = d 0 = [0, 0, 1, 0] h 1 = d 1 = [−0.17, 0.41, 0.83, −0.21] h 2 = d 2 = [−0.21, 0.83, 0.41, −0.17] The interpolated samples between x(n)= x up (3n) and x(n + 1)= x up (3n + 3) are calculated from Eqs. (12.2.18). 0 5 -5 4 -4 2 -2 1 -1 6 -6 3 -3 d(k′) k′ 1 0.83 0.83 0.41 0.41 -0.17 -0.17 -0.21 -0.21 L=3, M=2, N=13 Fig. P12.3 Length-13 symmetric impulse response of 3-fold FIR interpolator. All three subfilters act on the time-advanced (by M = 2) low-rate input samples ¦x(n+2), x(n+1), x(n), x(n −1)¦, or, ¦x up (3n +6), x up (3n +3), x up (3n), x up (3n −3)¦. Equations (12.2.18) can be cast in a compact matrix form: ⎡ ⎢ ⎣ y up (3n) y up (3n +1) y up (3n +2) ⎤ ⎥ ⎦ = ⎡ ⎢ ⎣ 0 0 1 0 −0.17 0.41 0.83 −0.21 −0.21 0.83 0.41 −0.17 ⎤ ⎥ ⎦ ⎡ ⎢ ⎢ ⎢ ⎣ x up (3n +6) x up (3n +3) x up (3n) x up (3n −3) ⎤ ⎥ ⎥ ⎥ ⎦ 252 These filtering equations can also be obtained by superimposing the symmetric impulse response of Fig. P12.3 on each of the contributing low-rate samples ¦x up (3n +6), x up (3n +3), x up (3n), x up (3n −3)¦ and adding up their contributions at each of the intermediate sampling instants 3n+i, i = 0, 1, 2, as shown in Fig. P12.4. x up (3n-3) 3n-3 x up (3n+3) y up (3n+1) 3n+3 x up (3n+6) 3n+6 x up (3n) 3n n′ Fig. P12.4 Superposition of impulse responses. The Hamming windowed version of the filter is obtained by multiplying the full length-13 filter response h by a length-13 Hamming window. The resulting impulse response will be: h = [0, −0.02, −0.06, 0, 0.32, 0.78, 1, 0.78, 0.32, 0, −0.06, 0.02, 0] The corresponding polyphase subfilters are obtained by extracting every third entry: h 0 = [0, 0, 1, 0] h 1 = [−0.02, 0.32, 0.78, −0.06] h 2 = [−0.06, 0.78, 0.32, −0.02] The interpolation equations will be in this case: ⎡ ⎢ ⎣ y up (3n) y up (3n +1) y up (3n +2) ⎤ ⎥ ⎦ = ⎡ ⎢ ⎣ 0 0 1 0 −0.02 0.32 0.78 −0.06 −0.06 0.78 0.32 −0.02 ⎤ ⎥ ⎦ ⎡ ⎢ ⎢ ⎢ ⎣ x up (3n +6) x up (3n +3) x up (3n) x up (3n −3) ⎤ ⎥ ⎥ ⎥ ⎦ Problem 12.4 For interpolation factor L = 4 and filter length N = 25, we find: N = 2LM+1 ⇒ M = (N−1)/2L = (25 −1)/8 = 3 Thus, we use 3 low-rate samples above and three below every interpolated value to be computed. The length-25 ideal interpolation impulse response is calculated from: d(k ¹ )= sin(πk ¹ /4) πk ¹ /4 , for −12 ≤ k ¹ ≤ 12 This generates the numerical values: 253 d = [ 0.000, 0.082, 0.127, 0.100, 0.000, −0.129, −0.212, −0.180, 0.000, 0.300, 0.637, 0.900, 1.000, 0.900, 0.637, 0.300, 0.000, −0.180, −0.212, −0.129, 0.000, 0.100, 0.127, 0.082, 0.000 ] This impulse response is shown in Fig. P12.5 (where the values have been rounded to 2-digit accuracy for convenience.) 0 4 -4 2 -2 1 -1 3 -3 d(k′) k′ 1 0.90 0.90 0.64 0.64 0.30 -0.18 -0.21 -0.13 12 -12 0.13 0.10 0.08 0.13 0.10 0.08 -0.13 -0.21 -0.18 0.30 L=4, M=3, N=25 Fig. P12.5 Length-25 symmetric impulse response of 4-fold FIR interpolator. Given 2M = 6 low-rate samples ¦A, B, C, D, E, F¦ as shown in Fig. 12.1.11, the three values ¦X, Y, Z¦ interpolated between C and D are calculated by convolving d with the upsampled low-rate samples. Using the flip-and-slide form of convolution as in Fig. 12.4.3, we position the impulse response d at the three successive positions, read off the values of d(k ¹ ) where it inter- sects with the low-rate samples, and add up the results. This procedure is shown in Fig. P12.6. The corresponding linear combinations of low-rate samples are precisely those of Eq. (12.1.3). They may be rewritten in the polyphase matrix form (with the low-rate samples listed from the latest down to the earliest): ⎡ ⎢ ⎣ X Y Z ⎤ ⎥ ⎦ = ⎡ ⎢ ⎣ 0.082 −0.129 0.300 0.900 −0.180 0.100 0.127 −0.212 0.637 0.637 −0.212 0.127 0.100 −0.180 0.900 0.300 −0.129 0.082 ⎤ ⎥ ⎦ ⎡ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎣ F E D C B A ⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎦ Problem 12.5 The ideal 3-fold interpolation case with M = 2, so that N = 2LM+ 1 = 2 · 3 · 2 + 1 = 13, was discussed in Problem 12.3. For the linear interpolator, using Eq. (12.3.7), we have: ⎡ ⎢ ⎣ y up (3n) y up (3n +1) y up (3n +2) ⎤ ⎥ ⎦ = ⎡ ⎢ ⎣ 0 0 1 0 0 1/3 2/3 0 0 2/3 1/3 0 ⎤ ⎥ ⎦ ⎡ ⎢ ⎢ ⎢ ⎣ x(n +2) x(n +1) x(n) x(n −1) ⎤ ⎥ ⎥ ⎥ ⎦ = _ 1/3 2/3 2/3 1/3 __ x(n +1) x(n) _ Problem 12.6 The following complete C program interp.c implements the polyphase sample-by-sample pro- cessing algorithm of Eq. (12.2.20) and the initialization procedure of (12.2.19): 254 n′ A B C D X E F 0.90 0.30 0.10 0.08 -0.13 -0.18 n′ A B C D Y E F 0.64 0.64 0.13 0.13 -0.21 -0.21 n′ A B C D Z E F 0.30 0.90 0.08 0.10 -0.18 -0.13 Fig. P12.6 Interpolated values are calculated by the flip-and-slide form of convolution. /* interp.c - L-fold FIR interpolator (rectangular and Hamming window design) * * Usage: interp hamm L M < xlow.dat > yhigh.dat * * hamm = 0/1 for rectangular/Hamming window * L = interpolation factor * M = half-length of polyphase subfilters (length = 2M, order = P = 2M- 1) * xlow.dat = file containing low-rate input samples * yhigh.dat = file containing high-rate interpolated output samples */ #include <stdio.h> #include <math.h> #include <stdlib.h> void delay(); double dot(); double d(); ideal interpolation filter void main(int argc, char ** argv) { int i, n, L, M, P, hamm; double x, *y, *w, **h, pi = 4 * atan(1.0); if (argc != 4) { 255 fprintf(stderr,"\nUsage: interp hamm L M < xlow.dat > yhigh.dat\n\n"); fprintf(stderr,"where: hamm = 0/1 for rectangular/hamm window\n"); fprintf(stderr," L = interpolation factor\n"); fprintf(stderr," M = half-length of polyphase subfilters\n"); fprintf(stderr," xlow.dat = file for low-rate input samples\n"); fprintf(stderr," yhigh.dat = file for high-rate interpolated output samples\n"); exit(0); } hamm = atoi(argv[1]); L = atoi(argv[2]); M = atoi(argv[3]); P = 2*M - 1; polyphase filter order h = (double **) calloc(L, sizeof(double *)); allocate L subfilters for (i=0; i<L; i++) h[i] = (double *) calloc(2*M, sizeof(double)); each of length 2M y = (double *) calloc(L, sizeof(double)); allocate L polyphase outfprintf(stderr, w = (double *) calloc(2*M, sizeof(double)); allocate low-rate internal state for (i=0; i<L; i++) construct polyphase subfilters for (n=0; n<2*M; n++) if (hamm == 0) rectangular window h[i][n] = d(L, L*n+i-L*M); else Hamming window h[i][n] = d(L, L*n+i-L*M) * (0.54 - 0.46*cos((L*n+i)*pi/(L*M))); initialize by Eq. (12.2.19) for (i=M; i>=1; i--) initialize state w by reading scanf("%lf", w + i); first M low-rate input samples process by Eq. (12.2.20) while(scanf("%lf", &x) != EOF) { keep reading low-rate samples till EOF w[0] = x; for (i=0; i<L; i++) { y[i] = dot(P, h[i], w); ith interpolated output sample printf("%.12lf\n", y[i]); and write it into stdout } delay(P, w); update low-rate delay line } for (n=0; n<M; n++) { input-off transients w[0] = 0.0; zero input for (i=0; i<L; i++) { y[i] = dot(P, h[i], w); ith interpolated output sample printf("%.12lf\n", y[i]); and write it into stdout } delay(P, w); update low-rate delay line } } /* -------------------------------------------------------- */ /* d(L, k) - ideal L-fold interpolation coefficients */ 256 double d(L, k) int L, k; { double t, pi = 4 * atan(1.0); if (k == 0) d(0) = 1 return (1.0); else { if (k%L == 0) d(k) vanishes at non-zero multiples of L return (0.0); else { t = pi * k / L; return (sin(t)/t); typical sin x/x impulse response } } } The program has usage: interp hamm L M < xlow.dat > yhigh.dat where the parameter hamm specifies a Hamming or rectangular window, L is the interpolation factor, and M is the half-length of the polyphase subfilters, so that the total filter length is N = 2LM+1. The program designs the windowed length-N interpolation filter and then reads the low-rate in- put samples sequentially from a file xlow.dat or stdin, computes the high-rate interpolated samples, and writes them to the file yhigh.dat or to the stdout. Each low-rate input generates L high-rate outputs. Inside the program, the rectangular and Hamming window design of the impulse response may be replaced easily by a Kaiser design. The program interp.c uses a linear-buffer version of the low-rate delay line used by all the polyphase subfilters. The following program cinterp.c is the circular-buffer version of in- terp.c: /* cinterp.c - circular-buffer version of interp.c */ #include <stdio.h> #include <math.h> #include <stdlib.h> void cdelay(), wrap(); double cdot(); circular version of dot.c double d(); ideal interpolation filter void main(int argc, char ** argv) { int i, n, L, M, P, hamm; double x, *y, *w, *p, **h, pi = 4 * atan(1.0); if (argc != 4) { fprintf(stderr,"\nUsage: cinterp hamm L M < xlow.dat > yhigh.dat\n\n"); fprintf(stderr,"where: hamm = 0/1 for rectangular/hamm window\n"); fprintf(stderr," L = interpolation factor\n"); fprintf(stderr," M = half-length of polyphase subfilters\n"); fprintf(stderr," xlow.dat = file for low-rate input samples\n"); 257 fprintf(stderr," yhigh.dat = file for high-rate interpolated output samples\n"); exit(0); } hamm = atoi(argv[1]); L = atoi(argv[2]); M = atoi(argv[3]); P = 2*M - 1; polyphase filter order h = (double **) calloc(L, sizeof(double *)); allocate L subfilters for (i=0; i<L; i++) h[i] = (double *) calloc(2*M, sizeof(double)); each of length 2M y = (double *) calloc(L, sizeof(double)); allocate L polyphase outfprintf(stderr, w = (double *) calloc(2*M, sizeof(double)); allocate low-rate internal state p = w; initialize circular pointer for (i=0; i<L; i++) construct polyphase subfilters for (n=0; n<2*M; n++) if (hamm == 0) rectangular window h[i][n] = d(L, L*n+i-L*M); else Hamming window h[i][n] = d(L, L*n+i-L*M) * (0.54 - 0.46*cos((L*n+i)*pi/(L*M))); initialize by Eq. (P12.1) for (i=M; i>=1; i--) { initialize state w by reading scanf("%lf", p); first M low-rate input samples cdelay(P, w, &p); } process by Eq. (P12.2) while(scanf("%lf", &x) != EOF) { keep reading low-rate samples till EOF *p = x; beginning of state vector for (i=0; i<L; i++) { y[i] = cdot(P, h[i], w, p); circular version of dot() printf("%.12lf\n", y[i]); and write it into stdout } cdelay(P, w, &p); update low-rate delay line } for (n=0; n<M; n++) { input-off transients *p = 0.0; zero input for (i=0; i<L; i++) { y[i] = cdot(P, h[i], w, p); circular version of dot() printf("%.12lf\n", y[i]); and write it into stdout } cdelay(P, w, &p); update low-rate delay line } } /* -------------------------------------------------------- */ /* d(L, k) - ideal L-fold interpolation coefficients */ double d(L, k) int L, k; 258 { double t, pi = 4 * atan(1.0); if (k == 0) d(0) = 1 return (1.0); else { if (k%L == 0) d(k) vanishes at non-zero multiples of L return (0.0); else { t = pi * k / L; return (sin(t)/t); typical sin x/x impulse response } } } /* -------------------------------------------------------- */ /* cdot(P, h, w, p) - circular version of dot.c */ double tap(); double cdot(P, h, w, p) computes dot product of h with double *h, *w, *p; current internal state vector int P; pointed to by pointer p { int i; double y; for (y=0, i=0; i<=P; i++) y += h[i] * tap(P, w, p, i); return y; } It uses a circular pointer p that circulates over the low-rate buffer w. The circular-buffer version of Eqs. (12.2.19) and (12.2.20), implemented by cinterp.c, can be stated as follows: for m= M down to m= 1 do: read low-rate input sample x ∗p = x cdelay(P, w, &p) (P12.1) and for each low-rate input sample x do: ∗p = x for m= 0, 1, . . . , P determine internal states: s m = tap(P, w, p, m) for i = 0, 1, . . . , L −1 compute output of ith filter: y i = dot(P, h i , s) cdelay(P, w, &p) (P12.2) The length-17 rectangular and Hamming windowed filters for this problemwere derived in Section 12.4.1. The given inputs were processed by interp.c. The upsampled versions of these inputs, x up (n ¹ ), are shown in Fig. P12.7 together with the corresponding interpolated output signals y up (n ¹ ), computed by the length-17 Hamming windowed version of the interpolation filter. 259 Fig. P12.7 Interpolation of triangular and sinusoidal signals. Problem 12.7 We start with f s = 40 kHz, Δf = 5 kHz, and A = 80 for all the stages. The effective single stage filter will have Kaiser length: N−1 = DL ΔF = 321.08 which is rounded up to: N = 337 = 2LM+1 = 16M+1 ⇒ M = 21 The 2×4 multistage filters, shown in Fig. P12.8, have Kaiser lengths: N 0 −1 = L 0 D ΔF = 80.27, N 1 −1 = DF 1 F 0 −1 = 8D 2 −1 = 40.14 and are rounded up to: N 0 = 85 = 2L 0 M 0 +1 = 4M 0 +1 ⇒ M 0 = 21 N 1 = 49 = 2L 1 M 1 +1 = 8M 1 +1 ⇒ M 1 = 6 The relative computational rate will be R multi R single = N 0 +N 1 F 0 N = 0.54 260 H 0 H 1 2f s 8f s f s 2 4 Fig. P12.8 2x4=8-fold oversampling filter. which compares well with the approximation: R multi R single = 1 L 1 + L 0 L 0 −1 ΔF = 0.50 Thus, the multistage realization requires only 54 percent the cost of the single-stage one. The combined filter H tot (f)= H 0 (f)H 1 (f) and the superimposed plots of the filters H 0 (f), H 1 (f) are shown in Fig. P12.9. Similarly, for the 4×2 case, shown in Fig. P12.10, we find the filter lengths: N 0 = 169, N 1 = 17 Fig. P12.9 Combined filter H 0 (f)H 1 (f), and individual filters H 0 (f), H 1 (f). H 0 H 1 4f s 8f s f s 2 4 Fig. P12.10 4x2=8-fold oversampling filter. The relative computational rate is in this case: R multi R single = N 0 +N 1 F 0 N = 0.70 The combined filter H tot (f)= H 0 (f)H 1 (f) and the superimposed plots of the filters H 0 (f), H 1 (f) are shown in Fig. P12.11. Initially, we designed the filters with stopband attenuations A 0 = A 1 = 80 dB. However, we found that in order to keep the overall stopband attenuation 261 below 80 dB, the attenuation of the second filter had to be increased to A 1 = 84 dB. This did not change the filter lengths, but it changed slightly the Kaiser parameters D 1 and α 1 for that factor. Finally, in the 2×2×2 case, shown in Fig. P12.12, we find the filter lengths Fig. P12.11 Combined filter H 0 (f)H 1 (f), and individual filters H 0 (f), H 1 (f). N 0 = 85, N 1 = 25, N 2 = 17 resulting in the relative computational rate R multi R single = N 0 +N 1 F 0 +N 2 F 1 N = 0.60 H 0 H 1 H 2 2f s 4f s f s 8f s 2 2 2 Fig. P12.12 2x2x2=8-fold oversampling filter. The combined filter H tot (f)= H 0 (f)H 1 (f)H 2 (f) and individual filters H 0 (f), H 1 (f), H 2 (f) are shown in Fig. P12.13. For reference, we also show in Fig. P12.14 the magnitude response of the single stage 8-fold oversampling filter. Again, the nominal attenuation of the last factor H 2 had to be increased to A 2 = 84 dB, whereas the first two were A 0 = A 1 = 80 dB. Problem 12.8 In units of f s = 44.1 kHz, the transition width from the edge of the passband to the edge of the stopband will be: ΔF = Δf f s = 24.1 −20 44.1 = 0.0930 The Kaiser window width parameter is D = (A − 7.95)/14.36 = (80 − 7.95)/14.36 = 5.0174. Thus, for a single-stage design with oversampling ratio L = 4, we find the Kaiser length: 262 Fig. P12.13 Combined filter H 0 (f)H 1 (f)H 2 (f), and individual filters H 0 (f), H 1 (f), H 2 (f). Fig. P12.14 Single-stage 8-fold oversampling filter. N−1 = DL ΔF = 5.0174 · 4 0.0930 = 215.803 ⇒ N = 217, M = (N−1)/(2L)= 27 The corresponding computational rate of the polyphase realization is R single = Nf s = 217 · 44.1 = 9569.7 MAC/msec = 9.5697 MIPS (assuming that each MAC is done with one instruction.) Thus, a 20-MIPS DSP chip can easily handle it. For the two-stage case, the design specifications are depicted in Fig. 12.2.9 of Section 12.2.5. Stage H 0 operating at 2f s will have the narrow transition width Δf = 4.1 kHz, or ΔF = 0.0930. This gives the Kaiser length: N 0 −1 = DL 0 ΔF = 5.0174 · 2 0.0930 = 107.9 ⇒ N 0 = 109, M 0 = (N 0 −1)/(2L 0 )= 27 The second stage H 1 will have a wider transition width Δf 1 = f s , or ΔF 1 = 1. Thus, the filter length will be: 263 N 1 −1 = DΔF 1 F 0 −1 = 5.0174 · 4 1.000 = 20.07 ⇒ N 1 = 25, M 1 = (N 1 −1)/(2L 1 )= 6 The polyphase computational rate of the two sections combined will be R multi = N 0 f s +N 1 (2f s )= 159f s = 159 · 44.1 = 7011.9 MAC/msec = 7.0119 MIPS Thus, the relative computational cost of the two-stage versus the single stage design will be: R multi R single = 159f s 217f s = 0.73 Problem 12.9 The frequency responses can be computed by the MATLAB code: f = (0:399) * 160 /400; 400 frequencies in [0,160] kHz f1 = 28; normalization frequency for Butterworth f2 = 16; normalization frequency for Bessel H1 = 1 ./ (1 + 2*j*(f/f1) - 2*(f/f1).^2 - j*(f/f1).^3); Butterworth H2 = 15 ./ (15 + 15*j*(f/f2) - 6*(f/f2).^2 - j*(f/f2).^3); Bessel magH1 = 20 * log10(abs(H1)); magH2 = 20 * log10(abs(H2)); argH1 = angle(H1) * 180 / pi; argH2 = angle(H2) * 180 / pi; The phase and magnitude responses are shown in Figs. P12.15 and P12.16. The Bessel phase response is essentially linear over the 0–20 kHz passband. But its magnitude response is not as flat as the Butterworth’s. Fig. P12.15 Phase responses of Bessel and Butterworth filters. 264 Fig. P12.16 Magnitude responses of Bessel and Butterworth filters. Problem 12.10 The filter H 0 has a cutoff frequency f c = f s /2. The linear, hold, and DAC magnitude responses (normalized to 0 dB at DC) are in the general and the particular case of L 0 = 4, L 1 = L 2 = 2: ¦H 1 (f)¦ = ¸ ¸ ¸ ¸ ¸ sin(πf/L 0 f s ) L 1 sin(πf/L 0 L 1 f s ) ¸ ¸ ¸ ¸ ¸ 2 = ¸ ¸ ¸ ¸ ¸ sin(πf/4f s ) 2sin(πf/8f s ) ¸ ¸ ¸ ¸ ¸ 2 ¦H 2 (f)¦ = ¸ ¸ ¸ ¸ ¸ sin(πf/L 0 L 1 f s ) L 2 sin(πf/L 0 L 1 L 2 f s ) ¸ ¸ ¸ ¸ ¸ = ¸ ¸ ¸ ¸ ¸ sin(πf/8f s ) 2sin(πf/16f s ) ¸ ¸ ¸ ¸ ¸ ¦H dac (f)¦ = ¸ ¸ ¸ ¸ ¸ sin(πf/L 0 L 1 L 2 f s ) πf/L 0 L 1 L 2 f s ¸ ¸ ¸ ¸ ¸ = ¸ ¸ ¸ ¸ ¸ sin(πf/16f s ) πf/16f s ¸ ¸ ¸ ¸ ¸ The filter H 0 operates at rate 4f s and cancels all the images at multiples of f s which are not multiples of 4f s . The linear interpolator H 1 operates at rate 8f s and vanishes at multiples of 4f s which are not multiples of 8f s . The filter H 2 operates at rate 16f s and vanishes at multiples of 8f s which are not multiples of 16f s . Finally, H dac vanishes at all non-zero multiples of 16f s . Thus, the combined effect of H 0 , H 1 , H 2 , and H dac is to (partially) remove all spectral images at multiples of f s . We note that the combined effect of the two hold transfer functions is an effective DAC operating at 8f s : ¦H 2 (f)H dac (f)¦ = ¸ ¸ ¸ ¸ ¸ sin(πf/L 0 L 1 f s ) L 2 sin(πf/L 0 L 1 L 2 f s ) ¸ ¸ ¸ ¸ ¸ · ¸ ¸ ¸ ¸ ¸ sin(πf/L 0 L 1 L 2 f s ) πf/L 0 L 1 L 2 f s ¸ ¸ ¸ ¸ ¸ = ¸ ¸ ¸ ¸ ¸ sin(πf/L 0 L 1 f s ) πf/L 0 L 1 f s ¸ ¸ ¸ ¸ ¸ = ¸ ¸ ¸ ¸ ¸ sin(πf/8f s ) πf/8f s ¸ ¸ ¸ ¸ ¸ The reason for using H 2 is that the higher the L, the more bits can be saved via the noise-shaping requantizer. Problem 12.11 The proof of the result may be seen graphically in Fig. P12.17 for the case L = 4. The ideal inter- polator has cutoff f s /2 and is periodic in f with period Lf s = 4f s . Thus, the passband replicates at multiples of 4f s . 265 4f s f 0 3f s 2f s -2f s -3f s -4f s f s -f s D(f -f s ) D(f) D(f -2f s ) D(f -3f s ) D(f ) + D(f -f s ) + D(f -2f s ) + D(f -3f s ) 4f s f 0 3f s 2f s -2f s -3f s -4f s f s -f s 4f s f 0 3f s 2f s -2f s -3f s -4f s f s -f s 4f s f 0 3f s 2f s -2f s -3f s -4f s f s -f s 4f s f 0 3f s 2f s -2f s -3f s -4f s f s -f s Fig. P12.17 Sum of successive shifts of ideal lowpass interpolator with L = 4 in Problem 12.11. The terms D(f −mf s ) correspond to the right shifts of D(f) centered at mf s . It is evident from the figure that the these shifted terms fill the gaps between the original replicas, resulting in a constant spectrum. The 1/L factor is needed to make the value of passband equal to unity. Thus, in the L = 4 case we have: 1 4 _ D(f)+D(f −f s )+D(f −2f s )+D(f −3f s ) _ = 1, for all f Problem 12.12 Writing k = Lk ¹ + m, m = 0, 1, . . . , L − 1, corresponds to the quotient and remainder of the division of k by L, and as such the integers ¦k ¹ , m¦ are uniquely determined by k. Therefore, we may change the summation over k into a double summation over k ¹ and m: X(f) = 1 T ∞ _ k=−∞ X a (f −kf s )= 1 T L−1 _ m=0 ∞ _ k ¹ =−∞ X a (f −(k ¹ L +m)f s ) = 1 T L−1 _ m=0 ∞ _ k ¹ =−∞ X a _ f −(k ¹ L +m)f s _ = 1 LT ¹ L−1 _ m=0 ∞ _ k ¹ =−∞ X a (f −mf s −k ¹ f s ¹ ) where we replaced T = LT ¹ and Lf s = f s ¹ . If in the definition of X ¹ (f) we replace f by f −mf s , we have: X ¹ (f −mf s )= 1 T ¹ ∞ _ k ¹ =−∞ X a (f −mf s −k ¹ f s ¹ ) Thus the k ¹ summation in the above double sum may be replaced by X ¹ (f −mf s ) resulting in the desired result: 266 X(f)= 1 L L−1 _ m=0 X ¹ (f −mf s ) If we use the variables ω and ω ¹ , then X(f) and X ¹ (f) are given by X(ω)= _ n x(n)e −jωn , X ¹ (ω ¹ )= _ n ¹ x ¹ (n ¹ )e −jω ¹ n ¹ The shifted frequency f −mf s is in units of ω ¹ : 2π(f −mf s ) f s ¹ = 2πf f s ¹ − 2πmf s Lf s = ω ¹ − 2πm L Thus, using ω ¹ = ω/L, we may write X(ω)= 1 L L−1 _ m=0 X ¹ _ ω ¹ − 2πm L _ = 1 L L−1 _ m=0 X ¹ _ ω−2πm)/L _ Problem 12.13 The discrete-time sampling function s ¹ (n ¹ ) consists of a periodic train of unit impulses at mul- tiples of L, that is, at n ¹ = nL, and separated by L − 1 zeros between. Thus, the product of s ¹ (n ¹ ) with x ¹ (n ¹ ) will insert such zeros. But at the sampling times n ¹ = nL we will have x up (n ¹ )= x ¹ (n ¹ )= x ¹ (nL)= x(n). Because of its periodicity in n ¹ with period L, the sampling function admits a DFS expansion, that is, and inverse DFT expansion of the form of Eq. (9.7.1): s ¹ (n ¹ )= 1 L L−1 _ m=0 S ¹ (ω ¹ m )e jω ¹ m n ¹ , ω ¹ m = 2π(mf s ) f s ¹ = 2π(mf s ¹ /L) f s ¹ = 2πm L = mth DFT frequency where S ¹ (ω ¹ m ) is the L-point DFT of s ¹ (n ¹ ) calculated from one period of s ¹ (n ¹ as follows: S ¹ (ω ¹ m )= L−1 _ n ¹ =0 s ¹ (n ¹ )e −jω ¹ m n ¹ But within the first period 0 ≤ n ¹ ≤ L −1, the sampling function acts as a unit impulse, s ¹ (n ¹ )= δ(n ¹ ). Therefore, the n ¹ -summation collapses to the term n ¹ = 0, which is unity: S ¹ (ω ¹ m )= 1, m= 0, 1, . . . , L −1 which gives for the inverse DFT: s ¹ (n ¹ )= 1 L L−1 _ m=0 e jω ¹ m n ¹ = 1 L L−1 _ m=0 e 2πjmn ¹ /L To transform the relationship x up (n ¹ )= s ¹ (n ¹ )x ¹ (n ¹ ) to the frequency domain, we replace s ¹ (n ¹ ) by its IDFT expression and use the modulation theorem of DTFTs to get: x up (n ¹ )= 1 L L−1 _ m=0 e jω ¹ m n ¹ x ¹ (n ¹ ) ⇒ X up (ω ¹ )= 1 L L−1 _ m=0 X ¹ (ω ¹ −ω ¹ m ) But we have seen in Eq. (12.2.21) that the upsampled spectrumis the same as the original low-rate spectrum, that is, X up (f)= X(f), or in units of ω and ω ¹ , X up (ω ¹ )= X(ω). It follows that X(ω)= X up (ω ¹ )= 1 L L−1 _ m=0 X ¹ (ω ¹ −ω ¹ m )= 1 L L−1 _ m=0 X ¹ _ ω ¹ − 2πm L _ 267 Problem 12.14 Starting with the filtering equation X ¹ (f)= D(f)X(f), we form the sum of shifted high-rate spectra: 1 L L−1 _ m=0 X ¹ (f −mf s )= 1 L L−1 _ m=0 D(f −mf s )X(f −mf s )= 1 L L−1 _ m=0 D(f −mf s )X(f)= X(f) where we used the periodicity of X(f) with period f s to write X(f − mf s )= X(f), and then we used the result of Problem 12.11 to replace the sum of shifted D(f)’s by unity. Problem 12.15 The attenuation of an Nth order Butterworth filter in dB is given by A(F)= 10log 10 _ 1 + _ F F 0 _ 2N _ where we used the normalized frequencies F = f/f s and F 0 = f 0 /f s . Given a required attenuation of A pass dB over the passband F pass = f pass /f s = (f s /2)/f s = 0.5, we obtain an equation for the 3-dB frequency F 0 : A pass = 10log 10 _ 1 + _0.5 F 0 _ 2N _ ⇒ F 0 = 0.5 _ 10 Apass/10 −1 _ 1/2N The prefilter’s stopband must begin at F stop = f stop /f s = (Lf s − f s /2)/f s = L − 0.5. Thus, the stopband attenuation will be A stop = 10log 10 _ 1 + _L −0.5 F 0 _ 2N _ ⇒ L = 0.5 +F 0 _ 10 Astop/10 −1 _ 1/2N For large A stop we may ignore the −1 to get L = 0.5 +F 0 10 Astop/20N With the values A pass = 0.1 and N = 3, we find F 0 = 0.94. Fig. P12.18 shows a plot of L versus A stop . Fig. P12.18 Decimation ratio versus stopband attenuation in Problem 12.15. 268 Problem 12.16 Using the expression of the attenuation of Problem 12.15, we get at the passband and stopband normalized frequencies F pass = 0.5, F stop = L −0.5: A pass = 10log 10 _ 1 + _0.5 F 0 _ 2N _ A stop = 10log 10 _ 1 + _L −0.5 F 0 _ 2N _ ⇒ _ L −0.5 0.5 _ 2N = 10 Astop/10 −1 10 Apass/10 −1 which may be solved for N, giving: N = ln _ 10 Astop/10 −1 10 Apass/10 −1 _ 2ln(2L −1) Let N 0 = ceil(N). In order for the filter order to remain fixed at N 0 , the computed quantity N must be in the range N 0 −1 < ln _ 10 Astop/10 −1 10 Apass/10 −1 _ 2ln(2L −1) Solving this inequality for L, we find the limits on L: 0.5 +0.5 _ 10 Astop/10 −1 10 Apass/10 −1 _ 1/2N0 ≤ L < 0.5 +0.5 _ 10 Astop/10 −1 10 Apass/10 −1 _ 1/2(N0−1) ≤ N 0 For the given numerical values, we find N 0 = 3 and the range 9.86 ≤ L < 40.97, which gives the integer range 10 ≤ L ≤ 40. Problem 12.17 The normalized transition width is ΔF = Δf/f s = (24.41 − 20)/44.1 = 0.1. Using a Kaiser design, the transition width parameter D and filter length N will be: D = A−7.95 14.36 = 95 −7.95 14.36 = 6.0620, N−1 = DL ΔF = 6.062 · 160 0.1 = 9699.2 ⇒ N = 9920 where the final N is of the form N = 2LK + 1 = 320K + 1 with K = 31. Thus, the interpola- tion/decimation filter operating at rate f s ¹¹ = 160f s = 147f s ¹ = 7.056 MHz can be implemented with 160 polyphase subfilters, each of length 2K = 62 and operating at a rate f s = 44.1 kHz. The overall sample rate conversion cost in MAC/sec can be calculated from Eq. (12.6.9): R = 2Kf s ¹ = 61f s ¹ = 61 · 48 = 2928 kMAC/sec = 2.928 MIPS The computational speed is easily handled by today’s DSP chips. Memory, however, to store the N FIR coefficients is high—of the order of 10k words. 269 Problem 12.18 Here, we have the conversion ratio f s ¹ = 32 = 32 48 · 48 = 2 3 f s , so that L = 2, M = 3. Because f s ¹ < f s , the filter’s cutoff frequency will be f c = f s ¹ /2 = 16 kHz. Assuming a :1 kHz transition width about f c , that is, Δf = 2 kHz, and a A = 60 dB stopband attenuation, we find the Kaiser parameter D and filter length N: D = A−7.95 14.36 = 60 −7.95 14.36 = 3.6247, N−1 = DLf s Δf = 3.6247 · 2 · 48 2 = 173.98 ⇒ N = 177 where we rounded N to the next odd integer of the form N = 2LK +1. Thus, K = 44, and there will be L = 2 polyphase subfilters of length 2K = 88. Fig. P12.19 shows the ideal specifications of such a filter. The filter operates at the fast rate f s ¹¹ = 3f s ¹ = 2f s = 96 kHz and acts as an antialiasing filter for the downsampler, that is, it removes the high frequencies from the input in the range [f s ¹ 2, f s /2]= [16, 24] kHz, so that the downshifted replicas—caused by the 3-fold downsampling operation—will not overlap. 0 0 f s ′ 2f s ′ 3f s ′ f s ′ 2f s ′ 3f s ′=f s ′′ 2f s =f s ′′ 0 f s 2f s f s 0 filter polyphase selector T′/3=T′′ T/2=T′′ 6T′′=3T=2T′ T x 0 x 1 x 2 y 0 y 1 t t t t f f f f T′ min(f s , f s ′ ) 1 2 0 1 i = Fig. P12.19 Ideal SRC filter with conversion ratio 2/3. Because T = T ¹¹ /2 and T ¹ = T ¹¹ /3, it follows that the basic block interval will be T block = 6T ¹¹ = 3T = 2T ¹ , containing 3 input-rate samples ¦x 0 , x 1 , x 2 ¦ and 2 output-rate samples ¦y 0 , y 1 ¦. The interpolated output y 1 that lies halfway between x 1 and x 2 is obtained by the polyphase filter h 1 . Indeed, the polyphase selector indices can be precomputed by i m = 3m%2 = [0, 1], for m= 0, 1 The sample processing algorithm of the 2/3 sample rate converter will be then: for each input block ¦x 0 , x 1 , x 2 ¦ do: w 0 = x 0 y 0 = dot(P, h 0 , w)= x 0 delay(P, w) w 0 = x 1 y 1 = dot(P, h 1 , w) delay(P, w) w 0 = x 2 delay(P, w) 270 where P = 2K − 1 is the order of the polyphase subfilters h 0 , h 1 , and w is the length-(P + 1) input-rate delay-line buffer. Note that there is no interpolated output after x 2 (the next two out- puts come from the next group of three inputs), and therefore, x 2 is simply read into the buffer w and the delay line is updated. For reference, we also show in Fig. P12.20 the reverse converter by a ratio 3/2, converting from 32 kHz up to 48 kHz. Here, the SRC filter acts as an anti-image filter for the upsampler. polyphase selector T′/2=T′′ T/3=T′′ 6T′′=2T=3T′ y 0 y 1 y 2 T x 0 x 1 t t t t f f f f T′ min(f s , f s ′ ) 1 2 0 2 1 i = f s 2f s 3f s =f s ′′ 0 f s 2f s 3f s 0 filter 0 f s ′ 2f s ′ 0 2f s ′=f s ′′ f s ′ Fig. P12.20 Ideal SRC filter with conversion ratio 3/2. In this case, we have f s ¹ = 3f s /2 = 3 · 32/2 = 48. The fast rate is f s ¹¹ = 2f s ¹ = 3f s = 96 kHz. The input- and output-rate sampling intervals are T = 3T ¹¹ and T ¹ = 2T ¹¹ , and the basic time block T block = 6T ¹¹ = 2T = 3T ¹ . Thus, every group of two input samples ¦x 0 , x 1 ¦ generates a group of three output samples ¦y 0 , y 1 , y 2 ¦. As can be seen in the figure, the polyphase selector sequence is i m = 2m%3 = [0, 2, 1], for m = 0, 1, 2. Therefore, the three interpolated outputs ¦y 0 , y 1 , y 2 ¦ will be computed by the subfilters ¦h 0 , h 2 , h 1 ¦. The corresponding sample processing algorithm will be: for each input block ¦x 0 , x 1 ¦ do: w 0 = x 0 y 0 = dot(P, h 0 , w)= x 0 y 1 = dot(P, h 2 , w) delay(P, w) w 0 = x 1 y 2 = dot(P, h 1 , w) delay(P, w) Problem 12.19 For the case L/M = 7/4, we have f s ¹ = 7f s /4 and f s ¹¹ = 4f s ¹ = 7f s , T ¹¹ = T ¹ /4 = T/7, T block = 28T ¹¹ = 7T ¹ = 4T. Fig. P12.21 depicts the operation of the converter both in the time and frequency domains. In the time domain, each input block of 4 input-rate samples ¦x 0 , x 1 , x 2 , x 3 ¦ generates 28 fast-rate interpolated samples, out of which 7 output-rate samples ¦y 0 , y 1 , y 2 , y 3 , y 4 , y 4 , y 6 ¦ are selected and computed according to their polyphase indices: 271 0 0 0 0 filter polyphase selector T′/4=T′′ T/7=T′′ 28T′′=4T=7T′ y 0 y 1 y 3 y 5 y 2 y 4 y 6 x 0 x 1 x 2 x 3 t t t t f f f f T′ T min(f s , f s ′ ) 1 2 0 4 1 2 5 6 3 i = f s 2f s 3f s 4f s 5f s 6f s 7f s =f s ′′ f s 2f s 3f s 4f s 5f s 6f s 7f s 4f s ′=f s ′′ 2f s ′ 3f s ′ f s ′ 4f s ′ 2f s ′ 3f s ′ f s ′ Fig. P12.21 Ideal SRC filter with conversion ratio 7/4. i m = 4m%7 = [0, 4, 1, 5, 2, 6, 3], for m= 0, 1, . . . , 6 n m = (4m−i m )/7 = [0, 0, 1, 1, 2, 2, 3] whenever the index n m is repeated, the input-rate polyphase delay line is not updated. The sample processing conversion algorithm is as follows: for each input block ¦x 0 , x 1 , x 2 , x 3 ¦ do: w 0 = x 0 y 0 = dot(P, h 0 , w)= x 0 y 1 = dot(P, h 4 , w) delay(P, w) w 0 = x 1 y 2 = dot(P, h 1 , w) y 3 = dot(P, h 5 , w) delay(P, w) w 0 = x 2 y 4 = dot(P, h 2 , w) y 5 = dot(P, h 6 , w) delay(P, w) w 0 = x 3 y 6 = dot(P, h 3 , w) delay(P, w) For example, the two output samples y 4 , y 5 lie between the input samples x 2 , x 3 and correspond to the i = 2 and i = 6 interpolated samples. The delay line is updated after both outputs are computed, and then the next input sample x 3 is read into the delay line, and so on. In the frequency domain, the SRC filter acts as an anti-image postfilter for the upsampler, remov- ing the L−1 = 6 replicas between multiples of the fast rate f s ¹¹ . The downshifting of the replicas caused by the downsampling operation will position replicas at the 3 multiples of the output rate f s ¹ , 2f s ¹ , and 3f s ¹ . 272 In the L/M = 4/7 case, we have f s ¹ = 4f s /7 and f s ¹¹ = 7f s ¹ = 4f s , T ¹¹ = T ¹ /7 = T/4, T block = 28T ¹¹ = 4T ¹ = 7T. Fig. P12.22 depicts the operation of the converter both in the time and frequency domains. 0 0 f s ′ 2f s ′ 3f s ′ 4f s ′ 5f s ′ 6f s ′ 7f s ′ f s ′ 2f s ′ 3f s ′ 4f s ′ 5f s ′ 6f s ′ 7f s ′=f s ′′ 4f s =f s ′′ 0 4f s 2f s 3f s f s 2f s 3f s f s 0 filter polyphase selector T′/7=T′′ T/4=T′′ 28T′′=7T=4T′ T x 0 x 1 x 3 x 5 x 2 x 4 x 6 y 0 y 1 y 2 y 3 t t t t f f f f T′ min(f s , f s ′ ) 1 2 0 3 2 1 i = Fig. P12.22 Ideal SRC filter with conversion ratio 4/7. In the time domain, each input block of 7 input-rate samples ¦x 0 , x 1 , x 2 , x 3 , x 4 , x 5 , x 6 ¦ generates 28 fast-rate interpolated samples, out of which 4 output-rate samples ¦y 0 , y 1 , y 2 , y 3 ¦ are selected and computed according to their polyphase indices: i m = 7m%4 = [0, 3, 2, 1], for m= 0, 1, . . . , 3 n m = (7m−i m )/4 = [0, 1, 3, 5] so that only the input samples x 0 , x 1 , x 3 , x 5 will produce output samples. However, for the remaining input samples the delay line must be updated. Thus, the sample processing conversion algorithm will be as follows: for each input block ¦x 0 , x 1 , x 2 , x 3 , x 4 , x 5 , x 6 ¦ do: w 0 = x 0 y 0 = dot(P, h 0 , w)= x 0 delay(P, w) w 0 = x 1 y 1 = dot(P, h 3 , w) delay(P, w) w 0 = x 2 delay(P, w) w 0 = x 3 y 2 = dot(P, h 2 , w) delay(P, w) w 0 = x 4 delay(P, w) w 0 = x 5 y 3 = dot(P, h 1 , w) delay(P, w) w 0 = x 6 delay(P, w) 273 In the frequency domain, the SRC filter acts as an antialiasing prefilter for the downsampler, re- moving the 3 replicas between multiples of the fast rate f s ¹¹ . The downshifting of the replicas caused by the downsampling operation will position replicas at the 6 multiples of the output rate f s ¹ , 2f s ¹ , . . . , 6f s ¹ , without overlapping. As a design example, consider the 4/7 case and assume a Kaiser design with a stopband attenu- ation of 80 dB and normalized transition width ΔF = Δf/f s = 0.1. The width parameter D and filter length N will be: D = A−7.95 14.36 = 80 −7.95 14.36 = 5.0174, N−1 = DL ΔF = 5.0174 · 4 0.1 = 200.70 ⇒ N = 209 where N the smallest odd integer of the form N = 2LK +1; here, K = 26. Problem 12.20 Atypical windowdepends on the time variable k through the ratio k/(N−1). The effective length of the stretched impulse response is N ρ − 1 = 2LK ρ = 2LK/ρ. A symmetric window of such length will depend on the variable k ¹¹ /(2LK ρ )= ρk ¹¹ /(2LK). Thus, the window of length 2LK ρ can be expressed in terms of the same window of length 2LK, via the stretching relationship w ρ (k ¹¹ )= w(ρk ¹¹ ). It follows that the corresponding windowed impulse responses will be w ρ (k ¹¹ )d ρ (k ¹¹ )= ρw(ρk ¹¹ )d(ρk ¹¹ ) Problem 12.21 The polyphase Kaiser filter can be designed by the code fragment: double *hd, **h, *w, *x, *y, wind, pi = 4 * atan(1.0); D = (A - 7.95) / 14.36; if (A > 50) alpha = 0.1102 * (A - 8.7); else if (A > 21) alpha = 0.5842 * pow(A-21, 0.4) + 0.07886 * (A-21); else alpha = 0; N = 1 + ceil(D*L / DF); Kaiser length K = ceil((N - 1) / (2.0*L)); round up N = 2*L*K + 1; final length P = 2*K - 1; polyphase filter order LK = L*K; filter delay hd = (double *) calloc(N, sizeof(double)); allocate direct form wc = pi / max(L, M); cutoff frequency I0alpha = I0(alpha); window normalization for (n=0; n<N; n++) compute filter if (n==LK) middle value hd[n] = L /(double) max(L, M); else { wind = I0(alpha * sqrt(n*(2.0*LK-n)) / LK) / I0alpha; 274 hd[n] = wind * L * (sin(wc*(n-LK))) / (pi*(n-LK)); } h = (double **) calloc(L, sizeof(double *)); allocate polyphase for (i = 0; i < L; i++) h[i] = (double *) calloc(P+1, sizeof(double)); i-th polyphase for (i=0; i<L; i++) define polyphase filters for (n=0; n<=P; n++) h[i][n] = hd[L*n+i]; Assuming the input data are being read from stdin, we allocate and initialize the polyphase delay-line buffer w as follows: w = (double *) calloc(P+1, sizeof(double)); allocate w for (i=K; i>=1; i--) read K input samples if (scanf("%lf", w+i) == EOF) { printf("must have at least K = %d input samples\n", K); exit(0); } Then, allocate the input/output blocks for the algorithm Eq. (12.6.13) and keep processing input samples in groups of M. The computed outputs go into stdout. Upon encountering the end- of-file of the inputs, we jump out of the for-ever loop and call Eq. (12.6.13) K/M more times with zero input samples. Because each call generates M zero inputs, the K/M calls will generate approximately M(K/M)= K zero inputs: x = (double *) calloc(M, sizeof(double)); y = (double *) calloc(L, sizeof(double)); for (;;) { for-ever do: for (n=0; n<M; n++) read M inputs if (scanf("%lf", x+n) == EOF) goto transients; src(L, M, P, h, w, x, y); compute L outputs for (m=0; m<L; m++) write L outputs printf("%.12lf\n", y[m]); } transients: for (i=0; i <= K/M; i++) { last K inputs for (n=0; n<M; n++) x[n] = 0; src(L, M, P, h, w, x, y); for (m=0; m<L; m++) printf("%.12lf\n", y[m]); } The sample processing algorithm (12.6.13) is implemented by the routine: /* src.c - sample rate converter processing algorithm */ #include <math.h> double dot(); 275 void delay(); void src(L, M, P, h, w, x, y) h is Lx(P+1) polyphase filter matrix double **h, *w, *x, *y; w is (P+1)-dimensional delay buffer { x,y are M- and L-dimensional vectors int n, m, i; double R = L / (double) M; conversion ratio for (n = 0; n < M; n++) { w[0] = x[n]; for (m = ceil(R*n); m <= floor(R*(n+1)); m++) { i = (M * m) % L; polyphase selector y[m] = dot(P, h[i], w); } delay(P, w); } } With the values A = 30 dB, ΔF = 0.1, the 5/3 filter has D = 1.536, α = 2.117, N = 81, K = 8, P = 2K − 1 = 15. The reverse 3/5 filter has the same D, α, K, and P, but its length is N = 49, because N = 2LK + 1, where now L = 3. The filter responses are shown in Fig. P12.23 both in absolute and dB scales. The dc gains are 5 and 3, respectively. The dB responses have been normalized to 0 dB at DC. Fig. P12.23 Frequency responses of SRC filters. Both filters have a cutoff frequency of f c = min(f s /2, f s ¹ /2)= 3/2 = 1.5 kHz, or, ω ¹¹ c = π/5. The passband ripple is δ = 10 −A/20 = 0.032. Their transition widths are different: the first filter has Δf = 0.1×3 = 0.3 kHz, and the second Δf = 0.1×5 = 0.5 kHz. Were they to be redesigned to have the same Δf, say 0.3 kHz, then for the 3/5 filter we would have ΔF = 0.06, resulting in the lengths N = 79, K = 13, P = 25. In that case, the filters would be virtually identical (except for the gain and the delay by 1 sample). The impulse responses are obtained from Eq. (12.6.5), with LK = 5×8 = 40 and LK = 3×8 = 24 in the two cases, that is, 276 h 5/3 (n ¹¹ )= 5 I 0 (α _ n ¹¹ (80 −n ¹¹ )/80) I 0 (α) sin _ π(n ¹¹ −40)/5 _ π(n ¹¹ −40) , n ¹¹ = 0, 1, . . . , 80 h 3/5 (n ¹¹ )= 3 I 0 (α _ n ¹¹ (48 −n ¹¹ )/48) I 0 (α) sin _ π(n ¹¹ −24)/5 _ π(n ¹¹ −24) , n ¹¹ = 0, 1, . . . , 48 The frequency responses were computed by direct evaluation of: H(f)= N−1 _ n ¹¹ =0 h(n ¹¹ )e −2πjfn ¹¹ /fs ¹¹ , with f s ¹¹ = 15 kHz Figure P12.24 shows the output y(n ¹ ) of the 5/3 filter and compares it with the signal x ¹ (n ¹ ) that would have been obtained had the analog signal been sampled at 3 kHz. On the right, it shows the effect of the reverse 3/5 filter on y(n ¹ ), and compares it with the original x(n). Fig. P12.24 Comparison of y(n ¹ ) and x ¹ (n ¹ ), and of x(n) and reconverted y(n ¹ ). Problem 12.22 Replacing the quantizer Q by its equivalent noise model, we can write the ζ-domain input/output equations: V ¹ (ζ) = X ¹ (ζ)−ζ −1 Y ¹ (ζ) W ¹ 0 (ζ) = V ¹ (ζ)+ζ −1 W ¹ 0 (ζ) Y ¹ (ζ) = E ¹ (ζ)+W ¹ 0 (ζ) Eliminating V ¹ (ζ) and W ¹ 0 (ζ), we obtain: Y ¹ (ζ)= X ¹ (ζ)+(1 −ζ −1 )E ¹ (ζ) Therefore, H x (ζ)= 1, and H NS (ζ)= 1 −ζ −1 . The main advantage of this form is that the input signal X ¹ (ζ) appears unchanged at the output (as opposed to being delayed as in the conventional case). 277 Problem 12.23 Using the signal labels indicated on the block diagram, we have the sample processing algorithm: for each input x do: v = x −u w 0 = v +w 1 y = Q(w 0 ) w 1 = w 0 u = y Iterating this algorithm 10 times, we get for x = 0.4 and x = −0.2: x y 0.40 1 0.40 −1 0.40 1 0.40 1 0.40 1 0.40 −1 0.40 1 0.40 1 0.40 −1 0.40 1 x y −0.20 −1 −0.20 1 −0.20 −1 −0.20 1 −0.20 −1 −0.20 −1 −0.20 1 −0.20 −1 −0.20 1 −0.20 −1 The averages of the y values are 0.4 and −0.2, respectively. Problem 12.24 Working in the ζ-domain, we note that the input and output of the filter H 1 (ζ) will be: X ¹ (ζ)−ζ −1 Y ¹ (ζ) and H 1 (ζ) _ X ¹ (ζ)−ζ −1 Y ¹ (ζ) _ Similarly, the input and output of H 2 (ζ) are: H 1 (ζ) _ X ¹ (ζ)−ζ −1 Y ¹ (ζ) _ −ζ −1 Y ¹ (ζ) and H 2 (ζ) _ H 1 (ζ) _ X ¹ (ζ)−ζ −1 Y ¹ (ζ) _ −ζ −1 Y ¹ (ζ) _ Adding E ¹ (ζ) to this output will generate Y ¹ (ζ). Thus, Y ¹ (ζ = E ¹ (ζ)+H 2 (ζ) _ H 1 (ζ) _ X ¹ (ζ)−ζ −1 Y ¹ (ζ) _ −ζ −1 Y ¹ (ζ) _ Moving the Y ¹ (ζ) to the left-hand side and solving for Y ¹ (ζ) gives the transfer relationship: Y ¹ (ζ)= H 1 (ζ)H 2 (ζ) 1 +ζ −1 H 2 (ζ)+ζ −1 H 1 (ζ)H 2 (ζ) X ¹ (ζ)+ 1 1 +ζ −1 H 2 (ζ)+ζ −1 H 1 (ζ)H 2 (ζ) E ¹ (ζ) Thus, we identify: H x (ζ)= H 1 (ζ)H 2 (ζ) 1 +ζ −1 H 2 (ζ)+ζ −1 H 1 (ζ)H 2 (ζ) , H NS (ζ)= 1 1 +ζ −1 H 2 (ζ)+ζ −1 H 1 (ζ)H 2 (ζ) The requirement that H x (ζ)= 1 and H NS (ζ)= (1 −ζ −1 ) 2 is satisfied by the choices: H 1 (ζ)= H 2 (ζ)= 1 1 −ζ −1 278 A block diagram realization is shown in Fig. P12.25. The corresponding sample processing algo- rithm can be stated as follows: for each input x ¹ do: w 0 = w 1 +(x ¹ −u) v 0 = v 1 +(w 0 −u) y ¹ = Q(v 0 ) w 1 = w 0 v 1 = v 0 u = y ¹ + + − − H 2 (ζ) H 1 (ζ) ζ -1 ζ -1 ζ -1 x′ w 0 v 0 w 1 v 1 u y′ quantizer Q Fig. P12.25 Discrete-time model of second-order delta-sigma quantizer. Problem 12.25 Without the feedback delay, we get a similar transfer relationship as in the previous problem, but without the ζ −1 delays in the denominators, that is, Y ¹ (ζ)= H 1 (ζ)H 2 (ζ) 1 +H 2 (ζ)+H 1 (ζ)H 2 (ζ) X ¹ (ζ)+ 1 1 +H 2 (ζ)+H 1 (ζ)H 2 (ζ) E ¹ (ζ) Thus, we identify: H x (ζ)= H 1 (ζ)H 2 (ζ) 1 +H 2 (ζ)+ 1 (ζ)H 2 (ζ) , H NS (ζ)= 1 1 +H 2 (ζ)+H 1 (ζ)H 2 (ζ) The requirement that H x (ζ)= ζ −1 and H NS (ζ)= (1 −ζ −1 ) 2 is satisfied by the choices: H 1 (ζ)= 1 1 −ζ −1 , H 2 (ζ)= ζ −1 1 −ζ −1 (This problem is similar to Problem 7.2.) Problem 12.26 Once the decimation filters are designed, the 2-level quantization of the input by the delta-sigma quantizer, and the subsequent filtering by the decimation filter can be carried out by the following for-loop (which does not discard the interpolated outputs, as discussed in Example 12.7.2): w1 = 0; initialize delay for (n=0; n<Ntot; n++) { x = 0.5 * sin(2 * pi * f0 * n); high-rate input sample 279 y = Q(w1); ΔΣ quantizer output v = x - y; delta part w0 = w1 + v; sigma part w1 = w0; update quantizer’s delay yup[n] = fir(N-1, h, w, y); (upsampled) decimator output } where h and w are the N-dimensional impulse response and internal state arrays for the decima- tor. In the Kaiser and the rectangular window designs, the filter length is N = 2LM+ 1. In the first-order comb case, it is N = 10, and the impulse response and transfer function are: h = 1 10 [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] , H(ζ)= 1 10 1 −ζ −10 1 −ζ −1 For the second-order comb case, we obtain the impulse response by convolving the first-order comb’s impulse response with itself. This gives a length N = 19 response and transfer function: h = 1 100 [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1] , H(ζ)= _ 1 10 1 −ζ −10 1 −ζ −1 _ 2 The magnitude response of the second-order comb case is the square of that of the first-order case: ¦H(f)¦ = ¸ ¸ ¸ ¸ ¸ sin(πf/f s ) Lsin(πf/10f s ) ¸ ¸ ¸ ¸ ¸ 2 It is plotted in dB in Fig. P12.26 together with the first-order comb case and the rectangular window design. The upsampled output y up (n ¹ ) of the second-order comb decimator is plotted in the right graph of Fig. P12.26. Fig. P12.26 Length-19 second-order comb magnitude response and filter output. Problem 12.27 The filter designs are the same as in the previous problems. The implementation of the second- order delta-sigma quantizer is given by the sample processing algorithm discussed in Problem 12.24. The following for-loop generates the high-rate input, quantizes it by the 2nd-order quan- tizer, and filters the quantized output with the decimation filter: 280 w1 = v1 = u = 0; initialize delays for (n=0; n<Ntot; n++) { x = 0.5 * sin(2 * pi * f0 * n); high-rate input sample w0 = w1 + x - u; output of H 1 v0 = v1 + w0 - u; output of H 2 y = Q(v0); ΔΣ quantizer output w1 = w0; update quantizer’s delays v1 = v0; update quantizer’s delays u = y; update quantizer’s delays yup[n] = fir(N-1, h, w, y); (upsampled) decimator output } Figure P12.27 shows the signal x ¹ (n ¹ ) and the 2-level quantized output y ¹ (n ¹ ) of the second-order quantizer. Fig. P12.27 High-rate input and output signals of second-order ΔΣ quantizer. The upsampled outputs y up (n ¹ ) of the averaging, second-order comb, rectangular, and Kaiser window decimators are shown in Fig. P12.28. Problem 12.28 Working in the ζ-domain, we obtain the I/O equation of the first stage. The input to H(ζ) is X ¹ (ζ)−ζ −1 Y ¹ 1 (ζ), Thus, adding the noise component, we have: Y ¹ 1 (ζ)= E ¹ 1 (ζ)+H(ζ) _ X ¹ (ζ)−ζ −1 Y ¹ 1 (ζ) _ which can be rearranged as: Y ¹ 1 (ζ)= H(ζ) 1 +ζ −1 H(ζ) X ¹ (ζ)+ 1 1 +ζ −1 H(ζ) E ¹ 1 (ζ) Inserting H(ζ)= 1/(1 −ζ −1 ), we obtain the transfer relationship of one stage: Y ¹ 1 (ζ)= X ¹ (ζ)+(1 −ζ −1 )E ¹ 1 (ζ)= X ¹ (ζ)+D(ζ)E ¹ 1 (ζ) (P12.3) where D(ζ)= 1−ζ −1 . The input to the second stage is obtained by forming the difference of the signals around the first quantizer, that is, (Y ¹ −E ¹ 1 )−Y ¹ = −E ¹ 1 . Applying the basic I/O equation (P12.3) to this input and corresponding noise E ¹ 2 , we obtain 281 Fig. P12.28 First- and second-order comb, and rectangular- and Kaiser-window decimator out- puts. Y ¹ 2 (ζ)= −E ¹ 1 (ζ)+D(ζ)E ¹ 2 (ζ) (P12.4) The overall output is obtained by the linear combination: Y ¹ (ζ) = Y ¹ 1 (ζ)+D(ζ)Y ¹ 2 (ζ)= X ¹ (ζ)+D(ζ)E ¹ 1 (ζ)+D(ζ) _ −E ¹ 1 (ζ)+D(ζ)E ¹ 2 (ζ) _ = X ¹ (ζ)+D(ζ)E ¹ 1 (ζ)−D(ζ)E ¹ 1 (ζ)+D 2 (ζ)E ¹ 2 (ζ)= X ¹ (ζ)+D 2 (ζ)E ¹ 2 (ζ) Thus, the quantization error from the first stage is canceled, whereas the error of the second stage gets filtered by the second-order highpass filter D 2 (ζ)= (1 −ζ −1 ) 2 . Problem 12.29 Such an arrangement is shown in Fig. P12.29. The outputs of the three stages are: Y ¹ 1 (ζ) = X ¹ (ζ)+D(ζ)E ¹ 1 (ζ) Y ¹ 2 (ζ) = −E ¹ 1 (ζ)+D(ζ)E ¹ 2 (ζ) Y ¹ 3 (ζ) = −E ¹ 2 (ζ)+D(ζ)E ¹ 3 (ζ) The overall output is obtained by the linear combination: 282 Y ¹ (ζ) = Y ¹ 1 (ζ)+D(ζ) _ Y ¹ 2 (ζ)+D(ζ)Y ¹ 3 (ζ) _ = X ¹ (ζ)+D(ζ)E ¹ 1 (ζ)+D(ζ) _ −E ¹ 1 (ζ)+D(ζ)E ¹ 2 (ζ)+D(ζ) _ −E ¹ 2 (ζ)+D(ζ)E ¹ 3 (ζ) __ = X ¹ (ζ)+D 3 (ζ)E ¹ 3 (ζ) x + − ζ -1 H(ζ) y 1 y 2 e 1 −e 1 −e 2 + + + − − − ζ -1 H(ζ) e 2 y 1st stage 2nd stage y 3 + − ζ -1 H(ζ) e 3 3d stage D(ζ) D(ζ) Fig. P12.29 MASH architecture of third-order delta-sigma quantizer. Problem 12.30 Such an architecture is depicted in Fig. P12.30. The I/O relationship of the first stage is Y ¹ 1 (ζ)= X ¹ (ζ)+D(ζ)E ¹ 1 (ζ) The input to the second-order quantizer is −E ¹ 1 (ζ). Therefore, its I/O relationship is (from Problem 12.8.3): Y ¹ 2 (ζ)= −E ¹ 1 (ζ)+D 2 (ζ)E ¹ 2 (ζ) The overall output is obtained by the linear combination: Y ¹ (ζ) = Y ¹ 1 (ζ)+D(ζ)Y ¹ 2 (ζ)= X ¹ (ζ)+D(ζ)E ¹ 1 (ζ)+D(ζ) _ −E ¹ 1 (ζ)+D 2 (ζ)E ¹ 2 (ζ) _ = X ¹ (ζ)+D 3 (ζ)E ¹ 2 (ζ) Problem 12.31 The delay of (N−1)/2 = LM introduced by the decimation filter must be taken into account in both multiplexing and control applications. In feedback control applications, such a delay may render the closed-loop system unstable. See [294] for further discussion. 283 x + − ζ -1 H(ζ) y 1 y 2 e 1 −e 1 + + − − − ζ -1 H(ζ) H(ζ) e 2 D(ζ) y 1st stage 2nd stage Fig. P12.30 MASH architecture of third-order delta-sigma quantizer. 284 Appendix B Problems Problem B.1 The input sequence is x(n)= _ i u i δ(n −iD−d) Its autocorrelation function is R xx (k)= E _ x(n +k)x(n) _ = _ i _ j D−1 _ d=0 E[u i u j ]δ(n +k −iD−d)δ(n −jD−d)p(d) where the expectation values were taken with respect to both u i and d. Because the u i are mutually independent and zero mean and d is uniform, we have E[u i u j ]= σ 2 u δ(i −j) and p(d)= 1/D. It follows that: R xx (k)= σ 2 u D _ i D−1 _ d=0 δ(n +k −iD−d)δ(n −iD−d) Changing variables to m= n−iD−d and noting that mruns over all the integers, we can replace the double summation over i and d by the summation over m: R xx (k)= σ 2 u D _ m δ(k +m)δ(m)= σ 2 u D δ(k) Thus, x(n) is stationary and has a delta-function autocorrelation. Sending this sequence into the interpolation filter will generate a stationary output sequence y(n) with a noise reduction ratio: NRR = σ 2 y σ 2 x = _ n h(n) 2 For the particular case of a hold interpolator, h(n) consists of D ones: NRR = σ 2 y σ 2 x = D−1 _ n=0 1 = D ⇒ σ 2 y = Dσ 2 x = D σ 2 u D = σ 2 u For the linear interpolator, we have h(n)= 1 −¦n¦/D, for ¦n¦ ≤ D. This gives: NRR = σ 2 y σ 2 x = D _ n=0 _ 1 − ¦n¦ D _ 2 = 1 +2 D _ n=1 _ 1 − n D _ 2 = 1 +2 1 D 2 D−1 _ m=1 m 2 Using the identity D−1 m=1 m 2 = 1 6 D(D−1)(2D−1), we obtain: NRR = σ 2 y σ 2 x = 1 +2 D−1 _ m=1 m 2 = 1 + D(D−1)(2D−1) 3D 2 = 1 + (D−1)(2D−1) 3D = 2D 2 +1 3D Thus, σ 2 y = 2D 2 +1 3D σ 2 x = 2D 2 +1 3D 2 σ 2 u 285 Problem B.2 The power spectral density of the output sequence will be related to that of the input by: S yy (z)= H(z)H(z −1 )S xx (z)= H(z)H(z −1 )σ 2 x = H(z)H(z −1 ) σ 2 u D For the hold interpolator, we have: H(z)= 1 −z −D 1 −z −1 , H(z −1 )= 1 −z D 1 −z = 1 −z −D 1 −z −1 z D−1 Thus, the output psd becomes: S yy (z)= H(z)H(z −1 ) σ 2 u D = 1 D _ 1 −z −D 1 −z −1 _ 2 z D−1 σ 2 u Taking inverse z-transforms with the help of Problem 5.11, we find: R yy (k)= _ 1 − ¦k¦ D _ σ 2 u Problem B.3 The generation of the held signal and the computation of its autocorrelation is illustrated by the following C program segment: double *u, *y, *R; long iseed; y = (double *) calloc(N, sizeof(double)); N-dimensional R = (double *) calloc(M+1, sizeof(double)); (M+1)-dimensional u[0] = ran(&iseed)-0.5; initialize u q = D * ran(&iseed); initialize q for (n=0; n<N; n++) y[n] = ranh(D, u, &q, &iseed); zero mean corr(N, y, y, M, R); sample autocorrelation A typical sample autocorrelation is shown in Fig. P14.1 Problem B.4 As was mentioned in the end of Section B.3, the averaged periodogramspectrumcan be calculated by the following loop: for (k=0; k<K; k++) { generate K = 200 blocks u[0] = ran(&iseed); initialize kth block q = D * ran(&iseed); for (n=0; n<N; n++) generate kth block X[n] = cmplx(ranh(D, u, &q, &iseed), 0.0); fft(N, X); compute its FFT for(n=0; n<N; n++) accumulate its periodogram S[i] += cabs(X[i]) * cabs(X[i]); } A typical averaged spectrum is shown in Fig. P14.2, for the case D = 5. 286 Fig. P14.1 Sample autocorrelation of length-100 hold noise. Fig. P14.2 Averaged periodogram spectrum of held noise. Problem B.5 The random number generator C routine is: /* rani.c - low-frequency random number generator using interpolation */ double ran(), dot(); void delay(), cdelay2(); double rani(L, P, h, w, q, iseed) usage: y=rani(L, P, h, w, & q, & iseed); int L, P, *q; q and iseed passed by reference double **h, *w; h = polyphase filter matrix long *iseed; required long by ran() { int i; double y; if (*q==0) every L calls get new random number w[0] = ran(iseed) - 0.5; zero mean i = (L - *q) % L; current polyphase index y = dot(P, h[i], w); compute interpolated value 287 cdelay2(L-1, q); decrement q for next call if (*q==0) every L calls update delay line delay(P, w); return y; } For the hold and linear interpolators, it generates the same output as ranh.c and ranl.c. The following program raniex.c is an example C program that invokes rani. Most of it is concerned with designing and allocating the polyphase filters. The very last for-loop generates the desired numbers. The for-loop before the last one, initializes the delay line w in accordance with Eq. (12.2.19): /* raniex.c - interpolated random number generator example */ run with: k = 0, 1, 2 = hold, linear, Kaiser interpolators L = 10, Ntot = 150, iseed = 1234567 A = 30 dB, ΔF = 0.3 #include <stdio.h> #include <math.h> #include <stdlib.h> double ran(), rani(), I0(); I0.c was given in Ch.10 void main(int argc, char ** argv) { double pi = 4 * atan(1.0); double **h, *w, *hd; double I0al, wind, A, D, wc, DF, al; int L, P, K, N, LK; int q, i, k, n, Ntot; long iseed; if (argc != 5) { puts("\nUsage: raniex k L Ntot iseed > y.dat\n" " k = 0,1,2 for hold,linear,general interpolator\n" " L = upsampling ratio\n" " Ntot = total random numbers\n" " iseed = initial seed\n"); exit(0); } k = atoi(argv[1]); L = atoi(argv[2]); Ntot = atoi(argv[3]); iseed = atol(argv[4]); if (k >= 2) { Kaiser interpolator fprintf(stderr, "enter A, DF (in units of fs): " ); scanf("%lf %lf", &A, &DF); D = (A - 7.95) / 14.36; 288 if (A > 50) al = 0.1102 * (A - 8.7); else if (A > 21) al = 0.5842 * pow(A-21, 0.4) + 0.07886 * (A-21); else al = 0; N = 1 + ceil(D * L / DF); K = ceil((N - 1) / (2.0*L)); N = 2 * L * K + 1; filter length P = 2 * K - 1; filter order LK = L * K; filter delay hd = (double *) calloc(N, sizeof(double)); direct form filter wc = pi / L; ideal cutoff frequency I0al = I0(al); for (n=0; n<N; n++) windowed filter if (n==LK) hd[n] = 1; else { wind = I0(al * sqrt(n*(2.0*LK-n)) / LK) / I0al; hd[n] = wind * L * (sin(wc*(n-LK)))/(pi*(n-LK)); } } if (k == 0) { hold interpolator N = L; K = 0; P = 0; for (n=0; n<N; n++) hd[n] = 1; } if (k == 1) { linear interpolator P = 1; K = 1; N = 2*L+1; for (n=0; n<N; n++) hd[n] = 1 - abs(n - L) / (double) L; } h = (double **) calloc(L, sizeof(double *)); polyphase subfilters for (i = 0; i < L; i++) allocate L subfilters h[i] = (double *) calloc(P+1, sizeof(double)); for (i=0; i<L; i++) for (n=0; n<=P; n++) h[i][n] = hd[L*n+i]; ith subfilter w = (double *) calloc(P+1, sizeof(double)); low-rate delay-line buffer for (i=K; i>=1; i--) w[i] = ran(&iseed) - 0.5; initialize w 289 q = 0; for (n=0; n<Ntot; n++) generate interpolated noise printf("%.12lf\n", rani(L, P, h, w, &q, &iseed)); } With the choices A = 30 dB, ΔF = 0.3, the Kaiser parameters become D = 1.536, α = 2.117. The generated sequences are shown in Fig. P14.3. Fig. P14.3 Kaiser, hold, and linearly interpolated random sequences. Problem B.6 Noting that the autocorrelation of a hold-interpolated sequence of period D is R(k)= (1 − ¦k¦/D)σ 2 u , −D ≤ k ≤ D, we have: R yy (k)= 1 B 2 B−1 _ b=0 R y b y b (k)= 1 B 2 B−1 _ b=0 _ 1 − ¦k¦ 2 b _ u(2 b −¦k¦) σ 2 u (P14.1) where the unit-step u(2 b −¦k¦) restricts the duration of the b-th termto be ¦k¦ ≤ 2 b , or ¦k¦ ≤ 2 b −1 for non-zero values of R yy (k). The resulting autocorrelation function is piece-wise linear, where the linear segments have geometrically increasing slopes. This is shown in Fig. P14.4 for the case B = 4. At lag k = 0, Eq. (P14.1) gives the expected result: σ 2 y = R yy (0)= 1 B 2 · Bσ 2 u = σ 2 u B The increasing linear slopes in R yy (k) cause it to have long-range correlations. Indeed, because of the restriction ¦k¦ ≤ 2 b −1, the maximum lag will be: k max = 2 B−1 −1 (P14.2) Given a lag k in the range ¦k¦ ≤ k max , the expression of Eq. (P14.1) can be summed in closed form as follows. The restriction ¦k¦ ≤ 2 b −1 can be turned around into a restriction for the summation index b ≥ log 2 (¦k¦ +1). Denoting the ceiling of this quantity by b(k)= ¦log 2 (¦k¦ +1)| 290 k k max =2 B-1 -1 R(k)/R(0) 1 3 5 7 9 4 6 8 10 2 1.00 0.75 0.50 0.25 0 B=4 Fig. P14.4 Theoretical autocorrelation of 1/f-noise model. we find R yy (k)= 1 B 2 B−1 _ b=b(k) _ 1 −¦k¦2 −b _ σ 2 u and using the finite geometric series formula (e.g., Eq. (6.3.13)), we get the expression of Eq. (B.25). Problem B.7 Figure P14.5 shows the theoretical autocorrelation (P14.1) or (B.25), together with the sample autocorrelation of a (zero-mean) block of 1/f-noise samples of length N = 2000 for B = 8. The maximum correlation length is in this case k max = 2 B−1 − 1 = 2 7 − 1 = 127. The sample autocorrelation was computed by the program segment: double *y, *R; y = (double *) calloc(N, sizeof(double)); N-dimensional R = (double *) calloc(M+1, sizeof(double)); (M+1)-dimensional for (n=0; n<N; n++) use N=2000 y[n] = ran1f(B, u, q, &iseed); zero-mean y’s corr(N, y, y, M, R); use M=150 Fig. P14.5 Theoretical and sample autocorrelations for B = 8. 291 The reason for using N = 2000 was because we wanted to evaluate the sample autocorrelation at M = 150 lags. Thus, the number of lags is 150/2000 ≡ 7.5% of the block length, which falls within the recommended range for getting statistically reliable lags using the routine corr, as was mentioned in Section A.1. Problem B.8 We look at the cases ω min = 0.001π and ω max = 0.1π, 0.3π, 0.6π. The designed model param- eters are: For ω max = 0.1π, we have B = 3 and c = 10, a = [0.6858, 0.9686, 0.9969] For ω max = 0.3π, we have B = 4 and c = 6.6943, a = [0.0575, 0.8592, 0.9790, 0.9969] For ω max = 0.6π, we have B = 6 and c = 3.5944, a = [−0.8850, 0.4756, 0.8541, 0.9594, 0.9887, 0.9969] The spectra are shown in Figs. P14.6—P14.8. Fig. P14.6 Model spectrum and periodogram estimate. ω max = 0.1π. Problem B.9 Solving the equation (0.99574) c = 0.94791, we find c = 12.5309. Then, the filter of Eq. (B.30) becomes: H(z)= G (1 −0.98444z −1 )(1 −0.82159z −1 )(1 −0.08522z −1 ) (1 −0.99574z −1 )(1 −0.94791z −1 )(1 −0.51153z −1 ) The NRR = h T h of the filter (B.29) without the factor G can be computed analytically or much faster using MATLAB to compute a fairly long portion of the impulse response h (e.g., of length 2000) and then setting G = 1/ √ NRR = 1/ _ h T h. The magnitude response squared of Eqs. (B.29) and (B.30) are shown in Fig. P14.9. The cascade realization is shown in Fig. P14.10. The corre- sponding sample processing algorithm will be: 292 Fig. P14.7 Model spectrum and periodogram estimate. ω max = 0.3π. Fig. P14.8 Model spectrum and periodogram estimate. ω max = 0.6π. for each white noise input sample x do: u 0 = 0.57534x +0.99574u 1 x 1 = u 0 −0.98444u 1 u 1 = u 0 v 0 = x 1 +0.94791v 1 x 2 = v 0 −0.83392v 1 v 1 = v 0 w 0 = x 2 +0.53568w 1 y = w 0 −0.07568w 1 w 1 = w 0 293 Fig. P14.9 1/f noise filters for Problem B.9. z -1 x u 0 v 0 w 0 u 1 x 1 x 2 v 1 w 1 y z -1 z -1 0.57534 0.99574 -0.98444 0.94791 -0.83392 0.53568 -0.07568 Fig. P14.10 Cascade realization of 1/f noise filter. 294 xa (t)= 2 cos(2πf1 t)− cos(2πf2a t)= 2 cos(πt)− cos(−πt)= cos(πt) A class of signals aliased with x(t) and xa (t) is obtained by replacing f1 and f2 by their shifted versions: f1 + mfs , f2 + nfs resulting in: x(nT) = cos(2πn/10)+ cos(2πn/10)+ cos(2πn/10)+ cos(6πn/10) = 3 cos(2πn/10)+ cos(6πn/10)= xa (nT) If fs = 12 Hz, then f1 and f3 will lie outside of [−6, 6] and will be aliased with 11 − 12 = −1 and 9 − 12 = −3. The aliased signal will be: xmn (t)= 2 cos(πt + 6πmt)− cos(πt − 6πnt) xa (t) = cos(2π(−1)t)+ cos(2πt)+ cos(2π(−3)t)+ cos(6πt) Problem 1.4 Using a trig identity, we write x(t)= cos(8πt)+ cos(10πt)+ cos(2πt). The frequencies contained in x(t) are thus, 1 Hz, 4 Hz, and 5 Hz. If the sampling rate is 5 Hz, then the Nyquist interval is [−2.5, 2.5] Hz, and therefore, the 4 Hz and 5 Hz components lie outside it and will be aliased with the frequencies 4 − 5 = −1 Hz and 5 − 5 = 0 Hz, etc. = 2 cos(2πt)+2 cos(6πt) Problem 1.7 We use the same technique as in the square-wave Example 1.4.6. At a sampling rate of 8 Hz, the signal frequencies of Problem 1.5 Using trig identities we find: will be aliased with: {1, 3, 5, 7, 9, 11, 13, 15, . . . } x(t)= sin(6πt) 1 + 2 cos(4πt) = sin(6πt)+ sin(10πt)+ sin(2πt) with frequency content: f1 = 3, f2 = 5, f3 = 1 kHz. The Nyquist interval is [−2, 2] kHz, and the aliased frequencies are: { 1, 3, − 3, − 1, 1, 3, − 3, − 1 , . . . } Therefore only sin(2πt) and sin(6πt) terms will appear in the aliased signal. Thus, we write it in the form: f 1a = f 1 − f s = 3 − 4 = − 1, Thus, f 2a = f 2 − f s = 5 − 4 = 1, f 3a = f 3 = 1 xa (t)= B sin(2πt)+C sin(6πt) To determine B and C, we demand that xa (t) and x(t) agree at the sampling instants t = nT = n/8, because T = 1/fs = 1/8 sec. Therefore, we demand xa (t)= sin(−2πt)+ sin(2πt)+ sin(2πt)= sin(2πt) B sin(2πn/8)+C sin(6πn/8)= x(n/8) Setting n = 1, 2, we get two equations Problem 1.6 Use the trigonometric identity 2 cos a cos b = cos(a + b)+ cos(a − b) three times to get B sin(2π/8)+C sin(6π/8)= x(1/8)= 0.5 B sin(4π/8)+C sin(12π/8)= x(2/8)= 1 x(t) = 2[cos(10πt)+ cos(6πt)]cos(12πt) = cos(22πt)+ cos(2πt)+ cos(18πt)+ cos(6πt) The frequencies present in this signal are f1 = 11, f2 = 1, f3 = 9, and f4 = 3 Hz. With a sampling rate of 10 Hz, only f1 and f3 lie outside the Nyquist interval [−5, 5] Hz, and they will be aliased with f1 − fs = 11 − 10 = 1 Hz and f3 − fs = 9 − 10 = −1 Hz. The aliased signal will be: ⇒ B√ + C√ 2 1 1 2 = 0.5 B−C=1 The values for x(1/8) and x(2/8) were obtained by inspecting the triangular waveform. Solving for B and C, we find: √ B= 2+2 , 4 √ C= 2−2 4 xa (t) = cos(2π(1)t)+ cos(2πt)+ cos(2π(−1)t)+ cos(6πt) = 3 cos(2πt)+ cos(6πt) To prove the equality of the samples, replace t = nT = n/10, because T = 1/fs = 1/10. Then, Problem 1.8 For fs = 5 kHz, we have: x(nT)= cos(22πn/10)+ cos(2πn/10)+ cos(18πn/10)+ cos(6πn/10) But, cos(22πn/10)= cos(2πn+2πn/10)= cos(2πn/10) and similarly, cos(18πn/10)= cos(2πn− 2πn/10)= cos(2πn/10). Therefore, the sample values become For fs = 10 kHz, we have: xa (t)= sin(2πf1 t) xa (t)= 2 sin(2πf1 t)+ sin(2πf2 t) 2 3 |HC | = 10−AC /20 = 10−28.08/20 = 0.0394 |HD | = 10−AD /20 = 10−56.16/20 = 0.0016 Thus, the resulting reconstructed signal will be: ya (t) = sin(10πt)+ sin(20πt)+|HC | sin(−20πt)+|HD | sin(10πt) = 1.0016 sin(10πt)+0.9606 sin(20πt) which agrees closely with the audible part of x(t). Fig. P1.1 Parts (a,b) of Problem 1.8. H(f) Analog Prefilter AB C D 48 dB/octave Problem 1.9 The audible and inaudible parts are: f 0 10 20 30 45 kHz x(t)= sin(10πt)+ sin(20πt) + sin(60πt)+ sin(90πt) audible inaudible Fig. P1.2 Prefilter specifications of Problem 1.9. The frequencies of the four terms and their aliased versions are: fA = 5 fB = 10 fC = 30 fD = 45 ⇒ fAa = 5 fBa = 10 fCa = 30 − 40 = −10 fDa = 45 − 40 = 5 Problem 1.10 The Fourier series expansion of the periodic function s(t) is: ∞ T/2 −T/2 s(t)= m=−∞ cm e2πjmt/T , cm = 1 T s(t)e−2πjmt/T dt a. When there is no prefilter the aliased signal at the output of the reconstructor will be: But within the basic period [−T/2, T/2], s(t) equals δ(t). Thus, ya (t)= sin(10πt)+ sin(20πt)+ sin(−20πt)+ sin(10πt)= 2 sin(10πt) b. When there is a perfect prefilter, the fC , fD components are removed prior to sampling thus, the sampled and reconstructed signal will remain unchanged, that is, the audible part of x(t): cm = 1 T/2 −T/2 T δ(t)e−2πjmt/T dt = 1 T Using the delta function integral representation: ∞ −∞ e−2πjf t dt = δ(f ) ya (t)= sin(10πt)+ sin(20πt) c. The attenuations introduced by the practical prefilter shown in Fig. P1.2 are obtained by determining the number of octaves to the frequencies fC , fD and multiplying by the filter’s attenuation of 48 dB/octave: log2 we find: S(f ) = = ∞ −∞ s(t)e−2πjf t dt = ∞ 1 ∞ m=−∞ ∞ −∞ T s(t)e−2πj(f −mfs )t dt 1 fC fs / 2 fD fs / 2 = log2 = log2 30 20 45 20 = 0.585 = 1.170 ⇒ ⇒ AC = 48 × 0.585 = 28.08 dB T δ(f − mfs ) m=−∞ Problem 1.11 AD = 48 × 1.170 = 56.16 dB This is simply the Fourier series expansion of the periodic function X(f ) in the variable f , and x(nT) are the Fourier series expansion coefficients calculated by integrating over one period, that is, over [−fs /2, fs /2]. log2 and in absolute units: 4 5 we changed the summation index from m to −m. sampled. .3 Spectra of analog. P1.3 shows the required spectra.5e2πjf0 t + 0. the attenuations due to the signal and filter combine to give: |XL (f )|2 = 1 − 2e−aLT cos 2π(f − f0 )LT + e−2aLT 1 − 2e−aT cos 2π(f − f0 )T + e−2aT A(f )= α log10 f fmax + β log10 f fmax = γ log10 f fmax In the limit L → ∞. we see that the spectrum of the truncated sampled signal has ripples that follow the general shape of X(f ).1(f − fs ) 8 The continuous time limit T → 0 of X(f ) gives rise to the analog spectrum: Its value at the passband frequency fpass = fmax = 20 kHz will be: 6 7 . which is only an approximation of the true spectrum even within the Nyquist interval. the sampled spectrum XL (f ) will tend to X(f ). .5δ(f − f0 )+0.5δ(f + f0 ) Its replication gives the spectrum of the sampled signal: X(f ) = = 1 ∞ T X(f − mfs )= m=−∞ ∞ 1 2T ∞ δ(f − mfs − f0 )+δ(f − mfs + f0 ) m=−∞ Fig. If f0 is small. L − 1 has spectrum: L−1 L−1 XL (f ) = n=0 x(nT)e−2πjf nT = n=0 −(a+2πj(f −f0 ))LT e−(a+2πj(f −f0 ))nT = with magnitude spectrum: 1−e 1 − e−(a+2πj(f −f0 ))T Problem 1. and windowed signals of Problem 1. 1. and magnitude spectra: x(t)= e−at e2πjf0 t = e−(a−2πjf0 )t . we see that as fs increases. As L → ∞. From the right graph. with Fourier transform: T→0 lim TX(f )= lim T 1 − e−(a+2πj(f −f0 ))T T→0 = 1 a + 2πj(f − f0 ) = X(f ) X(f )= 0.14 This is the same as Example 1.13 We have for the complex sinusoid.13.5. shifted to fs . . 1 t≥0 X(s)= s + a − 2πjf0 1 Fig.4. the sampled spectrum agrees more closely with the analog spectrum within the Nyquist interval.Problem 1. we will also get the spectral peaks at the negative frequency X(f )= 1 a + 2πj(f − f0 ) ⇒ |X(f )|2 = a2 + 4π2 (f − f0 )2 −f0 . The requirement A(fs − fmax )≥ A gives: γ log10 X(f )= n=0 x(nT)e−2πjf nT = 1 1 − e−(a+2πj(f −f0 ))T fs − fmax fmax ≥A ⇒ fs ≥ fmax + fmax 10A/γ Problem 1. In units of dB per decade. 1 2T δ(f − mfs − f0 )+δ(f + mfs + f0 ) m=−∞ where in the second term. .15 The first replica of Xin (f ). From the left graph. Fourier. n = 0. we have e−aLT → 0 and obtain the sampled spectrum of the infinitely long signal: ∞ where γ = α + β. In the case of real-valued signals.12 Write x(t)= 0. but apart from that the same conclusions can be drawn about the sampled signals. the peaks at ±f0 will influence each other somewhat.5e−2πjf0 t . P1. The length-L sampled signal x(nT)= e−(a−2πjf0 )nT . will have spectrum: with magnitude spectrum: |X(f )| = 2 1 1 − 2e−aT cos 2π(f − f0 )T + e−2aT |Xin (f − fs )| = 1 1 + 0. Problem 1. the Laplace. const.8 dB 8 R(fs )= 1 + (0.1(fmax − fs ) 8 −10 log10 |X(f )|2 = γ log10 f + const.281) = 4. 1f ) 8 where r = 10Apass /10 Its first replica |X(f − fs )| is required to be suppressed by A = 60 dB at fmax The antialiasing condition.2 dB Eq. Apass = 1 dB.1 kHz. Problem 1. is now 10 log10 or.1). With fs = 80. where γ = 140 dB/decade.918 N= ln(3194. A 0 fmax fs-fmax f s f 1 + (fmax − fs )/f0 1 + (fmax /f0 )2N 2N · 1 + 0.1fmax )8 6 fs − fmax fmax (P1.9 kHz. (P1. With fs = 70 kHz.2) N= 10A/10 rR(fs )−1 r−1 2 ln which gives fs = 80. the spectrum |X(f )| follows the power law 1 const.403 2 ln(50/20) ⇒ N=5 We calculate also f0 = fmax /(r − 1)1/2N = 22.1(fmax − fs ) · 1 + (0.1) and solving for N.14 would have given here fs = fmax + 10A/γ fmax = 20 + 20 · 1060/140 = 73.1fmax )8 8 1 + (fmax − fs )/fmax 2N (r − 1) =A (P1.1(fmax − fs ) · 1 + (0. the use of the prefilter enables us to reduce the sampling rate from 132 kHz to 80 kHz. thus. 1 + (fmax − fs )/f0 1 + (fmax /f0 )2N 2N |X( fmax )| |X( fs-fmax )| =|X( fmax-fs)| −10 log10 X(fmax − fs ) X(fmax ) 2 · 1 + 0.1fmax )8 8 = 60 dB ln (P1. that for large f .1 kHz. and 10A/10 R(fs )= 657.05 kHz.2) represents the stopband attenuation due to the filter. that is. r−1 −10 log10 |H(fmax )| = 10 log10 1 + (fmax /f0 ) 2 6 = Apass (P1.1(fmax − fs ) 1 + (0. 8 9 . we have r · 1 + 0.1fmax )8 8 = 60 which can be solved for fs to give fs = 132.|Xin (fmax − fs )| = 1 1 + 0.16 The passband condition at f = fmax = 20 kHz is: 10 log10 1 + (fmax /f0 )2N = Apass which can be solved for f0 in terms of N as follows: 2 f0 N = 2N fmax .4) where R(fs ) is defined by = Astop = 21.1(fmax − fs ) 1 + (0.3) which can be solved for f0 to give f0 = 25.1(fmax − fs ) 1 + (0. of which 60 dB/decade is due to the filter and 80 dB/decade due to the signal. |X(f )|2 = · ≈ · = 1 + (f /f0 )6 1 + (0.1(fmax − fs ) 1 + (0. This must be suppressed by A = 60 dB relative to |Xin (fmax )|.259. we require that its passband attenuation be Apass = 1 dB at fpass = fmax = 20 kHz. we have 10 log10 1 + (fmax − fs )/f0 1 + (fmax /f0 )6 1 + 0. The prefiltered signal that gets sampled is now |X(f )| = |H(f )Xin (f )| = 1 1 + (f /f0 )6 1 1 + ( 0 .0633 kHz.1f )8 f6 f8 f 14 giving rise to an effective attenuation 1 r = 10Apass /10 = 100.1fmax )8 8 = 10A/10 which gives the condition 10 log10 1 + (fmax − fs )/f0 1 + (fmax /f0 )6 6 2 Replacing f0 N by its expression above. (P1. we require: −10 log10 Xin (fmax − fs ) Xin (fmax ) 2 =A ⇒ 10 log10 1 + 0. The exact solution of Eq. (P1.4 or Problem 1. and the second the attenuation due to the signal. replacing Eq. The approximate method of Example 1.1fmax )8 8 = 10A/10 It can be solved approximately by ignoring the +1 in the numerators. we find Thus.4) gives the minimum prefilter order for a desired suppression level A and rate fs .1(fmax − fs ) 8 10 log10 = A − Astop = 38. 10 log10 (fmax − fs )/f0 1 + (fmax /f0 )6 6 0.52 kHz. Note also.1) is fs = 80. const. A = 60 dB. we obtain 1 + 0.1fmax )8 8 =A = A. The first factor in Eq. which is fairly close to the more accurate value of 80 kHz.1(fmax − fs ) 1 + (0.1fmax )8 1 + 0.65 kHz.5. (P1. Using the prefilter.1 = 1. that is. |Xin (fs − fmax )|2 = 10−A/10 |Xin (fmax )|2 Inserting the given expression for |Xin (f )|.14. fs = 30 kHz and fmax = 10 kHz. We find: γ= log10 A f fmax = log10 60 30 − 10 10 |Xin (f )|2 = 200 1 (f /fa )2Na . which gives: |X(f )|2 = |H(f )|2 |Xin (f )|2 = 1 1 · 1 + (f /f0 )2N 1 + (f /fa )2Na The antialiasing condition |X(fs − fmax )|2 = 10−A/10 |X(f )|2 gives now: 1 1 + (fs − fmax )/f0 2N Problem 1. for fixed A.4) as a function of fs for different choices of A.17 Figure P1. 2(N+Na ) = 10A/10 If we increase the sampling rate to 50 kHz.4 Butterworth order versus sampling rate. where A = 60 dB.14. |H(fmax )|2 = 1 = 10−B/10 1 + (fmax /f0 )2N The filtered input that gets sampled will now have spectrum X(f )= H(f )Xin (f ). we find the filter’s attenuation: β = γ − α = 200 − 80 = 120 dB/decade which translates into a filter order: which simplifies into: β = 20N ⇒ N = β/20 = 120/20 = 6 fs − fmax fmax or. that is. 1. fs = fmax + fmax 10A/20(N+Na ) It agrees with the results of Problem 1. we get the desired equation for fs in terms of A and fmax : 1 + (fmax /fa )2Na 1 + (fs − fmax )/fa If we use a Butterworth prefilter of order N: 2Na = 10−A/10 |H(f )|2 = 1 1 + (f /f0 )2N Fig. If we do not use a prefilter. For any fixed desired value of A.4 shows a plot of N given by Eq. |H(f )|2 1 (f /f0 )2N the antialiasing condition would read: a f 2N fmax (fs − fmax )2N (fs − fmax )2Na = 10−A/10 max · 2Na · 2N 2N 2Na f0 f0 fa fa 2N Because the signal has α = 80 dB/decade. at any fixed fs . P1. (P1. the 3-dB frequency f0 is determined by requiring that at the edge of the passband the attenuation be B dB: Problem 1. valid for large f ’s. the requirement that the aliased components (of the 1st replica) be suppressed by A dB relative to the signal components can be expressed in the form: fs = fmax + fmax 10A/20(N+Na ) → fmax + fmax = 2fmax In this case.18 Using the results of Problem 1. then.15. and that it decreases with fs .19 This problem is the generalization of Prob. the Butterworth filter resembles more and more a brick-wall filter with cutoff fmax . It is evident from this graph that the complexity of the prefilter increases with A. the limit N → ∞ gives Problem 1. 10 11 . with γ = α + β = 20Na + 20N. we solve for the combined attenuation γ of signal and prefilter: · 1 1 + (fs − fmax )/fa 2Na A = γ log10 fs − fmax fmax = 10−A/10 · ⇒ 1 1 · 1 + (fmax /f0 )2N 1 + (fmax /fa )2Na Using the asymptotic forms of the spectra. which gives β = 100 − 80 = 20 dB/decade and order N = β/20 = 1. the combined attenuation will be γ = 100. Notice the two data points on the A = 60 curve at fs = 70 and fs = 80 kHz that were computed in this and the last example. The replicas of X(f ) embedded in X(f ) will still be present. Am = δm .4 dB T H(fm )= sin(πfm T) πfm T e−jπfm T Thus.19: 2(N+Na ) Working in the frequency domain we have: Xa (f )= H(f )X(f )= n x(nT) e−2πjf nT H(f ) fs − fmax fmax or. For a pulse of width τ. leaving the central replica almost unchanged. Its sampled spectrum will be: ∞ ∞ Problem 1.20 The linear relationship between N and A follows from the approximation of Problem 1. that is. then P(f ) will be essentially flat within the Nyquist interval.24 Start with a complex sinusoid x(t)= e2πjf0 t . Fig. Thus. θm = arg H(fm ) fs 5fs ∞ Fig. P1. fm = f0 + mfs . Writing 1 ∞ m=−∞ T H(f0 + mfs )e2πj(f0 +mfs )t |P(f)| f -5fs -fs 0 1 T we have: H(fm )= Am ejθm . If τ T. so that Am = 1 T |H(fm )|. ∞ x(nT)h(t − nT) n xrec (t)= m=−∞ δm sin 2π(f0 + mfs )t = sin(2πf0 t) 12 13 . but they will be weighted by P(f ).23 Using convolution in the time domain. we find for the real sinusoidal case: Problem 1. xrec (t)= m=−∞ Am e2πj(f0 +mfs )t+jθm Taking imaginary parts.Problem 1. the narrower the width τ the flatter the spectrum P(f ). we get: xa (t)= 2(N + Na )log10 fs − fmax fmax x(nT)h(t − nT) n = A 10 Problem 1. we recognize the term in the bracket as the FT of h(t − nT). thus. Taking inverse Fourier transforms. we have: 1 Astop = A − ADAC = 40 − 14. we find: xrec (t)= Thus. we have θm = 0 and Am = 0 except at m = 0 where A0 = 1.6 dB Thus.22 The stopband frequency of the postfilter is: fstop = fs − fc = 6 − 1 = 5 kHz. we have: X(f )= 1 T X(f − mfs )= m=−∞ 1 T δ(f − f0 − mfs ) m=−∞ The spectrum of the reconstructed analog signal will be then: |P(f )| = τ sin(πf τ) πf τ Xrec (f )= H(f )X(f )= 1 ∞ T H(f )δ(f − f0 − mfs )= m=−∞ 1 ∞ T H(f0 + mfs )δ(f − f0 − mfs ) m=−∞ Therefore. the attenuation of the staircase DAC is ∞ xrec (t)= m=−∞ Am sin 2π(f0 + mfs )t + θm Assuming |f0 | < fs /2. θm = −πf0 T xa (t) = = ˆ h(t − t )x(t ) dt = n x(nT) −∞ h(t − t )δ(t − nT) dt For the ideal reconstructor.5 shows P(f ) relative to the replicas of X(f ) for the case τ = T/5. T H(fm )= sin(πf0 T) πfm T e−jπf0 T Problem 1.4 = 25.21 The presence of P(f ) is called the aperture effect.5 Butterworth order versus sampling rate. P1. the stopband attenuation of the postfilter at f = fstop must be: and because πfm T = πf0 T + mπ. = 10A/10 Using the delay theorem of Fourier transforms. going to the time domain. At this frequency. we get: ∞ −∞ ∞ Am = sin(πf0 T) πfm T . for the staircase reconstructor we have: 1 ADAC = −20 log10 sin(πfstop /fs ) πfstop /fs = 14. Thus. The need for using antialiasing prefilters to avoid overlapping of replicas remains the same. 000 1.000 1.1 The quantized values are: analog value 2.853 -4.1 3. complement the first bit in this table. we have n 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 x(n) 0.222 4.841 -2.939 -3. (1.524 -4.1 -3.911 4.990 4.423 4.243 2.000 -1.000 2. we have using Q = 2B = which gives √ 12erms : 10 R R = √ ≥ √ Q 12erms 12 · 10−3 14 15 .000 4.7 -4 quantized value 2 4 4 4 -2 -4 -4 -4 DAC output 001 010 010 010 111 110 110 110 For the offset binary case.9 -3.853 2.627 -1.6.755 4.Problem 1.939 1.3 With R = 10 volts and erms ≤ 10−3 volts.7 4 -2.524 3.000 -3.000 -5.627 -0.000 -2.000 1. Chapter 2 Problems Problem 2.000 5.000 offset binary 1000 1001 1010 1011 1100 1101 1101 1101 1101 1100 1011 1010 1001 0111 0110 0101 0100 0011 0011 0011 2’s complement 0000 0001 0010 0011 0100 0101 0101 0101 0101 0100 0011 0010 0001 1111 1110 1101 1100 1011 1011 1011 Problem 2. Problem 2.25 Take the linear combination of the results of the single sinusoid case of Eq.000 -5.000 2.9 3.000 4.000 5.000 -5.990 xQ (n) 0.12).000 5.000 5.000 3.841 0.000 3.911 -4.000 -4.409 3.2 Filling the table. if in each channel we must perform NMAC = 35 operations on each sample.1 kHz sampling rate.09 Mbytes 8 × 1024 × 1024 Problem 2. Mbytes: 2 × 60 × 44100 × 16 = 10. (2. The above results suggest that one use at least two DSPs to multiplex the required operations. Iterating the algorithm for i = 3.164. For part (b).7 Solving Eq.4 At 44. 8 The oversampled speech rates will be.1) with ΔB = 7 bits and p = 1. If each sample is quantized with 16 bits. we find: (P2.705 mvolt. the total number of bits will be 2 × 60 × 44100 × 16 bits or. a typical professional digital recording system would require the processing and mixing of at least 32 channels. which can perform a MAC operation within 30–80 nsec. (P2. we find: TMAC = 1 595 = = 37 nsec 16 · 35 · 48 kHz 16 which is just within the capability of the fastest DSP chips. TMAC = 1 = 0. with fs = 44. one minute of music has 60 sec containing 60 × 44100 samples. 0. The actual rms error will be me = = 0.1 kHz: Lfs = 67. 48 kHz Problem 2. we have: NMAC TMAC ≤ T which gives for the time per MAC: ⇒ TMAC ≤ 1 T = NMAC NMAC fs xQ = R(b1 2−1 + b2 2−2 + · · · + bB 2−B − 0. And. we get kbytes and by another 1024.5. we find: 22ΔB π2p 2p + 1 1 2p+1 L= With ΔB = 15 and p = 1. 5.Problem 2. with fs = 8 kHz: (3 × 60 sec)(16 channels)(48000 samples/sec)(20 bits/sample) = 330 Mbytes (8 bits/byte)(10242 bytes/Mbyte) that is. 1. −Q (e − me )2 p(e) de = 1 0 Q −Q e+ Q 2 de = Q2 12 Problem 2.1) L = 1523.114.5) = R (1 − b1 )2−1 + b2 2−2 + · · · + bB 2−B − 0. 1. 3. 2.2. dividing by 8 we get the total number of bytes: 2 × 60 × 44100 × 16 bytes 8 Dividing by 1024.5 Following similar steps as in the previous problem. for two stereo channels.8 Using Eq. p=0 p = ap + b3 p = ap + b2 p = ap + b1 p = ap + b0 = b3 = ab3 + b2 = a(ab3 + b2 )+b1 = a2 b3 + ab2 + b1 = a(a2 b3 + ab2 + b1 )+b0 = a3 b3 + a2 b2 + ab1 + b0 = B(a) 16 17 . 2. we find: Problem 2.764 MHz Problem 2. 104. 3. then the total number of MACs that must be performed within the sampling interval T are 16NMAC . 116.9 Replacing b1 = 1 − b1 . then these operations must be finished during the sampling interval T = 1/fs between samples: Lfs = 304. In practice.495 The mean is 0 Therefore. If a single DSP chip handles all 16 channels. 13.10) for L in terms of ΔB. 2 × 60 × 44100 samples.5 = R −b1 2−1 + b2 2−2 + · · · + bB 2−B where the first 2−1 canceled the last −0. This gives: Problem 2. consider the polynomial of degree M = 3: B(z)= b0 +b1 z+b2 z2 +b3 z3 . 40 The oversampled audio rates will be.10 As an example. practically the entire hard disk of a typical home PC. 2. and the variance: −Q ep(e) de = 1 0 Q −Q e de = − Q 2 2 erms = 2B 12 R √ = 10 212 12 √ 0 2 σe = E[(e − me )2 ]= The dynamic range will be 6B = 6 · 12 = 72 dB. B = 12.6 B ≥ log2 √ 10 12 · 10−3 = 11.595 · 10−3 msec = 595 nsec 35 · 48 kHz This is plenty of time for today’s DSP chips. we have for part (a): L = 38. 0 1.2 by rounding. 0 C = u(y − xQ ) 1 0 1 0 b1 b2 b3 b4 b1 b2 b3 b4 Problem 2.5 3.95. 5 1. we shift it by half the quantization spacing y = x + Q/2 = 1. 5 3.0 0.5 0.5 4.polynomial evaluator */ natural binary offset binary 2’s C b 1 b2 b3 b 4 double pol(M.5 −3. 0 3.45. 0 2. double p = 0.14 The quantization width is Q = R/2B = 8/24 = 0.0 1. a.5 −2. b. test bM = qM−1 bM−1 = qM−2 − aqM−1 bM−2 = qM−3 − aqM−2 ··· b1 = q0 − aq1 b0 = R − aq0 ⇒ qM−1 = bM qM−2 = aqM−1 + bM−1 qM−3 = aqM−2 + bM−2 ··· q0 = aq1 + b1 R = aq0 + b0 b 1 b2 b3 b4 1 0 0 0 0 1 0 0 0 0 1 1 0 0 0 1 xQ 4.5 volts.11 /* pol.2.Problem 2.0 5.5 2. i>=0.5 −1.5 7. Table P2. we iterate the algorithm for i = 3. we have y = x + Q/2 = 5.0 6.45. The following tables show the successive approximation tests for the natural and offset binary cases. and the remainder R must be a constant.0 2.0 m 8 7 6 5 4 3 2 1 0 −1 −2 −3 −4 −5 −6 −7 −8 xQ = Qm 4. So the objective of the algorithm is to compute R iteratively. 1: 0010 1010 The natural binary and 2’C cases agree because x lies in the positive range of both quantizers. For x = 5. Inserting the polynomial expressions we have: 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 Table P2.25 = 1. To convert x = 1.0 −0.0 4.5 −4. we find: Problem 2. for (i=M.c .1 shows the quantization levels and their binary codes.0 0.0 5.5 1.5 2.5 0.0 6. R = 8 volts.5 1.0 C = u(y − xQ ) 0 0 1 0 test b 1 b2 b 3 b4 1 1 1 1 0 1 0 0 0 0 1 1 0 0 0 1 xQ 0. setting z = a.0 −2. a) int M. The tests are shown below: test p=0 p = a(p + b3 )= ab3 p = a(p + b2 )= a(ab3 + b2 )= a2 b3 + ab2 p = a(p + b1 )= a(a2 b3 + ab2 + b1 )= a3 b3 + a2 b2 + ab1 = B(a) b 1 b2 b3 b4 1 1 1 1 0 1 0 0 0 0 1 1 0 0 0 1 xQ 4.0 5.0 b1 b2 b 3 b 4 — 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 — 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 Problem 2. 0 1.0 7.5 3. m 16 xQ = Qm 8. for x = −3.5 1. the quantizer saturates to its maximum positive value.0 −1. Finally. 5 C = u(y − xQ ) 1 1 1 1 b1 b2 b3 b4 b1 b2 b3 b4 1010 1111 For the 2’C case.0 C = u(y − xQ ) 1 0 1 0 test b 1 b2 b 3 b4 1 1 1 1 0 1 1 1 0 0 1 1 0 0 0 1 xQ 0.5 6.0 −3.2. int i.0 2. gives R = b(a).2 + 0. i--) p = a * p + b[i].12 Consider the division of B(z) by (z − a): B(z)= (z − a)Q(z)+R where the quotient polynomial Q(z) must have degree M − 1. we have y = −2. The 2’s complement case is obtained by complementing the MSB of the offset case.5 5. bM zM + bM−1 zM−1 + · · · + b1 z + b0 = (z − a)(qM−1 zM−1 + qM−2 zM−2 + · · · + q1 z + q0 )+R Equating like powers of z. double *b.13 For a polynomial of degree M = 3.5 5. return p.0 2. Indeed.1 Converter codes for B = 4 bits. and the following testing tables: 18 19 . 0 3.0 1. 0 1. B(z)= b1 z + b2 z2 + b3 z3 .0 1.0 3. 2. 0 2.0 3. R.25 * R * (2 * ran(&iseed) . fpe fpx = fopen("e". Problem 2. Rex = (double *) calloc(M+1. Ree[i]/normee). FILE *fpe. sizeof(double)). xq = dac(b.17 This problem is basically the same as Example 2. sizeof(double)).0).15 Similar to the testing tables of Examples 2. double normee. *Rxx. normee = Ree[0]. FILE *fpRee. M=50 */ #include <stdio.0 −3. the amplitude of the sinusoid A = 20 exceeds the quantizer range R/2 = 16. "w"). Q. x. *e. and therefore both the positive and negative peaks of the sinusoid will saturate to the positive and negative maxima of the quantizer. In part (c). Ree).0 void main() { int n. N.5 C = u(y − xQ ) 0 0 1 0 b1 b2 b3 b4 b1 b2 b3 b4 0000 0010 −3. R).0 0. /* exmpl246.0 −2. e. n++) { v = 0.1 to compute all the sample autocorrelations and cross-correlations. by y = x.5 0. *Ree. "% lf\n". sizeof(double)). M. b. M.4. e[n] = x[n] . "%lf\n". x. L. double dac(). for (i=0. Ree = (double *) calloc(M+1. fprintf(fpRex. e.c . &M).0 −2. fpRxx = fopen("Rxx".4. Rxx = (double *) calloc(M+1. &iseed. = fopen("x". normex. Problem 2. iseed. *fpRex.)) + v. e. Rxx[i]/Rxx[0]). To implement truncation instead of rounding. } Problem 2. Q = R / (1 << N). N.25 * R * cos(2 * pi * n / sqrt(131. x[n]).h> void adc(). fpRee = fopen("Ree". fpRex = fopen("Rex". R). 20 21 . e[n]). printf("enter L.1). Rxx). *b. sizeof(int)). the natural binary scale saturates to its minimum positive value. R = 32 volts. corr(). *Rex.double ran().xq. long iseed. pi = 4 * atan(1. i<=M. i. printf("enter N. xq.h> #include <stdlib. x = (double *) calloc(L. In this case. The same program segment of that example applies here for generating the codes and quantized values. Rex). M. M. N. x. fprintf(fpRxx. double *x.18 The following C program carries out all the required operations. normex = sqrt(Ree[0] * Rxx[0]). b = (int *) calloc(N. M = "). test b1 b2 b3 b4 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 xQ 4. It uses the routine corr of Appendix A. fprintf(fpx. "w"). scanf("%d %lf". &N.16 These versions are straight forward. Problem 2. R = "). *fpx. for (n=0.4.1 and 2. corr(L. &L. &R). "w"). "% lf\n". scanf("%d %ld %d". x[n] = 0. iseed=10. *fpRxx. } corr(L. "w"). corr(L. Rex[i]/normex).2. e = (double *) calloc(L. "w"). i++) { fprintf(fpRee. fprintf(fpe. double v. Only the full-scale range is different. n<L. "%lf\n".h> #include <math.0 1.quantization noise model * * default values: * N=10 bits * R=1024 * L=1000. replace the statement within adc: y = x + Q/2. sizeof(double)).0 2. sizeof(double)).5. "%lf\n".0 C = u(y − xQ ) 0 0 0 0 test b1 b2 b3 b4 1 0 0 0 0 1 0 0 0 0 1 1 0 0 0 1 xQ 0 . adc(x[n]. SNR = we may express the parameter a as: A 2 /2 2 σv E[v(n + k)cos(2πf0 n + φ)]= E[v(n + k)]·E[cos(2πf0 n + φ)]= 0 where the last zero follows either from the zero-mean property of v(n) and/or from the zero mean property of E[cos(2πf0 n + φ)]= 0. it varies of the limits E[cos(a + φ)]= 0 1 cos(a + φ)p(φ) dφ = 2π 2π 0 cos(a + φ) dφ = 0 Similarly. Q2 = R2 2B2 = R1 2B1 +B2 1 cos(a − b) 2 The following program segment illustrates the sequence of operations: E[cos 2πf0 (n + k)+φ cos(2πf0 n + φ)]= 1 1 cos(2πf0 (n + k)−2πf0 n)= cos(2πf0 k) 2 2 Finally.21 The quantization width of the first ADC will be Q1 = R1 /2B1 .5)2 ]= (0. we have the property: 2π E[cos(a + φ)cos(b + φ)] = = = Thus. by the independence assumption the expectation value of the product becomes the product of the expectation values: we finally have: a= A 2 /2 2 A2 /2 + σ v ⇒ 1−a= 2 σv 2 A2 /2 + σv ρxx (k)= a cos(2πf0 k)+(1 − a)δ(k) Defining the signal to noise ratio as the relative strength of the sinusoid versus the noise in the autocorrelation function.20 Inserting x(n)= A cos(2πf0 n + φ)+v(n) into the definition of the autocorrelation function. we will have: 22 23 . the cross terms will vanish. x2 = x − x1 . the normalized autocorrelation function becomes: ρxx (k)= Problem 2. } 2 E[v(n + k)v(n)]= σv δ(k) It follows that the autocorrelation of the noisy sinusoid will be: Problem 2.19 The mean of v is zero because E[u]= 0. Q/sqrt(12. Indeed.printf("erms = Q/sqrt(12) = %lf\n". and therefore. Thus. we must choose: cos(a + φ)cos(b + φ) dφ 1 2π R2 = Q 1 = R1 2B1 . we find: Defining the parameter: 2 σv A 2 /2 Rxx (k) = 2 2 cos(2πf0 k)+ 2 2 δ(k) Rxx (0) A /2 + σ v A /2 + σ v Rxx (k) = E[x(n + k)x(n)] = A2 E[cos 2πf0 (n + k)+φ cos(2πf0 n + φ)] + AE[cos 2πf0 (n + k)+φ v(n)]+AE[v(n + k)cos(2πf0 n + φ)] + E[v(n + k)v(n)] assuming φ and v(n) are independent random variables. is the quantization error. we find 0 cos(a + φ)cos(b + φ)p(φ) dφ 2π 0 − Q1 2 ≤ x2 ≤ Q1 2 These limits must serve as the full scale range of the second ADC. sqrt(normee)). We have: 2π a= SNR SNR + 1 ⇒ 1−a= 1 SNR + 1 Problem 2. The residual signal formed at the output of the first DAC. because v(n) is assumed to be zero-mean white noise. we have: Rxx (k)= 1 2 2 A cos(2πf0 k)+σv δ(k) 2 E[v]= 0.5R(E[u]−0. printf("Ree(0) = %lf\n".5: At lag k = 0.0)). that is.5)= 0 The variance of v is related to the variance of u as follows: 2 2 σv = E[v2 ]= (0.5R)2 Rxx (0)= R2 1 = 12 48 1 2 2 A + σv 2 Therefore.5R)2 E[(u − 0.5R)2 σu = (0. The latter follows from uniformity of φ whose probability density will be: p(φ)= 1/(2π). Q3 = R3 2B3 = R1 2B1 +B2 +B3 The following loop shows these operations: R2 = R1 / (1 << B1). − 3 ] h = [ 1 . b3 = (int *) calloc(B3. The term x(2n) will break time-invariance. h(n)= ah(n − 1)+δ(n) Iterating forward in time with zero initial condition h(−1)= 0. adc(x. R3). adc(x-x1. B1.9 for (b). Thus. we obtain the causal solution: h(0)= ah(−1)+δ(0)= a · 0 + 1 = 1 h(1)= ah(0)+δ(1)= a · 1 + 0 = a h(2)= ah(1)+δ(2)= a · a + 0 = a2 h(3)= ah(2)+δ(3)= a · a2 + 0 = a3 ··· h(n)= ah(n − 1)+δ(n)= a · an−1 = an . sizeof(int)). adc(x. 0 . but not linear since the output does not double whenever the input doubles. 1. B1. B1. Indeed. 4 ] h = [ 4 . the system is neither linear nor time-invariant. time-invariant since it has constant-in-time coefficients. which is then quantized to B3 bits with a full scale range and quantization width: y(n − D)= x2 (n − D − 1)+x(2(n − D))= x2 (n − D − 1)+x(2n − 2D) Thus.R2 = R1 / (1 << B1). (d) The system is linear. and a = 0. for (n=0. the system is not linear. 0 . (e) The time-dependent term n breaks both time invariance and linearity. B2. b1.x2. } Problem 3. b2. B1. R1). n<L. b3.22 The quantized triangularly-dithered signals were generated by the for-loop given in Example 2. for (n=0. adc(x3. (c) System is time-invariant.3 (a. R3 = Q2 = R2 2B2 . adc(x2. x2 = x . we find: (a) (b) (c) h = [ 3 . B2. the output due to x1 (n)= 2x(n) will be y1 (n)= 3x1 (n)+5 = 6x(n)+5 = 2(3x(n)+5).5. B2. however. 0 . Indeed. n++) { x = A * cos(2 * pi * f0 * n). x2 = dac(b2. sizeof(int)).1 (a) If the input is doubled the output is not doubled.2 Picking out the coefficients of the x-terms. for n ≥ 1 24 25 . sizeof(int)). x1 = dac(b1. R1). − 1 ] Problem 3. sizeof(int)). b1 = (int *) calloc(B1. Setting x(n)= δ(n) we find the difference equation for the impulse response: Problem 2.x1. −2 . The corresponding output yD (n) can be computed from the given I/O equation: When there is a third B3 -bit stage. sizeof(int)). n++) { x = A * cos(2 * pi * f0 * n). b2 = (int *) calloc(B2. b2 = (int *) calloc(B2. R3 = R2 / (1 << B2). x1 = dac(b1. R1). The system is. R2). B3.b) These problems are of the general form: y(n)= ay(n − 1)+x(n) with a = −0.1. (b) The quadratic term x2 (n − 1) breaks linearity because it quadruples whenever the input doubles. b1 = (int *) calloc(B1.9 for (a). 0.x1 . R2). this is not the same as the delayed (shifted) y(n) obtained by replacing n by n − D: B = B1 + B 2 + B 3 The B2 -bit output of the second ADC must be passed into a second DAC to get the corresponding analog value and subtracted from the input x − x1 to get the third error output. } Chapter 3 Problems Problem 3. x3 = x . let xD (n)= x(n − D) be a delayed input. the total number of bits will be yD (n)= x2 (n − 1)+xD (2n)= x2 (n − 1 − D)+x(2n − D) D but. R1). n<L. b2. b1. but the term nx(n − 3) breaks time-invariance. R2). 5xn−2 + 0.5)n−1 Proceeding as in the previous problem we have: if n = 0 if n ≥ 1 h(n)= yn = 5xn + 6 xn−1 + 0.81. . .6 We may write the given impulse response in the form: etc. Thus. 3(0.82 xn−3 + · · · 0. In cases (c) and (d).9. for (c) we have a = 0. 6(0.8yn−1 = 4xn−1 + 6 0. .81y(n − 2)+2x(n) And.Thus.5).81 = −(0. . h(n) will be the geometric series: h = [1. a2 .4 We have seen that if h(n)= an u(n). . h(n)= ah(n − 2)+δ(n) A few iterations (with zero initial conditions) give: Problem 3.5yn−1 = 4xn + 3xn−1 − 2xn−1 yn = 0. It follows that: 0.8xn−2 + 0. 3(0.5yn−1 = 2xn−1 + 3 0. we apply this result with a = 0.d) These problems are similar to Thus. a2 = −0. Thus.5yn−1 = 4xn + xn−1 or. we have: = 4xn + 3 xn−1 + 0. and y(n)= ay(n − 2)+x(n) with a = 0. we get: h(0)= 1 h(1)= 0 h(2)= ah(0)= a h(3)= ah(1)= 0 h(4)= ah(2)= a2 h(5)= ah(3)= 0.52 xn−3 + 0. and y(n)= 0. a.52 xn−3 + 0.5)3 . a3 .81y(n − 2)+2x(n) A systematic and simpler way of solving this type of problem will be presented after we cover z-transforms. a2 .8)2 . ] (e) The impulse response satisfies: h(n)= 0. 0. for (d) we have a = 0. a4 . 0.5h(1)= 3(0. 0. The impulse response will satisfy the difference equation: y(n)= −0. Problem 3.8). we apply this result twice and verify that h(n)= an u(n)+(−a)n u(n) leads to the difference equation y(n)= a2 y(n − 2)+2x(n) 26 27 . ] ⎧ ⎨4 ⎩3(0.5h(0)+1 = 3 h(2)= 0. .5)2 .81. .8)2 for (c).5 The impulse response sequence is explicitly: h = [4.82 xn−3 + · · · Problem 3.64 = (0.9 and a = −0.5)2 . a.9. . h(0)= 4 h(1)= 0. 6. ] (c. . a3 .9)2 for (d). 3. h(n)= 5δ(n)+6(0.5) h(3)= 0. 6(0.8)n−1 u(n − 1)= [5. then the I/O difference equation is which gives yn − 0. 0. . and a = −0. a2 = 0.5xn−2 + 0. ] Replacing these values into the convolutional equation. 0. .5h(n − 1)+4δ(n)+δ(n − 1) A few iterations give: yn − 0.8yn−1 = 5xn + 2xn−1 y(n)= ay(n − 1)+x(n) In cases (a) and (b). . 3(0.8xn−2 + 0.5h(2)= 3(0. all the odd-indexed h(n) are zero: yn = h0 xn + h1 xn−1 + h2 xn−2 + h3 xn−3 + h4 xn−4 + · · · etc.9j.53 xn−4 + · · · h = [1.53 xn−4 · · · Subtracting. which is valid for all n: a m h(m − 1)x(n − m)= a k h(k)x(n − k − 1)= ay(n − 1) the last equation following from the convolution equation by replacing n by n − 1: y(n)= k h(k)x(n − k) ⇒ y(n − 1)= k h(k)x(n − 1 − k) h(n)= c0 δ(n)+c1 an−1 u(n − 1) where the shifted unit-step u(n − 1) vanishes for n = 0 and equals one for all n ≥ 1. we map this difference equation for h(n) into a difference equation for y(n). that is. setting b0 = c0 and b1 = c1 − ac0 and solving for h(n) we find aM δ(n − M)+aM−1 δ(n − M + 1)+ · · · But. hn + a1 hn−1 + · · · + aM hn−M = 0. However. indeed. then these terms vanish too. which was essentially derived in Example 3. the second term of hn will be annihilated by (1 − p2 D). h(n) satisfies the recursions h(n)= ah(n − 1). b1 x(n − 1). with a change of variables of summation from m to k = m − 1 or m = k + 1.Problem 3.8 First. Therefore. let us determine directly the difference equation satisfied by h(n) and from that determine the difference equation for y(n). terms in hn will be annihilated by the delay polynomial: hn + a1 hn−1 + a2 hn−2 = (1 + a1 D + a2 D2 )hn = (1 − p1 D)(1 − p2 D)hh 28 29 .7 had b0 = c0 = 2 and b1 = c1 − ac0 = 4 − 2 · 0. Instead of manipulating the I/O convolutional equation into a difference equation as we did above. the a-term is recognized to be ay(n − 1). the a1 = −(p1 + p2 ). Therefore. n≥M+1 Problem 3. b0 x(n). p2 : 1 + a1 z−1 + a2 z−2 = (1 − p1 z−1 )(1 − p2 z−1 ) so that y(n) = m h(m)x(n − m) ah(m − 1)+b0 δ(m)+b1 δ(m − 1) x(n − m) m = =a h(m − 1)x(n − m)+ m m b0 δ(m)+b1 δ(m − 1) x(n − m) Then. Because h(n) satisfies h(n)= ah(n − 1) for n ≥ 2.4. etc. that is.5 = 3. we have n−1 u(n − 2) (1 − aD)fn = fn − afn−1 = an − aan−1 = 0 n where D is the delay operator defined by (Df )n = fn−1 . the presence of δ(m) extracts only the m = 0 term. h(n − 1)= c0 δ(n − 1)+c1 a and n−2 u(n − 2) Problem 3.10 Define the polynomial with roots p1 . we have (1 − p1 D)(1 − p2 D)· · · (1 − pM D)= 1 + a1 D + a2 D2 + · · · + aM DM h(n)−ah(n − 1)= c0 δ(n)−ac0 δ(n − 1)+c1 an−1 δ(n − 1) But note that an−1 δ(n − 1)= δ(n − 1) because it is nonzero only at n = 1 for which we have a1−1 δ(0)= a0 δ(0)= δ(0). we are led to consider the delayed function h(n − 1) and multiply it by a: We finally find the I/O difference equation for y(n): y(n)= ay(n − 1)+b0 x(n)+b1 x(n − 1) which is exactly the same as that satisfied by h(n). the difference equation satisfied by hn will be: h(n)= ah(n − 1)+b0 δ(n)+b1 δ(n − 1) Example 3. all the terms in hn will be annihilated by the product h(n)−ah(n − 1)= c0 δ(n)−ac0 δ(n − 1)+c1 a n−1 u(n − 1)−u(n − 2) But the difference u(n− 1)−u(n− 2)= δ(n− 1) as follows from the standard result u(n)−u(n− 1)= δ(n). Moreover. Then. that is.9 The Ci pn terms are annihilated by the same product as in the previous problem. The given expression for h(n) can be rewritten in the more compact form. pn i a 2 = p 1 p2 In the second sum. It follows that the first term p1 u(n) of hn will be annihilated by (1 − p1 D).4. To do this we start with the convolutional equation and replace h(m) by its difference equation expression. whereas the presence of δ(m − 1) extracts only the m = 1 term.4. Thus. if n ≥ M + 1. the i δ(n) term will contain the delayed terms: h(n)−ah(n − 1)= c0 δ(n)−ac0 δ(n − 1)+c1 δ(n − 1)= c0 δ(n)+(c1 − ac0 )δ(n − 1) Or. Next.7 It is evident from the definition that for n ≥ 2. Problem 3. note that if fn = an u(n) then for n ≥ 1 ah(n − 1)= ac0 δ(n − 1)+c1 a Subtracting. b2 may be found by explicitly calculating the right-hand side of this difference equation using the expression for hn .12 Define the polynomial with roots p1 . (P3. the results can be justified quickly using z-transforms: (1 − 0.5jD)(1 + 0.5D)= 1 − 0.5jD)= 1 + 0.4D)(1 − 0.4hn−2 = 0 For (b).25hn−2 = 0 For (c). the coefficient of C1 is p2 + a1 p1 + a2 . the a1 = −(p1 + p2 + p3 ). pn i a 2 = p 1 p2 + p 2 p3 + p 3 p 1 . Similarly.4hn−1 − 0. we obtain the I/O difference equation: hn + a1 hn−1 + a2 hn−2 + a3 hn−3 = 0.8D)= 1 − 1. 2: (C1 + C2 )−(C1 p2 + C2 p1 )z−1 C1 C2 = H(z)= + 1 − p1 z−1 1 − p2 z−1 (1 − p1 z−1 )(1 − p2 z−1 ) which may be rewritten as or. we have with n ≥ 2: ⇒ (1 − 0. a3 = −p1 p2 p3 terms in hn will be annihilated by the delay polynomial: (1 + a1 D + a2 D2 + a3 D3 )hn = (1 − p1 D)(1 − p2 D)(1 − p3 D)hh = 0 (P3.25D2 hn + 0. b2 .25D2 + 0.1D3 hn − 0. b1 . or.3hn−1 + 0. Problem 3. hn will satisfy the difference equation: Then. 1.3D + 0. p2 . 1: Problem 3. we evaluate the right hand side for n = 0.5D)(1 + 0. 2: b0 = C1 + C2 + C3 b1 = − C1 (p2 + p3 )+C2 (p3 + p1 )+C3 (p1 + p2 ) b2 = C1 p2 p3 + C2 p3 p1 + C3 p1 p2 b0 = h 0 b1 = h 1 + a 1 h0 b2 = h 2 + a 1 h1 + a 2 h 0 which give: Problem 3.13 For (a). we find: b0 = C 1 + C 2 b1 = C1 p1 + C2 p2 − (p1 + p2 )(C1 + C2 )= −(C1 p2 + C2 p1 ) To summarize.5D)(1 − 0. for n = 0.for n ≥ 2.4D2 hn − 1. we have with n ≥ 3: ⇒ C1 C2 + H(z) = C0 + 1 − p1 z−1 1 − p2 z−1 (C0 + C1 + C2 )− C1 p2 + C2 p1 + C0 (p1 + p2 ) z−1 + C0 p1 p2 z−2 = (1 − p1 z−1 )(1 − p2 z−1 ) (1 − 0. n≥3 yn + a1 yn−1 + a2 yn−2 = b0 xn + b1 xn−1 These results can be obtained quickly using z-transforms: The coefficients b0 . b1 . we have with n ≥ 2: b0 = C 0 + C 1 + C 2 b1 = C1 p1 + C2 p2 + a1 (C0 + C1 + C2 )= −(p1 + p2 )C0 − (C1 p2 + C2 p1 ) b2 = C1 p2 + C2 p2 + a1 (C1 p1 + C2 p2 )+a2 (C0 + C1 + C2 )= C0 p1 p2 1 2 In b2 .1hn−3 = 0 ⇒ 30 31 . b0 = h 0 b1 = h 1 + a 1 h 0 b2 = h 2 + a 1 h 1 + a 2 h0 H(z)= b0 + b1 z−1 1 + a1 z−1 + a2 z−2 b0 = C1 + C2 + C3 b1 = C1 p1 + C2 p2 + C3 p3 + a1 (C1 + C2 + C3 ) b2 = C1 p2 + C2 p2 + C3 p2 + a1 (C1 p1 + C2 p2 + C3 p3 )+a2 (C1 + C2 + C3 ) 1 2 3 which simplify into: and leads to the desired difference equations for hn and yn .1) for n ≥ 3.25hn−2 + 0. p3 : 1 + a1 z−1 + a2 z−2 + a3 z−3 = (1 − p1 z−1 )(1 − p2 z−1 )(1 − p3 z−1 ) so that b0 = h0 + a1 h−1 + a2 h−2 = h0 = C1 + C2 b1 = h1 + a1 h0 + a2 h−1 = h1 + a1 h0 = C1 p1 + C2 p2 + a1 (C1 + C2 ) Using the expression for a1 . for n = 0. 1. b1 may be found by explicitly calculating the right-hand side of this difference equation using the expression for hn . To determine the coefficients b0 . The coefficients b0 . the coefficient of C2 is zero.1) will be satisfied for n ≥ 3. hn + a1 hn−1 + a2 hn−2 = b0 δ(n)+b1 δ(n − 1) Inserting this into the convolutional equation. which is zero because p1 is a root of the polynomial 1 z2 + a1 z + a2 . Again.11 Now the difference equation Eq.4D − 0. y(n)= k h(k)x(n − k) ⇒ y(n − D)= k h(k)x(n − D − k) Problem 3.15 Starting with ˜ y(n) = m=−D ˜ h(m)x(n − m)= m=−D h(m)x(n − m) y(n)= m h(m)x(n − m) Subtracting. x(m)= sign h(−m) . we have: yD (n) = m hD (m)x(n − m)= m h(m − D)x(n − m) = k h(k)x(n − D − k)= y(n − D) where we changed summation variables from m to k = m − D. the terms m ≥ −D cancel and we get: −D−1 we obtain at n = 0: ˜ y(n)−y(n)= m=−∞ h(m)x(n − m) y(0)= m h(m)x(−m) Assuming x(n) is bounded by A. y(n) and. and evaluated y(n) at n − D.16 Working with the convolutional I/O equation. Therefore. we have: −D−1 −D−1 −D−1 But. It follows: ˜ |y(n)−y(n)| = | m=−∞ h(m)x(n − m)| ≤ m=−∞ |h(m)||x(n − m)| ≤ m=−∞ |h(m)|A y(0)= m h(m)x(−m)= m h(m)sign h(m) This summation is finite because it is a subsum of the stability condition: −D−1 ∞ Recognizing that in general xsign(x)= |x|. then this term would not contribute to the convolutional sum. we have: ∞ |y(n)| = | m h(m)x(n − m)| ≤ m |h(m)||x(n − m)| ≤ m |h(m)|B = AB y(n) = m=−∞ ∞ h(m)x(n − m) ∞ Problem 3.Problem 3. we find |h(m)| ≤ m=−∞ m=−∞ |h(m)| < ∞ y(0)= m |h(m)| In the limit of large D.18 ˜ Because h(n) agrees with h(n) for n ≥ −D. If at some m. hence y(0). the number of terms shrinks to zero giving: −D−1 D→∞ Because x(n) was bounded. h(m)= 0. 32 33 . that is.14 From the convolutional I/O equation we get: Problem 3.17 We have: hD (m)xA (n − m)= m m h(m − D)x(n − m + D)= k h(k)x(n − k) where we changed variables of summation from m to k = m − D. must be bounded. x(−m)= sign h(m) . lim |h(m)| → 0 m=−∞ Problem 3. 4 . aligning the output blocks according to their absolute timings and adding them up gives the final result: n y0 y1 y2 y 0 1 1 3 2 5 3 6 1 7 4 4 3 7 5 1 5 6 6 6 1 7 7 4 2 6 8 1 3 4 9 10 1 3 5 3 3 1 1 In practice this method is implemented efficiently by computing the individual block convolutions using the FFT instead of time-domain convolution. 1.Chapter 4 Problems Problem 4. we get y = [ 4. 2] y1 = h ∗ x1 = [1. It follows from timeinvariance that the corresponding output blocks will also begin at the same absolute times. 7. 5 . 5. 3. 4. the length of each x-block is chosen to be N1 = N − M.1 The convolution table is: h\x 1 1 2 1 Folding the table. 6. we get y = [ 1 . 6 . 1. The computational gain of this “fast” convolution method versus the conventional time-domain “slow” method is approximately log2 N fast = slow M If the input is divided into length-5 subblocks. 2] The first and last three samples are the input and output transients. 3. 1 . 3. 1. 3. 6. 6 . 2. Thus. 2. 0] These convolutions can be done by separately folding the three convolution subtables: block 2 2 2 4 2 0 1 1 1 2 1 1 1 1 2 1 block 2 2 2 4 2 1 1 1 1 2 1 1 1 1 2 1 block 1 1 1 2 1 2 0 0 0 0 0 Problem 4. 1] Aligning them at multiples of n = 5. 3 . 1. 0 ] x0 x1 x2 n y0 y1 y 0 1 1 1 3 3 2 5 5 3 7 7 4 7 7 5 5 1 6 6 5 2 7 7 2 4 6 8 4 4 9 3 3 10 1 1 where we padded an extra zero at the end to get a length-3 block. 7. 3 . and the middle 5 samples are the steady-state outputs. 1 . The LTI table is: 2 4 -4 -2 2 2 4 -4 -2 2 0 0 0 0 0 1 2 -2 -1 1 -1 -2 2 1 -1 0 0 0 0 0 1 2 -2 -1 1 2 4 -4 -2 2 h\ x 1 1 2 1 1 1 1 2 1 34 35 . the input is divided into the following three contiguous blocks: x = [ 1. the last subblock will have length 3: x = [ 1. 1. 4. 1 ] The first and last three samples are the input and output transients. 1. 7. 1] y2 = h ∗ x2 = [1. − 2 . − 6 . 1. 4. 5. − 5. 3. 6. 3. − 1 . 2. 1. 2. For an FIR filter of order M and an FFT of length N (which is a power of two). 4. 1 ] x0 The convolutions of the subblocks with the filter are: y0 = h ∗ x0 = [1. 5. respectively. we have: x1 n x\ h 1 2 1 1 2 1 1 1 0 1 1 1 1 1 2 2 2 2 2 1 3 1 1 4 1 1 4 5 6 7 8 9 10 partial output x(0)h(n − 0) x(1)h(n − 1) x(2)h(n − 2) x(3)h(n − 3) x(4)h(n − 4) x(5)h(n − 5) x(6)h(n − 6) x(7)h(n − 7) 2 2 1 2 1 2 2 1 1 4 1 1 7 2 2 1 1 6 1 2 1 4 1 2 3 1 1 y(n) 1 3 5 7 7 6 x(m)h(n − m) m For the overlap-add method. 1] y1 = h ∗ x1 = [1. 4. 7 . 7. 2. Convolving each block separately with h gives: y0 = h ∗ x0 = [1. and the middle 5 samples are the steady-state outputs. 0 . 1. 5. 3. 5. The LTI table is: 1 1 1 2 1 2 2 2 4 2 1 1 1 2 1 1 1 1 2 1 2 2 2 4 2 1 1 1 2 1 1 1 1 2 1 1 1 1 2 1 The three subblocks begin at the absolute times n = 0. 2. 1. 2 .2 The convolution table is: h\x 2 -2 -1 1 Folding the table. 3. and computed output signals. P4. 0 ] x0 x1 x2 n y(n) 4 3 2 1 0 3 6 10 13 on where we padded an extra zero at the end to get a length-3 block.1). −1] y1 = h ∗ x1 = [0. 2. 0. 2. −1. 1. h\ x 2 -2 -1 1 block 0 2 2 0 4 4 0 -4 -4 0 -2 -2 0 2 2 0 block 1 1 -1 0 2 -2 0 -2 2 0 -1 1 0 1 -1 0 block 2 1 2 2 4 -2 -4 -1 -2 1 2 For the direct form.1 shows the filter. we get: 10 + m ≤ n ≤ 20 + m Using the first of Eq. we change the sign of the second of Eq.3 Figure P4. 1.1) are equivalent to 3≤m≤6 n − 20 ≤ m ≤ n − 10 ⇒ max (3. 2] These convolutions can be done by separately folding the three convolution subtables: 16 20 steady 23 off 26 n Fig. To find the limits of summation over m. we have: Aligning the output subblocks at multiples of n = 3. 2. (P4. 0. 0. the inequalities in Eq.n x\h 2 2 0 1 -1 0 1 2 0 2 4 1 -2 -4 4 2 -1 -2 -4 0 3 1 2 -2 0 2 4 5 6 7 8 9 10 partial output x(0)h(n − 0) x(1)h(n − 1) x(2)h(n − 2) x(3)h(n − 3) x(4)h(n − 4) x(5)h(n − 5) x(6)h(n − 6) x(7)h(n − 7) n y0 y1 y 0 4 4 1 0 0 2 -6 -6 3 2 2 4 -2 -2 2 0 -2 -2 5 1 0 1 6 2 2 4 7 -1 2 1 8 -5 -5 9 -1 -1 10 2 2 0 -1 2 0 1 1 0 2 4 -1 0 -2 4 1 Problem 4. −2. −6.1) n y0 y1 y2 y 0 4 1 0 2 -6 3 0 2 2 4 2 -4 -2 5 1 1 1 6 7 8 9 10 ⇒ 13 ≤ n ≤ 26 4 0 -6 If the input is divided into length-5 subblocks. x(n). −1. 0. n − 10) The final expression for the direct form will be: 36 37 . and y(n) signals of Problem 4. 1. 1. 2. 0] y2 = h ∗ x2 = [2. −5. 1. we extend the range to: 2 2 4 -1 2 1 0 -5 -5 -1 -1 2 2 10 + 3 ≤ 10 + m ≤ n ≤ 20 + m ≤ 20 + 6 (P4. the input is divided into the following three contiguous blocks: x = [ 2. −2. 0. 2] Aligning them at multiples of n = 5.1 h(n). 0. (P4. −5. 2. 2. the indices of hm and xn−m are restricted to lie within their respective ranges: 3≤m≤6 10 ≤ n − m ≤ 20 Solving the second with respect to n. input. 0. −6. −1. 1. n − 20)≤ m ≤ min(6. (P4. 2 ] x0 The convolutions of the subblocks with the filter are: y0 = h ∗ x0 = [4. 2] y1 = h ∗ x1 = [2.1) and solve for m: −20 ≤ m − n ≤ −10 ⇒ n − 20 ≤ m ≤ n − 10 Thus. 2. we have: x1 This is the range of index n of the output yn . Convolving each block separately with h gives: y0 = h ∗ x0 = [4. −4. the last subblock will have length 3: x = [ 2. −1. 0 -1 -4 -5 1 -2 -1 2 2 y(n) 4 0 -6 2 -2 1 x(m)h(n − m) m h(n) 1 0 3 6 10 13 x(n) 16 20 23 26 For the overlap-add method. 2. −1. (4. where 0 < a < 1. that is.n−3) yn = m=max(10.n−20) 1 · 1 = min(6. For the LTI form. Eq.16) becomes: n yDC = m hm = 1 + 1 + 1 + 1 = 4 y(n)= m=max(0. n − 6)− max (20. 4 .n−L+1) am · 1 Using the geometric series identity M2 am = m=M1 aM1 − aM2 +1 1−a we find: 38 39 . In particular. if the filter and input signals are unity over the ranges (P4. (P4.1) is replaced by 10 ≤ m ≤ 20 3≤n−m≤6 This leads to the same range for the output index n. more explicitly: input-on: 13 ≤ n ≤ 15 steady-state: 16 ≤ n ≤ 23 input-off: 24 ≤ n ≤ 26 With numerical values: y = { 1. we have: yn = m=max(10. The middle samples are the steady samples.1. the output will not begin to come out until 3 time instants after the input begins.n−6) xm hn−m . (P4. 0≤n<∞ Note also that because the filter is delayed by 3 samples. Note that because the input is constant.2). 2 . the steady-state DC output can be predicted in advance from the DC gain: y(n)− → yn = n − 10 − 3 + 1 = n − 12 yn = 6 − 3 + 1 = 4 yn = 6 − (n − 20)+1 = 27 − n If x(n)= (−1)n u(n). we find: n y(n)= m=max(0. Eq. 3 . 3. In summary. input-on: 13 ≤ n ≤ 15 yn = m=3 6 hm xn−m Problem 4.2) The steady-state response is the large-n limit of this formula.n−20) hm xn−m . we use the formula: n n steady-state: 16 ≤ n ≤ 23 yn = m=3 6 input-off: 24 ≤ n ≤ 26 yn = m=n−20 hm xn−m y(n)= m=0 h(m)x(n − m)= m=0 am u(m)u(n − m) or. (P4.n−10) n y(n)= m=0 am = 1 − an+1 1−a yn = m=max(3. we have n 1 1−a for n − ∞ → n y(n)= m=0 am (−1)n−m = (−1)n m=0 (−a)m = (−1)n 1 − (−a)n+1 1+a Problem 4.1). Using the time-domain convolution formula determine a closedform expression for the output signal y(n) for the two time ranges: 0 ≤ n ≤ L − 1 and n ≥ L.n−6) 1 · 1 = min(10. for 13 ≤ n ≤ 26 For part (b). Also. n − 20)+1 (P4. at n = 23. Similarly. 2 . 4 . 4 . the three ranges are: n−10 min(20. the output can be expressed compactly as: min(6. 4 . Because the filter is infinite (M = ∞). that is.n−L+1) h(m)x(n − m).3) Note that Eq. 4 . Or. 1 } The first and last M = 3 samples are the input on/off transients. 4 . n − 10)− max (3.3) is equivalent to Eq.n−10) min(20.5 Consider the IIR filter h(n)= an u(n). the input is cutoff at n = 20 but this is not felt by the filter until 3 instants later.n−3) yn = m=max(3.min(6. n − 3)+1 (P4. 4 . that is at n = 13. The square pulse x(n)= u(n)−u(n − L) of duration L is applied as input.4 hm xn−m Because both the input and filter are causal and have infinite duration. for 13 ≤ n ≤ 26 The transition from the input-on transients to the steady state takes place at time 6 = n − 10 or n = 16 at which the upper limit switches from n − 10 to 6. for 13 ≤ n ≤ 26. but to the summation limits: Inserting the given signals for h(n) and x(n). the transition from steady state to the input-off transients occurs at 3 = n − 20 or n = 23 when the lower limit switches from 3 to n − 10. 4 . for 0 ≤ n ≤ L − 1. for n ≥ L.8: /* convex. for (n=0. m++) y[n] += x[m] * h[n-m]. for (n=0. yb). for (n=0. n++) printf("%lf\n". x.h> #include <stdlib. x. /* blkfilt. L. n++) printf("%lf\n". -0. n. n). for (n=0. int M. n++) ha[n] = 0. } Problem 4. we have max (0. ya = (double *) calloc(L+Ma.convolution example 4. The following routine is an implementation of Eq. L = 200. else x[n] = 0. -1. m <= min(n. (4. x = (double *) calloc(L. we have max (0. yb[n]).75.19): /* convlti. 4. y=output block M=filter order.1.8 */ #include <stdio. double *x. L=input length for (n = 0. sizeof(double)).8 y(n)= amax(0. *y. 2.8.Problem 4.2}. void main() { int K = 50. 4.(b) define filter (a) define input y(n)−ay(n − 1)= an−L+1 yL−1 − aan−1−L+1 yL−1 = 0 = x(n) Problem 4.2. we have at n = 0.h> #define MAX 64 memory allocation size 40 41 . and y(n)= 1−a 1−a n+1 (input-on transients and steady state) whereas for n ≥ L.h> void convlti(M. n<=Ma.convolution in LTI form */ #include <stdlib.1. L-1).FIR filtering by block convolution */ #include <stdio. h. n<L. sizeof(double)). n++) for (y[n] = 0. yb = (double *) calloc(L+Mb. } h=filter. hb.c . 1−a 1−a (input-off) Thus. *x.h> #define Ma 14 #define Mb 5 void conv().1. for 1 ≤ n ≤ L − 1. m. n++) if (n%K < K/2) x[n] = 1. -2. after the input is turned off. n<L+Ma. Problem 4. and y(n)= an−L+1 − an+1 1 − aL = an−L+1 = an−L+1 y(L − 1). n − L + 1)= n − L + 1.1. we have x(n)= 0 and Ex. we have x(n)= 1 and 1 − an+1 1 − an 1 − an+1 − a + an+1 −a = = 1 = x(n) y(n)−ay(n − 1)= 1−a 1−a 1−a Finally. m = max(0. *ya. n < L+M.c . y) double *h.7 For example.n−L+1) − an+1 1−a The following C program computes the output signals of the two filters (a) and (b) of Example 4. defines max( ) and min( ) In particular. x.9 A complete such program is included below. 1 − a0+1 − a · 0 = 1 = x(0) 1−a y(0)−ay(−1)= Then. L. n − L + 1)= 0. n-M).h> #include <math. sizeof(double)). conv(Mb. conv(Ma. hb[Mb+1] = {0.6 From the previous problem. the LTI form is obtained by interchanging the roles played by x and h and their lengths L and M + 1.8 (a) Ex.h> #include <stdlib. L. n<L+Mb. L. double ha[Ma+1]. x=input block. { int n. ya).c .25 * pow(0. *yb. 1.1. the output decays exponentially to zero. ya[n]). ha. compute outputs printf("\n\n"). and so on. N. } h = (double *) realloc((char *) h. The program can receive its input from stdin with the user entering the input samples one at a time.void blockcon(). int max = MAX.) { for (N=0. initial allocation size M--. i++) printf("%lf\n". write entire y block if (argc != 3) { fprintf(stderr. exit(0). At the end. } if ((fph = fopen(argv[1]. ytemp). one must enter a <CTRL-Z> (for MSDOS) in order for the program to process the input-off transients. final allocation x = (double *) calloc(L. preliminary allocation for (. output samples allocation for h and increment if (argc != 2) { fprintf(stderr. Then. x. h = (double *) realloc((char *) h. "%lf". sizeof(double)). } last: blockcon(M. *y. /* firfilt. Problem 4. "usage: blkfilt hfile L <xfile >yfile\n"). *ytemp. } if (fscanf(fph. h + M) == EOF) break. if necessary max += dmax. } block length The dimension of the filter array h is determined on the fly by reading the file of filter coefficients. int M. M). void main(int argc. x. L. double *h. allocate output block ytemp = (double *) calloc(M. input. "r")) == NULL) { fprintf(stderr. int M.h> #define MAX 64 double fir(). *x.FIR filtering by sample-by-sample processing */ #include <stdlib. argv[1]).10 A complete such program is included below. } if ((fph = fopen(argv[1]. reallocate h max += dmax. read input block N=L except for last process block write output block process last block last block has N<=L for (M=0. exit(0). "usage: firfilt hfile <xfile >yfile\n"). exit(0). The filtering portion of the program is identical to the program segment discussed at the end of Section 4. y.. h = (double *) realloc((char *) h. exit(0). for (i=0. L = blocksize initial allocation & increment for (i=0. (max + 1) * sizeof(double)). } h = (double *) calloc(max + 1. (max + 1) * sizeof(double)). states. "%lf". exit(0). read h for (M=0. sizeof(double)). i<N+M. char **argv) { FILE *fph. sizeof(double)). However.10. dmax = MAX. y. int max = MAX.1. allocate input block y = (double *) calloc(L + M. "r")) == NULL) { fprintf(stderr. sizeof(double)). initialized to zero start filtering: filter file filter. will the program output the first group of L outputs. } filter file M = filter order.c . double *h. h. 42 43 . i. y[i]). char **argv) { FILE *fph. h = (double *) calloc(max + 1. *w. N. sizeof(double)). "can’t open filter file: %s\n". i++) printf("%lf\n". L. M++) { if (M == max) { if necessary. "can’t open filter file: %s\n". the program keeps reallocating the length of h in increments of MAX coefficients until the final length is determined and the final reallocation is made.. x. ytemp).. y[i]). dmax = MAX. "blocksize L must be at least %d\n". the next group of L input samples is entered and the program outputs the corresponding group of L outputs. N<L. blockcon(M. M is filter order if (L < M) { fprintf(stderr. argv[1]). Because the length of this file is not known in advance. (M + 1) * sizeof(double)). y. only after a group of L samples has been entered followed by a <CR> (carriage return). x+N) == EOF) goto last. M++) { read h if (M == max) { reallocate h.h> #include <stdio. void main(int argc. } L = atoi(argv[2]). i<L. N++) if (scanf("%lf". h + M) == EOF) break. h. } if (fscanf(fph. i. } M--; M is filter order final allocation if ((fph = fopen(argv[1], "r")) == NULL) { fprintf(stderr, "can’t open filter file: %s\n", argv[1]); exit(0); } h = (double *) calloc(max + 1, sizeof(double)); preliminary allocation h = (double *) realloc((char *) h, (M + 1) * sizeof(double)); w = (double *) calloc(M + 1, sizeof(double)); start filtering: while(scanf("%lf", &x) != EOF) { y = fir(M, h, w, x); printf("%lf\n", y); } for (i=0; i<M; i++) { y = fir(M, h, w, 0.0); printf("%lf\n", y); } } keep reading input samples compute output sample write output sample input-off transients for (M=0;; M++) { read h if (M == max) { reallocate h, if necessary max += dmax; h = (double *) realloc((char *) h, (max + 1) * sizeof(double)); } if (fscanf(fph, "%lf", h + M) == EOF) break; } M--; M is filter order As in the case of blkfilt.c, the dimension of the filter array h is determined on the fly by reading the file of filter coefficients. The program keeps reallocating the length of h in increments of MAX coefficients until the final length is determined and the final reallocation is made. The filtering portion of the program is identical to the program segment discussed in Section 4.2.3. The program can receive its input from stdin with the user entering the input one sample at a time. After each input is entered followed by a <CR>, the program computes and outputs the corresponding output sample. (One can also enter a few input samples at a time, followed by a <CR>, and the program will produce the corresponding outputs.) At the end, one must enter a <CTRL-Z> (for MSDOS) in order for the program to process the input-off transients. } h = (double *) realloc((char *) h, (M + 1) * sizeof(double)); w = (double *) calloc(M + 1, sizeof(double)); initialize p p = w; start filtering: while(scanf("%lf", &x) != EOF) { y = cfir(M, h, w, &p, x); printf("%lf\n", y); } for (i=0; i<M; i++) { y = cfir(M, h, w, &p, 0); printf("%lf\n", y); } keep reading input samples compute output sample write output sample input-off transients Problem 4.11 A complete such program is included below. /* cfirfilt.c - FIR filtering using circular delay-line buffer */ #include <stdlib.h> #include <stdio.h> #define MAX 64 double cfir(); void main(int argc, char **argv) { FILE *fph; double *h, *w, *p; double x, y; int M, i; int max = MAX, dmax = MAX; initial allocation size It is identical to firfilt.c, except it uses the circular version cfir instead of fir to do the filtering. In addition, the circular pointer p is defined and initialized by the program. This program must be compiled and linked with cfir.c and wrap.c. The version using the routine cfir1 is identical. The following version is based on the routine cfir2 and uses the circular pointer index q instead of the pointer p. It must be linked with the routines cfir2 and wrap2. /* cfirfil2.c - FIR filtering using circular delay-line buffer */ #include <stdlib.h> #include <stdio.h> filter file filter, states, circular pointer input and output samples allocation for h and increment #define MAX 64 double cfir2(); void main(int argc, char **argv) { FILE *fph; double *h, *w; double x, y; int M, i, q; int max = MAX, dmax = MAX; initial allocation size if (argc != 2) { fprintf(stderr, "usage: cfirfilt hfile <xfile >yfile\n"); exit(0); } filter file filter, states, circular pointer input and output samples circular pointer index allocation for h and increment 44 45 if (argc != 2) { fprintf(stderr, "usage: cfirfil2 hfile <xfile >yfile\n"); exit(0); } if ((fph = fopen(argv[1], "r")) == NULL) { fprintf(stderr, "can’t open filter file: %s\n", argv[1]); exit(0); } h = (double *) calloc(max + 1, sizeof(double)); preliminary allocation if (argc != 3) { fprintf(stderr, "usage: cdelfilt i D <xfile >yfile\n"); exit(0); } i = atoi(argv[1]); D = atoi(argv[2]); if (i>D) { fprintf(stderr, "i must be in the range {0, 1, ..., D}\n"); exit(0); } w = (double *) calloc(D + 1, sizeof(double)); p = w; while(scanf("%lf", &x) != EOF) { *p = x; y = tap(D, w, p, i); cdelay(D, w, &p); printf("%lf\n", y); } for (j=0; j<i; j++) { *p = 0; y = tap(D, w, p, i); cdelay(D, w, &p); printf("%lf\n", y); } } for (M=0;; M++) { read h if (M == max) { reallocate h, if necessary max += dmax; h = (double *) realloc((char *) h, (max + 1) * sizeof(double)); } if (fscanf(fph, "%lf", h + M) == EOF) break; } M--; M is filter order initialize p keep reading input samples store in circular buffer y(n) = x(n-i) = i-th delay update delay line write output sample h = (double *) realloc((char *) h, (M + 1) * sizeof(double)); w = (double *) calloc(M + 1, sizeof(double)); initialize q q = 0; start filtering: input-off transients zero input while(scanf("%lf", &x) != EOF) { y = cfir2(M, h, w, &q, x); printf("%lf\n", y); } for (i=0; i<M; i++) { y = cfir2(M, h, w, &q, 0); printf("%lf\n", y); } } keep reading input samples compute output sample write output sample Problem 4.13 input-off transients Consider a 3d order filter with internal states wi (n)= x(n − i), i = 0, 1, 2, 3. They are delayed replicas of each other: w3 (n) = w2 (n − 1) w2 (n) = w1 (n − 1) Problem 4.12 The following C program is an implementation: /* cdelfilt.c - Implementation of delay using circular buffer */ #include <stdlib.h> #include <stdio.h> double cdelay(); double tap(); void main(int argc, char **argv) { double *w, *p; double x, y; int D, i, j; w1 (n) = w0 (n − 1) w0 (n) = x(n) Thus, the current states are obtained from the previous ones by shifting the previous contents of the delay line and reading x(n) into w0 (n). Once this shift is done, the filter’s output is computed by the dot product: y(n)= h0 w0 (n)+h1 w1 (n)+h2 w2 (n)+h3 w3 (n) The following routine firalt.c implements this alternative procedure: /* firalt.c - Alternative version of FIR filter in direct form */ linear buffer & circular pointer input and output samples double firalt(M, h, w, x) double *h, *w, x; int M; { Usage: y=firalt(M, h, w, x); h=filter, w=state, x=input M=filter order 46 47 int i; double y; for (i=M; i>=1; i--) w[i] = w[i-1]; w[0] = x; for (y=0, i=0; i<=M; i++) y += h[i] * w[i]; return y; } n y=output sample update states from previous call done in reverse order read current input sample x x 1 2 1 1 2 1 1 1 0 0 0 w0 1 2 1 1 2 1 1 1 0 0 0 w1 0 1 2 1 1 2 1 1 1 0 0 w2 0 0 1 2 1 1 2 1 1 1 0 w3 0 0 0 1 2 1 1 2 1 1 1 y = w0 + w1 + 2w2 + w3 1 3 5 7 7 6 7 6 4 3 1 process current output sample 0 1 2 3 4 5 6 7 8 9 10 Note that the previous state vector is updated first into its current value, the current input is read into w0 , and only then is the output y computed. Upon exit, the states are left at their current values and not updated. They will be updated by the next call. The vector w must be initialized to zero prior to the first call, just like the fir.c case. The first three outputs correspond to the input-on transients (the internal delay registers are still filling up). The period 3 ≤ n ≤ 7 corresponds to steady state (all delays are filled). The last three outputs, in general the last M outputs for an M-th order FIR filter, are the input-off (x = 0) transients (the delays gradually empty out their contents). A C routine and main program implementing this algorithm are given below: #include <stdio.h> #include <malloc.h> Problem 4.14 Introduce the internal states: declares calloc() w0 (n) = x(n) w1 (n) = x(n − 1)= w0 (n − 1) w2 (n) = x(n − 2)= w1 (n − 1) w3 (n) = x(n − 3)= w2 (n − 1) Then, the I/O equation together with the state-updating equations will read: double x[8] = {1,2,1,1,2,1,1,1}; double filter2(); void main() { int n; double y, *w; w = (double *) calloc(4, sizeof(double)); for (n=0; n<8; n++) { y = filter2(x[n], w); printf("%lf\n", y); } for (n=8; n<11; n++) { y = filter2(0.0, w); printf("%lf\n", y); } } double filter2(x, w) double x, *w; { double y; w[0] = x; y = w[0] + w[1] + 2 * w[2] + w[3]; w[3] = w[2]; w[2] = w[1]; w[1] = w[0]; usage: y = filter2(x, w); allocates & initializes w to zero w0 (n)= x(n) and w3 (n + 1) = w2 (n) w2 (n + 1) = w1 (n) w1 (n + 1) = w0 (n) input-on transients & steady-state y(n)= w0 (n)+w1 (n)+2w2 (n)+w3 (n) This leads to the following sample processing algorithm and block diagram: input-off transients x w0 w1 y z-1 z -1 for each input sample x do: w2 w3 z-1 2 w0 = x y = w0 + w1 + 2w2 + w3 w3 = w 2 w2 = w 1 w1 = w 0 read input sample compute output sample update internal states The sample processing algorithm generates the following output samples: 48 49 8016 w0 (n)= x(n) and w3 (n + 1) = w2 (n) w2 (n + 1) = w1 (n) w1 (n + 1) = w0 (n) y(n)= w0 (n)−w3 (n) Note that the output y(n) at time n and the next internal states at time n + 1 are computable from the knowledge of the present input x(n) and the present states at time n.17 We define the internal states: w1 (n) = y(n − 1) w2 (n) = y(n − 2)= w1 (n − 1) x w0 z w1 w2 w3 z -1 -1 y for each input sample x do: ⇒ w1 (n + 1) = y(n) w2 (n + 1) = y(n − 1)= w1 (n) z-1 -1 w0 = x y = w0 − w3 w3 = w2 w2 = w1 w1 = w0 The difference equation y(n)= 0.4400 4. 8w 1 + x 1.return y. i = 0.0000 1.25 w2 0 0 1 1 2. 8w 1 + x w0 (n) = x(n) w1 (n) = x(n − 1)= w0 (n − 1) w2 (n) = x(n − 2)= w1 (n − 1) w3 (n) = x(n − 3)= w2 (n − 1) Then.25w2 + x 1 1 2. This leads to the following sample processing algorithm and block diagram realization: Problem 4. The sample processing algorithm can be cranked on the given input samples to generate the output: n x 1 1 2 2 4 y = 0.25w2 (n)+x(n) w2 (n + 1) = w1 (n) and w1 (n + 1) = y(n) This leads to the following sample processing algorithm and block diagram realization: x y z-1 w1 z-1 w2 0. the I/O equation y(n)= x(n)−x(n − 3) together with the state-updating equations will read: w1 = y The table of computations is: n 0 1 2 3 4 x 1 1 2 2 4 w1 0.15 We define the state-variables wi (n).0000 1.25w2 + x The sample processing algorithm can be applied to the given input samples to generate the output samples: n 0 1 2 3 4 x 1 1 2 2 4 w0 1 1 2 2 4 w1 0 1 1 2 2 w2 0 0 1 1 2 w3 0 0 0 1 1 y = w0 − w 3 1 1 2 1 3 w2 = w1 w1 = y General versions of such routines will be considered in Chapter 7. the difference equation y(n)= 0.0000 1.8000 3.8y(n − 1)+x(n) and the state updating equation will read: y(n)= 0.25 y for each input sample x do: y = 0.8w1 (n)+x(n) and w1 (n + 1)= y(n) This leads to the following sample processing algorithm and block diagram realization: Problem 4.5625 w1 0 1 1 2. 2.4400 4.25 2.7520 y = 0 . 1.8 y for each input sample x do: y = 0 . } Then.25 4.25y(n − 2)+x(n) and state updating equations become: y(n)= 0.16 We define the internal state: w1 (n)= y(n − 1) 0 1 2 3 4 50 51 .8000 3. 3 as follows: x y z-1 w1 0.7520 7.25 Problem 4.25 2. Thus. p. n y0 y1 y 0 1 1 1 1 1 2 1 1 3 3 3 4 0 2 2 5 2 2 4 6 4 -1 3 7 3 3 8 3 3 9 1 1 10 2 2 52 53 . w0 . − 1 . w[qout ]. 1. 2] These convolutions can be done by separately folding the two convolution subtables: block 0 1 2 2 2 0 0 -1 -2 2 4 block 1 2 1 2 1 0 0 -2 -1 4 2 x1 Problem 4. 2. 2 units. 2. aligning the output blocks according to their absolute timings and adding them up gives the final result: qin = 0. the down-arrow indicates the w-register receiving the current input. 1. 2. 2. the call to cdelay circularly decrements the pointer p. & p) where tap-1 is not needed. 3. but tap-2 and tap-3 are. the input and output circular indices take on the sequence of values: The two subblocks begin at the absolute times n = 0. 0. 4. 2) s3 = tap(3. 2. ] x0 Convolving each block separately with h gives: y0 = h ∗ x0 = [1. y(n)= x(n − 2). so does pout .19 Figure P4. w. p. If pin points to w[qin ] and pout to w[qout ]. w1 ] at successive time instants. pout is shifted clockwise by 2 with respect to pin : pout = pin + 2 (modulo 3) As pin gets decremented circularly. 1 The following table lists the contents of w for both the linear and circular buffer implementations. which receives the input sample x. 1.18 The impulse response is read off from the coefficients of the I/O equation: h = [ 1. In the circular case. 0. Each time the circular pointer p = pin points to the w-register that receives the current input. 0. 0. 2. 1. It follows from timeinvariance that the corresponding output blocks will also begin at the same absolute times. whereas the pointer pout points to the w-register containing the current output. 3. that is. 1. In the linear case. that is. 3. 3) y = s0 − s2 + 2s3 cdelay(3.2 shows the contents of the registers w = [w0 . 1. 1. Therefore. 2 qout = 2. 1. 1. whereas the up-arrow indicates the corresponding output sample. In the circular case. 2. 2. that is. 0. w1 . 2. only one w-register changes value at each time instant. 4] y1 = h ∗ x1 = [2. then h\x 1 0 -1 2 pin = w + qin 1 1 0 -1 2 1 1 0 -1 2 2 2 0 -2 4 2 2 0 -2 4 pout = w + qout where qout = (qin + 2)% 3 Thus. The block diagram and sample processing algorithm are: Problem 4. w[qin ]. w. w1 and w2 are simply the input signal delayed by i = 0. respectively. After y is computed. 0. 2. 2.Notice how the computed y becomes the next w1 and w1 shifts into w2 . 0 . 1. 0. 2 ] The LTI form is implemented by the following table: x w0 w1 w2 y z z -1 for each input sample x do: -1 -1 n x\h 1 1 2 2 2 2 1 1 0 1 1 1 0 0 1 2 -1 -1 0 2 3 2 2 -1 0 2 4 5 6 7 8 9 10 partial output x(0)h(n − 0) x(1)h(n − 1) x(2)h(n − 2) x(3)h(n − 3) x(4)h(n − 4) x(5)h(n − 5) x(6)h(n − 6) x(7)h(n − 7) w3 z-1 2 w0 = x y = w0 − w2 + 2w3 w3 = w2 w2 = w1 w1 = w0 The corresponding circular-buffer version will be: for each input sample x do: 2 -2 0 2 4 -2 0 2 4 -2 0 1 3 4 -2 0 1 3 4 -1 0 3 2 -1 1 2 2 s0 = ∗p = x s2 = tap(3. w. the input is divided into the following length-4 contiguous blocks: x = [ 1. 1. 1. y(n) 1 1 1 3 2 4 x(m)h(n − m) m For the overlap-add method. 1. −1. 2. Tap-0 s0 is the content of the current location pointed to by p. Problem 4. and v3 (n+ 1) three times. and x(n) will be exchanged with y(n).3 Transposed direct form realization. we get y(n) = h0 x(n)+h1 x(n − 1)+v2 (n − 1) = h0 x(n)+h1 x(n − 1)+ h2 x(n − 2)+v3 (n − 2) = h0 x(n)+h1 x(n − 1)+h2 x(n − 2)+h3 x(n − 3) which is equivalent to Eq. 3. Reverse all signal flows. 4. Replace all adders by nodes. Fig. down-shifting v2 (n+ 1) twice. v3 (n − 2)= h3 x(n − 3).w1 0 n=0 0 n=1 w0 8 7 n=2 6 8 n=3 6 y(n) 5 h0 v1 (n) z-1 h1 pin pout w2 0 n=4 6 pout pin pin pout 8 x(n) pin pout 7 7 n=5 3 5 n=6 3 3 n=7 pout 2 2 v2(n) z-1 h2 v3(n) z-1 h3 pout pin pin pout 5 pin pout 4 pin 1 4 4 n=8 0 n=9 0 0 n=10 pout 0 0 pin pout 2 pin pout 1 pin 0 1 Fig. down-shifting v1 (n + 1). (4.3. we have v1 (n)= v2 (n − 1)+h1 x(n − 1) Therefore. Therefore. v2 (n).3. y(n)= h0 x(n)+v1 (n)= h0 x(n)+ h1 x(n − 1)+v2 (n − 1) Similarly. The I/O system leads then to the following sample by sample processing algorithm: For example. These inputs will become the contents of the delays at the next time instant.6). Exchange input with output.2. 2. 54 55 . P4. P4.2. Rather. the vi (n) are no longer the delayed versions of each other.1. the output adder will be replaced by a node with the signals flowing in reversed directions.7. Replace all nodes by adders.2 Circular delay-line buffer contents. that is. each is a delayed version of its input. and the nodes at the inputs of the delays will be replaced by adders. P4. and v3 (n) be the contents of the three delays at time n. v2 (n− 1)= v3 (n− 2)+h2 x(n− 2). linear circular n 0 1 2 3 4 5 6 7 8 9 10 x 8 7 6 5 4 3 2 1 0 0 0 w0 8 7 6 5 4 3 2 1 0 0 0 w1 0 8 7 6 5 4 3 2 1 0 0 w2 0 0 8 7 6 5 4 3 2 1 0 w0 8↓ 8 8↑ 5↓ 5 5↑ 2↓ 2 2↑ 0↓ 0 w1 0 0↑ 6↓ 6 6↑ 3↓ 3 3↑ 0↓ 0 0↑ w2 0↑ 7↓ 7 7↑ 4↓ 4 4↑ 1↓ 1 1↑ 0↓ qin 0 2 1 0 2 1 0 2 1 0 2 qout 2 1 0 2 1 0 2 1 0 2 1 y 0 0 8 7 6 5 4 3 2 1 0 Let v1 (n). in Fig.6).20 The transposed form is obtained by the following rules: 1. as in Fig. The resulting block diagram is shown in Fig. Indeed. We can draw it reversed. They can be thought of as the internal states of the realization. 4. Because of the intervening adders between the delays. 4.2. the I/O equations describing the filter are in this case: v1 (n + 1) = v2 (n)+h1 x(n) y(n)= v1 (n)+h0 x(n) and v2 (n + 1) = v3 (n)+h2 x(n) v3 (n + 1) = h3 x(n) This system is equivalent to the original I/O equation (4. that is. printf("%lf\n". h = (double *) realloc((char *) h. M++) { read h if (M == max) { reallocate h. int M. (max + 1) * sizeof(double)). "usage: firfilt hfile <xfile >yfile\n"). Problem 4.2. *v.FIR filtering in transposed form */ #include <stdlib. i. x. y.c is the corresponding version of firfilt. v.h> #include <stdio. } h = (double *) calloc(max + 1. dmax = MAX. &x) != EOF) { y = firtr(M. The v3 column is the delayed (down-shifted) version of the h3 x column. exit(0). (M + 1) * sizeof(double)). } if (fscanf(fph. i<=M-1. void main(int argc. y).c is an implementation: /* firtr. sizeof(double)). "r")) == NULL) { fprintf(stderr. { int i. "%lf". h. x=input M=filter order for (M=0. 1. int max = MAX. .1.20. x) double *h.. output & update states last state for each input sample x do: y = v1 + h 0 x v1 = v 2 + h 1 x v2 = v3 + h2 x v3 = h3 x For Example 4. v[M] = h[M] * x. . Table P4.21 The generalization of the transposed algorithm to order M is straightforward: for each input sample x do: for i = 0. h.c: /* firfiltr. Usage: y=firtr(M. v. The final result is the same as in Example 4.2. sizeof(double)). initial allocation size n 0 1 2 3 4 5 6 7 8 9 10 x 1 1 2 1 2 2 1 1 0 0 0 h0 x 1 1 2 1 2 2 1 1 0 0 0 h1 x 2 2 4 2 4 4 2 2 0 0 0 h2 x −1 −1 −2 −1 −2 −2 −1 −1 0 0 0 h3 x 1 1 2 1 2 2 1 1 0 0 0 v1 0 2 1 4 1 5 3 2 3 0 1 v2 0 v3 0 1 1 2 1 2 2 1 1 0 0 y = v1 + h0 x 1 3 3 5 3 7 4 3 3 0 1 −1 0 −1 1 −1 0 1 0 1 0 filter file filter array. M is filter order final allocation h = (double *) realloc((char *) h. char **argv) { FILE *fph. h. v. int M. i++) { keep reading input samples compute output sample write output sample input-off transients 56 57 . } y = v0 = v1 + h0 x The following stand-alone C program firfiltr. h=filter. i++) v[i] = v[i+1] + h[i] * x. while(scanf("%lf". } if ((fph = fopen(argv[1]. x). h + M) == EOF) break. x). M − 1 do: vi = vi+1 + hi x vM = hM x y = v0 where for indexing convenience we introduced v0 (n)= y(n)= v1 (n)+h0 x(n). i<M. v=state.c .h> #define MAX 64 double firtr(). return v[0]. The v1 and v2 entries in each row are obtained by forming v2 + h1 x and v3 + h2 x of the previous row.c instead of fir.c .c. input.FIR filter in transposed direct form */ double firtr(M. *v. . } for (i=0.1 Computations in Problem 4. x. exit(0). preliminary allocation Table P4. The vi are initialized to zero. "can’t open filter file: %s\n".for (i=0. output samples allocation for h and increment if (argc != 2) { fprintf(stderr.1 shows the contents of the vi registers at each time instant. double *h. The following C routine firtr. argv[1]). The only difference is that it uses the routine firtr.1. . v = (double *) calloc((M + 1). if necessary max += dmax. } M--. y = firtr(M. such as in the implementation of FIR decimators and interpolators in multirate applications. The unit-step has z-transform: U(z)= 1/(1 − z−1 ). Y(z)= H(z)X(z) Problem 5. where Δ(z)= 1 is the ztransform of δ(n). The ROC is the entire z-plane with the exception of the point z = 0. c. From the delay property of z-transforms. X(z)= z5 Δ(z)= z5 . we have: ∞ ∞ y(n)= m=−∞ h(m)x(n − m)= m=−∞ h(m)xm (n) Taking z-transforms of both sides and using the linearity and delay properties. Thus. so that n = k + D. MATLAB uses this form to implement its built-in filtering routines. y). we get: ∞ ∞ Y(z)= m=−∞ h(m)Xm (z)= m=−∞ h(m)z−m X(z)= ∞ m=−∞ h(m)z−m X(z) or. but now the ROC must only exclude the point at infinity z = ∞. printf("%lf\n".0). Writing y(n) in terms of the delayed replicas of x(n).2 a. The convolution property follows from the linearity and delay properties. Similarly. X(z)= z−5 U(z)= with ROC |z| > 1. } } compute output sample Chapter 5 Problems Problem 5. Thus.1 The linearity property follows from: ∞ n=−∞ ∞ n=−∞ ∞ n=−∞ Transposed forms are convenient in some applications. d. h. v. We may work with the definition: ∞ 5 z−5 1 − z−1 X(z) = n=−∞ u(−n + 5)z−n = n=−∞ 1 · z−n = z−5 + z−4 + z−3 + z−2 + z−1 + 1 + z + z2 + z3 + · · · = z−5 1 + z + z2 + z3 + · · · = z−5 1−z = z−5 U(z−1 ) 58 59 . X(z)= z−5 . b. [a1 x1 (n)+a2 x2 (n)]z−n = a1 x1 (n)z−n + a2 x2 (n)z−n The delay property follows from: ∞ XD (z) = n=−∞ ∞ xD (n)z−n = ∞ n=−∞ x(n − D)z−n = ∞ k=−∞ = k=−∞ x(k)z−(k+D) = z−D x(k)z−k = z−D X(z) where we changed summation index from n to k = n − D. X(z)= z−5 Δ(z). 0. = 1−x with x = az −1 and m = 9 would require ROC |z| < 0. namely. a .5.8jz−1 (1 − 0. The signal in (d) is unstable from both sides of the time axis.5| = 0. a .25 and |z| > 4. both terms are anticausal. 0. therefore |z| > 0.5)z−1 )= 1/(1 + 0. 0. Convergence of the geometric series requires that |x| < 1 or | − a2 z−2 | < 1 or |z| > |a| or in our case |z| > 0. 0.25z−1 1 − 4z−1 1 − 4. . 0. we rewrite 2(0. 0. a8 . In case (b). that is.5z−1 ).25 < |z| < 4.5z−1 ) 1 − 0.5z−1 )(1 + 0. that is.8j)n +(−0.25)n z−n + ∞ n=0 4n z−n m 1 − xm+1 . −1. Z g(−n)− G(z−1 ) → Z ROC is |z| > |0. The intersection of the two ROC sets is empty. we have with x = −a2 z−2 .c) all have the same z-transform. An alternative method is to list a few of the signal values and then use the infinite geometric series to sum them up.8. Thus. the signals in questions (a) and (b) are the same.b.5 The three signals in parts (a. 0. we have X(z)= (1 − (−0. a .5z−1 1 + 0. 0. ] X(z) = 1 − z−2 + z−4 − z−6 + z−8 − · · · = 1 + x + x2 + x3 + x4 + · · · = 1 1 + z−2 x=−z−2 = 1 1−x x=−z−2 = (0. 1.8)n cos(πn/2) = (0. 0.5.25z−1 + = 1 − 0. ROC |z| > |a|. with θ = πn/2 and also the fact that ejπ/2 = j and e−jπ/2 = −j.8j| = 0. 2 cos θ = ejθ + e−jθ . Thus. we obtain: X(z)= → 1/(1 − (−0. Method 1: Let w(n)= u(n)−u(n − 10) with z-transform W(z).3 a. X(z)= 0. Combining.8jz−1 ) 1 + 0. ROC |z| > 1 − 0.8)n [ejπn/2 + e−jπn/2 ] x(n) = [1. The first term in the z-transform expansion −1 X(z)= 1 + az−1 + a2 z−2 + · · · + a9 z−9 = where in the last step we used the finite geometric series: 1 + x + x + ··· + x 2 1 − a10 z−10 1 − az−1 X(z)= − n=−∞ (0.5)10 z−10 )/(1 + 0. the first term requires |z| > 0.8)n [jn + (−j)n ]= (0.8j)n Thus. Using the general property that X(z)= 1 1 2 2 = + = 1 − 0. −1. −a2 . ROC is |z| < 0. 1 1 2 − 4. Using the general result: a u(n)− 1/(1 − az ).6 Method 1: List the values of x(n) and sum the geometric series: Problem 5. In case (c). c. that is.8jz−1 1 + 0. Method 2: We recognize that x(n) is the finite sequence X(z)= x(n)= [1. we find ROC 0. a . 0.25 and the second |z| > 4.5. a . . 0. there is no set of z’s for which the z-transform would converge. 1. −1. b. · · · ] 2 3 4 5 6 7 8 9 and use the definition of z-transforms: They differ only in their region of convergence: In case (a). 0. a. |z| < 0.5z−1 (1 − 0. a4 .8: x(n)= 2[1.4 Using Euler.25 while the second |z| < 4. with a = 0.64z−2 g(n)− G(z) ⇒ → we find X(z)= z−5 U(z−1 ).25 and |z| < 4. · · · ] we obtain n −1 Problem 5.8jz−1 )(1 + 0. 0. Their z-transform is where convergence of the geometric series requires: 60 61 . . both terms are causal. 0. an w(n)− W(z/a)= → 1 − (z/a)−10 1 − a10 z−10 = −1 1 − (z/a) 1 − az−1 Problem 5. Using the linearity and delay properties. a . −a10 . thus.5z−1 ). ROC is the whole z-plane minus the point z = 0. Alternatively. we recognize that x(n) is the delayed version of u(−n). 0.8. with ROC |z| > | − 0. 0.The convergence of the series requires the ROC |z| < 1.25z−2 Problem 5. 1 1 2 2 = + = . a . ROC is |z| > 4. we have X(z)= 2[1 − a2 z−2 + a4 z−4 − a6 z−6 + a8 z−8 − a10 z−10 + · · · ]= where we applied the infinite geometric series 1 + x + x2 + x3 + · · · = 1 1−x 2 1 + a2 z−2 W(z)= U(z)−z −10 U(z)= (1 − z −10 1 − z−10 )U(z)= 1 − z−1 Using the modulation property of z-transforms. x(n)= u(−n + 5)= u(−(n − 5)).25. −a6 .25z−1 + z−2 With a = −0. a . g.9| = | − 0.3z−1 ) A B = = + −2 1 − 0.25z−2 = z=0 6z2 − 3z − 2 z2 − 0. g. 62 63 .5. . we get: X(z) = 6 − 3z−1 − 2z−2 6 − 3z−1 − 2z−2 = −2 1 − 0. −1. −4.9z−1 =1 z=−0.7 Whenever X(z) is a polynomial.5)n u(n)+C(−0. the best method to invert is to just pick out the coefficients of the polynomial.Problem 5.5z−1 = − 4. the signal is non-zero only at n = −3. 0. x(n)= −A(0.5. −12] B= 6 − 3z−1 − 2z−2 1 + 0.8 |x| < 1 ⇒ | − z−2 | < 1 ⇒ |z| > 1 a.5z−1 X(z)= G(z) 1 − z−4 = 1 − z−2 1 − z−2 1 = = 1 − z−4 (1 − z−2 )(1 + z−2 ) 1 + z−2 where B and C are determined in the usual manner and A is determined by evaluating X(z) at z = 0: Problem 5.3z−1 ) 3(1 + 0.5)n u(−n − 1)−C(−0.9)n u(n) As expected.25 = z=0 −2 =8 −0.5)n u(n) For the second ROC. we see that x(n) will be the periodic replication of g(n): x = [g. 0. because the ROC does not contain the unit circle. the answer is stable because the ROC contains the unit circle. the two terms will be inverted anticausally: x(n)= Aδ(n)−B(0.9 The first ROC is |z| > |0. b. we find: X(z)= 1/2 1 − jz−1 + 1/2 1 + jz−1 = 1 (1 − jz−1 )(1 + jz−1 ) = 1 1 + z−2 A= 3(1 + 0.9)n u(−n − 1)−B(−0. z=0. . we may still have an expansion of the form: x(n)= g(n)+g(n − 4)+g(n − 8)+g(n − 12)+ · · · Taking z-transforms of both sides gives X(z)= G(z)+z−4 G(z)+z8 G(z)+ · · · = 1 + z−4 + z−8 + z−12 + · · · G(z) Summing up the series and using G(z)= 1 − z−2 .3z−1 ) 1 − 0.9)n u(−n − 1) The answer is unstable. 2: For the first ROC. 0].5z−1 ) =A+ B 1 − 0.9| = | − 0.25 X(z) = (1 − 4z−2 )(1 + 3z−1 )= 1 + 3z−1 − 4z−2 − 12z−3 ⇒ x(n) = [1.5z−1 =2 z=−0. Defining the length-4 sequence g = [1. |z| > 0.9z−1 )(1 + 0. Method 3: Recognize that x(n) is periodic with period 4. However.81z (1 − 0. we have: A= 6 − 3z−1 − 2z−2 1 − 0. For (a).5z−1 )(1 + 0.9 B= 3(1 + 0. thus both terms will be inverted anticausally: for a = j and a = −j.9)n u(n)+B(−0.9z−1 ) 1 − 0.5 For (b). z=0.9|. 3.9|. The second ROC is |z| < |0. the last two terms will be inverted causally: x(n)= 5δ(n)+3δ(n + 3)+2δ(n − 2) x(n)= Aδ(n)+B(0.5)n u(−n − 1) As expected.25z (1 − 0.9z−1 where we used eπj/2 = j. Taking z-transforms.9z−1 1 + 0. Carry out a partial fraction expansion: Method 2: Use Euler’s formula to split x(n) as the sum of two terms of the form an u(n): X(z)= where x(n)= cos(πn/2)u(n)= 1 1 πjn/2 + e−πjn/2 u(n)= [jn + (−j)n ]u(n) e 2 2 3(1 + 0. .9z−1 = 2. Ordinary partial fraction expansion is not valid in this case because the degree of the numerator is the same as the degree of the denominator. thus both terms will be inverted causally: where we applied the result an u(n)− → Z 1 1 − az−1 x(n)= A(0. ] or.5z−1 + C 1 + 0. |z| < 0.3z−1 ) 1 + 0.5 C= 6 − 3z−1 − 2z−2 1 − 0. only the first inverse is stable because its ROC contains the unit circle. 8)n−5 u(−n + 4) The u(−n + 4) was obtained as u(−(n − 5)−1).5)n cos(πn/2)u(−n − 1) e.25z−2 = z=0 10z2 + 1 z2 + 0. because the last two terms are complex conjugates of each other.8)n u(n)+B(−0.5jz−1 |z| > 2 and |z| < 2 64 65 .8z−1 B(0. When the poles are complex. the problem is reduced to the problem of finding w(n). x(n) has a slightly causal part extending to the right up to n = 4. The minor new feature of this problem is that the poles are complex-valued. In this case. that is.8)n−5 u(n − 5) + B(−0.5z−1 x(n) = −6A(0. The degree of the numerator is strictly greater than the degree of the denominator.5.64z−2 10 + z−2 10.8)n u(−n − 1) − A(0.5j)n u(n) Now. and use B∗ for the conjugate pole.5)n u(n)+(−0. get its inverse ztransform. Note also that the last two terms are now active for −n + 4 ≥ 0 or n ≤ 4. Doing a partial fraction expansion on W(z).5j)n u(n)+B∗ (−0. Re[jn ]= Re[ejπn/2 ]= cos(πn/2) Thus.5z−1 (1 − z−1 )(1 − 0. f. all terms are inverted causally to give: x(n)= 4u(n)+(0. the two terms are inverted causally: w(n)= A(0.5jz−1 ) The two regions of convergence are: B∗ B + =A+ 1 − 0.8)n u(−n − 1) which gives for x(n): X(z)= 6 − 2z−1 − z−2 4 1 1 + + = 1 + 0.5jz−1 1 + 0.5)n Re[jn ]u(n) But.8)n−5 u(n − 5) Note that the last two terms are active only for n ≥ 5.5j)n u(n)+B∗ (−0. write Again. and finally restore the effect of the numerator.25 = z=0 1 =4 0.25z−2 ) 1 − z−1 1 − 0. d. we have x(n)= 6w(n)+w(n − 5) Thus. we have then 10 + z−2 1 + 0.25z−2 (1 − 0.8z−1 )(1 + 0.8z−1 1 + 0.5jz−1 =3 z=0.5)n cos(πn/2)u(n) For the anticausal case.5j)n u(n)= 6(0.8)n u(n)+A(0.8. we obtain the anticausal version of the second term. For the ROC |z| < 0. that is.25 1 1 − 0. we may use the general identity 2Re(z)= z + z∗ to write W(z)= A B 1 1 = = + 1 − 0. This happened because the strictly anticausal signal w(n) was delayed (shifted to the right) by 5 time units by the term w(n − 5). we find x(n)= Aδ(n)+B(0. For the causal case. For the ROC |z| > 0.8)n u(n)+6B(−0. The simplest approach in such cases is to use the “remove/restore” method. To show these steps. only half of the residues need be computed: Because ROC is |z| > 1 > 0. The PF expansion gives: X(z) = −4 + = −4 + 1 1 = −4 + 1 + 4z−2 (1 − 2jz−1 )(1 + 2jz−1 ) 1/2 1/ 2 + 1 − 2jz−1 1 + 2jz−1 X(z) = 10 + z−2 10 + z−2 = 1 + 0. too. the corresponding residues are complex conjugates. ignore the numerator completely.8)n u(n) Inserting in x(n)= 6w(n)+w(n − 5).8)n u(−n − 1)−B(−0.5j)n u(n)]= 6(0. we have the anticausal/unstable answer: x(n)= 4δ(n)+6(0.8z−1 ) 1 − 0.5j)n u(n)+B∗ (−0. Thus.5jz−1 )(1 + 0. they come in conjugate pairs.64z−2 ≡ (6 + z−5 )W(z)= 6W(z)+z−5 W(z) In the time-domain.64z−2 (1 − 0. the A-term is needed because the degrees of numerator and denominator polynomials are equal. namely. x(n)= 4δ(n)−6(0.8. The partial fraction expansion is: w(n)= −A(0.5. We find A= B= X(z) = 6 + z−5 = (6 + z−5 )· 1 − 0.c. do a partial fraction on the denominator.8)n−5 u(−n + 4)−B(−0.5j We only needed to calculate B.5)n u(n) The answer is marginally stable because the pole z = 1 is on the unit circle.5)n cos(πn/2)u(n) and the final result is x(n) = 6A(0. where A = B = 0. we find B(0.8)n u(−n − 1)−6B(−0.5j)n u(n)= 2Re[B(0. 0.5 > |z| > 0.5 =3 z=−0. The PF expansion is in this case: as n n ∂ ∂ Xa (z)= ∂a ∂a 1 1 − az−1 = z−1 (1 − az−1 )2 nan−1 u(n)− → Multiplying by a.5)n u(n)+C(−0. derive the z-transform of the sequence x(n)= nan u(n).5)n u(−n − 1)−C(−0. The B-term in x2 (n) and both the B and C terms of x3 (n) diverge exponentially for large negative n. ∂ ∂a 1 1 − az−1 = az−1 (1 − az−1 )2 nan u(n)− → Z az−1 (1 − az−1 )2 66 67 . we have: 2n cos(πn/2)u(−n − 1)= 2−|n| cos(πn/2)u(−n − 1)→ 0 g.4z−1 4 − 0.6z−1 + 0. we have: Z ∂ ∂a k 1 1 − az−1 x1 (n) = Aδ(n)+B(0. we may write: 1 1 0.4)n u(−n − 1) Only x1 (n) is stable. Noting that = 2n cos(πn/2) Thus.6z−1 + 0. we can rewrite: we get ∂ xa (n)= nan−1 u(n) ∂a x1 (n) = −4δ(n)+2 cos(πn/2)u(n) x2 (n) = −4δ(n)−2 cos(πn/2)u(−n − 1) Thus.4 Thus. 5 · 0 .2z−2 =A+ + (1 − 0.5z−1 1 + 0.5z−1 )(1 + 0.5z−1 = z=0 0.4z−1 Problem 5.6z−1 + 0.5 (2j)n +(−2j)n ] = 2n [jn + (−j)n ]= 2n [ejπn/2 + e−jπn/2 ] 2 2 xa (n)= an u(n) Xa (z)= 1 1 − az−1 Applying the derivative operator ∂/∂a to the pair. because in the second term n is effectively negative and causes it to decay exponentially for large negative n.4)n u(n) x2 (n) = Aδ(n)−B(0.4. writing n = −|n|.2z−2 (1 − 0. that is.4 > |z| → a nk an u(n)− In particular.5(−2j)n u(−n − 1) Using Euler’s formula.4z−1 ) 4 − 0.5(2j)n u(n)+0.4)n u(n) x3 (n) = Aδ(n)−B(0.5)n u(−n − 1)+C(−0. we get: Z z−1 (1 − az−1 )2 n → −∞ nan u(n)− → Z az−1 (1 − az−1 )2 X(z)= where B C 4 − 0. Only x2 (n) is stable because its ROC contains the unit circle.2z−2 1 − 0.They correspond to the causal and anticausal inverses: Problem 5.5z−1 )(1 + 0.5(2j)n u(−n − 1)+0. The corresponding inverses are: 0.4 D(an ) = a ∂ (an )= anan−1 = nan ∂a D2 (an ) = D(D(an ))= D(nan )= nD(an )= n(nan )= n2 an D3 (an ) = D(D2 (an ))= D(n2 an )= n2 D(an )= n2 (nan )= n3 an ··· D (a ) = nk an k n =2 z=0.4z−1 ) 1 − 0. 2 = −1 − 0 . a Therefore. or.5.2z−2 1 + 0.6z−1 + 0.10 We note that each application of D brings down a factor of n: A= B= C= The three ROC’s are: 4 − 0.5(−2j)n u(n) x2 (n) = −4δ(n)−0. Its ROC contains the unit circle. for k = 1.9 Consider the z-transform pair: x1 (n) = −4δ(n)+0. in the z-domain: |z| > 0. n)≤ m ≤ min(L − 1. n + L − 1)− min(0.n+L−1) L 1·1= m=max(0.n) −(L − 1)≤ n ≤ L − 1 Because over this range. n + L − 1)− min(0. we obtain the overall range of the index n of x(n). the right-hand-side of the desired z-transform is the product: an u(n)− → and apply it for a = Rejω0 and a∗ = Re−jω0 : 1 1 − az−1 → Rn ejω0 n u(n) − Rn e−jω0 n u(n) − → Z Z 1 1 − Rejω0 z−1 1 1 − Re−jω0 z−1 X(z)= 1 L 1−z 1 − z−1 −L 2 zL−1 = 1 L G1 (z)G2 (z) The cosine and sine signals are obtained from the above as the following linear combinations: Thus. both g1 (n) and g2 (n) are unity. L −(L − 1)≤ n ≤ L − 1 At all other n. we also get: n(n + 1)an u(n)− → Z 2az−1 (1 − az−1 )3 For the cases k = 3. 4. u(n)− U(z)= → we find the z-transforms: Z 1 1 − z−1 Problem 5. we obtain the restrictions on the convolution summation indices: 0≤m≤L−1 = az−1 = Therefore. it is easily verified that the above expression is equivalent to: g1 (n) = u(n)−u(n − L) g2 (n) = g1 (n + L − 1)= u(n + L − 1)−u(n − 1) and using the z-transform x(n)= 1 L max (L − 1.n+L−1) az−1 (1 + 4az−1 + a2 z−2 ) → n a u(n) − (1 − az−1 )4 3 n Z L g1 (m)g2 (n − m). that is. n)+1 Problem 5. we obtain: az−1 (1 + 11az−1 + 11a2 z−2 + a3 z−3 ) n a u(n) − → (1 − az−1 )5 4 n Z x(n)= 1 min(L−1. m=max(0. we apply D again to get: a ∂ ∂a 2 1 1 − az−1 = a ∂ ∂a az−1 (1 − az−1 )2 1 Because g1 (n) is non-zero only over 0 ≤ n ≤ L − 1 and g2 (n) over −(L − 1)≤ n ≤ 0. For k = 2. n)+1 = 1 − |n| . n + L − 1) The convolution sum becomes then: ⇒ n≤m≤n+L−1 Adding the results of the k = 1 and k = 2 cases. −1 (1 − az)2 −1 + 2az−1 (1 − az−1 )3 −(L − 1) ≤ n − m ≤ 0 By adding them. in the time domain we have the convolution: Rn cos(ω0 n)u(n) = Rn g1 (m)g2 (n − m) m 1 ejω0 n u(n)+e−jω0 n u(n) 2 1 ejω0 n u(n)−e−jω0 n u(n) 2j x(n)= 1 L g1 (n)∗g2 (n)= 1 L Rn sin(ω0 n)u(n) = Rn 68 69 . we obtain the range of the summation in m: n2 an u(n)− → Z az−1 (1 + az−1 ) (1 − az−1 )3 0≤m≤L−1 0≤m−n≤L−1 which combine into the single inequality: max (0. x(n) is zero.n) 1 L max (L − 1.12 Start with the result Z 1 − z−L G1 (z) = U(z)−z−L U(z)= 1 − z−1 1 − z−L L−1 G2 (z) = U(z)zL−1 − z−1 U(z)= z 1 − z−1 Therefore.which agrees with the previous problem. including the end-points n = ±L.11 Defining the square pulses By checking separately the ranges −(L − 1)≤ n ≤ 0 and 0 ≤ n ≤ L − 1. az (1 + az ) (1 − az−1 )3 −(L − 1)≤ n ≤ L − 1 For any n in this range. we find after some tedious algebra: x(n)= 1 min(L−1. a3 }. the z-transform of the periodic signal is recognized as the sum of the delayed replicas of A(z).14 Factoring the denominator 1 − z−4 . a2 . x(n) = a0 + a1 + a2 + a3 4 + a0 − a1 + a2 − a3 4 (−1)n X(z) = a0 + a1 z−1 + a2 z−2 + a3 z−3 + a0 z−4 + a1 z−5 + a2 z−6 + a3 z−7 + a0 z−8 + a1 z−9 + a2 z−10 + a3 z−11 + · · · = (a0 + a1 z−1 + a2 z−2 + a3 z−3 )+z−4 (a0 + a1 z−1 + a2 z−2 + a3 z−3 ) + z−8 (a0 + a1 z−1 + a2 z−2 + a3 z−3 )+ · · · = A(z)+z−4 A(z)+z−8 A(z)+ · · · = (1 + z = −4 + a0 − a2 2 cos(πn/2)+ a1 − a3 2 sin(πn/2) Setting n = 0. we have: 1 1 + z−2 a0 + a1 z−1 + a2 z−2 + a3 z−3 1 − z−4 X(z)= 1 − z−2 + z−4 − z−6 + z−8 − · · · = 1 − z−2 (1 − z−2 + z−4 − z−6 + z−8 − · · · )= 1 − z−2 X(z) which gives where the convergence of the geometric series requires the ROC |z| > 1.5(−j)n u(n)= cos(πn/2)u(n) 70 71 .) The PFE coefficients are determined as follows: x(n)= 0. we can verify the first four values {a0 . we obtain for n ≥ 0: x(n) = A + B(−1)n +Cjn + C∗ (−j)n = A + B(−1)n +Cejπn/2 + C∗ e−jπn/2 = A + B(−1)n +2Re Cejπn/2 = A + B(−1)n +2Re (CR − jCI )ejπn/2 = A + B(−1)n +2CR cos(πn/2)+2CI sin(πn/2) So that finally: Problem 5. a1 . 3.15 Summing the geometric series. 2. Problem 5.Therefore. we have: +z −8 A(z) + · · · )A(z)= 1 − z−4 X(z)= 1 − z−2 + z−4 − z−6 + z−8 − · · · = Alternatively. 1. that is.5 0.13 Define the z-transform of one period: A(z)= a0 + a1 z−1 + a2 z−2 + a3 z−3 Then.5jn + 0. Problem 5.5 = + 1 + z−2 1 − jz−1 1 + jz−1 + B 1 + z−1 + C 1 − jz−1 + C∗ 1 + jz−1 where the coefficients C and C∗ are conjugates because they correspond to the conjugate poles ±j (this follows from the fact that the denominator has real coefficients. we obtain the PF expansion: (1 + z−2 )X(z)= 1 ⇒ X(z)= 1 1 + z−2 The inverse z-transform is causal and can be obtained from the PFE: a0 + a1 z−1 + a2 z−2 + a3 z−3 a0 + a1 z−1 + a2 z−2 + a3 z−3 = X(z) = 1 − z−4 (1 − z−1 )(1 + z)(1 − jz−1 )(1 + jz−1 ) = A 1 − z−1 X(z)= which gives: 1 0. the corresponding linear combinations of z-transforms will be: → Rn cos(ω0 n)u(n) − n Z Z 1 2 1 1 + 1 − Rejω0 z−1 1 − Re−jω0 z−1 1 1 − Rejω0 z−1 A= B= C= a0 + a1 z−1 + a2 z−2 + a3 z−3 (1 + z)(1 − jz−1 )(1 + jz−1 ) −1 −2 −3 = z=1 a0 + a1 + a2 + a3 4 1 R sin(ω0 n)u(n) − → 2j which simplify into: − 1 1 − Re−jω0 z−1 a0 + a1 z + a2 z + a3 z (1 − z−1 )(1 − jz−1 )(1 + jz−1 ) a0 + a1 z + a2 z + a3 z (1 − z−1 )(1 + z)(1 + jz−1 ) −1 −2 −3 = z=−1 a0 − a1 + a2 − a3 4 1 − R cos ω0 z−1 R cos(ω0 n)u(n) − → 1 − 2R cos ω0 z−1 + R2 z−2 n Z = z=j (a0 − a2 )−j(a1 − a3 ) 4 ≡ CR − jCI Rn sin(ω0 n)u(n) − → Z R sin ω0 z−1 1 − 2R cos ω0 z−1 + R2 z−2 Taking (causal) inverse z-transforms of the PF expansion. 0. that is. e±3jπ/4 A∗ (Ai + A∗ )−(Ai p∗ + A∗ pi )z−1 Ai i i i i + ∗ −1 = −1 1 − pi z 1 − pi z 1 − (pi + p∗ )z−1 + pi p∗ z−2 i i where the numerator and denominator coefficients are all real. 0. 0. 0. . Thus. 0. 0. The z-transform and its inverse are: A= B= 1 (1 − e−jπ/4 z−1 )(1 − e3jπ/4 z−1 )(1 − e−3jπ/4 z−1 ) 1 z=eπj/4 = = 1 4 1 4 (1 − ejπ/4 z−1 )(1 − e−jπ/4 z−1 )(1 − e−3jπ/4 z−1 ) z=e3πj/4 X(z) = 1 = 1 − z−4 + z−8 − z−12 + z−16 − · · · 1 + z−4 Thus. 0. 0. 3 Ai z=e jπ/4 . 0. 0. 1. Q(z) will have degree L − M. 0. . 0. 1. 0. a. ] b. 0. 0. 1. 0. . 0. 1. . 0. 2. . −1. 1. −1. 0.c. The z-transform and its inverse are: Cases (b.19 for the denominator zeros. . e 3jπ/4 . 0. X(z) = 1 = 1 − z−8 + z−16 − z−24 + · · · 1 + z−8 x(n) = [1. . 0. 0. the term R(z)/D(z) will admit a PF expansion of the form: R(z) Ai = D(z) i=1 1 − pi z−1 where pi are the M zeros of D(z) or the poles of H(z). See the solution of Problem 5. k = 0. we expand in the appropriate geometric series and pick out the coefficients of the expansion. 1. ] c. e 7jπ/4 1 − pi z−1 + 1 − p∗ z−1 i A∗ i which are the conjugate pairs: which can be assembled into the 2nd order section: z = e±jπ/4 . They are obtained as follows: Because the degree of R(z) is strictly less than the degree of D(z). we find the causal inverse for n ≥ 0: x(n) = [1. . 0. 0. 0. 0. 0. 0. 0.16 In all cases. Thus. the four numbers ⇒ z = e(jπ+2jπk)/4 . 0.d) are done in a similar fashion. . 0. 0. 1. 0. 0. . Any truly complex poles will come in conjugate pairs. . 0. 0. 1. 0. the roots of the denominator are the solutions of 1 + z−4 = 0 or. 0. 0. of the type: M z4 = −1 = ejπ = ejπ+2jπk that is. Then. ] Problem 5. 0. Problem 5. 0. The z-transform and its inverse are: x(n) = = 1 jπn/4 1 1 1 e + e−jπn/4 + e3jπn/4 + e−jπn/4 4 4 4 4 1 1 cos(πn/4)+ cos(3πn/4) 2 2 X(z) = 1 = 1 + z−4 + z−8 + z−12 + z−16 + · · · 1 − z−4 x(n) = [1. 1. 0. 0. R(z) degree M − 1. 0. 0. 0. 0. 0. 0.Problem 5. 0. The z-transform and its inverse are: It follows that: N(z)= Q(z)D(z)+R(z) X(z) = 1 1 − z−8 =1+z −8 +z −16 +z −24 + ··· H(z)= Q(z)D(z)+R(z) R(z) N(z) = = Q(z)+ D(z) D(z) D(z) x(n) = [1. −1. z4 = −1. 0. 0.18 Let Q(z) and R(z) be the quotient and remainder polynomials of the division of N(z) by D(z). 0. e 5jπ/4 . 0. ] d. 0. 0. 0. . 0. 0.17 For case (a). 0. 0. 1. −1. 0. 1. 0. the z-transform factors as follows and has the PF expansion: X(z) = = 1 1 + z−3 1 = (1 − ejπ/4 z−1 )(1 − e−jπ/4 z−1 )(1 − e3jπ/4 z−1 )(1 − e−3jπ/4 z−1 ) A 1− ejπ/4 z−1 + A∗ 1− e−jπ/4 z−1 + B 1− e3jπ/4 z−1 + B∗ 1− e−3jπ/4 z−1 where the coefficients are: 72 73 . 0. 0. 0. 20 The roots of 1 − az−D are the solutions of the equation = x(n) k = 0 . Its z-transform is: n X(ω) = n x(n)e−jωn x∗ (n)ejωn n Y(z)= n y(n)z−n = n an x(n)z−n = n x(n)(z/a)−n X∗ (ω) = 74 75 . where k is an integer. . . the relationship Y(ejω )= X(ej(ω−ω0 ) ) may be written as (1 − zk z−1 )= 1 − z−D k=0 This identity follows from a theorem of algebra that states that if two polynomials have the same set of roots and unity constant coefficient. the roots of 1 + az−D . zD = a = aej2πk ⇒ zk = a1/D ej2πk/D .21 Let y(n)= a x(n). Then. we get 1 2π π −π Fig. we have: Problem 5.23 We may assume in general that x(n) is complex-valued. . k = 0. for n = m the left hand side is unity. k = 0 . lie on the same circle. D − 1 Problem 5. that is.22 We use the identity 1 2π π −π They also lie on the unit circle at D equal divisions. . . and take D-th roots of both sides: Comparing with X(z)= n x(n)z−n we see that zD = 1 = e2πjk ⇒ zk = ej2πk/D . For the other case. Indeed. Now. we have: 1 2π π −π ejω(n−m) dω = cos π(n − m) − cos −π(n − m) 2πj(n − m) =0 z8 = 1 z 8 = -1 Inserting the definition of the DTFT into the inversion formula. The product of the 1st order zero factors must make up the polynomial 1 − z−D : D−1 z/a = ejω /ejω0 = ej(ω−ω0 ) Thus. the unit circle lies in the ROC or that the signal x(n) is strictly stable).19 The roots of the polynomial 1 − z−D are the solutions of the equation zD = 1. and find the roots −D Y(ω)= X(ω − ω0 ) Alternatively. . but they are shifted as a whole with respect to the standard D-th roots of unity by a rotation angle of π/D. P5.1 Roots of 1 − z−8 and 1 + z−8 . P5. . 1 . replace 1 by e2πjk = 1. we have the solutions of 1 + z ejπ+j2πk with any integer k. They all lie on a circle of radius a1/D at the D-th root of unity angles.Problem 5. we may work directly with the definition of the DTFT: = 0 or z = −1. D − 1 obtained by dividing the circle into D equal parts. Similarly. we replace −1 = e D πj = Y(ω)= n y(n)e−jωn = n ejω0 n x(n)e−jωn = n x(n)e−j(ω−ω0 )n = X(ω − ω0 ) zD = −1 = ejπ(2k+1) ⇒ zk = ejπ(2k+1)/D . k = 0. X(ω)ejωn dω = = 1 2π π −π m x(m)e−jωm ejωn dω 1 2π π −π x(m) m ejω(n−m) dω = m x(m)δ(n − m) Problem 5. Problem 5. . . ejω(n−m) dω = δ(n − m) for n. . And. Fig. . 1. D − 1 Y(z)= X(z/a) Since the spectrum X(ω) is obtained by replacing z = ejω . 1. but at the shifted D-th root of unity angles. the scaled z will be They lie on the unit circle at the angles ωk = 2πk/D. then they must be identically equal to each other. . the D-th roots of unity. . . D − 1 where we interchanged the series with the integral (this step is justified by assuming that the series is convergent. 1. To find them.1 shows the two cases for D = 8. m integers. for n = m. . that is. it has a pole in the low frequency range.8e−jω 76 77 . arg X(−ω)= − arg X(ω) H(z)= that is. w1 = y |X(−ω)|e −j arg X(−ω) = |X(ω)|e j arg X(ω) b. The I/O equation Y(z)= 0.8z−1 1 − 0.g. the filter will tend to enhance high frequencies.8 y for each input sample x do: y = − 0.8z−1 Y(z)+X(z) it follows: n 1 x (n) 2π X(ω)e dω H(z)= = n x∗ (n)x(n) 1 1 + 0. near the “high frequency” part of the unit circle. 8 w 1 + x |X(−ω)|ej arg X(−ω) ∗ = |X(ω)|ej arg X(ω) or.8z−1 Y(z)+X(z)+z−1 X(z) gives Equating magnitudes and phases. the magnitude spectrum is even in ω and the phase spectrum is odd. it will behave as a high pass filter: z-plane X(ω) = n x(n)e−jωn x(n)ejωn n = pole |H(ω)| 0.8z−1 ⇒ H(ω)= 1 1 + 0.8)n u(n). e.8)n u(n) A= 1 + z−1 1 − 0. z = −1. Change −0. Now the pole at z = 0. that is.24 For a real-valued signal x(n)..8 in the above problem. we replaced ω by −ω.Using the inverse DTFT formula. it follows that 1 2π π −π Chapter 6 Problems π −π ∗ X(ω)X∗ (ω) dω = = 1 2π X(ω) n π −π x∗ (n)ejωn jωn dω Problem 6. and it has a zero in the high frequency range. we get the conditions: |X(−ω)| = |X(ω)| . X(ω)= |X(ω)|ej arg X(ω) .8 1 x(n)e−jωn π ω where in the third equation. From Y(z)= −0.8 = 2.. Comparing the first and third equations.8 is in the “low frequency” part of the unit circle and the filter is acting as a low pass filter.8z−1 ⇒ h(n)= Aδ(n)+B(0.e.55 0 5 X∗ (ω) = X∗ (−ω) = n -0.8. There is only one pole at z = −0.25 The filter enhances low frequencies for two reasons: first.8 to 0. i.1 a. we have: The causal inverse z-transform of H(z) is h(n)= (−0.8e−jω Problem 5. the hermitian property reads: x y z-1 w1 -0. c. Its frequency response will be H(ω)= 1 + e−jω 1 − 0.25. z=0 B = 1 + z−1 z=0.8. we obtain: Block diagram realization and the sample-by-sample processing algorithm: X∗ (−ω)= X(ω) Writing X(ω) in its polar form. where 1 + z−1 B =A+ 1 − 0. z = 0. Thus.8z−1 = −1. 5.8 w2 = w 1 w1 = w 0 0 π ω The direct form realization and its sample processing algorithm are: The canonical form realization and its sample processing algorithm are: 78 79 .25z−2 X(z) x z-1 v1 0.5 y for each input sample x do: w 0 = 0 . 1 − 0.8z−1 Using the “remove/restore numerator” method of problem (2h).8 0 π ω The filter has a zero at z = 0.5j = zeros = poles |H(ω)| A= 1 − 0.5 0. Thus. the filter will tend to act as a lowpass filter.8z−1 Y(z)+X(z)−0.8 w0 z-1 w1 -0. 8 w 1 + x + v 1 1 + 0. The canonical form realization and its sample processing algorithm are: x w0 z-1 w1 z-1 w2 0.8)n u(n) z-plane 0.8 w 1 + x x y = w0 + w1 w1 = w0 y z v1 -0.8 = 0.5)/(1 − 0.8z−1 = 0.25z−2 . whereas its response at ω = π or z = −1 is (1 + 0. and whichever is closest to the unit circle ultimately wins. the filter will enhance low frequencies and suppress midrange frequencies: d. Indeed.5z−1 z=0.833.8)= 0. The I/O equation Y(z)= 0.25w2 z-plane 0.8 w0 -1 y for each input sample x do: w 0 = 0 .5 0.5z−1 B =A+ 1 − 0.5w1 -1 0.8 w 1 + x − 0 .5)/(1 + 0.8. we find H(z)= v1 = x w1 = y h(n)= (0.5 0. their effect will be to cancel each other.625.5z−1 X(z) gives H(z)= where 1 − 0.8 = zeros = poles |H(ω)| 2.8z−1 1 − 0.8 ⇒ -1 z -1 for each input sample x do: y = 0 . Thus. z = ±0. 5 v 1 w1 w1 v1 = x w1 = y The direct form realization and its sample processing algorithm are: e.z-plane = zeros = poles 10 |H(ω)| exact zero x ω 0.8 — both in the low frequency range.8)= 2.8)n u(n)+0. Y(z)= 0. Thus.375 -0.5j 0.5z−1 1 − 0.25 y for each input sample x do: w 0 = 0 .5 and a pole at z = 0. the pole is nearer. z=0 B = 1 − 0.8z−1 ⇒ h(n)= Aδ(n)+B(0.8 w 1 + x y = w0 + 0.5e±jπ/2 .8 0 π w1 = w 0 The canonical form realization and its sample processing algorithm are: The direct form realization and its sample processing algorithm are: x z 0.833 0.8)n−2 u(n − 2) The filter has two conjugate zeros at midrange.25(0.8 y z-1 w1 for each input sample x do: y = 0.8 w 1 + x y = w0 − 0. its response at ω = 0 or z = 1 is (1 − 0.8z−1 Y(z)+X(z)+0. and a low frequency pole at z = 0. Here.5j = 0. evaluating at a few n’s we find: Thus. The value of the magnitude response at ω = 0 or z = 1 is |1 + 1 − 6|/|1 − 0.9 w 1 − 0 . . we have: z-plane 0. Thus. 18.5z−1 −1 −1 = −30 z=0 Problem 6.4.5z−1 ) (1 + 3z )(1 − 2z 1 − 0. Note that when you send in a unit step.2z−2 x z-1 v1 z-1 v2 -6 -0. we get 80 81 .x z-1 v1 z-1 v2 0.4) u(n)+C(0.25 0.9z−1 Y(z)−0. For the alternating step.9z−1 + 0.5 (1 + 3z−1 )(1 − 2z−1 ) 1 − 0.9 y z-1 w1 z-1 w2 for each input sample x do: y = x + v 1 − 6v 2 + 0 .5||1 + 0. the filter will be a low pass filter.2 0. cutting off the highfrequency input.2z−2 Y(z)+X(z)+z−1 X(z)−6z−2 X(z). H(1)= 1 + 6 + 11 + 6 = 24. 0. That constant value can be easily precalculated as H(1). 5.4z−1 )(1 − 0. Y(z)= 0. 0.4| = 2. and the 2nd term only for n ≥ 2. 0. 24.8 y z-1 w1 for each input sample x do: y = x + 0. 24. the remaining constant values are the steady part.33 2 0 |H(ω)| 2.4| = 13. Thus. 2w 2 Factor numerator and denominator and expand in partial fractions: B (1 + 3z−1 )(1 − 2z−1 ) C =A+ H(z)= + (1 − 0. Inverting. . · · · ] There is a pole zero cancellation: the filter has a zero at z = −1. the 3d term is active only n ≥ 2. y(n)= [1.4z−1 1 − 0.5) u(n). 0.5z−1 ) 1 − 0.2 f. 6. h(n)= Aδ(n)+B(0. whereas its value at ω = π or z = −1 is |1 − 1 − 6|/|1 + 0.86. 7. The two poles at z = 0. The two zeros at z = −3 and z = 2 are too far from the unit circle to have any significant effect on the magnitude response.9 y for each input sample x do: w 0 = x + 0 .5z−1 where v2 = v1 v1 = x w2 = w1 w1 = y A= B= C= (1 + 3z−1 )(1 − 2z−1 ) (1 − 0.4 = 136 = −105 z=0.86 Y(z) = 1 + 6z−1 + 11z−2 + 6z−3 = 1 + 5z−1 + 6z−2 1 + z−1 π ω y(n) = [1. 9w 1 − 0.5||1 − 0. In the present case.5 = zeros = poles 13.8w1 x w0 z-1 w1 0.4 -3 0.4z−1 n n y(n)= u(n)+6u(n − 1)+11u(n − 2)+6u(n − 3) The 4th term is active only for n ≥ 3. the output always settles to a constant value (for a stable filter). ] The first 3 outputs are the initial transients.5 are both in the low frequency range.33. . b. Noting that the input z-transform is X(z)= 1/(1 − z−1 ).4z−1 )(1 − 0.2 w 2 y = w 0 + w 1 − 6w 2 v2 = v1 v1 = x w1 = y z-1 w2 -6 w2 = w 1 w1 = w 0 -0. we find ) z=0.25v2 + 0. which implies The direct form realization and its sample processing algorithm are: H(z)= 1 + z−1 − 6z−2 1 − 0. Setting x(n)= u(n) in the I/O difference equation.2 a. we find The canonical form realization and its sample processing algorithm are: Y(z)= H(z)X(z)= 1 − z−4 = 1 + z−1 + z−2 + z−3 1 − z−1 where we used the finite geometric series. 24. 24. 8z−1 ) 1 − z−1 1 − 0.5z−1 )(1 + 0.5z−1 A B = + (1 − z−1 )(1 − 0. For filter (f): Y(z) = 1 (1 − z−1 )(1 + 0.8. For filter (b): Problem 6. −1.where A = H(−1)= 4/5 and y(n)= [1.5. the remaining zeros are the steady state.25.5j Problem 6.5z−1 ) B= And.5jz−1 ) Y(z) = C 1 + 0.5z−1 y(n) = Au(n)+B(0.8z−1 A B B∗ = + + −1 −1 1−z 1 − 0. 1.8z−1 y(n) = Au(n)+B(0.1. for the alternating step: = 0.5.25z−2 B + =A+ (1 − z−1 )(1 − 0. The A-term is the steady part. we have: 1 1 Y(z) = H(z)X(z)= = (1 − z−1 )(1 − 0.5j)n u(n)+B∗ (−0.5jz−1 ) For the alternating step and filter (a) of Problem 6. . we have: B B∗ A + + 1 + z−1 1 − 0.5j)n u(n) y(n) = A(−0.3 For filter (a).5) u(n)+C(−0.5)n u(n)+C(−0. the filter cuts off the unit step from going through because the filter has a zero at z = 1.8z−1 + B 1 − z−1 Again. B = −0. B = H(1)= 1/1.8z−1 )(1 + z−1 ) = A 1 + 0.1 + 0 . 1. ] The first four samples are the transients.8)n u(n)+Bu(n) where A = −4. B = 1/6.5jz−1 ) (1 − A z−1 )(1 + 1 + z−1 − 6z−2 − 0. B = −9. For the alternating step.5) u(n) where A = H(−1)= 4/3. C = −5. 1.4 For a unit-step input and the filter (a) of Problem 6.8)n u(n)+B(−1)n u(n) 82 83 . 2 j z=0.4z−1 )(1 − 0.5jz−1 )(1 + 0. For filter (d): Y(z) = = 1 1 = (1 + z−1 )(1 − 0.8)n u(n)+Bu(n) where A = 1/2.5jz−1 Y(z) = 1 (1 + 0.5z−1 ) C 1 + 0. .5)n u(n) where A = H(1)= 4/3.8)n u(n) with A = H(1)= 10.5.25z−2 ) A 1 + z−1 n + B 1 − 0.25. 0. 0.8z−1 )(1 − z−1 ) = A 1 + 0. 0. 0.25z−2 ) (1 − z−1 )(1 − 0.5z−1 n Y(z) = 1 − 0.25z−2 ) A 1 − z−1 y(n) = A(0. C = 1/6. −1. 0.5j) u(n)+B (−0. y(n) = A(−0. 1.5z−1 ) (1 + z−1 )(1 − 0.5jz−1 1 + 0.8z−1 + B 1 + z−1 y(n) = A(−1)n u(n)+B(0. The A-term is the steady part.8z−1 ) 1 − z−1 1 − 0. For filter (c): + B 1 − 0.4z−1 1 − z−1 + C 1 − 0. In the steady-state.1. cutting off the high frequency input. we have: Y(z) = (1 − z−1 )(1 B A 1 + z−1 + = − 0. C = −0.8)n u(n) with A = H(1)= 2.5z−1 + y(n) = Au(n)+B(0.5z−1 1 (1 − 0. The pole of the input canceled the zero of the filter.8z−1 y(n) = Au(n)+B(0. · · · ] Y(z) = H(z)X(z)= 1 (1 + 0. . B = H(1)= 5.5j = B 1 − 0. B = −1.3125. For (b).4)n u(n)+C(0. The B-term represents the steady part.5625.5jz−1 y(n) = Au(n)+B(0.25z−2 ) = 1 (1 + z−1 )(1 − 0. For filter (e): y(n) = A(−1) u(n)+B(0.5z−1 )(1 + 0. we have: Y(z)= 1−z = 1 − z−1 + z−2 − z−3 1 + z−1 −4 ⇒ y(n)= [1. 1 − 0. 0.8)n u(n) where A = Y(0)= 0.5jz−1 ) = 0 . 0. For the alternating step: B= 1 (1 + z−1 )(1 + 0.8z−1 )(1 − z−1 ) = A 1 − 0.5z−1 + n C 1 + 0. the filter has a high frequency zero at z = −1. B = H(1)= 6.8z−1 ) 1 − z−1 1 − 0. The B-term represents the steady part. The B-term is the steady part. 2 j z=0.8z−1 + B 1 − z−1 Y(z) = = (1 − z−1 )(1 − 0. we have: 1 1 = Y(z) = (1 − z−1 )(1 + 0.5.5j) u(n) where A = H(1)= 4/5 and n ∗ n y(n) = Aδ(n)+Bu(n)+C(0.5)n u(n) 1 Y(z) = = (1 + z−1 )(1 + 0.5jz 1 + 0.5jz−1 )(1 + 0. H(ω)= e−5jω and |H(ω)| = 1.25z−2 =A+ Y(z) = + (1 + z−1 )(1 − 0. For filter (d): n Problem 6.4z−1 )(1 − 0. The B-term represents the steady part.8z−1 ) 1 + z−1 1 − 0. The output is only transient — it decays to zero exponentially. i.8z−1 ) 1 − 0.5 Filter (a): H(z)= z−5 with I/O equation Y(z)= H(z)X(z)= z−5 X(z) and in the time domain y(n)= x(n − 5).4)n u(n)+C(0. For question (d). y(n) = (0. For filter (c): 1 + z−1 1 = Y(z) = −1 )(1 − 0.8z−1 ) Z n H(ω)= e−5jω 1 − e−jω ⇒ |H(ω)| = 1 2| sin(ω/2)| The pole at z = 1 or ω = 0 dominates the frequency response.5z−1 ) −1 −2 y = w5 w5 = w4 w4 = w3 w3 = w2 w2 = w1 w1 = x A 1 + z−1 + B 1 − 0. For filter (f): w2 Y(z) = = 1 + z − 6z (1 + z−1 )(1 − 0.5z−1 y(n) = A(0. For question (e).4)n u(n)+B(0.8z−1 (1 + 0.8)n u(n) Again.8z−1 x z-1 w1 z-1 z-1 w3 z-1 w4 z-1 w5 y Filter (b): H(z)= z−5 U(z)= z−5 /(1 − z−1 ) and the I/O equation gives for each input sample x do: y(n) = A(−1)n u(n)+B(0.5z−1 B = + (1 + z−1 )(1 − 0. Thus.8)n u(n) For filter (e): B C 1 + 0. The filter acts as a lowpass filter (it is actually an accumulator with delay). For filter (b): Y(z) = 1 (1 − 0. 84 85 . Y(z) = 1 1 + 0.8z−1 ) (1 + z 1 − 0. flat in ω.5z−1 )(1 − 0.e.8z−1 y(n) = Aδ(n)+B(−1)n u(n)+C(0.25z−2 ).8)n u(n) The B-term is the steady part.8z−1 Y(z)= H(z)X(z)= z−5 X(z) 1 − z−1 ⇒ (1 − z−1 )Y(z)= z−5 X(z) ⇒ Y(z)= z−1 Y(z)+z−5 X(z) ⇒ Its frequency response is y(n)= y(n − 1)+x(n − 5) y(n) = (0.5z−1 ). B = H(−1)= 1/1. y(n) = (0. Therefore.1(d) gives: 1 − 0.8z−1 + B 1 + z−1 Y(z) = = (1 + 3z−1 )(1 − 2z−1 ) (1 − 2z−1 )(1 − 0. the signal poles were canceled by the filter zeros.5z−1 ) 1 − 0.5)n u(n) The unstable input was canceled by a filter zero to give a stable output.4z−1 1 − 0. Block diagram realization and sample-by-sample processing algorithm: Y(z) = A 1 − 0.4z−1 )(1 − 0. the input has X(z)= 1/(1 − 2z−1 ). applied to Problem 6.5z−1 1 = Y(z) = (1 − 0.5z−1 y(n) = A(−1)n u(n)+B(0.8) u(n) → The filter zero canceled the signal pole. we have x(n)= (0.4z−1 )(1 − 0.where A = −4.4z−1 + C 1 − 0.25z−2 = 1 − 0..8) u(n) The high frequency zero at z = −1 of the filter canceled the high frequency input signal. the input z-transform is X(z)= 1/(1 − 0.5)n cos(πn/2)u(n)− X(z)= 1/(1 + 0.8z−1 ) 1 + z−1 1 − 0.8z−1 )(1 + z−1 ) = A 1 − 0.25. Thus.8.8z−1 y(n) = A(0. The B-term represents the steady part.25z−2 )(1 − 0.8)n u(n)+B(−1)n u(n) where A = 1/2. B = H(−1)= 5.5)n u(n) For question (c).5z−1 ) A B 1 + 3z−1 = + (1 − 0. 8z−1 ⇒ (1 − 0.8z−1 )Y(z)= X(z) ⇒ Y(z)= −0. a5 .8z−1 )Y(z)= X(z) ⇒ Y(z)= 0. Filter (e): With a = −0.8z−1 Y(z)+X(z) ⇒ y(n)= −0. a. 4 . 5 . 0. a6 .8y(n − 1)+x(n) 1 0 The canonical form realization and its sample processing algorithm are: π ω The rest is as in problem (3c). 7 z-plane = zeros y 1 The direct form realization and its sample processing algorithm are: z=a=-0.8ejπ e2πjk/8 .8z−1 ) and the I/O equation becomes: z-plane = poles |H(ω)| 0.8z−1 ) and the I/O equation becomes: Y(z)= H(z)X(z)= X(z) 1 − 0. They are shown below k = 1 . a7 .8.8z−1 Y(z)+X(z) y = x + aw1 + a2 w2 + a3 w3 + a4 w4 + a5 w5 + a6 w6 + a7 w7 w7 = w6 w6 = w5 w5 = w4 w4 = w3 w3 = w2 w2 = w1 w1 = x 86 87 . 6. 0. the impulse response is finite: h(n)= [1.and in the time domain y(n)= 0. z = ae2πjk/8 = −0. solve the equation z8 = a8 and exclude the solution z = a. 0.8 for each input sample x do: v2 -1 z v3 z-1 v4 z-1 v5 z w1 -1 y = w1 + v5 w1 = y v5 = v4 v4 = v 3 v3 = v 2 v2 = v 1 v1 = x The I/O equation in the time domain is y(n)= x(n)+ax(n − 1)+a2 x(n − 2)+ · · · + a7 x(n − 7) Sample-by-sample processing algorithm and block diagram realization: for each input sample x do: y Filter (c): H(z)= 1/(1 − 0. 3.8z−1 ⇒ (1 + 0. To find them.5 Y(z)= H(z)X(z)= X(z) 1 + 0. a2 . a3 . a4 . 2 . that is. · · · ] Its z-transform is x z-1 w0 w1 z-1 z -1 H(z)= 1 + az−1 + a2 z−2 + a3 z−3 + a4 z−4 + a5 z−5 + a6 z−6 + a7 z−7 = 1 − a8 z−8 1 − az−1 for each input sample x do: w2 w3 z-1 w4 z-1 w5 x z-1 v1 z -1 w0 = x + w1 y = w5 w5 = w 4 w4 = w 3 w3 = w 2 w2 = w 1 w1 = w 0 The point z = a is not really a pole of H(z) because it is canceled by a numerator zero — H(z) has seven zeros.8y(n − 1)+x(n) The rest is as in problem (3d). Filter (d): H(z)= 1/(1 + 0.8e2πjk/8 = 0. |z| > (0.h): -1 w0 z -8 w8 0.8)n 2Re[jn ]u(n) = (0.5z−8 + 0.64z−2 Y(z)+2X(z) −0.x a0 w1 z -1 a1 z -1 w2 z -1 w3 z -1 a4 w4 z -1 w5 z -1 w6 z -1 w7 There is a conjugate pair of poles at midfrequency.64y(n − 2)+2x(n) There is a low frequency pole at z = 0.64z−2 0 π/2 π ω Y(z) = H(z)X(z)= ⇒ Y(z)= 0.64z−2 Y(z)+2X(z) The direct form realization and its sample processing algorithm are: x 2 y(n) = 0.8jz−1 1 + 0. the filter will emphasize mid frequencies: a2 a3 a5 a6 a7 z-plane 0.52 z−16 + 0.75z−8 1 + 0.5)1/8 .64 Filters (g.8jz−1 1 + 0. h(n) = 2(0.8)n cos(πn/2)u(n)= (0.5z−8 + 0.52 z−16 + 0.7 Because z = ejω . w) w2 = w 1 w1 = y w2 where the call to delay updates the 9-dimensional state vector of the eightfold delay w = [w0 . .64 y for each input sample x do: y = 2x − 0. Thus.8j)n u(n) 1 1 2 + = H(z) = 1 − 0.5z−8 It can be written in a form that can be expanded in powers of z−8 : y(n) = −0.8j)n u(n)+(−0.64z−2 Problem 6. . or. . The block diagram and sample processing algorithm are: x w1 z 0.5 + z−8 1 − 0.53 z−24 + · · · = The direct form realization and its sample processing algorithm are: 1 1 − 0.6 0 π/2 π ω Taking z-transforms.5z−8 88 89 .64z−2 ⇒ Y(z)= −0.8 H(z)= 1 + 0. we find: -0.8 0.8 and a high frequency pole at z = −0.5 + 0.75z−8 = −0.8z−1 1 + 0.8z−1 1 − 0. the filter will emphasize both the low and high frequencies: y z-1 w1 z-1 w2 -0.64y(n − 2)+2x(n) H(z)= −0.64w2 where convergence requires |z|8 > 0.8j = poles |H(ω)| y -0. w8 ].8. w1 .5.5 + 0. .8e±π/2 .53 z−24 + · · · 1 − 0.5 y for each input sample x do: y = w 0 = x + 0. z = ±0. Thus.8j = 0.5z−8 x 2 y z -1 y for each input sample x do: y = 2x + 0. we can deduce the transfer function from H(ω): H(z)= Y(z) = H(z)X(z)= 2X(z) 1 + 0.8j Filter (f): H(z)= 1 1 2 + = 1 − 0. 5 w 8 delay(8.64z−2 2X(z) 1 − 0.64w2 w2 = w1 w1 = y z-plane = poles |H(ω)| Problem 6. ] It is depicted below: where A= B= z−1 1 + φ−1 z−1 z −1 = z=φ φ−1 1 = √ 1 + φ−2 5 φ 1 + φ2 h(n) 0. we take z-transforms of both sides of Eq. 0. 0. Therefore. The poles of H(z) are the roots of 1 − z−1 − z−2 = 0 or r(n)r(n − 1)= r(n − 1)+1 1± 5 2 √ z2 − z − 1 = 0 ⇒ z= The limiting value r(n)→ r will satisfy the limiting equation: Denoting the first one by φ. we may write this as: b. r = φ because they are the positive solutions.1) h(n)= h(n − 1)+h(n − 2)+δ(n − 1) h(n + 1) Aφn+1 → =φ h(n) Aφn This can also be seen from the difference equation of h(n).5)2 ..75/2 0.1) to get H(z): Dividing by h(n − 1). using the property φ2 = φ + 1 and successively multiplying it by powers of φ. 0. φ n≥0 1. 2 √ − 1 √ φ which is the same as that satisfied by φ. d.618). the other one will be: r2 = r + 1 = 1− 5 2 φ= Indeed. Problem 6. Solving for H(z): H(z)= z−1 1 − z−1 − z−2 h(n) h(n + 1) h(n) = +1 · h(n − 1) h(n − 1) h(n) If we denote the ratio r(n)= h(n + 1)/h(n). we get − 1 φ =− 2 1+ √ 5 =− 2 ( 1 − 5) 2 ( 1 − 5) 1− 5 √ √ =− = 1−5 2 (1 + 5)(1 − 5) √ √ √ y(3) = φ2 = φ + 1 = y(2)+y(1) y(4) = φ3 = φ2 + φ = y(3)+y(2) y(5) = φ4 = φ3 + φ2 = y(4)+y(3) ··· Performing a partial fraction expansion on H(z). (P6. we have Indeed. the ratio of two successive Fibonacci numbers will tend to: (P6.75/4 1 − φz−1 z=−φ−1 =− = −√ 1 5 . 0.Thus. 0. 0. 0. .75(0. 0. 0. we have: h(n + 1)= h(n)+h(n − 1) H(z)= z −1 H(z)+z −2 H(z)+z −1 h(n + 1) h(n) = +1 h(n − 1) h(n − 1) or. 0. 0. 0.75. because the z-transform of δ(n − 1) is z−1 .5). The sequence is properly initialized at n = 0. Thus.75 0.8 a. 1: h(0) = h(−1)+h(−2)+δ(−1)= 0 + 0 + 0 = 0 h(1) = h(0)+h(−1)+δ(0)= 0 + 0 + 1 = 1 Next. 0. 0. 0. . Indeed. 0.. we obtain a closed-form solution for the nth Fibonacci number: 0 -0. 0. for n ≥ 2 the δ(n − 1) term is absent and each h(n) is the sum of the previous two. we have 1+ 5 . we get: A z−1 B z−1 = = + H(z)= 1 − z−1 − z−2 (1 − φz−1 )(1 + φ−1 z−1 ) 1 − φz−1 1 + φ−1 z−1 90 91 . For n ≥ 1. The impulse response h(n) satisfies the difference equation: c. 0. It is unstable because φ is greater than 1 (note. 0. For large n. the impulse response will be h = [−0. the exponentially increasing term φn dominates the expression. 0. Taking the causal inverse z-transform. The sequence y(n) satisfies the recursion y(n)= y(n − 1)+y(n − 2) for n ≥ 3. . 0.5 n h(n)= Aφn + B(−φ)−n . 0. 0. 0.75(0.5. the transfer function is θ 1 A = −B = 2 = √ θ +1 2 2 Thus. . we find H(z): Y2 (z)= 1 1 − 0. the impulse response satisfies the difference equation: X1 (z)= Y1 (z)= It follows that transfer function is: h(n)= 2h(n − 1)+h(n − 2)+δ(n − 1) with zero initial conditions. it may be thought of as the output when the input is: z−1 Y(z) 1 − φz−1 = 1 + φ−1 z−1 X(z)= = z−1 H(z) (1 − φz−1 )(1 + φ−1 z−1 ) which gives the sequence: X(z)= 1 + θ−1 z−1 or. which may be solved for X(z): Y(z)= z−1 z−1 · (1 + θ−1 z−1 )= H(z)(1 + θ−1 z−1 ) = −1 −1 )(1 + θ−1 z−1 ) 1 − θz (1 − θz and therefore. 0.4z−1 H(z)= 2z −1 H(z)+z −2 H(z)+z −1 ⇒ z−1 H(z)= 1 − 2z−1 − z−2 √ X2 (z)= 0. . that is.5(0. 0 . . x(n)= δ(n)+θ−1 δ(n − 1) ⇒ x = [1. ] x(n)= δ(n)+φ−1 δ(n − 1) or x = [1.4z−1 Problem 6. 0.5z−1 )(1 − 0. Therefore.10 The input and output z-transforms are: 1 . having z-transform h(0) = 2h(−1)+h(−2)+δ(−1)= 0 + 0 + 0 = 0 h(1) = 2h(0)+h(−1)+δ(0)= 0 + 0 + 1 = 1 will be produced by Taking z-transforms.4z−1 ) 2(1 − 0. 0. . the ratio of two successive numbers will converge to y2 (n)= 2bn u(n) 92 93 .5z−1 1 1 2(1 − 0. the nth Pell number will be: H(z)= If the input x2 (n)= cn u(n) is applied it will have z-transform X2 (z)= 1/(1 − cz−1 ) and will cause the output: h(n)= Aθn + B(−θ)−n . the two start-up values are: H(z)= Therefore. −θ−1 } X1 (z) = Y1 (z) = H(z)= where A z−1 B z−1 = = + 1 − 2z−1 − z−2 (1 − θz−1 )(1 + θ−1 z−1 ) 1 − θz−1 1 + θ−1 z−1 where c = (a + b)/2. n≥0 Y2 (z)= H(z)X2 (z)= and in the time domain: 2(1 − cz−1 ) 1 2 · = 1 − bz−1 1 − cz−1 1 − bz−1 Because the exponentially diverging term θn dominates the sum. 5 Y2 (z) = H(z) 1 − 0. 1 − 0.The z-transform of y(n) will be the once-delayed z-transform of the geometric series.4z−1 (1 − 0. ] Problem 6.11 The input and output z-transforms are: 1 1 − az−1 1 1 2 − (a + b)z−1 ) 2(1 − cz−1 ) = + = 1 − az−1 1 − bz−1 (1 − az−1 )(1 − bz−1 ) (1 − az−1 )(1 − bz−1 ) 2(1 − cz−1 ) Y1 (z) = X1 (z) 1 − bz−1 z 2 = 2z + 1 The PF expansion is then ⇒ z=1± 2 = {θ. 0.45)n u(n) The roots of the denominator polynomial are the solutions of Problem 6.9 As in the previous problem.5z−1 1 − 0. Y(z)= z−1 1 − φz−1 h(n + 1) Aθn+1 =θ → h(n) Aθn The y(n) sequence has z-transform Thinking of Y(z) as the output of H(z) for a particular input X(z). 0 .45z−1 ⇒ x2 (n)= 0. we have Y(z)= H(z)X(z).45z−1 ) Y1 (z) = X1 (z) 1 − 0. φ−1 .45z−1 ) + = 1 − 0. That is. θ−1 . 0. the second output. 0. 1π [rads/sample] 5000 2π20 = 0.008π = 0.6z−1 ) Y(z) = H(z)= X(z) 1 − 0.001. the Q -factor of the filter will be: 0 .5z−1 1 − 0.4 − 1 − 0.8781z−1 + 0.008π We take the filter poles to be at locations: where T = 1/fs is the interval between samples. the scale factor is: ln ln 1 2 = ln(0.5)n u(n) which compares well with the exact value.9874 · cos(0.6z−1 ) 0.5z−1 Expanding in partial fractions. In seconds.8781 a2 = p∗ p = R2 = 0.01) = 366.14 The -level time constant of a filter is (in sampling instants): 2πf0 2π250 = 0.5z−1 (1 − 0.47 0.13 The normalized peak and width frequencies are: Problem 6.15 Using the approximate expression of Problem 6.008π h(n)= 2.001) πΔf = 2.01) 2 R=1− 1 1 Δω = 1 − 0. p∗ = Re−jω0 The pole radius R may be determined from the approximate relationship τ1 = ln ln 1 2 τ2 Δω = 2(1 − R) which gives: In particular.7z−1 1 1 2 ( 1 − 0.01) = = 363. The approximate numerical value of neff = − 2 ln Δω =− 2 ln(0.4 = 2 . for the 60 versus 40 dB time constants.7z−1 )(1 − 0. ln 1 T.1π)= −1.13 and The denominator polynomial will be: 1 + a1 z−1 + a2 z−2 = (1 − pz−1 )(1 − p∗ z−1 )= 1 − (p + p∗ )z−1 + p∗ pz−2 which gives: = 0.9750 τ=− ln πΔf − ln(0.5z−1 ) −1 Therefore.Problem 6. Problem 6.1 π ω0 = = 12.4δ(n)−0.2 Δf 94 95 .5 Q= Δω 0.001) 3 = = 1 .5z−1 where we used the small-x approximation ln(1 − x) the time constant will be: −x. the designed filter will be: H(z)= 1 1 − 1. ln ρ τ2 = ln 2 T ln ρ p = Rejω0 .9874) Therefore the transfer function will be: 2(1 − 0.5 ln(0.12 The input and output z-transforms are: 1 1 − 0. we have: The approximate expression is obtained by replacing R in terms of Δω: neff = ln ln = ln R ln(1 − Δω/2) ln −Δω/2 =− 2 ln Δω H(z)= which has the causal inverse: 2(1 − 0.9874 2 2 Problem 6.9750z−2 X(z) = Y(z) = The time constant of the resonator is given in terms of the maximum pole radius (there is only one radius here): neff = ln ln(0. the time constant is: fs = τ = neff T = ln T ln ρ 1 Therefore. It follows that the will be and 2 level time constants τ1 = And therefore.18 ln R ln(0.7z−1 1 − 0.008π [rads/sample] 5000 ln ln ρ ω0 = Δω = fs 2πΔf = neff = where ρ = max i |pi | is the maximum pole radius. 6 z ) + = 1 − 0. we have: T=− ln τ = neff T = − which gives: 2 ln Δω T=− 2 ln 2πΔf T πΔf a1 = −(p + p∗ )= −2R cos ω0 = −2 · 0.4(0. 1 Filter realizations of Problem 6. w) implements the updating of the delay line. w) where the call to delay(8. we may write: h(n)= g(n)+g(n − 4)+g(n − 8)+g(n − 12)+ · · · 96 97 . 4 The sample processing algorithm for the canonical case is: for each input x do: w0 = x + w 4 y = w 1 + 2w 2 + 3w 3 delay(4. we have: H(z)= G(z)+z−4 G(z)+z−8 G(z)+ · · · = (1 + z−4 + z−8 + · · · )G(z)= where G(z)= z−1 + 2z−2 + 3z−3 . 0] is the basic period of length 8.16 The periodic impulse response may be thought of as the sum of the delayed replicas of one period. . Problem 6.Problem 6. that is. 4. H(z)= z−1 + 2z−2 + 3z−3 = 1 − z−4 z−1 1 − z−2 1 + 2z−1 + 3z−2 1 + z−2 ≡ H0 (z)H1 (z) for each input x do: The block diagram is shown in Fig. The corresponding sample processing algorithm is: for each input x do: w0 = x + w 8 y = w 0 + 2w 1 + 3 w 2 + 4 w 3 delay(8. 2.17. that is. .2 Direct and canonical realizations of Problem 6.16. Taking z-transforms we obtain: H(z)= z−1 + 2z−2 + 3z−3 1 − z−4 H(z)= G(z)+z−8 G(z)+z−16 G(z)+ · · · = (1 + z−8 + z−16 + · · · )G(z) where G(z)= 1 + 2z−1 + 3z−2 + 4z−3 . w1 = w0 . Using the geometric series on the first factor we obtain: 1 + 2z−1 + 3z−2 + 4z−3 G(z) H(z)= = 1 − z−8 1 − z−8 The direct and canonical realizations are shown in Fig. 1. P6. The cascade realization is obtained by factoring the numerator and denominator into (up to) 2nd order polynomials: Fig. . w8 = w7 . P6. P6. Here. w4 = w3 . w) implements the updating of the delay line. w) where the call to delay(4. 2. .17 The solution is similar to that of Problem 6. 3]. the repetition period is 4 and we have: w0 = x + w 2 x1 = w 1 w2 = w1 w1 = w0 v 0 = x1 − v 2 y = v 0 + 2v1 + 3v 3 v2 = v1 v1 = v0 Using partial fractions. . G(z) 1 − z−4 h(n)= g(n)+g(n − 8)+g(n − 16)+ · · · where g(n)= [1. Thus. . w7 = w6 . x z -1 y z 2 3 -1 x w0 z w1 -1 y z-1 z-1 z-1 w2 z-1 z-1 w3 w4 z-1 z-1 z-1 2 3 x z-1 z-1 z-1 2 3 4 y z-1 x w0 z-1 w1 z-1 w2 w3 w4 w5 w6 z-1 z-1 z-1 z-1 w7 w8 z-1 z-1 2 3 y z-1 z-1 z-1 z-1 z-1 z-1 z-1 Fig.3. In the z-domain. . The sample processing algorithm for the canonical case is: The direct and canonical realizations are shown in Fig.2. . 0. that is. w3 = w2 . 0. where g(n)= [0. but the last 5 are lumped together into a fivefold delay z−5 .16.1. 3. P6. Note that in the canonical realization the total number of delays is 8. w1 = w 0 . P6. 0. 1. 2. 2. 3 . 3 . . w6 = w5 . The output due to the input x = [3. 2. 6 . . 3. . 6. 0. 0. . 6 . 0 . 1 . P6. 3. . 5.18 Expand the denominator in powers of z−7 and pick out the coefficients of the powers of z−1 . 0. 0. A B C − jD C + jD = + + + 1 − z−1 1 + z−1 1 − jz−1 1 + jz−1 where the PFE coefficients C ± jD are conjugates. 3 . 1. 1. 2. . The powers of z−7 cause the period-7 replication of the basic period G(z)= 1 + z−1 + z−2 + z−3 : Problem 6. . 0. . 2.18. .5 z=1 = − 0. 0. 1. 2. 5 . 0. . 1. 0. 0. 1. ] Thus. 0. 1. . 0. its period-2 replicas will overlap with each other and must be added together: h(n)= [1.4. 0. The numerical values are: The canonical realization is shown in Fig. 1] may be obtained by using the LTI form of convolution. 3 . .4 Canonical realizations of Problem 6. 0 .5 z=−1 w0 = x + w7 y = w0 + w1 + w2 + w3 delay(7. P6. We have for the output z-transform: h(n)= [0. 3. 1. 1. . 1. ] 98 99 . 0. . 1.5(−1)n − cos(πn/2)− sin(πn/2) Evaluating at the first couple of periods. 0. 6 . 0. 0. 2. . . 0 . 2. .x w0 z-1 w1 z-1 w2 x1 v0 z-1 v1 z-1 v2 -1 3 2 y x w0 z-1 w1 z-1 w2 w3 w4 w5 w6 z-1 w7 z-1 z-1 z-1 z-1 y H0(z) H1(z) Fig. 1 . 0.19 The expansion of the denominator. 0. The sample processing algorithm is: for each input x do: A= B= C − jD = z−1 + 2z−2 + 3z−3 (1 + z−1 )(1 − jz−1 )(1 + jz−1 ) z−1 + 2z−2 + 3z−3 (1 − z−1 )(1 − jz−1 )(1 + jz−1 ) z−1 + 2z−2 + 3z−3 (1 − z−1 )(1 + z−1 )(1 + jz−1 ) = 1. The same conclusion can be reached working with z-transforms. 6. 1. we find for n ≥ 0: x 0 h n = [ 3 . 2. 2. . that is. 6. 2. 0. 0 . 1. 1. 1. . 0. 0 . we find: n n n x0 hn−1 = [0. ] Y(z)= H(z)X(z) = = (1 + z−1 + z−2 + z−3 )(3 + 2z−1 + z−2 ) 1 − z−7 3 + 5z−1 + 6z−2 + 6z−3 + 3z−4 + z−5 1 − z−7 Problem 6. 0. 0. 0.3 Cascade realization of Problem 6. 1. 5. P6.5 + j 0 . 3 . 0. . 3. 0 . 1. 0 . Because the numerator has length 4. 3 . 3. 1. 0. 0. 2. 1. 2. 0. We have: H(z)= 1 + z−1 + z−2 + z−3 = (1 + z−1 + z−2 + z−3 )(1 + z−7 + z−14 + · · · ) 1 − z−7 The expansion of the denominator in powers of z−7 will cause the period-7 replication of the numerator. . 1. 1. 3. H(z) = z−1 + 2z−2 + 3z−3 z−1 + 2z−2 + 3z−3 = 1 − z−4 (1 − z−1 )(1 + z−1 )(1 − jz−1 )(1 + jz−1 ) Fig. 2. 0. scaled by the input samples: = − 0 . 1. will cause the period-2 replication of the numerator. ] y n = [ 3 . 3 . 5 z=j Taking (causal) inverse z-transforms. 3. 3 . 1. 2. 1.17. w) where the call to delay implements the delay-line updates w7 = w6 . 1. 3 . 0. 1. . summing up the delayed replicas of the impulse response. ] n jπn/2 h(n) = A + B(−1) +(C − jD)j + (C + jD)(−j) = A + B(−1) +2Re (C − jD)e = A + B(−1)n +2C cos(πn/2)+2D sin(πn/2) = 1. 3 . 0 . 3. ] x0 hn−2 = [0. the output also has period 7. 0.5 − 0. w1 = w0 . . . 0. 0. 1. 2. the causal impulse response will be h(n): Y(z)= W0 (z)+z−2 W0 (z)= (1 + z−2 )W0 (z)= (1 + z−2 ) X(z) 1 − z−1 100 101 . 0. 0. 0. 2. 0. if n = 0 ⎪ ⎪ ⎨ h(n)= Ban/16 . 1. . 2. 1. The impulse response is obtained by expanding H(z) into powers of z−16 . . 0.5. the magnitude response will vanish at the harmonics ωk = kω1 = 2πk/16. 0. . . 0. ]+ · · · =[1. . zk = ejωk = e2πjk/16 .21 The number of harmonics fitting within the Nyquist interval are: x w0 z-1 w1 -1 w2 z y for each input x do: w3 z -1 w0 = x + w 2 y = w0 + w 1 + w 2 + w 3 w3 = w2 w2 = w1 w1 = w0 fs 240 = =4 60 f1 Therefore. and be essentially flat between zeros. 2. 2. 3 The numerator polynomial 1 − z−4 will have ejωk as roots. . that is. 0. in the z-domain where 0 < a < 1 must be chosen to be very near 1. ] The canonical realization and sample processing algorithm are: H(z)= 1 + z−1 + z−2 + z−3 (1 + z−2 )(1 + z−1 ) = (1 − z−1 )(1 + z−1 ) 1 − z−2 which is the same as that of Problem 6. . . 1.6 shows a sketch of |H(ω)|. . Putting the poles just behind the zeros. We have with A = 1/a and B = 1 − A = 1 − 1/a: W1 (z)= z−1 W0 (z). otherwise W0 (z)= X(z)+z−1 W0 (z) ⇒ W0 (z)= Thus. W1 (z). 1. . 1. . 4 k = 0. P6.19. . k = 0. 1. the harmonics will lie at the fourth roots of unity around the unit circle: ωk = kω1 = 2πk . W2 (z)= z−1 W1 (z)= z−2 W0 (z) X(z) 1 − z−1 H(z)= B 1 − z−16 =A+ = A + B(1 + az−16 + a2 z−32 + · · · ) 1 − az−16 1 − az−16 ⎧ ⎪A + B = 1. ] Multiplying numerator and denominator by 1 + z−1 . we obtain: pk = a1/16 ejωk = a1/16 e2πjk/16 . we have 1 − z−4 1 − az−4 w0 (n) = x(n)+w1 (n) y(n) = w0 (n)+w2 (n) w2 (n + 1) = w1 (n) w1 (n + 1) = w0 (n) or. if n is a non-zero multiple of 16 ⎪ ⎪ ⎪ ⎩0. . 0. 0. If a is very near 1. 2. 0. . 0.20 H(z)= Writing the sample processing algorithm in terms of the time index n. 2. 1. 0. 0. 0. . 0. . 1. 0. in the time domain: h =[1. we get the desired multinotch filter: Problem 6. 2.which gives: H(z)= 1 + z−1 + z−2 + z−3 = (1 + z−1 + z−2 + z−3 )(1 + z−2 + z−4 + · · · ) 1 − z−2 H(z)= 1 + z−2 Y(z) = X(z) 1 − z−1 or. 1. 1. 2. 0. . 0. 1. 15 The zeros and poles are shown in Fig. 2. Problem 6. 2. k = 0. Problem 6. 1.22 The zeros are at the 16th roots of unity. we get: +[0. 1. . Fig. 0. P6. ] +[0. W2 (z) in favor of Y(z) and X(z). 1. 15 The poles are just behind the zeros at the same angles: W0 (z) = X(z)+W1 (z) Y(z) = W0 (z)+W2 (z) zW2 (z) = W1 (z) zW1 (z) = W0 (z) Eliminating W0 (z). 22.5)n u(−n − 1) Only the second one is stable.5.5)n u(n). Problem 6. 15ω1 16ω1=2π Fig. P6. as well as the canonical realization. The corresponding sample processing algorithm will be: for each input x do: 1 y = x + a(w1 − x) w1 = y Fig.5z−1 where the call to delay updates the 17-dimensional delay line.25 The canonical realization and sample processing algorithm are: The filter poles are at z = 2. for each input x do: 3 − 3z−1 − z−2 3 − 3z−1 − z−2 = 1 − 1.6 Magnitude response of Problem 6. Its ROC contains the unit circle.5)n u(n) h(n)= Aδ(n)−B2n u(−n − 1)−C(−0.5 Pole/zero pattern of Problem 6.24. Thus.6(0. h(n)= Aδ(n)+B2n u(n)+C(−0. we have: H(z)= where B 3 − 3z−1 − z−2 C =A+ + (1 − 2z−1 )(1 + 0. −0.5.5z−1 A= B= C= 3 − 3z−1 − z−2 1 − 1. H(z)= −0.3 + 1 − 0. w) Expanding in partial fractions. are shown in Fig. 6.5)n u(n) h(n)= Aδ(n)−B2n u(−n − 1)+C(−0. |z| < 0.5z−1 − z−2 (1 − 2z−1 )(1 + 0.5.7 Realizations of Problem 6.6 .22. P6.z-plane = zeros = zeros y(n)= x(n)+a(y(n − 1)−x(n)) A realization based on this expression. .23 0 . The direct form I/O difference equation is obtained from: =1 z=−0.5z−1 3 − 3z−1 − z−2 1 − 2z−1 =1 z=0 =1 z=2 Problem 6.24.5z−1 ) 1 − 2z−1 1 + 0.3δ(n)+0.5 H(z)= or. 2 > |z| > 0. |H(ω)| ω1 = 2π/16 x 1−a w0 z-1 w1 y x a − + y z-1 w1 ω 0 ω1 2ω1 3ω1 4ω1 a Fig.24 The gain factor 1 − a normalizes the magnitude response to unity at DC.5z−1 ) x w0 w16 a z-16 -1 y H(z)= w0 = x + w16 y = w0 − aw16 delay(16.5z−1 − z−2 3 − 3z−1 − z−2 1 + 0.. Problem 6.. It follows that h(n)= −0. 1−a Y(z) = X(z) 1 − az−1 The three possible ROCs and corresponding inverses are: ⇒ (1 − az−1 )Y(z)= (1 − a)X(z) Y(z)= az−1 Y(z)+(1 − a)X(z)= X(z)+a(z−1 Y(z)−X(z)) and in the time domain: |z| > 2 . 102 103 . P6. we get: ⎧ ⎨Ge−jDω . assuming its spectrum is restricted to be only over the range [−ωc . in the two cases: 104 105 . that is.5z−1 + z−2 (1 − 2z−1 )(1 − 0.5 Problem 6.5n u(n) h(n)= Aδ(n)−B2n u(−n − 1)−C0. h(n)= Aδ(n)+B2n u(n)+C0. the z-transform of the input x(n) will be: Z 1 1 + z−2 where the i-th coefficient is obtained by deleting the factor (1 − pi z−1 ) from the left-hand side and evaluating the remainder at z = pi .5z−1 3( 1 + z ) 1 − 2z−1 −2 −2 y(n)= =3 z=0 1 2π ωc −ωc Ge−jDω X(ω)ejωn dω = G 1 2π ωc −ωc X(ω)ejω(n−D) dω Comparing this with the expression of x(n). we find: 1 − 2z−1 3 3(1 + z−2 ) · = 1 − 0.5z−1 Y(z)−z−2 Y(z)+3X(z)+3z−2 X(z) ⇒ H(z)= Y(z) 3(1 + z−2 ) = X(z) 1 − 2. we find for h(n): M Y(z)= H(z)X(z)= Inverting causally. Thus.5). Thus. for the input signal. |z| < 0.3.5n u(n) h(n)= Aδ(n)−B2n u(−n − 1)+C0.5z−1 A= B= C= 3( 1 + z ) 1 − 2. the definition of H(ω) over one Nyquist interval will be: Factoring the denominator into its poles and expanding in partial fractions.5) u(n) n The z-transforms of the causal and anticausal sinusoidal inputs are the same up to a negative sign: Problem 6. respectively.5z−1 + z−2 3(1 + z−2 ) 1 − 0.5z−1 ) 1 + z−2 h(n)= i=1 Ai pn u(n) i Problem 6. the output z-transform will be: Z 1 − 2z−1 1 + z−2 ⎥ ⎥ ⎥ )⎦ z=pi = j=i N(pi ) (1 − pj p−1 ) i Taking causal inverse z-transforms. (6.5.Problem 6. The output z-transform will be Y(z)= H(z)X(z). we have: π −π ejω0 n u(n) − → Z Z 1 1 − ejω0 z−1 1 1 − ejω0 z−1 y(n)= 1 2π H(ω)X(ω)ejωn dω ejω0 n u(−n − 1) − − → Similarly.28 The PF expansion of H(z) is of the form: Thus. ⎡ ⎢ ⎢ Ai = ⎢ ⎣ j=i ⎤ N(z) (1 − p j z −1 x(n)= g(n)−2g(n − 1)− X(z)= G(z)−2z−1 G(z)= (1 − 2z−1 )G(z)= → Thus.5z−1 + z−2 Using d(ω)= D. the ROCs and corresponding inverses are: |z| > 2 . the integration range for y(n) also collapses to [−ωc . 2 > |z| > 0.27 Using the inverse DTFT formula of Eq. for 0 ≤ |ω| ≤ ωc H(ω)= ⎩ 0. ωc ]. ωc ]: with ROCs |z| > 1 and |z| < 1.5z−1 ) 1 − 2z−1 1 − 0. giving: H(z)= where B 3(1 + z−2 ) 3(1 + z−2 ) C =A+ = 1 − 2. we recognize that =5 z=2 y(n)= Gx(n − D) = −5 z=0.29 y(n)= 3(0. for ωc < |ω| ≤ π where G is its passband gain.26 The transfer function is obtained from the I/O difference equation by taking z-transforms of both sides and solving for the ratio Y(z)/X(z): x(n)= 1 2π ωc −ωc X(ω)ejωn dω Y(z)= 2.5.5z−1 (1 − 2z−1 )(1 − 0.5n u(−n − 1) H(z)= N(z) M M = i=1 Ai 1 − pi z−1 (1 − pi z−1 ) i=1 The z-transform of the signal g(n) is: g(n)= cos(πn/2)u(n)− G(z)= → Therefore. we must assume a particular ROC. that is.5z−1 )(1 − 2z−1 ) 1 − 0. Therefore. we used the property u(n)+u(−n − 1)= 1 for all n. that is: where C = H(ω0 ). so that all the PFE terms will be inverted causally. we take the filter part to be causal and the input anticausal. 2−D zD · (1 − 2z−1 )= 2−D zD 1 − 2z−1 y(n) = H(ω0 )ejω0 n u(n)+ i=1 Bi pn u(n)+H(ω0 )ejω0 n u(−n − 1)− i i=1 Bi pn u(n) i and in the time domain: E(z)= = H(ω0 )ejω0 n u(n)+H(ω0 )ejω0 n u(−n − 1) = H(ω0 )e jω0 n e(n)= 2−D δ(n + D) By choosing D large enough. and Bi are obtained by deleting the factor (1 −pi z−1 ) and evaluating the rest at z = pi : ⎡ ⎤ ⎥ ⎢ N(z) ⎥ ⎢ ⎥ Bi = ⎢ ⎣ (1 − ejω0 z−1 ) (1 − p z−1 ) ⎦ j j=i z=pi = N(pi ) M ⎧ ⎪δ(n)+0.3. 106 107 .5-pole term will be inverted causally and the 2-pole anticausally: h(n)= δ(n)+0. (6. −∞ < n < ∞ The error output will be x(n)= δ(n)−2δ(n − 1)− X(z)= 1 − 2z−1 → where. For the causal case. −D ≤ n ≤ −1 ⎪ ⎪ ⎪ ⎩0. 5 z 1 − 2z−1 2−D zD 1 − 2z−1 2−D zD 1 − 2z−1 Z y(n) = H(ω0 )ejω0 n u(n)+ i=1 Bi pn u(n) i M H(z)= H(z)− or. These choices for the ROCs.5n ]z−n − 2n z−n Comparing with the result of the previous problem.5n . the error transfer function: y(n) = H(ω0 )ejω0 n u(−n − 1)− i=1 Bi pn u(n) i H(z)−H(z)= The given input has z-transform: Adding up the right-sided and left-sided sinusoidal inputs gives rise to the double-sided input: ejω0 n u(n)+ejω0 n u(−n − 1)= ejω0 n u(n)+u(−n − 1) = ejω0 n . For the anticausal case. we have: Bi = Ai 1 − ejω0 p−1 i The last term can be summed by changing summation variables from n to m = −n: −1 n=−D D To get the inverse z-transform y(n). as we saw in Eq. the 0. the ROC will be the annular region between the maximum pole and the unit circle: max |pi | < |z| < 1 i 2n z−n = m=1 2−m zm = 2−1 z(1 − 2−D zD ) 1 − 2−D zD =− 1 − 2−1 z 1 − 2z−1 where we used the finite geometric series: D xm = x + x2 + · · · xD = x(1 + x + x2 + · · · xD−1 )= m=1 x(1 − xD ) 1−x Thus.10). which is recognized as the standard steady-state sinusoidal response of the filter.5z−1 1 − 2z−1 Y(z)= ± Bi C ± 1 − ejω0 z−1 1 − pi z−1 i=1 M The stable ROC containing the unit circle will be 0.5 < |z| < 2. the factor 2−D can be made as small as desired. give: M H(z)= 1 + Comparing with the exact H(z) we have: 1 1 − 2−D zD + −1 1 − 0. It follows from the linearity of the filter that the corresponding output will be the sum of the two outputs obtained above. This gives: M M E(z)= Y(z)−Y(z)= H(z)X(z)−H(z)X(z)= H(z)−H(z) X(z) or.Problem 6. we take the ROC to be |z| > 1.30 Y(z)= ± (1 − e The partial fraction expansion leads to N(z) M jω0 −1 The PF expansion of H(z) gives: −1 z ) i=1 (1 − p i z ) H(z)= 3 − 5z−1 + z−2 1 1 =1+ + (1 − 0. In this case the C term will be inverted anticausally and the Bi terms causally. n ≥ 0 ⎪ ⎪ ⎨ h(n)= −2n . n ≤ −D − 1 ∞ −1 n=−D (1 − ejω0 p−1 ) i j=i − (1 − pj pi 1 ) The corresponding z-transform is by definition: H(z)= n=0 [δ(n)+0.5n u(n)−2n u(−n − 1) The truncated impulse response agrees with h(n) for n ≥ −D and is zero otherwise. 1.1 Direct and canonical realizations of Problem 7. w2 . Factoring the denominator as 1 − z transfer functions: −5 = (1 − z −1 )(1 + z −1 +z −2 +z −3 +z −4 ). 2. v) w0 = x1 − w1 − w2 − w3 − w4 y = w 0 + 2 w 1 + 3 w 2 + 4w 3 delay(4. P7. 4. v1 ]. 1. The corresponding sample processing algorithm is as follows: 108 109 . P7. 4. for each input x do: Problem 7. The calls to the delay routines update the delay line. P7. But because the numerator itself has length 5. for each input x do: v0 = x + v 1 x1 = v 1 delay(1. 0. w3 = w2 . w4 . w4 = w3 . 3. v) delay(5. w) for each input x do: w0 = x + w 5 y = w 1 + 2w 2 + 3 w 3 + 4 w 4 delay(5. −5 x v0 z v1 -1 x1 w0 -1 w z 1 -1 w2 z -1 w z 3 -1 -1 y 2 3 4 -1 -1 z-1 w4 x v0 z v1 z-1 v2 v3 v4 z-1 z-1 3 4 2 -1 w0 z w1 z-1 w2 w3 w4 w5 z-1 z-1 z-1 -1 y x w0 z w1 z-1 w2 w3 w4 w5 z-1 z-1 z-1 3 4 2 -1 y Fig. with each filter realized in its canonical form. v1 . 2.2 Cascade realization of Problem 7. w) is equivalent to the shifts: w5 = w4 . resulting in: Y(z)= H2 (z) H1 (z) Y(z)−X(z) − Y(z) + E(z) Moving the Y-dependent terms to the left. .2 shows the cascade of these two filters. w2 = w1 . The sample processing algorithms are expressed with the help of the routine delay. 3. 4.Chapter 7 Problems Problem 7. w = [w0 . the desired transfer functions are identified to be: Hx (z) = He (z) = H1 (z)H2 (z) 1 + H2 (z)+H1 (z)H2 (z) 1 1 + H2 (z)+H1 (z)H2 (z) Figure P7. we get: 1 + H2 (z)+H1 (z)H2 (z) Y(z)= H1 (z)H2 (z)X(z)+E(z) and solving for Y(z): where v = [v0 . we get the cascaded Y(z)= H1 (z)H2 (z) 1 + H2 (z)+H1 (z)H2 (z) X(z)+ 1 E(z) 1 + H2 (z)+H1 (z)H2 (z) H(z)= 1 + 2z−1 + 3z−2 + 4z−3 z−1 + 2z−2 + 3z−3 + 4z−4 z−1 = · 1 − z−5 1 − z−1 1 + z−1 + z−2 + z−3 + z−4 Thus. w4 ] are the internal state vectors for the two filter sections. 3. w = [w0 . w2 . w1 . e.and 6-dimensional state vectors needed for the numerator and denominator polynomials. w) H1 (z) Y(z)−X(z) − Y(z)− H2 (z) H1 (z) Y(z)−X(z) − Y(z) → Adding the noise component E(z) to the output of H2 (z) will generate Y(z). w) where v = [v0 .g. Therefore. 2. .2 In the z-domain. 1. its output will be H1 (z) Y(z) −X(z) .. which updates the filter’s internal state vectors. the call delay(5. the replicas will not overlap.w5 ] are the 5. w1 = w0 .1. ] The direct and canonical realizations are shown in Fig.1. v2 . v4 ]. Fig. and we will get the repetition of the numerator coefficients: h = [0. . 0.1 Expanding the denominator in powers of z will replicate the numerator periodically with period 5.1. w1 . The input and output of H2 (z) will be then : v0 = x w0 = w5 + v1 + 2v2 + 3v3 + 4v4 y = w0 delay(4. the input to H1 (z) is X(z)−Y(z). w3 . w3 . 0. . we note that the numerator corresponds to the length-6 signal b = [0. ] Fig. 0. w2 = w1 .3 Multiplying the numerator factors. 0. u2 ]. 3.3. The corresponding sample processing algorithm is as follows: The direct and canonical realizations are shown in Fig. u1 . w5 = w4 . e.. The presence of z−1 in the numerator of H2 (z) is necessary to make the overall closed loop computable. v5 ]. 1.and 7-dimensional state vectors needed for the numerator and denominator polynomials. w2 ]. w4 = w3 . P7. we get the transfer function: z-1 v2 2 -1 z-1 w2 3 H(z)= z−1 (1 + 2z−2 )(1 + 3z−2 ) z−1 + 5z−3 + 6z−5 = 1 − z−6 1 − z−6 Fig. for each input x do: v0 = x w0 = v1 + 5v3 + 6v5 + w6 y = w0 delay(5. They are both integrators. 0. 5.24 and 12. v2 . v) delay(6. . u) v0 = x1 − v1 − v2 x 2 = v 0 + 2v 2 delay(2. w2 . the call delay(6. v2 ]. 1. 6]. the replicas will not overlap.3 Direct and canonical realizations of Problem 7.4 Cascade realization of Problem 7. The sample processing algorithms are expressed with the help of the routine delay. 5. 0. 0. w6 ] are the 6. Expanding the denominator in powers of z−6 will replicate the numerator periodically with period 6. 3. 5. v1 . To determine the impulse response.3. w3 = w2 .The conditions that Hx (z) be a plain delay and He (z) a double differentiator. with each filter realized in its canonical form. See also Problems 12. v = [v0 . are the internal state vectors for the three filter sections. . w) where u = [u0 . v4 .25.4 The z-domain versions of the time domain difference equations are: w0 = x + w 6 y = w 1 + 5 w 3 + 6w 5 delay(6. w5 .3. 0.g. gives the two equations: H1 (z)H2 (z) 1 + H2 (z)+H1 (z)H2 (z) = z−1 where v = [v0 . w = [w0 . 0.4 shows the cascade of these three filters. w1 . w) is equivalent to the shifts: w6 = w5 . w) for each input x do: Problem 7. w = [w0 . 1. x u0 z-1 u1 z-1 u2 x1 v0 -1 v1 z -1 -1 x2 w0 -1 w1 z y Problem 7. v) w0 = x2 + w1 − w2 y = w 0 + 3w 2 delay(2. v1 . w1 . 3. But because the numerator itself has length 6. x v0 z-1 v1 z-1 v2 v3 v4 v5 z-1 z-1 z-1 6 5 w0 z-1 w1 z-1 w2 w3 w4 w5 w6 z-1 z-1 z-1 z-1 y x w0 z-1 w1 z-1 w2 w3 w4 w5 w6 z-1 z-1 z-1 z-1 6 5 y for each input x do: u0 = x + u 2 x1 = u1 delay(2. The calls to the delay routines update the delay line.w4 . 1. 5. w3 . and we will get the repetition of the numerator coefficients: h = [0. which updates the filter’s internal state vectors. 0. Factoring the denominator as 1 − z−6 = (1 − z−2 )(1 + z−2 + z−4 )= (1 − z−2 )(1 + z−1 + z−2 )(1 − z−1 + z−2 ) we get the cascade transfer function: 1 = (1 − z−1 )2 1 + H2 (z)+H1 (z)H2 (z) which can be solved for H1 (z) and H2 (z) giving: H1 (z) = H2 (z) = 1 1− z−1 H(z)= z−1 1 − z−2 · 1 + 2z−2 1 + 3z−2 · 1 + z−1 + z−2 1 − z−1 + z−2 z−1 1 − z−1 Figure P7. w1 = w0 . 0. w) v(n) = x(n)+v(n − 1) y(n) = v(n)+v(n − 2)+v(n − 4) ⇒ V(z) = X(z)+z−1 V(z) Y(z) = V(z)+z−2 V(z)+z−4 V(z) 110 111 . P7. P7. 25 0. w) And for the cascade realization: for each input x do: Fig.6.5 v 2 x1 = 2 v 0 − 3 v 1 delay(2. P7. v) delay(4. w) x x1 v0 z-1 v1 v2 z-1 w1 w2 w0 z-1 z-1 -1 y x 2 v0 z v1 z-1 v2 v3 z-1 -1 w0 -3 2 -3 y x 2 w0 z -1 y z -1 w1 z-1 w2 z-1 z -1 -3 2 -3 w1 w2 w3 z-1 z-1 z -1 Fig.25z−4 1 − 0 .4. The cascade realization is shown in Fig. Y(z)= (1 + z−2 + z−4 )V(z)= 1 + z−2 + z−4 X(z) 1 − z−1 for each input x do: Therefore. and cascade realizations are shown in Fig. gives: V(z)= X(z) 1 − z−1 .25w4 y = 2w 0 − 3w 1 + 2w 2 − 3w 3 delay(4.Eliminating V(z) in favor of Y(z). w) 112 113 . v0 = x + v 1 x1 = v0 + v1 + v2 delay(2.5 w 2 w0 = x + w 1 y = w0 + w 2 + w 4 delay(4. P7.5.7.25w4 y = w0 delay(3. v) w 0 = x 1 − 0 . and cascade realizations of Problem 7. w) for each input x do: w0 = x + 0. v) w0 = x1 y = w0 − w1 + w2 delay(2.5 Direct. we may write the transfer function as: 2 − 3z−1 1 + z−2 2 − 3z−1 + 2z−2 − 3z−3 = · −2 −2 1 − 0. canonical. 5z x v0 z-1 v1 z-1 v2 v3 v4 z-1 z-1 w0 z-1 w1 y x w0 z-1 w1 w2 w3 w4 z-1 z-1 z-1 y H(z)= The direct and canonical realizations are shown in Fig. v) delay(1. Its sample processing algorithm is: for each input x do: v 0 = x + 0 . X(z). canonical.5 Factoring the denominator. P7. P7. The direct and canonical sample processing algorithms are: for each input x do: w3 w4 0. P7. w) Problem 7. 5z 1 + 0. w) y = w0 + w2 delay(2. Their sample processing algorithms are: for each input x do: v0 = x w0 = 2v0 − 3v1 + 2v2 − 3v3 + 0. the transfer function is: H(z)= 1 + z−2 + z−4 1 + z−1 + z−2 = · (1 − z−1 + z−2 ) 1 − z−1 1 − z−1 where we factored the numerator as 1 + z−2 + z−4 = (1 + z−1 + z−2 )(1 − z−1 + z−2 ) The direct.5.25 w4 v0 = x w0 = v0 + v2 + v4 + w1 y = w0 delay(4.6 Direct and canonical realizations of Problem 7. 5 v0 z-1 v1 0.5j)n u(n)+2. in the causal case. ±0.8.5)n u(n) Writing jn + (−j)n = ejπn/2 + e−jπn/2 = 2 cos(πn/2).5)n cos(2πn/2)+2(0.6 The direct and canonical realizations are shown in Fig.25 w0 z-1 w1 z-1 w2 z-1 z-1 0. The cascade realization is shown in Fig.5)n u(n)+2(−0.10. define only two ROCs.25w2 delay(4. v) y = w0 = x1 + 0. the causal case |z| > 0.5jz−1 1 + 0. P7.4096 w1 w2 w3 Fig.7 The direct and canonical realizations are shown in Fig. P7. P7. Its sample processing algorithm is: for each input x do: v0 = x − 0.25v2 delay(2.0625 x v0 z v1 z-1 v2 v3 v4 z-1 z-1 0.7 Cascade realization of Problem 7.5(−0. It corresponds the factorization: H(z)= 2 .25v2 x1 = v0 − 2.4096 -2 -1 w0 z -1 y x w0 z -1 y w1 z-1 w2 z-1 z-1 w3 w4 0. v) delay(4. Their sample processing algorithms are: for each input x do: The four poles z = ±0.9. w) x v0 z-1 v1 z-1 v2 -2.9 Cascade realization of Problem 7.11. P7.5j.5z−1 H(z)= 1 − 2z−2 + z−4 1 − z−2 1 − z−2 = · 1 − 0. P7.8 Direct and canonical realizations of Problem 7. P7.5 2.25v2 + 0. w) w3 w4 0.4096w4 delay(4.0625w4 y = w0 − 2.10 Direct and canonical realizations of Problem 7.5)n u(n) Problem 7.25 w0 z-1 w1 -2. namely. the impulse response will be: h(n)= 2.5.0625 y x w0 z-1 w1 w2 w3 z-1 z-1 -2. we have: z-1 z-1 z-1 w4 -2 Fig.25 0. w) for each input x do: w0 = x + 0. w) h(n)= 5(0.25w2 delay(2. For example. we have: v0 = x w0 = v0 − 2. The cascade realization is shown in Fig.5z−1 1 + 0.5j)n u(n)+2(0.4096w4 y = w 0 − 2w 2 + w 4 delay(4. Their sample processing algorithms are: for each input x do: for each input x do: w0 = x + 0.25 y z-1 v2 z-1 w2 z-1 v2 z-1 w2 Fig.5 2 2 + + + 1 − 0. v) delay(4.5 -3 y x x1 v0 z-1 v1 -0.5 and the anticausal one |z| < 0.5.0625w4 y = w0 delay(2. Fig. Problem 7.64z−2 114 115 .4096z−4 1 − 0. w) Expanding H(z) in partial fractions.5(0.25 z-1 w4 y v0 = x y = w0 = v0 − 2v2 + v4 + 0. P7.5.x 2 x1 w0 z-1 w1 -0.5jz−1 1 − 0. P7.64z−2 1 + 0.6.6.5)n u(n)+2(−0.7. 8 z Problem 7.9 x x1 v0 z-1 v1 0.0. it follows that H(ω) will have unit magnitude. y = .64z−4 z-1 v2 z-1 w2 -1 1 + z−4 = (1 + z−1 )(1 − z−1 + z−2 ) we obtain the cascade factors: Fig.75w10 y = −0.75 * w[0] + w[10]. v) w0 = x1 − 0. x x1 v0 z-1 v1 0. v) w0 = x1 − 0.64z 1 − 0. Problem 7. return y. 116 117 .75e−10jω ) Noting that the ratio of two conjugate complex numbers has unit magnitude.64v2 } for (i=10. P7. i--) w[i] = w[i-1]. double y. Its sample processing algorithm is: for each input x do: v 0 = x + 0 .Note that the numerator could also have been factored as: 1 − 2z−2 + z−4 = (1 − z−2 )2 = (1 − z−1 )2 (1 + z−1 )2 = (1 − 2z−1 + z−2 )(1 + 2z−1 + z−2 ) But the chosen one has the simplest coefficients.8 -1 y z-1 v2 z-1 w2 Fig.75z−10 Its block diagram realization and sample processing algorithm are given below: x w0 z 0. i>=1.64w2 y = w0 − w 2 delay(2. w) H(ω)= (1 − 0. From the transfer function.75 -10 -0.8z−2 1 − 0. w) x1 = v0 + v1 delay(2.75 + e−10jω e e = = −10jω −10jω 1 − 0. w) double x. 8v 2 H(z)= −0.11 Cascade realization of Problem 7.12 Cascade realization of Problem 7.75e 1 − 0. { int i. w) w10 The C version of the algorithm is as follows: double reverb(x.9.8 w0 z-1 w1 -0.64 w0 z-1 w1 -1 -0. w[11]. P7.75 * w[10]. we obtain the frequency response: x1 = v0 − v 2 delay(2. w[0] = x + 0. H(z)= 1 + z−3 1 + z−1 1 − z−1 + z−2 · = −4 −2 1 + 0.75 + z 1 − 0.8 The given difference equations describe the canonical realization form of the filter: −10 The cascade realization is shown in Fig.75 y for each input sample x do: w0 = x + 0. P7.75w0 + w10 delay(10.75e10jω −10jω −0.64 y The given sample processing algorithm corresponds to the canonical realization of the filter: H(z)= Factoring the numerator in the form: 1 + z−3 1 − 0. Its sample processing algorithm is: for each input x do: v0 = x + 0.7.75e (1 − 0.12.8w2 y = w0 − w1 + w2 delay(2.75e−10jω )∗ −10jω 1 − 0. 81v2 √ x1 = v0 − 2v1 + v2 delay(2.81z−2 )(1 − 0. 118 119 .13 together with the corresponding sketches of the magnitude responses |H(ω)| over the right half of the Nyquist interval 0 ≤ ω ≤ π.9. the zeros will be at the roots of 1 + z−4 = 0. ω The first filter has zeros at z = ±j. the 4th roots of unity rotated by 45o .11. 1] -0.e. each being a triple zero.9 H(z)= (1 + z−2 )3 = 1 + 3z−2 + 3z−4 + z−6 ⇒ h = [ 1 . k = 0. and a pole at z = 0. P7.9)n u(n)] π -0. ±j.9j. 0 . 0 . where w(n)= (0. The pole/zero plots of the three filters are shown in Fig. w) Therefore.6561w4 delay(4.14 shows the pole/zero locations and the corresponding magnitude response. 2.10.81w2 √ y = w 0 + 2w 1 + w 2 delay(2.10 The first filter is an FIR filter with transfer function and impulse response: = zeros = poles 0. P7. z4 = − 1 ⇒ z = ejπ(2k+1)/4 . and the third filter has zeros at the fourth roots of unity.9j.6561 y z-1 π ω π ω π ω v2 v3 w3 w4 Fig. w) x -j |H(ω)| |H(ω)| |H(ω)| -j v0 z-1 v1 z-1 z-1 z-1 w0 w1 w2 z-1 z-1 z-1 z-1 0. 3 . 1 .16.11 Fig. h(n)= w(n)−w(n − 4).9m.15 Direct and canonical realizations of Problem 7. P7.. The poles are at z = ±0. that is. Fig.13 Pole/zero patterns of Problem 7. v) delay(4. The direct and canonical realizations are shown in Fig. P7. ±0.9 The causal impulse response of the third filter is obtained by the remove restore method. The second filter has poles at z = ±0. that is.81z−2 ) H(z)= (1 − √ √ The cascade realization is shown in Fig.9j Fig. w) for each input x do: w0 = x + 0. v4 w4 Problem 7. Their sample processing algorithms are: Problem 7. we obtain: 2z−1 + z−2 )(1 + 2z−1 + z−2 ) 1 + z−4 = 1 − 0.6561w4 y = w0 + w 4 delay(4. that is. z = ±1.Problem 7. 3 that is. v) w0 = x1 + 0.11. P7. j = zeros = poles j 0. P7. Multiplying the transfer function factors. Its sample processing algorithm is: for each input x do: v0 = x − 0.9 1 for each input x do: v0 = x y = w0 = v0 + v4 + 0.12 The zeros are at the roots of 1 + 16z−4 = 0.9j -1 -0.9j |H(ω)| 0.6561 y x w0 z-1 w1 w2 w3 z-1 z-1 0. 0 . i. P7.9j 0.6561z−4 (1 + 0.14 Pole/zero plot of Problem 7. 3 .15. 0625v0 + v4 − 0. Similarly.0625.25v2 √ x 1 = v 0 − 2 2v 1 + 4 v 2 delay(2.5 2z−1 + 0.0625z−4 1 − 0. Indeed. The magnitude response is constant in ω. 3 that is. setting c = 1/16.0625w0 + w4 delay(4. 1 . the 4th roots of unity rotated by 45o and scaled in magnitude by a factor of 2. the poles are at: 1 z =− 16 4 x 0.81 2 y Noting that 1/16 = 0.18 Direct and canonical realizations of Problem 7.25z−2 1 + 0. we find: √ 2az−1 + a2 z−2 )(1 + √ 2az−1 + a2 z−2 ) √ √ 1 1 1 + z−4 = (1 + 24 z−4 )= (1 − 2 2z−1 + 4z−2 )(1 + 2 2z−1 + 4z−2 ) 16 16 16 ⎧ ⎪c ⎪ ⎪ ⎪ ⎪ ⎨−(1 − c2 )c(n−4)/4 h(n)= ⎪(1 − c2 )c(n−4)/4 ⎪ ⎪ ⎪ ⎪ ⎩ 0 if n = 0 if n is an even multiple of 4 if n is an odd multiple of 4 otherwise 120 121 .0625w4 y = 0. k = 0.0625 y x 0. we have: ω The cascade realization is shown in Fig.0625 y ⇒ z = 0.18. z-1 = zeros = poles unit circle v3 w3 w4 |H(ω)| 1 v4 w4 Fig.17 shows the pole/zero locations. π Fig.2 w0 z-1 w1 0.0625x + 0.5 2z−1 + 0. v) √ w0 = x1 − 0. 1 . P7.5 2w1 − 0. giving |H(ω)| = |e−4jω | · ) (1 + ce (1 + ce−4jω ) −4jω ∗ =1·1=1 H(z)= c + z−4 1 + cz−4 =c+ (1 − c2 )z−4 = c + (1 − c2 ) z−4 − cz−8 + c2 z−12 − c3 z−16 + · · · 1 + cz−4 To get the cascade form.25w2 √ y = w 0 + 2 2w 1 + 4w 2 delay(2. P7.0625 · · 1 + 0. k = 0. the impulse response may be obtained by writing: H(ω)= c + e−4jω 1 + ce−4jω = e−4jω (1 + ce4jω ) (1 + ce−4jω )∗ = e−4jω 1 + ce−4jω (1 + ce−4jω ) The ratio of the two conjugate factors will have unity magnitude. w) Fig. P7. 5 e jπ(2k+1)/4 . 2. w) z4 = −16 ⇒ z = 2ejπ(2k+1)/4 .0625 v0 z-1 v1 z-1 v2 z-1 z-1 w0 w1 w2 z-1 z-1 z-1 z-1 -0. v0 = x y = w0 = 0.25z−2 √ √ z-1 v2 z-1 w2 The direct and canonical realizations are shown in Fig.11. P7.12. P7. the transfer function is then: H(z)= 0.16 Cascade realization of Problem 7.0625 + z−4 1 − 2 2z−1 + 4z−2 1 + 2 2z−1 + 4z−2 √ √ = 0.0625w4 delay(4. v) delay(4. w) Finally. 2 .12.0625 w0 z-1 w1 w2 w3 z-1 z-1 -0. Their sample processing algorithms are: for each input x do: for each input x do: w0 = x − 0.19. Its sample processing algorithm is: for each input x do: √ v0 = 0.81 .x x1 v0 z-1 v1 -0.5 2v1 − 0.17 Pole/zero plot of Problem 7. P7. we may factor the numerator and denominator using the identity: 1 + a4 z−4 = (1 − Thus the numerator becomes: Extracting the coefficients of z−1 . 3 Fig. sizeof(double)).6f\n". **B. scanf("%d". } /* input data */ printf("\n\n"). sizeof(double)). B[i]+j).891 -0. sizeof(double)). A = B = W = for (double **) calloc(K. a). sizeof(double *)). i).19 Cascade realization of Problem 7. and piped into the program by iirfilt < input.6lf % . i<K.206 0 0.147 0. j<3.h> void cas2can(). ycas). b = (double *) calloc(M+1. wdir. sizeof(double)). b. sizeof(double *)). B[i] = (double *) calloc(3.6f % .313 0. The program stops filtering as soon as the end-of-file of x.117 0. and also conv required by cas2can and sos required by cas. a = (double *) calloc(M+1. b[i]). The number of sections K and the corresponding rows of the matrices A and B are entered interactively. M. while(fscanf(fpx. A. vdir.147 0.103 -0. &x) != EOF) { a. ydir. x. sizeof(double)).294 0. j++) scanf("%lf". double *vdir. W[i] = (double *) calloc(3. *a. cas(). "r"). x). P7. j++) scanf("%lf". x). double dir(). double x. can(). printf("\n a. i). M. } cas2can(K. 0. sizeof(double *)). j<3. ydir = dir(M.780 0.360 0.5 2 -0.x 0. fpx = fopen("x.234 0. ydir. can. A[i]+j). vdir = (double *) calloc(M+1.6f % . (i=0. printf("no.373 -1. ycas. b = \n").25 z-1 w2 22 4 Fig.dat The input signal xn to be filtered is assumed to be in the file x. i++) { A[i] = (double *) calloc(3. M=2*K. *wdir.313 0. FILE *fpx.103 These inputs may also be saved in a file.25 z-1 v2 -2 2 4 -0. *b. K. sizeof(double)). /* direct form coefficients */ for (i=0. j. sizeof(double)). a. sections K = ").dat is encountered. say. wcan. i++) { 122 123 . % . void main() { int i. b). } The program must be linked with the routines cas2can. W. wdir = (double *) calloc(M+1.dat. input. &K). ycan.712 0. x). ycan. double **A.6lf\n".13 The following program implements this computer experiment: /* iirfilt.6f } "%lf". } for(i=0.190 0 0. i++) { printf("enter B[%d] = ". printf("% . M.117 0. B. A. For example. sizeof(double)). b.h> #include <stdlib.dat".12.dat. a[i]. for(j=0.i++) printf("% .c .IIR filtering experiments */ #include <stdio. ycas = cas(K.122 -0. (double **) calloc(K. B. ycan = can(M. i<K. **W. the user input for the given transfer functions will be (starting with K = 4): 4 1 1 1 1 0.5 2 -0. dir. Problem 7. i<K.0625 x1 v0 -1 v1 z w0 -1 w1 z y printf("enter A[%d] = ".i<=M. cas2can(K. The first 10 of the input and output samples are shown below: for(i=0. *wcan. wcan = (double *) calloc(M+1. (double **) calloc(K. for(j=0. cas. char **argv) { FILE *fpa. state.dat\n"). It is patterned after firfilt. *fpb. P7.807624 1. The first 10 impulse response samples computed by the three realizations are shown below: Problem 7. the steady-state DC response will be coefficient files coeffs.011644 0.120828 −0. argv[2]).112201 0.120828 −0.164600 1. The program reads and allocates the filter coefficient arrays.079222 0. } a = (double *) calloc(max + 1. plotted together with the input.163405 0.026788 0.13. output.005637 0.005637 0. It is shown also in Fig.000000 1.IIR filtering in canonical form */ #include <stdlib.dat <x. "Usage: canfilt a.000000 1.000000 0.807624 1. argv[1]).164600 1.003881 0.275606 0.005637 0.006191 0.019407 0.019407 0.000000 0.20 Input.018165 0.000000 1.592519 −0. Therefore.000554 0. initial allocation size x(n) 1. The outputs computed by dir.000000 1. The last while loop performs the actual filtering: /* canfilt. "r")) == NULL) { fprintf(stderr.032979 0.000000 0.043772 1.dat containing 1 followed by 49 zeros. } if ((fpa = fopen(argv[1].006191 0. can.000000 0. y.000554 0.20. input. "Can’t open filter file: %s\n".000000 1.236148 0.120828 −0.112201 0. for (M=0. P7.000000 hdir (n) 0.000554 0.000554 0. K. *w.dat b. "Can’t open filter file: %s\n". output initial allocation and increment H(ω) ω=0 = H(z) z=1 =1 This can be observed in the output which rises up to 1 before it dies out to zero.079222 0.873631 −4.283588 0.524036 0.163405 0.112201 0.236148 0.c of Problem 4. x.248430 0.011644 0.236148 0.000554 0. 0 ≤ n < 50 can be computed by running this program on a file x.000000 0.275606 0.000000 0.157457 ycan (n) 0.000000 1. Fig. exit(0). exit(0).157457 ycas (n) 0.dat >y.007142 hcan (n) 0. Calling cas2can on the matrices A and B gives the direct form denominator and numerator coefficients: a 1.196860 −0. P7. int max = MAX.465987 2.000000 1.807624 1.000000 b 0.c . M.941724 0. *b.283588 0.026788 0.166000 4. int L..h> #define MAX 64 double can().003881 0.157457 Fig.10.275606 0. "r")) == NULL) { fprintf(stderr.000000 if (argc != 3) { fprintf(stderr.283588 0.043772 1. void main(int argc.524036 0.000000 0. dmax = MAX.248430 0.007142 hcas (n) 0.000000 −3.006191 0.000000 0.079222 0. i. M++) { if (M == max) { 124 125 ..043772 1.000000 1.164600 1. The impulse response h(n).000000 0.000000 1.x(n) 1.524036 0.000554 0. and impulse response of Problem 7.163405 0. exit(0).248430 0. sizeof(double)).14 An example of such program is given below.20 shows the full output.032979 0.007142 The given filter is an example of a lowpass Butterworth filter and the normalization gains in each section have been chosen to give unity gain at DC. and cas are of course the same.026788 0. } if ((fpb = fopen(argv[2]. double *a.000000 ydir (n) 0.032979 0.000554 0.000554 0.h> #include <stdio. dmax = MAX. W = (double **) calloc(K. } } process input samples if ((fpa = fopen(argv[1]. (max + 1) * sizeof(double)).dat >y. i<K. (max + 1) * sizeof(double)). "r")) == NULL) { fprintf(stderr. L++) { if (L == max) { max += dmax. printf("%lf\n". "%lf". K. b = (double *) realloc((char *) b. void main(int argc. double **A. for(i=0. b + L) == EOF) break. B[i] + j). } if (fscanf(fpa.. double *a. sizeof(double)). j<3. and then it reshapes it into the K×3 matrix A. a + M) == EOF) break. "%lf". i++) for(j=0. w. j++) fscanf(fpb. b.dat in a concatenated form. x). M++) { if (M == max) { max += dmax.m . W. } M--. a = (double *) realloc((char *) a. x. } a = (double *) calloc(max + 1.dat <x. % if (argc != 3) { fprintf(stderr. y. } if ((fpb = fopen(argv[2]. B[i] = (double *) calloc(3.dat B. sizeof(double *)).m is given below. "Can’t open filter file: %s\n". while(scanf("%lf". argv[1]). if (M%3 != 0) { fprintf(stderr. } a = (double *) realloc((char *) a. i. sizeof(double *)). } } process input samples Problem 7.max += dmax. a = (double *) realloc((char *) a. i<K. The last while loop performs the actual filtering: /* casfilt. &x) != EOF) { y = can(M. (L + 1) * sizeof(double)). w = (double *) calloc((K + 1). "r")) == NULL) { fprintf(stderr. } if (fscanf(fpa. } else K = M / 3.IIR filtering in cascade form */ #include <stdlib. &x) != EOF) { y = cas(K. sizeof(double)).m N times. **W. j<3. **B. sizeof(double *)). y). a temporary array a is used to read the rows of A. x). B.. W[i] = (double *) calloc(3. exit(0). i<K.IIR filtering in cascade form % % y = casfilt(B. L. K = (L <= M) ? M : L. exit(0).15 An example of such program is given below. } for(i=0. The program reads and allocates the filter coefficient matrices A and B.c . A. for (i=0. It calls cas. (M + 1) * sizeof(double)). int M. (max + 1) * sizeof(double)). x). "%lf". where N is the input length: % casfilt. a = (double *) realloc((char *) a. sizeof(double)). sizeof(double)). "%lf". m. a + M) == EOF) break. A. *fpb. "Can’t open filter file: %s\n". exit(0). } 126 127 . } L--. To facilitate the initial allocation of A. i++) for(j=0. b = (double *) realloc((char *) b. char **argv) { FILE *fpa.h> #include <stdio. (M + 1) * sizeof(double)).dat\n"). "all rows of A must be 3-dimensional"). sizeof(double)). initial allocation size coefficient files temporary coefficient array allocation and increment The MATLAB version casfilt. sizeof(double)). i++) { A[i] = (double *) calloc(3. for (L=0. j. A = (double **) calloc(K. printf("%lf\n". j++) A[i][j] = a[3*i + j]. int max = MAX. } if (fscanf(fpb. for (M=0.h> #define MAX 64 double cas(). exit(0). argv[2]). y). while(scanf("%lf". B = (double **) calloc(K. b = (double *) calloc(max + 1. a. "Usage: casfilt A. u[0] = G2 * x .comb filtering examples */ #include <stdio. v = (double *) calloc(9. fprintf(fpy2.00 * * * * pi pi pi pi / / / / 8. fpy2 = fopen("y2. for (n=0. for n = 1:N. x). void main() { int n. 8. we find the impulse responses. 1 − 0.c . sizeof(double)).dat". y2). P7.3 and 7. scanf("%d". *w.0625 * w[8]. s). fprintf(fps.94 * u[8]. x. } } "%.8lf\n".96z−8 · −8 1 + 0. *v. section 1 */ /* filter 2.16 The two filters are: 1 + z−8 .8lf\n". v[0] = x1 + 0. The second filter has a longer time constant. end printf("enter input length N = "). "w").5 0.h> #include <stdlib. for 0 ≤ n ≤ 16: 128 129 . "w").4. /* filter 1 */ |H1 (ω0 )| = |H2 (ω0 )| = 1 The following program implements this computer experiment. delay(8. B. y2 = v[0] . w3.17 Performing a partial fraction expansion on H1 (z) and H2 (z).98z−8 Expanding in powers of z−8 and extracting coefficients.% B = Kx3 numerator matrix (K = number of sections) % A = Kx3 denominator matrix % x = row vector input % y = row vector output fpx = fopen("x. w2.98z−8 H1 (z)= 0. P7. y1). except the input sample x gets multiplied by the corresponding normalization gains: /* combex. v). The sample processing algorithms of Examples 7. sizeof(double)). void delay().h> #include <math. delay(8. pi = 4*atan(1. Problem 7.5π/8.98021 /* filter 2 */ /* section 1 output */ /* section 2 output */ #define G1 #define G2 Fig. x) [K. *u. /* filter 1 */ /* filter 2.98021 · The scale factors. y1. w).06191 0. fps = fopen("s. were chosen such that the magnitude responses are unity at ω = ω0 = 0.02150 − 12. delay(8. fpy1 = fopen("y1. section 2 */ function y = casfilt(B.70849 0. "%.98 * v[8]. sizeof(double)).94z−8 1 − 0.50 0.4 remain the same. 8.0). w1.70849 · H2 (z)= 0. u = (double *) calloc(9. x1 = u[0] + u[8].8lf\n". &N).5 0. noise-free. x(n)).3).5 0.8lf\n". *fpx.4. but it removes the noise very well. y2.0. H1 (z) = −11. fprintf(fpx.04433 1 − 0.96 * v[8]. x1.dat". s. "w"). The first filter has a short time constant. w = (double *) calloc(9. A. x = s + A2 * cos(w2*n) + A3 * cos(w3*n).dat". *fpy1. The corresponding output signals y1 (n) and y2 (n) from H1 (z) and H2 (z) are shown in Fig.94z 1 − 0. [y(n). n<N. fprintf(fpy1. we find (where the PFE coefficients are given with 5-digit accuracy): N. A. N] = size(x). n++) { s = A0 * cos(w0*n) + A1 * cos(w1*n).75 1. 8.02063 + 1 + 0.0625z−8 1 + z−8 1 − 0.dat".00 3. *fpy2. that is. "%.0625z−8 FILE *fps.22. K1] = size(A). double double double Problem 7. w0.0. but does not remove the noise component well. y1 = w[0] + w[8].h> #define #define #define #define A0 A1 A2 A3 1. w0 w1 w2 w3 = = = = 0. "w"). signal s(n) and the noisy signal x(n). "%. u). 0.0 0. which serves as the input to the comb filters. w[0] = G1 * x + 0. W = zeros(K. W] = cas(K.21 shows the desired. W. [N1.33584 + H2 (z) = 1. ccas(). *wcan. P7. /* initialize */ 130 131 . sizeof(double)). ccan(). p = wcan.h> #include <stdlib. *b. *wdir. P7. **W. P7.c . FILE *fpx. ycas. ydir. double x.circular buffer versions */ #include <stdio. sections K = ").18 The following program replaces iirfilt. printf("no.22 Outputs of comb filters 1 and 2 of Problem 7.70849 0 0 0 0 0 0 0 0. n 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 h1 (n) 0. Fig.23 Fig.IIR filtering experiments . **B. The computed impulse responses are shown in Fig.98021 0 0 0 0 0 0 0 0.c of Problem 7.13. Problem 7.h> void cas2can(). /* circular pointers */ wdir = (double *) calloc(M+1.c is left in the program as before.The impulse responses of the two filters can be computed by the same program as above. "r").04705 h2 (n) 0. wcan = (double *) calloc(M+1. *a.16. scanf("%d". M. double **A. fpx = fopen("x. M=2*K. K. j. double *p.21 Desired and noisy inputs of Problem 7. sizeof(double)). double *vdir. but with changing the input x(n) into an impulse δ(n). Fig.23 Impulse responses of comb filters 1 and 2 of Problem 7.17. double dir(). For comparison. vdir = (double *) calloc(M+1.07841 0 0 0 0 0 0 0 −0.16. **P. dir. ycan. P7.dat".03489 void main() { int i. &K).75277 0 0 0 0 0 0 0 0. /* iirfilt. sizeof(double)). } cas2can(K. "%lf". for (i=0. w) for each input x do: s3 = tap(3.6lf\n".5)2 z−6 + (0. j++) scanf("%lf". sizeof(double)). } printf("a.5 0.5 0 0 s2 0 0 1 0 0 0 . w. It has z-transform: W(z)= 1 D(z) X(z)= 1 X(z) 1 − 0. W. wcan. 1 . &p. w. M. i++) { printf("enter B[%d] = ". cas2can(K. sizeof(double *)). x). . A[i]+j). b. sizeof(double)). b = \n"). i). &p. 0. The linear and circular buffer versions of the sample processing algorithm are as follows: that is. ycan. } x 6 y w0 s0 z-3 w3 s3 /* allocate */ 0.5 0. sizeof(double)). b. for(j=0. . ycas). a). i++) { A[i] = (double *) calloc(3. i).5)3 z−9 + · · · which gives the impulse response: h = 6.24. for(j=0. vdir. B. 0 . a. W[i] = (double *) calloc(3. M. which is the intermediate signal obtained at the output of the input adder. .5)3 .5 0. wcan.5z−3 H(z)= 4 + 2 1 + (0.5 w 3 y = 6w 0 − 2w 3 delay(3. 2(0. printf("% .5)z−3 + (0. x).6f % . x.6f\n". 0. b.5 One minor difference in ccan is that it assumes the same order M for both vectors a and b. j<3.19. P7. W = (double **) calloc(K. p. A. B[i] = (double *) calloc(3. . b[i]). /* initialize */ for each input x do: w 0 = x + 0 . 0.i++) printf("% .5s3 y = 6s0 − 2s3 ∗p = s0 cdelay(3. 5 2 s1 0 1 0 0 0 . b = (double *) calloc(M+1. they are the successively delayed versions of w(n). P. P[i] = W[i]. while(fscanf(fpx.a = (double *) calloc(M+1. i++) { printf("enter A[%d] = ". a[i]. } for(i=0.5 . sizeof(double)). &x) != EOF) { ydir = dir(M. A. b.5). b). x). i<K.5)2 . . A = (double **) calloc(K. sizeof(double)).6f % . 2(0. The states si represent the delay-line outputs: whereas the usage of can was: ycan = can(M. 0. P = (double **) calloc(K.6lf % .5 -2 Fig. a. sizeof(double *)). a.i<=M. a.5z−3 1 − 0. ycan = ccan(M.24 Canonical realization of Problem 7. B[i]+j). . 0 . 3) s0 = x + 0. 0 .5 n 0 1 2 3 4 5 6 x 1 0 0 0 0 0 0 w0 1 1 1 1 0 0 0 w1 0 0 0 0. 2(0.5 w2 0 0 0 0 0 0 0. s0 (n) ⎢ s (n) ⎢ 1 s(n)= ⎢ ⎣ s2 (n) s3 (n) ⎡ ⎤ ⎡ w(n) ⎥ ⎢ w(n − 1) ⎥ ⎢ ⎥=⎢ ⎦ ⎣ w(n − 2) w(n − 3) ⎤ ⎥ ⎥ ⎥ ⎦ Problem 7. for (i=0. B = (double **) calloc(K. } for(i=0. 0. we have: 6 − 2z−3 2 =4+ 1 − 0. P7. x). wcan. printf("\n\n").52 w3 0 0 0 0 0 0 0 s0 1 0 0 0. ycas = ccas(K. 0 . wdir. = [ 6 . j++) scanf("%lf".19 The canonical realization is shown in Fig. i<K.5 0 0 0.5 0 y = 6s 0 − 2 s 3 6 0 0 1 0 0 0 . 0. Therefore its usage is: ycan = ccan(M. i<K. 0.5z−3 132 133 . 0 . & p) The impulse response can be obtained by dividing out the numerator and writing H(z)= Expanding in powers of z−3 . sizeof(double *)).6f % . ] s3 0 0 0 1 0 0 0. B. ydir. x). j<3. 0. sizeof(double *)). 0. because rounding does not preserve products—the rounded product of two numbers is not equal to the product of the two rounded numbers. 0.5π. 5 0. 0. −3. we have X(z)= 1.024.5z−3 and in the time domain: w(n)= [1. The corresponding cascade transfer function will be: (P7. a11 . in the sense that if we round its coefficients also to 2-digit accuracy.2) (P7. R1 = 0.9) p0 = R0 ejω0 . Thus. ω 0 = 0. −1. the p0 pole has moved outside the unit circle.9859] The poles are at: (P7. 0. ˆ ˆ ˆ p1 = R1 ejω1 . −3. Indeed. 0.9) are shown in Fig. If we round the direct form coefficient vector a to 2-digit accuracy. a01 .46.0961π ˆ R1 = 0.0390.8) and their conjugates. the filter will remain stable.6065. (P7. a02 ]= [1. ˆ ω1 = 0.4749. we obtain: ˆ ˆ ˆ ˆ ˆ = [1. but has not affected the stability of the filter.5)z−3 + (0. −3.5 1 s3 0 0 0 1 2 3 0.2000π (P7.4) ˆ ˆ The filters Hdir (z) and Hcas (z) are not equal. Problem 7.7.9930] a1 = [1. a01 .02. The impulse response and the magnitude response of the cascaded filter (P7. . on the other hand. a12 ]= [1.25 Full and 2-digit precision filters.25 s1 0 1 2 3 0 .3) ˆ Hcas (z)= 1 1 · ˆ ˆ ˆ ˆ 1 + a01 z−1 + a02 z−2 1 + a11 z−1 + a12 z−2 (P7. . together with the exact magnitude response.20 The full precision direct form denominator is: a = [1. (P7. are: ˆ ˆ ˆ p0 = R0 ejω0 . therefore. Rounding the cascade coefficients to 2-digit accuracy is not equivalent to rounding the direct form coefficients.99] a ˆ ˆ ˆ1 = [1. a4 ]= [1. The seemingly benign replacement of a by the rounded ˆ has made the direct form a realization unusable. 0.9950 ω0 = 0.25 w3 0 2 2 2 2 1.1045π ˆ ω1 = 0.5 1 1 .979] The full precision cascade coefficients are: a0 = [1.9965.For a delta-function input. 5. The zeros of a polynomial are indirect functions of the coefficients 134 135 .5) This filter is unstable. P7. ] For the input x = [1. 5 0. They are both inside the unit circle. rendering the filter unstable. a3 . The magnitude responses are plotted in dB.7) gives the following direct form vector.61.1989π (P7.5 y = 6 s 0 − 2s 3 6 12 18 1 2 3 0 .464. −1.9801] a a ˆ R0 = 1. 0.25. its four poles. a3 . 0. 0. . Thus.52 . The latter is blowing up exponentially. −3.1) and (P7. The sensitivity of the direct form and the robustness of the cascade form can be understood analytically in the following way. 0.8955. 5. Indeed.4): ˆ0 ∗ ˆ1 = [1.6) ˆ ˆ p 1 = R1 e ˆ jω1 . a12 ]= [1. rounding does not preserve convolution. in the cascade case the rounding operation changed the magnitude response somewhat. the roots of the denominator polynomial. P7. a2 .2) to 2-digits gives: ˆ ˆ ˆ0 = [1.5 s2 0 0 1 2 3 0. p1 = R1 e jω1 R0 = 0.26.98] a and the corresponding direct form transfer function: ˆ Hdir (z)= 1 ˆ 1 + a1 (P7. that is. a1 . that is.90. the filter remains stable.5)2 z−6 + (0.5) are shown in Fig. 0.7) ˆ ˆ R0 = 0.5 s0 1 2 3 0. which is the right half of the Nyquist interval. 2.9950. we have: n 0 1 2 3 4 5 6 x 1 2 3 0 0 0 0 w0 1 1 1 1 1 1 1 w1 0 0 0 0. giving: W(z)= 1 = 1 + (0. 1π ω 1 = 0. 20 log10 |H(ω)|. −1.9860. carrying out the convolution of the two vectors in Eq. P7.99] a The roots of these sections are: ˆ ˆ ˆ p0 = R0 ejω0 . a2 . −1. 0. Indeed. a11 . 5 0. (P7.5. 0. a4 ]= [1. ˆ R1 = 0.5)3 z−9 + · · · 1 − 0. a02 ]= [1. 3].5100. 2π .5 1 1. and their conjugates. 5. which is not quite the same as that given by Eq. 0.0045. rounding the SOS coefficients (P7. ˆ ω0 = 0. −3. over 0 ≤ ω ≤ 0. The impulse responses of the two filters (7. 5 w2 0 0 3 3 3 3 0. ˆ = a0 ∗ a1 ≠ ˆ0 ∗ ˆ1 a a a z−1 ˆ + a2 z−2 ˆ + a3 z−3 ˆ + a4 z−4 (P7.50. −3.1) The cascade realization.9929.5 Fig. is more robust. Therefore. 0.502.5 1 .5 0. a1 . a → a + da dp0 = − p0 da01 + da02 . the induced changes in the poles dpi will be large even if the coefficient changes dai are small. . A similar calculation can be made based on Eq.12) (pi − pj ) j=1 j≠i In the cascade realization. The above sensitivity formulas generalize easily [2.11).13).5836 With these values of the poles and dai . we take differentials of both sides of the above polynomial identity to get: The sensitivity of each pole depends only on the SOS it belongs to. In the cascade form.4) and (P7. For example. . we find for dp1 : dp1 = − p3 da1 1 + + p1 da3 + da4 (p1 − p∗ )(p1 − p0 )(p1 − p∗ ) 0 1 p2 da2 1 (P7. we obtain the induced changes in the poles due to small changes in the coefficients of the sections: (1 − p0 z−1 )(1 − p∗ z−1 )(1 − p1 z−1 )(1 − p∗ z−1 )= 1 + a1 z−1 + a2 z−2 + a3 z−3 + a4 z−4 1 0 A small change in the coefficients will induce a small change in the zeros p0 and p1 . such factors cause large shifts in the pole locations. the induced changes in the zeros can be large. a1 .9965ej0.3238 = 1.10) dp1 = −0. p2 .1π = 0. causing them to move outside the unit circle.4) in the form ˆ = a + da. that is. small changes in the latter will induce changes in the former. 0.004. . Therefore. pM : dpi = ∂pi ∂pi ∂pi da1 + da2 + · · · + daM ∂a1 ∂a2 ∂aM where the partial derivatives are: ∂pi =− ∂am Fig.9501 + j0.2π = 0.1989π Similarly. we obtain subtracting (P7. (P7. we can calculate the pole shifts using (P7. da3 . .3. . Writing the rounded ˆ of Eq. 136 137 . 1 To determine dp0 and dp1 in terms of da. that is.0037ej0.1046π ˆ p1 = p1 + dp1 = 0. da4 ]= [0.0066 dp0 = − p3 da1 + p2 da2 + p0 da3 + da4 0 0 (p0 − p∗ )(p0 − p1 )(p0 − p∗ ) 0 1 ˆ p0 = p0 + dp0 = 0. . We find: −dp0 p−1 (1 − p∗ p−1 )(1 − p1 p−1 )(1 − p∗ p−1 )= da1 p−1 + da2 p−2 + da3 p−3 + da4 p−4 0 0 0 0 0 0 0 0 1 0 Multiplying by p4 and solving for dp0 .9929ej0. therefore. The dependence of p0 on a0 and p1 on a1 is established through the identities of the polynomial.13) ⇒ pi → pi + dpi . the denominator involves the differences between poles. aM ] with M zeros p1 .3079 p1 = 0.11) involve differential changes.0033 − j0.0023 + j0. . a2 . (p0 − p∗ ) 0 dp1 = − p1 da11 + da12 ∗ (p1 − p1 ) (P7. not on the other sections. (P7.10) and (P7.26 Impulse and magnitude responses of 2-digit-precision cascade form. setting z = p1 . we obtain 0 dp0 = 0.11). the distances from all the other poles.Because. the new pole locations will be: (P7. da1 . Setting z = p0 will remove all but the first term in the left-hand-side.5770 = 0. if p0 is near p1 . For the direct form.002.9477 + j0. The relationship of the zeros to the coefficients is established via the polynomial identity: (1 − p0 z−1 )(1 − p∗ z−1 ) = 1 + a01 z−1 + a02 z−2 0 (1 − p1 z−1 )(1 − p∗ z−1 ) = 1 + a11 z−1 + a12 z−2 1 Using the above procedure of taking differentials of both sides and setting z = p0 in the first and z = p1 in the second.001] Using the numerical values given in Eq. i = 0.3).10) and (P7. (P7. (P7. p0 is associated with the first SOS and p1 with the second. giving the relationship: p0 = 0. In Eqs. it follows that if the poles are closely clustered. the induced changes remain small.6).1): a a a da = ˆ − a = [0.004. we have − dp0 z−1 (1 − p∗ z−1 )(1 − p1 z−1 )(1 − p∗ z−1 ) 0 1 − (1 − p0 z − (1 − p0 z −1 −1 )dp0 z ∗ −1 (1 − p 1 z −1 )(1 − p1 z (1 − p1 z ∗ −1 ∗ −1 ) ) )(1 − p0 z ∗ −1 )dp1 z −1 − (1 − p0 z−1 )(1 − p∗ z−1 )(1 − p1 z−1 )dp∗ z−1 0 1 = da1 z−1 + da2 z−2 + da3 z−3 + da4 z−4 which is still an identity in z. 0. the sensitivity of each pole is coupled to the other poles. thus.7999 + j0. through the denominator factors of the form (p0 − p1 ). we may actually apply them to the above example and estimate the pole shifts for the 2-digit case. P7. consider the above fourth order denominator vector a.246] to the case of an order-M filter a = [1.9863ej0. Even though the sensitivity formulas (P7.0159. 0.10) and (P7. (P7.11) which compare well with the actual values of Eq.8033 + j0. −0. da2 . pM−m i M (P7. . 9240×10−5 Table P7. But. defined as the ratio relative error = (P7.215719 0.999999 0. as we see below.and 4-digit ˆ. a The impulse responses of the 5-digit case and the 4-digit cascade case based on ˆcas are shown a in Fig. ˆ1 . a a a For the 5-digit direct form.978849 0. The 4-digit cascade response.8992] a ˆ2 = [1.23 See the solution of Problem 7.2 shows the poles of the exact and approximate filters. for the 4-digit direct form.078152 magnitude 0.74710000 1.301303 0.933552 ± j0.00000000 −5.215739 0.999999 0. The second and third columns of this table show the quantized versions of a.927976 0.05062482 −16.079185 4-digit direct 0.925902 ± j0. The magnitude responses of the full precision. Problem 7. 0.929194 a 1. 5. on the other hand. the 4-digit cascade form gives an adequate approximation of the exact filter.74713000 3.56573000 13. the filter remains stable. the error in the 5-digit case is less than that in the 4-digit case.2580×10−7 a 4-digit ˆ 1.05046030 −16. the roots of the denomia nator polynomials a. Thus.933557 ± j0.925911 ± j0. that is.8518.58649943 0.923469 ± j0.49540000 11. the error of the cascade case is larger. and 4-digit coefficients.20.and 4-digit accuracy.22 See the solution of Problem 7. P7. whereas both the 5.00000000 −5.49540000 11.21.929217 magnitude 0. The fourth column of Table P7.29.980962 0.9623] a ˆ1 = [1.2 Filter poles.58650000 0. Problem 7.84990000 −4.05062000 −16. Note that the 5-digit direct no longer meets the passband specs. Figure P7.20.078311 5-digit direct 0.1. and ˆ2 .952730 0. P7. −1. da a = ˆ−a a a where a denotes the length of the vector a.931610 ± j0.216576 0.1 shows the equivalent direct-form coefficient vector ˆcas arising a from the cascade of the quantized second order section coefficients.853736 4-digit cascade 0.853736 magnitude 0.21 The numerical values of a are shown in the first column of Table P7. one root of ˆ a has moved outside the unit circle and the third conjugate pair of roots has been replaced by two real-valued ones.1 Exact.74713457 relative error a 5-digit ˆ 1.56570000 13.74710016 1.27 shows the impulse responses of the exact filter based on a and the 4-digit-precision filter based on ˆ.84993647 −4. the quantized coefficients ˆ correspond a to an unstable filter. P7.948265 0. This behavior can be traced to the pole sensitivity formula Eq. 138 139 . 0. one almost on the unit circle.284105 0.and 4-digit direct forms fail.27 Impulse responses of full-precision and 4-digit-precision filters.05060000 −16.49508213 11. the roots of the 4-digit quantized cascaded form ˆcas remain a inside the unit circle. and 4-digit cascade cases are shown in Fig.00000000 −5.980971 0.927787 ± j0. full precision 0.888774 ± j0. Table P7.58650000 0.56570000 13. By contrast. Problem 7. 5-digit direct.56573395 13.49540451 11.8634] a The table also shows the relative error in each case.967208 ± j0.84994000 −4. The rounded ai are: ˆ0 = [1.923396 ± j0. which is unstable.008071 0.266869 0.301259 0. Fig. (P7.923398 ± j0. −1. and in fact they are practically equal to the unquantized ones.6487×10−6 ˆcas a 1. But. However. 0.84961490 −4.948258 0.00000000 −5. rounded to 4-digit accuracy.Problem 7. rounded to 5. and of the rounded SOS polynomials ˆ0 . it has a passband ripple of almost 2 dB instead of the required 1 dB. meets the specifications.12) which can cause large shifts in the poles even though da is small. 5-digit. As expected.28.14) Table P7.926857 magnitude 1.300414 0.8671. −1.8468.58633537 0. 15) Transposed realizations of FIR filters are obtained by the four transposition rules of exchanging input with output. x. by 140 141 . replacing nodes by adders. for example. 2.1. b.c is an implementation. /* transp. double transp(M. int M.IIR filtering in transposed of canonical form */ (P7. b. a.c . i<=M-1. that is. 5-digit direct.or. for each input sample x do: (P7.b have same order M output y(n)= v0 (n) state updating for (i=1.4). Problem 7. M−1 do: vi = bi x − ai v0 + vi+1 v M = b M x − aM v0 The following C function transp. the overall I/O system. y = v 0 = b0 x + v1 for i = 1.25 In the case of a general transfer function of the type of Eq. i++) v[i] = b[i] * x . .17) Problem 7. *v. . { int i. v2 (n). .a[M] * v[0]. (7.28 Impulse responses of 5-digit direct and 4-digit cascade filters. v. For indexing convenience. for example. v[0] = b[0] * x + v[1]. . . return v[0].16) y = v 0 = b 0 x + v1 v1 = b1 x − a1 y + v2 v 2 = b 2 x − a 2 y + v3 v3 = b3 x − a 3 y Problem 7. v1 (n)= b1 x(n − 1)−a1 v0 (n − 1)+v2 (n − 1)= b1 x(n − 1)−a1 y(n − 1)+v2 (n − 1) Its usage is the same as that of can or dir. . P7. where we assumed L = M for simplicity: for each input sample x do: Fig. which includes the updating of the internal states.21. usage: y = transp(M. a. Problem 7.29 Magnitude responses of exact. } v0 (n)= y(n)= b0 x(n)+v1 (n) The output of each delay is the delayed version of the output of the adder below it.24 The transfer function is: b0 + b1 z−1 + b2 z−2 + b3 z−3 H(z)= 1 + a1 z−1 + a2 z−2 + a3 z−3 (P7. P7.a[i] * v[0] + v[i+1]. v.21. and adders by nodes. . *b. advancing it to the next time instant: v1 (n + 1)= b1 x(n)−a1 v0 (n)+v2 (n)= b1 x(n)−a1 y(n)+v2 (n) Therefore. These rules can be applied to the canonical or direct realizations of IIR filters. will be: y(n)= v0 (n)= b0 x(n)+v1 (n) v1 (n + 1)= b1 x(n)−a1 y(n)+v2 (n) v2 (n + 1)= b2 x(n)−a2 y(n)+v3 (n) v3 (n + 1)= b3 x(n)−a3 y(n) which leads to the sample processing algorithm: Fig. The (M+1)-dimensional array v = [v0 . and 4-digit cascade. The I/O difference equations describing the time-domain operation of the realization and the corresponding sample processing algorithm can be obtained by introducing as internal states the contents of the three delay registers at time n: v1 (n). x) double *a. v3 (n). v[M] = b[M] * x . we also introduce the quantity v0 (n) which is the overall output obtained at the top adder. we have the sample processing algorithm. v1 . x). v = internal state vector a. reversing all flows. . vM ] must be declared and allocated in the main program. The I/O difference equations are: 142 143 . It replaces canfilt. *v.dat\n").dat b. which is basically the transposed form: Y = b0 X + z−1 (b1 X − a1 Y)+z−1 (b2 X − a2 Y)+z−1 (b3 X − a3 Y) The transposed form can also be used in the cascade realization.c of Problem 7.c of Problem 7. exit(0). } if (fscanf(fpa. dmax = MAX. } if ((fpa = fopen(argv[1]. a. which is similar to H¨rner’s rule of evaluating a polynomial. y. char **argv) { FILE *fpa.2. "Usage: trspfilt a.5z−2 1 + 0. L++) { if (L == max) { max += dmax. } if (fscanf(fpb. &x) != EOF) { y = transp(M. b + L) == EOF) break. v = (double *) calloc(M+1. argv[2]). exit(0). "%lf". } v = (double *) calloc(M + 1.b must have same length").25. x). calling the routine transp.30.b must have same length"). double *a. "r")) == NULL) { fprintf(stderr.25z−4 1 − 0 . exit(0). The sample processing algorithm of a 2nd order section is simply: for each input sample x do: y = v0 = b0 x + v 1 v1 = b 1 x − a 1 y + v 2 v2 = b 2 x − a 2 y which can replace Eq. } a = (double *) calloc(max + 1. y). "%lf". "coefficient vectors a. i. (max + 1) * sizeof(double)). 4z 1 + 0. sizeof(double)).27 coefficient files coeffs.dat <x. (L + 1) * sizeof(double)). this program aborts if the lengths are unequal.15) can be written as: fprintf(stderr. input. (P7. b = (double *) realloc((char *) b. sizeof(double)). a = (double *) realloc((char *) a. } M--. } } process input samples H(z)= −(a1 z−1 + a2 z−2 + a3 z−3 )H(z)+b0 + b1 z−1 + b2 z−2 + b3 z−3 which can be written in the nested form: H = b0 + z−1 (b1 − a1 H)+z−1 (b2 − a2 H)+z−1 (b3 − a3 H) Multiplying both sides by the z-transform X(z) of the input x(n). sizeof(double)).h> #define MAX 64 double transp(). int max = MAX.dat >y. where each second order section will be realized in its transposed form. M++) { if (M == max) { max += dmax. *fpb. for (L=0.17) has a certain simplicity and elegance. exit(0). For o example. "r")) == NULL) { fprintf(stderr. b.5z−2 −2 + 0. "Can’t open filter file: %s\n". b = (double *) realloc((char *) b. x.h> #include <stdio. void main(int argc. It corresponds to writing the transfer function of the filter in a nested form. /* trspfilt.26 The following program implements filtering in the transposed form. *b. output initial allocation and increment The transfer function is: H(z)= 9 − 4z−2 + 4z−4 3 − 4z−1 + 2z−2 3 + 4z−1 + 2z−2 = · −1 + 0. L. if (M != L) { fprintf(stderr. Transposed realizations are not intuitively obvious. a = (double *) realloc((char *) a. "coefficient vectors a. and using Y(z)= H(z)X(z).double *v.14. P7. argv[1]). we obtain the following nested form for the computation of the output.. } L--. sizeof(double)).84z The transpose of the canonical form is shown in Fig. Problem 7. } if ((fpb = fopen(argv[2].c . Because transp assumes that a and b have the same length M.. printf("%lf\n". the transfer function (P7. (7. a + M) == EOF) break. "Can’t open filter file: %s\n".. v.IIR filtering in transposed form */ #include <stdlib. (M + 1) * sizeof(double)). b = (double *) calloc(max + 1. but their overall implementation in terms of Eq.2).4z−1 + 0. (max + 1) * sizeof(double)). fprintf(stderr. if (argc != 3) { initial allocation size Problem 7. state. while(scanf("%lf". for (M=0. int M. P7. block diagram is to assign names to all signal lines that do not already have names and then set up the various adder and filtering equations.5 Fig. x(n) e(n) z -1 g(n) H1(z) H2(z) y(n) f(n) Fig. The general approach to analyzing this.5y -4 0.5x1 y = 3x1 + v11 v11 = 4x1 − 0.4x1 (n)+v02 (n) v02 (n + 1)= 2x(n)−0.84y(n)+v3 (n) v3 (n + 1)= v4 (n) v4 (n + 1)= 4x(n)−0. P7.84 v3(n) z -1 for each input sample x do: y = 9x + v 1 v4(n) z 4 -1 v1 v2 v3 v4 = v2 = −4x − 0.4 v02(n) z-1 2 -0. P7.28 The overall.5 2 v12(n) z-1 -0. transfer function of the feedback system can be worked out easily using z-transforms.25 Fig. with signal names assigned as in Fig.4x1 + v02 v02 = 2x − 0. P7.5y(n) The sample processing algorithm will be: for each input sample x do: x1 = 3x + v01 v01 = −4x + 0.4y + v12 v12 = 2x1 − 0. The cascade form with both 2nd order sections realized in their transposed form is shown in Fig.31 Cascade form with transposed sections.4 4 -0.25y(n) and the corresponding sample processing algorithm: v0 (n) v1 (n) z-1 v2(n) z -1 y(n) -4 -0.30 Transposed of canonical form. Consider case A.9 x(n) y(n)= 9x(n)+v1 (n) v1 (n + 1)= v2 (n) v2 (n + 1)= −4x(n)−0.32 Case A of Problem 7. The I/O difference equations are in this case: x(n) 3 v00 (n) v01 (n) z-1 x1(n) 3 v10 (n) v11 (n) z-1 y(n) x1 (n)= 3x(n)+v01 (n) v01 (n + 1)= −4x(n)+0. and any other.28 Problem 7. P7.32 Then.31.25y -0.84y + v3 = v4 = 4x − 0. closed-loop.4y(n)+v12 (n) v12 (n + 1)= 2x1 (n)−0.5x1 (n) y(n)= 3x1 (n)+v11 (n) v11 (n + 1)= 4x1 (n)−0. the adder and filtering equations are in the time and z domains: e(n) = x(n)+f (n) g(n) = e(n − 1) y(n) = h1 (n)∗g(n) f (n) = h2 (n)∗y(n) ⇒ E(z) = X(z)+F(z) G(z) = z−1 E(z) Y(z) = H1 (z)G(z) F(z) = H2 (z)Y(z) 144 145 . 4v(n − 1) e(n) = x(n)+f (n) w(n) = 0.4 v(n-1) 0. The difference equations and sample processing algorithm. are: for each input sample x do: e=x+f w 0 = 0 .4z−2 H(z)= 1 − 1.5z 1 − 0. written in the right computational order. the overall transfer function remains the same. we would have e(n)= x(n)+f (n).6z−1 − 0. 5w 1 + e y = w0 + w1 v 0 = 0. Problem 7.4(v0 − v1 ) (update delays) f1 = f0 w1 = w 0 v1 = v 0 w(n) w0 -1 z w1 0.29.4z−1 v(n) = 0.4v(n)−0. If this delay were not there. 4 v 1 + y f0 = 0.4v(n − 1)+y(n − 1) f (n) = 0.4 v(n-1) 0. The change causes a re-ordering of the computational cycle. Now. 1 − 0. we assign internal state variables as shown in Fig.4(v0 − v1 ) H1 (z)= 1 + z−1 .4(1 − z−1 )z−1 1 + z−1 1− · −1 1 − 0.5z−1 H2 (z)= z−1 0. the start of the computational cycle is v(n)= 0. P7. The difference equations and corresponding sample processing algorithm are now: for each input sample x do: v0 = 0.33 Case A of Problem 7.4 v(n) y(n) f1 f(n-1) z-1 z−1 H1 (z) H(z)= 1 − z−1 H1 (z)H2 (z) Case B has the same transfer function H(z). which is not possible because f (n) is not yet Fig.4 Notice how the extra delay factor z−1 in H2 (z) delays the output f (n) and allows the start of the computational cycle with e(n)= x(n)+f (n − 1).5w(n − 1)+e(n) y(n) = w(n)+w(n − 1) v(n) = 0.4z−1 1 + 0.4v1 + y1 f = 0.4 v(n) y(n) y(n-1) y1 z-1 f(n) v0 z-1 v1 -0.34.29.28 and the individual transfer functions: In case B.5 w(n-1) f0 f(n) 0.4v(n)−0.4z−3 In case A. P7.Eliminating F(z) and E(z) in favor of X(z) and Y(z) gives: x(n) e(n) Y(z)= z−1 H1 (z)E(z)= z−1 H1 (z) X(z)+F(z) = z−1 H1 (z) X(z)+H2 (z)Y(z) and 1 − z−1 H1 (z)H2 (z) Y(z)= z−1 H1 (z)X(z) Solving for the closed-loop transfer function H(z)= Y(z)/X(z).4 H(z)= 1− z−1 H H1 (z) 1 (z)H2 (z) computed. The output f (n) is computed last.5 w(n-1) 0. we find: w(n) w0 z-1 w1 0.5w(n − 1)+e(n) y(n) = w(n)+w(n − 1) H1 (z) = H(z)= 1 − H1 (z)H2 (z) which gives 1 + z−1 1 − 0.29 The overall transfer function of this system can be computed using the results of Problem 7.4(1 − z−1 ) 1 − 0. Cases C and D have: v0 z-1 v1 -0. shown in Fig.4v(n − 1) e = x + f1 w 0 = 0 . P7.2z−2 + 0.4v(n − 1)+y(n) f (n) = 0. where both quantities 146 147 .5z−1 0. P7.3z−1 + 0.33.5 w 1 + e y = w0 + w1 y1 = y (update delays) w1 = w0 v1 = v0 x(n) e(n) e(n) = x(n)+f (n − 1) w(n) = 0. Fig.4v(n − 1)+y(n − 1).34 Case B of Problem 7. y(n − 3): 148 149 . δ(n − 2).30 The filter G(z) can be implemented by the input/output sample processing algorithm of its canonical form: for each x do: y = 0. v2 are the input impulse and its delays: δ(n). y(n − 1). Identifying the proper input and output to the filter G(z) and using the above sample processing algorithm. v0 u2 Fig. w. Fig. w) The following table shows the initialization and steady part of the linear buffer case. v).1. δ(n − 1). y(n − 2).30. 1. if the input is a unit impulse so that x = 1 at the first iteration of the algorithm and zero for all other iterations. P7. Their sample processing algorithms are: for each input x do: for each input x do: w1 = u y = v0 = x + u delay(4. p. The w-columns are the successively delayed output signals y(n).1 Problem 7. From then on. P7. Chapter 8 Problems Problem 8. Note that y(n) is computed last and then put into the feedback delay to be used in the next time step.2 u 2 + 0 . 2 x + 0. v) y = u 0 = x + v2 v 0 = 0 .1.35 Feedback systems of Problem 7. w2 . w3 of the next row.35 shows the three cases with explicitly assigned signal labels. that is. The columns v0 . in the time. delay(2. 8w 1 for each x do: for each x do: z−1 + 2z−2 1 − z−3 The direct and canonical realizations are shown in Fig. v1 . then the first three iterations will fill the feedback delay buffer w with the desired waveform samples.8y(n − 1). u) v0 = x y = w0 = v 1 + 2 v 2 + w 3 delay(2. giving rise to the following generation algorithm. & p) w0 = w 3 delay(3.2x(n)+0. 2v 4 + 0. P8.1 Direct and canonical realizations of Problem 8. v) y = x + v4 v 0 = 0. w) w0 = x + w 3 y = w 1 + 2w 2 delay(3. 8 w 1 The transfer function is obtained by the period-3 repetition of the sequence b(n)= [0. w. 8 w 1 w 1 = v0 delay(4. the feed-forward part of the algorithm will be zero. w1 (n)= y(n − 1) in the difference equation: y(n)= 0. we obtain the implementation of the three cases: for each x do: u = 0 . that is. 2]. 3) cdelay(3. expressed in its of the linear and circular buffer versions: repeat forever: repeat forever: ∗p = tap(3. At each iteration. 8 w 1 w 1 = v0 delay(2.v(n − 1) and y(n − 1) are available from the previous time step. w0 is replaced by the value of w3 and only then is the row of w’s shifted to the right to give the values of w1 .and z-domains: h(n) = b(n)+b(n − 3)+b(n − 6)+ · · · H(z) = B(z)+z−3 B(z)+z−6 B(z)+ · · · = B(z) 1 − z−3 = w1 = y where w1 is its internal state. For the direct form realization. v) delay(3. 2 y + 0. P8. w) x v0 z-1 v1 w0 z-1 w1 z-1 2 y x w0 z-1 w1 z-1 w2 w3 z-1 2 y (a) (b) (c) x z -4 y v0 u G(z) x v4 z -4 y x v2 z-2 G(z) u0 z-2 y z-1 w2 w3 z-1 v2 v4 v0 G(z) Fig. Thus.2 Expanding the denominator in powers of z−5 . −5].2. w) for each input x do: n 0 1 2 3 4 5 q 0 5 4 3 2 1 w0 = x + w5 y = w 0 + 2w 1 + 3 w 2 − 4 w 3 − 5 w 4 delay(5. −4. 3. The direct and canonical realizations are shown in Fig. P8. w) w0 1↑ 1 1 1 1 1 w1 0 0 0 0 0 1↑ w2 0 0 0 0 − 5↑ −5 w3 0 0 0 − 4↑ −4 −4 w4 0 0 3↑ 3 3 3 w5 0 2↑ 2 2 2 2 y 1 2 3 −4 −5 1 The steady parts of the linear and circular buffer generation algorithms are: repeat forever: repeat forever: ∗p = tap(5. Their sample processing algorithms are: for each input x do: The circular version is given in the following table. will cause the period-5 replication of the numerator sequence b = [1. 5) cdelay(5. 2. & p) w0 = w5 delay(5. The buffer entry that contains the current output sample is shown with an up-arrow symbol and it corresponds to the entry wq defined by the circulating value of q: v0 = x w0 = v0 + 2v1 + 3v2 − 4v3 − 5v4 + w5 y = w0 delay(4.2 Direct and canonical realizations of Problem 8. w) 150 151 . w. p. n 0 1 2 3 q 0 3 2 1 w0 ↑0 0 0 0 w1 0 0 0 ↑0 w2 0 0 ↑2 2 w3 0 ↑1 1 1 y 0 1 2 0 n 4 5 6 7 q 0 3 2 1 w0 ↑1 1 1 1 w1 0 0 0 ↑1 w2 2 2 ↑0 0 w3 1 ↑2 2 2 y 1 2 0 1 The following table shows the initialization and steady parts of the linear buffer case: n 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 v0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 v1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 v2 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 v3 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 v4 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 w0 1 2 3 −4 −5 1 2 3 −4 −5 1 2 3 −4 −5 w1 0 1 2 3 −4 −5 1 2 3 −4 −5 1 2 3 −4 w2 0 0 1 2 3 −4 −5 1 2 3 −4 −5 1 2 3 w3 0 0 0 1 2 3 −4 −5 1 2 3 −4 −5 1 2 w4 0 0 0 0 1 2 3 −4 −5 1 2 3 −4 −5 1 w5 0 0 0 0 0 1 2 3 −4 −5 1 2 3 −4 −5 y 1 2 3 −4 −5 1 2 3 −4 −5 1 2 3 −4 −5 n 8 9 10 11 q 0 3 2 1 w0 ↑2 2 2 2 w1 1 1 1 ↑2 w2 0 0 ↑1 1 w3 2 ↑0 0 0 y 2 0 1 2 n 12 13 14 15 q 0 3 2 1 w0 ↑0 0 0 0 w1 2 2 2 ↑0 w2 1 1 ↑2 2 w3 0 ↑1 1 1 y 0 1 2 0 The table entries circulate every D(D + 1)= 12 iterations.x n 0 1 2 3 4 5 6 7 8 v0 z-1 v1 z-1 v2 v3 v4 z-1 z-1 2 3 -4 -5 w0 z-1 w1 z-1 w2 w3 w4 w5 z-1 z-1 z -1 y x w0 z-1 w1 z-1 w2 w3 w4 w5 z-1 z-1 z -1 y 2 3 -4 -5 v0 1 0 0 0 0 0 0 0 0 v1 0 1 0 0 0 0 0 0 0 v2 0 0 1 0 0 0 0 0 0 w0 0 1 2 0 1 2 0 1 2 w1 0 0 1 2 0 1 2 0 1 w2 0 0 0 1 2 0 1 2 0 w3 0 0 0 0 1 2 0 1 2 y = w0 0 1 2 0 1 2 0 1 2 The circular version is given in the following table. w.2. entry n = 3 and n = 15 will be the same. We used 15 iterations because they contain one complete cycle of the table entries after the first 3 initializing iterations. The buffer entry that contains the current output sample is shown with an up-arrow symbol and it corresponds to the entry wq defined by the circulating value of q: Fig. P8. v) delay(5. Problem 8. b1 . q1 . Thus. q3 .Problem 8. q2 . w[1] = [b0 . q3 . w[4]. 7. The five q-arrows are now at relative angles ω = 2π/5. b2 . q1 .36): q0 = 0 q1 = q0 − c = − q2 = q1 − c = 2 8 8 32 ≡8− = =6 5 5 5 5 4 32 8 24 − = =4 5 5 5 5 1 24 8 16 − = =3 5 5 5 5 3 16 8 8 − = =1 5 5 5 5 n 12 13 14 15 16 17 q 0 5 4 3 2 1 w0 3↑ 3 3 3 3 3 w1 2 2 2 2 2 3↑ w2 1 1 1 1 2↑ 2 w4 −4 −4 − 5↑ −5 −5 −5 w4 −5 −5 1↑ 1 1 1 w5 3 − 4↑ −4 −4 −4 −4 y 3 −4 −5 1 2 3 q3 = q2 − c = q4 = q3 − c = Fig. w[2] = [b0 . q4 ]= [0. b6 ] Rounding to the nearest integer gives: The table entries circulate every D(D + 1)= 30 iterations. q3 . q4 ]= [0. w[3]. 5. 3. w[3]. w[2] = [b0 . b2 . 2] w[0].1. b6 ] For the linear interpolation case. P8. we have the outputs: 152 153 . q2 . b4 . 6. b5 .3 n 6 7 7 9 10 11 q 0 5 4 3 2 1 w0 2↑ 2 2 2 2 2 w1 1 1 1 1 1 2↑ w2 −5 −5 −5 −5 1↑ 1 w3 −4 −4 −4 − 5↑ −5 −5 w3 −5 −5 −5 1↑ 1 1 w4 3 3 − 4↑ −4 −4 −4 w5 2 3↑ 3 3 3 3 y 2 3 −4 −5 1 2 The shift is c = D/d = 8/5 = 1. b5 . 2] w[0]. w[6]. 6. w[5]. entry n = 5 and n = 35 will be the same. 4. 1] w[0]. q1 . Down-truncation gives the following integer values for the q’s and corresponding buffer entries: [q0 .6. w[5]. w[7]. q4 ]= [0. (8. 4. [q0 . w[6]. b3 . b7 ] Up-truncation gives: n 30 31 32 33 34 35 q 0 5 4 3 2 1 w2 −4 −4 −4 −4 − 5↑ −5 w3 3 3 3 − 4↑ −4 −4 w4 2 2 3↑ 3 3 3 w5 1 2↑ 2 2 2 2 y 1 2 3 −4 −5 1 [q0 . We used 35 iterations because they contain one complete cycle of the table entries after the first 5 initializing iterations.3 shows the relative locations of the q’s with respect to the circular buffer. The d = 5 possible values of the offset index q are obtained by iterating Eq.3 Successive positions of q when d = 5. q2 . 5. q4 n 18 19 20 21 22 23 q 0 5 4 3 2 1 w0 − 4↑ −4 −4 −4 −4 −4 w0 − 5↑ −5 −5 −5 −5 −5 w0 1↑ 1 1 1 1 1 w1 3 3 3 3 3 − 4↑ w2 2 2 2 2 3↑ 3 w3 1 1 1 2↑ 2 2 w5 −4 − 5↑ −5 −5 −5 −5 w5 −5 1↑ 1 1 1 1 y −4 −5 1 2 3 −4 q3 w 3 b5 w4 b 4 q 2 w5 b3 w2 b6 b7 w1 q0 b 0 w0 b2 w6 b1 w7 q1 n 24 25 26 27 28 29 q 0 5 4 3 2 1 w1 −4 −4 −4 −4 −4 − 5↑ w1 −5 −5 −5 −5 −5 1↑ w2 3 3 3 3 − 4↑ −4 w3 2 2 2 3↑ 3 3 w4 1 1 2↑ 2 2 2 y −5 1 2 3 −4 −5 Fig. w[4]. 3. P8. b4 . b3 . w[4]. . 6. y0 . y4 . ] [b0 . b0 . P8. w[5]. b6 . The d = 6 possible values of the offset index q are obtained by iterating Eq. b5 . depending on the output method. . y1 . b3 . ]= [1. . b5 . b5 . b2 . b5 . y2 . b3 . ] where the y’s were given above.2. b2 . . b2 . b4 . b1 . b3 . b0 . (8. The six q-arrows are now at relative angles ω = 2π/6. 1] w[0]. . b4 . 5. b7 . q3 . 8. q5 ]= [0. 2] w[0]. q1 . b0 . q3 . b2 .4 The shift is c = D/d = 8/6 = 4/3. . b3 . y4 . .4 shows the relative locations of the q’s with respect to the circular buffer. b3 . we have for the cases of truncating down. y0 . 4. w[2]. . q1 . 1. b1 . q2 . q2 . b6 . b7 . b3 . 5. b4 . . ] [b0 . 7. w[1] = [b0 . the following period-5 subsequences will be produced: Fig. w[3]. 4.1. b5 . b3 . Referring to Fig. b2 . 7.1. . b7 . b3 . 3. b2 . w[4]. .14. b4 . b3 . ]= [1. . b0 . 6. 4. . b3 . b4 . q2 . b5 . b6 . 3. . b5 . y1 . b7 . y3 . b0 . b7 ] For the linear interpolation case. . w[1] = [b0 . b6 . (truncate down) (truncate up) (round) (interpolation) Rounding to the nearest integer gives: [q0 . b3 . w[2] = [b0 . 4. b6 . b2 .q4 q0 = 0 6 < q1 < 7 4 < q2 < 5 3 < q3 < 4 1 < q4 < 2 q5 b5 w2 b6 b7 w1 q0 ⇒ y0 = w[0]= b0 2 3 ⇒ y1 = w[6]+(q1 − 6)(w[7]−w[6])= b1 + b2 5 5 w3 q3 w4 b 4 w5 q2 b3 ⇒ y2 = w[4]+(q2 − 4)(w[5]−w[4])= 4 1 b3 + b4 5 5 b 0 w0 b2 w6 b1 w7 q1 1 4 ⇒ y3 = w[3]+(q3 − 3)(w[4]−w[3])= b4 + b5 5 5 ⇒ y4 = w[1]+(q4 − 1)(w[2]−w[1])= 3 2 b6 + b7 5 5 Thus. w[7]. ] [y0 . b4 . (truncate down) (truncate up) (round) (interpolate) [q0 . b2 . b7 . . b6 . the following period-5 subsequences will be produced: Fig. q1 . y1 . [b0 . . 1] w[0]. b5 .36): q0 = 0 6 < q1 < 7 5 < q2 < 6 2 20 4 4 ≡8− = =6 3 3 3 3 ⇒ y0 = w[0]= b0 ⇒ y1 = w[6]+(q1 − 6)(w[7]−w[6])= ⇒ y2 = w[5]+(q2 − 5)(w[6]−w[5])= ⇒ y3 = w[4]= b4 ⇒ y4 = w[2]+(q4 − 2)(w[3]−w[2])= ⇒ y5 = w[1]+(q5 − 1)(w[2]−w[1])= 2 1 b5 + b 6 3 3 1 2 b6 + b 7 3 3 2 1 b1 + b 2 3 3 1 2 b2 + b 3 3 3 q0 = 0 q1 = q 0 − c = − q2 = q 1 − c = q3 = q 2 − c = q4 = q 3 − c = q5 = q 4 − c = q3 = 4 2 < q4 < 3 1 < q5 < 2 1 20 4 16 − = =5 3 3 3 3 16 4 12 − = =4 3 3 3 2 12 4 8 − = =2 3 3 3 3 1 4 4 8 − = =1 3 3 3 3 Thus. b1 . b5 . y4 . 4. . y2 . b4 . b6 . 2. 6. q4 . b6 . b7 . 6. w[6]. and rounding: [q0 . b2 . w[5]. y4 . q5 ]= [0. ] (truncate down) (truncate up) (round) 154 155 . y5 . . P8. . . b4 . . . . b5 . w[7]. y3 . b7 ] Up-truncation gives: Problem 8. q5 ]= [0. q3 . ] [b0 . y3 . y2 . 4. b1 . ] where the y’s are given above. 4. b6 . b1 . b1 . . b4 . . b1 . 3. . we have the outputs: Problem 8. ] [b0 . y3 . 6. ] [y0 . . w[4]. b3 . 7. . . . Down-truncation gives the following integer values for the q’s and corresponding buffer entries: [b0 . y5 . b4 . q4 . b0 . b3 . b4 .5 This problem is similar to Example 8. b4 . depending on the output method. . . up. . b2 . . b6 ] [b0 . 7. b6 . b0 . 3. 1. b0 . b0 . b5 . b2 . . ] [b0 . b2 . y1 . q4 .4 Successive positions of q when d = 6. y2 . b5 . . b5 . b5 . b1 . . w[6]. b4 . . . 6.1. b3 . . 1. b6 . ]= [1. . ] [b0 . w[3]. . A. . b3 .2.667.h> #include <math. } for (n=0. . n<D. 4.6 This problem is similar to Problem 8. F. we get the sequence: y0 = b0 = 1 y1 = y2 = 1 2 1 2 11 b2 + b3 = 3 + 4 = = 3. ]= [1. 5. sizeof(double)).9 The zero patterns and magnitude responses |H(ω)| of the four filters are shown in Fig. . ] [b0 . w1 = (double *) calloc(D. 1. w3. . . n.6. b4 . 4. so that the period-3 sequence is: [1. 3. ]= [1. b7 ]= [1. 3. for (i=0. A. 7. F. . w3 = (double *) calloc(D. F = c / D.8.c .dat". D = atoi(argv[3]). The first filter has H(z)= 1 + z−8 . b2 . 2. . Inserting the numerical values for the wavetable contents: b = [b0 . 6. . Problem 8.0. fprintf(fp2.7 An example program that exercises the wavetable routines is listed below. 2. c. 1. sizeof(double)). 1. i). . double wavgen(). square wave. .8 5 5 5 5 3 2 3 2 b 6 + b 7 = 7 + 8 = 7 . and trapezoidal. } A = atof(argv[1]). F. b1 . } Problem 8. y4 . F=c/D\n"). c = atof(argv[2]). &q3). 1. . w1. fprintf(stderr. A. fp2 = fopen("y2. 8. 3. 6.If we interpolate linearly. 7 . q3. i<D.3. wavgen(D. Problem 8. . if (argc != 4) { fprintf(stderr. "c = no. q1.4. ] where (truncate down) (truncate up) (round) (interpolation) fp1 = fopen("y1. 3.4. b6 . *fp2. gdelay2(D-1. "%lf\n". i++) { w1[q1] = sine(D.667. b6 .8 Partial C code for this problem was given in the text. "w").20 and 8. Problem 8. Therefore.9. 6. .dat". &q2). of periods in D samples.dat".1. . y2 . . FILE *fp1.h> #include <stdlib. ] "usage: wavgenex A. ]= [1. 6. "%lf\n". ] [y0 . fprintf(stderr. A. 3*D/4. 7. w3[q3] = trapez(D. "D = wavetable size\n"). *w2.667. just before Figs. .6 5 5 5 5 4 1 4 1 b 3 + b 4 = 4 + 5 = 4 . wavgen(D. 8] we find for the period-5 sequences: [b0 . n++) { fprintf(fp1. "%lf\n". its zeros are the solutions of: 156 157 . . sizeof(double)). "A = wavetable amplitude\n"). gdelay2(D-1. ] [b0 . i). 7. fprintf(fp3. 3. double *w1. b4 . 8. b4 . b1 . . /* wavgenex. . 4. 5. &q2)). . square(). q2. . w2[q2] = square(D/2. trapez(). &q1). . q2 = 0.21. b2 . 4. q1 = 0.1. } /* load wavetables */ /* might need the cast w1[(int)q1] */ y0 = b 0 = 1 y1 = y2 = y3 = y4 = 2 3 2 3 b 1 + b 2 = 2 + 3 = 2 .0. double sine(). &q3)). c. b7 . b2 . ]= [1. b5 . 7. . y3 . *fp3.0. b5 . fp3 = fopen("y3. *w3. b5 . 3. fprintf(stderr.667.667 3 3 3 3 3 1 2 1 2 20 b5 + b6 = 6 + 7 = = 6. . . b6 . D. char **argv) { int i. q3 = 0. w2.4 5 5 5 5 The case d = 6 is similar to Problem 8. y1 . "w").h> void gdelay2(). 5. F. It generates three wavetables: sinusoidal. D\n"). b3 .circular wavetable example */ #include <stdio. "w"). wavgen(D. exit(0). 2.667 3 3 3 3 3 void main(int argc. w2 = (double *) calloc(D. i). 0. 5. &q1)). gdelay2(D-1.2 5 5 5 5 1 4 1 1 b 4 + b 5 = 5 + 6 = 5 . *p = y. P8. /* u1 is 2-dim */ /* mean = D/2 */ /* mean = 1 */ /* input x(n) */ /* delay x(n-d1) */ /* output */ /* update delay */ /* declaration of fpx */ 158 159 . . cdelay(D.z8 = −1 = ejπ e2πjk ⇒ zk = ejπ/8 ej2πk/8 . P8. its zeros are the 8th roots of unity. p.5o . w. d/D). 2*d1/D). &iseed2)). y). For the double chorus case. w. &iseed4). but among them the roots of the denominator 1 + z−8 must be excluded. Fig. xd1 = tapi(D.h> #include <stdlib.50 * D * (1 . u1. fprintf(fpx. Similarly. d2). a1 = 1 + ranl(Dran. y = a * yd + x. P8. we have the code fragment: |H(ω)| 2 2 3 3 2π ω 2π ω 2π ω 2π ω Fig.5 + ranl(Dran. For the recursive flanger. a2 = 1 + ranl(Dran. "%lf\n".9. x). This results in 16 zeros. fprintf(fpx.5 Comb filters of Problem 8. "%lf\n". we have the code segment: for (n=0. . "%lf\n". double *w2. 1 . x = cos(2 * pi * F * n). d2 = D * (0. d). allpass. fprintf(fpy. x = cos(2 * pi * F * n). *p2. *p = x. . &iseed3). o k = 0.5 . x). &q3.h> double plain(). w. "%lf\n". the last filter’s zeros are the 24th roots of unity with the 8th roots of unity excluded. cdelay(D.6 Double chorusing of sinusoidal signal.11 is given in the text. The second filter has H(z)= 1 − z−8 and thus. a1). y = (x + a1 * xd1 + a2 * xd2) / 3. fprintf(fpa. p. u2. y). 8.2. fprintf(fpd. &q1. &p). 7 That is. xd2 = tapi(D. w. &iseed1)).10 Typical C code for generating Fig. n<Ntot.5 + ranl(Dran. char **argv) { double *w1. n<Ntot. "%lf\n". allpass(). n++) { d = 0. using the finite geometric series: H(z) = 1 − z−8 + z−16 = H(z) = 1 + z−8 + z−16 = 1 + z−24 1 + z−8 1 − z−24 1 − z−8 for (n=0. u4. fprintf(fpy.7. . &q4. } /* is not shown */ Typical output is shown in Fig. } /* yd is y(n-d) */ The third has roots the 24th roots of unity shifted by π/24 = 7.2.6. u3. void main(int argc. *p1. &p). P8.9 and 8.plain. the 8th roots of unity rotated by π/8 ≡= 22. and lowpass reverb */ #include <stdio. yd = tapi(D. n++) { d1 = D * (0.c . "%lf\n". w. p.11 A typical program is as follows: /* reverb. Problem 8.h> #include <math. Problem 8.cos(2 * pi * Fd * n)). Typical output for D = 100 and D = 10 is shown in Fig. fprintf(fpd. d1). "%lf\n". The third and fourth filters can be written as follows. lowpass(). &q2. x. y1). y. y3. fpy = fopen("y.5}. *fp3.75. sD. double x. sizeof(double)). &p1. *p3. w3.dat". a. double v[2] = {0. double y1. *p4. -0. double b[2] = {0. w1. allpass(). Ntot = atoi(argv[2]). y5. x). fp3 = fopen("y3. n. y3.12 A typical program is as follows: Fig. for (n=0.75 . n. Ntot. y2. } D = atoi(argv[1]). w3. double a0 = 0.h> #include <stdlib. y2).7 Recursive flanger. y3). double *w6.h> use D=20.75 . *p3. sizeof(double)).75 . (double *) calloc(D+1. fp1 = fopen("y1.. *p6. double *w3. *p1. "w"). FILE *fpy. *p2. n++) { triangular pulse if (n<=5) x=n. /* reverb.75 .Schroeder’s plain/allpass reverb system */ #define #define #define #define #define #define #define #define #define #define #define #define D1 D2 D3 D4 D5 D6 a1 a2 a3 a4 a5 a6 29 37 44 50 27 31 . sizeof(double)). y2 = allpass(D. "%lf\n". fprintf(fp3. x). Ntot=100 double plain(). *p5. fprintf(fp1. b. a0. int Ntot=500. "w").dat". "usage: reverb D Ntot"). 160 161 .c .15}. int D. sizeof(double)). else x=0. n<Ntot. *fp2. "w"). w1. if (argc != 3) { fprintf(stderr. y1. w1 = (double *) calloc(D1+1. v. w1 p1 w2 p2 w3 p3 = = = = = = (double *) calloc(D+1. double *w2. } } Problem 8. else if (n<=10) x = 10-n.3. void main() { double *w1. x). FILE *fp1. &p3. fp2 = fopen("y2. y2. (double *) calloc(D+1. p1 = w1.y1 = plain(D. 0. P8. a0. exit(0). w2.dat". &p2. fprintf(fp2. y4. 0. sizeof(double)). "w").}. M. double *w5.75 . M=1. double a[2] = {1. "%lf\n". w2. y3 = lowpass(D.75 double *w3. "%lf\n".h> #include <math. #include <stdio. double *w4.dat". w2 = (double *) calloc(D2+1. } } Problem 8. w5. w2. *fp2. double double double int D. double v[2] = {0. w6 = (double *) calloc(D6+1. a5. impulse Problem 8. &p6. w4 = (double *) calloc(D4+1. L=150.15}.29.7*y4. w6. v0 = sD − a1 v1 u = b 0 v0 + b 1 v 1 v1 = v0 y =x+u ∗p = y cdelay(D. = 0.14 The response to a causal sinusoid will be of the form: D+1 ejωn u(n)− H(ω)ejωn u(n)+ → i=1 Bi pn u(n) i where Bi = Ai pi /(pi − ejω ). y = allpass(D6. double a[2] = {1. void main(int argc. = 4*atan(1. *p1. y). sizeof(double)). w3.p2 = w2.c .3. p3 = w3.2pi. double *w2. n++) { if(n==0) x = 1. pi L. y). D+1 y(n)= H(ω)ejωn u(n)−u(n − L) + i=1 Bi pn u(n)−ejωL p−L u(n − L) i i y = y1 + 0. char **argv) { double *w1. a1. a6. lowpass(). p4 = w4. y1. *p2. y2. &p2.h> Problem 8. &p3. p.. x). D) double plain().15 A typical C program that utilizes the routines plain and lowpass is given below: /* reverbex.75. w=pi * */ #include <stdio.5}. p5 = w5. a0 w. a4. plain(D3.8*y3 + 0. we find that the response to the finite sinusoid: x(n)= ejωn u(n)−u(n − L) is x). &p4. else x = 0. double b[2] = {0. sizeof(double)). w1. &p5. & p) FILE *fp1. 0. plain(D4. n. -0. y1 y2 y3 y4 = = = = plain(D1.}. y5).9*y2 + 0. 162 163 . w3 = (double *) calloc(D3+1.0). N.plain and lowpass reverberation of sinusoid */ * * run with: * D=300.h> #include <stdlib. It follows that the response to a delayed sinusoid will be: D+1 ejω(n−L) u(n − L)− H(ω)ejω(n−L) u(n − L)+ → i=1 Bi pn−L u(n − L) i Multiplying both sides by the factor ejωL and subtracting from the undelayed result. "%lf\n". plain(D2. x. x). w.h> #include <math. sizeof(double)). M=1. sD. n<Ntot. a3. y5 = allpass(D5. p6 = w6. w5 = (double *) calloc(D5+1. w. w4. a2. fprintf(fpy. as shown in Problem 6.13 The difference equations are: v(n) = y(n − D)−a1 v(n − 1) u(n) = b0 v(n)+b1 v(n − 1) y(n) = x(n)+u(n) The corresponding circular version of the sample processing algorithm is for each input x do: sD = tap(D. &p1. 0. for (n=0. N=300. sizeof(double)). w=0. x). h> #include <math. y1). 164 165 . n++) { if (n < L) x = cos(pi*w*n). x). if j ~= i. w1. end #include <stdio.dat".fp1 = fopen("ypl. iseed=1234567 D=50. a0. "%.dat". w. D) % calculate y(n) for a finite-duration sinusoidal input. x). if (n<L).16lf\n". D) % returns poles and residues of lowpass reverberator (delay D) % [p. D) % % b=[b(1).p(j)). M. fprintf(fp2. the following MATLAB function calculates the residues Bi and computes N samples of the output signal y(n): function [y. end end end for (n=0. end else y(n+1) = 0. lowpass(). w2. Using the MATLAB function lprevb. b(2)] % a=[1. iseed=1234567 c = [a. b. void main(int argc. y(n+1) = y(n+1) + B(i) * p(i)^n. A] = yon(N.. y2). in units of pi w1 p1 w2 p2 (double *) calloc(D+1. (double *) calloc(D+1. D). *p. else x = 0. y(n+1) = H * z^n. w2. sinusoid on for L samples y1 = plain(D. a. p=roots(c). end for n=0:N-1. &p1.h> double ran(). y2 = lowpass(D.D-2). [p.z^(-D) * (b(1) + z^(-1)*b(2)) / (1 + a(2)*z^(-1))). n<N. p. } } Problem 8. a. "w"). "w").m given below. exit(0). for i=1:D+1. a. double v[2] = {0. Ntot=500. fp2 = fopen("ylp. y(n+1) = y(n+1) + B(i) * p(i)^n * (1 .0}. zeros(1.16 A typical C program is as follows: The analytical expression for y(n) can be obtained as follows. char **argv) { double *w. A] = lprvb(b. sizeof(double)). double a[2] = {1. A(i) = 1 + a(2) / p(i). A(i) = A(i) * p(i) / (p(i) .h> #include <stdlib. Ntot=500. atoi(argv[3]). z = exp(j * w). we determine the poles pi and residues Ai of the transfer function: function [p. -b]. A] = lprvb(b. &p2. H = 1 / (1 .Karplus-Strong String Algorithm */ run with: D=25.16lf\n". v. A] = lprvb(b. = = = = end end Then. atof(argv[4]). for i=1:D+1. for i=1:D+1. "%. 0. atoi(argv[2]). if (argc != 5) { puts("usage: reverbex D L N w\n\n" "D = delay period\n" "L = time to turn off input\n" "N = total duration of input \n" "w = in units of pi \n"). for j=1:D+1. a. L.}. sizeof(double)). w1. a.c . } D L N w = = = = atoi(argv[1]). for i=1:D+1.z). 0. a(2)] /* * * * * * /* karplus.z^L / p(i)^L). b. fprintf(fp1. B(i) = A(i) * p(i) / (p(i) . P8. w. The sample processing algorithm is in its linear and circular buffer forms: for each input x do: sD = tap(D. n++) { y = lowpass(D. *b. y. iseed = atol(argv[2]). *a. can(). P8. M=1. fpy = fopen("y. The C routines are: /* plaindel. a.a. sizeof(double)). w. w = (double *) calloc(D+1. w. w. v. a. } } initialize w(n) = aw(n − D)+x(n) y(n) = cx(n)+bw(n − D) c w0 wD b x z -D a y Fig.5}. & p) Problem 8. *p. x.&p.double b[2] = {0.w. n.0).x). p.16lf\n". double plaindel(D. D). y). "%. void cdelay(). w. v. b. **p. 0.9 Prototypical delay effect. a. p.0. y = tap(D. { double y.18 The block diagrams and sample processing algorithms are essentially given in Section 8. b.plain reverberating delay */ double tap(). /* lpdel. "usage: karplus D Ntot iseed"). 0.dat".17 A block diagram realization is given in Fig. } D = atoi(argv[1]). M.5. x) double *w. p is passed by address The output signals corresponding to D = 25 and D = 50 are shown in Fig.c . n<=D. Problem 8. } usage: y=plaindel(D. **p. return y.c . n++) w[n] = ran(&iseed) . p). w. w. P8. *v.8. x) double *w. exit(0). Ntot. a. Ntot = atoi(argv[2]).2. long iseed.5.9. cdelay(D.4. double x. int D. fprintf(fpy. if (argc != 4) { fprintf(stderr. &p. M. for (n=0. D) for each input x do: y = cx + bwD w0 = awD + x delay(D. "w"). for (n=0. x. **p = x + a * y.8 Karplus-Strong string algorithm outputs. p. int D. void cdelay(). The difference equations are the system: double lpdel(D. D-th tap delay output delay input update delay line Fig. w) x=0 y = cx + bsD ∗p = asD + x cdelay(D. FILE *fpy. n<Ntot.lowpass reverberating delay */ double tap(). 166 167 . P8. Note how the initial random numbers get smoothed at each D-cycle resulting in a decaying quasi-periodic signal tuned to the frequency f = fs /D. p = w. M. x). s[1] = tap(D1+D2. sizeof(double)). b. 0. y). 0. return y.15}. /* lowpass */ /* output */ where the initializations are: double x. /* /* x1 = lpdel(D1. **p = s[0]. x).}. *w2. b. s[0] = x + a[1] * s[1] + a[2] * s[2]. double b[3]. w2.c . a. x2 = plaindel(D2. D2. P8. w. y. } /* plain */ Fig. } D-th tap delay output delay input update delay line The routines differ from plain and lowpass in that the filter outputs are taken after the delay z−D .3. p. n<Ntot. b1=0. D2.6 a0 = 0. **p. v2[2] = {0. y). b.10. *w.11 and is obtained by the code segment: for (n=0. w. else x = 0. void cdelay(). a.. we have: 168 169 . x).75. p). */ x2 = lpdel(D2. /* p passed by reference */ Typical output is as in Fig. x). **p = x + can(M. &p1. b0=1. { double y. *p. n<Ntot. p). P8. &p. a. x.21 From the pole equation. a[3]. } /* use L=1 or L=200 */ w1 = (double *) calloc(D1+1. /* /* /* /* /* /* state of LP filter 1 */ state of LP filter 2 */ G(z) denominator */ G(z) numerator */ feed-forward coefficients */ feedback for plain delay */ p1 = w1. a.5}. *w1. w1. *p. fprintf(fpy. 1. Problem 8. w2. &p1.8lf\n". cdelay(D. D1). return y. b. b. instead of before. s[2] = tap(D1+D2. x) int D1. { double s[3]. w2 = (double *) calloc(D2+1. D2. a0. w.multi-tap delay line */ double tap(). n++) { if (n<L) /* use if (n<1) for impulse response */ x = 1. } Typical output is shown in Fig.16lf\n". v. x1). fprintf(fpx. D). x1 = plaindel(D1. w. double mlttap(D1. x2. It can easily be generalized to more than two multitap delay segments: Problem 8. *p2. &p2. -0. v2. "%. &p2.int D. n++) { if (n < L) x = 1. p2 = w2..19 Typical C code for this problem is: for (n=0.16lf\n". w. a. w. Problem 8. D1+D2). x). cdelay(D1+D2.8. y). b[2] = {0. fprintf(fpy.}. else x = 0. y = b[0] * x + b[1] * s[1] + b[2] * s[2].8lf\n". "%. */ y = b0 * x + b1 * x1 + b2 * x2.10 Multi-delay effects processor outputs. fprintf(fpx. "%. /* mlttap. *p. 0. double double double double double double v1[2] = {0. sizeof(double)). "%. a[2] = {1. y = tap(D. b2=0. v1. a0. x1. x1). w1.20 The sample processing routine is as follows. y = mlttap(D1. P8. y. *p1. w. 1. the outputs of these delays will be z−L WL (z) and z−R WR (z). For the case GL (z)= aL . we would have: HLL (z) = cL + HLR (z) = 0 HRL (z) = bL z−L 1 − z−L GL (z) |z|D1 +D2 ≥ |z|D2 > |a1 ||z|D2 + |a2 ||z|D2 ≥ |a1 ||z|D2 + |a2 | which contradicts Eq.11 Multi-Tap Delay Line. we get: YL (z) = HLL (z)XL (z)+HLR (z)XR (z) YR (z) = HRL (z)XL (z)+HRR (z)XR (z) 170 171 .1). P8. YR (z) in terms of XL (z). Thus. GR (z)= aR . . Denote the left and right delay-line buffers by wL = [wL0 . . wL1 . Thus. then using the inequality |a1 | + |a2 | < 1.where HLL (z) = cL + HLR (z) = HRL (z) = 1 1 D(z) 1 − z−R GR (z) bL z−L D(z) 1 dR bR z−L z−R dL bL z−R z−L 1 1 − z−L GL (z) bR z−R D(z) HRR (z) = cR + with Fig. . (P8. and let the corresponding delay outputs be sL and sR .22 Working in the z-domain and denoting by WL (z) and WR (z) the inputs to the delays z−L and z−R . the transfer functions simplify to: 1 − z−L GL (z) |z|D1 +D2 = |a1 zD2 + a2 | ≤ |a1 ||z|D2 + |a2 | If a pole had |z| ≥ 1. dL = dR = 0. . the I/O equations of the block diagram will be: 1 − z−R GR (z) dL bL z−L z−R 1 − z−L GL (z) HRR (z) = cR + The corresponding I/O system is then: bR z−R 1 − z−R GR (z) YL (z) = cL XL (z)+z−L WL (z) WL (z) = z−L GL (z)WL (z)+bL XL (z)+dR z−R WR (z) YR (z) = cR XR (z)+z WR (z) = z −R −R YL (z) = HLL (z)XL (z) YR (z) = HRL (z)XL (z)+HRR (z)XR (z) which means that the left channel responds only to the left input (it does not receive any crossfeedback from the right channel). . then the left and right channels decouple completely. . but the right channel responds to both the right input and the cross feedback from the left output.1) D(z)= 1 − z−R GR (z) and therefore. wR1 . we get: WL (z)= zL YL (z)−cL XL (z) . wRR ]= (R+1)-dimensional Let pL and pR be the circular pointers circulating over them. the sample processing algorithm is straightforward. we get the system: 1 − z−L GL (z) 1 − z−R GR (z) YL (z)−cL XL (z) − dR z−L YR (z)−cR XR (z) = bL z−L XL (z) YR (z)−cR XR (z) − dL z−R YL (z)−cL XL (z) = bR z−R XR (z) Solving for YL (z). If both cross-feedbacks are zero. . WR (z)= zR YR (z)−cR XR (z) Inserting them into the second and fourth. Then. D(z) D(z)= 1 − z−R GR (z) 1 − z−L GL (z) − dL dR z−L z−R For the special case when the cross couplings are dL = 0 and dR = 0. all poles must have |z| < 1. the computational sample processing algorithm will be: WR (z) −L GL (z)WR (z)+bR XR (z)+dL z WL (z) Solving the first and third for the Ws. Problem 8. . wLL ]= (L+1)-dimensional wR = [wR0 . we have: zD1 +D2 = a1 zD2 + a2 ⇒ (P8. responding independently to their respective inputs. XR (z). for each input pair {xL , xR } do: sL = tap(L, wL , pL , L) sR = tap(R, wR , pR , R) yL = cL xL + sL y R = c R xR + s R ∗pL = bL xL + aL sL + dR sR ∗pR = bR xR + aR sR + dL sL cdelay(L, wL , & pL ) cdelay(R, wR , & pR ) Problem 8.23 The sample processing algorithm is implemented by the C code segment: int L = 30, R = 70; double *wL, *wR, *pL, *pR; wL = (double *) calloc(L+1, sizeof(double)); wR = (double *) calloc(R+1, sizeof(double)); for (n=0; n<Ntot; n++) { if (n < P) xL = 1; else xL = 0; sL = tap(L, wL, pL, L); sR = tap(R, wR, pR, R); yL = cL * xL + sL; yR = cR * xR + sR; *pL = bL * xL + aL * sL + dR * sR; *pR = bR * xR + aR * sR + dL * sL; cdelay(L, wL, &pL); cdelay(R, wR, &pR); fprintf(fp1, "%.16lf\n", yL); fprintf(fp2, "%.16lf\n", yR); } pL = wL; pR = wR; Fig. P8.12 Stereo delays, with dL = dR = 0.3. /* use xR = 0 */ Fig. P8.13 Stereo delays, with dL = 0.3, dR = 0. } for (n=0; n<N; n++) { if (n < N/3) x = A1 * cos(w0 * n); else if (n < 2*N/3) x = A2 * cos(w0 * n); else x = A3 * cos(w0 * n); c = a * c1 + (1-a) * fabs(x); c1 = c; g = f(rho, c/c0); if (L > 1) G = fir(L-1, h, v, g); else G = g; y = G * x; /* use N = 600 */ /* generate input */ /* use w0 = 0.15 * pi */ Figures P8.12 and P8.13 show typical outputs. The left output does not start until n = L, therefore, the first right output will begin at n = L + R. That output will be fed back into the left and will come out at n = 2L + R. Similarly, the second left pulse at n = 2L will appear on the right at n = 2L + R, and so on. /* control signal */ /* update delay */ /* gain function */ Problem 8.24 The sample processing algorithm is implemented by the C code segment: if (L > 1) h = v = for { (double *) calloc(L, sizeof(double)); (double *) calloc(L, sizeof(double)); (n=0; n<L; n++) h[n] = 1.0 / L; /* L-point smoother */ /* gain smoothing */ /* no smoothing */ /* compressor output */ 172 173 fprintf(fpx, fprintf(fpy, fprintf(fpc, fprintf(fpg, } "%.16lf\n", "%.16lf\n", "%.16lf\n", "%.16lf\n", x); y); c); G); /* /* /* /* save save save save input */ output */ control */ gain */ where the compressor function is defined by f (x)= xρ−1 , for x ≥ 1: /* compressor function with 1:rho compressor ratio */ #include <math.h> double f(rho, x) double rho, x; { if (x >= 1) return pow(x, rho-1); else return 1; } Fig. P8.14 Expander output and gain with increased threshold. The compressing action takes place only above the threshold. For an expander, the gain function is defined as follows, where now ρ > 1, but it takes effect only below the threshold: /* expander gain function with 1:rho expander ratio */ #include <math.h> double f(rho, x) double rho, x; { if (x <= 1) return pow(x, rho-1); else return 1; } Fig. P8.15 Noise gate output and gain with increased threshold. Problem 8.25 Increasing the threshold to c0 will cause both A1 and A3 to be attenuated. However, A3 because it is further from c0 than in the case of Fig. 8.2.38, it will be attenuated more. Fig. P8.14 shows the results. The noise gate with threshold c0 = 1.5, will suppress both A1 and A3 , but A3 by much more, for the same reasons explained above. Fig. P8.15 shows the results. Problem 8.27 Assuming a partial fraction expansion of the form: M H(z)= i=1 Ai 1 − pi z−1 we have for the impulse response: M Problem 8.26 Assuming the causal sequence {x(0), x(1), . . . } is zero-mean white, then the terms in the convolutional sum will be mutually uncorrelated and zero-mean: It follows that we have the bound: M hn = i=1 Ai pn u(n) i y(n)= h0 x(n)+h1 x(n − 1)+ · · · + h(n)x(0) Thus, the output will have zero mean and its variance will be the sum of the variances of the successive terms: n 2 2 2 2 2 σy = E[y(n)2 ]= h2 σx + h2 σx + · · · h2 σx = σx 0 1 n M M |hn | = i=1 M A i pn ≤ i i=1 |Ai ||pi |n ≤ i=1 |Ai ||pmax |n = C|pmax |n h2 m n=0 where C = i=1 |Ai | and we used the inequality |pi | ≤ |pmax |. The NRR inequality follows now by squaring and summing the above inequality for |hn | and applying the geometric series on the right-hand side. 174 175 Problem 8.28 For ideal filter shapes, the NRR is computed most conveniently using its frequency response definition: NRR = 2 σyv 2 σv then we have the recursion: s2 1 = s 2 + n+ n 1 n+1 (xn − mx )2 −s2 n π = −π |H(ω)|2 dω 2π For a bandpass filter, H(ω) is non-zero only over the interval ωa ≤ |ω| ≤ ωb , where it is unity. Thus, NRR = 2 σyv 2 σv initialized with s2 = 0. The following program will calculate the input and output signals and 0 the experimental mean-square values. Any discrepancies are due to the filter transients and they disappear with increasing L: /* smoothex.c - filtering with 1st order smoother */ #include <stdio.h> #include <math.h> double gran(); void main(int argc, char **argv) { int n, L; long iseed; double s=5, x, y, w1, a, m=0, sigma=1; double sx2=0, sy2=0; FILE *fpx, *fpy; if (argc != 4) { puts("\nUsage: smoothex a iseed L"); exit(0); } a = atof(argv[1]); iseed = atol(argv[2]); L = atoi(argv[3]); fpx = fopen("ttx", "w"); fpy = fopen("tty", "w"); for (w1=0, n=0; n<L; n++) { x = s + gran(m, sigma, &iseed); y = (1 - a) * x + a * w1; w1 = y; fprintf(fpx, "%lf\n", x); fprintf(fpy, "%lf\n", y); sx2 += ((x-s)*(x-s) - sx2) / (n+1); sy2 += ((y-s)*(y-s) - sy2) / (n+1); } printf("theoretical 1/NRR = %lf\n", (1+a)/(1-a)); printf("experimental 1/NRR = %lf\n", sx2/sy2); } = −ωa −ωb dω + 1· 2π ωb ωa ωb − ωa dω = 1· 2π π Problem 8.29 The following program is an implementation: /* smooth1.c - 1st-order exponential smoother */ #include <stdio.h> #include <math.h> void main(int argc, char **argv) { double a, x, y, w1 = 0; if (argc != 2) { fprintf(stderr, "usage: smooth1 a <x.dat >y.dat\n"); exit(0); } a = atof(argv[1]); fprintf(stderr, "%lf\n", a); while(scanf("%lf", &x) != EOF) { y = a * w1 + (1-a) * x; w1 = y; printf("%lf\n", y); } } Problem 8.30 The mean of x(n) is mx = s = 5. The mean of y(n) is the same because it is preserved through the filter. Indeed, taking means of both sides of y(n)= ay(n − 1)+(1 − a)x(n) gives Problem 8.31 my = amy + (1 − a)mx ⇒ m y = mx The requirement that the high-frequency signal s(−1)n go through unchanged is that the filter have unity gain at ω = π or z = −1. This requires the value for the constant b: The mean-square values may be determine recursively as follows: If we define s2 = n 1 n−1 b (xk − mx )2 1 − az−1 z=−1 = b 1+a =1 ⇒ b=1+a n k=0 176 177 and therefore it must be larger at low frequencies because it is a lowpass filter. . Because g2 = h2 . |H(π)|2 = 1 where H(z)= A A∗ G = + 1 − p∗ z−1 (1 − pz−1 )(1 − p∗ z−1 ) 1 − pz−1 Problem 8. N − 1 1 0 π ω This gives hn = λ(−1)n .Thus the filter transfer function and impulse response will be: H(z)= The NRR is: 1+a . the solution of the highpass problem will be: Thus. the NRR must be minimized subject to this AC condition: N−1 N−1 NRR = NRR = n=0 h2 = min. . and A as given above. its values at DC and AC are: N Problem 8. . Thus. . n subject to n=0 hn (−1)n = 1 A∗2 2|A|2 A2 + + ∗2 2 1−p 1−p 1 − |p|2 This can be solved by Lagrange multipliers or more simply by defining the quantities gn = hn (−1)n . the NRR is magnified if 0 < a < 1. ∞ n≥0 H(π)= n=0 hn (−1)n = 1 which sums up to NRR = n=0 h2 = n n=0 A2 p2n + A∗2 p∗2n + 2AA∗ |p|2n where we used the fact ejπn = (−1)n . 1. . 1.4 to be gn = 1/N. P8. This can be understood in the frequency domain by the Fig. we modify the NRR to be minimized into the effective performance index: ( 1+a ( 1. and the AC constraint then fixes λ to be: N−1 N−1 hn (−1)n = λ n=0 n=0 (−1)2n = λN = 1 ⇒ λ= 1 Fig. hn = (−1)n gn = 1 N (−1)n . .32 For an FIR filter of length N. n subject to n=0 gn = 1 1+a h(n) = (1 + a) = NRR = 1 − a2 1−a n=0 2 2 ∞ 1 whose solution was found in Example 8. .16.a 2 J= output noise spectrum N−1 N−1 h 2 + 2λ 1 − n n=0 n=0 hn (−1)n The minimization condition with respect to the unknowns hn are: input noise spectrum ∂J = 2hn − 2λ(−1)n = 0. . N − 1 The Lagrange multiplier method is as follows. N− 1. Introducing a Lagrange multiplier. that enforces the constraint. . n = 0. 178 179 . Thus. P8. 1 − az−1 h(n)= (1 + a)an u(n) N−1 N−1 NRR = n=0 g2 = min. n = 0. .16 Lowpass filter for extracting high-frequency signal. . and replacing G2 by its normalized value G2 = (1 − R)2 1 − 2R cos(2ω0 )+R2 gives the desired expression for NRR after some tedious algebra.3. say λ. ∂hn n = 0. its frequency response will be: N−1 A= G 1 − p∗ /p = Gp jGejω0 =− p − p∗ 2 sin ω0 H(ω)= n=0 hn e−jωn The corresponding impulse response and NRR will be then The condition that the gain is unity at AC is: N−1 ∞ hn = Apn + a∗ p∗n . The magnitude response is normalized to unity at high frequencies. the problem reduces to the following minimization problem: n n Inserting p = Rejω0 . 1 . Indeed. .33 Expand the transfer function into partial fractions: |H(0)|2 = 1+a 1−a 2 . 35.34. For Q = 60. hn = Bδn + Ap un + A p from which we can calculate the NRR: ∞ ∞ n ∗ ∗n un NRR = n=0 h2 = B 2 + n n=1 ∞ (Apn + A∗ p∗n )2 = B2 + n=1 A2 p2n + A∗2 p∗2n + 2|A|2 |p|2n + A∗2 p∗2 2|A|2 |p|2 + 1 − p∗2 1 − |p|2 G(1 − p2 ) p2 − |p|2 = B2 + The parameters B and A are: A 2 p2 1 − p2 B=− G . the filter is identical to that of Example 8. |p|2 A=− Fig.8541 = 0. the design equations give: H(z)= 0. we start with neff from which we may solve for R = (0.17 Magnitude responses and noisy input of Problem 8.3.8541z−2 H(z)= Its pole radius is R = √ a2 = √ 0.22) and (8.34 For the first filter.8833z−1 + 0.35 For Q = 6. 180 181 .1.0064π. H(z)= 0.17 and P8.96953 Problem 8. (8.0099(1 − z−2 ) 1 − 1. For the second filter.9901 where R is related to the 3-dB width by: R 2 = a 2 = 2b − 1 = 1 − tan(Δω/2) 1 + tan(Δω/2) which gives Δω = 0.21 show the input signal.34.18.9802z−2 and NRR = 1/101.93906z−2 Fig.0730(1 − z−2 ) 1 − 1. filter responses. the transfer function is designed using Eqs. Problem 8. and output signals.2. Figures P8.23): 1 − 1.9242. P8.7633z−1 + 0. The numerical value of NRR is NRR = 1/13.19 Noisy input and desired signal of Problem 8. The required graphs are shown in Figs.19–P8.05)1/neff = 0. P8. P8.80289z−1 + 0.18 Filter outputs of Problem 8. Then.4. which gives the 5% time constant: neff = ln(0.2. P8. we find the transfer function: 0.36 The designed filter has the form: Its 1% time constant is neff = 146.05) = 38 ln(R) Its NRR can be computed by carrying out a partial fraction expansion of the form: H(z)= B + which gives the impulse response: A 1 − pz−1 + A∗ 1 − p∗ z−1 Fig.85955z−1 + z−2 1 − 1.Problem 8.8. Problem 8. Problem 8.26.36.37 The following MATLAB m-file designs the 60 Hz notch filter. Fig. P8.23 Filtered output y(n) when Q = 80. P8. Problem 8.6 5863.35. for Q = 6 and Q = 60.996088 0. P8. Fig.Fig.35. generates the noisy ECG and filters it. Problem 8.36. P8.24 Filtered s(n) for Q = 80 and Q = 200. Problem 8. P8.21 Filter outputs. and computes the filter’s magnitude response: 182 183 .8 Fig.22–P8. H(z)= b The time constant is computed as: 1 − z−D 1 − az−D neff = D where ln ln a = 0. Fig. Problem 8.4 2931.01 for the 1% time constant. P8.992207 0.980741 0.20 Magnitude responses.7 11727.984414 0.36. The relevant graphs are shown in Figs. The filter parameters are in the four cases: Q 80 200 400 800 a 0.992177 0. for Q = 6 and Q = 60.961481 0.998040 neff 1172.996081 b 0.22 Desired signal and noisy input. compute filter’s magnitude response. A = [1. beta = tan(dw * 10 / 4). 9. m = max(x). P8. x). v = v0. % % compute notch filter coefficients % generate length-500 ecg by calling x0=ecg(500). w0 = 2 * pi * f0. dw = 2 * pi * df / fs. end v = 2 + v.simulated ECG + 60Hz square-wave noise example % % assume 1 beats/sec => 1 sec/beat => 600 samples/beat => 600 samples/sec % % compute notch filter coefficients % generate length-600 ecg by calling x0=ecg(600). x). h = abs(b * (1 . 5.5 * v. f0 = 60/1000.^10)). h = abs((B(1) + B(2)*z + B(3)*z.5 sec/beat => 500 samples/beat => 1000 samples/sec % f0=60. % add 80 percent 60-Hz noise % and filter it yv=filter(B.beta) / (1 + beta). A = [1 0 0 0 0 0 0 0 0 0 -a]. x = x/m. x = [x0.26 Magnitude responses for Q = 80 and Q = 800. b = 1 / (1+tan(dw/2)). x = [x0. A. xv = x + 0. 1]. % noise baseline shift % noisy ECG 184 185 . z = exp(-i*w). w0 = 2 * pi * f0 / fs. fs = 600. % numerator % denominator % ecgex1.36. xv).38 The following MATLAB m-file designs the 60 Hz comb filter./ (1 .n = 0:1499. B = b * [1 0 0 0 0 0 0 0 0 0 -1]. x0]. normalize it to 1. for k=1:119. x). B(2). B = b * [1. x = sgfilt(0. z = exp(-i*w). x0].36.5 * cos(w0 * n). x0 = ecg(600). % add shifted square wave % and filter it yv=filter(B./ (1 + A(2)*z + A(3)*z.m . v = [v. x = x/m. 5.z.x0] and smooth them with x=sgfilt(0.xv) % finally.A. v0 = [1 1 1 1 1 -1 -1 -1 -1 -1].x0] and smooth them with x=sgfilt(0. v0].25 Filtered s(n) for Q = 400 and Q = 800. yv = filter(B. w = (0:499)*pi/500.75. xv). generates the noisy ECG and filters it. P8. and computes the filter’s magnitude response: Fig.^2) . x = sgfilt(0. m = max(x). 9.x0. w = (0:500)*pi/500.x0.A. df = 0. normalize it to 1. x0. % replicate three beats x=[x0. x0 = ecg(500). % one noise period % 120 noise periods % D=10 here Fig. dw = 2 * pi * df. 2*b-1]. xv = x + 0.^10) . x). -2*cos(w0).^2)). b = (1 + a) / 2. a = (1 . f0 = 60. % replicate three beats x=[x0. Q=60. Problem 8. compute filter’s magnitude response. yv = filter(B. Q = 60.a * z. df=f0/Q.xv) % finally.simulated ECG + 60Hz noise example % % assume 2 beats/sec => 0. n = 0:1199. Problem 8. df = f0/Q. % ecgex2. A.m . Problem 8. s[n]). char **argv) { int n. "%lf\n". . 0. i++) s[i] = i / D4. p. fps = fopen("s.0).0. . } 186 187 . for (i = 0. .c . "w"). 0. n++) { x = s[n] + 0. *p = b * x + a * sD.. long iseed. s = (double *) calloc(D. "w").dat". 0. x). . fprintf(fps. *fpx. 0. double *s. N = atoi(argv[2]). and filters them using the circular buffer implementation of the canonical realization of the filter: /* combex. A+B=b h = [b. &p). fprintf(fpx. . 0. 1. . exit(0).h> #include <math.dat". the tangent has argument: ΔωD 4 = Δω 4 · π πΔω 2π = = ω1 2ω 1 2Q where we used ω1 = 2π/D. we expand puts("\nUsage: combex D N iseed"). . cdelay(D. double a. triang(). a b period number of periods initial seed filter output noise-free input noisy input H(z)= b where B 1 + z−D =A+ = (A + B)+Baz−D + Bz2 z−2D + · · · 1 − az−D 1 − az−D b A=− .5 * gran(0. . 0. D). one period of triangular wave triang(D. } Problem 8. Ba3 . *fps. } D = atoi(argv[1]). . i<3*D4. . w = (double *) calloc(D+1. i++) s[i] = 1 + (D4 . *p. "w"). i++) s[i] = -1 + (i .i) / D4. s).3*D4) / D4. w.0008 * pi. } NRR = n=0 h2 = b 2 + B 2 n m=1 a 2m = b 2 + B 2 a 2 1 − a2 = = b2 (1 − a2 )+b2 a2 (1 + a−2 ) 2b2 (1 + a) 2(1 − a)2 (1 + a) = = 1 − a2 1 − a2 4(1 − a)(1 + a) 1−a 2 In the filter design parameter β = tan(ΔωD/4). fpy = fopen("y.. double D4 = D/4. for (i=3*D4. n<D.h> double gran(). = (1 .*/ /* triang. double *s. p = w. Ba. FILE *fpy.IIR comb filter with noisy periodic input */ #include <stdio. void cdelay(). generate N periods for (i=0. a Thus. y). 0. for (i=D4. N. *w. i. The sum of the squares is ∞ ∞ = (1 . constructs 40 periods of length-50 of the noisy triangular waveform. or D = 2π/ω1 . double x. b. fprintf(fpy. ] with the nonzero entries separated by D − 1 zeros. sD = tap(D.tan(D*dw/4)) / (1 + tan(D*dw/4)). i<D. if (argc != 4) { /* -------------------------------------------------------. void main(int argc. w. "%lf\n".39 Using partial fractions. { int i. D. y.40 The following program designs the comb filter. . sizeof(double)). dw = 0. iseed = atol(argv[3]). y = (*p) + sD.triangular wave */ void triang(D. tap(). . the impulse response is B=b 1+ 1 a .h> #include <stdlib. . "%lf\n". . Ba2 . . sD. fpx = fopen("x. 0.a) / 2. s) int D. i<D4.dat".c . &iseed). 0. i++) for (n=0.Problem 8. i<N. pi=4*atan(1. sizeof(double)). 27 shows the frequency responses in the four cases. *p. namely. The advantage of the circular implementation is that only one entry of w. &x) != EOF) { /* keep reading input samples */ *p = tap(D. the content of w[q] is updated by w[q]= w[qD ]+x. w. i. For example. w. we have half-order M = 8/2 = 4.h> void cdelay(). fprintf(stderr. } D = atoi(argv[1]). i<D. p.signal averaging */ #include <stdio. for (k=0. P8. the Nyquist frequency here is fs /2 = 2fsc = 7.Problem 8. The inputs to the program are the period D and the number N of periods to be averaged.42 See Table P8. exit(0).1. cdelay(D. D). This is efficient in hardware implementations and for large values of D. w[q]. i++) printf("%. Thus. "x. w = (double *) calloc(D+1.41 The complementarity properties may be verified for each pair.5 MHz.h> #include <stdlib.159 MHz. 188 189 . D) + x / N. Problem 8. &p). "usage: sigav D N < x. Table P8. "Input must have %d periods of length %d\n".dat must contain N periods of length D\n"). 6 7 8 9 10 11 12 s0 s1 s2 − − − − Table P8.12lf\n". sizeof(double)). i<D. } for (i=0. p = w. so that the subcarrier frequency shown in the figure is only one-quarter of the Nyquist interval.1 Signal averager with circular delay for D = 3. N = 4. double tap().43 The following is a complete C program for performing signal averaging. w. The input data are taken from stdin and the averaged period is output to the stdout: /* sigav. The frequency scale is in MHz and extends only up to about 4. N. int D. is changed at each time instant. where the scaling by N is done afterwards.dat > y.1 shows the results. Note that the circular pointer p points to the buffer entry w[q].27 Lowpass/bandpass and highpass/bandstop responses. k++) for (i=0. k. P8. } HLP (z)+HBP (z)= 1 1 (1 + z−2 )2 (−1 + 6z−2 − z−4 )+ (1 − z−2 )4 = z−4 16 16 which follows by expanding out the terms.c . } else { fprintf(stderr. i++) if (scanf("%lf". At each time instant. we must verify: void main(int argc. for filter 2. Problem 8. whereas the D-th tap output is the content of w[qD ].41. Fig. Fig. *w. k<N. N. n 0 1 2 3 4 5 x s0 s1 s2 s0 s1 s2 s0 s1 s2 s0 s1 s2 − qD 3 2 1 0 3 2 1 0 3 2 1 0 q 0 3 2 1 0 3 2 1 0 3 2 1 w0 s0 s0 s0 s0 2s1 2s1 2s1 2s1 3s2 3s2 3s2 3s2 w1 0 0 0 2s0 2s0 2s0 2s0 3s1 3s1 3s1 3s1 4s2 4s2 w2 0 0 w3 0 y = w q /4 s0 /4 s1 /4 s2 /4 2s0 /4 2s1 /4 2s2 /4 3s0 /4 3s1 /4 3s2 /4 s2 s2 s2 s2 3s 0 3s 0 3s 0 3s 0 4s 1 4s 1 4s 1 s1 s1 s1 s1 2s 2 2s 2 2s 2 2s 2 4s 0 4s 0 4s 0 4s 0 Problem 8. exit(0).dat\n"). p. if (argc != 3) { fprintf(stderr. For reference. char **argv) { double x. N = atoi(argv[2]). tap(D. D-i)). xv = x + v. *w. n<D. void main(int argc. i<N. p.c . p. After processing the ND input samples. i<D. else s[i] = -1. tap().dat".. y1 = sgfilt(d. and averages these periods using the circular buffer form of the averager. iseed = atol(argv[3]). fpx = fopen("x.h> #include <stdlib. s[n]). n<D. D. "%.dat". so that the files y. } } Problem 8. i++) for (n=0.33 and 8. rand(’normal’). D). *p = sD + x. double sD. N. fps = fopen("s. 8. "w"). } for (n=0.. v = 0. x0).28 Double SG filtering. "w"). 1). char **argv) { int n. *p. The following figures should be compared with the single-pass cases of Figs. "%. write averaged period 190 191 . n++) { accumulate N periods each of length D noisy input D-th tap of averager accumulate x update delay line save input sample period number of periods noise seed fprintf(fps. x. if (argc != 4) { puts("\nUsage: sigavex D N iseed"). fpy = fopen("y. w = (double *) calloc(D+1.45 The following MATLAB function generates the noisy ECG and smoothes it once and twice by Savitzky-Golay filter of length N and smoothing order d: % sgecgex. tap(D. n++) { x = s[n] + gran(0. Fig. fprintf(fpy. FILE *fpx. x = sgfilt(0. cdelay(D. 10033). N. &iseed).dat and s. "w").12lf\n". i.dat". p = w.h> #include <math. w. rand(’seed’.12lf\n". w. % generate ECG % unity max % generate noise % generate noisy ECG % first pass through SG % second pass The filtering twice through the SG filter improves the smoothing operation but introduces longer transients in the filters. i++) if (i < D/2) s[i] = 1. 15. it writes out the contents of the delay line in reverse order. y2).SG filtering of noisy ECG L=500.44 The following program generates N periods of length D of the noisy signal. exit(0). *fps. } D = atoi(argv[1]). d=2. x = x/mx. N = atoi(argv[2]). D-n)/N). sizeof(double)). s = (double *) calloc(D. *fpy. double *s.3. w. sizeof(double)). mx = max(x). for (i=0.34. void cdelay().3 * rand(L. fprintf(fpx. P8.Problem 8. long iseed. 41 and d = 0. "%lf\n". xv). sD = tap(D.h> double gran(). N=11. N = 11. 1.m . x). N. x0 = ecg(L)’. for (i=0.3. &p).signal averaging example */ #include <stdio.dat will contain the averaged periods and the noise-free period: /* sigavex. y2 = sgfilt(d. we expect to see a peak at k = 8 and another one at k = −8. L = 8 kHz × 128 msec = 1024 samples. N = 11. Problem 9. P8. · · · . If the signal is reduced mod-256.2 Fig. we expect to see a peak at the kth DFT bin.30 Double SG filtering. N = 11. This cost may be added to the costs of FFT or reduced DFT. P8. 1. the total signal length will be N = kD = k fs f which gives for k = 16. The sinusoidal signal is something like x(t)= cos(2πf t). If the DFT is done directly. which translates mod-N to N − k.1 Use the formula TR = LT = L/fs to solve for L = fs TR .Chapter 9 Problems Problem 9. the second peak will be at k = 56. where M = L/N = 1024/256 = 4 is the number of segments. or in words no. 41 and d = 2. fk = k fs =f N Thus. we would require L · N = 1024 · 256 = 262144 multiplications. The cost of performing the mod-256 reduction is N(M − 1)= 256 · 3 = 768 additions. And if the FFT is used. where f = 10 kHz. N = 16 · 8 = 128 samples. that is. then because of the choice of N.29 Double SG filtering.3 The number of samples in one period is given by: D= 40 fs = = 8 samples f 5 Therefore. if k periods are collected . We will also get a peak at the negative index −k. of seconds) Thus. Fig. Because the DFT X(k) is periodic in k with period N and because we always list the indices in the positive range k = 0. The frequency spacing is Δf = fs /N = 8000/256 = 31. Problem 9. Its spectrum will have peaks at ±f . we shift the negative index by one period N to get the positive index: −k → N − k = 64 − 8 = 56 Thus.25 Hz. the k-th DFT frequency will coincide with f . N log2 N/2 = 256 · 8/2 = 1024. In summary. of samples = (no. of samples per second) x (no. 41 and d = 4. Is there a DFT index k such that the kth DFT frequency fk equals ±f ? ±f = fk = fs k N ⇒ k = ±N 10 f = ±64 = ±8 fs 80 Thus. then the number of multiplications would be N · N = 256 · 256 = 65536. we expect to see peaks at the DFT indices: k = 16 and N − k = 128 − 16 = 112 192 193 . If we perform an N-point DFT. N − 1. DTFT of a signal at a frequency vector w % % X = dtft(x. f2 = 0. f3 = 0. w0 = 0.c k = 36 − 2 × 16 = 4 It corresponds to the DFT frequency fk = kfs /N = 4 · 8/16 = 2 kHz. the width of the main lobe of the data window must be equal or smaller than the width of the peak. For the other cases.7 The following MATLAB function generates the time data and computes the required DTFTs: % sinexp.dat xham.c . included below. The duration of these 400 samples will be TR = LT ≥ 1 1 L = = = 50 msec fs Δf 20 To avoid wrap-around errors in the inverse FFT.3. for n = L-1:-1:0.h> #include <stdlib. % % x = row vector of time samples % w = row vector of frequencies in rads/sample % X = row vector of DTFT values % % based on and replaces both dtft.4 The expected DFT index will be at 18 f k = N = 16 · = 36 fs 8 Because k is greater than N − 1 = 15.h> void dtftr(). This is frequency within the Nyquist interval that is aliased with f = 18 kHz. save save save save xrec. [L1. w)). % windowed data % DTFT of rectangular data % DTFT of Hamming data 194 195 .N)).3 sinusoids of length L=10 L=10. or. use L = 10.N)).54 . x = cos(2*pi*f1*n) + cos(2*pi*f2*n) + cos(2*pi*f3*n). which replaces the C functions dtft. xham = wh .c: % dtftexp.rectangular/hamming windowed sinsuoids L = 200. f1 = 0.Problem 9. The next power of two is N = 512. Problem 9. N=256. end fs ≤ Δf L ⇒ L≥ fs Δf Problem 9. 100 and N = 256. n = 0:(L-1). This gives the condition X = 0. Xham = abs(fft(xham. N = 200.dat fham.h> #include <cmplx.. w) falias = f mod fs = 18 mod 8 = 18 − 2 × 8 = 2 kHz The −2 kHz or −18 kHz component will be represented by the DFT index N − k = 16 − 4 = 12. in our case. xham = w. w). n = 0:(L-1). computational resolution example */ #include <stdio. we have function X = dtft(x. i. X = x(n+1) + z . % frequency range % Hamming window Problem 9. Xham = abs(dtft(xham.m .2. xrec = cos(w0 * n).5 To be able to resolve a peak.e.physical vs.c and dtftr. The 32-point DFT is extracted by keeping one out of every 256/32 = 8 points of the 256-point DFT.c and dtftr. L] = size(x). /ascii.25.dat xrec xham Xrec Xham /ascii.2 * pi / N.* xrec. We must pad 112 zeros to the end of the length-400 signal before the FFT is taken. the FFT length must be at least L.dat frec. 20. Problem 9. indeed.1*pi. with L = 10. /ascii.8 The following C program generates the length-L time signal and computes its N-point DFT.* X. it may be reduced mod-N down to: where % dtft. Xrec = abs(dtft(xrec.m . w = (0:N-1) * 0.c.*x.54 . L ≥ 8000/20 = 400 samples. w)).46 * cos(2*pi*n/(L-1)). Instead of the DFT routine dft.6 The following MATLAB function generates the time data and computes the required DTFTs with the help of the function dtft. /* dtftex. wh = 0. N ≥ L = 400. 100.m. w = 0. /ascii.46 * cos(2*pi*n/(L-1)).c.m .0. z = exp(-j*w).0. X = abs(fft(x. 40. one could use fft. 3. f3 = 0.7. f2 = 0.3.main() { int L. "%lf\n". X). ˜ The mod-4 wrapped version of x is x = [3.8. sizeof(double)). P9. &L. the DTFT will have peaks at the corresponding pair of DFT indices (and their negatives.2 Spectra of DTMF sinusoids. fpdtft= fopen("dtft. dft(L. Its 4-point DFT is X(0) ⎢ X(1) ⎢ X=⎢ ⎣ X(2) X(3) ⎡ ⎤ ⎡ ⎥ ⎢ 1 ⎥ ⎢ ⎥=⎢ ⎦ ⎣ 1 1 1 1 −j −1 j 1 −1 1 −1 j ⎥⎢ 3 ⎥ ⎢ 0 ⎥ ⎥ ⎢ ⎥ ⎥⎢ ⎥=⎢ ⎥ ⎥⎢ −1 ⎦ ⎣ 3 ⎦ ⎣ 0 ⎦ −j 3 0 1 ⎤⎡ 3 ⎤ ⎡ 12 ⎤ For the IDFT we use the formula IDFT(X)= [DFT(X∗ )]∗ /N: 196 197 . FILE *fpdtft. sizeof(complex)). k++) fprintf(fpdtft.1. N − kA and N − kB . we obtain: kA = 22.6. X = (complex *) calloc(N. k<N.0). 47.3 Problem 9. x.25.1 and P9.30.dat". complex *X. 30. 27. N: "). kA = 22.1 kB = 38.9 See Example 9. &N). double *x. pi = 4 * atan(1. for (n=0. "w"). scanf("%d %d". double f1 = 0. printf("enter L. P9. k. 43. n++) x[n] = cos(2*pi*f1*n) + cos(2*pi*f2*n) + cos(2*pi*f3*n). 25. Problem 9. cabs(X[k])).10 Using the relationship k = Nf /f s. 3.2. 47 X(0) ⎢ X(1) ⎢ ⎢ X= ⎣ X(2) X(3) ⎡ ⎤ ⎡ ⎥ ⎢ 1 ⎥ ⎢ ⎥=⎢ ⎦ ⎣ 1 1 1 1 1 −1 1 −1 1 1 1 1 1 1 1 −1 1 −1 1 ⎡ ⎢ ⎢ ⎤⎢ ⎢ ⎢ ⎥⎢ ⎥⎢ ⎥⎢ ⎦⎢ ⎢ ⎢ ⎢ ⎢ ⎣ Because each keypress generates one tone from group A and one from group B. N. 24. } N-point DFT Problem 9. x = (double *) calloc(L. n<L.11 The time signal and its DTFT are shown in Figs. N. 3]. that is. both for the rectangular and Hamming windows. we calculate the group-A and group-B DFT indices: group A group B and their rounded versions: group A: group B: Fig. 3. DTFT file Fig. 30 kB = 39. 27. 42.20.) −j −1 j j −1 −j −j −1 j j −1 −j 1 2 2 1 2 1 1 2 ⎤ ⎥ ⎥ ⎥ ⎡ ⎥ ⎥ ⎥ ⎢ ⎥ ⎢ ⎥=⎢ ⎥ ⎣ ⎥ ⎥ ⎥ ⎥ ⎦ 12 0 0 0 ⎤ ⎥ ⎥ ⎥ ⎦ Problem 9. for (k=0.1 Rectangularly and Hamming windowed DTMF sinusoids.12 Acting on x by the 4×8 DFT matrix. P9. n.2. 198 199 . 2N − 1. 8 4 2π 2 π ω2 = = . The butterfly operations can be done is small parts. 1. Then. The first merging stage require mulk tiplication by the twiddle factors W2N . 4. The total cost is the cost of four N-point FFTs. These are then merged first into (2N)-point DFTs and then into the desired (4N)-point DFT. The second stage uses the factors k W4N . Problem 9. k = 0. . we express x(n) as a sum of sinusoids: x(n) = 1 8 7 X(k)ejωk n = k=0 1 4ejω1 n − 4jejω2 n + 4ejω3 n + 4ejω5 n + 4jejω6 n + 4ejω7 n 8 1 jω2 n 1 1 1 −jω2 n 1 1 = ejω1 n + e e + ejω3 n + e−jω3 n − + e−jω1 n 2j 2 2 2j 2 2 = cos(ω1 n)+ sin(ω2 n)+ cos(ω3 n)= cos(πn/4)+ sin(πn/2)+ cos(3πn/4) which agrees with the above IFFT values at n = 0. The required FFT of X∗ is: The four N-dimensional vectors are then shipped over to the FFT processor. 3 . .Problem 9. in groups of N operations at a time so that they can be implemented by the DSP hardware. 8 2 2π 3 3π ω3 = = 8 4 It is easily verified that the costs of the two methods are the same. The (4N)-dimensional time data vector is shuffled once into two (2N)-dimensional subvectors by putting every other one of its entries on top and the remaining entries on the bottom. . for example. 4. ω3 . 1. . and a (4N)-fold multiplication for the second stage: 1 cost = 4 N log2 N + 2N + 2N = 2N log2 N + 4N 2 If the (4N)-point FFT could be done in one pass. 6 .3 shows the procedure. ω2 .15 x(0) ⎢ x(1) ⎢ x=⎢ ⎣ x(2) x(3) ⎡ ⎤ ⎡ ⎥ 1 ⎢ 1 ⎢ ⎥ ⎢ ⎥= ⎦ 4 ⎣ 1 1 1 1 1 −j −1 j −1 1 −1 j ⎥⎢ 0 ⎥ ⎢ 3 ⎥ ⎥ ⎢ ⎥ ⎥⎢ ⎥=⎢ ⎥ ⎥⎢ −1 ⎦ ⎣ 0 ⎦ ⎣ 3 ⎦ −j 0 3 1 ⎤⎡ 12 ⎤ ⎡ 3 ⎤ Figure P9. . . ω6 . 7 . and their FFTs are returned into four N-dimensional DFT vectors. 1. 6 . N − 1. We used the values of the DFT frequencies: 2π π ω1 = = .16 The ordinary convolution is y = h ∗ x = [ 1 . . 7.3 Performing large FFTs. 3 . ω5 are the negatives (modulo-2π) of ω1 . respectively. X(ω4 )= 8 Problem 9. The IFFT is obtained by conjugating X. P9. the cost of two N-fold multiplications for the first merging stage.14 Fig. The indirect method is of course much slower because of all the I/O time for shipping data back and forth from secondary storage to the FFT processor.13 The 8-point FFT is: shuffling ⎡ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ x=⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎣ 5 −1 −3 −1 5 −1 −3 −1 DFT merging N-FFT ⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎦ ⎡ 8−FFT − → ⎢ 0 ⎥ ⎥ ⎢ ⎥ ⎢ ⎢ 16 ⎥ ⎥ ⎢ ⎢ 0 ⎥ ⎥ ⎢ ⎥ X=⎢ ⎢ 8 ⎥ ⎥ ⎢ ⎢ 0 ⎥ ⎥ ⎢ ⎥ ⎢ ⎣ 16 ⎦ 0 0 ⎤ N 2N N 4N N 2N N N-FFT N-FFT N-FFT N 2N N W2N 4N N k 2N W4N k N W2N k It follows that the FFT spectrum will show peaks at the frequencies: X(ω2 )= X(ω6 )∗ = X(−ω2 )∗ = 16. . . Problem 9. k = 0. . computing its FFT. . each of the (2N)-dimensional vectors is shuffled again into two N-dimensional subvectors. one at a time. and dividing by 8. 1 ] The DFT frequencies ω7 . we would have cost: cost = 1 (4N)log2 (4N)= 2N log2 (4N) 2 ⎡ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ∗ X =⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎣ 0 4 4j 4 0 4 − 4j 4 ⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎦ ⎡ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎣ 8−FFT − → 16 8 0 −8 −16 8 0 −8 ⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎦ ⎡ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ x=⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎣ ⇒ 2 1 0 −1 −2 1 0 −1 ⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎦ Using the inverse DFT formula. . ˜ x = [2. .21 This follows from the results of Problem 9. 3. in this case the answer is zero. Problem 9. 2]. finally. because whenever it is a multiple of N. 9. All of the N terms in the sum become unity. 6. 3 . 9. X8 (k)= X16 (2k). 2. giving N/N = 1. reduce that modulo 4 to get y = [9. Thus. 2 . we have a ratio of 0/0. ω0 = 0. In conclusion. 8. . 5.20 For a general power p. k = 0. we would get unity as an answer (and zero otherwise). 4. the numerator vanishes but not the denominator. 1. 8. 1. 15 A geometrical way to understand this is to recognize that the 8th roots of unity are a subset of the 16th roots of unity and are obtained by taking every other one of the latter. . 1. taking every other entry of that gives the 2-point FFT: X= 8 24 X(ω)= n=0 x(n)e−jωn L−1 Can we get these results directly? Yes. If k = 0. and ω6 = 3π/2 ≡ −π/2. 9]. 2 − b. Note. compute their ordinary convolution: ˜ ˜ h ∗ x = [4.19 Using the finite geometric series and the definition WN = e−2πj/N .17 Carrying out the 8-point FFT gives: ⎡ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ x=⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎣ 4 2 4 −6 4 2 4 −6 ⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎦ ⎡ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ X=⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎣ 8−FFT − → 8 0 −16j 0 24 0 16j 0 ⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎦ N If k = 0. ω4 = π. . then. gives 1 N−1 kn WN = n=0 Nk 1 1 − WN 1 1 − e−2πjk = k N 1 − WN N 1 − e−2πjk/N Problem 9. a. and unity if k = 0. 1. 3. 6. 9. b] It should be evident that. 2]. first reduce the signal modulo 4 to get ⎤ ⎡ ⎡ ⎤ 8 8 ⎥ ⎢ ⎢ −16j ⎥ 4 ⎥ 4−FFT ⎢ ⎢ ⎥ ⎥ ⎥ ˜ − → X=⎢ x=⎢ ⎣ ⎣ 24 ⎦ 8 ⎦ −12 16j Putting the above 8-point FFT into the 8-point inverse FFT formula gives 1 x(n)= 8 7 XN (k)= n=0 L−1 kn x(n)WN XpN (k)= n=0 kn x(n)WpN Replacing k by pk in the third and using part (a). 5 ] .20 by setting N = 8 and p = 2. we have: L−1 L−1 XpN (pk)= X(k)ejωk n 1 = 8ejω0 n − 16jejω2 n + 24ejω4 n + 16jejω6 n 8 n=0 x(n)WpN = n=0 pkn kn x(n)WN = XN (k) k=0 Problem 9. To do the 4-point FFT. that these arguments break down if k is allowed to go beyond the range 0 ≤ k ≤ N − 1. which implies: Noting that for an 8-point FFT. 200 201 . · · · . but in this case. Taking every other entry of the result gives the 4-point FFT. 9]. 5. 1. 7. its mod-5 reduction is [ 1. 1].18 Consider the length-7 signal [1 − a. and using Euler’s formula we obtain: πn x(n)= 1 + 4 sin( )+3 cos(πn) 2 which agrees with the given x. namely. 4 . we can just go back to the series definition and set k = 0. ω2 = π/2. Problem 9. the answer is zero if k = 0. The alternative method is to reduce first x and h mod-4: ˜ h = [2. for n = 0.˜ Reducing this mod-4 gives: y = [9. Problem 9. for any values of the parameters a and b. ˜ and. we have: p ⎡ ⎢ ⎢ X=⎢ ⎣ 8 −16j 24 16j ⎤ ⎥ ⎥ ⎥ ⎦ WpN = e−2πj/(pN) p = e−2πj/N = WN The DTFT of a length-L signal and its N-point and (pN)-point DFTs are: L−1 And. .5W(ω)−jW(ω − ω4 )+jW(ω − ω12 )+1. 0. 4] kHz are. X(4)= 8. 0. −3 ] 8−FFT and noting that π/2 = 8π/16 = ω4 . .23 Using Euler’s formula. 8. 8j. Comparing with the IDFT formula. − → X = [0.5ejω0 n − jejω4 n + jωjω12 n + 1. 8j. 1 .g. Their aliased versions that lie inside the Nyquist interval [−4. ω12 = −ω4 mod(2π). 24. 0. we shifted the negative frequency exponents by adding 2πn to them. respectively. ω2 = π/2. X(15)= 16. and 2 kHz. Using Euler’s formula. e.1) x(n) = 1 + 2 sin( πn 4 )−2 sin( πn 2 )+2 sin( 3πn )+3(−1)n 4 where ω0 = 0. 0. −8j. 8j] W(ω)= sin(8ω) −15jω/2 1 − e−16jω e = 1 − e−jω sin(ω/2) The magnitude spectrum |X(ω)| is plotted versus 0 ≤ ω ≤ 2π in Fig. 10.. 8. we get: X = [8. P9. we write x(n) = 0. The spectral peaks at the signal frequencies are evident. ω8 = 2π8/16 = π are the signal frequencies expressed as 16-point DFT frequencies.and 8-point DFTs because the peak frequencies coincide with DFT frequencies. 1. 0. replaced −πn/8 by 2πn − πn/8 = 15πn/8. ω6 = −(π/2)mod(2π). X(8)= 16. −8j.5ejω8 n (P9. 1 . The DTFT of each complex sinusoid is given by the shifted spectrum of the rectangular window W(ω) of length-16: = 1 − jejπn/4 + je−jπn/4 + jejπn/2 − je−jπn/2 − jej3πn/4 + je−j3πn/4 + 3ejπn = 1 8ejω0 n − 8jejω1 n + 8jejω2 n − 8jejω3 n + 24ejω4 n + 8jejω5 n − 8jejω6 n + 8jejω7 n 8 where X(ω)= 0. setting ω4 = π. we get: Problem 9.5eπjn/2 + 0. 0. 2. 0. 0. 16] The same DFT values can be determined without any computation by comparing x(n) with the inverse DFT. 1 . the aliased signal that would be reconstructed by an ideal reconstructor will be: where. It so happens that the zeros of the sidelobes of the W(ω − ωi ) coincide with 16-point DFT frequencies. 3π/2 = 24π/16 = ω12 . 8. and 2 kHz. comparing with the 16-point IDFT formula x(t)= cos(8πt)+ sin(4πt)+ sin(4πt)= cos(8πt)+2 sin(4πt) Setting t = nT = n/8. X(24)= 16. gives the above DFT vector: x(n)= 1 8 7 X(k)ejωk n k=0 Problem 9. 0] X = [0. we write: x(n)= 0. and 15π/8 = 30π/16 = ω15 . we get the equivalent expression: Problem 9. 0. −8j. 202 203 .4. 16.26 Write x(n) in its complex sinusoidal form: Problem 9. π/8 = 2π/16 = ω1 . 7 gives the values. we may identify the (non-zero) values of X(k) as follows: X(1)= 16. Dividing the Nyquist interval into 16 equal bins. 0.24 Using Euler’s formula. and their FFT: x = [ 1 . we get the time samples: x(n)= 1 16 15 X(k)ejωk n k=0 x(n)= cos(πn)+2 sin(πn/2) Evaluating it at n = 0. ω4 = 2π4/16 = π/2. gives the 16-point DFT. 1 . 0.5W(ω − ω8 ) where we reordered the terms according to increasing DFT index.5e−πjn/2 + eπjn/8 + e−πjn/8 = 1 8eπjn/2 + 8e3πjn/2 + 16eπjn/8 + 16e15πjn/8 16 x(t)= cos(24πt)+2 sin(12πt)cos(8πt)= cos(24πt)+ sin(20πt)+ sin(4πt) The frequencies of the three terms are 12. and multiplying and dividing by 8. Thus.22 Using a trig identity to write the product of sines as a sum of sines. The peak values are correctly identified by the 16.25 Arguing in a similar fashion. 0. . we find the (non-zero) values of the 32-point DFT: x(n)= ejπn − jejπn/2 + je−jπn/2 = 1 −8jejω2 n + 8ejω4 n + 8jejω6 n 8 X(2)= 32. Taking every other 16-DFT point gives the 8-point DFT. . 0. 0. 4.Problem 9. Now. −8j. X(12)= 8. or. 1 . 8j. −3 . X(30)= 32 Comparing with the 8-point IDFT. 0. 8 . 0]. − 2. 2 ] The mod-4 reduction of this is y = [0. we note that the above sum will be zero if i = j. 1. 2. that is. 16-point and 8-point DFTs. 2. Using the results of Problem 9. 0. it will be equal to N if i = j.19. −3. 0. −16j. 8. ⎥ ⎥ ⎥ ⎥ ⎥ ⎦ ⎡ ⎢ 1 ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ 2 ⎥ ⎢ ⎥ ⎢ −3 ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ 2 ⎥ ⎢ ⎥ ⎢ 1 ⎥ ⎢ ⎥ ⎢ ⎥ ⎣ 2 ⎦ −3 ⎤ ⎡ 2 ⎤ ⎡ 8−FFT − → ⎢ 0 ⎥ ⎥ ⎢ ⎥ ⎢ ⎢ − 8j ⎥ ⎥ ⎢ ⎢ 0 ⎥ ⎥ ⎢ ⎥ ⎢ ⎢ 12 ⎥ ⎥ ⎢ ⎢ 0 ⎥ ⎥ ⎢ ⎥ ⎢ ⎣ 8j ⎦ 0 4 ⎤ (AA∗ )ij = n=0 WN (i−j)n Multiply them point-wise: = Nδ(i − j) ⎡ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎣ which is equivalent to the matrix relationship AA∗ = NI where I is the N × N identity matrix.27 We will show that the product AA is proportional to the identity matrix. 1. 0] Every other entry is the 8-point DFT: X = [8. −1. 0. we may extract the DFT coefficients: X = [8. 7. 2. 0. 0] and wrap it mod-8 to get ˜ y = [ 8. −2. − 1 . The ij-th matrix element of the product is: N−1 N−1 ∗ ⎡ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎣ (AA∗ )ij = n=0 Ain A∗ = nj n=0 in WN WN −jn N−1 = n=0 WN (i−j)n ∗ − where we used the fact that WN = WN1 . 0 π 2π ω Fig. 24. 2]. 2. 4. 8 . (P9. 0. of the N × N DFT matrix. 1. 0. 1]∗[2. 8 . − 2 ] Then. − 2 . Thus. the length should be N = 8. 2. 1. One minor detail is that in the mod-8 case. 0. Using X = Ax and the property AA† = A† A = NIN . 0. 0. −1.30 The 16-point DFT can be determined from the expression of x(n) by comparing it with 16-point IDFT formula. the desired equation reads x† x = 1 10 0 2 0 2 0 2 0 ⎤ ⎡ ⎥ ⎢ 0 ⎥ ⎢ 0 ⎥ ⎥ ⎢ ⎥ ⎢ ⎥ ⎥ ⎢ ⎥ ⎢ ⎥ ⎥ ⎢ −8j ⎥ ⎢ −16j ⎥ ⎥ ⎢ ⎥ ⎢ ⎥ ⎥ ⎢ ⎥ ⎢ 0 ⎥ ⎢ 0 ⎥ ⎥ ⎢ ⎥ ⎥×⎢ ⎥=⎢ ⎥ ⎥ ⎢ 12 ⎥ ⎢ 24 ⎥ ⎥ ⎢ ⎥ ⎢ ⎥ ⎥ ⎢ ⎥ ⎢ 0 ⎥ ⎢ 0 ⎥ ⎥ ⎢ ⎥ ⎥ ⎢ ⎥ ⎢ ⎥ ⎦ ⎣ 8j ⎦ ⎣ 16j ⎦ 0 0 4 40 ⎤ Divide by N = 8. The minimal N is N = Ly = Lx + Lh − 1 = 4 + 4 − 1 = 7. And. 1. −3] = [4. 6 . Finally. we can write compactly: N−1 2 1 1 1 2 1 1 1 ⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎦ ⎡ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎣ 8−FFT − → 10 0 2 0 2 0 2 0 ⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥. The mod-5 reduction is y = [1. − 1. conjugate every entry. 24. y = [2. compute the ordinary linear convolution: y = h ∗ x = [ 2 . −2. 4. −1. the mod-6 reduction is y = [4. −1].28 Vectorially. 2. −16j. Problem 9. 16j. the mod-7 and mod-8 reductions of y leave it unchanged.29 First. − 2. 1. and take an 8-point FFT: ⎡ X† X N where † denotes conjugate transpose. 0. 6 . −1. −1.|X(ω)| = DTFT 24 16 8 = 16-point DFT = 8-point DFT Problem 9. 0. −2. 1. P9. 2. 2 . strictly speaking y is y with one zero padded at the end. 7. −2]. 0. 11. 16j.4 DTFT. 2. 0. 1. we obtain (IN = N × N identity matrix) ⎢ 0 ⎢ ⎢ ⎢ 2j ⎢ ⎢ 0 ⎢ ⎢ ⎢ 3 ⎢ ⎢ 0 ⎢ ⎢ ⎣ − 2j 0 5 ⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎦ ⎡ 8−FFT − → X† X = x† A† Ax = x† NIN x = Nx† x ⎢ 6 ⎥ ⎥ ⎢ ⎥ ⎢ ⎢ 8 ⎥ ⎥ ⎢ ⎢ −2 ⎥ ⎥ ⎢ ⎥ ⎢ ⎢ 8 ⎥ ⎥ ⎢ ⎢ 6 ⎥ ⎥ ⎢ ⎥ ⎢ ⎣ 8 ⎦ −2 8 ⎤ 204 205 . 0. Multiplying and dividing Eq. 1. −2. compute the linear convolution of the given signals: y = h ∗ x = [2. −3] Problem 9. −1. Problem 9. −2.1) by 16. compute the FFTs of the two signals: First. −2. 0. thus. −2. 2. 0] X(k)= A(k)+jB(k) ⇒ X(N − k)∗ = A(N − k)∗ −jB(N − k)∗ N X(k)ejωk n . Nhalf=N/2. A(N − k)= A(k)∗ void fftreal(N. 1. 0.35 kn WN n=0 ∗ A(k)∗ = But. 1. { int n. because a(n) is real N−1 Problem 9. A(N − k)∗ = A(k) and B(N − k)∗ = B(k). 2]. double pi=4*atan(1. 0.h> #include <stdlib. 12. 0. On the other hand.h> #include <cmplx. 1. c. The 8-FFT algorithm gives x = [ 6 .0).5 2 2 2 1 2 log2 N N log2 N 2 If one takes into account the multiplications required for computing the Wk powers. Using x(n)= 1 N−1 Problem 9. the divisions by 2 k and 2j. 12]. 1 .c .34 The expressions for G(k) and H(k) follow from the results of Problem 9.FFT of a real-valued signal */ #include <math. k=0 Using the results of Problem 9. 65% of the standard cost for N = 1024. 8. 6. 1. 0. 1. complex *X. 0. time data FFT array 206 207 .33 Using linearity. then the total becomes ˜ d.5 N log2 N 2 log2 N N N−1 A(N − k)= n=0 −kn WN a(n) Typically.h> void fft(). 12. 12. Thus the total number of multiplications using this method compared to a direct N-point FFT will be 3N N 1N log2 ( )+ 2 = 1 + 2. 8. x. 1. it can be written as WN (N−k)n a(n) N 2 log2 ( 4N )+ 2 2 = 1 + 1 . 6 . Reduce x mod-4 to get x = [12. 1. 1 ] b. Problem 9. 0. x = [6 − a. 0 . 6. a.32 Start with N−1 A(k)= n=0 kn WN a(n) and evaluate it at N − k N−1 A(N − k)= n=0 N Noting that WN = 1. we have ⇒ X = [16. Thus. we obtain X(N − k)∗ = A(k)−jB(k). = −kn WN Thus. b] Problem 9. kn ∗ WN a(n) /* fftreal.32.31 a. (that is. except that the dimension of the FFTs is N/2. The additional multiplications to build X(k) from Y(k) are 3N/2. we have the system of equations: x(n)= πn 1 16 + 12ejπn/2 + 8ejπn + 12e−jπn/2 = 2 + 3 cos + (−1)n 8 2 X(k) = A(k)+jB(k) X(N − k)∗ = A(k)−jB(k) which can be solved for A(k) and B(k). 1 .Problem 9. and multiplications by WN ). 1 − b. Its 4-FFT is easily found to be X = [16. 1. With arbitrary values of a and b: x = [6 − a.33. k. X) int N. a]. 0. 2. 0. double *x. 0 . It can also be obtained by picking every other entry of the 8-point DFT. The final expressions that construct X(k) are the standard Butterfly operations for merging G(k) and H(k). . one = cmplx(1. it will satisfy the hermitian property ∗ Y2N−k = Yk . halfj. and the results of Problem 9. x1 . 2N − 1 The operation of delay on the reflected signal then gives: At k = N. Next. . 1. . 0. xR ]= [x. Replacing Yk in terms of Ck gives for n = 0. we get k Yk = Y(ωk )= X(ωk )+ejωk X(−ωk )= ejωk /2 e−jωk /2 X(ωk )+ejωk /2 X(−ωk ) = 2ejωk /2 Re e−jωk /2 X(ωk ) where we used the hermitian property X(−ω)= X(ω)∗ . In terms of Ck . we used X(z−1 )= X(−ωk )= X(−k)= X(N − k) by the periodicity of the k N-point DFT. -2*pi/N)). . Y). . temp = cmul(Wk. . xR ] N zeros N zeros Thus. we have in the z-domain: Y(z)= X(z)+z−N XR (z)= X(z)+z−2N+1 X(z−1 ) where the factor z−N represents the delay of xR by N samples. Y = (complex *) calloc(Nhalf. k++) { if (k==0) temp = conjg(Y[0]).0. X[k+Nhalf] = csub(Gk. 1. x0 ] It follows that −1 −2 −3 It follows that Yk = 2ejωk /2 Ck = 2ejπk/2N Ck + x2 z + x3 z −2 ⇒ ⇒ X(z)= x0 + x1 z XR (z)= x3 + x2 z −1 + x1 z + x0 z−3 Because Yk is the (2N)-point DFT of a real-valued signal. W = cexp(cmplx(0.0. N − 1: where in the last step. Wk = cmul(W. . n++) Y[n] = cmplx(x[2*n]. else temp = conjg(Y[Nhalf-k]). . temp). sizeof(complex)). n<Nhalf.36. k<Nhalf. . 1. for (Wk=one. xn = 1 2N 2N−1 2ejωk /2 Ck ejωk n = k=0 1 2N−1 N Ck ejωk (n+1/2) k=0 208 209 . using linear superposition. Hk. the reversed signal xR is delayed by N samples. half. 0]+[0. 0.0).0. . } } Wk = Wk note: Y(0) = Y(N/2) Problem 9. The quantity under the real part is now: N−1 N−1 G(k) H(k) Wk H(k) next Wk = Wk+1 G(k) + Wk H(k) e−jωk /2 X(ωk )= e−jωk /2 n=0 xn e−jωk n = n=0 xn e−jωk (n+1/2) G(k) − Wk H(k) Thus. Replacing z by zk = ejωk . . k=0. . we have: Y2N−k = 2ejπ(2N−k)/2N C2N−k = 2ejπ e−jπk/2N C2N−k = −2e−jπk/2N C2N−k XR (z)= z−3 [x3 z3 + x2 z2 + x1 z + x0 ]= z−3 X(z−1 ) ∗ Yk = 2e−jπk/2N Ck In the time domain. x2 . it gives C2N−N = −CN or CN = −CN which implies CN = 0. 0. we have x = [x. Gk = cmul(half. cadd(Y[k]. that is. halfj = cmplx(0. . 0. 0. Hk = cmul(halfj. fft(Nhalf. we have: Z xR (n)= x(N − 1 − n)= x(−(n − N + 1))− z−(N−1) X(z−1 ) → −k The N-point DFT of the reversed signal is obtained by setting z = zk = e2πjk/N = WN . For N = 4. csub(Y[k]. we have: x = [x0 . 0.36 An example will demonstrate the result. k=0 n = 0. . . . . x3 ] xR = [x3 . x2 . 2N − 1 XR (k)= z−N+1 X(z−1 )= WN k k (N−1)k −k X(−k)= WN X(N − k) But the first N samples of yn are precisely xn . its real part is the cosine transform: N−1 Re e−jωk /2 X(ωk ) = n=0 xn cos ωk (n + 1/2) = Ck Problem 9. X[k] = cadd(Gk.5. complex *Y. temp)).0). half = cmplx(0. temp. temp). Using N the property WN = 1. Gk. the delay property of z-transforms. Hk).5). -0. .37 In the definition of y. we find: yn = 1 2N 2N−1 Yk ejωk n . x1 . temp)). the operation of reflection leads to the z-transform pairs: Equating the right-hand sides and canceling the common factors gives the symmetry property x(n)− X(z) → Z ⇒ → x(−n)− X(z−1 ) Z C2N−k = −Ck . k = 0. W. x[2*n+1]). and using the result z2N = 1. considering the inverse DFT for Yk .complex one. . for (n=0. . Wk. Wk). 1] The overlap-save method divides the input signal into segments of length N = 8 that are overlapping by M = 3 points. 0] Abutting the rest of the points. 0. −1. 0. (1. we can write 2N−1 ik Xi (zk )= z−i X0 (zk )= W5 X0 (zk ). −2. − 2 . 1. 0. 0. 1. 2 . 0][−2. 0. 0. −1. 0] = [1. x. 3. 0. −1. (3. 0. the first and the third. x. 0. 2. 2 . 0. 3] = [1.41 Using the convolution table. x. Problem 9. 1][0. the answer is correct. 1. −2. 2. 0 . 0. we obtain −k i = 1. 4 where the second summation starts at k = N + 1 because CN = 0. 1. 1. for example. 0. 0. − 1 . 0. 1. 2. 1]∗[1. 1. 1. 2. 3 . −3. −2. 2. 1 . 0. we have ejω2N−m (n+1/2) = ejπ(2N−m)(n+1/2)/N = e2jπ(n+1/2) e−jπm(n+1/2)/N = −e−jωm (n+1/2) we have (with the two minus signs canceling): N−1 N−1 X3 (z)−X1 (z)= x6 z−2 (1 − z−4 )+x7 z−3 (1 − z−4 )= (x6 z−2 + x7 z−3 )(1 − z−4 ) Cm e −jωm (n+1/2) C2N−m e m=1 jω2N−m (n+1/2) = m=1 Evaluating at the 4th roots of unity. x. 0. 1]∗[3. k = 0. x. 2. 0][−1. that is. 1 . 0. 0. 0 . 0.39 Observe that the five length-5 sequences are the mod-5 wrapped versions of the following “linearly shifted” sequences: x0 0 0 0 0 x1 x0 0 0 0 x2 x1 x0 0 0 x3 x2 x1 x0 0 x4 x3 x2 x1 x0 0 x4 x3 x2 x1 0 0 x4 x3 x2 0 0 0 x4 x3 0 0 0 0 x4 0 0 0 0 0 210 211 . 1. − 1. −1. 1. 1. 1. 0] ˜ y2 = [x. 0.Next. 0] = exp −2πj2nk/2N = exp −2πjnk/N = L−1 L−1 2nk x(n)W2N = Thus. 3 xn = 1 N−1 N−1 N C0 + k=1 Ck ejωk (n+1/2) + k=1 Ck e−jωk (n+1/2) Problem 9. −1. 0. 2. 4 N−1 Ck ejωk (n+1/2) = k=N+1 m=1 C2N−m ejω2N−m (n+1/2) Problem 9. x. 2N−1 xn = 1 N−1 N C0 + k=1 Ck ejωk (n+1/2) + k=N+1 Ck ejωk (n+1/2) Setting z = zk = e jωk Xi (z)= z−i X0 (z). 3. −1. 1. 0.40 Consider. 3. 0. 1. 0 . 1]∗[1. −1. 1] y3 = [1. −1. 1]∗[1. 2 . 1. 1. 0] With the exception of the first M points. 1] = [1. 0] ˜ y1 = [x. −1. 1. 0 . 2. 2nk x(n)W2N y0 = [1. Their z-transforms are Using the symmetry property C2N−m = −Cm . 3] y1 = [1. and the trig identity X1 (z) = x0 + x1 z−1 + x2 z−2 + x3 z−3 + x4 z−4 + x5 z−5 + x6 z−6 + x7 z−7 X3 (z) = x0 + x1 z−1 + (x2 + x6 )z−2 + (x3 + x7 )z−3 + x4 z−4 + x5 z−5 Subtracting. we get y = [x. 0. as shown below: x= 1. 1. −1. 0. 1. 2. −1. 3. 1. 2. 0. 1. 3.38 By definition. 0. 0. 1. 2. we obtain: ˜ y0 = [x. −1. −2. −1. If we change variables from k to m = 2N − k. x. 0) The two summations now combine with Euler’s formula to give: xn = 1 N−1 N C0 + 2 k=1 Ck cos ωk (n + 1/2) Problem 9. 2. z = zk = e2πjk/4 . the inverse DFT becomes (changing the summation from m back to k): X3 (zk )−X1 (zk )= 0. 0. 2 . 0. 1. 0. 3 . 1] ˜ y3 = [x. 0. − 1 . 0. 3 . = W5 . −2. 0. 1. we obtain Thus. 2. −1. −1. 1. 1. −1. 2nk W 2N ⇒ X2N (2k)= n=0 nk WN . 2. 1. −3. perform the ordinary linear convolution of the given signal and filter to get y = h ∗ x = [ 1. 2] = [3. 3. 3. 0. −1. X2N (2k)= n=0 nk x(n)WN = XN (k) n=0 Reducing these mod-8 and ignoring their first M = 3 points (indicated by x). x. −1. − 1 . 0. 2] y2 = [1. 2). 0. −3. 0. k i = 1. −1. 2. 0 . 1. −1. 1. x. x. − 2 . we have L−1 L−1 nk x(n)W2N n=0 Convolving these segments with the filter gives: X2N (k)= But. 0. 0. 0. 0. we split the summation into three terms: Their z-transforms differ by a simple delay factor. "r")) == NULL) { fprintf(stderr. the total number of segments can be estimated to be: K= L N−M Per segment.5 ⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎦ DFT − → ⎢ −j(2 + √2) ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ 0 ⎢ ⎥ √ 1 ⎢ j(2 − 2) ⎥ ⎢ ⎥ ⎥. which gives: Problem 9. N.. void main(int argc. "%lf".7.5 . we will have: if (argc != 3) { fprintf(stderr. *xhead. n.9.2) In Fig. M = filter order N log2 N + N = N(1 + log2 N) per segment Thus. namely.4). ifft(). the input blocks have length N − M and are non-overlapping. char **argv) { FILE *fph. − 0 . Thus. fft().42 At fs = 8 Hz. preliminary allocation L = (N − M)K + M (N − M)K which is essentially the same as in Eq. 0 .5 1 0. the relative cost of the fast versus slow convolution will be: fast = slow x(n)= 1 { 0 . for (M=0.5 .) Thus. complex *H. 0 . if there are K blocks in the total length. (max + 1) * sizeof(double)). argv[1]). 5 . − 0 . "usage: fastconv hfile N < xfile exit(0). These samples can be evaluated by setting t = nT = n/8 in the expression for x(t). for K segments. } > yfile\n"). sizeof(double)). *X. we have cost: KN(1 + log2 N)= LN(1 + log2 N) N−M if (N <= 2*M) { fprintf(stderr. we have in the overlap-save method: if ((fph = fopen(argv[1]. } if (fscanf(fph. there are 8 samples per period. if necessary max += dmax. the total length will be (N − M)K plus an extra M points at the end. − 1 . int M. we treat these MACs as complex-valued.5 −1 − 0. 2*M). 1 . *x. we are doing two FFTs and N multiplications. h = (double *) realloc((char *) h. whereas b3 and b5 correspond to ±f2 = ±3 Hz. Thus. h + M) == EOF) break. (9. the aliased coefficients can be obtained by computing the 8-point DFT of one period and dividing by 8. but again if there are K segments. ⎡ ⎢ ⎢ ⎢ ⎢ ⎢ 1⎢ ⎢ x= ⎢ 4⎢ ⎢ ⎢ ⎢ ⎢ ⎣ 0 0 . *Y.44 An example of such a program is given below: /* ovsave. Thus. exit(0). dmax = MAX. exit(0).h> #include <cmplx.Problem 9. int max = MAX.1. complexify(). double *h.c .5) and after using Euler’s formula: xal (t)= 2jb1 sin(2πf1 t)+2jb3 sin(2πf2 t)= 2+ 2 2− 2 sin(2πt)− sin(6πt) 16 16 √ √ filter file x = length-N block N-point DFTs It can be verified easily that xal and x(t) agree at the sampling instants t = nT = n/8. realloc() initial allocation size The coefficients b1 and b7 correspond to frequencies ±f1 = ±1 Hz. h = (double *) calloc(max + 1.7. X= ⎢ ⎥ 0 4⎢ ⎢ ⎥ √ ⎢ −j(2 − 2) ⎥ ⎢ ⎥ ⎢ ⎥ ⎣ ⎦ 0 √ j(2 + 2) ⎡ 0 ⎤ ⎡ ⎢ ⎢ ⎢ ⎢ ⎢ 1⎢ ⎢ b= ⎢ 4⎢ ⎢ ⎢ ⎢ ⎢ ⎣ 0 √ (2 + 2)/8j 0 √ −(2 − 2)/8j 0 √ (2 − 2)/8j 0 √ −(2 + 2)/8j ⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎦ calloc(). "can’t open filter file: %s\n". (P9.h> #define MAX 64 void circonv().5 } 4 LN(1 + log2 N) N(1 + log2 N) N−M = L(M + 1) (N − M)(M + 1) According to Eq. M++) { read h if (M == max) { reallocate h. i. 0 . L = (N − M)K (P9. } N = atoi(argv[2]). in both cases.5 0 − 0. "must have N > 2M = %d". } 212 213 . This DFT can be done quickly by an 8-point FFT by hand. 9. Thus. we find from Eq.43 In the overlap-add method.2) for large L. (9. the input blocks overlap by M points.h> #include <stdlib. Problem 9. We find: This is to be compared with the cost of L(M + 1) of linear convolution of the entire input array with the filter (here.FIR filtering by overlap-save method and FFT */ #include <stdio. } M--. complex *H. sizeof(double)). i<N.) { for (n=0. n++) printf("%lf\n". 0) done by fft discard first M points. for (i=M. save the rest void circonv(N. double *x. X[k]). fft(N. x + n) == EOF) goto lastblocks. k++) Y[k] = cmul(H[k]. circonv(N. Y). for (. complexify(N. for (n=0. process very last block if n > N-M. must be done previously n = index where EOF occurred for (i=n. for (k=0. H = (complex *) calloc(N.0).. n<N. X. circonv(N. pad rest of x with zeros if n <= N-M there is only one last block to consider otherwise. sizeof(complex)). k<N.M]. complexify(N. X. X = (complex *) calloc(N. the tail of previous block will be non-zero head of very last block 214 215 . Y) int N. *Y. circonv(N. n++) xhead[n] = 0. X). i<N. X). X) int N.0. for (n=0. x. n<M. n++) if (scanf("%lf".M]. n<N. n++) x[n] = xhead[n]. H. n++) if (n <= M) H[n] = cmplx(h[n]. X. *X. X).0). i<N. real(Y[i])). x. for (i=M. sizeof(complex)). { int k. real(Y[n])). fft(N. i++) printf("%lf\n". for (n=0. Y = (complex *) calloc(N. n++) X[n] = cmplx(x[n]. complex *X. (M+1) * sizeof(double)). for (n=0. there are two last blocks exit. x = (double *) calloc(N. i++) xhead[i] = x[i + N . { int n. n<N. n<N. head/tail of input block xhead = (double *) calloc(M. i<N. n<M. i++) printf("%lf\n". X. real(Y[i])). x. 0. 0. x. for (i=0. rest of block is zero complexify/extend to length N } ——————————————————————– H = FFT(h). 0. sizeof(complex)). Y). n++) xhead[n] = x[n + N . sizeof(double)). Y). done once pad M zeros in front of first block keep reading input in blocks x previous tail is head of present block x void complexify(N. i++) x[i] = 0. } lastblocks: tail of present block x will be head of next block X = cmplx(x. else H[n] = cmplx(0. } ——————————————————————– read rest of x from input stream for (n=M. H). for (n=M. i++) if (i < M) x[i] = xhead[i]. allocate DFT arrays x[i] = 0. if (n <= N-M) exit(0). if only one last block otherwise. Y). ifft(N. H.else h = (double *) realloc((char *) h. H. H. } circular convolution via FFT H = FFT(h). X).0). i<M. n<M. complexify(N. for (i=0. it will have d(0)= 0. Performing the differentiation.1 Start with ∞ Problem 10. d(0)= 0 because it must satisfy d(−0)= −d(0). we have π ωc −ωc D(ω)= k=−∞ d(k)e−jωk = ∞ k=−∞ d(−k)e−jω(−k) = − ∞ k=−∞ d(k)e−j(−ω)k = −D(−ω) d(k)= Together with the reality condition. and its equal to unity for k = 0. 216 217 . Because d(k)= d(−k). Setting d(−k)= −d(k) in the sum. In the latter. or by recognizing the integrand as the derivative with respect to k (treating k initially as a real variable and at the end restricting it to integer values. we have: d(k)= sin(πk)− sin(ωb k) πk D(ω)= k=−∞ d(k)e−jωk = ∞ k=−∞ d(−k)e−jω(−k) = ∞ k=−∞ d(k)e−j(−ω)k = D(−ω) The first term is zero for all non-zero k. we set d(−k)= d(k) and combine the two sums with Euler’s formula to get: ∞ d(k)= ωc cos(ωc k) sin(ωc k) − πk πk2 Setting ωc = π gives the full-band differentiator: D(ω)= d(0)+2 k=1 d(k)cos(ωk) (symmetric case) d(k)= cos(πk) k − sin(πk) πk2 For the antisymmetric case. we can rewrite D(ω) in the form: ∞ It can be evaluated either by parts.Chapter 10 Problems Problem 10. Thus. and ωb = π the highpass one. see the more general cases of Problem 10. we may replace it by δ(k): Thus. we get −π D(ω)ejωk dω = 2π jωejωk dω 2π D(ω)= D(−ω)∗ = −D(−ω) which implies that D(ω) is pure imaginary and odd in ω. In the antisymmetric case. we can change the summation from k to −k to get: ∞ Setting ωa = 0.3.2 For the bandpass example. Thus. Taking conjugates and replacing ω by −ω.3 For the lowpass differentiator. the reality and evenness conditions imply together: d(k)= δ(k)− sin(ωa k) πk D(ω)= D(−ω) = D(−ω) which states that D(ω) is both real and even in ω.and positive-k terms. Problem 10. we use the fact that D(ω)= 1 over the passband ωa ≤ |ω| ≤ ωb to get: π d(k) = d(k)e −jωk D(ω)= k=−∞ −π D(ω)ejωk ejωk −e dω = 2π ωb ωa −ωa −ωb D(ω)ejωk dω + 2π −ωa ωb ωa D(ω)ejωk ejωk 2πjk ωb ωa dω = 2π and assume that d(k) is real and even in k. The second term vanishes for nonzero integer ks. we obtain: ∞ Because d(k) belongs to the antisymmetric class. and therefore ∞ ∗ For the differentiator and Hilbert transformer.) d(k)= ∂ ∂k ωc −ωc ejωk dω ∂ = 2π ∂k sin(ωc k) πk D(ω)= d(0)+ k=1 d(k)e−jωk + −1 k=−∞ d(k)e−jωk = d(0)+ ∞ k=1 d(k)e−jωk + ∞ d(−k)ejωk k=1 where the ω-integration gave the standard lowpass filter. gives the lowpass case. gives = = −ωa −ωb dω + 2π −jωb k ejωk dω = 2π jωa k ejωk 2πjk = + −ωb D(−ω)∗ = ∞ d(k)ejωk k=−∞ ∗ ∞ = k=−∞ d(k)e−jωk = D(ω) e −jωa k 2πjk + e jωb k −e sin(ωb k)− sin(ωa k) 2πjk πk This result uses only the reality of d(k) and is the usual hermitian property for transfer functions of real-valued impulse responses. we have for k = 0: D(ω)= −2j k=1 d(k)sin(ωk) (antisymmetric case) d(k)= cos(πk) k = (−1)k k (differentiator) The Hilbert transformer case is similar. Separating the negative. we get the required expression for d(k): In the symmetric case. we have d(−k)= −d(k). 3. for the differentiator filter. we have ∞ M Thus. it increases rapidly with ωc . thus canceling the first term and resulting in EM → 0. the second term in the right-hand side tends to the Parseval limit. we expand the frequency response at low frequencies: But the left-hand side is twice the required sum: ∞ H(ω)= 1 − e −jω 1 − (1 − jω)= jω for small ω Thus. Using Parseval’s identity we have ∞ π ⇒ H(z)= 1 − z −1 ⇒ H(ω)= 1 − e −jω h2 0 + h2 1 =1+1=2 d2 (k)= k=−∞ −π |D(ω)|2 dω = 2π π −π ω2 dω π2 = 2π 3 Thus. k=0 Problem 10. EM = π −π |D(ω)−D(ω)|2 ∂ d(k)= ∂k sin(ωb k)− sin(ωa k) dω = d2 (k) 2π |k|>M πk The right-hand side sum can be written with the help of Parseval’s identity applied to D(ω) itself: ∞ π which becomes the difference of two lowpass differentiators: ωb cos(ωb k) ωa cos(ωa k) sin(ωb k) sin(ωa k) − + d(k)= − πk πk2 πk πk2 d2 (k)= |k|>M k=−∞ d2 (k)− |k|≤M d2 (k)= −π |D(ω)|2 dω − d(k)2 2π k=−M M Problem 10. the NRR will be NRR = In the limit as M → ∞. we have in this case: Parseval’s identity applied to e(k) gives then π ωb ωa d(k)= ∂ ∂k −ωa −ωb ejωk dω + 2π ejωk dω 2π −π |E(ω)|2 dω = e2 (k)= d2 (k) 2π k=−∞ |k|>M ∞ or. and frequency response: h = [ 1 . The integrations give the bandpass filter case. Thus.5 For the first-order differentiator.4 Using the differentiation argument. the noise power doubles at the output. we have impulse response. the NRR can be computed as: NRR = ωc −ωc |D(ω)|2 dω = 2π ωc −ωc |jω|2 ω3 dω = c 2π 3π 2 k=1 1 k2 = π2 3 ∞ ⇒ k=1 1 k2 = π2 6 Thus. Thus. d(k) is nonzero only for odd k. To see how closely it resembles the ideal differentiator. we have ωc π 3 d(k)= 1 − cos(πk) πk = 1 − (−1)k πk . we have NRRmax = π3 /3π = π2 /3 and therefore. the time-domain coefficients of the error are: d2 (k)= 2 k=−∞ k=1 k=odd 4 π2 k2 e(k)= 0 d(k) if |k| ≤ M if |k| > M Thus.Problem 10. NRR = NRRmax For the full-band Hilbert transformer. Then. transfer function. we have d(k)= (−1)k /k. − 1] Thus. we obtain 218 219 . ∞ d2 (k)= k=−∞ k=0 1 ∞ k2 =2 k=1 1 k2 For the ideal lowpass differentiator case. and is in this case d(k)= 2/πk. k = 0. Compared to the full-band maximum NRR obtained with ωc = π. Problem 10.7 From Problem 10. Parseval’s identity applied to this filter gives: ∞ π d2 (k)= k=−∞ −π |D(ω)|2 dω = 2π π −π |jsign(ω)|2 dω = 2π π −π 1 dω =1 2π E(ω)= D(ω)−D(ω)= k=−∞ d(k)e−jωk − k=−M d(k)e−jωk = |k|>M d(k)e−jωk The left-hand side on the other hand becomes: ∞ ∞ because the coefficients d(k) cancel for |k| ≤ M.6 Let E(ω)= D(ω)−D(ω) be the error in the designed filter. then z∗ is also a zero. the transfer function will be z∗ = 0. it follows that if z0 is a zero. Using the antisymmetry property and splitting the sum in two parts. − 3 . 1/z0 and 1/z∗ are both zeros. D(ω) vanishes. we have for the outputs: 1 −jsign(ω)ejωn − jsign(ω)e−jωn = −sign(ω)cos(ωn) → sin(ωn)− 2j D Setting ω = 0. then because the window w(k) is symmetric with respect to the origin. we have in particular for z = ±1. In the symmetric/antisymmetric cases. P10. the symmetry/antisymmetry properties of d(k) will be preserved and will imply similar results on the locations of the zeros.5 − 0. M D(z−1 )= ± k=−M d(k)z−k = ±D(z) H(z)= 1−(0.5z−2 −3z−3 +z−4 In the time domain.5j. 220 221 .5j. Thus. and using the odd symmetry property of D(ω).9 From the definition of D(z). because sin(ωn)= [ejωn − e−jωn ]/2j. 3 .1 Pattern of zeros of linear phase filters. − 3 . forming the same linear combination of outputs.5+0. − 3 . Therefore. that is. we have in addition two zeros at z = ±1 contributing a factor (1 −z−2 ) to the transfer function.5z−2 − 3. we get the length-5 symmetric (about its middle) impulse response: h = [ 1 . we have: M M M Problem 10. Thus.5−0.5z−2 − 3z−3 + z−4 )= 1 − 3z−1 + 3. 1] In the antisymmetric case. it follows that the zeros will come in conjugate pairs if they are complex.1.5j)z−1 1−(1−j)z−1 1−(1+j)z−1 = 1−3z−1 +4. it follows by subtraction that the sum over even integers will be: ∞ k=2 k=even * z0 1 k2 = π2 6 − π2 8 = π2 24 1/z0 Fig. z∗ .5j)z−1 1−(0. jωn M e jωn − D(ω)e → D jωn = −jsign(ω)e Replacing ω by −ω. 0 1 z0 = 1 − j. 0 . Thus. Finally.5 . 1 z∗ 0 =1+j where in the last step we changed summation from k to −k. P10.∞ 2 k=1 k=odd 4 ∞ π 2 k2 =1 ⇒ k=1 k=odd 1 k2 = π2 8 * 1/z0 z0 If the sum for all integers k is π2 /6 and for odd ones π2 /8. π.10 For the symmetric case. Problem 10. we have d(k)= ±d(k). − 1 ] ∗ } are shown in Fig. and therefore. 5 . From the symmetry or antisymmetry 0 properties. d (k)= w(k)w(k). we have: D(±1)= k=−M d(k)(±1)k = 0 e−jωn − D(−ω)e−jωn = jsign(ω)e−jωn → But cos(ωn)= [ejωn + e−jωn ]/2. 0 0 1 ∗ If z0 lies on the unit circle then because 1/z0 = z0 . From the reality of d(k). we note that if d(k) is windowed by a window w(k). corresponding to z = ±1. 5 . the only other distinct zero is the complex conjugate.5z−4 + 3z−5 − z−6 and in the time domain: h = [ 1 . 4. 3 . we get: M M M 1 −jsign(ω)ejωn + jsign(ω)e−jωn = sign(ω)sin(ωn) 2 D(ω)= k=−M d(k)e−jωk = k=1 d(k) e−jωk − ejωk = −2j k=1 d(k)sin(ωk) Similarly. − 3 . The same conclusion follows from the frequency response. 1 H(z)= (1 − z−2 )(1 − 3z−1 + 4. if z0 is a complex zero. z 0 z0 . then D(z−1 )= ±D(z0 )= 0 0 Thus. The four zeros {z0 . we have: cos(ωn)− → D D This follows because d(k) is odd and summed over symmetric limits and because the factor (±1)k is even in k. Problem 10. we have sin(ωk)= 0.5 + 0. Thus.8 The sinusoidal response of D(ω) in its steady-state form is: In the antisymmetric case. the following must necessarily be zeros: D(z)= k=−M d(k)z−k ⇒ D(z−1 )= k=−M d(k)zk = k=−M d(−k)z−k z0 = 0. 05 dB Problem 10. we find the transfer function of the symmetric case: Δf = Dfs 5. the transition width is required to be: Δf = 24. −1] The corresponding ripple will be Problem 10.25z −2 +z −4 −3.5 H(ω)= 2e−2jω cos(2ω)−3 cos(ω)+4.017 14.25.25.25.36 Inserting this into the Kaiser design formula.805 14. which in dB is A = −20 log10 δ = Astop = 80.12 We use the first-order Taylor series approximation: ln(1 ± x) Changing to base-10.15 The window’s width factor is D = 5. 3.1 = = 1.2007 kHz = N−1 251 − 1 Problem 10.017 · 10 Dfs = 0.2.34 =1+ 0.5jz−1 )(1−2jz−1 )(1+2jz−1 )= 1+4.000027 which gives the passband attenuation: ±x Apass = 17.0001.36 4f s ⇒ A = 14.5jz−1 )(1+0. we find the minimum width (where we used N instead of N − 1 in the denominator): The transition width is Δf = fstop − fpass = 2 − 1.36D + 7.55 − 19. −3.0058.25z −4 −z −6 A − 7. we calculate δpass and δstop from Eq. 0.36 fs ⇒ A = 14. 100.017 · 44.55 = 5 kHz This gives the width factor and attenuation: Apass = 20 log10 1 + δpass 1 − δpass = 20 log10 (1 + δpass )−20 log10 (1 − δpass ) D= 20 · 0.857.95 = 5.95 Δf = (N − 1) = 5.31/20 = 0.25z−2 +z−4 and for the antisymmetric case: ⇒ h = [1.5 kHz. Thus. δstop )= δstop = 0.1/20 + 1 Assuming that an N-tap filter requires approximately N instructions for processing each input sample. (10.000472 dB In the 4-times oversampling case. The D and α parameters are computed by: Nmax = T finstr = Tinstr fs α = 0.25z −2 H(z)= (1−z −2 )(1+4.017 as in the previous problem.0001 Therefore. the filter length will be: Δf = N =1+ 5. that is.5 For the antisymmetric case. H(z)= z−3 (z3 − z−3 )−3(z2 − z−2 )+3. then we may solve for the D-factor and attenuation A: D= )= 1+3.7)= 7.16 Problem 10.4343 x ln(10) δ = 10−A/20 = 10−91. we have: ⇒ Δf = Dfs N−1 As in the previous problem.5): 100.13 First.4343 δpass = 17.95 = 60. we have: log10 (1 ± x)= It follows that ln(1 ± x) = ±0. 0.The frequency response in the symmetric case is obtained by factoring out a factor of z−2 and using Euler’s formula: Problem 10.729 kHz N−1 129 − 1 H(z)= (1−0. the maximum filter length will correspond to the maximum number of instructions that fit within the sampling interval T.1102(80 − 8. 0. Problem 10. 5 Δf Dfs Dfs = N finstr 2 ⇒ N = 103 222 223 . 4. δpass = δstop = 10−80/20 = 0. δ = min(δpass .11 Proceeding as in the previous problem.31 dB ⇒ h = [1. if Δf = 2 kHz.017. therefore. 0.017 · 10 Dfs = 101. we find D = 5.14 The transition width is inversely related to the filter length N: H(z)= z−2 z2 + z−2 − 3(z + z−1 )+4.5(z − z−1 ) H(ω)= −2je−3jω sin(3ω)−3 sin(2ω)+3.372 δpass A − 7.1/20 − 1 = 0.5 sin(ω) ⇒ Δf = 5.4343 δpass + 20 · 0.1102(A − 8.6281 14.7)= 0.36D + 7.95 Δf = (N − 1) = 3. 0. 1] Conversely. D= A − 7.5 = 0.95 = 91. Thus.372 δ = 0. P10. The filter lengths depend only on the values of Δf and A. omega). omega = (0:NF-1) * pi / NF. fstop. N).Problem 10. wc.2 and P10. Apass.20 Use the design MATLAB routine kdiff. A = 60 dB. fs. NF = 200.1. fpass.95 Δf 0. Apass = 0. fsa.1. fpb = 6. h = kbp(fs. Δω = 0.95 Δf finstr Δf =N = = Finstr ΔF 2 14. π] % frequency response For example. H = dtft(h. fpass = 5.36 fs fs ⇒ A = 14.05.4π. H = dtft(h. 0.46 * cos(2 * pi * (0:N-1) / (N-1)). omega). the f ’s are the ω’s in units of π. in kHz in dB % s = −1 for highpass Fig.4. fstop = 4. fpb. fsb. omega = (0:NF-1) * pi / NF.36Finstr ΔF + 7. Apass = 0. with fs = 2 so that ω = 2πf /2 = πf . N = 81. omega = (0:NF-1) * pi / NF.18 The following MATLAB program segment computes the rectangularly and Hamming windowed impulse responses with the help of the MATLAB function dlh. P10. Hham = dtft(hham. NF = 200. in the case ωc = 0. hrec = dlh(1. w = 0.05π. the highpass filter can be designed by: fs = 20.4π. 224 225 . 60).17 Using N = finstr /fs for the maximum filter length.05 A 30 60 30 60 N 33 75 63 147 Problem 10.10 0.m. fsa = 3. we have the MATLAB code: h = kdiff(2. Astop = 80. π] with the help of the function dtft. fpa = 4. in kHz in dB % s = −1 for alternative design Similarly. H = dtft(h. we obtain the maximum width parameter D and attenuation A: Problem 10. Astop = 80. Astop). omega = (0:NF-1) * pi / NF. h = klh(-1.2.19 As an example. -1). % cutoff frequency % filter length % Hamming window % ideal lowpass filter % windowed filter % 200 frequencies in rads/sample % over the interval [0. Problem 10. they are: D= A − 7.3 * pi. hham = w .2 Lowpass differentiator with ωc = 0. Hrec = dtft(hrec.10 0. omega).2 (alternative design): fs = 20.05 0. omega). Apass. The magnitude responses are shown in Figs. NF = 200. fsb = 8. NF = 200.3. omega). Astop. and then it computes the corresponding frequency responses over NF equally spaced frequencies over the right half of the Nyquist interval [0. that is. the following MATLAB program segment computes the bandpass filter of Example 10.0.54 . fpa. 0.* hrec.m: wc = 0. Δω = 0.46 * cos(2*pi*n/(L-1))) . G(:. n = (0:L-1). P10.m: F1 = 0. NF = 256. The filter lengths depend only on the values of Δf and A. Xkmax = max(Xk). omega)). P10. same as in Problem 10. omega = (0:NF-1) * pi / NF. G = dtft(g. P10.4 Comparison of Kaiser and SG differentiators. The Kaiser window parameters are determined by the function kparm2.* x.0. omega). the Hilbert transformer with ωc = 0.20. Xk = abs(dtft(xk. 0. A3 = 1. % units of fs % amplitudes % sidelobe level in dB % Kaiser parameters NF = 500. S * F^(-1). the f ’s are the ω’s in units of π. F = G = g = S] = sg(3.8. % Kaiser windowed signal % Hamming windowed signal The magnitude responses are shown in Fig.30. P10. % Kaiser differentiator % Savitzky-Golay smoothing filters % polynomial basis matrix % Savitzky-Golay differentiator filters % first-order derivative filter Problem 10.22 Use the design MATLAB routine khilb.3 Lowpass differentiator with ωc = 0. omega). H = dtft(h.Fig. For example. A2 = 10^(-50/20). Xh = abs(dtft(xh.8π. omega = (0:NF-1) * pi / NF. Δω = 0. with fs = 2 so that ω = 2πf /2 = πf . L) .4. F3 = 0.05. in the case ωc = 0. H = dtft(h. 0. 0. Problem 10.05π. % DTFT spectrum % normalized and in dB Problem 10. % frequency responses xk = kwind(alpha.4.25. omega).5 and P10. 0. [alpha. x = A1 * cos(2*pi*F1*n) + A2 * cos(2*pi*F2*n) + A3 * cos(2*pi*F3*n). % frequency responses Fig.8π. can be designed by the MATLAB segment: h = khilb(2. xh = (0. S’ * S.6. R = 70. they are the 226 227 .05π.4π. and A = 60 dB. F2 = 0. [B. N). omega)).54 .05. that is.21 For example. Xk = 20 * log10(Xk / Xkmax). DF = (F2-F1)/3. A1 = 1. 60). omega = (0:NF-1) * pi / NF. L] = kparm2(DF.2)’.20.* x. R).23 The following MATLAB segment computes the Kaiser and Hamming spectra in dB. we have the MATLAB segment that computes the Kaiser differentiator and the Savitzky-Golay differentiators of polynomial order d = 3: h = kdiff(2. 60). The magnitude responses are shown in Figs. NF = 200. A = 60 dB. P10.5 Lowpass Hilbert transformer with ωc = 0. P10. 228 229 . Xh = 20 * log10(Xh / Xhmax). Xhmax = max(Xh). Fig.Fig.8π.6 Full-band Hilbert transformer. For the arithmetic. gB )γ2 Ω2 0 Then. or. we obtain the approximate expression Δω = 2(1 − R). if we take them also to be related by the substitution gB → g−1 .3 For the 3-dB case. 0 ≤ β ≤ 1. gB )= 1 . gB )= D(g. However. expanding R to first-order in β and thus to first-order in Δω. Indeed. This range covers most practical applications. Normalizing everything to the reference gain G0 .1 Here. g−1 )γ2 Ω2 0 B (Ω2 − Ω2 )2 +D(g−1 . g−1 )= D(g. g 1 . gB )γ2 Ω2 0 |Hcut (Ω)|2 = G2 0 (Ω2 − Ω2 )2 +N(g−1 . Adding the two transfer functions. D(g. the boost and cut magnitude responses are: B |Hboost (Ω)|2 = G2 0 (Ω2 − Ω2 )2 +N(g. g−1 }. then we can B show that the boost and cut filters are inverses to each other. gB )= 1 (arithmetic) gB = g .2 For small values of Δω. that is. g2 − g2 B D(g. B D(g−1 . then there are two real poles. (Ω2 − Ω2 )2 +D(g. g2 − g 2 B where g= G . gB )= g . gB )= g2 . the functions N and D interchange roles. the substitution g → g−1 changes a boost into an equal and opposite cut. g−1 )= N(g.Chapter 11 Problems Problem 11. D(g. gB )γ2 Ω2 0 (Ω2 − Ω2 )2 +D(g. the parameter b is the same for both filters. Solving for N(g. This condition implies that the poles are complex conjugate and have radius Problem 11. Even though the boost and =1 cut gains are equal and opposite. we have neff = ln ln R |H(Ω)|2 = G2 0 Problem 11. gB )= g2 − 1 B g2 − g 2 B where we used the Taylor expansions (1 ∓ x)±1/2 1 − x/2 and (1 − x/2)2 Δω. 0 ≤ Δf ≤ fs /4 in Hz. g2 Hnotch (z)+Hpeak (z) = b = 1 − z−2 1 − 2 cos ω0 z−1 + z−2 + (1 − b) 1 − 2b cos ω0 z−1 + (2b − 1)z−2 1 − 2b cos ω0 z−1 + (2b − 1)z−2 1 − 2b cos ω0 z−1 + (2b − 1)z−2 b(1 − 2 cos ω0 z−1 + z−2 )+(1 − b)(1 − z−2 ) = 1 − 2b cos ω0 z−1 + (2b − 1)z−2 1 − 2b cos ω0 z−1 + (2b − 1)z−2 For the magnitude responses squared we may use the equivalent analog expressions to get: |Hnotch (ω)|2 +|Hpeak (ω)|2 = |Hnotch (Ω)|2 +|Hpeak (Ω)|2 = (Ω2 − Ω2 )2 α 2 Ω2 0 + =1 (Ω2 − Ω2 )2 +α2 Ω2 (Ω2 − Ω2 )2 +α2 Ω2 0 0 Now. we may use the first-order Taylor expansion tan(x) imately: (Ω2 − Ω2 )2 +g2 α2 Ω2 0 . . we recognize that the two numerators add up to become the denominator: g2 = B 2 1 + g2 . which does not depend on the gains. gB )= 1 . under the substitutions {g.4 The analog transfer function and magnitude response squared are in the general boost or cut case: H(s)= where G0 (s2 + Ω2 )+Gαs 0 s2 + αs + Ω2 0 ⇒ |H(Ω)|2 = G2 (Ω2 − Ω2 )2 +G2 α2 Ω2 0 0 (Ω2 − Ω2 )2 +α2 Ω2 0 R2 = 1−β 1+β ⇒ R= 1−β 1+β α = (1 + Ω2 )β = (1 + Ω2 )tan 0 0 Δω 2 G2 − G 2 0 B ≡γ G2 − G2 B G2 − G2 0 B G2 − G 2 B (If β > 1. we assume that the parameter β = tan(Δω/2) remains positive and less than one. one can show easily that N(g−1 . N(g. (geometric) (harmonic) N(g. gB )γ2 Ω2 0 . gB ) . which happens when π/2 < Δω ≤ π. say by A dB (with respect to the reference). then the boost and cut gains will be g = 10±A/20 .) It follows that the -level time constant will be where the last step defines the parameter γ. 2 2g 2 1 + g2 N(g. and harmonic mean choices for g2 the functions N and D simplify B as follows: Problem 11. if we consider an equal and opposite boost and cut by. geometric. gB ) B 230 231 . and vice versa. we have: where the numerator and denominator gain functions are defined by R= 1−β 1+β (1 − 1 1 β)(1 − β) 2 2 1−β 1− Δω 2 1 − x. (Ω2 − Ω2 )2 +α2 Ω2 0 α=γ g2 − 1 B . This is guaranteed if the bandwidth is 0 ≤ Δω ≤ π/2 in rads/sample. g−1 )γ2 Ω2 0 B Under this substitution. gB } → {g−1 . the bandwidth levels g2 may be defined arbitrarily in the two B cases. gB )= g2 g2 − 1 B . G0 gB = GB G0 x to write approx- Then. we may express the magnitude squared response in the following form that explicitly shows the gains: β = tan Δω 2 Δω 2 |H(Ω)|2 = G2 0 (Ω2 − Ω2 )2 +N(g. Thus. g2 = B . pi./ H2 = dtft(b2. G. 0. parmeq(1.1*pi). gB )γ2 Ω2 0 |Hcut (Ω)|2 = G2 0 (Ω2 − Ω2 )2 +D(g./ dtft(a3.1.m . 0. x).G*beta)] / (1+beta). h1 = filter(b1. 0. which also shows how to compute the magnitude responses of the two complementary cases: 232 233 . sqrt(0.m implements the design of both the lowpass and highpass shelving filters (the parameter s = ±1 selects the two cases): 200 frequencies over [0. gB ) s2 + Ω2 + γs N(g−1 . b = [(G0 + G*beta).1*pi). % b = [b0 . not just their magnitudes. a2. w) . 10^(6/20). [b4. 1/sqrt(2). Note the rapid variations in the vicinities of the center s2 + Ω2 + γs N(g. a4. w) . 0. The geometric-mean and weighted geometric0 mean choices for g2 are special cases of the substitution {g. a2. x).Therefore. a1. H3 = abs(dtft(b3. 0. beta1] = parmeq(0. w)). highpass The 5-percent time constants can be calculated as in Problem 11. x). a. Hboost (s)= G0 2 s + Ω2 + γs D(g. -s*(G0 . [b2. h2 = filter(b2. w0. beta2] = parmeq(0.60*pi.05. 0. x).G0^2)) / sqrt(abs(G^2 . w). w) . Gc. argH1 argH2 argH3 argH4 = = = = angle(H1) angle(H2) angle(H3) angle(H4) * * * * 180 180 180 180 / / / / pi. B B satisfy the desired property.35*pi. dtft(a2. 0. 10^(-9/20). 10^(9/20). −1 = lowpass.1*pi.1 and computes their impulse response./ H4 = dtft(b4. the following MATLAB code designs the first four filters of Example 11. and phase responses (in degrees): [b1. [b1. 1. a2. Gc = reference./ dtft(a1. G0./ H3 = dtft(b3.6. 10^(-6/20).^2. gB ) 0 s2 + Ω0 + γs D(g−1 . w0.7 impulse responses The following MATLAB function lheq. a2. gB ) 0 frequencies. G. zeros(1. -s*(1-beta)/(1+beta)]. H1 = dtft(b1.1 and 11. Note. frequency. a1. gB )γ2 Ω2 0 (Ω2 − Ω2 )2 +N(g. 10^(-3/20). g−1 . impulse responses Hence. the boost and cut filters will be: |Hboost (Ω)|2 = G2 0 (Ω2 − Ω2 )2 +N(g. also that the transfer functions themselves are inverses to each other.2. w0. Gc.^2. Problem 11. 99)]. Indeed. w) . x = [1. zeros(1.1). any other choice of gB will do. that is. and therefore. b1 ] = numerator coefficients % a = [1. w) . h3 = filter(b3. Dw = 0. filter(b4. a1 ] = denominator coefficients % G0 .Gc^2)). gB )γ2 Ω2 0 . (Ω2 − Ω2 )2 +D(g.60*pi. their product will be identically equal to G4 . beta1] beta2] beta3] beta4] = = = = parmeq(1. w). gB )γ2 Ω2 0 h1 h2 h3 h4 = = = = filter(b1. G0. w)). g−1 ) 0 B which implies for the analog and the bilinearly transformed digital transfer functions: Hcut (s)= G2 0 Hboost (s) ⇒ Hcut (z)= G2 0 Hboost (z) Problem 11. 0. w)). beta] = lheq(s. boost/cut. and cutoff gains % wc = cutoff frequency in [rads/sample] % beta = design parameter β Problem 11. H1 = abs(dtft(b1. G. wc) beta = (tan(wc/2))^s * sqrt(abs(Gc^2 . equal and opposite bandwidth gains in B dB. x). w) . 1.2 may be designed by the following MATLAB code. 49)]. Dw). Figure P11. [b3. x). with = 0. P11. dtft(a4.lowpass/highpass first-order shelving EQ filter design % % [b. 10^(9/20). dtft(a3.6 For example.1 Phase responses of Problem 11.^2./ dtft(a1.35*pi.4. function [b. a3. [b3. π] magnitude responses % lheq. gB ) 0 . a = [1. a. Dw). H2 = abs(dtft(b2. filter(b3. 10^(-9/20). g−1 }. pi. length-50 unit impulse The filters of Examples 11.2. a4. we can write them in the form: w = (0:199)*pi/200. a3. a3. gB } → {g−1 . in rads/sample peaking 3-dB width peaking 10-dB width notching 3-dB width unit impulse Fig. gB ) 0 = G0 2 Hcut (s)= G0 2 −1 s + Ω2 + γs N(g. 1/sqrt(2).2*pi). wc) % % s = 1. a1. w) . computes their impulse responses. s2 + Ω2 + γs D(g. 10^(3/20). a3. x). But. [b2. w).35*pi. parmeq(1. w = (0:199)*pi/200. pi. Dw). beta3] = parmeq(1. and their magnitude responses: w0 = 0.1 shows the phase responses. as long as one defines the boost bandwidth to be gB and the cut bandwidth. parmeq(1. x = [1. beta] = lheq(s. filter(b2. a1. 0.2*pi). w).5 The following MATLAB code segment designs the three filters (two peaking and one complementary notch)./ dtft(a2. 0. H1 = abs(dtft(b1. P11. den1. 20 * log10(abs(H1)). omega). w. 0. omega) . 0. q = 0.2 Phase responses and impulse response of Problem 11. c2. 199)]. x).comb filtering with circular buffer % % [y.[b1.^2. p. 0.2*pi). w. 0. D) x s0 z-D sD a b y s0 = x + asD y = bs0 − csD ∗p = s0 cdelay(D.9). -a2].m b − cz−D algorithm of the transfer function H(z)= are given below: 1 − az−D 234 235 . beta1] = lheq(1. 0. c1.5. [1.2*pi). b. q. lowpass cases highpass cases 200 frequencies in [0. w. 0.^2. omega = (0:399)*2*pi/ 400. -c1]. b1. -a1]. b. [b6./ dtft(den2. [1. D-1). for each input sample x do: sD = tap(D. D.9). b. 0. sD. 10^(3/20). 1/sqrt(2). x. [a2. end note: h1=y1 } The MATLAB version is the function combfilt. a1. w. 1.7*pi). 20 * log10(abs(H2)). D+1). sqrt(0. D. 10^(-3/20). it also computes the impulse response of the first filter in two ways: (a) using MATLAB’s function filter and (b) the customized function combfilt. omega). w. omega)). wc. w = zeros(1. p. π] magnitude response squared Problem 11. 1/sqrt(2). that is.2. y. double tap().9). c. length-200 unit impulse impulse response 400 frequencies in [0. beta4] = lheq(1. beta6] = lheq(-1.7*pi). a2. and computes the corresponding magnitude and phase responses. 0. D-1). cdelay(D. q] = combfilt(a1.c x = [1. [b2. omega). **p. 1. zeros(1. a6. with unshifted peaks. 1. h1 = filter(num1. **p = s0. zeros(1. b1. [b4. dtft(num1. *p. D. D. % % The filter parameters [a. w. a5.m . 10^(-12/20). 10^(9/20). [b5. omega).8 The following MATLAB code generates the first pair of comb and notch filters of Example 11. 1. 0.c is an implementation: -c numerator coefficients denominator coefficients frequency response magnitude response phase response in degrees /* combfilt. 1. sqrt(0. D.c * sD.m given below: The phase responses of the comb and notch filters and the impulse response of the comb are shown in Fig. D-1). b. a4. q. D-1). q] = combfilt(a. 1). 1. num1 den1 H1 magH1 angH1 num2 den2 H2 magH2 angH2 = = = = = = = = = = [b1. sqrt(0./dtft(a1. a3. x(n+1)). 1). w. w. b2. D). x) double a.8. sD = tap(D. [b2. x). double combfilt(a. c1. dtft(num2.m that uses a circular buffer: D = 10. s0 = x + a * sD. [a1. wc. beta2] = lheq(1./dtft(a5. p).2*pi). The canonical realization and the corresponding circular buffer version of the sample processing % combfilt. 0. beta2] = combeq(1. p passed by address as in cfir. angle(H2) * 180 / pi. & p) The following C function combfilt. c. int D. [b3. 2π] Fig. c] can be obtained from combeq. 0. w. 1/sqrt(2). beta5] = lheq(-1. zeros(1. zeros(1. y = b * s0 . beta3] = lheq(1. omega)).comb filtering with circular buffer */ void cdelay(). [y1(n+1).2*pi). return y.025 * pi. *w.1. Dth tap output input to D-fold delay output sample update circular delay line (D+1)-dimensional state vector circular pointer index for n=0:199. H5 = abs(dtft(b5. zeros(1. wc = 0. beta1] = combeq(1.c . { double s0. -c2]. c. omega = (0:199)*pi/200./ dtft(den1. P11. angle(H1) * 180 / pi. omega) . % % It uses cdelay2.m, wrap2.m, tap2.m % based on combfilt.c ⎡ A(Ωpass )= 10 log10 ⎣1 + ε2 stop Ωpass Ωstop 2N ⎤ ⎦ < 10 log (1 + ε2 )= Apass 10 pass function [y, w, q] = combfilt(a, b, c, D, w, q, x) sD = tap2(D, w, q, D); s0 = x + a * sD; y = b * s0 - c * sD; w(q+1) = s0; q = cdelay2(D, q); Thus, in either case, the specifications are more than satisfied. Problem 11.11 The call to the MATLAB function lhbutt.m: [A, B, P] = lhbutt(1, 40, 10, 15, 3, 35); It uses the following routine tap2.m that helps extract the components of the circular internal state vector: % tap2.m - read ith tap of circular delay-line buffer % % si = tap2(D, w, q, i) % % w = (D + 1)-dimensional % q = circular index into w % delay amount i = 0, 1, . . . , D % based on tap2.c produces the following cascade matrices 0.5001 ⎢ B = ⎣ 0.3821 0.2765 ⎡ 0.5001 2 × 0.3821 2 × 0.2765 0 ⎥ 0.3821 ⎦ , 0.2765 ⎤ ⎡ ⎢ A=⎣ 1 1 1 0.0002 0.0007 0.0005 0 ⎥ 0.5279 ⎦ 0.1056 ⎤ Thus, the designed transfer function will be: H(z)= function si = tap2(D, w, q, i) si = w(rem(q+i, D+1)+1); % si is delayed output s(n − i) 0.5001(1 + z−1 ) 0.3821(1 + z−1 )2 0.2765(1 + z−1 )2 · · 1 + 0.0002z−1 1 + 0.0007z−1 + 0.5279z−2 1 + 0.0005z−1 + 0.1056z−2 The parameter vector P is: P = [Ωpass , Ωstop , εpass , εstop , Nexact , N, Astop , Ω0 , f0 ] = [1, 2.4142, 0.9976, 56.2252, 4.57, 5, 38.26, 1.0005, 10.0030] where Astop is the actual stopband attenuation realized by the designed filter, and f0 is the 3dB cutoff frequency. The apparent discrepancy between the computed 3-dB frequency and the given 3-dB passband specification is accounted for from the fact that the 3-dB frequency Ω0 or f0 is defined to be the frequency where the magnitude squared response drops to one-half its DC value; this is almost a 3-dB drop, but not exactly. By hand, the design is as follows. First, we prewarp the physical frequencies: Problem 11.9 In the FIR case of designing a lowpass filter, the limits 1 ± δpass and ±δstop represent the ripples of the (real-valued) frequency response D(ω). These translate to the limits for the magnitude response 1 ± δpass in the passband and [0, δstop ] in the stopband. In the IIR case, the definitions are motivated by the closed-form expressions of the magnitude response squared in the Butterworth and Chebyshev cases. Problem 11.10 Because Ωstop > Ωpass , and N ≥ Nexact , we have the inequality Ωpass = tan Ωstop = tan >1+ ε2 stop ωpass 2 = tan = tan πfpass fs πfstop fs = tan = tan π10 40 = tan(0.25π)= 1 = tan(0.375π)= 2.4142 ωstop 2 π15 40 Ωstop Ωpass 2N > Ωstop Ωpass 2Nexact = ε2 stop ε2 pass ⇒ 1+ ε2 pass Ωstop Ωpass 2N Then, we compute the -parameters: Thus, using Eq. (11.6.14) we have: ⎡ A(Ωstop )= 10 log10 ⎣1 + ε2 pass Ωstop Ωpass 2N ⎤ ⎦ > 10 log (1 + ε2 )= Astop 10 stop εpass = 10Apass /10 − 1 = 103/10 − 1 = 0.9976, and the exact and up-rounded value of N: εstop = 10Astop /10 − 1 = 1035/10 − 1 = 56.2252 Similarly, if we fix Ω0 by the stopband specification, then we have: Nexact = Ωpass Ωstop 2N ln(εstop /εpass ) ln(Ωstop /Ωpass ) = ln(56.2252/0.9976) = 4.57 , ln(2.4142/1.0000) N=5 Ωpass Ωstop 2N < Ωpass Ωstop 2Nexact = ε2 pass ε2 stop ⇒ 1 + ε2 stop < 1 + ε2 pass Then, we calculate the 3-dB Butterworth parameter Ω0 and invert it to get the 3-dB frequency f0 : Then, using Eq. (11.6.15), we have: Ω0 = Ωpass ε1/N pass = 1 (0.9976)1/5 = 1.0005 , f0 = fs arctan(Ω0 )= 1.0030 kHz π 236 237 The coefficients of the 2nd-order sections are computed by Eq. (11.6.24). Note that because of the small discrepancy mentioned above, Ω0 is not exactly equal to unity, and therefore, the a1 coefficients of all the sections will not be exactly zero. The Butterworth angles are computed by Problem 11.14 Using a trig identity, we obtain: θi = which gives π 2N (N − 1 + 2i)= π 10 (4 + 2i), i = 1, 2 | sin(ω1 + ω2 )| = | sin ω1 cos ω2 + sin ω2 cos ω1 | ≤ | sin ω1 || cos ω2 | + | sin ω2 || cos ω1 | ≤ | sin ω1 | + | sin ω2 | = sin ω1 + sin ω2 where we used the inequalities | cos ω1 | ≤ 1 and | cos ω2 | ≤ 1 and the fact that sin ω1 and sin ω2 are non-negative for values of their arguments in the range [0, π]. Thus, the above inequality implies |c| ≤ 1. θ1 = 0.6π, θ 2 = 0 . 8π Problem 11.12 The call to lhbutt.m: [A, B, P] = lhbutt(-1, 10, 3, 2, 0.5, 35); Problem 11.15 Here, the Butterworth filter order is given to be N = 3. Thus, there remains only the parameter Ω0 to be fixed. The normalized passband frequencies are produces the following cascade matrices ωpa = 0.3414 0.2454 2πfpa B= 0.3414 0.2454 −2 × 0.3414 −2 × 0.2454 , A= 1 1 0.0817 0.0587 0.4471 0.0404 fs = 2π 2 = 0.2π, 20 ωpb = 2πfpb fs = 2π 8 = 0 .8 π 20 Because they add up to π, the bilinear transformation parameter c will be zero, as follows from the equation Thus, the designed transfer function will be: 0.3414(1 − z−1 )2 0.2454(1 − z−1 )2 H(z)= · 1 + 0.0817z−1 + 0.4471z−2 1 + 0.0587z−1 + 0.0404z−2 The parameter vector P is: c= sin(ωpa + ωpb ) sin ωpa + sin ωpb 1 + z−2 1 − z−2 =0 Thus, the bilinear transformation will be here: P = [Ωpass , Ωstop , εpass , εstop , Nexact , N, Astop , Ω0 , f0 ] = [0.7265, 1.3764, 0.3493, 3.0000, 3.37, 4, 13.27, 0.9451, 2.5899] where Astop is the actual stopband attenuation realized by the designed filter, and f0 is the 3-dB cutoff frequency in kHz. The required closed-form expression for part (c) is: s= The analog passband frequency will be: c − cos ωpb Ωpass = sin ωpb = − cot ωpb = 1.3764 The εpass parameter is calculated to be: |H(ω)|2 = 1+ 1 cot(ω/2) 2N εpass = 10Apass /10 − 1 = 100.5/10 − 1 = 0.3493 which implies for Ω0 : Ω0 Problem 11.13 The real part of s can be expressed as follows: Re s = Ω0 = Ωpass ε1/N pass = 1.3764 = 1.9543 0.34931/3 z∗2 − 2cz∗ + 1 (z2 − 2cz + 1)(z∗2 − 1)+(z∗2 − 2cz∗ + 1)(z2 − 1) z2 − 2cz + 1 1 + = (s + s∗ )= 2(z2 − 1) 2(z∗2 − 1) 2(z2 − 1)(z2 − 1)∗ 2 The coefficients of the second- and fourth-order digital filter sections are calculated from Eqs. (11.6.43) and (11.6.41), where the there is only one Butterworth angle, namely, θ1 = π 2N (N − 1 + 2)= 2π 3 ⇒ cos θ1 = −0.5 |z|4 − 1 − c(z + z∗ )(|z|2 − 1) (|z|2 − 1)(|z|2 − c(z + z∗ )+1) = = |z2 − 1|2 |z2 − 1|2 where in the last step we factored |z|4 − 1 = (|z|2 − 1)(|z|2 + 1). Because |c| ≤ 1, the second factor of the numerator is non-negative. Indeed, noting that (z + z∗ ) is real-valued, we have: We find for the second-order section: G0 = 0.6615, and the fourth-order section: a01 = 0, a02 = −0.3230 |c(z + z∗ )| ≤ |z + z∗ | ≤ |z| + |z∗ | = 2|z| Adding |z|2 + 1 to both sides we get the inequality: ⇒ −2|z| ≤ c(z + z∗ )≤ 2|z| G1 = 0.5639, a11 = 0, a12 = −0.8325, a13 = 0, a14 = 0.4230 resulting in the transfer function: ∗ 2 |z| −2|z|+1 ≤ |z| −c(z+z )+1 ≤ |z| +2|z|+1 2 2 2 ∗ ⇒ 0 ≤ (|z|−1) ≤ |z| −c(z+z )+1 ≤ (|z|+1) 2 2 H(z)= 0.5639(1 − z−2 )2 0.6615(1 − z−2 ) · −2 1 − 0.8325z−2 + 0.4230z−4 1 − 0.3230z Therefore, the sign of Re s is the same as the sign of the factor (|z|2 − 1), and the desired result follows. The 3-dB frequencies are calculated from Eq. (11.6.44) with c = 0. We find: f0a = 1.5054 kHz, f0b = 8.4946 kHz 238 239 Problem 11.16 We have: 1 Problem 11.18 Ω2 0 Ω2 − 2sΩ0 cos θi + s2 0 Ω2 0 Ω2 − 2 0 1 − z−1 1 + z−1 Matching the stopband specifications exactly means that the stopband frequencies ωsa , ωsb map onto ±Ωstop and that at Ωstop the attenuation is exactly Astop . The first requirement implies 1 − z−1 1 + z−1 2 s2 s 1−2 cos θi + 2 Ω0 Ω0 = = = Ω0 cos θi + −Ωstop = Ωstop = which can be solve for c and Ωstop : c − cos ωsa sin ωsa c − cos ωsb sin ωsb Ω2 (1 + z−1 )2 0 2 −1 )2 −2(1 − z−1 )(1 + z−1 )Ω cos θ + (1 − z−1 )2 Ω 0 (1 + z 0 i Ω2 (1 + z−1 )2 0 = 2 Ω0 (1 + 2z−1 + z−2 )−2(1 − z−2 )Ω0 cos θi + (1 − 2z−1 + z−2 ) = Ω2 (1 + z−1 )2 Gi (1 + z−1 )2 0 = 1 + ai1 z−1 + ai2 z−2 (1 − 2Ω0 cos θi + Ω2 )+2(Ω2 − 1)z−1 + (1 + 2Ω0 cos θi + Ω2 )z−2 0 0 0 c= sin(ωsa + ωsb ) , sin ωsa + sin ωsb Ωstop = c − cos ωsb sin ωsb Given the value of c, we compute next the two candidates for Ωpass : where the final result was obtained by dividing numerator and denominator by the factor (1 − 2Ω0 cos θi + Ω2 ) in order to make the constant coefficient of the denominator unity. 0 The highpass case is obtained by replacing z−1 by −z−1 , which effectively changes the sign of the ai1 coefficient. The bandpass case can be done in a similar, but more tedious, fashion. Ωpa = c − cos ωpa , sin ωpa Ωpb = c − cos ωpb sin ωpb Ideally, we would like have Ωpb = Ωpass and Ωpa = −Ωpass . But this is impossible because c has already been fixed. Because the Butterworth magnitude response is a monotonically decreasing function of Ω, it is enough to choose the widest of the two passbands defined above. Thus, we define: Problem 11.17 The right 3-dB frequency is obtained by solving the equation Ωpass = max |Ωpa |, |Ωpb | c − cos ω0b = Ω0 sin ω0b Once we have computed Ωpass and Ωstop , we design our Butterworth analog filter; that is, compute N and Ω0 from Using the trig identities cos ω0b = 1 − tan2 (ω0b /2) , 1 + tan2 (ω0b /2) sin ω0b = 2 tan(ω0b /2) 1 + tan2 (ω0b /2) Nexact = ln(εstop /εpass ) ln(Ωstop /Ωpass ) , N = Nexact , Ω0 = Ωstop ε1/N stop The above equation reduces to the quadratic equation in the variable t = tan(ω0b /2): where the equation for Ω0 matches the stopband specification exactly. The digital filter coefficients are then computed in terms of N and Ω0 as usual. The following MATLAB function bpbutt2.m implements the above procedure and is an alternative to bpsbutt.m: % bpbutt2.m - bandpass Butterworth digital filter design % c− 1 − t2 1 + t2 = Ω 0 2t ⇒ (1 + c)t2 − 2Ω0 t − (1 − c)= 0 % [A, B, P] = bpbutt2(fs, fpa, fpb, fsa, fsb, Apass, Astop) % % alternative to bpsbutt.m % it matches stopbands and uses worst passband. % % design parameters: % P = [Wpass, Wstop, Wpa, Wpb, c, fc, epass, estop, Nex, N, Apass, W0, f0a, f0b]; % A,B are Kx5 matrices of cascade of 4th/2nd order sections 1+ t2 which has positive solution: t= implying for the 3-dB frequency Ω0 + Ω2 0 + (1 − c)(1 + c) 1+c function [A, B, P] = bpbutt2(fs, fpa, fpb, fsa, fsb, Apass, Astop) 2 2 fs ⎜ Ω0 + 1 − c + Ω 0 ⎟ arctan ⎝ ⎠ π 1+c tan ω 0b 2 = tan πf0b fs = Ω2 + 1 − c 2 + Ω 0 0 1+c ⎛ ⎞ c = sin(2*pi*(fsa + fsb) / fs) / (sin(2*pi*fsa / fs) + sin(2*pi*fsb / fs)); fc = 0.5 * (fs/pi) * acos(c); Wstop = abs((c - cos(2*pi*fsb / fs)) / sin(2*pi*fsb / fs)); Wpa = (c - cos(2*pi*fpa / fs)) / sin(2*pi*fpa / fs); Wpb = (c - cos(2*pi*fpb / fs)) / sin(2*pi*fpb / fs); ⇒ f 0b = The left 3-dB frequency is obtained by replacing Ω0 by −Ω0 in the above solution. 240 241 1 + 2 * i) / (2 * N).0^(Apass/10) .cos(2*pi*fpb / fs)) / sin(2*pi*fpb / fs). A(1.c^2 + 1) .m . 0].4 * c * Wi^2 / (1 + Wi^2).m % matches stopbands instead of passbands % % design parameters: % P = [Wpass. W0 = sinh(a) / Wstop. -2.1).cos(2*pi*fpa / fs)) / sin(2*pi*fpa / fs). 0. Nex N = r = K = = log(estop/epass) / log(Wstop/Wpass).W0) / (1 + W0). Nex. epass. b2. a2 = -(1 . B are Kx5 matrices of cascade 4th/2nd order sections function [A. 0. (N .2 * W0 * cos(th) + W0^2. D = 1 . f3a. 0]. 0. b2 = 2 * (Wi^2 * (2*c*c+1) . 0.m is an alternative to the bandpass Chebyshev type-2 design function bpcheb2. fpb. f3a. G = W0 / (1 + W0). a1. a2 = (1 . a2. a4 = (1 + 2 * W0 * cos(th) + W0^2 + Wi^2) / D. Wpb. B(1. end % reciprocal of text Similarly. A(1.4 * c * (W0 * cos(th) + 1) / D.1). end for i=1:K. 0. Apass. 0.:) = G * [1. P] = bpcheb2a(fs. f3b = (fs/pi) * atan((sqrt(W3^2 . end for i=1:K. B. f3a = (fs/pi) * atan((sqrt(W3^2 . A(1. a2 = 2 * (2*c^2 + 1 .c^2 + 1) . Wpb. G = (1 + Wi^2) / D.:) = [1. 0. W0 = Wstop * (estop^(-1/N)).Wi^2) / D. else B(1.:) = [1.Wpass = max(abs(Wpa).:) = [1. the function bpcheb2a.W3)/(c+1)). f3b. fc. 0]. Nex. 0]. 0. a1 = 4 * c * (W0 * cos(th) . Wpb = (c .W0^2 . Apass. c. fsa. a3.alternative bandpass Chebyshev type 2 digital filter design % % [A. 0.1). 0]. a2.W0)/(c+1)). 0. c. 0. 0]. rem(N. epass = sqrt(10. a2 = 2 * ((2*c*c + 1)*(W0^2 + Wi^2) . Wstop = abs((c . Apass = 10 * log10(1 + (Wpass/W0)^(2*N)). 0. B. Wpa = (c .1) / D.1) / D. 0. c. a3. Wstop. abs(Wpb)). epass = sqrt(10. P = [Wpass. Wpa.0^(Astop/10) . estop. b1. estop.cos(2*pi*fsb / fs)) / sin(2*pi*fsb / fs)). else B(1. estop = sqrt(10. B(i+1. Astop) 242 243 . B(1. Wpb.:) = [1. 0. -1. f0b = (fs/pi) * atan((sqrt(W0^2 . fsb. Wstop. A(1. epass. a1.:) = G * [1. f0b]. 0].0^(Apass/10) . Wi = sin(th) / Wstop. Wpa. W0. N. th = pi * (N .:) = G * [1. estop = sqrt(10. 0.1) / (1 + Wi^2).2 * W0 * cos(th) + W0^2 + Wi^2. end a = asinh(estop) / N. 1]. 0.m: % bpcheb2a.c^2 + 1) + W0)/(c+1)). fsb. rem(N. 0.1 + 2 * i) / (2 * N).r) / 2. epass.1). f0a = (fs/pi) * atan((sqrt(W0^2 .:) = G * [1. a1 = -2 * c / (1 + W0). a3 = .:) = [1. % A. 0. fpb. fpa. c = sin(2*pi*(fsa + fsb) / fs) / (sin(2*pi*fsa / fs) + sin(2*pi*fsb / fs)).2). N. Wpa. a1 = 4 * c * (W0 * cos(th) . Wstop.0^(Astop/10) . W3 = Wstop / cosh(acosh(estop)/N). a2. 0].W0) / (1 + W0). a3 = . a1. Apass. a4]. Nex N = r = K = = acosh(estop/epass) / acosh(Wstop/Wpass). ceil(Nex). f3b. a1.2).W0^2) / D. G = 1 / (1 + W0).:) = [1. fpa. -1. B(i+1. a2.r) / 2. a1 = -2 * c * W0 / (1 + W0). a4 = (1 + 2 * W0 * cos(th) + W0^2) / D. f0a. 1]. a]. estop. Nex. P] = bpcheb2a(fs. A(i+1.:) = [1.4 * c * (W0 * cos(th) + W0^2 + Wi^2) / D. b1. abs(Wpb)). a4]. G = W0^2 / D. b1 = . N. if r==1.c^2 + 1) + W3)/(c+1)). (N . if r==1. 0. P = [Wpass. Wpass = max(abs(Wpa). ceil(Nex). th = pi * (N . fsa. A(i+1. a]. D = 1 .:) = [1. 0. Astop) % % alternative to bpcheb2. W[i]. i++) y = sos4(A[i]. argv[1]). double **A. Problem 11. This can be done by saving the A and B outputs of the MATLAB functions into ASCII files and then invoking the following filtering routine casfilt4.a[3]*w[3] .dat <x. could replace these updates by the single call to delay(4. x) double *a. exit(0). bpcheb2.c and cas4. x. j. return y. K.21 The following C functions sos4. { int i.c . x. double **A. } if ((fpb = fopen(argv[2]. i. exit(0). dmax = MAX. w are 5-dimensional a[0]= 1 always void main(int argc. double *a. double y. **B. such as bpsbutt.m. w). x) int K. "Usage: casfilt4 A.c which is analogous to casfilt. int M. for (i=0. w[0] = x . i<K.19 We work with the type-2 design since it has more complicated numerator. b. m.IIR filtering in cascade of fourth-order sections */ double sos4().h> #include <stdio. A. exit(0). } a = (double *) calloc(max + 1. } and 244 245 . x. B[i]. *b. argv[2]).c of Problem 7. or bscheb2.IIR filtering in cascade of fourth-order sections */ #include <stdlib. **B. "r")) == NULL) { fprintf(stderr. a.dat\n").h> #define MAX 64 initial allocation size |si |2 = Ω2 cos2 θi + Ωi 2 cosh2 a = Ω2 (1 − sin2 θi )+Ωi 2 (1 + sinh2 a) 0 0 = Ω2 + Ωi 2 + (Ω2 sin2 θi − Ωi 2 sinh2 a)= Ω2 + Ωi 2 0 0 0 where the last two terms canceled because Ω0 sin θi = Ωpass sinh a sin θi = Ωi sinh a double cas4(). coefficient files temporary coefficient array allocation and increment if (argc != 3) { fprintf(stderr. y). w. w[2].dat >y. 0 output of ith section final output from last SOS4 Problem 11.a[2]*w[2] .20 The s-domain poles are si = Ωpass sinh a cos θi + jΩpass cosh a sin θi = Ω0 cos θi + jΩi cosh a It follows that The K × 5 matrices A and B are generated by the filter design MATLAB functions. **W. } single 4th-order section = (1 + z−1 )2 +Ωi −2 (1 − z−1 )2 −1 )2 −2Ω−1 cos θ (1 − z−1 )(1 + z−1 )+(Ω−2 + Ω −2 )(1 − z−1 )2 (1 + z i i 0 0 A. *w. int max = MAX.c . **W. "Can’t open filter file: %s\n". W are K×5 matrices = = (1 + Ωi −2 )+2(1 − Ωi −2 )z−1 + (1 + Ωi −2 )z−2 − − (1 − 2Ω−2 cos θi + Ω−2 + Ωi −2 )+2(1 − Ω−2 − Ωi −2 )z−1 + (1 + 2Ω0 2 cos θi + Ω0 2 + Ωi −2 )z−2 0 0 0 Gi (1 + bi1 z−1 + z−2 ) 1 + ai1 z−1 + ai2 z−2 initial input to first SOS4 where the final step follows by dividing the numerator by the factor (1 + Ωi −2 ) and the denomi− nator by (1 − 2Ω0 2 cos θi + Ω−2 + Ωi −2 ). y = b[0]*w[0] + b[1]*w[1] + b[2]*w[2] + b[3]*w[3] + b[4]*w[4].c implement the sample-by-sample processing algorithm of the cascade of fourth-order sections: /* sos4. and can be passed as inputs to the above C functions. W. double cas4(K. "r")) == NULL) { fprintf(stderr.Problem 11.a[1]*w[1] . *fpb. y. { double y. w[0]. return y. w[4] w[3] w[2] w[1] = = = = w[3]. b. B.15 and which reads A and B dynamically from the command line: /* casfilt4. w[1]. "Can’t open filter file: %s\n". y = x. sizeof(double)).m. B.m. } if ((fpa = fopen(argv[1].c .a[4]*w[4]. char **argv) { FILE *fpa. The transformation of the analog second-order sections is as follows: 1 + Ωi −2 s2 − 1 − 2Ω−1 cos θi s + (Ω0 2 + Ωi −2 )s2 0 /* cas4.IIR filtering by single (canonical) fourth-order section */ double sos4(a.dat B. B4.m . i++) for(j=0.5. 2. i<K. W] = cas4(K. end process input samples The MATLAB version of sos4 is as follows: % sos4. B3. for i = 1:K.for (M=0. b4] = 5-dim numerator (row vector) % a = [1. W = zeros(K. 5. A.5. i++) for(j=0. sizeof(double *)). y = b * w’. printf("%lf\n". a = (double *) realloc((char *) a. bandpass. w2. P6] = bpsbutt(1. [y(n). i<K. B1. end The MATLAB version of casfilt4 for filtering of a long input vector is as follows. 0. W] = cas4(K. A. 20. Apass. A = (double **) calloc(K. 20. It is analogous to casfilt. W = (double **) calloc(K.5. b2. highpass. x) y = x. a3. B. x). 1. a1.22 The following MATLAB code designs the pairs of lowpass. j++) A[i][j] = a[5*i + j]. a2. x) % % b = [b0. B[i] + j). sizeof(double)). W.5. 10). P1] = lhbutt(1. P2] = lhbutt(1. W[i] = (double *) calloc(5. "%lf". 0. 20.5.98). j++) fscanf(fpb. a. and bandstop Butterworth filters. j<5. 4. B. x) w(1) = x . N] = size(x). 5. j<5. A. B[i] = (double *) calloc(5.m . sizeof(double *)). Astop). if (M%5 != 0) { fprintf(stderr. A. 0.5). A. 4. B5. B6. 2. Astop = -10*log10(0. M++) { if (M == max) { max += dmax. (M + 1) * sizeof(double)).m . B. P3] = lhbutt(-1. w. "all rows of A must be 5-dimensional"). 20. A(i.:)] = sos4(B(i. W(i. } } allocate K rows states of each SOS4 each row is 5-dim % cas4. Apass. [A2. 4. for(i=0. B = (double **) calloc(K. sizeof(double)). 5. 10). 4. 20. w.5. 4. B2. while(scanf("%lf".:). [A5. W. W. and shows how to compute the phase response and impulse response of one of the filters (the first bandpass filter): Apass = -10*log10(0. b1. w3. } for(i=0.cascade of fourth order sections % % [y. [A4.a(2:5) * w(2:5)’. The MATLAB version of cas4: 246 247 . 10). } a = (double *) realloc((char *) a. W] = cas4(K. sizeof(double *)). [y.:). P4] = lhbutt(-1. x) % % B = Kx5 numerator matrix % A = Kx5 denominator matrix % W = Kx5 state matrix % x = scalar input % y = scalar output function [y. w). y). w = delay(4. w] = sos4(b. &x) != EOF) { y = cas4(K. a. B. a4] = 5-dim denominator (row vector) % w = [w0. Astop). [N1. for n = 1:N. A. i<K. "%lf". sizeof(double)). exit(0). W(i. stringent case lowpass lowpass highpass highpass bandpass bandpass function [y. Apass. (max + 1) * sizeof(double)).fourth order section % % [y. [A1. Astop). 1.:). [A3. 4. y). x(n)). [A6. 4. K1] = size(A). } if (fscanf(fpa.. 20. 5.02).15: % casfilt4. i++) { A[i] = (double *) calloc(5. x) [K. b3. w] = sos4(b. for (i=0. P5] = bpsbutt(1. w4] = 5-dim filter state (row vector) % x = scalar input % y = scalar output Problem 11. x) % % B = Kx5 numerator matrix % A = Kx5 denominator matrix % x = row vector input % y = row vector output form A matrix read B matrix function y = casfilt4(B.cascade of fourth-order sections % % y = casfilt4(B. } else number of SOS4 K = M / 5.5. 4.m of Problem 7. a + M) == EOF) break. w1. W. P11. 4. 2. 4. 99)]. x).5.5. B7.5. H7 = dtft(b7. 4. y7=h7 The computed phase and impulse responses are shown in Fig. P11. bandpass. P4] = lhcheb1(-1. 10). 5. π] bandpass case frequency response phase response (in degrees) length-100 unit impulse impulse response bandstop bandstop [A9. Astop). 1. 4. B2. 5. 1. Note.5. π] bandpass case frequency response phase response (in degrees) length-100 unit impulse impulse response BS type 2 BS type 2 conventional method. Note that the Chebyshev phase response is not as linear within its passband. Apass. 20. 2. [A3. om) . 99)]. A5. P7] = bpcheb2(20.02). P11. H5 = dtft(b5. [A6. 4. 200 frequencies in [0.5.5. [A1. a7. 1. 10). 0. P6] = lhcheb2(1. Fig.4. 2. 2.5. P8] = bpsbutt(-1.5. x = [1. 20. Astop). [A10. P9] = bscheb2(20. Note. The computed phase and impulse responses are shown in Fig. A7. [A5. 4. 200 frequencies in [0. x). 4. om).5. 4. B6. P2] = lhcheb1(1.5. 20. 0.23 The following MATLAB code designs the pairs of lowpass. P10] = bscheb2(20. P5] = lhcheb2(1. 2. 4. x). B3.5. 4. Astop). Astop = -10*log10(0. [A7. a5. zeros(1. h7 = casfilt4(B7. a5 = cas2can(A5). Astop).3. P8] = bpcheb2(20. Astop).5. 10). 1. 4. [A2. 10). B4. 10). om).5. 0. y5=h5 conventional method. B7. Apass. 0. Apass. B8.5. Apass. Apass./ dtft(a7.4 Phase and impulse responses of (the less stringent) bandpass filter of Problem 11. 5. stringent case LP type 1 LP type 1 HP type 1 HP type 1 LP type 2 LP type 2 BP type 2 BP type 2 248 249 . [A4. om). 2. b5 = cas2can(B5). 20. P3] = lhcheb1(-1.5.5. om = (0:199) * pi / 200. 4. y7 = filter(b7./dtft(a5. B5.[A7.22. 4. 4. P1] = lhcheb1(1. [A8. om = (0:199) * pi / 200. and bandstop Chebyshev filters. Notice how the phase response is almost linear within its passband.23. 20. Astop). 1. and shows how to compute the phase response and impulse response of one of the filters (the first bandpass filter): Apass = -10*log10(0.98). 20. argH5 = angle(H5) * 180 / pi. a7 = cas2can(A7).3 Phase and impulse responses of (the less stringent) bandpass filter of Problem 11. argH7 = angle(H7) * 180 / pi. 1. b7 = cas2can(B7). B10.5. Problem 11. 20. P7] = bpsbutt(-1. 0. B8. x = [1. 5. 4. Fig. 5. 4. zeros(1. highpass. 5. 20.5. [A8. 10). 4. Apass. x). y5 = filter(b5. h5 = casfilt4(B5. B1. B9. 4. 0. P11. (12.64 0 −0.64 1 0. P12. 1.21ζ −4 ) {xup (2n + 4). 0. (12.2 In this case.90(ζ + ζ −1 )+0. xup (2n − 2)}.30(ζ 3 + ζ −3 ) − 0. P12.05. 0 ] The corresponding polyphase subfilters are obtained by extracting every second entry: h0 = [0. Equations (12.30z + 0. xup (2n + 2). so that N = 2LM + 1 = 9.21z + 0. 0. N=9 0.21 4 k′ −1 −1 Fig. The resulting impulse response will be: h = [0.05. −0. 0] h1 = d1 = [−0. 1.18ζ 8 + 0. πk /2 −4 ≤ k ≤ 4 n′ 2n-2 2n 2n+2 2n+4 h = d = [0.13(ζ 7 + ζ −7 ) xup(2n-2) xup(2n) yup(2n+1) xup(2n+2) xup(2n+4) Problem 12. x(n + 1).18) can be cast in a compact matrix form: H3 (z) = −0. M=2.64 D0 (z) = 1 D1 (z) = −0. numerically. The two polyphase subfilters are defined by Eq.64 0. −0. xup (2n).64z −2 −2 − 0.64z −1 −1 + 0.18).4.18ζ 8 4 8 4 −4 ) These filtering equations can also be obtained by superimposing the symmetric impulse response of Fig.13 + 0. 0. The Hamming windowed version of the filter is obtained by multiplying the full length-9 filter response h by a length-9 Hamming window. for i = 0.64. −0.18z −3 − 0.90z + 0. corresponding to Eq. The ideal impulse response is: d(k )= or. −0.1): ⎡ yup (2n) yup (2n + 1) = 0 −0.1. P12.64 − 0.64.64ζ + 0.21 + 0. 0.21ζ + 0. 0. −0.18 + 0. −2 ≤ k ≤ 1 They can be extracted from h by taking every second entry. xup (2n + 2). 0.1 The low-rate transfer functions. The two subfilters act on the time-advanced (by M = 2) low-rate input samples {x(n + 2).1 on each of the contributing low-rate samples −2 (−0.21.90z + 0. 0 ] It is depicted in Fig.18z−1 D2 (z) = −0.2.21] 250 251 .10).30z−2 − 0.21z 2 2 -4 -3 -2 -1 -0.64 − 0.4. 0. that is.05.15). L = 2 and we choose M = 2.2.18(ζ 5 + ζ −5 )−0. Di (z) and Hi (z)= z−2 Di (z). (12. D3 (z) = −0.13z H0 (z) = z−2 H1 (z) = −0.30z H2 (z) = −0.21(ζ 6 + ζ −6 )−0. i = 0.21 0 1 2 3 -0.21.2) will be: d(k′) 1 L=2. x(n − 1)}.2. 0] h1 = [−0.2. starting with the ith entry: h0 = d0 = [0.90 − 0.1 Length-9 symmetric impulse response of 2-fold FIR interpolator. P12.90 − 0.90ζ 4 + 0.13ζ −4 ) =1 + 0. as shown in Fig.05] di (k)= d(2k + i).64(ζ 2 + ζ −2 )+0.21z−3 The interpolated samples between x(n)= xup (2n) and x(n+ 1)= xup (2n+ 2) are calculated from Eqs. 0. 1.30 − 0.2 Superposition of impulse responses. 0.55. Fig.Chapter 12 Problems Problem 12. x(n). (12.64. 0.55. (12. 0.30 − 0. 0.90z−1 + 0.55.13z2 + 0.13z−3 Setting z = ζ 4 and using Eq. 0.64. P12.30ζ + 0.13ζ + 0.21 xup (2n + 4) ⎢ x (2n + 2) ⎢ up ⎢ ⎣ xup (2n) xup (2n − 2) ⎤ ⎥ ⎥ ⎥ ⎦ D(ζ)=D0 (ζ 4 )+ζ −1 D1 (ζ 4 )+ζ −2 D2 (ζ 4 )+ζ −3 D3 (ζ 4 ) =1 + ζ +ζ −1 (−0. xup (2n). which is recognized as the double-sided ζ -transform of the sequence d given in Eq. 1.2. sin(πk /2) .55.18z + 0. we obtain the transfer function D(ζ). or. xup (2n − 2)} and adding up their contributions at each of the intermediate sampling instants 2n + i. 0. 1. {xup (2n + 4).21.64z + 0. + ζ −3 (−0. 1.21 0 0. −0. 4 For interpolation factor L = 4 and filter length N = 25. as shown in Fig.55 1 0.83. (12. x(n − 1)}.78 0.17 -3 -2 -1 -0. −0.41.32.06. 0] The corresponding polyphase subfilters are obtained by extracting every third entry: h0 = [0.41 4 3 -0. h = d = [0. 0.32.41 0. P12. starting with the ith entry: h0 = d0 = [0.06. that is.02. 0. −0. 0.2.02. 0.02] The interpolation equations will be in this case: di (k)= d(3k + i). xup (3n − 3)}.02 xup (3n − 3) ⎡ ⎤ ⎥ ⎥ ⎥ ⎦ -0.10).17. 1. 0.41. xup(3n-3) xup(3n) yup(3n+1) xup(3n+3) xup(3n+6) −6 ≤ k ≤ 6 n′ 3n-3 3n 3n+3 3n+6 Fig.41.2. numerically.21. corresponding to filter length N = 2LM + 1 = 13.41 -6 -5 -4 -0.4 Superposition of impulse responses.17 Problem 12.83. with time origin at the middle of the vector. 0. x(n).21 ⎦ ⎢ ⎣ xup (3n) −0. 1. 0.4.17. 0.78.02 −0.78.06 ⎦ ⎢ ⎣ xup (3n) −0. 0.3 on each of the contributing low-rate samples {xup (3n + 6). for i = 0.21] h2 = d2 = [−0. 0.17] The interpolated samples between x(n)= xup (3n) and x(n + 1)= xup (3n + 3) are calculated from Eqs.83 1 0. xup (3n + 3).55 0 −0.41 ⎤ xup (3n + 6) 0 ⎢ ⎥ ⎢ xup (3n + 3) −0. i = 0.78. −0. 1. M=2.3 Length-13 symmetric impulse response of 3-fold FIR interpolator.83. 0. −0. The length-25 ideal interpolation impulse response is calculated from: d(k )= sin(πk /4) . we use 3 low-rate samples above and three below every interpolated value to be computed.21.83 0.2. xup (3n). and d is the symmetric one.21 yup (3n + 2) ⎡ 0 0.3. N=13 ⎡ ⎤ ⎡ yup (3n) 0 ⎢ ⎥ ⎢ ⎣ yup (3n + 1) ⎦ = ⎣ −0. 2. 0. −2 ≤ k ≤ 1 They can be extracted from h by taking every third entry. P12. 0.06] h2 = [−0. 0. −0.18) can be cast in a compact matrix form: N = 2LM + 1 ⇒ M = (N − 1)/2L = (25 − 1)/8 = 3 ⎤ ⎡ yup (3n) 0 ⎥ ⎢ ⎢ ⎣ yup (3n + 1) ⎦ = ⎣ −0. we find: Fig.The interpolation equations will be in this case: ⎡ yup (2n) yup (2n + 1) = 0 −0. All three subfilters act on the time-advanced (by M = 2) low-rate input samples {x(n+2). 2. 0. (12. 0] h1 = [−0. Problem 12. xup (3n + 3). −0. The resulting impulse response will be: h = [0. d(k′) 1 0.17. πk /3 or. −0.32 0.78. 0.02.06 yup (3n + 2) 0 0. P12. −0.83 0.83. 1. 0] where h is the causal version.17 xup (3n − 3) ⎡ ⎤ ⎥ ⎥ ⎥ ⎦ Thus. 0.83 0. 0] h1 = d1 = [−0. P12.21.41. P12.21 5 6 L=3. −0. The ideal impulse response is: sin(πk /3) d(k )= .78 1 0. The Hamming windowed version of the filter is obtained by multiplying the full length-13 filter response h by a length-13 Hamming window.05 xup (2n + 4) ⎢ x ( 2n + 2) ⎢ up ⎢ ⎣ xup (2n) xup (2n − 2) ⎤ ⎥ ⎥ ⎥ ⎦ These filtering equations can also be obtained by superimposing the symmetric impulse response of Fig. 1. 0. 0. x(n+1). πk /4 for − 12 ≤ k ≤ 12 This generates the numerical values: 252 253 .06.32. 0.18).3 For the case of a 3-fold interpolator. 1. 0. −0.32 k′ ⎤ xup (3n + 6) 0 ⎢ ⎥ ⎢ xup (3n + 3) −0. 0. with time origin at the left of the vector.21 0 1 2 0. {xup (3n + 6). we have L = 3 and choose again M = 2. xup (3n − 3)} and adding up their contributions at each of the intermediate sampling instants 3n + i.17 −0. xup (3n).05 0 0. The three polyphase subfilters are defined by Eq.32. −0. or. Equations (12. This impulse response is shown in Fig. 0. 11.6 Interpolated values are calculated by the flip-and-slide form of convolution. 0. B A 0.637 0. M.2. 0.127 Z 0.180 0.300.300.4. −0.1.3). 0. 0.13 0.) d(k′) 1 0. P12. L.13 -0. They may be rewritten in the polyphase matrix form (with the low-rate samples listed from the latest down to the earliest): 0.2. Given 2M = 6 low-rate samples {A. char ** argv) { int i.h> void delay(). The corresponding linear combinations of low-rate samples are precisely those of Eq.13 This impulse response is shown in Fig. **h.082 ⎢ ⎥ ⎢ ⎣ Y ⎦ = ⎣ 0. and add up the results. P12.129 ⎤⎢ ⎢ ⎢ 0.082.08 12 -4 -3 -2 -1 0 1 2 3 4 -0.30 L=4. 0.3.90 A 0.000.300 −0.082 ⎢ ⎣ F E D C B A ⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎦ Problem 12. 0.90 0. *y.900 0. B. 0. −0.L-fold FIR interpolator (rectangular and Hamming window design) Usage: hamm L M interp hamm L M < xlow. C. 0. P.10 0.000.212.1.000. E.dat = file containing high-rate interpolated output samples ⎤ ⎡ yup (3n) 0 ⎥ ⎢ ⎢ ⎣ yup (3n + 1) ⎦ = ⎣ 0 0 yup (3n + 2) ⎡ 0 1/ 3 2/3 1 2/3 1/3 ⎤ x(n + 2) 0 ⎢ ⎥ ⎢ x(n + 1) 0 ⎦⎢ ⎣ x(n) 0 x(n − 1) ⎡ ⎤ ⎥ ⎥ ⎥= ⎦ 1/3 2/3 2/3 1/3 #include <stdio.21 -0.13 -0.129.300 0. −0.3.180 −0.900. we have: /* * * * * * * 1) * * */ interp.212 −0. For the linear interpolator. order = P = 2M- xlow. if (argc != 4) { x(n + 1) x(n) ideal interpolation filter Problem 12. (12.5 Length-25 symmetric impulse response of 4-fold FIR interpolator.000.13 0.21 -0.D CX d= [ 0. M=3.08 n′ -0.129 −0. 0.129.0).13 0.18 D C B A 0. 0. 12.64 0. Z} interpolated between C and D are calculated by convolving d with the upsampled low-rate samples.64 0.000. −0.64 Y E F 0.30 0. Y.30 0. we position the impulse response d at the three successive positions. hamm.c implements the polyphase sample-by-sample processing algorithm of Eq.90 0. 0.082.5 The ideal 3-fold interpolation case with M = 2. read off the values of d(k ) where it intersects with the low-rate samples.13 -0. so that N = 2LM + 1 = 2 · 3 · 2 + 1 = 13. double d().6. n.7). 0. 0. (12.18 -0. −0. was discussed in Problem 12.637.000 ] 0.180. 0.5 (where the values have been rounded to 2-digit accuracy for convenience. 12. pi = 4 * atan(1.10 -0.h> #include <math.100 ⎥⎢ 0. (12. P12.18 F -0.3.212 −0.127 ⎦ ⎢ ⎢ ⎢ 0.h> #include <stdlib.000. using Eq.21 C B E 0.900 0.c .08 0. F} as shown in Fig.100 ⎤ ⎡ −0. *w.637.900. 0.127.13 n′ -0.dat = 0/1 for rectangular/Hamming window = interpolation factor = half-length of polyphase subfilters (length = 2M. ⎡ ⎡ X 0. This procedure is shown in Fig.100. Using the flip-and-slide form of convolution as in Fig. P12.21 0.6 The following complete C program interp. −0.18 k′ Z D Fig.127.dat > yhigh. 0. D.637 0. double x.08 -0.19): 254 255 .180. 1.10 n′ Fig.212.10 -12 0. the three values {X. void main(int argc.20) and the initialization procedure of (12.64 0.100. double dot(). N=25 0.30 0.dat = file containing low-rate input samples yhigh.90 E F 0. } } /* -------------------------------------------------------. n++) { w[0] = 0. so that the total filter length is N = 2LM + 1.dat = file for low-rate input samples\n"). printf("%.0). = 0/1 for rectangular/hamm window\n"). double x. char ** argv) { int i.c */ #include <stdio. k. i<L. if (k == 0) return (1. i>=1. n<M. w). M = atoi(argv[3]). y[i]). L. hamm. h[i]. sizeof(double *)).*/ /* d(L. 256 257 .2. sizeof(double)).fprintf(stderr. i++) h[i] = (double *) calloc(2*M. y = (double *) calloc(L. fprintf(stderr.dat > yhigh. fprintf(stderr. i<L. w).dat for (i=0. i<L. k) int L.0. h[i]. = file for low-rate input samples\n"). w + i)."where: hamm fprintf(stderr. h = (double **) calloc(L.0. &x) != EOF) { w[0] = x. Hamming window else h[i][n] = d(L. initialize by Eq.1.20) ith interpolated output sample and write it into stdout update low-rate delay line /* cinterp.c is the circular-buffer version of inkeep reading low-rate samples till EOF terp. computes the high-rate interpolated samples. = interpolation factor\n"). return (sin(t)/t)." L fprintf(stderr. The following program cinterp.2. y[i]).0). sizeof(double)). polyphase filter order allocate L subfilters each of length 2M allocate L polyphase outfprintf(stderr.c ideal interpolation filter ith interpolated output sample and write it into stdout update low-rate delay line hamm L M < xlow.0). else { t = pi * k / L.46*cos((L*n+i)*pi/(L*M))). } delay(P. for (i=0. fprintf(stderr. } hamm = atoi(argv[1]). and writes them to the file yhigh. sizeof(double)). k) ." L = interpolation factor\n"). n<2*M. = half-length of polyphase subfilters\n"). *w.h> #include <stdlib. w). L is the interpolation factor.54 . for (i=0. i<L. n. and M is the half-length of the polyphase subfilters.dat or to the stdout." M = half-length of polyphase subfilters\n").circular-buffer version of interp. M." M fprintf(stderr. for (i=M. i++) construct polyphase subfilters for (n=0."\nUsage: interp hamm L M < xlow. allocate low-rate internal state double d(L."where: hamm = 0/1 for rectangular/hamm window\n"). (12. } } } d(0) = 1 d(k) vanishes at non-zero multiples of L typical sin x/x impulse response The program has usage: interp hamm L M < xlow. fprintf(stderr. pi = 4 * atan(1. the rectangular and Hamming window design of the impulse response may be replaced easily by a Kaiser design. void main(int argc.12lf\n". fprintf(stderr.dat > yhigh.c: process by Eq. if (argc != 4) { fprintf(stderr. } delay(P. } for (n=0." xlow. *y. P = 2*M . Inside the program. double d().dat\n\n").dat or stdin. exit(0). for (i=0. L*n+i-L*M). pi = 4 * atan(1. w = (double *) calloc(2*M. L*n+i-L*M) * (0. i++) { y[i] = dot(P.dat > yhigh.dat = file for high-rate interpolated output samples\n").h> #include <math." yhigh. i++) { y[i] = dot(P.0). n++) rectangular window if (hamm == 0) h[i][n] = d(L. *p. Each low-rate input generates L high-rate outputs.c uses a linear-buffer version of the low-rate delay line used by all the polyphase subfilters. wrap().12lf\n". P. initialize state w by reading first M low-rate input samples while(scanf("%lf".dat\n\n"). printf("%. The program designs the windowed length-N interpolation filter and then reads the low-rate input samples sequentially from a file xlow. i--) scanf("%lf". (12." xlow.dat input-off transients zero input circular version of dot. double cdot(). { double t.h> void cdelay().19) where the parameter hamm specifies a Hamming or rectangular window.c . else { if (k%L == 0) return (0."\nUsage: cinterp fprintf(stderr. **h.ideal L-fold interpolation coefficients */ The program interp. w). L = atoi(argv[2]). { double t. sizeof(double)). p.0.1.0). p = w. sizeof(double)).2. i>=1. &x) != EOF) { *p = x. p). for (i=0. keep reading low-rate samples till EOF beginning of state vector circular version of dot() and write it into stdout update low-rate delay line It uses a circular pointer p that circulates over the low-rate buffer w.46*cos((L*n+i)*pi/(L*M))).4. are shown in Fig. m) for i = 0. . p). w.1. s) cdelay(P. h[i].1) for (i=M. i++) { y[i] = cdot(P. printf("%.19) and (12. (P12.c */ double tap(). w. w. w. (12. hi . *w. } initialize state w by reading first M low-rate input samples process by Eq. y[i]). L*n+i-L*M) * (0. int P. w. k) int L. L*n+i-L*M). w = (double *) calloc(2*M. i++) construct polyphase subfilters for (n=0. i<L. i). (P12.c. if (k == 0) return (1. printf("%. double cdot(P.c. 1.0. 258 259 . The circular-buffer version of Eqs.12lf\n". *p." exit(0).0).20). } cdelay(P.0). y = (double *) calloc(L. .7 together with the corresponding interpolated output signals yup (n ). The given inputs were processed by interp.2. i<=P. } cdelay(P. implemented by cinterp. can be stated as follows: for m = M down to m = 1 do: read low-rate input sample x ∗p = x cdelay(P. n<2*M. & p) and for each low-rate input sample x do: (P12. typical sin x/x impulse response /* -------------------------------------------------------. p) double *h.1) input-off transients zero input circular version of dot() and write it into stdout update low-rate delay line ∗p = x for m = 0. & p) (P12. p) . . Hamming window else h[i][n] = d(L. k) .circular version of dot. for (i=0. cdelay(P. The upsampled versions of these inputs. i++) y += h[i] * tap(P. n<M. return (sin(t)/t). .dat = file for high-rate interpolated output samples\n"). i++) { y[i] = cdot(P. else { t = pi * k / L. p. initialize by Eq. i<L. w. computed by the length-17 Hamming windowed version of the interpolation filter. h. xup (n ). P determine internal states: sm = tap(P. w. M = atoi(argv[3]). . { int i.54 . } } } d(0) = 1 d(k) vanishes at non-zero multiples of L polyphase filter order allocate L subfilters each of length 2M allocate L polyphase outfprintf(stderr.ideal L-fold interpolation coefficients */ double d(L. L − 1 compute output of ith filter: yi = dot(P.*/ allocate low-rate internal state initialize circular pointer /* cdot(P.fprintf(stderr. &p). w. yhigh. &p). w. 1.*/ /* d(L. } for (n=0. i=0. . sizeof(double *)). . i++) h[i] = (double *) calloc(2*M. computes dot product of h with current internal state vector pointed to by pointer p for (i=0. for (y=0. i--) { scanf("%lf". h. n++) { *p = 0. k. else { if (k%L == 0) return (0. n++) rectangular window if (hamm == 0) h[i][n] = d(L. for (i=0. i<L. &p). i<L. w. h[i]. double y. } } /* -------------------------------------------------------. pi = 4 * atan(1. .2) The length-17 rectangular and Hamming windowed filters for this problem were derived in Section 12. y[i]). P12. sizeof(double)). p). L = atoi(argv[2]).2) } while(scanf("%lf". P = 2*M . w.12lf\n". } hamm = atoi(argv[1]). return y. h = (double **) calloc(L. 11. H1 (f ) are shown in Fig. P12.50 Rsingle L1 L0 − 1 Thus.14 F0 − 1 2−1 Fig. P12.fs 2 H0 2fs 4 8fs H1 Fig. The combined filter Htot (f )= H0 (f )H1 (f ) and the superimposed plots of the filters H0 (f ). ΔF N1 − 1 = 8D DF1 = = 40. N1 = 17 Fig.10. Problem 12.70 = Rsingle N The combined filter Htot (f )= H0 (f )H1 (f ) and the superimposed plots of the filters H0 (f ). and individual filters H0 (f ). we found that in order to keep the overall stopband attenuation Rmulti N0 + N 1 F0 = 0. P12. Initially.10 4x2=8-fold oversampling filter. Δf = 5 kHz.9 Combined filter H0 (f )H1 (f ). H1 (f ) are shown in Fig. have Kaiser lengths: N0 − 1 = and are rounded up to: L0 D = 80. we find the filter lengths: N0 = 169. which compares well with the approximation: L0 Rmulti 1 = + ΔF = 0. the multistage realization requires only 54 percent the cost of the single-stage one. P12. shown in Fig.9. The relative computational rate is in this case: N0 = 85 = 2L0 M0 + 1 = 4M0 + 1 N1 = 49 = 2L1 M1 + 1 = 8M1 + 1 The relative computational rate will be ⇒ ⇒ M0 = 21 M1 = 6 N0 + N1 F0 Rmulti = 0.7 We start with fs = 40 kHz.7 Interpolation of triangular and sinusoidal signals. P12.54 = N Rsingle 260 261 . shown in Fig. N = 337 = 2LM + 1 = 16M + 1 ⇒ M = 21 fs 4 H0 4fs 2 8fs H1 The 2×4 multistage filters. P12.27. for the 4×2 case. The effective single stage filter will have Kaiser length: N−1= which is rounded up to: DL = 321. Similarly.8. we designed the filters with stopband attenuations A0 = A1 = 80 dB. P12.8 2x4=8-fold oversampling filter.08 ΔF Fig. However. H1 (f ). and A = 80 for all the stages. P12. 803 = ΔF 0. For the two-stage case. in the 2×2×2 case.12 2x2x2=8-fold oversampling filter.13 Combined filter H0 (f )H1 (f )H2 (f ).7 MAC/msec = 9. H1 (f ). the attenuation of the second filter had to be increased to A1 = 84 dB. we find the filter lengths Fig. Again.5.9 of Section 12.0930 = fs 44. For reference. resulting in the relative computational rate N1 = 25. H2 (f ). a 20-MIPS DSP chip can easily handle it. This gives the Kaiser length: Problem 12.below 80 dB. P12.0930 ⇒ N0 = 109.0930 ⇒ N = 217.1 N0 − 1 = DL0 5. M = (N − 1)/(2L)= 27 The corresponding computational rate of the polyphase realization is Rsingle = Nfs = 217 · 44.2.60 = N Rsingle fs 2 H0 2fs 2 H1 4fs 2 H2 8fs Fig.1 kHz.1 − 20 Δf = 0. the filter length will be: 262 263 . Thus. Thus. P12. or ΔF1 = 1. P12. 12.95)/14.8 In units of fs = 44.0174 · 4 = 215. and individual filters H0 (f ). Fig. the design specifications are depicted in Fig. whereas the first two were A0 = A1 = 80 dB. the transition width from the edge of the passband to the edge of the stopband will be: ΔF = 24. Stage H0 operating at 2fs will have the narrow transition width Δf = 4.95)/14.2.0930.13.0174 · 2 = 107.12. DL 5. Finally. or ΔF = 0. P12.36 = (80 − 7. P12. P12.36 = 5.9 = ΔF 0. M0 = (N0 − 1)/(2L0 )= 27 The Kaiser window width parameter is D = (A − 7.) Thus. but it changed slightly the Kaiser parameters D1 and α1 for that factor. the nominal attenuation of the last factor H2 had to be increased to A2 = 84 dB. N−1= Fig.1 = 9569. we also show in Fig. we find the Kaiser length: The second stage H1 will have a wider transition width Δf1 = fs . shown in Fig. for a single-stage design with oversampling ratio L = 4.0174. N2 = 17 N 0 + N 1 F0 + N 2 F 1 Rmulti = 0.11 Combined filter H0 (f )H1 (f ). P12. and individual filters H0 (f ). H1 (f ). H2 (f ) are shown in Fig. N0 = 85.14 Single-stage 8-fold oversampling filter. The combined filter Htot (f )= H0 (f )H1 (f )H2 (f ) and individual filters H0 (f ). H1 (f ).14 the magnitude response of the single stage 8-fold oversampling filter. This did not change the filter lengths.1 kHz.5697 MIPS (assuming that each MAC is done with one instruction. 264 265 .10 The filter H0 has a cutoff frequency fc = fs /2. The filter H0 operates at rate 4fs and cancels all the images at multiples of fs which are not multiples of 4fs . |H1 (f )| = |H2 (f )| = |Hdac (f )| = sin(πf /L0 fs ) L1 sin(πf /L0 L1 fs ) 2 = = sin(πf /4fs ) 2 sin(πf /8fs ) 2 sin(πf /L0 L1 fs ) L2 sin(πf /L0 L1 L2 fs ) sin(πf /L0 L1 L2 fs ) sin(πf /8fs ) 2 sin(πf /16fs ) πf /L0 L1 L2 fs = sin(πf /16fs ) πf /16fs The phase and magnitude responses are shown in Figs.07 F0 − 1 1.73 Rsingle 217fs Problem 12. the relative computational cost of the two-stage versus the single stage design will be: Rmulti 159fs = = 0.16 Magnitude responses of Bessel and Butterworth filters. P12. M1 = (N1 − 1)/(2L1 )= 6 The polyphase computational rate of the two sections combined will be Rmulti = N0 fs + N1 (2fs )= 159fs = 159 · 44.j*(f/f2).9 MAC/msec = 7. H2 . f1 = 28. and DAC magnitude responses (normalized to 0 dB at DC) are in the general and the particular case of L0 = 4. magH2 = 20 * log10(abs(H2)). The ideal interpolator has cutoff fs /2 and is periodic in f with period Lfs = 4fs . Problem 12.15 Phase responses of Bessel and Butterworth filters. the more bits can be saved via the noise-shaping requantizer./ (15 + 15*j*(f/f2) . The filter H2 operates at rate 16fs and vanishes at multiples of 8fs which are not multiples of 16fs . The proof of the result may be seen graphically in Fig.0119 MIPS Thus. H1 .1 = 7011. Finally.0174 · 4 = = 20./ (1 + 2*j*(f/f1) . The Bessel phase response is essentially linear over the 0–20 kHz passband. argH1 = angle(H1) * 180 / pi.16. and Hdac is to (partially) remove all spectral images at multiples of fs .9 The frequency responses can be computed by the MATLAB code: f = (0:399) * 160 /400. magH1 = 20 * log10(abs(H1)). the passband replicates at multiples of 4fs . H2 = 15 . We note that the combined effect of the two hold transfer functions is an effective DAC operating at 8fs : |H2 (f )Hdac (f )| = sin(πf /L0 L1 fs ) sin(πf /L0 L1 L2 fs ) · L2 sin(πf /L0 L1 L2 fs ) πf /L0 L1 L2 fs = sin(πf /L0 L1 fs ) πf /L0 L1 fs = sin(πf /8fs ) πf /8fs The reason for using H2 is that the higher the L.^2 .15 and P12.17 for the case L = 4.N1 − 1 = DΔF1 5. Hdac vanishes at all non-zero multiples of 16fs .11 Fig. The linear. hold.^3). f2 = 16.000 ⇒ N1 = 25. P12. But its magnitude response is not as flat as the Butterworth’s. The linear interpolator H1 operates at rate 8fs and vanishes at multiples of 4fs which are not multiples of 8fs . argH2 = angle(H2) * 180 / pi.^2 . Thus.^3).2*(f/f1). L1 = L2 = 2: H1 = 1 . the combined effect of H0 . Problem 12. P12. Thus. P12. 400 frequencies in [0.j*(f/f1).6*(f/f2).160] kHz normalization frequency for Butterworth normalization frequency for Bessel Butterworth Bessel Fig. then X(f ) and X (f ) are given by X(ω)= n x(n)e−jωn . m=0 ωm = 2π(mfs ) fs = 2π(mfs /L) fs = 2πm L = mth DFT frequency where S (ωm ) is the L-point DFT of s (n ) calculated from one period of s (n as follows: L−1 Problem 12. corresponds to the quotient and remainder of the division of k by L. we may write L−1 = 2πf fs − 2πmfs Lfs =ω − 2πm L X(ω)= 1 L X ω − m=0 2πm L = 1 L−1 L X ω − 2πm)/L m=0 D(f ) + D(f-fs) + D(f-2fs) + D(f-3fs) Problem 12.7. P12. . we replace s (n ) by its IDFT expression and use the modulation theorem of DTFTs to get: xup (n )= 1 L−1 X (f − mfs )= 1 ∞ L ejωm n x (n ) m=0 ⇒ Xup (ω )= 1 L−1 L X (ω − ωm ) m=0 T Xa (f − mfs − k fs ) k =−∞ But we have seen in Eq. Xup (ω )= X(ω). the sampling function acts as a unit impulse. and as such the integers {k . the sampling function admits a DFS expansion.13 f The discrete-time sampling function s (n ) consists of a periodic train of unit impulses at multiples of L. The terms D(f − mfs ) correspond to the right shifts of D(f ) centered at mfs .17 Sum of successive shifts of ideal lowpass interpolator with L = 4 in Problem 12. that is. The 1/L factor is needed to make the value of passband equal to unity. we have: To transform the relationship xup (n )= s (n )x (n ) to the frequency domain.11. m = 0.D(f) -4fs -3fs -2fs -fs 0 fs 2fs 3fs 4fs f X(f )= 1 L−1 L X (f − mfs ) m=0 D(f-fs) -4fs -3fs -2fs -fs 0 fs 2fs 3fs 4fs f If we use the variables ω and ω . But at the sampling times n = nL we will have xup (n )= x (n )= x (nL)= x(n). It follows that Thus the k summation in the above double sum may be replaced by X (f − mfs ) resulting in the desired result: X(ω)= Xup (ω )= 1 L−1 L X (ω − ωm )= m=0 1 L−1 L X ω − m=0 2πm L 266 267 . 4 for all f s (n )= 1 L−1 L S (ωm )ejωm n . that is. or in units of ω and ω . (12. m} are uniquely determined by k. It is evident from the figure that the these shifted terms fill the gaps between the original replicas. using ω = ω/L. which is unity: S (ωm )= 1. in the L = 4 case we have: 1 D(f )+D(f − fs )+D(f − 2fs )+D(f − 3fs ) = 1.1): -4fs -3fs -2fs -fs 0 fs 2fs 3fs 4fs Fig. s (n )= δ(n ). . (9. . X (ω )= n x (n )e−jω n D(f-2fs) -4fs -3fs -2fs -fs 0 fs 2fs 3fs 4fs D(f-3fs) -4fs -3fs -2fs -fs 0 fs 2fs 3fs 4fs f f The shifted frequency f − mfs is in units of ω : 2π(f − mfs ) fs Thus. 1. Therefore. which gives for the inverse DFT: m = 0. that is. L − 1. at n = nL. Xup (f )= X(f ). the n -summation collapses to the term n = 0. . resulting in a constant spectrum. and inverse DFT expansion of the form of Eq. we may change the summation over k into a double summation over k and m: S (ωm )= n =0 s (n )e−jωm n But within the first period 0 ≤ n ≤ L − 1.21) that the upsampled spectrum is the same as the original low-rate spectrum. Thus. L − 1 X(f ) = 1 ∞ T 1 Xa (f − kfs )= k=−∞ L−1 ∞ 1 L−1 ∞ T Xa (f − (k L + m)fs ) m=0 k =−∞ = T Xa f − (k L + m)fs = m=0 k =−∞ 1 L−1 ∞ s (n )= Xa (f − mfs − k fs ) 1 L−1 L ejωm n = m=0 1 L−1 L e2πjmn m=0 /L LT m=0 k =−∞ where we replaced T = LT and Lfs = fs . Therefore. .12 Writing k = Lk + m. If in the definition of X (f ) we replace f by f − mfs . . the product of s (n ) with x (n ) will insert such zeros. . and separated by L − 1 zeros between.2. 1. Thus. . Because of its periodicity in n with period L. 5 F0 2N ⇒ L − 0 .5 2N F0 L − 0. Memory. 5 10Apass /10 − 1 1/2N 1/2N0 Solving this inequality for L.2 = ΔF 0.062 · 160 DL = 9699. we find N0 = 3 and the range 9. 14.5 + F0 10Astop /20N With the values Apass = 0.928 MIPS The computational speed is easily handled by today’s DSP chips. (12. the transition width parameter D and filter length N will be: D= 95 − 7.5 F0 2N ⇒ L = 0.5 10Astop /10 − 1 10Apass /10 − 1 The prefilter’s stopband must begin at Fstop = fstop /fs = (Lfs − fs /2)/fs = L − 0.18 Decimation ratio versus stopband attenuation in Problem 12. each of length 2K = 62 and operating at a rate fs = 44.1 ⇒ N = 9920 where the final N is of the form N = 2LK + 1 = 320K + 1 with K = 31. and then we used the result of Problem 12. 268 269 .11 to replace the sum of shifted D(f )’s by unity. the interpolation/decimation filter operating at rate fs = 160fs = 147fs = 7. to store the N FIR coefficients is high—of the order of 10k words.5 + F0 10Astop /10 − 1 1/2N For the given numerical values. we find F0 = 0. Given a required attenuation of Apass dB over the passband Fpass = fpass /fs = (fs /2)/fs = 0. Fig.5: L X (f − mfs )= m=0 1 L−1 L D(f − mfs )X(f − mfs )= m=0 1 L−1 L D(f − mfs )X(f )= X(f ) m=0 Apass = 10 log10 1 + Astop = 10 log10 1 + 0 .1.056 MHz can be implemented with 160 polyphase subfilters.Problem 12. P12.97.15 The attenuation of an Nth order Butterworth filter in dB is given by ln N= 10Astop /10 − 1 10Apass /10 − 1 2 ln(2L − 1) A(F)= 10 log10 1 + F F0 2N Let N0 = ceil(N).5 2N F0 ⇒ F0 = 0.18 shows a plot of L versus Astop .9): R = 2Kfs = 61fs = 61 · 48 = 2928 kMAC/sec = 2. which gives the integer range 10 ≤ L ≤ 40.5 10Astop /10 − 1 10Apass /10 − 1 1/2(N0 −1) ≤ N0 Astop = 10 log10 1 + L − 0 .6.16 Using the expression of the attenuation of Problem 12. Fstop = L − 0.0620. The overall sample rate conversion cost in MAC/sec can be calculated from Eq.15.95 = = 6.14 Starting with the filtering equation X (f )= D(f )X(f ). Thus.5. the stopband attenuation will be ≤ L < 0 . In order for the filter order to remain fixed at N0 .36 14. Fig.17 The normalized transition width is ΔF = Δf /fs = (24.86 ≤ L < 40. Problem 12. we get at the passband and stopband normalized frequencies Fpass = 0.5 + 0. we obtain an equation for the 3-dB frequency F0 : N0 − 1 < Apass = 10 log10 1 + 0. however. we find the limits on L: 0 .1 = 0. we form the sum of shifted high-rate spectra: 1 L−1 Problem 12. giving: Problem 12.5 0 .95 A − 7. For large Astop we may ignore the −1 to get L = 0.36 N−1 = 6.15.5 2N = where we used the periodicity of X(f ) with period fs to write X(f − mfs )= X(f ).5. Using a Kaiser design.1 and N = 3. 5 + 0 .94. Thus. 10Astop /10 − 1 10Apass /10 − 1 which may be solved for N.5.1 kHz.41 − 20)/44. the computed quantity N must be in the range ln 10Astop /10 − 1 10Apass /10 − 1 2 ln(2L − 1) where we used the normalized frequencies F = f /fs and F0 = f0 /fs . P12. The corresponding sample processing algorithm will be: for each input block {x0 .Problem 12. 1 The sample processing algorithm of the 2/3 sample rate converter will be then: for each input block {x0 . we find the Kaiser parameter D and filter length N: where P = 2K − 1 is the order of the polyphase subfilters h0 . containing 3 input-rate samples {x0 .19 For the case L/M = 7/4. w) Problem 12. y6 } are selected and computed according to their polyphase indices: 270 271 . Because T = T /2 and T = T /3. y2 }. P12. Assuming a ±1 kHz transition width about fc . the SRC filter acts as an anti-image filter for the upsampler. we have the conversion ratio fs = 32 = · 48 = fs . we also show in Fig.21 depicts the operation of the converter both in the time and frequency domains. fs ′) 2fs′ Fig. The filter operates at the fast rate fs = 3fs = 2fs = 96 kHz and acts as an antialiasing filter for the downsampler. y1 . so that the downshifted replicas—caused by the 3-fold downsampling operation—will not overlap. For reference. w)= x0 y1 = dot(P. P12. we have fs = 7fs /4 and fs = 4fs = 7fs . w) delay(P. for m = 0. it follows that the basic block interval will be Tblock = 6T = 3T = 2T . for m = 0. the polyphase selector indices can be precomputed by im = 3m % 2 = [0. and w is the length-(P + 1) input-rate delay-line buffer. w) w 0 = x0 y0 = dot(P.6247 · 2 · 48 DLfs = = 173. h1 . we have fs = 3fs /2 = 3 · 32/2 = 48. Δf = 2 kHz.19 Ideal SRC filter with conversion ratio 2/3. h2 . 2. The interpolated output y1 that lies halfway between x1 and x2 is obtained by the polyphase filter h1 . so that L = 2. Thus. 1]. y2 . it removes the high frequencies from the input in the range [fs 2. x1 x0 T polyphase selector i= 0 2 1 filter t 0 t T/3=T′′ t 0 fs fs′ fs′ 2fs 3fs=fs′′ f 0 2fs′=fs′′ f 0 1 2 f fs 2fs 3fs f x0 polyphase selector i= 0 x1 x2 t T t 1 filter f 0 fs fs fs′ fs′ 2fs′ 2fs′ 2fs f 0 t 2fs=fs′′ f 0 3fs′=fs′′ f 0 1 2 y0 y1 y2 T′ T′/2=T′′ t T/2=T′′ 6T′′=2T=3T ′ min(fs . x1 } generates a group of three output samples {y0 .95 = = 3.20 the reverse converter by a ratio 3/2. converting from 32 kHz up to 48 kHz. y4 . x1 . h1 }. that is.20 Ideal SRC filter with conversion ratio 3/2.and output-rate sampling intervals are T = 3T and T = 2T . w) w0 = x1 y2 = dot(P. the three interpolated outputs {y0 . In this case. M = 3. x2 } do: w 0 = x0 y0 = dot(P. Indeed. w) w0 = x1 y1 = dot(P. P12. every group of two input samples {x0 . Because 48 3 fs < fs .36 N−1 = 3.98 Δf 2 ⇒ N = 177 where we rounded N to the next odd integer of the form N = 2LK + 1. w) delay(P. Tblock = 28T = 7T = 4T. x2 .19 shows the ideal specifications of such a filter. w)= x0 delay(P. fs /2]= [16. Here. Fig. The input. P12. the polyphase selector sequence is im = 2m % 3 = [0. and therefore. each input block of 4 input-rate samples {x0 .95 60 − 7. K = 44. h1 . D= A − 7. x1 . y1 . h0 . 1]. the filter’s cutoff frequency will be fc = fs /2 = 16 kHz. out of which 7 output-rate samples {y0 . y3 . x2 } and 2 output-rate samples {y0 . h1 . 24] kHz. h0 . and there will be L = 2 polyphase subfilters of length 2K = 88. y4 . T = T /4 = T/7. Therefore. Thus. w) delay(P. x1 } do: y0 y1 T′ 6T′′=3T=2T ′ T′/3=T′′ t min(fs . The fast rate is fs = 2fs = 3fs = 96 kHz. fs ′) 3fs′ Fig. y1 . and the basic time block Tblock = 6T = 2T = 3T . that is. y1 }. w) w0 = x2 delay(P.18 32 2 Here. 14. x2 is simply read into the buffer w and the delay line is updated. h2 . x3 } generates 28 fast-rate interpolated samples. x1 . P12. 1. y2 } will be computed by the subfilters {h0 . As can be seen in the figure.6247. In the time domain. and a A = 60 dB stopband attenuation. 2. Fig.36 14. Note that there is no interpolated output after x2 (the next two outputs come from the next group of three inputs). w) delay(P. . y2 . w) w0 = x3 y6 = dot(P. y5 lie between the input samples x2 . 6. 3. w) w0 = x1 y2 = dot(P. In the time domain. w) w0 = x3 y2 = dot(P. x4 . the SRC filter acts as an anti-image postfilter for the upsampler. . w)= x0 y1 = dot(P. w) w0 = x6 delay(P. 1]. . w) y3 = dot(P. 1. 2. out of which 4 output-rate samples {y0 . . the sample processing conversion algorithm will be as follows: for each input block {x0 . for m = 0.21 Ideal SRC filter with conversion ratio 7/4. and 3fs . P12. T′ 28T′′=7T=4T ′ im = 4m % 7 = [0. Tblock = = 4T = 7T. w)= x0 delay(P. 3] whenever the index nm is repeated. x3 . h4 . x1 . However. 2. for the remaining input samples the delay line must be updated. 3]. x3 } do: im = 7m % 4 = [0. The sample processing conversion algorithm is as follows: for each input block {x0 . x3 . 1. h0 . P12. we have fs = 4fs /7 and fs = 7fs = 4fs . the input-rate polyphase delay line is not updated. Fig. removing the L − 1 = 6 replicas between multiples of the fast rate fs . w) delay(P. h2 . w) w0 = x2 y4 = dot(P. . 3 w0 = x0 y0 = dot(P. f ′) s s 2 2fs′ 2fs′ 3fs′ 3fs′ 2fs 2fs 4fs′ 4fs′ 3fs 3fs 5fs′ 5fs′ 6fs′ 6fs′ 4fs f 0 4fs=fs′′ f 0 t 7fs′=fs′′ f 0 7fs′ 2 1 0 1 2 T′/7=T′′ t y2 y3 min(fs . fs ′) Fig. x2 . 2fs . w) delay(P. w) w0 = x2 delay(P. h0 . In the frequency domain. x1 . y3 } are selected and computed according to their polyphase indices: nm = (4m − im )/7 = [0. w) delay(P. 0. w) 272 273 . w) w 0 = x4 delay(P. h1 . Thus. x5 . h1 . h6 . x1 . . and then the next input sample x3 is read into the delay line. h5 . 2. T = T /7 = T/4. 1. x6 } generates 28 fast-rate interpolated samples. h3 . 4. x2 . w) delay(P. w) w0 = x5 y3 = dot(P. the two output samples y4 . x2 . x5 will produce output samples. 5. .22 Ideal SRC filter with conversion ratio 4/7. x3 . 5] so that only the input samples x0 .22 depicts the operation of the converter both in the time and frequency domains. The delay line is updated after both outputs are computed. nm = (7m − im )/4 = [0. w) w0 = x1 y1 = dot(P. P12. x1 . x4 . 2. y1 . 1. h2 . w) For example. and so on. w) delay(P. 3. w) y5 = dot(P. 6 Fig. w) delay(P. 1 5 2 6 3 T′/4=T′′ t y1 y2 y3 y4 y5 y6 t T′ 28T′′=4T=7T ′ 0 0 y0 f x2 x0 x1 6fs 7fs=fs′′ polyphase f selector 4fs′=fs′′ i= 0 3 f 4fs′ y0 y1 x3 x4 T x5 x6 t T/4=T′′ t 0 filter f fs fs fs′ fs′ 1 min(f . 1. The downshifting of the replicas caused by the downsampling operation will position replicas at the 3 multiples of the output rate fs .x0 polyphase selector i= 0 4 x1 x2 T x3 t T/7=T′′ t 0 filter fs fs fs′ fs′ 2fs 2fs 3fs 3fs 2fs′ 2fs′ 4fs 4fs 5fs 5fs 3fs′ 3fs′ 6fs 7fs f28T In the L/M = 4/7 case. . for m = 0. h3 . each input block of 7 input-rate samples {x0 . x5 . x3 and correspond to the i = 2 and i = 6 interpolated samples. 1. x6 } do: w0 = x0 y0 = dot(P. removing the 3 replicas between multiples of the fast rate fs .1102 * (A . K = ceil((N . 6fs .. Kaiser length round up final length polyphase filter order filter delay allocate direct form cutoff frequency window normalization compute L outputs write L outputs N = 1 + ceil(D*L / DF). n<=P. .1 ⇒ N = 209 where N the smallest odd integer of the form N = 2LK + 1.95 = 5. .07886 * (A-21). for (i=0. n<N. 0.21 The polyphase Kaiser filter can be designed by the code fragment: double *hd.95) / 14.1.) { for (n=0. Thus. K = 26. y[m]). we allocate and initialize the polyphase delay-line buffer w as follows: w = (double *) calloc(P+1. via the stretching relationship wρ (k )= w(ρk ). n++) if (scanf("%lf". 21) = 0. D = (A . Because each call generates M zero inputs. y = (double *) calloc(L. wc = pi / max(L. . m++) printf("%. i <= K/M. n++) h[i][n] = hd[L*n+i]. allocate polyphase i-th polyphase define polyphase filters D= 80 − 7. (12.1. **h. (12. m++) printf("%. N = 2*L*K + 1. } h = (double **) calloc(L. w+i) == EOF) { printf("must have at least K = %d input samples\n".0). the SRC filter acts as an antialiasing prefilter for the downsampler. Upon encountering the endof-file of the inputs. n<M.95 A − 7. for (i = 0. P. M.13) is implemented by the routine: /* src. i < L. for (m=0. M). for (n=0. m<L.13) K/M more times with zero input samples.0*LK-n)) / LK) / I0alpha.5842 * pow(A-21. P. = 14. w.6. A symmetric window of such length will depend on the variable k /(2LKρ )= ρk /(2LK). *w.1) / (2. i>=1. i++) { for (n=0. i++) for (n=0. sizeof(double)). Assuming the input data are being read from stdin. pi = 4 * atan(1. } wρ (k )dρ (k )= ρw(ρk )d(ρk ) Problem 12. *x. The effective length of the stretched impulse response is Nρ − 1 = 2LKρ = 2LK/ρ. sizeof(double *)).12lf\n". It follows that the corresponding windowed impulse responses will be for (i=K. allocate the input/output blocks for the algorithm Eq. i<L. here. sizeof(double)). src(L. x. x+n) == EOF) goto transients. } last K inputs The sample processing algorithm (12. allocate w Problem 12. } transients: for-ever do: read M inputs = 0. we jump out of the for-ever loop and call Eq. sizeof(double)). LK = L*K.12lf\n". = 0.13) and keep processing input samples in groups of M.4) + 0. sizeof(double)). n<M. *y.8.0174 . w. . n++) x[n] = 0.70 = ΔF 0.7).7. M). n++) compute filter if (n==LK) middle value hd[n] = L /(double) max(L. The downshifting of the replicas caused by the downsampling operation will position replicas at the 6 multiples of the output rate fs .0*L)). 274 275 .20 A typical window depends on the time variable k through the ratio k/(N− 1).36 14.h> double dot(). y). the window of length 2LKρ can be expressed in terms of the same window of length 2LK. m<L. y[m]). hd = (double *) calloc(N. for (m=0. for (i=0. i--) read K input samples if (scanf("%lf". I0alpha = I0(alpha). sizeof(double)).0174 · 4 = 200. P = 2*K . The computed outputs go into stdout. the K/M calls will generate approximately M(K/M)= K zero inputs: x = (double *) calloc(M.6. h.c . i++) h[i] = (double *) calloc(P+1. without overlapping. The width parameter D and filter length N will be: hd[n] = wind * L * (sin(wc*(n-LK))) / (pi*(n-LK)). As a design example.In the frequency domain.6. consider the 4/7 case and assume a Kaiser design with a stopband attenuation of 80 dB and normalized transition width ΔF = Δf /fs = 0. if (A > 50) alpha else if (A > alpha else alpha Then. src(L. y).36 N−1 = DL 5. for (.36. x.sample rate converter processing algorithm */ #include <math. K). M. wind. else { wind = I0(alpha * sqrt(n*(2. exit(0). h. 2fs . 3 kHz. *x.5 kHz. . . Fig. y[m] = dot(P. x. (12. α. fs /2)= 3/2 = 1. With the values A = 30 dB.536. The passband ripple is δ = 10−A/20 = 0. the 5/3 filter has D = 1. and of x(n) and reconverted y(n ). . h[i]. } } The frequency responses were computed by direct evaluation of: N−1 H(f )= n =0 h(n )e−2πjf n /fs . Were they to be redesigned to have the same Δf .23 both in absolute and dB scales. The dB responses have been normalized to 0 dB at DC. I0 (α) π(n − 24) n = 0. P = 2K − 1 = 15. The impulse responses are obtained from Eq. { int n. because N = 2LK + 1. double R = L / (double) M. with LK = 5 × 8 = 40 and LK = 3 × 8 = 24 in the two cases.22 Replacing the quantizer Q by its equivalent noise model. m++) { polyphase selector i = (M * m) % L. K = 13.23 Frequency responses of SRC filters.5 kHz. K. P12. P = 25. h is Lx(P+1) polyphase filter matrix w is (P+1)-dimensional delay buffer x. V (ζ) = X (ζ)−ζ −1 Y (ζ) W0 (ζ) = V (ζ)+ζ −1 W0 (ζ) Y (ζ) = E (ζ)+W0 (ζ) Eliminating V (ζ) and W0 (ζ). . P12. } delay(P. . ΔF = 0. and P. *y. . n++) { w[0] = x[n].06.1×3 = 0.24 shows the output y(n ) of the 5/3 filter and compares it with the signal x (n ) that would have been obtained had the analog signal been sampled at 3 kHz. m <= floor(R*(n+1)). void src(L. but its length is N = 49. K = 8. 276 277 .24 Comparison of y(n ) and x (n ).5). The filter responses are shown in Fig. we obtain: Y (ζ)= X (ζ)+(1 − ζ −1 )E (ζ) Therefore.1×5 = 0.void delay(). w). respectively. The dc gains are 5 and 3. I0 (α) π(n − 40) I0 (α n (48 − n )/48) sin π(n − 24)/5 .117. Hx (ζ)= 1. On the right. n < M. ωc = π/5. w. with fs = 15 kHz Figure P12. then for the 3/5 filter we would have ΔF = 0. .032. resulting in the lengths N = 79. The main advantage of this form is that the input signal X (ζ) appears unchanged at the output (as opposed to being delayed as in the conventional case). α = 2. N = 81. 48 for (n = 0. say 0. that is. P12. where now L = 3. y) double **h. The reverse 3/5 filter has the same D. 1.and L-dimensional vectors conversion ratio h5/3 (n )= 5 h3/5 (n )= 3 I0 (α n (80 − n )/80) sin π(n − 40)/5 . . Problem 12. for (m = ceil(R*n). h. 80 n = 0.1.y are M.6.3 kHz. P. Their transition widths are different: the first filter has Δf = 0. *w. w). and compares it with the original x(n). In that case. m. we can write the ζ -domain input/output equations: Fig. and HNS (ζ)= 1 − ζ −1 . the filters would be virtually identical (except for the gain and the delay by 1 sample). M. or. Both filters have a cutoff frequency of fc = min(fs /2. 1. and the second Δf = 0. i. it shows the effect of the reverse 3/5 filter on y(n ). 20 −0.40 0.Problem 12.20 y −1 1 H1(ζ) H2(ζ) x′ + − -1 w1 ζ w0 + − v0 v1 u ζ -1 ζ -1 −1 1 Q quantizer y′ −1 −1 1 −1 1 −1 Fig.40 0.24 Working in the ζ -domain.20 −0. Problem 12.20 −0.23 Using the signal labels indicated on the block diagram.20 −0.5 * sin(2 * pi * f0 * n). 1 − ζ −1 H2 (ζ)= ζ −1 1 − ζ −1 (This problem is similar to Problem 7. we note that the input and output of the filter H1 (ζ) will be: Y (ζ)= X (ζ)−ζ −1 H1 (ζ)H2 (ζ) 1 + H2 (ζ)+H1 (ζ)H2 (ζ) X (ζ)+ Y (ζ) and H1 (ζ) X (ζ)−ζ −1 Y (ζ) Thus. Problem 12.4 and x = −0. The requirement that Hx (ζ)= ζ −1 and HNS (ζ)= (1 − ζ −1 )2 is satisfied by the choices: Y (ζ = E (ζ)+H2 (ζ) H1 (ζ) X (ζ)−ζ −1 Y (ζ) − ζ −1 Y (ζ) Moving the Y (ζ) to the left-hand side and solving for Y (ζ) gives the transfer relationship: 1 H1 (ζ)H2 (ζ) E (ζ) X (ζ)+ Y (ζ)= 1 + ζ −1 H2 (ζ)+ζ −1 H1 (ζ)H2 (ζ) 1 + ζ −1 H2 (ζ)+ζ −1 H1 (ζ)H2 (ζ) Thus.40 0. and the subsequent filtering by the decimation filter can be carried out by the following for-loop (which does not discard the interpolated outputs.25.25 Without the feedback delay. P12.40 0.40 0.4 and −0.2: w0 = w1 + (x − u) v0 = v1 + (w0 − u) y = Q(v0 ) w1 = w0 v1 = v 0 u=y x 0.20 −0. Thus. the 2-level quantization of the input by the delta-sigma quantizer. n++) { x = 0.40 0. Hx (ζ)= 1 + ζ −1 H2 (ζ)+ζ −1 H1 (ζ)H2 (ζ) HNS (ζ)= 1 1 + ζ −1 H2 (ζ)+ζ −1 H1 (ζ)H2 (ζ) The requirement that Hx (ζ)= 1 and HNS (ζ)= (1 − ζ −1 )2 is satisfied by the choices: H1 (ζ)= H2 (ζ)= 1 1 − ζ −1 high-rate input sample 278 279 . the input and output of H2 (ζ) are: H1 (ζ) X (ζ)−ζ −1 Y (ζ) −ζ −1 Y (ζ) and H2 (ζ) H1 (ζ) X (ζ)−ζ −1 Y (ζ) −ζ −1 Y (ζ) Hx (ζ)= H1 (ζ)H2 (ζ) 1 + H2 (ζ)+1 (ζ)H2 (ζ) .25 Discrete-time model of second-order delta-sigma quantizer.26 Once the decimation filters are designed. The averages of the y values are 0. P12.40 0. but without the ζ −1 delays in the denominators. that is. respectively.2): w1 = 0. we identify: H1 (ζ)= 1 .20 −0. we get for x = 0. n<Ntot.7. we get a similar transfer relationship as in the previous problem.) Problem 12. The corresponding sample processing algorithm can be stated as follows: for each input x do: v =x−u w0 = v + w1 y = Q(w0 ) w1 = w0 u=y Iterating this algorithm 10 times. initialize delay H1 (ζ)H2 (ζ) .20 −0.20 −0.40 y 1 −1 1 1 1 −1 1 1 −1 1 x −0.20 −0.2.2.40 0. we have the sample processing algorithm: for each input x do: A block diagram realization is shown in Fig. HNS (ζ)= 1 1 + H2 (ζ)+H1 (ζ)H2 (ζ) Adding E (ζ) to this output will generate Y (ζ). as discussed in Example 12. we identify: 1 E (ζ) 1 + H2 (ζ)+H1 (ζ)H2 (ζ) Similarly.40 0. for (n=0. 26 Length-19 second-order comb magnitude response and filter output. The implementation of the secondorder delta-sigma quantizer is given by the sample processing algorithm discussed in Problem 12.28 Working in the ζ -domain. v1 = v0. 8.27 shows the signal x (n ) and the 2-level quantized output y (n ) of the second-order quantizer. Applying the basic I/O equation (P12. 3. y = Q(v0). w1 = w0. The upsampled outputs yup (n ) of the averaging. n++) { x = 0. and filters the quantized output with the decimation filter: Inserting H(ζ)= 1/(1 − ζ −1 ). for (n=0. yup[n] = fir(N-1. The input to H(ζ) is X (ζ)−ζ −1 Y1 (ζ). 1 . 1 . we obtain the impulse response by convolving the first-order comb’s impulse response with itself. 4. Fig. H(ζ)= 1 1 − ζ −10 10 1 − ζ −1 2 The magnitude response of the second-order comb case is the square of that of the first-order case: |H(f )| = sin(πf /fs ) L sin(πf /10fs ) 2 It is plotted in dB in Fig. (Y − E1 )−Y = −E1 .y. 1 . 6. The following for-loop generates the high-rate input. Thus. and Kaiser window decimators are shown in Fig. adding the noise component. 1 . In the Kaiser and the rectangular window designs. 2. 5. y). The upsampled output yup (n ) of the second-order comb decimator is plotted in the right graph of Fig. 1 . we obtain the I/O equation of the first stage. we have: Y1 (ζ)= E1 (ζ)+H(ζ) X (ζ)−ζ −1 Y1 (ζ) which can be rearranged as: Fig. In the first-order comb case.27 High-rate input and output signals of second-order ΔΣ quantizer. n<Ntot. yup[n] = fir(N-1. 10 H(ζ)= 1 1 − ζ −10 10 1 − ζ −1 For the second-order comb case.26 together with the first-order comb case and the rectangular window design. 1 ] . w. u = y. w0 = w1 + x .3) where D(ζ)= 1 − ζ −1 .28. 100 Figure P12. it is N = 10. quantizes it by the 2nd-order quantizer. h. 2. P12.27 The filter designs are the same as in the previous problems.u.26. 5. Y1 (ζ)= H(ζ) 1 + ζ −1 H(ζ) X (ζ)+ 1 E (ζ) 1 + ζ −1 H(ζ) 1 Problem 12. w. } initialize delays high-rate input sample output of H1 output of H2 ΔΣ quantizer output update quantizer’s delays update quantizer’s delays update quantizer’s delays (upsampled) decimator output where h and w are the N-dimensional impulse response and internal state arrays for the decimator. 9. 3. 1 . h. 1] . 6. we obtain 280 281 . 10. the filter length is N = 2LM + 1. } ΔΣ quantizer output delta part sigma part update quantizer’s delay (upsampled) decimator output w1 = v1 = u = 0. w1 = w0. P12. 7.3) to this input and corresponding noise E2 . v = x . P12. 7. P12.y = Q(w1). second-order comb. Problem 12. y). v0 = v1 + w0 .u. 8. w0 = w1 + v.24. 9. and the impulse response and transfer function are: h= 1 [ 1. P12. 1 . that is.5 * sin(2 * pi * f0 * n). 4. The input to the second stage is obtained by forming the difference of the signals around the first quantizer. 1. rectangular. we obtain the transfer relationship of one stage: Y1 (ζ)= X (ζ)+(1 − ζ −1 )E1 (ζ)= X (ζ)+D(ζ)E1 (ζ) (P12. This gives a length N = 19 response and transfer function: h= 1 [1. such a delay may render the closed-loop system unstable. Therefore.28 puts.30. The outputs of the three stages are: = X (ζ)+D3 (ζ)E2 (ζ) Y1 (ζ) = X (ζ)+D(ζ)E1 (ζ) Problem 12. the quantization error from the first stage is canceled. y 2nd stage − + −e1 + − H(ζ) ζ -1 D(ζ) D(ζ) y3 Fig. The I/O relationship of the first stage is Y2 (ζ)= −E1 (ζ)+D(ζ)E2 (ζ) The overall output is obtained by the linear combination: (P12. First. P12. See [294] for further discussion. In feedback control applications.3): Y (ζ) = Y1 (ζ)+D(ζ)Y2 (ζ)= X (ζ)+D(ζ)E1 (ζ)+D(ζ) −E1 (ζ)+D(ζ)E2 (ζ) = X (ζ)+D(ζ)E1 (ζ)−D(ζ)E1 (ζ)+D2 (ζ)E2 (ζ)= X (ζ)+D2 (ζ)E2 (ζ) Thus.4) Y1 (ζ)= X (ζ)+D(ζ)E1 (ζ) The input to the second-order quantizer is −E1 (ζ).and Kaiser-window decimator out- Problem 12. P12. whereas the error of the second stage gets filtered by the second-order highpass filter D2 (ζ)= (1 − ζ −1 )2 .31 The delay of (N − 1)/2 = LM introduced by the decimation filter must be taken into account in both multiplexing and control applications.8.29 MASH architecture of third-order delta-sigma quantizer. Y2 (ζ) = −E1 (ζ)+D(ζ)E2 (ζ) Y3 (ζ) = −E2 (ζ)+D(ζ)E3 (ζ) The overall output is obtained by the linear combination: 282 283 . P12.30 Such an architecture is depicted in Fig.29 Such an arrangement is shown in Fig. Y2 (ζ)= −E1 (ζ)+D2 (ζ)E2 (ζ) The overall output is obtained by the linear combination: Y (ζ) = Y1 (ζ)+D(ζ)Y2 (ζ)= X (ζ)+D(ζ)E1 (ζ)+D(ζ) −E1 (ζ)+D2 (ζ)E2 (ζ) Problem 12.Y (ζ) = Y1 (ζ)+D(ζ) Y2 (ζ)+D(ζ)Y3 (ζ) = X (ζ)+D(ζ)E1 (ζ)+D(ζ) −E1 (ζ)+D(ζ)E2 (ζ)+D(ζ) −E2 (ζ)+D(ζ)E3 (ζ) = X (ζ)+D3 (ζ)E3 (ζ) 1st stage x + − H(ζ) ζ -1 e1 y1 e2 y2 e3 − + −e2 3d stage + − H(ζ) ζ -1 Fig.29.and second-order comb. and rectangular. its I/O relationship is (from Problem 12. P12. σx 2 =1+2 m=1 m2 = 1 + 2 σy = 2D 2 + 1 2 2D 2 + 1 2 σu σx = 3D 2 3D 284 285 . we can replace the double summation over i and d by the summation over m: Rxx (k)= 2nd stage − + −e1 + 2 σu D δ(k + m)δ(m)= m 2 σu δ(k) D Thus. h(n) consists of D ones: NRR = 2 σy 2 σx D−1 = n=0 1=D ⇒ 2 2 σy = Dσx = D 2 σu 2 = σu D For the linear interpolator.Appendix B Problems Problem B. x(n) is stationary and has a delta-function autocorrelation. This gives: NRR = 2 σy D σx 2 = n=0 1− |n| D 2 D =1+2 n=1 1− n D 2 =1+2 1 D−1 D2 m2 m=1 Using the identity 2 σy D−1 m=1 m2 = 1 D(D − 1)(2D − 1).1 The input sequence is x(n)= i ui δ(n − iD − d) Its autocorrelation function is D−1 Rxx (k)= E x(n + k)x(n) = i j d=0 E[ui uj ]δ(n + k − iD − d)δ(n − jD − d)p(d) where the expectation values were taken with respect to both ui and d.30 MASH architecture of third-order delta-sigma quantizer. P12. For the particular case of a hold interpolator. It follows that: Rxx (k)= 2 σu D D−1 δ(n + k − iD − d)δ(n − iD − d) i d=0 1st stage x + − H(ζ) ζ -1 e1 y1 e2 y2 − H(ζ) − H(ζ) ζ -1 D(ζ) y Changing variables to m = n − iD − d and noting that m runs over all the integers. Because the ui are mutually 2 independent and zero mean and d is uniform. for |n| ≤ D. Sending this sequence into the interpolation filter will generate a stationary output sequence y(n) with a noise reduction ratio: NRR = 2 σy 2 σx = n h(n)2 Fig. we have E[ui uj ]= σu δ(i − j) and p(d)= 1/D. we have h(n)= 1 − |n|/D. we obtain: 6 2D 2 + 1 D(D − 1)(2D − 1) (D − 1)(2D − 1) = =1+ 3D 2 3D 3D D−1 NRR = Thus. 0). Problem B. cdelay2(). h. w). y. P14.2 The power spectral density of the output sequence will be related to that of the input by: 2 Syy (z)= H(z)H(z−1 )Sxx (z)= H(z)H(z−1 )σx = H(z)H(z−1 ) 2 σu D For the hold interpolator. double rani(L. & q. the output psd becomes: H(z)= H(z−1 )= 1 − zD 1 − z−D D−1 z = 1−z 1 − z−1 1 − z−D 1 − z−1 2 2 zD−1 σu Syy (z)= H(z)H(z−1 ) 2 σu 1 = D D Taking inverse z-transforms with the help of Problem 5. 0. w. long iseed. P14. 1 − z−1 Thus. usage: y=rani(L. y = (double *) calloc(N.0. y = dot(P. P14. iseed) int L. n++) y[n] = ranh(D.1 Problem B. long *iseed. we have: 1 − z−D .c . zero mean sample autocorrelation Problem B. fft(N. void delay(). R = (double *) calloc(M+1. *y. double y.5. if (*q==0) w[0] = ran(iseed) . X). w. *w. P. h. N-dimensional (M+1)-dimensional initialize u initialize q Fig.4 As was mentioned in the end of Section B. u.3. for (n=0. R).Problem B. } generate K = 200 blocks initialize kth block generate kth block compute its FFT every L calls get new random number zero mean current polyphase index compute interpolated value accumulate its periodogram A typical averaged spectrum is shown in Fig.5. we find: Ryy (k)= 1 − |k| 2 σu D Fig.5 The random number generator C routine is: /* rani. q = D * ran(&iseed). u[0] = ran(&iseed)-0. for the case D = 5. y. P. *R. for(n=0. i = (L .2 Averaged periodogram spectrum of held noise. n<N.3 The generation of the held signal and the computation of its autocorrelation is illustrated by the following C program segment: double *u. P14. & iseed). n++) S[i] += cabs(X[i]) * cabs(X[i]). n++) X[n] = cmplx(ranh(D. { int i. corr(N. n<N. n<N. sizeof(double)). k<K. &iseed).low-frequency random number generator using interpolation */ double ran(). for (n=0. u. *q.2. P.1 Sample autocorrelation of length-100 hold noise. &iseed). 286 287 . M. h[i]. k++) { u[0] = ran(&iseed). q and iseed passed by reference h = polyphase filter matrix required long by ran() A typical sample autocorrelation is shown in Fig. sizeof(double)). q. &q.*q) % L. the averaged periodogram spectrum can be calculated by the following loop: for (k=0. q = D * ran(&iseed).11. double **h. dot(). &q. initialize w 288 289 . initializes the delay line w in accordance with Eq. if (*q==0) delay(P. sizeof(double)). hd[n] = wind * L * (sin(wc*(n-LK)))/(pi*(n-LK)). wc = pi / L. K. w = (double *) calloc(P+1. double **h. sizeof(double)).5. n<N. DF. i--) w[i] = ran(&iseed) . sizeof(double *)). windowed filter for (n=0.c and ranl.2.dat\n" = 0. wc. sizeof(double)).95) / 14. N = 1 + ceil(D * L / DF). The following program raniex. if (argc != 5) { puts("\nUsage: " k " L " Ntot " iseed exit(0).7. "enter A.07886 * (A-21).10 if (k == 0) { N = L. for (i=K.abs(n .1. P = 2 * K .c is an example C program that invokes rani.linear. i++) h[i] = (double *) calloc(P+1. for (i = 0. for (n=0. it generates the same output as ranh. al. Ntot = 150. (12. 1.c was given in Ch. long iseed. n<=P. n++) if (n==LK) hd[n] = 1. n<N. LK. &A. n++) hd[n] = 1.h> #include <math.7). atoi(argv[1]). N.cdelay2(L-1.h> #include <stdlib. i++) for (n=0. w). int q.h> double ran(). i.2 for hold. atol(argv[4]). polyphase subfilters allocate L subfilters Kaiser interpolator if (k >= 2) { fprintf(stderr. The very last for-loop generates the desired numbers. i < L. linear. char ** argv) { double pi = 4 * atan(1. atoi(argv[2]). &DF). Most of it is concerned with designing and allocating the polyphase filters.L) / (double) L. P = 0. DF (in units of fs): " ). } k L Ntot iseed = = = = I0.1102 * (A . K = 1. N = 2 * L * K + 1.0*L)). ΔF = 0. iseed = 1234567 A = 30 dB. 2 = hold. N = 2*L+1. } decrement q for next call every L calls update delay line if (A > 50) al = 0. wind. i<L.19): /* raniex. n<N. } hold interpolator linear interpolator raniex k L Ntot iseed > y. n. For the hold and linear interpolators. *w. D. I0().c . k. double I0al. return y.general interpolator\n" = upsampling ratio\n" = total random numbers\n" = initial seed\n"). void main(int argc. 0. h = (double **) calloc(L.interpolated random number generator example */ K = ceil((N . } } #include <stdio. filter length filter order filter delay direct form filter ideal cutoff frequency run with: k = 0. else { wind = I0(al * sqrt(n*(2. atoi(argv[3]).36.0. Ntot. ith subfilter low-rate delay-line buffer D = (A .1. rani(). for (i=0. hd = (double *) calloc(N. q). } if (k == 1) { P = 1. i>=1. *hd. K = 0.0*LK-n)) / LK) / I0al.4) + 0. n++) h[i][n] = hd[L*n+i]. n++) hd[n] = 1 . else al = 0.3 I0al = I0(al).5842 * pow(A-21. P.8.c. scanf("%lf %lf". Kaiser interpolators L = 10. A.0).1) / (2. else if (A > 21) al = 0. for (n=0. The for-loop before the last one. int L. LK = L * K. &q.1) can be summed in closed form as follows. hold.25).4 for the case B = 4.117.50 0.1) gives the expected result: 2 σy = Ryy (0)= 1 B2 2 · Bσu = 2 σu B The increasing linear slopes in Ryy (k) cause it to have long-range correlations.. together with the sample autocorrelation of a (zero-mean) block of 1/f -noise samples of length N = 2000 for B = 8.75 0. for (n=0. q. The restriction |k| ≤ 2b − 1 can be turned around into a restriction for the summation index b ≥ log2 (|k| + 1). P14. 290 291 . P14. Eq. *R. sizeof(double)). Denoting the ceiling of this quantity by b(k)= log2 (|k| + 1) Fig. P. (P14. (B.7 Fig. or |k| ≤ 2b −1 for non-zero values of Ryy (k). At lag k = 0. This is shown in Fig.1) where the unit-step u(2b −|k|) restricts the duration of the b-th term to be |k| ≤ 2b . (6. ΔF = 0. rani(L. Problem B.3. and linearly interpolated random sequences. sizeof(double)). h. Problem B. Figure P14.5 shows the theoretical autocorrelation (P14. we get the expression of Eq. y. &iseed)).25). n++) printf("%. n<Ntot.2) Given a lag k in the range |k| ≤ kmax . P14. The sample autocorrelation was computed by the program segment: double *y. the maximum lag will be: kmax = 2B−1 − 1 (P14. M. we have: 1 B−1 N-dimensional (M+1)-dimensional use N=2000 zero-mean y’s use M=150 Ryy (k)= B2 Ryb yb (k)= b=0 1 B−1 B2 1− b=0 |k| 2b 2 u(2b − |k|) σu (P14. Indeed. −D ≤ k ≤ D. the Kaiser parameters become D = 1.3 Kaiser.4 Theoretical autocorrelation of 1/f -noise model.13)). α = 2. corr(N.536. y = (double *) calloc(N. because of the restriction |k| ≤ 2b − 1. Eq.1) or (B. generate interpolated noise for (n=0.12lf\n". The generated sequences are shown in Fig. R = (double *) calloc(M+1. (P14. The resulting autocorrelation function is piece-wise linear.R(k)/R(0) q = 0. k Fig. P14.6 Noting that the autocorrelation of a hold-interpolated sequence of period D is R(k)= (1 − 2 |k|/D)σu . the expression of Eq. 1.5 Theoretical and sample autocorrelations for B = 8. R). y. The maximum correlation length is in this case kmax = 2B−1 − 1 = 27 − 1 = 127. w. u.g.3. we find Ryy (k)= 1 B−1 2 1 − |k|2−b σu B2 b=b(k) and using the finite geometric series formula (e. n++) y[n] = ran1f(B. &iseed).25 0 1 2 3 4 5 6 7 8 9 10 B=4 kmax=2B-1-1 } With the choices A = 30 dB. where the linear segments have geometrically increasing slopes. P14. n<N.00 0.3. (B.30) are shown in Fig.9969] Fig.8850. The cascade realization is shown in Fig.4756. a = [−0. 0..9790. 0. P14. ωmax = 0.3π.0575.3π.9 Solving the equation (0.6π. c = 6.9969] For ωmax = 0.99574z−1 )(1 − 0.30) becomes: H(z)= G (1 − 0. a = [0. P14.1π. ωmax = 0.9.5309.98444 u1 Problem B. the number of lags is 150/2000 ≡ 7.9969] The spectra are shown in Figs.8541.29) without the factor G can be computed analytically or much faster using MATLAB to compute a fairly long portion of the impulse response h (e. The corresponding sample processing algorithm will be: 292 293 . For ωmax = 0.94791. Thus. 0. P14.9887.94791 v1 x2 = v0 − 0. 0.08522z−1 ) (1 − 0.5944.51153z−1 ) u1 = u 0 v0 = x1 + 0.29) and (B.53568 w1 y = w0 − 0. 0.57534 x + 0.6π. ωmax = 0.1.1π.6 Model spectrum and periodogram estimate. for each white noise input sample x do: u0 = 0.99574)c = 0.The reason for using N = 2000 was because we wanted to evaluate the sample autocorrelation at M = 150 lags.83392 v1 v1 = v 0 w0 = x2 + 0. the filter of Eq.8.6π.9686.07568 w1 w1 = w0 The NRR = hT h of the filter (B.6943. The magnitude response squared of Eqs.g.99574 u1 x1 = u0 − 0. Then.7 Model spectrum and periodogram estimate.6858. 0. of length √ 2000) and then setting G = 1/ NRR = 1/ hT h. 0.9594.8 Model spectrum and periodogram estimate.82159z−1 )(1 − 0. 0.1π. which falls within the recommended range for getting statistically reliable lags using the routine corr.8592.98444z−1 )(1 − 0. Problem B.6—P14. we have B = 6 and c = 3. 0.3π. 0.5% of the block length.001π and ωmax = 0. Fig. 0. we have B = 4 and a = [0. 0.94791z−1 )(1 − 0. we find c = 12. as was mentioned in Section A. we have B = 3 and c = 10. The designed model parameters are: For ωmax = 0. P14.10. (B. P14.8 We look at the cases ωmin = 0. Fig. P14. 9 1/f noise filters for Problem B.99574 -0.Fig.9.94791 -0.10 Cascade realization of 1/f noise filter.07568 Fig.98444 x2 v0 z-1 v1 0. 294 .83392 y w0 z-1 w1 0.53568 -0. P14.57534 x1 u0 z-1 u1 0. P14. x 0.
Copyright © 2024 DOKUMEN.SITE Inc.