Professional Documents
Culture Documents
Signal Processing: Introduction To
Signal Processing: Introduction To
Problem 1.1
The Nyquist interval is [fs /2, fs /2]= [4, 4] Hz. The 6 Hz frequency of the wheel lies outside
it, therefore, it will be aliased with f fs = 6 8 = 2 Hz. Thus, the wheel will appear to be
turning at 2 Hz in the opposite direction.
INTRODUCTION TO
Signal Processing
If fs = 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 f1 = 1, f2 = 4, and f3 = 6 Hz. Of
these, f2 and f3 lie outside the Nyquist interval [2.5, 2.5]. Therefore, they will be aliased with
f2 fs = 4 5 = 1 and f3 fs = 6 5 = 1 and the aliased signal will be:
Solutions Manual
Sophocles J. Orfanidis
Department of Electrical & Computer Engineering
Rutgers University, Piscataway, NJ 08855
orfanidi@ece.rutgers.edu
= 5 sin(2n/5)= xa (nT).
If fs = 10 Hz, then the Nyquist interval is [5, 5] Hz and only f3 lies outside it. It will be aliased
with f3 fs = 6 10 = 4 resulting in the aliased signal:
Problem 1.3
Using the trig identity 2 sin sin = cos( ) cos( + ), we nd:
The frequencies in the signal are f1 = 0.5 and f2 = 2.5 kHz. The Nyquist interval is [1.5, 1.5]
kHz, and f2 lies outside it. Thus, it will be aliased with f2a = 2.5 3 = 0.5 giving rise to the
signal:
Problem 1.4
= 2 cos(2t)+2 cos(6t)
Using a trig identity, we write x(t)= cos(8t)+ cos(10t)+ cos(2t). 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.
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 nd:
{ 1, 3, 3, 1, 1, 3, 3, 1 , . . . }
with frequency content: f1 = 3, f2 = 5, f3 = 1 kHz. The Nyquist interval is [2, 2] kHz, and the
aliased frequencies are:
Therefore only sin(2t) and sin(6t) terms will appear in the aliased signal. Thus, we write it
in the form:
f 1a = f 1 f s = 3 4 = 1,
f 2a = f 2 f s = 5 4 = 1,
f 3a = f 3 = 1
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
Thus,
Problem 1.6
Use the trigonometric identity 2 cos a cos b = cos(a + b)+ cos(a b) three times to get
To prove the equality of the samples, replace t = nT = n/10, because T = 1/fs = 1/10. Then,
= 0.5
The values for x(1/8) and x(2/8) were obtained by inspecting the triangular waveform. Solving
for B and C, we nd:
B=
2+2
,
4
C=
22
4
Problem 1.8
For fs = 5 kHz, we have:
xa (t)= sin(2f1 t)
BC=1
B + C
Analog Prefilter
H(f)
AB
48 dB/octave
Problem 1.9
inaudible
10
20 30
kHz
45
The frequencies of the four terms and their aliased versions are:
fA = 5
fAa = 5
fB = 10
fC = 30
fD = 45
Problem 1.10
fBa = 10
fCa = 30 40 = 10
fDa = 45 40 = 5
s(t)=
cm e2jmt/T ,
cm =
m=
a. When there is no prelter the aliased signal at the output of the reconstructor will be:
cm =
T/2
T/2
c. The attenuations introduced by the practical prelter shown in Fig. P1.2 are obtained by
determining the number of octaves to the frequencies fC , fD and multiplying by the lters
attenuation of 48 dB/octave:
log2
log2
fC
fs / 2
fD
fs / 2
= log2
= log2
30
20
45
20
S(f ) =
=
AC = 48 0.585 = 28.08 dB
= 1.170
AD = 48 1.170 = 56.16 dB
s(t)e2jmt/T dt
(t)e2jmt/T dt =
e2jf t dt = (f )
we nd:
= 0.585
T/2
T/2
But within the basic period [T/2, T/2], s(t) equals (t). Thus,
s(t)e2jf t dt =
m=
m=
s(t)e2j(f mfs )t dt
(f mfs )
Problem 1.11
Problem 1.12
Write x(t)= 0.5e2jf0 t + 0.5e2jf0 t , with Fourier transform:
)= lim
lim TX(f
T0
)=
X(f
=
m=
1
2T
X(f mfs )=
1
2T
m=
T0
T
1 e(a+2j(f f0 ))T
a + 2j(f f0 )
= X(f )
Fig. P1.3 shows the required spectra. From the left graph, we see that as fs 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
), which is only
). As L , the sampled spectrum X
L (f ) will tend to X(f
general shape of X(f
an approximation of the true spectrum even within the Nyquist interval.
m=
Problem 1.13
We have for the complex sinusoid, the Laplace, Fourier, and magnitude spectra:
X(s)=
X(f )=
a + 2j(f f0 )
t0
s + a 2jf0
|X(f )|2 =
L (f ) =
X
x(nT)e2jf nT =
L
1
Problem 1.14
(a+2j(f f0 ))LT
1e
1 e(a+2j(f f0 ))T
In the case of real-valued signals, we will also get the spectral peaks at the negative frequency
f0 . If f0 is small, the peaks at f0 will inuence each other somewhat, but apart from that the
e(a+2j(f f0 ))nT
n=0
n=0
Fig. P1.3 Spectra of analog, sampled, and windowed signals of Problem 1.13.
a2 + 42 (f f0 )2
This is the same as Example 1.5.4. In units of dB per decade, the attenuations due to the signal
and lter combine to give:
)=
X(f
x(nT)e2jf nT =
n=0
1
1 e(a+2j(f f0 ))T
A(f )= log10
+ log10
fmax
fmax
= log10
)| =
|X(f
fmax
log10
fs fmax
fmax
Problem 1.15
The rst replica of Xin (f ), shifted to fs , will have spectrum:
|Xin (f fs )| =
8
1 + 0.1(f fs )
Its value at the passband frequency fpass = fmax = 20 kHz will be:
|Xin (fmax fs )| =
8
1 + 0.1(fmax fs )
where = 140 dB/decade, of which 60 dB/decade is due to the lter and 80 dB/decade due to
the signal. The approximate method of Example 1.5.4 or Problem 1.14 would have given here
fs = fmax + 10A/ fmax = 20 + 20 1060/140 = 73.65 kHz, which is fairly close to the more accurate
value of 80 kHz.
2
X (f
in max fs )
=A
10 log10
Xin (fmax )
10 log10
8
1 + 0.1(fmax fs )
1 + (0.1fmax )8
= 60
which can be solved for fs to give fs = 132.52 kHz. Using the prelter, we require that its
passband attenuation be Apass = 1 dB at fpass = fmax = 20 kHz, that is,
1
1 + (f /f0 )6
f02N =
1 + ( 0 . 1f ) 8
2N
fmax
,
r1
10 log10
1 + (fmax fs )/f0
1 + (fmax /f0 )2N
8
2 N
1 + 0.1(fmax fs )
1 + (0.1fmax )8
=A
or,
A
0
fmax fs-fmax fs
1 + (fmax fs )/f0
1 + (fmax /f0 )2N
2 N
8
1 + 0.1(fmax fs )
1 + (0.1fmax )8
= 10A/10
(P1.3)
2
X(f
max fs )
= A,
10 log10
X(fmax )
= Apass
which can be solved for f0 to give f0 = 25.05 kHz. The preltered signal that gets sampled is now
Problem 1.16
1 + (fmax fs )/f0
1 + (fmax /f0 )6
6
1 + (fmax fs )/fmax
8
1 + 0.1(fmax fs )
1 + (0.1fmax )8
=A
ln
(P1.2)
which gives fs = 80.1 kHz. The exact solution of Eq. (P1.1) is fs = 80.0633 kHz. The rst factor
in Eq. (P1.2) represents the stopband attenuation due to the lter, and the second the attenuation
due to the signal. With fs = 80.1 kHz, we have
10 log10
10 log10
1 + (fmax fs )/f0
1 + (fmax /f0 )6
= A Astop = 38.2 dB
Thus, the use of the prelter 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
1
1
const. const.
const.
|X(f )|2 =
=
1 + (f /f0 )6 1 + (0.1f )8
f6
f8
f 14
1 + 0.1(fmax fs )
1 + (0.1fmax )8
10A/10 rR(fs )1
r1
2 ln
fs fmax
fmax
R(fs )=
(P1.4)
1 + (0.1fmax )8
8
1 + 0.1(fmax fs )
Eq. (P1.4) gives the minimum prelter order for a desired suppression level A and rate fs . With
fs = 70 kHz, A = 60 dB, Apass = 1 dB, we nd
and
N=
ln(3194.281)
= 4.403
2 ln(50/20)
= 10A/10
= Astop = 21.8 dB
8
N=
6
1 + 0.1(fmax fs )
1 + (0.1fmax )8
8
10 log10
(r 1)
(P1.1)
8
6
0.1(fmax fs )
(fmax fs )/f0
= 60 dB
6
8
1 + (fmax /f0 )
1 + (0.1fmax )
2 N
N=5
A/10
2Na = 10
|H(f )|2 =
then, the 3-dB frequency f0 is determined by requiring that at the edge of the passband the
attenuation be B dB:
|H(fmax )|2 =
Problem 1.17
Figure P1.4 shows a plot of N given by Eq. (P1.4) as a function of fs for different choices of A.
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. It is evident from this graph that the complexity of the prelter
increases with A, at any xed fs ; and that it decreases with fs , for xed A.
A
log10
60
= 200
=
30 10
f
log10
10
fmax
|Xin (f )|2
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.
1
1
(f /fa )2Na
|H(f )|2
(f /f0 )2N
2N
f 2N fmaxa
(fs fmax )2N (fs fmax )2Na
= 10A/10 max
2N
2Na
f02N fa2Na
f0
fa
which simplies into:
N = /20 = 120/20 = 6
2Na
Using the asymptotic forms of the spectra, valid for large f s, that is,
= 20N
2 N
= 10A/10
Using the results of Problem 1.14, we solve for the combined attenuation of signal and prelter:
A = log10
1
1
The antialiasing condition |X(fs fmax )|2 = 10A/10 |X(f )|2 gives now:
fs fmax
fmax
1
= 10B/10
1 + (fmax /f0 )2N
The ltered input that gets sampled will now have spectrum X(f )= H(f )Xin (f ), which gives:
Problem 1.18
1
1 + (f /f0 )2N
fs fmax
fmax
2(N+Na )
= 10A/10
or,
Problem 1.19
This problem is the generalization of Prob. 1.15. If we do not use a prelter, 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:
In this case, the Butterworth lter resembles more and more a brick-wall lter with cutoff fmax .
10
11
Problem 1.20
)=
Xa (f )= H(f )X(f
The linear relationship between N and A follows from the approximation of Problem 1.19:
fs fmax
fmax
2(N+Na )
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:
or,
2(N + Na )log10
x(nT) e2jf nT H(f )
= 10A/10
fs fmax
fmax
xa (t)=
x(nT)h(t nT)
A
10
Problem 1.24
Problem 1.21
Start with a complex sinusoid x(t)= e2jf0 t . Its sampled spectrum will be:
) will
The presence of P(f ) is called the aperture effect. The replicas of X(f ) embedded in X(f
still be present, but they will be weighted by P(f ). The need for using antialiasing prelters to
avoid overlapping of replicas remains the same. For a pulse of width , we have:
sin(f )
|P(f )| =
f
)=
X(f
|P(f)|
-fs
m=
m=
(f f0 mfs )
m=
m=
xrec (t)=
m=
5fs
fs
X(f mfs )=
f
-5fs
)=
Xrec (f )= H(f )X(f
Therefore, the narrower the width the atter the spectrum P(f ). If T, then P(f ) will be
essentially flat within the Nyquist interval, thus, leaving the central replica almost unchanged.
) for the case = T/5.
Fig. P1.5 shows P(f ) relative to the replicas of X(f
H(fm )= Am ejm ,
so that Am =
|H(fm )|,
m = arg H(fm )
we have:
xrec (t)=
m=
Problem 1.22
xrec (t)=
The stopband frequency of the postlter is: fstop = fs fc = 6 1 = 5 kHz. At this frequency,
the attenuation of the staircase DAC is
ADAC
sin(f
stop /fs )
= 14.4 dB
= 20 log10
fstop /fs
Am sin 2(f0 + mfs )t + m
m=
H(fm )=
sin(fm T)
fm T
ejfm T
H(fm )=
sin(f0 T)
fm T
ejf0 T
Thus,
Problem 1.23
Am =
xa (t) =
=
(t
) dt
=
h(t t
)x
x(nT)
h(t t
)(t
nT) dt
fm T
m sin 2(f0 + mfs )t = sin(2f0 t)
m=
12
m = f0 T
For the ideal reconstructor, we have m = 0 and Am = 0 except at m = 0 where A0 = 1, that is,
Am = m . Thus,
xrec (t)=
x(nT)h(t nT)
sin(f0 T)
13
Chapter 2 Problems
Problem 1.25
Take the linear combination of the results of the single sinusoid case of Eq. (1.6.12).
Problem 2.1
The quantized values are:
analog value
2.9
3.1
3.7
4
-2.9
-3.1
-3.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, complement the rst bit in this table.
Problem 2.2
Filling the table, we have
x(n)
xQ (n)
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
0.000
1.243
2.409
3.423
4.222
4.755
4.990
4.911
4.524
3.853
2.939
1.841
0.627
-0.627
-1.841
-2.939
-3.853
-4.524
-4.911
-4.990
0.000
1.000
2.000
3.000
4.000
5.000
5.000
5.000
5.000
4.000
3.000
2.000
1.000
-1.000
-2.000
-3.000
-4.000
-5.000
-5.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
2s complement
0000
0001
0010
0011
0100
0101
0101
0101
0101
0100
0011
0010
0001
1111
1110
1101
1100
1011
1011
1011
Problem 2.3
With R = 10 volts and erms 103 volts, we have using Q =
2B =
12erms :
10
R
R
=
Q
12erms
12 103
which gives
14
15
B log2
Problem 2.6
10
12 103
= 11.495
The mean is
0
me =
erms =
2B 12
10
212 12
= 0.705 mvolt.
0
Q
e de =
e2 = E[(e me )2 ]=
ep(e) de =
(e me )2 p(e) de =
Q
2
e+
de =
Q2
12
Problem 2.7
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
L=
22B 2p
2p + 1
1
2p+
1
(P2.1)
L = 1523, 116, 40
Problem 2.8
Using Eq. (P2.1) with B = 7 bits and p = 1, 2, 3, we nd:
Problem 2.5
L = 38, 13, 8
Following similar steps as in the previous problem, we have for part (a):
NMAC TMAC T
TMAC
Problem 2.9
Replacing b1 = 1 b1 , we have:
xQ = R(b1 21 + b2 22 + + bB 2B 0.5)
= R (1 b1 )21 + b2 22 + + bB 2B 0.5
= R b1 21 + b2 22 + + bB 2B
1
T
=
NMAC
NMAC fs
TMAC =
1
= 0.595 103 msec = 595 nsec
35 48 kHz
This is plenty of time for todays DSP chips, which can perform a MAC operation within 3080
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 16NMAC . This gives:
TMAC =
1
595
=
= 37 nsec
16 35 48 kHz
16
16
Problem 2.10
As an example, consider the polynomial of degree M = 3: B(z)= b0 +b1 z+b2 z2 +b3 z3 . Iterating
the algorithm for i = 3, 2, 1, 0, we nd:
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)
17
Problem 2.11
natural binary
16
8.0
4.0
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
0
7.5
7.0
6.5
6.0
5.5
5.0
4.5
4.0
3.5
3.0
2.5
2.0
1.5
1.0
0.5
0.0
7
6
5
4
3
2
1
0
1
2
3
4
5
6
7
8
3.5
3.0
2.5
2.0
1.5
1.0
0.5
0.0
0.5
1.0
1.5
2.0
2.5
3.0
3.5
4.0
1
1
1
1
1
1
1
1
0
0
0
0
0
0
0
0
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:
bM = qM1
qM1 = bM
b1 = q0 aq1
q0 = aq1 + b1
b0 = R aq0
R = aq0 + b0
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)
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
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
Problem 2.14
The quantization width is Q = R/2B = 8/24 = 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 2s complement case is obtained by complementing the MSB of the
offset case.
test
b1
b2
b3
b4
Problem 2.13
For a polynomial of degree M = 3, B(z)= b1 z + b2 z2 + b3 z3 , we iterate the algorithm for i = 3,
2, 1:
1
1
1
1
0
0
0
0
1
1
1
1
0
0
0
0
2s C
xQ = Qm
int i;
double p = 0;
offset binary
double pol(M, b, a)
int M;
double *b, a;
xQ = Qm
b 1 b2 b3 b 4
b 1 b2 b3 b4
xQ
0
0
0
1
4.0
2.0
1.0
1.5
0010
1.0
1
0
0
0
0
1
0
0
0
0
1
1
C = u(y xQ )
test
0
0
1
0
b1
b2
b3
b4
b 1 b2 b 3 b4
xQ
0
0
0
1
0. 0
2. 0
1. 0
1. 5
1010
1. 0
1
1
1
1
0
1
0
0
0
0
1
1
C = u(y xQ )
1
0
1
0
The natural binary and 2C 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
b1
b2
b3
b4
b 1 b2 b3 b4
xQ
0
0
0
1
4.0
6.0
5.0
5.5
1010
5.0
1
1
1
1
0
1
0
0
0
0
1
1
C = u(y xQ )
test
1
0
1
0
b1
b2
b3
b4
b 1 b2 b 3 b4
xQ
0
0
0
1
0. 0
2. 0
3. 0
3. 5
1111
3. 5
1
1
1
1
0
1
1
1
0
0
1
1
C = u(y xQ )
1
1
1
1
For the 2C case, the quantizer saturates to its maximum positive value. Finally, for x = 3.2, we
have y = 2.95, and the following testing tables:
18
19
double ran();
test
b1
b2
b3
b4
b1 b2 b3 b4
xQ
0
0
0
1
4.0
2.0
1.0
0.5
0000
0.0
1
0
0
0
0
1
0
0
0
0
1
0
C = u(y xQ )
test
0
0
0
0
b1
b2
b3
b4
xQ
C = u(y xQ )
0
0
0
1
0 .0
2.0
3.0
2.5
0
0
1
0
0010
3.0
b1 b2 b3 b4
1
0
0
0
0
1
0
0
0
0
1
1
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);
In this case, the natural binary scale saturates to its minimum positive value.
Problem 2.15
printf("enter N, R = ");
scanf("%d %lf", &N, &R);
printf("enter L, iseed, M = ");
scanf("%d %ld %d", &L, &iseed, &M);
Problem 2.16
These versions are straight forward. To implement truncation instead of rounding, replace the
statement within adc:
y = x + Q/2;
fpe
fpx
= fopen("e",
= fopen("x",
"w");
"w");
fpRee = fopen("Ree",
fpRex = fopen("Rex",
fpRxx = fopen("Rxx",
"w");
"w");
"w");
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>
20
21
Problem 2.19
Rxx (k)=
1 2
A cos(2f0 k)+v2 (k)
2
At lag k = 0, we have:
E[v]= 0.5R(E[u]0.5)= 0
Rxx (0)=
R2
1
=
12
48
xx (k)=
Problem 2.20
Inserting x(n)= A cos(2f0 n + )+v(n) into the denition of the autocorrelation function, we
nd:
2
E[cos(a + )]=
1
cos(a + )p() d =
2
2
0
cos(a + ) d = 0
v2
A 2 /2
Rxx (k)
= 2
(k)
2 cos(2f0 k)+ 2
Rxx (0)
A /2 + v
A /2 + v2
a=
A 2 /2
A2 /2 + v2
=
=
1
2
Dening 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
v2
a=
SNR
SNR + 1
1a=
The quantization width of the rst ADC will be Q1 = R1 /2B1 . The residual signal formed at the
output of the rst DAC, x2 = x x1 , is the quantization error, and therefore, it varies of the limits
Q1
2
x2
Q1
2
These limits must serve as the full scale range of the second ADC. Thus, we must choose:
2
cos(a + )cos(b + ) d
1
cos(a b)
2
R2 = Q 1 =
R1
2B1
Q2 =
1
1
E[cos 2f0 (n + k)+ cos(2f0 n + )]= cos(2f0 (n + k)2f0 n)= cos(2f0 k)
2
R2
2B2
R1
2B1 +B2
Thus, we nd
22
SNR + 1
Problem 2.21
v2
A2 /2 + v2
2
0
1a=
we nally have:
E[cos(a + )cos(b + )] =
1 2
A + v2
2
23
R2 = R1 / (1 << B1);
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 x1 (n)= 2x(n) will be y1 (n)= 3x1 (n)+5 = 6x(n)+5 = 2(3x(n)+5).
The system is, however, time-invariant since it has constant-in-time coefcients.
(b) The quadratic term x2 (n 1) breaks linearity because it quadruples whenever the input
doubles. The term x(2n) will break time-invariance. Indeed, let xD (n)= x(n D) be
a delayed input. The corresponding output yD (n) can be computed from the given I/O
equation:
When there is a third B3 -bit stage, the total number of bits will be
B = B1 + B 2 + B 3
but, this is not the same as the delayed (shifted) y(n) obtained by replacing n by n D:
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, which is then
quantized to B3 bits with a full scale range and quantization width:
R3 = Q2 =
R2
2B2
Q3 =
R3
2B3
R1
2B1 +B2 +B3
R2 = R1 / (1 << B1);
R3 = R2 / (1 << B2);
Problem 3.2
(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:
Problem 2.22
The quantized triangularly-dithered signals were generated by the for-loop given in Example 2.5.1.
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
24
25
for n 1
h = [1, a, a2 , a3 , . . . ]
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(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,
etc.
It follows that:
h = [1, 0, a, 0, a2 , 0, a3 , 0, a4 , 0, . . . ]
Subtracting, we have:
(e) The impulse response satises:
or,
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 ,
Problem 3.6
We may write the given impulse response in the form:
etc.
h(n)=
if n = 0
3(0.5)n1
if n 1
Problem 3.4
yn = 5xn + 6 xn1 + 0.8xn2 + 0.82 xn3 +
0.8yn1 = 4xn1 + 6 0.8xn2 + 0.82 xn3 +
which gives
We have seen that if h(n)= an u(n), then the I/O difference equation is
26
27
Problem 3.7
It is evident from the denition that for n 2, h(n) satises the recursions h(n)= ah(n 1).
Instead of manipulating the I/O convolutional equation into a difference equation as we did above,
let us determine directly the difference equation satised 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:
y(n)=
h(k)x(n k)
y(n 1)=
h(k)x(n 1 k)
where the shifted unit-step u(n 1) vanishes for n = 0 and equals one for all n 1. Because
h(n) satises h(n)= ah(n 1) for n 2, we are led to consider the delayed function h(n 1)
and multiply it by a:
n2
u(n 2)
Problem 3.8
and
n1
u(n 2)
Subtracting, we have
n1
u(n 1)u(n 2)
where D is the delay operator dened by (Df )n = fn1 . It follows that the rst term p1n u(n) of
hn will be annihilated by (1 p1 D), the second term of hn will be annihilated by (1 p2 D), etc.
Therefore, all the terms in hn will be annihilated by the product
But the difference u(n 1)u(n 2)= (n 1) as follows from the standard result u(n)u(n
1)= (n), which was essentially derived in Example 3.4.4. Therefore, we have
(1 p1 D)(1 p2 D) (1 pM D)= 1 + a1 D + a2 D2 + + aM DM
Problem 3.9
But note that an1 (n 1)= (n 1) because it is nonzero only at n = 1 for which we have
a11 (0)= a0 (0)= (0). Then,
The Ci pn
i terms are annihilated by the same product as in the previous problem. However, the
(n) term will contain the delayed terms:
aM (n M)+aM1 (n M + 1)+
y(n) =
But, if n M + 1, then these terms vanish too. Thus, the difference equation satised by hn will
be:
hn + a1 hn1 + + aM hnM = 0,
Problem 3.10
Dene the polynomial with roots p1 , p2 :
h(m)x(n m)
1 + a1 z1 + a2 z2 = (1 p1 z1 )(1 p2 z1 )
ah(m 1)+b0 (m)+b1 (m 1) x(n m)
=a
nM+1
b0 (m)+b1 (m 1) x(n m)
so that
a1 = (p1 + p2 ),
In the second sum, the presence of (m) extracts only the m = 0 term, that is, b0 x(n), whereas
the presence of (m 1) extracts only the m = 1 term, that is, b1 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
Then, the
pni
a 2 = p 1 p2
29
for n 2. The coefcients b0 , b1 may be found by explicitly calculating the right-hand side of
this difference equation using the expression for hn , for n = 0, 1:
Problem 3.12
Dene the polynomial with roots p1 , p2 , p3 :
b0 = h0 + a1 h1 + a2 h2 = h0 = C1 + C2
1 + a1 z1 + a2 z2 + a3 z3 = (1 p1 z1 )(1 p2 z1 )(1 p3 z1 )
b1 = h1 + a1 h0 + a2 h1 = h1 + a1 h0 = C1 p1 + C2 p2 + a1 (C1 + C2 )
so that
a1 = (p1 + p2 + p3 ),
b0 = C 1 + C 2
Then, the
a 2 = p 1 p2 + p 2 p3 + p 3 p 1 ,
a3 = p1 p2 p3
pni
(P3.1)
for n 3, or,
Inserting this into the convolutional equation, we obtain the I/O difference equation:
n3
The coefcients b0 , b1 , b2 may be found by explicitly calculating the right-hand side of this difference equation using the expression for hn , for n = 0, 1, 2:
b0 = h 0
b1 = h 1 + a 1 h 0
b2 = h 2 + a 1 h 1 + a 2 h0
H(z)=
b0 + b1 z1
1 + a1 z1 + a2 z2
or,
b0 = C1 + C2 + C3
b1 = C1 p1 + C2 p2 + C3 p3 + a1 (C1 + C2 + C3 )
b2 = C1 p21 + C2 p22 + C3 p23 + a1 (C1 p1 + C2 p2 + C3 p3 )+a2 (C1 + C2 + C3 )
Problem 3.11
Now the difference equation Eq. (P3.1) will be satised for n 3. To determine the coefcients
b0 , b1 , b2 , we evaluate the right hand side for n = 0, 1, 2:
b0 = h 0
b0 = C1 + C2 + C3
b1 = C1 (p2 + p3 )+C2 (p3 + p1 )+C3 (p1 + p2 )
b1 = h 1 + a 1 h0
b2 = C1 p2 p3 + C2 p3 p1 + C3 p1 p2
b2 = h 2 + a 1 h1 + a 2 h 0
which give:
Problem 3.13
For (a), 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 p21 + C2 p22 + a1 (C1 p1 + C2 p2 )+a2 (C0 + C1 + C2 )= C0 p1 p2
In b2 , the coefcient of C1 is p21 + a1 p1 + a2 , which is zero because p1 is a root of the polynomial
z2 + a1 z + a2 . Similarly, the coefcient of C2 is zero.
Again, the results can be justied quickly using z-transforms:
C1
C2
+
H(z) = C0 +
1 p1 z1
1 p2 z1
(C0 + C1 + C2 ) C1 p2 + C2 p1 + C0 (p1 + p2 ) z1 + C0 p1 p2 z2
=
(1 p1 z1 )(1 p2 z1 )
30
hn 1.3hn1 + 0.4hn2 = 0
For (b), we have with n 2:
hn + 0.25hn2 = 0
For (c), we have with n 3:
31
Problem 3.14
Problem 3.18
Because h(n)
agrees with h(n) for n D, we have:
|y(n)| = |
h(m)x(n m)|
|h(m)||x(n m)|
|h(m)|B = AB
Problem 3.15
y(n) =
h(m)x(n m)
m=
(n) =
y
h(m)x(n
m)=
m=D
Starting with
y(n)=
h(m)x(n m)
(n)=
y(n)y
we obtain at n = 0:
D
1
h(m)x(m)
y(0)=
h(m)x(m)=
h(m)sign h(m)
(n)| = |
|y(n)y
D
1
h(m)x(n m)|
m=
D
1
y(0)=
m=
|h(m)|
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.
lim
D
1
|h(m)| 0
m=
Problem 3.16
Working with the convolutional I/O equation, we have:
hD (m)x(n m)=
h(m D)x(n m)
y(n)=
h(k)x(n k)
y(n D)=
h(k)x(n D k)
Problem 3.17
We have:
hD (m)xA (n m)=
h(k)x(n k)
32
|h(m)| <
m=
yD (n) =
|h(m)||x(n m)|
h(m)x(n m)
m=
y(0)=
h(m)x(n m)
m=D
33
D
1
m=
|h(m)|A
Chapter 4 Problems
The three subblocks begin at the absolute times n = 0, 3, 6, respectively. It follows from timeinvariance 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 nal
result:
Problem 4.1
The convolution table is:
h\x
1
1
2
1
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
y0
y1
y2
y
n
x\ h
1
2
1
1
2
1
1
1
y(n)
0
1
1
1
1
1
2
2
2
2
2
1
3
1
1
4
1
1
2
2
1
2
1
2
2
1
1
4
1
1
2
2
1
1
1
2
1
1
2
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)
x(m)h(n m)
34
1
1
1
1
2
1
1
1
1
2
1
block
1
1
1
2
1
10
6
1
7
4
2
6
1
3
4
3
3
1
1
x1
x0
y1 = h x1 = [1, 2, 4, 4, 3, 1]
Aligning them at multiples of n = 5, we have:
0
1
1
3
2
5
3
7
4
7
5
5
1
6
6
5
2
7
7
2
4
6
10
4
4
3
3
1
1
-1
-2
2
1
-1
0
0
0
0
0
1
2
-2
-1
1
2
4
-4
-2
2
Problem 4.2
The convolution table is:
h\x
2
-2
-1
1
These convolutions can be done by separately folding the three convolution subtables:
block
2
2
2
4
2
y0 = h x0 = [1, 3, 5, 7, 7, 5, 5, 2]
y2 = h x2 = [1, 2, 3, 3, 1, 0]
1
1
1
2
1
y1 = h x1 = [1, 3, 5, 6, 4, 1]
1
1
1
2
1
x2
y0 = h x0 = [1, 3, 5, 6, 4, 1]
5
1
5
x = [ 1, 2, 1, 1, 2, 1, 1, 1 ]
y0
y1
y
where we padded an extra zero at the end to get a length-3 block. Convolving each block separately
with h gives:
block
2
2
2
4
2
4
4
3
If the input is divided into length-5 subblocks, the last subblock will have length 3:
1
1
1
2
1
3
6
1
log2 N
fast
=
slow
M
x = [ 1, 2, 1, 1, 2, 1, 1, 1, 0 ]
h\ x
1
1
2
1
2
5
In practice this method is implemented efciently by computing the individual block convolutions
using the FFT instead of time-domain convolution. For an FIR lter 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 N1 = N M.
The computational gain of this fast convolution method versus the conventional time-domain
slow method is approximately
For the overlap-add method, the input is divided into the following three contiguous blocks:
x1
1
3
10
x0
0
1
2
4
-4
-2
2
2
4
-4
-2
2
0
0
0
0
0
1
2
-2
-1
1
y = [ 4, 0 , 6 , 2 , 2 , 1 , 4 , 1 , 5, 1 , 2]
The rst 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
x\h
2
2
0
1
-1
0
1
2
y(n)
0
2
4
1
-2
-4
4
2
-1
-2
-4
0
3
1
2
-2
0
2
-6
2
0
-2
-2
-2
0
-1
2
0
1
1
0
2
10
-1
0
-2
4
0
-1
-4
1
-2
-5
-1
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)
y0
y1
y
1
0
2
-6
3
2
4
-2
-6
-2
5
1
0
1
6
2
2
4
h(n)
10
-5
-5
-1
-1
2
2
x(n)
10
13
16
x1
x = [ 2, 2, 0, 1, 1, 0, 1, 2, 0 ]
x0
Figure P4.1 shows the lter, input, and computed output signals.
For the overlap-add method, the input is divided into the following three contiguous blocks:
7
-1
2
1
Problem 4.3
x(m)h(n m)
0
4
20
23
26
23
26
y(n)
x2
where we padded an extra zero at the end to get a length-3 block. Convolving each block separately
with h gives:
4
3
2
1
y0 = h x0 = [4, 0, 6, 0, 2]
y1 = h x1 = [2, 4, 1, 2, 1, 0]
y2 = h x2 = [2, 2, 5, 1, 2]
10
13
16
on
20
steady
off
These convolutions can be done by separately folding the three convolution subtables:
Fig. P4.1 h(n), x(n), and y(n) signals of Problem 4.3.
block 0
2
2
0
4
4
0
-4
-4
0
-2
-2
0
2
2
0
h\ x
2
-2
-1
1
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, the indices of hm and xnm are restricted to lie within their respective ranges:
3m6
(P4.1)
10 n m 20
Solving the second with respect to n, we have:
n
y0
y1
y2
y
0
4
1
0
2
-6
-6
3
0
2
4
2
-4
5
1
1
-2
2
2
4
-1
2
1
0
-5
-5
2
2
If the input is divided into length-5 subblocks, the last subblock will have length 3:
x = [ 2, 2, 0, 1, 1, 0, 1, 2 ]
x0
10 + m n 20 + m
10
x1
10 + 3 10 + m n 20 + m 20 + 6
36
13 n 26
This is the range of index n of the output yn . To nd 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
n 20 m n 10
37
min(6
,n10)
yn =
hm xnm ,
for
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:
13 n 15
yn =
n
10
for
13 n 26
16 n 23
yn =
yn =
min(20
,n3)
(P4.3)
m=max(10,n6)
hm xnm
m=3
steady-state:
xm hnm ,
m=max(10,n6)
m=max(3,n20)
input-on:
min(20
,n3)
yn =
13 n 26
Problem 4.4
hm xnm
Because both the input and lter are causal and have innite duration, we use the formula:
m=3
24 n 26
input-off:
yn =
y(n)=
hm xnm
h(m)x(n m)=
m=0
am u(m)u(n m)
or,
m=0
m=n20
In particular, if the lter and input signals are unity over the ranges (P4.1), the output can be
expressed compactly as:
y(n)=
am =
m=0
yn =
min(6
,n10)
(P4.2)
The steady-state response is the large-n limit of this formula; that is,
m=max(3,n20)
y(n)
13 n 15
yn = n 10 3 + 1 = n 12
steady-state:
16 n 23
yn = 6 3 + 1 = 4
input-off:
24 n 26
yn = 6 (n 20)+1 = 27 n
1 an+1
1a
1
1a
for n
y(n)=
am (1)nm = (1)n
m=0
(a)m = (1)n
m=0
1 (a)n+1
1+a
Problem 4.5
y = { 1, 2 , 3, 4 , 4 , 4 , 4 , 4 , 4 , 4 , 4 , 3 , 2 , 1 }
The rst 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:
yDC =
Consider the IIR lter h(n)= an 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 closedform expression for the output signal y(n) for the two time ranges: 0 n L 1 and n L.
Because the lter is innite (M = ), Eq. (4.1.16) becomes:
y(n)=
hm = 1 + 1 + 1 + 1 = 4
10 m 20
h(m)x(n m),
m=max(0,nL+1)
Note also that because the lter 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 lter until 3 instants later, that is, at n = 23. For the LTI form, Eq. (P4.1)
is replaced by
y(n)=
Using the geometric series identity
M2
3nm6
m=M1
This leads to the same range for the output index n, but to the summation limits:
am =
aM1 aM2 +1
1a
we nd:
38
am 1
m=max(0,nL+1)
39
0n<
Problem 4.8
y(n)=
amax(0,nL+1) an+1
1a
The following C program computes the output signals of the two lters (a) and (b) of Example
4.1.8:
n+1
y(n)=
y(n)=
anL+1 an+1
1 aL
= anL+1
= anL+1 y(L 1),
1a
1a
(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 a0+1
a 0 = 1 = x(0)
1a
#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));
yb = (double *) calloc(L+Mb, sizeof(double));
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):
dene input
compute outputs
void convlti(M, h, L, x, y)
double *h, *x, *y;
int M, L;
{
int n, m;
printf("\n\n");
for (n=0; n<L+Mb; n++)
printf("%lf\n", yb[n]);
Ex. 4.1.8.(b)
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
40
41
void blockcon();
lter le
M = lter order, L = blocksize
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, "cant open filter file: %s\n", argv[1]);
exit(0);
}
L = atoi(argv[2]);
block length
M is lter 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)); nal 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 ltering:
for (;;) {
for (N=0; N<L; N++)
if (scanf("%lf", x+N) == EOF) goto last;
blockcon(M, h, L, x, y, ytemp);
process block
last:
blockcon(M, h, N, x, y, ytemp);
42
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 rst group of L outputs. Then, the next group of L input
samples is entered and the program outputs the corresponding group of L outputs, and so on. At
the end, one must enter a <CTRL-Z> (for MSDOS) in order for the program to process the input-off
transients.
Problem 4.10
A complete such program is included below.
read h
for (M=0;; M++) {
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--;
The dimension of the lter array h is determined on the y by reading the le of lter coefcients. Because the length of this le is not known in advance, the program keeps reallocating
the length of h in increments of MAX coefcients until the nal length is determined and the nal
reallocation is made. The ltering portion of the program is identical to the program segment
discussed at the end of Section 4.1.10.
double fir();
void main(int argc, char **argv)
{
FILE *fph;
double *h, *w, x, y;
int M, i;
int max = MAX, dmax = MAX;
lter le
lter, states, input, output samples
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, "cant open filter file: %s\n", argv[1]);
exit(0);
}
h = (double *) calloc(max + 1, sizeof(double));
preliminary allocation
43
}
M--;
M is lter order
nal allocation
start ltering:
input-off transients
preliminary allocation
M--;
M is lter order
As in the case of blkfilt.c, the dimension of the lter array h is determined on the y by reading
the le of lter coefcients. The program keeps reallocating the length of h in increments of MAX
coefcients until the nal length is determined and the nal reallocation is made. The ltering
portion of the program is identical to the program segment discussed in Section 4.2.3.
start ltering:
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.
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>
It is identical to firfilt.c, except it uses the circular version cfir instead of fir to do the ltering. In addition, the circular pointer p is dened 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.
#define MAX 64
lter le
#define MAX 64
double cfir2();
if (argc != 2) {
fprintf(stderr, "usage: cfirfilt hfile <xfile >yfile\n");
exit(0);
}
44
lter le
lter, states, circular pointer
input and output samples
circular pointer index
allocation for h and increment
45
if (argc != 3) {
fprintf(stderr, "usage: cdelfilt i D <xfile >yfile\n");
exit(0);
}
if (argc != 2) {
fprintf(stderr, "usage: cfirfil2 hfile <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);
}
preliminary allocation
M is lter order
input-off transients
initialize p
input-off transients
zero input
Problem 4.13
Consider a 3d order lter 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
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 lters output is
computed by the dot product:
double cdelay();
double tap();
46
double firalt(M, h, w, x)
double *h, *w, x;
int M;
{
47
int i;
double y;
y=output sample
w[0] = x;
return y;
}
Note that the previous state vector is updated rst 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 rst call, just like the fir.c case.
w0
w1
w2
w3
y = w0 + w1 + 2w2 + w3
0
1
2
3
4
5
6
7
8
9
10
1
2
1
1
2
1
1
1
0
0
0
1
2
1
1
2
1
1
1
0
0
0
0
1
2
1
1
2
1
1
1
0
0
0
0
1
2
1
1
2
1
1
1
0
0
0
0
1
2
1
1
2
1
1
1
1
3
5
7
7
6
7
6
4
3
1
The rst three outputs correspond to the input-on transients (the internal delay registers are
still lling up). The period 3 n 7 corresponds to steady state (all delays are lled). The
last three outputs, in general the last M outputs for an M-th order FIR lter, 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:
Problem 4.14
#include <stdio.h>
#include <malloc.h>
w0 (n) = x(n)
double filter2();
w0 (n)= x(n)
and
declares calloc()
void main()
{
int n;
double y, *w;
w3 (n + 1) = w2 (n)
w2 (n + 1) = w1 (n)
input-off transients
w1 (n + 1) = w0 (n)
This leads to the following sample processing algorithm and block diagram:
w0
y
for each input sample x do:
z-1
w0 = x
y = w0 + w1 + 2w2 + w3
w3 = w 2
w2 = w 1
w1 = w 0
w1
-1
z
w2
w3
z-1
48
}
double filter2(x, w)
double x, *w;
{
double y;
w[0] = x;
w[3] = w[2];
w[2] = w[1];
w[1] = w[0];
49
Then, the difference equation y(n)= 0.8y(n 1)+x(n) and the state updating equation will
read:
return y;
}
Problem 4.15
We dene the state-variables wi (n), i = 0, 1, 2, 3 as follows:
w0 (n) = x(n)
Then, the I/O equation y(n)= x(n)x(n 3) together with the state-updating equations will
read:
w3 (n + 1) = w2 (n)
and
w2 (n + 1) = w1 (n)
w1 (n + 1) = w0 (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:
w0
z
w0 = x
y = w0 w3
w3 = w2
w2 = w1
w1 = w0
w1
-1
w2
w3
w1
y = 0 . 8w 1 + x
0
1
2
3
4
1
1
2
2
4
0.0000
1.0000
1.8000
3.4400
4.7520
1.0000
1.8000
3.4400
4.7520
7.8016
Problem 4.17
We dene the internal states:
w1 (n) = y(n 1)
z-1
w1
w2
w3
y = w0 w 3
0
1
2
3
4
1
1
2
2
4
1
1
2
2
4
0
1
1
2
2
0
0
1
1
2
0
0
0
1
1
1
1
2
1
3
Problem 4.16
We dene the internal state:
w1 (n)= y(n 1)
50
and
w1 (n + 1) = y(n)
This leads to the following sample processing algorithm and block diagram realization:
z-1
w1
The sample processing algorithm can be applied to the given input samples to generate the output
samples:
w0
w2 (n + 1) = w1 (n)
The difference equation y(n)= 0.25y(n 2)+x(n) and state updating equations become:
-1
w1 (n + 1) = y(n)
-1
w1 = y
0.8
z-1
w1
w0 (n)= x(n)
w2 = w1
w1 = y
z-1
w2
0.25
General versions of such routines will be considered in Chapter 7. The sample processing algorithm can be cranked on the given input samples to generate the output:
y = 0.25w2 + x
w1
w2
0
1
2
3
4
1
1
2
2
4
1
1
2.25
2.25
4.5625
0
1
1
2.25
2.25
0
0
1
1
2.25
51
Notice how the computed y becomes the next w1 and w1 shifts into w2 .
Problem 4.18
The impulse response is read off from the coefcients of the I/O equation:
w0
-1
w2
1
1
2
2
2
2
1
1
y(n)
0
1
1
1
0
0
1
2
-1
-1
0
2
3
2
2
-1
0
2
2
-2
0
2
4
-2
0
2
4
-2
0
1
w3
10
4
-2
0
1
4
-1
0
2
-1
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)
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, 2, 2, 1, 1, ]
x0
x1
y0 = h x0 = [1, 1, 1, 3, 0, 2, 4]
2
2
0
-2
4
2
2
0
-2
4
block 1
2
1
2
1
0
0
-2
-1
4
2
y0
y1
y
0
1
1
1
2
1
3
3
4
0
2
2
5
2
2
4
52
6
4
-1
3
z-1
2
s0 = p = x
s2 = tap(3, w, p, 2)
s3 = tap(3, w, p, 3)
y = s0 s2 + 2s3
cdelay(3, w, & p)
where tap-1 is not needed, but tap-2 and tap-3 are. Tap-0 s0 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.
As pin gets decremented circularly, so does pout . If pin points to w[qin ] and pout to w[qout ], then
pin = w + qin
1
1
0
-1
2
pout = w + qout
where
The two subblocks begin at the absolute times n = 0, 4, respectively. It follows from timeinvariance 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 nal
result:
-1
These convolutions can be done by separately folding the two convolution subtables:
1
1
0
-1
2
w0 = x
y = w0 w2 + 2w3
w3 = w2
w2 = w1
w1 = w0
Figure P4.2 shows the contents of the registers w = [w0 , w1 , w1 ] at successive time instants. Each
time the circular pointer p = pin points to the w-register that receives the current input, whereas
the pointer pout points to the w-register containing the current output, that is, y(n)= x(n 2).
Therefore, pout is shifted clockwise by 2 with respect to pin :
y1 = h x1 = [2, 2, 1, 3, 3, 1, 2]
h\x
1
0
-1
2
Problem 4.19
block 0
1
2
2
2
0
0
-1
-2
2
4
w1
h = [ 1, 0 , 1 , 2 ]
n
x\h
y
-1
10
3
3
3
3
1
1
2
2
Thus, the input and output circular indices take on the sequence of values:
qin = 0, 2, 1, 0, 2, 1, 0, 2, 1, 0, 2
qout = 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 implementations. In the linear case, w0 , w1 and w2 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[qin ], whereas the up-arrow indicates the corresponding output sample, that is, w[qout ]. In
the circular case, only one w-register changes value at each time instant.
53
n=0
w1 0
n=1
0
w0
pin
pout
pout
n=2
6
8
n=5
3
pout
5
pin
pout
n=9
0
pin
pout 2
z-1
pout
2
v3(n)
z-1
h3
pout
0
pin
linear
circular
w0
w1
w2
0
1
2
3
4
5
6
7
8
9
10
8
7
6
5
4
3
2
1
0
0
0
8
7
6
5
4
3
2
1
0
0
0
0
8
7
6
5
4
3
2
1
0
0
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
qout
0
2
1
0
2
1
0
2
1
0
2
2
1
0
2
1
0
2
1
0
2
1
0
0
8
7
6
5
4
3
2
1
0
Let v1 (n), v2 (n), and v3 (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 vi (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 lter 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.2.6). Indeed, down-shifting v1 (n + 1),
we have
y(n)= h0 x(n)+v1 (n)= h0 x(n)+ h1 x(n 1)+v2 (n 1)
Problem 4.20
The transposed form is obtained by the following rules:
1.
2.
4.
3.
h2
pin
1
pout
v2(n)
n=10
pin
z-1
h1
n=8
0
n=7
3
x(n)
v1 (n)
n=6
pout 5
h0
y(n)
pout
pin
pin
4
pin
n=4
6
pin
pout 8
pin
w2 0
n=3
6
Similarly, down-shifting v2 (n+ 1) twice, that is, v2 (n 1)= v3 (n 2)+h2 x(n 2), and v3 (n+ 1)
three times, that is, v3 (n 2)= h3 x(n 3), we get
For example, in Fig. 4.2.7, the output adder will be replaced by a node with the signals owing
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.
which is equivalent to Eq. (4.2.6). The I/O system leads then to the following sample by sample
processing algorithm:
54
55
v[M] = h[M] * x;
last state
return v[0];
y = v0 = v1 + h0 x
y = v1 + h 0 x
v1 = v 2 + h 1 x
v2 = v3 + h2 x
v3 = h3 x
For Example 4.2.1, Table P4.1 shows the contents of the vi registers at each time instant. The vi
are initialized to zero. The v1 and v2 entries in each row are obtained by forming v2 + h1 x and
v3 + h2 x of the previous row. The v3 column is the delayed (down-shifted) version of the h3 x
column. The nal result is the same as in Example 4.2.1.
h0 x
h1 x
h2 x
h3 x
v1
v2
v3
y = v1 + h0 x
1
1
2
1
2
2
1
1
10
double firtr();
void main(int argc, char **argv)
{
FILE *fph;
double *h, *v, x, y;
int M, i;
int max = MAX, dmax = MAX;
lter le
lter array, input, output samples
allocation for h and increment
if (argc != 2) {
fprintf(stderr, "usage: firfilt hfile <xfile >yfile\n");
exit(0);
}
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:
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). The following C
routine firtr.c is an implementation:
preliminary allocation
M is lter order
double firtr(M, h, v, x)
double *h, *v, x;
int M;
{
int i;
input-off transients
56
57
nal allocation
y = firtr(M, h, v, 0.0);
printf("%lf\n", y);
}
Chapter 5 Problems
Problem 5.1
n=
n=
x1 (n)zn + a2
x2 (n)zn
n=
XD (z) =
xD (n)zn =
n=
x(n D)zn =
n=
x(k)z(k+D) = zD
k=
x(k)zk = zD X(z)
k=
y(n)=
h(m)x(n m)=
m=
h(m)xm (n)
m=
Taking z-transforms of both sides and using the linearity and delay properties, we get:
Y(z)=
h(m)Xm (z)=
m=
h(m)zm X(z)=
m=
h(m)zm X(z)
m=
or,
Y(z)= H(z)X(z)
Problem 5.2
a. From the delay property of z-transforms, X(z)= z5 (z), where (z)= 1 is the ztransform of (n). Thus, X(z)= z5 . The ROC is the entire z-plane with the exception of
the point z = 0.
b. Similarly, X(z)= z5 (z)= z5 , but now the ROC must only exclude the point at innity
z = .
c. The unit-step has z-transform: U(z)= 1/(1 z1 ). Thus,
X(z)= z5 U(z)=
z5
1 z1
X(z) =
u(n + 5)zn =
n=
1 zn
n=
= z5 + z4 + z3 + z2 + z1 + 1 + z + z2 + z3 +
z5
= z5 U(z1 )
= z5 1 + z + z2 + z3 + =
1z
58
59
g(n) G(z)
X(z)=
1
1
2
2
=
+
=
1 0.8jz1
1 + 0.8jz1
(1 0.8jz1 )(1 + 0.8jz1 )
1 + 0.64z2
ROC is |z| > |0.8j| = 0.8. An alternative method is to list a few of the signal values and then use
the innite geometric series to sum them up, that is, with a = 0.8:
g(n) G(z1 )
we nd X(z)= z5 U(z1 ).
Problem 5.3
we obtain
1
a. Using the general result: a u(n) 1/(1 az ), ROC |z| > |a|, we obtain: X(z)=
1/(1 (0.5)z1 )= 1/(1 + 0.5z1 ), with ROC |z| > | 0.5| = 0.5.
n
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
1 z10
)U(z)=
1 z1
an w(n) W(z/a)=
1 (z/a)10
1 a10 z10
=
1
1 (z/a)
1 az1
x(n)= [1, a, a , a , a , a , a , a , a , a , 0, 0, 0, ]
4
X(z)= 1 + az1 + a2 z2 + + a9 z9 =
Problem 5.5
1
1
2 4.25z1
+
=
1 0.25z1
1 4z1
1 4.25z1 + z2
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 rst term requires |z| > 0.25
while the second |z| < 4. Combining, we nd 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 rst term in the z-transform expansion
1 a10 z10
1 az1
X(z)=
(0.25)n zn +
n=
1 + x + x + + x
c. X(z)=
0.5.
1 xm+1
,
=
1x
with x = az
and m = 9
1
1
2
2
=
+
=
, ROC |z| >
1 0.5z1
1 + 0.5z1
(1 0.5z1 )(1 + 0.5z1 )
1 0.25z2
4n zn
n=0
1
1x
with x = a2 z2 . Convergence of the geometric series requires that |x| < 1 or | a2 z2 | < 1 or
|z| > |a| or in our case |z| > 0.8.
X(z)=
2
1 + a2 z2
The three signals in parts (a,b,c) all have the same z-transform, namely,
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 zs 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, . . . ]
Problem 5.4
Using Euler, 2 cos = ej + ej , with = n/2 and also the fact that ej/2 = j and ej/2 = j,
we rewrite
2(0.8)n cos(n/2) = (0.8)n [ejn/2 + ejn/2 ]
60
X(z) = 1 z2 + z4 z6 + z8
= 1 + x + x2 + x3 + x4 + x=z2 =
=
1
1 + z2
61
1x
1
x=z2
Problem 5.8
|x| < 1
| z2 | < 1
|z| > 1
Method 2: Use Eulers formula to split x(n) as the sum of two terms of the form an u(n):
x(n)= cos(n/2)u(n)=
1
1 jn/2
+ ejn/2 u(n)= [jn + (j)n ]u(n)
e
2
2
X(z)=
1 jz1
1/2
1 + jz1
3(1 + 0.3z1 )
3(1 + 0.3z1 )
A
B
=
=
+
2
1 0.81z
(1 0.9z1 )(1 + 0.9z1 )
1 0.9z1
1 + 0.9z1
where
X(z)=
1
1 + z2
A=
3(1 + 0.3z1 )
1 + 0.9z1
= 2,
B=
z=0.9
3(1 + 0.3z1 )
1 0.9z1
=1
z=0.9
The rst ROC is |z| > |0.9| = | 0.9|, thus both terms will be inverted causally:
an u(n)
1 az1
for a = j and a = j.
Method 3: Recognize that x(n) is periodic with period 4. Dening 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,
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(z)= G(z)+z4 G(z)+z8 G(z)+ = 1 + z4 + z8 + z12 + G(z)
X(z) =
X(z)=
G(z)
1 z4
1 z2
1 z2
1
=
=
1 z4
(1 z2 )(1 + z2 )
1 + z2
=A+
A=
Whenever X(z) is a polynomial, the best method to invert is to just pick out the coefcients of
the polynomial. For (a), we have:
B
1 0.5z1
C
1 + 0.5z1
where B and C are determined in the usual manner and A is determined by evaluating
X(z) at z = 0:
Problem 5.7
6 3z1 2z2
6 3z1 2z2
=
2
1 0.25z
(1 0.5z1 )(1 + 0.5z1 )
B=
6 3z1 2z2
1 0.25z2
6 3z1 2z2
1 + 0.5z1
=
z=0
6z2 3z 2
z2 0.25
= 4,
z=0.5
C=
=
z=0
2
=8
0.25
6 3z1 2z2
1 0.5z1
=2
z=0.5
For the rst ROC, |z| > 0.5, the last two terms will be inverted causally:
62
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 ztransform, and nally restore the effect of the numerator. To show these steps, write
X(z) =
6 + z5
= (6 + z5 )
1 0.64z2
1
1 0.64z2
Again, the A-term is needed because the degrees of numerator and denominator polynomials are equal. We nd
A=
B=
x(n)= 6w(n)+w(n 5)
Thus, the problem is reduced to the problem of nding w(n). Doing a partial fraction
expansion on W(z), we nd
A
B
1
1
=
=
+
1 0.64z2
(1 0.8z1 )(1 + 0.8z1 )
1 0.8z1
1 + 0.8z1
where A = B = 0.5. For the ROC |z| > 0.8, the two terms are inverted causally:
=
z=0
10 + z2
1 + 0.5jz1
10z2 + 1
z2 + 0.25
=
z=0
1
=4
0.25
=3
z=0.5j
For the anticausal case, we obtain the anticausal version of the second term, namely,
Note that the last two terms are active only for n 5. For the ROC |z| < 0.8, we have the
anticausal/unstable answer:
X(z)=
X(z) =
We only needed to calculate B, and use B for the conjugate pole. For the causal case, we
have
W(z)=
10 + z2
10.25z2
10 + z2
10 + z2
=
1 + 0.25z2
(1 0.5jz1 )(1 + 0.5jz1 )
B
B
+
=A+
1 0.5jz1
1 + 0.5jz1
64
6 2z1 z2
4
1
1
+
+
=
1 + 0.5z1
(1 z1 )(1 0.25z2 )
1 z1
1 0.5z1
Because ROC is |z| > 1 > 0.5, all terms are inverted causally to give:
X(z) = 4 +
= 4 +
1
1
= 4 +
1 + 4z2
(1 2jz1 )(1 + 2jz1 )
1/2
1/ 2
+
1 2jz1
1 + 2jz1
|z| > 2
and
65
|z| < 2
Problem 5.9
1
1
0.5 (2j)n +(2j)n ] = 2n [jn + (j)n ]= 2n [ejn/2 + ejn/2 ]
2
2
xa (n)= an u(n)
Xa (z)=
1
1 az1
Applying the derivative operator /a to the pair, derive the z-transform of the sequence x(n)=
nan u(n).
Noting that
= 2n cos(n/2)
Thus, we can rewrite:
we get
n
Xa (z)=
a
a
1
1
az1
z1
(1 az1 )2
Thus,
Only x2 (n) is stable because its ROC contains the unit circle, or, because in the second
term n is effectively negative and causes it to decay exponentially for large negative n, that
is, writing n = |n|, we have:
2n cos(n/2)u(n 1)= 2|n| cos(n/2)u(n 1) 0
as
Multiplying by a, we get:
Z
nan u(n)
X(z)=
B
C
4 0.6z1 + 0.2z2
=A+
+
(1 0.5z1 )(1 + 0.4z1 )
1 0.5z1
1 + 0.4z1
z1
(1 az1 )2
nan1 u(n)
az1
(1 az1 )2
Problem 5.10
We note that each application of D brings down a factor of n:
where
A=
B=
C=
4 0.6z1 + 0.2z2
(1 0.5z1 )(1 + 0.4z1 )
4 0.6z1 + 0.2z2
1 + 0.4z1
4 0.6z1 + 0.2z2
1 0.5z1
=
z=0
D(an ) = a
0. 2
= 1
0 . 5 0 .4
=2
z=0.5
=3
D (a ) = nk an
k
z=0.4
1
Z
nk an u(n) a
a
1 az1
66
1
1 az1
az1
(1 az1 )2
Therefore,
Z
nan u(n)
az1
(1 az1 )2
67
which agrees with the previous problem. For k = 2, we apply D again to get:
1
1 az1
a
= a
= az1
az1
(1 az1 )2
1
(1 az)2
2az1
(1 az1 )3
(L 1) n m 0
By adding them, we obtain the overall range of the index n of x(n), that is,
az (1 + az )
(1 az1 )3
(L 1) n L 1
For any n in this range, we obtain the range of the summation in m:
Therefore,
Z
n2 an u(n)
0mL1
az1 (1 + az1 )
(1 az1 )3
(1
az1 )3
az1 (1 + 4az1 + a2 z2 )
n a u(n)
(1 az1 )4
Problem 5.11
min(L
1,n+L1)
g1 (m)g2 (n m),
(L 1) n L 1
m=max(0,n)
Because over this range, both g1 (n) and g2 (n) are unity, we obtain:
x(n)=
nmn+L1
2az1
0mnL1
x(n)=
min(L
1,n+L1)
m=max(0,n)
11=
1
max (L 1, n + L 1) min(0, n)+1
g1 (n) = u(n)u(n L)
x(n)=
|n|
1
,
max (L 1, n + L 1) min(0, n)+1 = 1
L
(L 1) n L 1
u(n) U(z)=
1
1 z1
we nd the z-transforms:
Problem 5.12
Start with the result
Z
1 zL
G1 (z) = U(z)zL U(z)=
1 z1
1 zL L1
G2 (z) = U(z)zL1 z1 U(z)=
z
1 z1
Therefore, the right-hand-side of the desired z-transform is the product:
X(z)=
1z
1 z1
2
zL1 =
G1 (z)G2 (z)
x(n)=
g1 (n)g2 (n)=
68
g1 (m)g2 (n m)
an u(n)
1
1 az1
1
1 Rej0 z1
1
1 Rej0 z1
Rn ej0 n u(n)
Rn ej0 n u(n)
The cosine and sine signals are obtained from the above as the following linear combinations:
Rn cos(0 n)u(n) = Rn
1 j0 n
u(n)+ej0 n u(n)
e
2
Rn sin(0 n)u(n) = Rn
1 j0 n
u(n)ej0 n u(n)
e
2j
69
Rn cos(0 n)u(n)
1
2
1
1
R sin(0 n)u(n)
2j
Z
Rej0 z1
1
1 Rej0 z1
1
1
A=
1 Rej0 z1
Rn cos(0 n)u(n)
Z
Rn sin(0 n)u(n)
Rej0 z1
1 R cos 0 z1
1 2R cos 0 z1 + R2 z2
R sin 0 z1
1 2R cos 0 z1 + R2 z2
Problem 5.13
a0 + a1 z1 + a2 z2 + a3 z3
(1 + z)(1 jz1 )(1 + jz1 )
1
a0 + a1 + a2 + a3
4
z=1
a0 + a1 z + a2 z + a3 z
a0 a1 + a2 a3
=
(1 z1 )(1 jz1 )(1 + jz1 ) z=1
4
1
2
3
a0 + a1 z + a2 z + a3 z
(a0 a2 )j(a1 a3 )
C=
=
CR jCI
(1 z1 )(1 + z)(1 + jz1 ) z=j
4
B=
A(z)= a0 + a1 z1 + a2 z2 + a3 z3
So that nally:
x(n) =
Then, the z-transform of the periodic signal is recognized as the sum of the delayed replicas of
A(z), that is,
X(z) = a0 + a1 z1 + a2 z2 + a3 z3 + a0 z4 + a1 z5 + a2 z6 + a3 z7
+ a0 z8 + a1 z9 + a2 z10 + a3 z11 +
a0 + a1 + a2 + a3
a0 a2
2
a0 a1 + a2 a3
4
cos(n/2)+
a1 a3
2
= (1 + z
=
+z
A(z)
+ )A(z)=
1 z4
a0 + a1 z1 + a2 z2 + a3 z3
1 z4
Problem 5.15
Summing the geometric series, we have:
X(z)= 1 z2 + z4 z6 + z8 =
Alternatively, we have:
which gives
(1 + z2 )X(z)= 1
Problem 5.14
Factoring the denominator 1 z4 , we obtain the PF expansion:
B
1 + z1
C
1 jz1
C
1 + jz1
where the coefcients C and C are conjugates because they correspond to the conjugate poles
j (this follows from the fact that the denominator has real coefcients.)
The PFE coefcients are determined as follows:
70
X(z)=
1
1 + z2
The inverse z-transform is causal and can be obtained from the PFE:
a0 + a1 z1 + a2 z2 + a3 z3
a0 + a1 z1 + a2 z2 + a3 z3
=
X(z) =
1 z4
(1 z1 )(1 + z)(1 jz1 )(1 + jz1 )
1 z1
1
1 + z2
X(z)= 1 z2 + z4 z6 + z8 = 1 z2 (1 z2 + z4 z6 + z8 )= 1 z2 X(z)
where the convergence of the geometric series requires the ROC |z| > 1.
sin(n/2)
(1)n
X(z)=
1
0.5
0.5
=
+
1 + z2
1 jz1
1 + jz1
which gives:
x(n)= 0.5jn + 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 coefcients of the
expansion.
a. The z-transform and its inverse are:
X(z) =
A=
B=
1
= 1 z4 + z8 z12 + z16
1 + z4
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:
1 z8
=1+z
+z
+z
24
For case (a), the roots of the denominator are the solutions of 1 + z4 = 0 or, z4 = 1. They are
obtained as follows:
z = e(j+2jk)/4 ,
k = 0, 1, 2, 3
3j/4
5j/4
M
R(z)
Ai
=
D(z) i=1 1 pi z1
where pi 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:
ej/4 z1
A
i
1
1 p
i z
1
=
(1 ej/4 z1 )(1 ej/4 z1 )(1 e3j/4 z1 )(1 e3j/4 z1 )
A
1
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:
1
A
(Ai + A
Ai
i
i )(Ai pi + Ai pi )z
+
1 =
1
1 pi z
1 pi z
1 (pi + pi )z + pi pi z
e3j/4
Q(z)D(z)+R(z)
R(z)
N(z)
=
= Q(z)+
D(z)
D(z)
D(z)
z = ej/4 ,
X(z) =
1
1
cos(n/4)+ cos(3n/4)
2
2
1 pi z1
7j/4
1 jn/4
1
1
1
e
+ ejn/4 + e3jn/4 + ejn/4
4
4
4
4
Ai
z=e
A
1
1
4
N(z)= Q(z)D(z)+R(z)
H(z)=
Problem 5.17
j/4
It follows that:
16
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, . . . ]
z4 = 1 = ej = ej+2jk
1
4
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,
X(z) =
z=e3j/4
Cases (b,c,d) are done in a similar fashion. See the solution of Problem 5.19 for the denominator
zeros.
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, . . . ]
z=ej/4
Problem 5.18
1
= 1 z8 + z16 z24 +
1 + z8
1
= 1 + z4 + z8 + z12 + z16 +
1 z4
e3j/4 z1 )
x(n) =
X(z) =
(1
e3j/4 z1 )(1
x(n) = [1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, . . . ]
X(z) =
ej/4 z1 )(1
ej/4 z1
B
1
e3j/4 z1
B
1
e3j/4 z1
72
73
Problem 5.19
Comparing with
The roots of the polynomial 1 zD are the solutions of the equation zD = 1, that is, the D-th
roots of unity. To nd them, replace 1 by e2jk = 1, where k is an integer, and take D-th roots of
both sides:
zD = 1 = e2jk
zk = ej2k/D ,
x(n)zn
we see that
k = 0 , 1, . . . D 1
Y(z)= X(z/a)
They lie on the unit circle at the angles k = 2k/D, k = 0, 1, . . . , D 1 obtained by dividing the
circle into D equal parts. The product of the 1st order zero factors must make up the polynomial
1 zD :
D
1
X(z)=
(1 zk z1 )= 1 zD
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 coefcient, then they must be identically equal to each other.
For the other case, we have the solutions of 1 + z
ej+j2k with any integer k, and nd the roots
zD = 1 = ej(2k+1)
= 0 or z = 1. Now, we replace 1 = e
D
Y()=
y(n)ejn =
zk = ej(2k+1)/D ,
Y()= X( 0 )
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.
ej0 n x(n)ejn =
x(n)ej(0 )n = X( 0 )
Problem 5.22
We use the identity
1
2
ej(nm) 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
z8 = 1
Fig. P5.1 Roots of 1 z
and 1 + z
ej(nm) d =
1
2
X()ejn d =
=
1
2
zk = a1/D ej2k/D ,
k = 0 , 1, . . . , D 1
They all lie on a circle of radius a1/D at the D-th root of unity angles. Similarly, the roots of
1 + azD , lie on the same circle, but at the shifted D-th root of unity angles.
Problem 5.21
Let y(n)= a x(n). Its z-transform is:
y(n)zn =
1
2
ej(nm) d =
x(m)(n m)
where we interchanged the series with the integral (this step is justied 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
X() =
an x(n)zn =
x(n)ejn
x(n)(z/a)n
X () =
x (n)ejn
74
=0
x(m)ejm ejn d
Y(z)=
= x(n)
x(m)
Problem 5.20
zD = a = aej2k
cos (n m) cos (n m)
2j(n m)
Inserting the denition of the DTFT into the inversion formula, we get
z 8 = -1
8
75
Chapter 6 Problems
X()X () d =
=
1
2
X()
x (n)ejn
1
x (n)
2
X()e
jn
Problem 6.1
a. From Y(z)= 0.8z1 Y(z)+X(z) it follows:
d
H(z)=
x (n)x(n)
1
1 + 0.8z1
H()=
1
1 + 0.8ej
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 lter will
tend to enhance high frequencies, i.e., it will behave as a high pass lter:
Problem 5.24
For a real-valued signal x(n), we have:
X() =
z-plane
= pole
x(n)ejn
|H()|
X () =
x(n)ejn
X () =
-0.8
0.55
x(n)ejn
where in the third equation, we replaced by . Comparing the rst and third equations, we
obtain:
Writing X() in its polar form, e.g., X()= |X()|ej arg X() , the hermitian property reads:
X ()= X()
y
for each input sample x do:
y = 0. 8 w 1 + x
z-1
w1
or,
w1 = y
-0.8
|X()|e
j arg X()
= |X()|e
j arg X()
|X()| = |X()| ,
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 lter is acting as a low pass lter.
c. The I/O equation Y(z)= 0.8z1 Y(z)+X(z)+z1 X(z) gives
H(z)=
that is, the magnitude spectrum is even in and the phase spectrum is odd.
1 + z1
B
=A+
1 0.8z1
1 0.8z1
where
A=
1 + z1
1 0.8z1
= 1.25,
B = 1 + z1 z=0.8 = 2.25
z=0
The lter enhances low frequencies for two reasons: rst, it has a pole in the low frequency
range, z = 0.8, and it has a zero in the high frequency range, z = 1. Its frequency
response will be
H()=
76
77
1 + ej
1 0.8ej
= zeros
= poles
z-plane
-1
|H()|
10
exact
zero
The direct form realization and its sample processing algorithm are:
The canonical form realization and its sample processing algorithm are:
w0
-1
-1
v1
1 + 0.25z2
.
1 0.8z1
Using the remove/restore numerator method of problem (2h), we nd
H(z)=
The lter has two conjugate zeros at midrange, z = 0.5j = 0.5ej/2 , and a low frequency
pole at z = 0.8. Thus, the lter will enhance low frequencies and suppress midrange
frequencies:
v1 = x
w1 = y
0.8
H(z)=
0.8
y
z-1
w1
v1 = x
w1 = y
w1
-0.5
The direct form realization and its sample processing algorithm are:
z-1
v1
0.8
-1
y = w0 + w1
w1 = w0
w1
w1 = w 0
-0.5
0.8
z-1
w1
0.8
w0
= zeros
= poles
z-plane
|H()|
0.5j
where
A=
1 0.5z1
1 0.8z1
= 0.625,
B = 1 0.5z1 z=0.8 = 0.375
-0.5j
= zeros
= poles
2.5
w0
0.8
0.833
z-1
w1
w2 = w 1
w1 = w 0
z-1
w2
0.25
The direct form realization and its sample processing algorithm are:
The canonical form realization and its sample processing algorithm are:
78
The canonical form realization and its sample processing algorithm are:
|H()|
0.5
0.8
The lter 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 lter will tend to act as a lowpass lter.
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
z=0
79
x
z-1
z-1
w1
v1
z-1
v2
0.9
0.25
f. Y(z)= 0.9z1 Y(z)0.2z2 Y(z)+X(z)+z1 X(z)6z2 X(z), which implies
x
z-1
v1
B
(1 + 3z1 )(1 2z1 )
C
=A+
H(z)=
+
(1 0.4z1 )(1 0.5z1 )
1 0.4z1
1 0.5z1
0.9
z-1
v2
where
|H()|
2.86
0
The canonical form realization and its sample processing algorithm are:
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 ns we nd:
Y(z) =
0.4
2
-0.2
13.33
0.5
z-1
= zeros
= poles
z-plane
v2 = v1
v1 = x
w2 = w1
w1 = y
Problem 6.2
Thus, h(n)= A(n)+B(0.4) u(n)+C(0.5) u(n). The two zeros at z = 3 and z = 2 are
too far from the unit circle to have any signicant effect on the magnitude response. The
two poles at z = 0.4, 0.5 are both in the low frequency range. Thus, the lter will be a low
pass lter. 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.
n
z-1
w1
w2
-6
A=
-3
-6
The direct form realization and its sample processing algorithm are:
1 + z1 6z2
1 0.9z1 + 0.2z2
w2 = w 1
w1 = w 0
z-1
w2
-0.2
H(z)=
z-1
w1
v2 = v1
v1 = x
w1 = y
0.8
w0
y(n) = [1, 5, 6, 0, 0, 0, ]
There is a pole zero cancellation: the lter has a zero at z = 1, cutting off the highfrequency input.
b. Noting that the input z-transform is X(z)= 1/(1 z1 ), we nd
Y(z)= H(z)X(z)=
1 z4
= 1 + z1 + z2 + z3
1 z1
80
81
y(n)= [1, 1, 1, 1, 0, 0, 0, 0, . . . ]
The rst four samples are the transients, the remaining zeros are the steady state. In the
steady-state, the lter cuts off the unit step from going through because the lter has a
zero at z = 1. The pole of the input canceled the zero of the lter. For the alternating
step:
4
Y(z)=
1z
= 1 z1 + z2 z3
1 + z1
y(n)= [1, 1, 1, 1, 0, 0, 0, ]
Again, the lter has a high frequency zero at z = 1, cutting off the high frequency input.
B=
1
(1 + z1 )(1 + 0.5jz1 )
= 0 .1 + 0 . 2 j
z=0.5j
Problem 6.4
For a unit-step input and the lter (a) of Problem 6.1, we have:
Y(z) = H(z)X(z)=
(1 + 0.8z1 )(1 z1 )
A
1 + 0.8z1
B
1 z1
Problem 6.3
Y(z) = H(z)X(z)=
Y(z) =
=
(1 z1 )(1 0.25z2 )
A
1 z1
B
1 0.5z1
Y(z) =
1
1
=
(1 + z1 )(1 0.5z1 )(1 + 0.5z1 )
(1 + z1 )(1 0.25z2 )
A
1 + z1
B
1 0.5z1
C
1 + 0.5z1
A
B
B
=
+
+
1
1z
1 0.5jz
1 + 0.5jz1
Y(z) =
1
(1 z1 )(1 + 0.5jz1 )
Y(z) =
C
1 + 0.25z2
B
+
=A+
(1 z1 )(1 0.8z1 )
1 z1
1 0.8z1
Y(z) =
= 0. 1 0. 2 j
z=0.5j
(1
1 + z1 6z2
0.4z1 )(1 0.5z1 )
z1 )(1
A
1 z1
B
1 0.4z1
C
1 0.5z1
Y(z) =
1 0.5z1
A
B
=
+
(1 z1 )(1 0.8z1 )
1 z1
1 0.8z1
where A = Y(0)= 0.3125, B = H(1)= 6.25, C = 5.5625. The B-term is the steady part. For
lter (f):
(1
B
A
1 + z1
+
=
0.8z1 )
1 z1
1 0.8z1
z1 )(1
1
1
=
Y(z) =
(1 z1 )(1 + 0.25z2 )
(1 z1 )(1 0.5jz1 )(1 + 0.5jz1 )
B=
B
1 z1
where A = H(1)= 4/3, B = 1/6, C = 0.5. The A-term is the steady part. For (b), we have:
A
1 0.8z1
where A = 4, B = H(1)= 5. The B-term represents the steady part. For lter (c):
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:
1 + 0.5z1
Y(z) =
(1 0.8z1 )(1 z1 )
(1 + z1 )(1 + 0.25z2 )
B
B
A
+
+
1 + z1
1 0.5jz1
1 + 0.5jz1
82
For the alternating step and lter (a) of Problem 6.1, we have:
Y(z) =
(1 + 0.8z1 )(1 + z1 )
A
1 + 0.8z1
83
B
1 + z1
where A = 4, B = H(1)= 5. The B-term represents the steady part. For lter (b):
Y(z) =
(1 0.8z1 )(1 + z1 )
A
1 0.8z1
Y(z) =
1 + z1
where A = 1/2.25, B = H(1)= 1/1.8. The B-term represents the steady part. For lter (c):
1 + z1
1
=
Y(z) =
(1 + z 1 )(1 0.8z1 )
1 0.8z1
The unstable input was canceled by a lter zero to give a stable output.
Problem 6.5
The high frequency zero at z = 1 of the lter canceled the high frequency input signal. The
output is only transient it decays to zero exponentially. For lter (d):
Y(z) =
A
1 0.5z1
B
=
+
(1 + z1 )(1 0.8z1 )
1 + z1
1 0.8z1
Filter (a): H(z)= z5 with I/O equation Y(z)= H(z)X(z)= z5 X(z) and in the time domain
y(n)= x(n 5). H()= e5j and |H()| = 1, i.e., at in . Block diagram realization and
sample-by-sample processing algorithm:
z-1
w1
B
C
1 + 0.25z2
=A+
Y(z) =
+
(1 + z1 )(1 0.8z1 )
1 + z1
1 0.8z1
w2
w3
z-1
1
w4
1 + z 6z
(1 + z1 )(1 0.4z1 )(1 0.5z1 )
A
1 + z1
B
1 0.4z1
z-1
w5
1 0.5z1
Filter (b): H(z)= z5 U(z)= z5 /(1 z1 ) and the I/O equation gives
Y(z)= H(z)X(z)=
z5 X(z)
1 z1
(1 z1 )Y(z)= z5 X(z)
H()=
Z
The lter zero canceled the signal pole. For question (d), we have x(n)= (0.5)n cos(n/2)u(n)
X(z)= 1/(1 + 0.25z2 ). Thus,
Y(z) =
y = w5
w5 = w4
w4 = w3
w3 = w2
w2 = w1
w1 = x
z-1
Y(z) =
z-1
e5j
1 ej
|H()| =
The pole at z = 1 or = 0 dominates the frequency response. The lter acts as a lowpass lter
(it is actually an accumulator with delay).
1
1 + 0.25z2
=
1 0.8z1
(1 + 0.25z2 )(1 0.8z1 )
84
1
2| sin(/2)|
85
z-plane
|H()|
= poles
Y(z)= H(z)X(z)=
0.5
The canonical form realization and its sample processing algorithm are:
The rest is as in problem (3c). Filter (e): With a = 0.8, the impulse response is nite:
h(n)= [1, a, a2 , a3 , a4 , a5 , a6 , a7 , 0, 0, 0, ]
Its z-transform is
H(z)= 1 + az1 + a2 z2 + a3 z3 + a4 z4 + a5 z5 + a6 z6 + a7 z7 =
w0
z-1
w1
z-1
X(z)
1 + 0.8z1
w0 = x + w1
y = w5
w5 = w 4
w4 = w 3
w3 = w 2
w2 = w 1
w1 = w 0
w2
-1
w3
z-1
w4
1 a8 z8
1 az1
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 nd them, solve the equation z8 = a8 and exclude the solution z = a, that
is,
k = 1 , 2 , 3, 4 , 5 , 6, 7
= zeros
z-plane
z-1
w5
y
1
The direct form realization and its sample processing algorithm are:
x
z=a=-0.8
z-1
v1
for each input sample x do:
-1
y = w1 + v5
w1 = y
v5 = v4
v4 = v 3
v3 = v 2
v2 = v 1
v1 = x
v2
-1
v3
z-1
v4
w1
z-1
-1
v5
Filter (c): H(z)= 1/(1 0.8z1 ) and the I/O equation becomes:
Y(z)= H(z)X(z)=
X(z)
1 0.8z1
86
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
87
w2
w1
z -1
a0
z -1
a1
w3
z -1
a2
w4
z -1
a3
w5
z -1
a4
w6
z -1
a5
w7
There is a conjugate pair of poles at midfrequency, z = 0.8j = 0.8e/2 . Thus, the lter will
emphasize mid frequencies:
z -1
a6
a7
z-plane
= poles
|H()|
0.8j
y
-0.8j
Filter (f): H(z)=
/2
1
1
2
+
=
1 0.8z1
1 + 0.8z1
1 0.64z2
Y(z) = H(z)X(z)=
2X(z)
1 0.64z2
The direct form realization and its sample processing algorithm are:
z-1
w1
There is a low frequency pole at z = 0.8 and a high frequency pole at z = 0.8. Thus, the lter
will emphasize both the low and high frequencies:
z-plane
= poles
y = 2x 0.64w2
w2 = w1
w1 = y
z-1
w2
|H()|
-0.64
-0.8
Problem 6.6
0.8
/2
where convergence requires |z|8 > 0.5, or, |z| > (0.5)1/8 . The block diagram and sample processing algorithm are:
-1
w1
z
w8
0.5
0.64
where the call to delay updates the 9-dimensional state vector of the eightfold delay w = [w0 ,
w1 , . . . , w8 ].
Filters (g,h):
z -8
w2
Y(z) = H(z)X(z)=
w0
w2 = w 1
w1 = y
-1
1
1 0.5z8
Problem 6.7
Because z = ej , we can deduce the transfer function from H():
H(z)=
H(z)= 0.5 +
88
0.5 + z8
1 0.5z8
0.75z8
= 0.5 + 0.75z8 1 + 0.5z8 + 0.52 z16 + 0.53 z24 +
1 0.5z8
89
where
h(n)
0.75
Taking the causal inverse z-transform, we obtain a closed-form solution for the nth Fibonacci number:
0.75/2
0.75/4
z1
1
1
=
=
1
1+ z
1 + 2
5
z=
1
1
z
=
=
B=
1 z1 z=1
1 + 2
5
A=
...
h(n)= An + B()n ,
n0
-0.5
It is unstable because is greater than 1 (note, 1.618).
Problem 6.8
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)
An+1
=
h(n)
An
(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:
This can also be seen from the difference equation of h(n). For n 1, we have
h(0) = h(1)+h(2)+(1)= 0 + 0 + 0 = 0
h(1) = h(0)+h(1)+(0)= 0 + 0 + 1 = 1
H(z)= z
H(z)+z
H(z)+z
h(n + 1)
h(n)
=
+1
h(n 1)
h(n 1)
h(n)
h(n + 1)
h(n)
=
+1
h(n 1)
h(n 1)
h(n)
H(z)=
or,
z1
If we denote the ratio r(n)= h(n + 1)/h(n), we may write this as:
1 z1 z2
z2 z 1 = 0
z=
1 5
2
r2 = r + 1
1+ 5
,
2
1 5
2
which is the same as that satised by . Thus, r = because they are the positive
solutions.
Indeed, we have
2
1+
2 ( 1 5)
2 ( 1 5)
1 5
=
=
15
2
(1 + 5)(1 5)
A
z1
B
z1
=
=
+
H(z)=
1 z1 z2
(1 z1 )(1 + 1 z1 )
1 z1
1 + 1 z1
90
d. The sequence y(n) satises 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)=
h(n + 1)
An+1
=
h(n)
An
z1
1 z1
Y(z)=
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):
z1
z1
(1 + 1 z1 )= H(z)(1 + 1 z1 )
=
1
1 z
(1 z )(1 + 1 z1 )
and therefore, it may be thought of as the output when the input is:
z1
Y(z)
1 z1
= 1 + 1 z1
X(z)=
=
z1
H(z)
(1 z1 )(1 + 1 z1 )
X(z)= 1 + 1 z1
or,
x(n)= (n)+1 (n 1)
x = [1, 1 , 0, 0, 0, 0 . . . ]
x(n)= (n)+1 (n 1)
x = [1, 1 , 0, 0, 0, 0 . . . ]
or
Problem 6.10
The input and output z-transforms are:
Problem 6.9
X1 (z)=
As in the previous problem, the impulse response satises the difference equation:
1
,
1 0.5z1
1
1
2(1 0.45z1 )
+
=
1 0.5z1
1 0.4z1
(1 0.5z1 )(1 0.4z1 )
Y1 (z)=
H(z)=
2(1 0.45z1 )
Y1 (z)
=
X1 (z)
1 0.4z1
h(0) = 2h(1)+h(2)+(1)= 0 + 0 + 0 = 0
Y2 (z)=
h(1) = 2h(0)+h(1)+(0)= 0 + 0 + 1 = 1
1
1 0.4z1
will be produced by
Taking z-transforms, we nd H(z):
H(z)= 2z
H(z)+z
H(z)+z
z1
H(z)=
1 2z1 z2
z 2 = 2z + 1
z=1
2 = {, 1 }
H(z)=
A
z1
B
z1
=
=
+
1 2z1 z2
(1 z1 )(1 + 1 z1 )
1 z1
1 + 1 z1
where
1
A = B = 2
=
+1
2 2
Thus, the nth Pell number will be:
h(n)= An + B()n ,
n0
Because the exponentially diverging term n dominates the sum, the ratio of two successive
numbers will converge to
92
X2 (z)=
0. 5
Y2 (z)
=
H(z)
1 0.45z1
Problem 6.11
The input and output z-transforms are:
X1 (z) =
1
1 az1
Y1 (z) =
1
1
2 (a + b)z1 )
2(1 cz1 )
=
+
=
1 az1
1 bz1
(1 az1 )(1 bz1 )
(1 az1 )(1 bz1 )
H(z)=
2(1 cz1 )
Y1 (z)
=
X1 (z)
1 bz1
If the input x2 (n)= cn u(n) is applied it will have z-transform X2 (z)= 1/(1 cz1 ) and will
cause the output:
2(1 cz1 )
1
2
=
1 bz1
1 cz1
1 bz1
93
Problem 6.12
X(z) =
Y(z) =
1
1 1.8781z1 + 0.9750z2
H(z)=
1
1 0.7z1
1
1
1
2 ( 1 0. 6 z )
+
=
1 0.7z1
1 0.5z1
(1 0.7z1 )(1 0.5z1 )
The time constant of the resonator is given in terms of the maximum pole radius (there is only
one radius here):
neff =
neff =
ln
ln
ln
2 ln
=
=
ln R
ln(1 /2)
/2
where we used the small-x approximation ln(1 x) x. The approximate numerical value of
the time constant will be:
neff =
ln
ln(0.01)
=
= 363.18
ln R
ln(0.9874)
2 ln
2 ln(0.01)
= 366.47
0.008
Problem 6.14
Problem 6.13
0 =
=
2f0
fs
2f
fs
2250
= 0.1 [rads/sample]
5000
220
= 0.008 [rads/sample]
5000
0.008
neff =
where = max i |pi | is the maximum pole radius. In seconds, the time constant is:
p = Rej0
where T = 1/fs is the interval between samples. It follows that the 1 and 2 level time constants
will be
1 =
ln 1
T,
ln
2 =
ln 2
T
ln
And therefore,
1 =
= 2(1 R)
ln
T
ln
= neff T =
p = Rej0 ,
ln
ln
ln 1
2
ln 2
In particular, for the 60 versus 40 dB time constants, the scale factor is:
ln(0.001)
3
ln 1
= = 1 .5
=
ln 2
ln(0.01)
2
which gives:
R=1
1
1
= 1 0.008 = 0.9874
2
2
Problem 6.15
Using the approximate expression of Problem 6.13 and = 0.001, we have:
= neff T =
2 ln
T=
2 ln
ln
T=
2f T
f
which gives:
94
ln
ln(0.001)
2.2
=
f
f
f
95
Problem 6.16
The periodic impulse response may be thought of as the sum of the delayed replicas of one period,
that is,
H(z)=
z-1
z-1
z-1
z-1
z-1
z-1
z-1
z-1
z-1
w1
w2
z-1
w4
z-1
w5
z-1
z-1
z-1
z-1
z-1
z-1
w2
3
z-1
w3
z-1
w4
z-1
z-1
z-1
w0 = x + w 4
y = w 1 + 2w 2 + 3w 3
delay(4, w)
z-1
z-1
w8
Fig. P6.1 Filter realizations of Problem 6.16.
w0 = x + w 8
y = w 0 + 2w 1 + 3 w 2 + 4 w 3
delay(8, w)
where the call to delay(4, w) implements the updating of the delay line, that is, w4 = w3 , w3 = w2 ,
. . . , w1 = w0 . The cascade realization is obtained by factoring the numerator and denominator
into (up to) 2nd order polynomials:
H(z)=
z1 + 2z2 + 3z3
=
1 z4
z1
1 z2
1 + 2z1 + 3z2
1 + z2
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
Problem 6.17
The solution is similar to that of Problem 6.16. Here, the repetition period is 4 and we have:
H0 (z)H1 (z)
The block diagram is shown in Fig. P6.3. The corresponding sample processing algorithm is:
where the call to delay(8, w) implements the updating of the delay line, that is, w8 = w7 , w7 = w6 ,
. . . , w1 = w 0 .
96
z
w1
w6
w7
-1
z-1
z-1
w0
w0
w3
-1
z-1
y
z1 + 2z2 + 3z3
1 z4
-1
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 vefold delay z5 . The
sample processing algorithm for the canonical case is:
G(z)
1 z4
97
x1
w0
v0
z-1
w1
v1
z-1
z-1
w2
z-1
w2
v2
z-1
w3
-1
H0(z)
w0
z-1
z-1
w1
z-1
w4
H1(z)
z-1
w5
z-1
w6
z-1
w7
H(z) =
z1 + 2z2 + 3z3
z1 + 2z2 + 3z3
=
1 z4
(1 z1 )(1 + z1 )(1 jz1 )(1 + jz1 )
A
B
C jD
C + jD
=
+
+
+
1 z1
1 + z1
1 jz1
1 + jz1
where the PFE coefcients C jD are conjugates. The numerical values are:
A=
z1 + 2z2 + 3z3
(1 + z1 )(1 jz1 )(1 + jz1 )
= 1.5
w0 = x + w7
y = w0 + w1 + w2 + w3
delay(7, w)
z=1
z1 + 2z2 + 3z3
= 0.5
(1 z1 )(1 jz1 )(1 + jz1 ) z=1
z1 + 2z2 + 3z3
= 0 .5 + j 0 . 5
C jD =
(1 z1 )(1 + z1 )(1 + jz1 ) z=j
B=
jn/2
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, . . . ]
x0 hn1 = [0, 2, 2, 2, 2, 0, 0, 0, 2, 2, 2, 2, 0, 0, 0, 2, 2, 2, 2, 0, 0, . . . ]
x0 hn2 = [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, . . . ]
h(n)= [0, 1, 2, 3, 0, 1, 2, 3, . . . ]
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) =
Problem 6.18
Expand the denominator in powers of z7 and pick out the coefcients of the powers of z1 . We
have:
H(z)=
1 + z1 + z2 + z3
= (1 + z1 + z2 + z3 )(1 + z7 + z14 + )
1 z7
The powers of z7 cause the period-7 replication of the basic period G(z)= 1 + z1 + z2 + z3 :
(1 + z1 + z2 + z3 )(3 + 2z1 + z2 )
1 z7
3 + 5z1 + 6z2 + 6z3 + 3z4 + z5
1 z7
The expansion of the denominator in powers of z7 will cause the period-7 replication of the
numerator.
Problem 6.19
h(n)= [1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, . . . ]
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:
98
99
which gives:
H(z)=
1 + z1 + z2 + z3
= (1 + z1 + z2 + z3 )(1 + z2 + z4 + )
1 z2
H(z)=
H(z)=
+[0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, . . . ]
=[1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, . . . ]
Problem 6.21
fs
240
=
=4
60
f1
z-1
w0 = x + w 2
y = w0 + w 1 + w 2 + w 3
w3 = w2
w2 = w1
w1 = w0
w1
-1
w2 z
-1
w3
w0
1 + z1 + z2 + z3
(1 + z2 )(1 + z1 )
=
(1 z1 )(1 + z1 )
1 z2
+[0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, . . . ]+
1 + z2
Y(z)
=
X(z)
1 z1
Therefore, the harmonics will lie at the fourth roots of unity around the unit circle:
k = k1 =
2k
,
4
k = 0, 1, 2, 3
The numerator polynomial 1 z4 will have ejk as roots. Putting the poles just behind the
zeros, we get the desired multinotch lter:
Problem 6.20
H(z)=
Writing the sample processing algorithm in terms of the time index n, we have
1 z4
1 az4
Problem 6.22
w2 (n + 1) = w1 (n)
w1 (n + 1) = w0 (n)
zk = ejk = e2jk/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 = k1 = 2k/16, and be essentially at between zeros. Fig. P6.6 shows a
sketch of |H()|.
The impulse response is obtained by expanding H(z) into powers of z16 . We have with A = 1/a
and B = 1 A = 1 1/a:
W1 (z)= z1 W0 (z),
W0 (z)=
X(z)
100
H(z)=
B
1 z16
=A+
= A + B(1 + az16 + a2 z32 + )
1 az16
1 az16
1 z1
k = 0, 1, . . . , 15
X(z)
1 z1
A + B = 1, if n = 0
h(n)= Ban/16 ,
if n is a non-zero multiple of 16
0,
otherwise
101
= zeros
= zeros
z-plane
y = x + a(w1 x)
w1 = y
Fig. P6.5 Pole/zero pattern of Problem 6.22.
1a
1 = 2/16
|H()|
w0
x
a
z-1
w1
1 21 31 41
...
z-1
w1
151 161=2
Problem 6.25
The lter poles are at z = 2, 0.5. Thus,
w0
w0 = x + w16
y = w0 aw16
delay(16, w)
z-16
w16
a
H(z)=
H(z)=
-1
3 3z1 z2
3 3z1 z2
=
1 1.5z1 z2
(1 2z1 )(1 + 0.5z1 )
B
3 3z1 z2
C
=A+
+
(1 2z1 )(1 + 0.5z1 )
1 2z1
1 + 0.5z1
where
Problem 6.23
A=
0 .6
. It follows that h(n)= 0.3(n)+0.6(0.5)n u(n).
H(z)= 0.3 +
1 0.5z1
B=
Problem 6.24
C=
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)=
1a
Y(z)
=
X(z)
1 az1
3 3z1 z2
1 1.5z1 z2
3 3z1 z2
1 + 0.5z1
3 3z1 z2
1 2z1
=1
z=0
=1
z=2
=1
z=0.5
or,
|z| > 2 ,
2 > |z| > 0.5,
|z| < 0.5,
Only the second one is stable. Its ROC contains the unit circle.
102
103
Problem 6.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):
H(z)=
Y(z)
3(1 + z2 )
=
X(z)
1 2.5z1 + z2
x(n)=
B
3(1 + z2 )
3(1 + z2 )
C
=A+
=
1 2.5z1 + z2
(1 2z1 )(1 0.5z1 )
1 2z1 1 0.5z1
A=
B=
C=
3( 1 + z )
1 2.5z1 + z2
3(1 + z2 )
1 0.5z1
2
3( 1 + z )
1 2z1
where G is its passband gain. Thus, the integration range for y(n) also collapses to [c , c ],
giving:
y(n)=
=3
z=0
GejD X()ejn d = G
1
2
c
c
X()ej(nD) d
y(n)= Gx(n D)
z=2
= 5
Problem 6.28
z=0.5
H(z)=
1
1 + z2
(1 pi z1 )
Ai
i=1
1 pi z1
i=1
N(z)
Ai =
(1 p z1 )
N(z)
M
where the i-th coefcient is obtained by deleting the factor (1 pi z1 ) from the left-hand side
and evaluating the remainder at z = pi , that is,
=
1 2z1
1 + z2
j=i
N(pi )
1
(1 pj p
i )
j=i
z=pi
Y(z)= H(z)X(z)=
|z| > 2 ,
2 > |z| > 0.5,
|z| < 0.5,
1
2
=5
X()ejn d
GejD , for 0 || c
H()=
0,
for c < ||
where
Using d()= D, the denition of H() over one Nyquist interval will be:
Factoring the denominator into its poles and expanding in partial fractions, we get:
H(z)=
1
2
1 2z1
3
3(1 + z2 )
=
1 0.5z1
(1 2z1 )(1 0.5z1 ) 1 + z2
h(n)=
Ai pni u(n)
i=1
Problem 6.29
n
Problem 6.27
The z-transforms of the causal and anticausal sinusoidal inputs are the same up to a negative
sign:
Z
y(n)=
1
2
ej0 n u(n)
Z
H()X()ejn d
Similarly, for the input signal, assuming its spectrum is restricted to be only over the range
[c , c ]:
104
1
1 ej0 z1
ej0 n u(n 1)
1
1 ej0 z1
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
Problem 6.30
Y(z)=
(1 e
N(z)
M
z ) (1 pi z1 )
j0 1
H(z)=
i=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:
Bi
C
1
0
1e
z
1 pi z1
i=1
M
Y(z)=
where C = H(0 ), as we saw in Eq. (6.3.10), and Bi are obtained by deleting the factor (1 pi z1 )
and evaluating the rest at z = pi :
The truncated impulse response agrees with h(n) for n D and is zero otherwise, that is:
(n)+0.5 , n 0
n
'
h(n)= 2 ,
D n 1
0,
n D 1
N(z)
Bi =
(1 ej0 z1 ) (1 p z1 )
j
j=i
=
z=pi
3 5z1 + z2
1
1
=1+
+
(1 0.5z1 )(1 2z1 )
1 0.5z1
1 2z1
N(pi )
M
1
(1 ej0 p
(1 pj pi1 )
i )
j=i
'
H(z)=
Bi =
2n zn =
2m zm =
m=1
n=D
xm = x + x2 + xD = x(1 + x + x2 + xD1 )=
In this case the C term will be inverted anticausally and the Bi terms causally. These choices for
the ROCs, give:
'
1+
H(z)=
x(1 xD )
1x
1
1 2D zD
+
1
1 0. 5 z
1 2z1
Bi pni u(n)
i=1
Adding up the right-sided and left-sided sinusoidal inputs gives rise to the double-sided input:
ej0 n u(n)+ej0 n u(n 1)= ej0 n u(n)+u(n 1) = ej0 n ,
i=1
2D zD
1 2z1
'
H(z)H(z)=
2D zD
1 2z1
< n <
where, we used the property u(n)+u(n 1)= 1 for all n. It follows from the linearity of the
lter that the corresponding output will be the sum of the two outputs obtained above. This
gives:
'
H(z)=
H(z)
or, the error transfer function:
Bi pni u(n)
i=1
'
'
'
E(z)= Y(z)Y(z)=
H(z)X(z)H(z)X(z)=
H(z)H(z)
X(z)
or,
Bi pni u(n)
E(z)=
i=1
21 z(1 2D zD )
1 2D zD
=
1 21 z
1 2z1
Thus,
m=1
2n zn
n=D
Ai
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 lter 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:
[(n)+0.5n ]zn
n=0
1
1 ej0 p
i
2D zD
(1 2z1 )= 2D zD
1 2z1
e(n)= 2D (n + D)
j0 n
106
107
Chapter 7 Problems
x1
v0
-1
Problem 7.1
-1 w z
1
v1
Expanding the denominator in powers of z 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 coefcients:
-1
-1 w2 z
-1
v0
v2
w2
z-1
z-1
v4
w3
w4
w5
z-1
z-1
z-1
w2
z-1
w3
z-1
w4
z-1
w5
The sample processing algorithms are expressed with the help of the routine delay, which updates
the lters internal state vectors.
v0 = x
w0 = w5 + v1 + 2v2 + 3v3 + 4v4
y = w0
delay(4, v)
delay(5, w)
w0 = x + w 5
y = w 1 + 2w 2 + 3 w 3 + 4 w 4
delay(5, w)
where v = [v0 , v1 , v2 , v4 ], w = [w0 , w1 , w2 , w3 , w4 .w5 ] are the 5- and 6-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(5, w) is equivalent to the shifts: w5 = w4 , w4 = w3 ,
w3 = w2 , w2 = w1 , w1 = w0 .
H(z)=
= (1 z
where v = [v0 , v1 ], w = [w0 , w1 , w2 , w3 , w4 ] are the internal state vectors for the two lter
sections.
Problem 7.2
In the z-domain, the input to H1 (z) is X(z)Y(z). Therefore, its output will be H1 (z) Y(z)
X(z) . The input and output of H2 (z) will be then :
v0 = x + v 1
x1 = v 1
delay(1, v)
w0 = x1 w1 w2 w3 w4
y = w 0 + 2 w 1 + 3 w 2 + 4w 3
delay(4, w)
z-1
w4
w1
z-1
z-1
w1
z-1
-1
v1
w0
-1
v3
w0
-1
-1
-1 w z
3
h = [0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4, . . . ]
w0
-1
)(1 + z
+z
+z
+z
1 z5
1 z1 1 + z1 + z2 + z3 + z4
Figure P7.2 shows the cascade of these two lters, with each lter realized in its canonical form.
The corresponding sample processing algorithm is as follows:
108
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), resulting in:
Y(z)= H2 (z) H1 (z) Y(z)X(z) Y(z) + E(z)
Moving the Y-dependent terms to the left, we get:
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)
Hx (z) =
He (z) =
H1 (z)H2 (z)
1 + H2 (z)+H1 (z)H2 (z)
1
1 + H2 (z)+H1 (z)H2 (z)
109
The conditions that Hx (z) be a plain delay and He (z) a double differentiator, gives the two
equations:
H1 (z)H2 (z)
1 + H2 (z)+H1 (z)H2 (z)
= z1
1
= (1 z1 )2
1 + H2 (z)+H1 (z)H2 (z)
H1 (z) =
H2 (z) =
1
1
H(z)=
z1
z1
1 z2
1 + 2z2
1 + 3z2
1 + z1 + z2 1 z1 + z2
Figure P7.4 shows the cascade of these three lters, with each lter realized in its canonical form.
z1
1 z1
They are both integrators. The presence of z1 in the numerator of H2 (z) is necessary to make
the overall closed loop computable. See also Problems 12.24 and 12.25.
x1
x2
u0
z-1
-1
z-1
z1 (1 + 2z2 )(1 + 3z2 )
z1 + 5z3 + 6z5
=
1 z6
1 z6
w0
-1
w1 z
-1 v1 z
z-1
u2
v0
u1
Problem 7.3
H(z)=
v2
-1
z-1
w2
-1
v0
z-1
z-1
z-1
v5
z-1
z-1
w3
w4
w5
w6
u0 = x + u 2
x1 = u1
delay(2, u)
v0 = x1 v1 v2
x 2 = v 0 + 2v 2
delay(2, v)
w0 = x2 + w1 w2
y = w 0 + 3w 2
delay(2, w)
w1
z-1
w2
z-1
w0
z-1
w1
v2
v4
z-1
v1
v3
w0
w2
z-1
w3
z-1
w4
z-1
w5
z-1
w6
z-1
z-1
z-1
z-1
where u = [u0 , u1 , u2 ], v = [v0 , v1 , v2 ], w = [w0 , w1 , w2 ], are the internal state vectors for the
three lter 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 z6 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 coefcients:
The sample processing algorithms are expressed with the help of the routine delay, which updates
the lters internal state vectors.
for each input x do:
v0 = x
w0 = v1 + 5v3 + 6v5 + w6
y = w0
delay(5, v)
delay(6, w)
110
w0 = x + w 6
y = w 1 + 5 w 3 + 6w 5
delay(6, w)
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)
111
V(z)=
X(z)
1 z1
Y(z)= (1 + z2 + z4 )V(z)=
1 + z2 + z4
X(z)
1 z1
v0 = x + v 1
x1 = v0 + v1 + v2
delay(2, v)
w0 = x1
y = w0 w1 + w2
delay(2, w)
H(z)=
1 + z2 + z4
1 + z1 + z2
=
(1 z1 + z2 )
1 z1
1 z1
Problem 7.5
Factoring the denominator, we may write the transfer function as:
The direct, canonical, and cascade realizations are shown in Fig. P7.5.
v0
w0
z-1
w0
z-1
v1
w1
z-1
v2
v3
v4
z-1
w2
z-1
w3
z-1
w4
v0
z-1
v1
w0
z-1
w1
w2
v2
v0
w0
-1
z-1
z-1
v0 = x
w0 = 2v0 3v1 + 2v2 3v3 + 0.25w4
y = w0
delay(3, v)
delay(4, w)
z-1
x1
2 3z1
1 + z2
2 3z1 + 2z2 3z3
=
2
1 0.25z4
1 0 . 5z
1 + 0. 5z
The direct and canonical realizations are shown in Fig. P7.6. Their sample processing algorithms
are:
z-1
w1
H(z)=
z
-1
z-1
v1
z-1
v2
v3
z-1
v0 = x
w0 = v0 + v2 + v4 + w1
y = w0
delay(4, v)
delay(1, w)
And for the cascade realization:
w0 = x + w 1
y = w0 + w 2 + w 4
delay(4, w)
w0
-1
-3
w1
w1
z-1
z-1
-3
w2
w2
w3
w3
-1
-3
z-1
z-1
-3
-1
w4
0.25
0.25
w4
y = w0 + w2
delay(2, w)
112
-1
z
The direct and canonical sample processing algorithms are:
113
x1
v0
z-1
v1
w0
x1
v0
z-1
-3
w1
z-1
v2
0.5
z-1
v1
z-1
w2
-0.5
-0.25
The direct and canonical realizations are shown in Fig. P7.8. Their sample processing algorithms
are:
for each input x do:
v0
w0
z-1
z-1
w1
-2.25
z-1
z-1
w2
w2
w3
w3
w4
0.0625
0.0625
w2
0.25
Problem 7.7
The direct and canonical realizations are shown in Fig. P7.10. Their sample processing algorithms
are:
for each input x do:
v0 = x
y = w0 = v0 2v2 + v4 + 0.4096w4
delay(4, v)
delay(4, w)
z-1
z-1 -2.25
z-1
w4
v0
The cascade realization is shown in Fig. P7.9. Its sample processing algorithm is:
for each input x do:
v0 = x 0.25v2
x1 = v0 2.25v2
delay(2, v)
y = w0 = x1 + 0.25w2
delay(2, w)
w0
-1
z-1
v2
v3
-1
z
w1
w1
w2
w2
w3
w3
z-1
-2
z-1
z-1
z-1
w0
z-1
v4
-1
v1
z-1
-2
z-1
z-1
w4
0.4096
0.4096
w4
H(z)=
-2.25
The four poles z = 0.5, 0.5j, dene 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:
z-1
z-1
v2
z-1
w0
w1
w1
z-1
z-1
v1
v2
z-1
Problem 7.6
v0 = x
w0 = v0 2.25v2 + 0.0625w4
y = w0
delay(2, v)
delay(4, w)
w0
2 .5
2.5
2
2
+
+
+
1 0.5jz1
1 + 0.5jz1
1 0.5z1
1 + 0.5z1
114
H(z)=
1 2z2 + z4
1 z2
1 z2
=
1 0.4096z4
1 0.64z2 1 + 0.64z2
115
Note that the numerator could also have been factored as:
return y;
}
But the chosen one has the simplest coefcients. Its sample processing algorithm is:
x1 = v0 v 2
delay(2, v)
w0 = x1 0.64w2
y = w0 w 2
delay(2, w)
H()=
(1 0.75e10j ) 10j
1 0.75e10j 10j
0.75 + e10j
e
e
=
=
10
j
10
j
1 0.75e
1 0.75e
(1 0.75e10j )
Noting that the ratio of two conjugate complex numbers has unit magnitude, it follows that H()
will have unit magnitude.
Problem 7.9
x1
v0
z-1
v1
The given sample processing algorithm corresponds to the canonical realization of the lter:
H(z)=
z-1
w1
z-1
v2
0.64
w0
-1
-0.64
z-1
w2
1 + z3
1 0.64z4
1 + z4 = (1 + z1 )(1 z1 + z2 )
-1
we obtain the cascade factors:
H(z)=
1 + z3
1 + z1
1 z1 + z2
2
1 + 0.8z2
1 0.64z
1 0. 8 z
The cascade realization is shown in Fig. P7.12. Its sample processing algorithm is:
Problem 7.8
The given difference equations describe the canonical realization form of the lter:
10
H(z)=
0.75 + z
1 0.75z10
x1 = v0 + v1
delay(2, v)
w0 = x1 0.8w2
y = w0 w1 + w2
delay(2, w)
Its block diagram realization and sample processing algorithm are given below:
-0.75
y
for each input sample x do:
w0 = x + 0.75w10
y = 0.75w0 + w10
delay(10, w)
w0
-10
w10
x1
v0
0.75
z-1
v1
double reverb(x, w)
double x, w[11];
{
int i;
double y;
0.8
w0
z-1
w1
z-1
v2
-0.8
-1
z-1
w2
116
117
Problem 7.10
= zeros
= poles
The rst lter is an FIR lter with transfer function and impulse response:
|H()|
0.9j
-0.9
h = [ 1 , 0 , 3 , 0 , 3 , 0 , 1]
0.9
The causal impulse response of the third lter is obtained by the remove restore method, that is,
where
-0.9j
The rst lter has zeros at z = j, each being a triple zero. The second lter has poles at
z = 0.9j, and the third lter 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 lters 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
0.9j
0.9
-1
v0 = x
y = w0 = v0 + v4 + 0.6561w4
delay(4, v)
delay(4, w)
y = w0 + w 4
delay(4, w)
-0.9j
x
-j
-j
|H()|
|H()|
w0
z-1
|H()|
v0
z-1
z-1
z-1
z-1
z-1
z-1
v4
w0
z-1
w1
v2
v3
z-1
v1
w1
w2
w2
w3
w3
z-1
z-1
z-1
w4
0.6561
0.6561
w4
Problem 7.11
Fig. P7.15 Direct and canonical realizations of Problem 7.11.
Multiplying the transfer function factors, we obtain:
H(z)=
(1
The cascade realization is shown in Fig. P7.16. Its sample processing algorithm is:
for each input x do:
v0 = x 0.81v2
x1 = v0 2v1 + v2
delay(2, v)
w0 = x1 + 0.81w2
y = w 0 + 2w 1 + w 2
delay(2, w)
z4 = 1
z = ej(2k+1)/4 ,
k = 0, 1 , 2, 3
that is, the 4th roots of unity rotated by 45o . 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:
Problem 7.12
The zeros are at the roots of 1 + 16z4 = 0, that is,
118
119
x1
v0
z-1
v1
-0.81
w0
z-1
- 2
w1
z-1
v2
0.81
H(z)=
The direct and canonical realizations are shown in Fig. P7.18. Their sample processing algorithms
are:
z-1
w2
v0 = x
y = w0 = 0.0625v0 + v4 0.0625w4
delay(4, v)
delay(4, w)
z4 = 16
z = 2ej(2k+1)/4 ,
1
z =
16
z = 0. 5 e
j(2k+1)/4
0.0625
v0
w0
z-1
k = 0, 1 , 2, 3
v3
z-1
z-1
z-1
|H()|
0.0625
w0
z-1
w1
w1
w2
w2
w3
w3
z-1
v2
= zeros
= poles
z-1
v1
z-1
unit
circle
k = 0, 1 , 2 , 3
that is, the 4th roots of unity rotated by 45o and scaled in magnitude by a factor of 2. Similarly,
the poles are at:
4
0.0625 + z4
1 2 2z1 + 4z2
1 + 2 2z1 + 4z2
= 0.0625
1 + 0.0625z4
1 0.5 2z1 + 0.25z2 1 + 0.5 2z1 + 0.25z2
z-1
v4
z-1
z-1
z-1
w4
-0.0625
-0.0625
w4
1
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:
x 1 = v 0 2 2v 1 + 4 v 2
delay(2, v)
y = w 0 + 2 2w 1 + 4w 2
delay(2, w)
H()=
c + e4j
1 + ce4j
e4j (1 + ce4j )
(1 + ce4j )
= e4j
1 + ce4j
(1 + ce4j )
The ratio of the two conjugate factors will have unity magnitude, giving
(1 + ce4j )
=11=1
|H()| = |e4j |
(1 + ce4j )
To get the cascade form, we may factor the numerator and denominator using the identity:
1 + a4 z4 = (1
2az1 + a2 z2 )(1 +
2az1 + a2 z2 )
1
1
1
+ z4 =
(1 + 24 z4 )=
(1 2 2z1 + 4z2 )(1 + 2 2z1 + 4z2 )
16
16
16
120
H(z)=
c + z4
1 + cz4
=c+
(1 c2 )z4
= c + (1 c2 ) z4 cz8 + c2 z12 c3 z16 +
1 + cz4
(1 c2 )c(n4)/4
h(n)=
(1 c2 )c(n4)/4
if n = 0
if n is an even multiple of 4
if n is an odd multiple of 4
otherwise
121
x1
0.0625
w0
-1
v1 z
-1
w1 z
0.5 2
-0.25
z-1
-2 2
v2
-0.5 2
-0.25
v0
z-1
w2
22
Problem 7.13
printf("\n\n");
while(fscanf(fpx,
ydir = dir(M,
ycan = can(M,
ycas = cas(K,
printf("% .6f
}
printf("\n a, b = \n");
/* direct form coefficients */
for (i=0;i<=M;i++)
printf("% .6lf % .6lf\n", a[i], b[i]);
void main()
{
int i, j, K, M;
double x, ydir, ycan, ycas;
double *vdir, *wdir, *wcan, **W;
double **A, **B, *a, *b;
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):
FILE *fpx;
fpx = fopen("x.dat", "r");
/* input data */
4
1
1
1
1
0.313
0.147
0.117
0.103
-0.373
-1.122
-0.891
-0.780
0
0.712
0.360
0.190
0.313
0.294
0.234
0.206
0
0.147
0.117
0.103
These inputs may also be saved in a le, say, input.dat, and piped into the program by
iirfilt < input.dat
The input signal xn to be ltered is assumed to be in the le x.dat. The program stops ltering
as soon as the end-of-le of x.dat is encountered. The rst 10 of the input and output samples
are shown below:
122
123
x(n)
ydir (n)
ycan (n)
ycas (n)
1.000000
1.000000
1.000000
1.000000
1.000000
1.000000
1.000000
1.000000
1.000000
1.000000
0.000554
0.006191
0.032979
0.112201
0.275606
0.524036
0.807624
1.043772
1.164600
1.157457
0.000554
0.006191
0.032979
0.112201
0.275606
0.524036
0.807624
1.043772
1.164600
1.157457
0.000554
0.006191
0.032979
0.112201
0.275606
0.524036
0.807624
1.043772
1.164600
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 le x.dat containing 1 followed by 49 zeros. It is shown also in
Fig. P7.20. The rst 10 impulse response samples computed by the three realizations are shown
below:
x(n)
1.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
0.000000
hdir (n)
0.000554
0.005637
0.026788
0.079222
0.163405
0.248430
0.283588
0.236148
0.120828
0.007142
hcan (n)
0.000554
0.005637
0.026788
0.079222
0.163405
0.248430
0.283588
0.236148
0.120828
0.007142
hcas (n)
0.000554
0.005637
0.026788
0.079222
0.163405
0.248430
0.283588
0.236148
0.120828
0.007142
The given lter is an example of a lowpass Butterworth lter 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 coefcients:
a
1.000000
3.166000
4.873631
4.465987
2.592519
0.941724
0.196860
0.018165
0.000000
124
b
0.000554
0.003881
0.011644
0.019407
0.019407
0.011644
0.003881
0.000554
0.000000
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 lter coefcient arrays. The last while loop performs the
actual ltering:
/* canfilt.c - IIR filtering in canonical form */
#include <stdlib.h>
#include <stdio.h>
#define MAX 64
double can();
void main(int argc, char **argv)
{
FILE *fpa, *fpb;
double *a, *b, *w, x, y;
int L, M, K, i;
int max = MAX, dmax = MAX;
coefcient les
coeffs., state, input, output
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, "Cant open filter file: %s\n", argv[1]);
exit(0);
}
if ((fpb = fopen(argv[2], "r")) == NULL) {
fprintf(stderr, "Cant 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));
K = (L <= M) ? M : L;
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));
}
Problem 7.15
An example of such program is given below. The program reads and allocates the lter coefcient
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 K3 matrix A. The last
while loop performs the actual ltering:
double cas();
void main(int argc, char **argv)
{
FILE *fpa, *fpb;
double **A, **B, **W, x, y;
double *a;
int M, K, i, j, m;
int max = MAX, dmax = MAX;
coefcient les
}
temporary coefcient array
allocation and increment
if (argc != 3) {
fprintf(stderr, "Usage: casfilt A.dat B.dat <x.dat >y.dat\n");
exit(0);
}
126
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 = caslt(B, A, x);
%
127
function y = casfilt(B, A, x)
[K, K1] = size(A);
[N1, N] = size(x);
W = zeros(K,3);
w0
w1
w2
w3
for n = 1:N,
[y(n), W] = cas(K, B, A, W, x(n));
end
=
=
=
=
H1 (z)= 0.70849
1 + z8
,
1 0.0625z8
H2 (z)= 0.98021
1 + z8
1 0.96z8
8
1 + 0.94z
1 0.98z8
The scale factors, were chosen such that the magnitude responses are unity at = 0 = 0.5/8,
that is,
|H1 (0 )| = |H2 (0 )| = 1
The following program implements 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:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
8;
8;
8;
8;
1.0
0.5
0.5
0.5
/* filter 1 */
/* filter 2 */
/* section 1 output */
"%.8lf\n",
"%.8lf\n",
"%.8lf\n",
"%.8lf\n",
/* section 2 output */
s);
x);
y1);
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 lters. The corresponding output signals y1 (n) and y2 (n) from H1 (z)
and H2 (z) are shown in Fig. P7.22.
The rst lter has a short time constant, but does not remove the noise component well. The
second lter has a longer time constant, but it removes the noise very well.
0.70849
0.98021
void main()
{
int n,
double
double
double
Problem 7.17
void delay();
Performing a partial fraction expansion on H1 (z) and H2 (z), we nd (where the PFE coefcients
are given with 5-digit accuracy):
N;
s, x, y1, x1, y2;
*w, *v, *u;
pi = 4*atan(1.0), w0, w1, w2, w3;
/
/
/
/
fprintf(fps,
fprintf(fpx,
fprintf(fpy1,
fprintf(fpy2,
}
#define G1
#define G2
pi
pi
pi
pi
A0
A1
A2
A3
*
*
*
*
Problem 7.16
#define
#define
#define
#define
0.50
0.75
1.00
3.00
/* filter 1 */
/* filter 2, section 1 */
/* filter 2, section 2 */
= fopen("s.dat", "w");
128
H1 (z) = 11.33584 +
H2 (z) = 1.02150
12.04433
1 0.0625z8
0.06191
0.02063
+
1 + 0.94z8
1 0.98z8
129
The impulse responses of the two lters 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
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();
h1 (n)
h2 (n)
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
0.70849
0
0
0
0
0
0
0
0.75277
0
0
0
0
0
0
0
0.04705
0.98021
0
0
0
0
0
0
0
0.07841
0
0
0
0
0
0
0
0.03489
130
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;
131
/* initialize */
A
= (double **) calloc(K, sizeof(double *));
B
= (double **) calloc(K, sizeof(double *));
W
= (double **) calloc(K, sizeof(double *));
P
= (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));
P[i] = W[i];
}
w0 s0
z-3
w3 s3
0.5
/* allocate */
-2
/* initialize */
p = s0
cdelay(3, w, & p)
The impulse response can be obtained by dividing out the numerator and writing
6 2z3
2
=4+
1 0.5z3
1 0.5z3
H(z)=
Expanding in powers of z3 , we have:
cas2can(K, A, a);
cas2can(K, B, b);
H(z)= 4 + 2 1 + (0.5)z3 + (0.5)2 z6 + (0.5)3 z9 +
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:
= [ 6 , 0 , 0 , 1 , 0 , 0 , 0 .5 , . . . ]
w0
w1
w2
w3
s0
s1
s2
s3
y = 6s 0 2 s 3
0
1
2
3
4
5
6
1
0
0
0
0
0
0
1
1
1
1
0
0
0
0
0
0
0.5
0.5
0.5
0.5
0
0
0
0
0
0
0.52
0
0
0
0
0
0
0
1
0
0
0.5
0
0
0. 5 2
0
1
0
0
0 .5
0
0
0
0
1
0
0
0 .5
0
0
0
0
1
0
0
0.5
6
0
0
1
0
0
0 .5
s0 (n)
s (n)
1
s(n)=
s2 (n)
s3 (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:
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
W(z)=
D(z)
X(z)=
133
1
X(z)
1 0.5z3
W(z)=
1
= 1 + (0.5)z3 + (0.5)2 z6 + (0.5)3 z9 +
1 0.5z3
w0
w1
w2
w3
s0
s1
s2
s3
y = 6 s 0 2s 3
0
1
2
3
4
5
6
1
2
3
0
0
0
0
1
1
1
1
1
1
1
0
0
0
0. 5
0. 5
0. 5
0. 5
0
0
3
3
3
3
0.25
0
2
2
2
2
1.5
1 .5
1
2
3
0.5
1
1.5
0.25
0
1
2
3
0 .5
1
1 .5
0
0
1
2
3
0.5
1
0
0
0
1
2
3
0.5
6
12
18
1
2
3
0 .5
The cascade realization, on the other hand, is more robust, in the sense that if we round its coefcients also to 2-digit accuracy, the lter will remain stable. Indeed, rounding the SOS coefcients
(P7.2) to 2-digits gives:
Problem 7.20
01 , a
02 ]= [1, 1.90, 0.99]
a0 = [1, a
11 , a
12 ]= [1, 1.61, 0.99]
a1 = [1, a
(P7.1)
(P7.2)
p1 = R1 e
j1
R0 = 0.9965,
0 = 0. 1
R1 = 0.9929,
1 = 0. 2
(P7.3)
a = [ 1, a
0 = 0.9950
0 = 0.0961
R
1
1 ej
1 = R
p
,
1 = 0.9950,
R
1 = 0.2000
(P7.8)
and their conjugates. They are both inside the unit circle, therefore, the lter remains stable. The
corresponding cascade transfer function will be:
p0 = R0 ej0 ,
(P7.7)
(P7.4)
cas (z)=
H
1
1
02 z2 1 + a
11 z1 + a
12 z2
01 z1 + a
1+a
(P7.9)
a0
a1
a = a(
0 a1
1
1
1+a
z1
2
+a
z2
3
+a
z3
4
+a
z4
(P7.5)
This lter is unstable. Indeed, its four poles, the roots of the denominator polynomial, are:
0
0 ej
0 = R
p
,
1 e
1 = R
p
1
j
0 = 1.0045,
R
1 = 0.9860,
R
0 = 0.1045
1 = 0.1989
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):
(P7.6)
and their conjugates. Thus, the p0 pole has moved outside the unit circle, rendering the lter
unstable. The seemingly benign replacement of a by the rounded
a has made the direct form
realization unusable. The impulse responses of the two lters (7.7.1) and (P7.5) are shown in
Fig. P7.25. The latter is blowing up exponentially.
The impulse response and the magnitude response of the cascaded lter (P7.9) are shown in
Fig. P7.26, together with the exact magnitude response. The magnitude responses are plotted in
dB, that is, 20 log10 |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 lter.
The sensitivity of the direct form and the robustness of the cascade form can be understood analytically in the following way. The zeros of a polynomial are indirect functions of the coefcients
134
135
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
dpi will be large even if the coefcient changes dai are small. The above sensitivity formulas
generalize easily [2,3,246] to the case of an order-M lter a = [1, a1 , a2 , . . . , aM ] with M zeros
p1 , p2 , . . . , pM :
dpi =
pi
pi
pi
da1 +
da2 + +
daM
a1
a2
aM
pMm
pi
= M i
am
(pi pj )
(P7.12)
j=1
ji
In the cascade realization, p0 is associated with the rst SOS and p1 with the second. The dependence of p0 on a0 and p1 on a1 is established through the identities
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 coefcients is
established via the polynomial identity:
1
1
)(1 p1 z1 )(1 p
)= 1 + a1 z1 + a2 z2 + a3 z3 + a4 z4
(1 p0 z1 )(1 p
1z
0z
A small change in the coefcients will induce a small change in the zeros p0 and p1 , that is,
a a + da
pi pi + dpi ,
i = 0, 1
To determine dp0 and dp1 in terms of da, we take differentials of both sides of the above polynomial identity to get:
1
1
dp0 z1 (1 p
)(1 p1 z1 )(1 p
)
0z
1z
(1 p0 z
(1 p0 z
)dp0 z
(1 p 1 z
)(1 p0 z
)dp1 z
)(1 p1 z
(1 p1 z
p0 da01 + da02
,
(p0 p
0)
dp1 =
p1 da11 + da12
(p1 p1 )
(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 (p0 p1 ); if p0 is near p1 , such factors cause large shifts in the
pole locations.
3
1
1
1
1
1
2
4
dp0 p
0 (1 p0 p0 )(1 p1 p0 )(1 p1 p0 )= da1 p0 + da2 p0 + da3 p0 + da4 p0
dp1 =
dp0 =
which is still an identity in z. Setting z = p0 will remove all but the rst term in the left-hand-side,
giving the relationship:
p31 da1
Using the above procedure of taking differentials of both sides and setting z = p0 in the rst and
z = p1 in the second, we obtain the induced changes in the poles due to small changes in the
coefcients of the sections:
a a = [0, da1 , da2 , da3 , da4 ]= [0, 0.002, 0.004, 0.004, 0.001]
da =
(p0 p
0 )(p0 p1 )(p0 p1 )
1
(1 p1 z1 )(1 p
) = 1 + a11 z1 + a12 z2
1z
Even though the sensitivity formulas (P7.10) and (P7.11) involve differential changes, we may
actually apply them to 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):
1
1
)(1 p1 z1 )dp
(1 p0 z1 )(1 p
0z
1z
dp0 =
1
(1 p0 z1 )(1 p
) = 1 + a01 z1 + a02 z2
0z
+
+ p1 da3 + da4
(p1 p
0 )(p1 p0 )(p1 p1 )
p21 da2
136
(P7.11)
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 rst 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
acas
1.00000000
5.56573395
13.05062482
16.49540451
11.84993647
4.58649943
0.74713457
1.00000000
5.56573000
13.05062000
16.49540000
11.84994000
4.58650000
0.74713000
1.00000000
5.56570000
13.05060000
16.49540000
11.84990000
4.58650000
0.74710000
1.00000000
5.56570000
13.05046030
16.49508213
11.84961490
4.58633537
0.74710016
relative error
3.2580107
1.6487106
1.9240105
full precision
magnitude
0.933557 j0.301259
0.923398 j0.215739
0.925911 j0.078311
0.980962
0.948265
0.929217
5-digit direct
magnitude
0.931610 j0.300414
0.927787 j0.216576
0.923469 j0.079185
0.978849
0.952730
0.926857
4-digit direct
magnitude
0.967208 j0.284105
0.888774 j0.266869
0.999999
0.853736
1.008071
0.927976
0.999999
0.853736
4-digit cascade
magnitude
0.933552 j0.301303
0.923396 j0.215719
0.925902 j0.078152
0.980971
0.948258
0.929194
(P7.14)
Table P7.2 Filter poles.
a a
da
=
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 lter, 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 lters, that is, the roots of the denomia1 , and
a2 .
nator polynomials a, 5- and 4-digit
a, and of the rounded SOS polynomials
a0 ,
For the 5-digit direct form, the lter 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 coefcients
a correspond
to an unstable lter. By contrast, the roots of the 4-digit quantized cascaded form
acas 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 lter based on a and the 4-digit-precision lter based
on
a, which is unstable.
The impulse responses of the 5-digit case and the 4-digit cascade case based on
acas 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 specications.
138
Fig. P7.27 Impulse responses of full-precision and 4-digit-precision lters. Problem 7.21.
Problem 7.22
See the solution of Problem 7.20.
Problem 7.23
See the solution of Problem 7.20.
139
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.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 = b0 x + v1
for i = 1, 2, . . . , M1 do:
vi = bi x ai v0 + vi+1
v M = b M x aM v0
Fig. P7.29 Magnitude responses of exact, 5-digit direct, and 4-digit cascade. Problem 7.21.
Problem 7.24
(P7.17)
b0 + b1 z1 + b2 z2 + b3 z3
H(z)=
1 + a1 z1 + a2 z2 + a3 z3
(P7.15)
Transposed realizations of FIR lters are obtained by the four transposition rules of exchanging
input with output, reversing all ows, replacing nodes by adders, and adders by nodes. These
rules can be applied to the canonical or direct realizations of IIR lters.
double transp(M, a, b, v, x)
double *a, *b, *v, x;
int M;
{
int i;
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), v2 (n), v3 (n). For indexing convenience,
we also introduce the quantity v0 (n) which is the overall output obtained at the top adder, that
is,
state updating
Its usage is the same as that of can or dir. The (M+1)-dimensional array v = [v0 , v1 , . . . , vM ]
must be declared and allocated in the main program, for example, by
140
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 lter in a nested form, which is similar to H
orners rule of evaluating a polynomial. For
example, the transfer function (P7.15) can be written as:
H = b0 + z1 (b1 a1 H)+z1 (b2 a2 H)+z1 (b3 a3 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 = b0 X + z1 (b1 X a1 Y)+z1 (b2 X a2 Y)+z1 (b3 X a3 Y)
The transposed form can 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:
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. (7.2.2).
Problem 7.26
if (M != L) {
fprintf(stderr, "coefficient vectors a,b must have same length");
exit(0);
}
The following program implements ltering 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
double transp();
void main(int argc, char **argv)
{
FILE *fpa, *fpb;
double *a, *b, *v, x, y;
int M, L, i;
int max = MAX, dmax = MAX;
Problem 7.27
coefcient les
H(z)=
9 4z2 + 4z4
3 4z1 + 2z2
3 + 4z1 + 2z2
=
2
1 0 . 4z + 0 . 5z
1 + 0.4z1 + 0.5z2
1 + 0.84z + 0.25z
The transpose of the canonical form is shown in Fig. P7.30. The I/O difference equations are:
if (argc != 3) {
142
143
v0 (n)
x(n)
y(n)= 9x(n)+v1 (n)
y(n)
v1 (n)
z-1
v1 (n + 1)= v2 (n)
v2(n)
-1
v3 (n + 1)= v4 (n)
-0.84
-4
v4 (n + 1)= 4x(n)0.25y(n)
v3(n)
z
for each input sample x do:
y = 9x + v 1
v1
v2
v3
v4
v4(n)
-1
= v2
= 4x 0.84y + v3
= v4
= 4x 0.25y
-0.25
x(n)
v00 (n)
v01 (n)
-4
v11 (n)
z-1
0.4
-0.4
v02(n)
v10 (n)
z-1
x1(n)
v12(n)
z-1
2
z-1
-0.5
-0.5
x(n)
e(n)
g(n)
z -1
H1(z)
f(n)
H2(z)
y(n)
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
ltering equations.
Consider case A, with signal names assigned as in Fig. P7.32 Then, the adder and ltering equations are in the time and z domains:
144
E(z) = X(z)+F(z)
f (n) = h2 (n)y(n)
G(z) = z1 E(z)
Y(z) = H1 (z)G(z)
F(z) = H2 (z)Y(z)
145
y(n)
e(n)
x(n)
Y(z)= z1 H1 (z)E(z)= z1 H1 (z) X(z)+F(z) = z1 H1 (z) X(z)+H2 (z)Y(z)
w(n)
w0
z-1
w1
0.5 w(n-1)
and
f1
f(n-1)
z-1
f0
0.4 v(n)
v0
z-1
v1
f(n)
z1 H1 (z)
H(z)=
1 z1 H1 (z)H2 (z)
-0.4 v(n-1)
Case B has the same transfer function H(z). Cases C and D have:
H(z)=
y(n)
0.4
H1 (z)
1 (z)H2 (z)
z1 H
computed.
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:
H1 (z)=
1 + z1
,
1 0.5z1
H1 (z)
=
H(z)=
1 H1 (z)H2 (z)
H2 (z)= z1
0.4(1 z1 )
1 0.4z1
1 + z1
1 0.5z1
0.4(1 z1 )z1
1 + z1
1
1
1 0.5z
1 0.4z1
which gives
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:
for each input sample x do:
v0 = 0.4v1 + y1
f = 0.4(v0 v1 )
e=x+f
w 0 = 0 .5 w 1 + e
y = w0 + w1
y1 = y
(update delays)
w1 = w0
v1 = v0
1 + 0.6z1 0.4z2
H(z)=
1 1.3z1 + 0.2z2 + 0.4z3
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)
e(n) = x(n)+f (n 1)
e = x + f1
w 0 = 0 . 5w 1 + e
y = w0 + w1
v 0 = 0. 4 v 1 + y
f0 = 0.4(v0 v1 )
(update delays)
f1 = f0
w1 = w 0
v1 = v 0
w(n)
w0
-1
z
w1
0.5 w(n-1)
y(n-1)
0.4 v(n)
f(n)
y(n)
v0
y1
z-1
z-1
v1
-0.4 v(n-1)
0.4
Notice how the extra delay factor z1 in H2 (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
Now, the start of the computational cycle is v(n)= 0.4v(n 1)+y(n 1), where both quantities
146
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.
Chapter 8 Problems
Problem 8.1
Problem 7.30
The lter G(z) can be implemented by the input/output sample processing algorithm of its
canonical form:
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:
w1 = y
where w1 is its internal state, that is, w1 (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 lter 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
w1 = u
y = v0 = x + u
delay(4, v)
y = u 0 = x + v2
v 0 = 0 .2 u 2 + 0 . 8 w 1
w 1 = v0
delay(2, v), delay(2, u)
(a)
(b)
v0
v0
z -4
G(z)
v4
v2
z -4
v4
z-2
z-2
v0 G(z)
v0
u0
G(z)
u2
w0 = x + w 3
y = w 1 + 2w 2
delay(3, w)
z-1
w1
z-1
z-1
w2
w3
w0
z-1
w1
z-1
v2
w0
v1
(c)
z1 + 2z2
1 z3
v0 = x
y = w0 = v 1 + 2 v 2 + w 3
delay(2, v)
delay(3, w)
z-1
x
The direct and canonical realizations are shown in Fig. P8.1. Their sample processing algorithms
are:
y = x + v4
v 0 = 0. 2 y + 0. 8 w 1
w 1 = v0
delay(4, v)
B(z)
1 z3
w2
z-1
w3
z-1
w0 = 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
v0 , v1 , v2 are the input impulse and its delays: (n), (n 1), (n 2). At each iteration, w0 is
replaced by the value of w3 and only then is the row of ws shifted to the right to give the values
of w1 , w2 , w3 of the next row. The w-columns are the successively delayed output signals y(n),
y(n 1), y(n 2), y(n 3):
148
149
x
n
v0
v1
v2
w0
w1
w2
w3
y = w0
0
1
2
3
4
5
6
7
8
1
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
1
2
0
1
2
0
1
2
0
0
1
2
0
1
2
0
1
0
0
0
1
2
0
1
2
0
0
0
0
0
1
2
0
1
2
0
1
2
0
1
2
0
1
2
v0
z-1
z-1
v4
z-1
z-1
-5
0
1
2
3
0
3
2
1
8
9
10
11
0
3
2
1
w0
0
0
0
0
w0
2
2
2
2
w1
w2
w3
0
0
0
0
0
0
2
2
0
1
1
1
0
1
2
0
4
5
6
7
0
3
2
1
w1
w2
w3
1
1
1
2
0
0
1
1
2
0
0
0
2
0
1
2
12
13
14
15
0
3
2
1
w0
1
1
1
1
w0
0
0
0
0
w1
w2
w3
0
0
0
1
2
2
0
0
1
2
2
2
1
2
0
1
w1
w2
w3
2
2
2
0
1
1
2
2
0
1
1
1
0
1
2
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 rst 3 initializing iterations.
Problem 8.2
Expanding the denominator in powers of z5 , 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:
v0 = x
w0 = v0 + 2v1 + 3v2 4v3 5v4 + w5
y = w0
delay(4, v)
delay(5, w)
w0 = x + w5
y = w 0 + 2w 1 + 3 w 2 4 w 3 5 w 4
delay(5, w)
The steady parts of the linear and circular buffer generation algorithms are:
repeat forever:
w0 = w5
delay(5, w)
w4
w5
z-1
w3
z-1
w4
z-1
z-1
-4
z-1
-5
-1
w5
The following table shows the initialization and steady parts of the linear buffer case:
v0
v1
v2
v3
v4
w0
w1
w2
w3
w4
w5
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
0
0
0
0
0
0
0
0
0
0
1
2
3
4
5
1
2
3
4
5
1
2
3
4
5
0
1
2
3
4
5
1
2
3
4
5
1
2
3
4
0
0
1
2
3
4
5
1
2
3
4
5
1
2
3
0
0
0
1
2
3
4
5
1
2
3
4
5
1
2
0
0
0
0
1
2
3
4
5
1
2
3
4
5
1
0
0
0
0
0
1
2
3
4
5
1
2
3
4
5
1
2
3
4
5
1
2
3
4
5
1
2
3
4
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 wq dened by
the circulating value of q:
0
1
2
3
4
5
0
5
4
3
2
1
w0
1
1
1
1
1
1
w1
0
0
0
0
0
1
w2
w3
0
0
0
0
5
5
0
0
0
4
4
4
repeat forever:
p = tap(5, w, p, 5)
cdelay(5, w, & p)
150
w2
-1
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 wq dened by
the circulating value of q:
w2
w3
z-1
w1
z-1
-4
w0
w1
v2
z-1
v1
v3
w0
151
w4
0
0
3
3
3
3
w5
0
2
2
2
2
2
y
1
2
3
4
5
1
Problem 8.3
n
6
7
7
9
10
11
0
5
4
3
2
1
12
13
14
15
16
17
0
5
4
3
2
1
18
19
20
21
22
23
0
5
4
3
2
1
24
25
26
27
28
29
0
5
4
3
2
1
w0
2
2
2
2
2
2
w0
3
3
3
3
3
3
w1
1
1
1
1
1
2
w1
2
2
2
2
2
3
w2
5
5
5
5
1
1
w2
1
1
1
1
2
2
w3
4
4
4
5
5
5
w3
5
5
5
1
1
1
w4
3
3
4
4
4
4
w4
4
4
5
5
5
5
w5
2
3
3
3
3
3
y
2
3
4
5
1
2
w5
3
4
4
4
4
4
3
4
5
1
2
3
w5
4
5
5
5
5
5
y
4
5
w5
5
1
y
5
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):
q0 = 0
q1 = q0 c =
2
8
8
32
8 =
=6
5
5
5
5
q2 = q1 c =
4
32
8
24
=
=4
5
5
5
5
q3 = q2 c =
1
24
8
16
=
=3
5
5
5
5
q4 = q3 c =
3
16
8
8
= =1
5
5
5
5
Fig. P8.3 shows the relative locations of the qs with respect to the circular buffer. The ve
q-arrows are now at relative angles = 2/5.
q4
30
31
32
33
34
35
0
5
4
3
2
1
w0
4
4
4
4
4
4
3
3
3
3
3
4
w0
5
5
5
5
5
5
w1
4
4
4
4
4
5
w0
1
1
1
1
1
1
w1
w1
5
5
5
5
5
1
w2
2
2
2
2
3
3
w2
3
3
3
3
4
4
w2
4
4
4
4
5
5
w3
1
1
1
2
2
2
w3
2
2
2
3
3
3
w3
3
3
3
4
4
4
w4
5
5
1
1
1
1
w4
1
1
2
2
2
2
w4
2
2
3
3
3
3
1
1
1
1
w5
1
2
2
2
2
2
q3 w
3
b5
1
2
3
4
1
2
3
4
5
y
1
2
3
4
5
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 rst 5 initializing iterations.
w2
b6
b7
w4 b 4
q 2 w5
b3
w1
b 0 w0
b2
w6
b1
w7
q1
[q0 , q1 , q2 , q3 , q4 ]= [0, 6, 4, 3, 1]
w[0], w[6], w[4], w[3], w[1] = [b0 , b2 , b4 , b5 , b7 ]
Up-truncation gives:
[q0 , q1 , q2 , q3 , q4 ]= [0, 7, 5, 4, 2]
w[0], w[7], w[5], w[4], w[2] = [b0 , b1 , b3 , b4 , b6 ]
Rounding to the nearest integer gives:
[q0 , q1 , q2 , q3 , q4 ]= [0, 6, 5, 3, 2]
w[0], w[6], w[5], w[3], w[2] = [b0 , b2 , b3 , b5 , b6 ]
For the linear interpolation case, we have the outputs:
152
q0
153
q4
q0 = 0
y0 = w[0]= b0
w3
b5
6 < q1 < 7
2
3
y1 = w[6]+(q1 6)(w[7]w[6])= b1 + b2
5
5
4 < q2 < 5
y2 = w[4]+(q2 4)(w[5]w[4])=
3 < q3 < 4
1
4
y3 = w[3]+(q3 3)(w[4]w[3])= b4 + b5
5
5
w5
1 < q4 < 2
y4 = w[1]+(q4 1)(w[2]w[1])=
3
2
b6 + b7
5
5
q2
q3
4
1
b3 + b4
5
5
(truncate down)
(truncate up)
(round)
(interpolation)
b7
w4 b 4
b3
w1
b 0 w0
b2
w6
q0
b1
w7
q1
Thus, depending on the output method, the following period-5 subsequences will be produced:
[b0 , b2 , b4 , b5 , b7 , b0 , b2 , b4 , b5 , b7 , . . . ]
[b0 , b1 , b3 , b4 , b6 , b0 , b1 , b3 , b4 , b6 , . . . ]
[b0 , b2 , b3 , b5 , b6 , b0 , b2 , b3 , b5 , b6 , . . . ]
[y0 , y1 , y2 , y3 , y4 , y0 , y1 , y2 , y3 , y4 , . . . ]
q5
w2
b6
[q0 , q1 , q2 , q3 , q4 , q5 ]= [0, 7, 5, 4, 3, 1]
w[0], w[7], w[5], w[4], w[3], w[1] = [b0 , b1 , b3 , b4 , b5 , b7 ]
Problem 8.4
q0 = 0
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):
q0 = 0
q1 = q 0 c =
y0 = w[0]= b0
6 < q1 < 7
y1 = w[6]+(q1 6)(w[7]w[6])=
2
1
b1 + b 2
3
3
5 < q2 < 6
y2 = w[5]+(q2 5)(w[6]w[5])=
1
2
b2 + b 3
3
3
2
20
4
4
8 =
=6
3
3
3
3
q3 = 4
y3 = w[4]= b4
q2 = q 1 c =
1
20
4
16
=
=5
3
3
3
3
2 < q4 < 3
y4 = w[2]+(q4 2)(w[3]w[2])=
2
1
b5 + b 6
3
3
q3 = q 2 c =
16
4
12
=
=4
3
3
3
1 < q5 < 2
y5 = w[1]+(q5 1)(w[2]w[1])=
1
2
b6 + b 7
3
3
q4 = q 3 c =
2
12
4
8
= =2
3
3
3
3
q5 = q 4 c =
1
4
4
8
= =1
3
3
3
3
Fig. P8.4 shows the relative locations of the qs 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 qs and corresponding buffer entries:
[q0 , q1 , q2 , q3 , q4 , q5 ]= [0, 6, 5, 4, 2, 1]
w[0], w[6], w[5], w[4], w[2], w[1] = [b0 , b2 , b3 , b4 , b6 , b7 ]
Up-truncation gives:
[q0 , q1 , q2 , q3 , q4 , q5 ]= [0, 7, 6, 4, 3, 2]
w[0], w[7], w[6], w[4], w[3], w[2] = [b0 , b1 , b2 , b4 , b5 , b6 ]
154
Thus, depending on the output method, the following period-5 subsequences will be produced:
[b0 , b2 , b3 , b4 , b6 , b7 , b0 , b2 , b3 , b4 , b6 , b7 , . . . ]
[b0 , b1 , b2 , b4 , b5 , b6 , b0 , b1 , b2 , b4 , b5 , b6 , . . . ]
[b0 , b1 , b3 , b4 , b5 , b7 , b0 , b1 , b3 , b4 , b5 , b7 , . . . ]
[y0 , y1 , y2 , y3 , y4 , y5 , y0 , y1 , y2 , y3 , y4 , y5 , . . . ]
(truncate down)
(truncate up)
(round)
(interpolate)
Problem 8.5
This problem is similar to Example 8.1.2. Referring to Fig. 8.1.14, we have for the cases of truncating down, up, and rounding:
[b0 , b3 , b6 , b0 , b3 , b6 , . . . ]= [1, 4, 7, 1, 4, 7, . . . ]
[b0 , b2 , b5 , b0 , b2 , b5 , . . . ]= [1, 3, 6, 1, 3, 6, . . . ]
[b0 , b3 , b5 , b0 , b3 , b5 , . . . ]= [1, 4, 6, 1, 4, 6, . . . ]
155
(truncate down)
(truncate up)
(round)
y0 = b0 = 1
y1 =
1
2
1
2
11
b2 + b3 = 3 + 4 =
= 3.667
3
3
3
3
3
y2 =
1
2
1
2
20
b5 + b6 = 6 + 7 =
= 6.667
3
3
3
3
3
Problem 8.6
A = atof(argv[1]);
c = atof(argv[2]);
D = atoi(argv[3]);
This problem is similar to Problem 8.3. Inserting the numerical values for the wavetable contents:
b = [b0 , b1 , b2 , b4 , b5 , b6 , b7 ]= [1, 2, 3, 4, 5, 6, 7, 8]
F = c / D;
[b0 , b2 , b4 , b5 , b7 , . . . ]= [1, 3, 4, 5, 7 . . . ]
[b0 , b1 , b3 , b4 , b6 , . . . ]= [1, 2, 3, 5, 7, . . . ]
[b0 , b2 , b3 , b5 , b6 , . . . ]= [1, 3, 4, 6, 7, . . . ]
[y0 , y1 , y2 , y3 , y4 , . . . ]= [1, 2.6, 4.2, 5.8, 7.4, . . . ]
(truncate down)
(truncate up)
(round)
(interpolation)
where
y0 = b 0 = 1
y1 =
2
3
2
3
b 1 + b 2 = 2 + 3 = 2 .6
5
5
5
5
y2 =
4
1
4
1
b 3 + b 4 = 4 + 5 = 4 .2
5
5
5
5
y3 =
1
4
1
1
b 4 + b 5 = 5 + 6 = 5 .8
5
5
5
5
y4 =
3
2
3
2
b 6 + b 7 = 7 + 8 = 7 .4
5
5
5
5
q1 = 0;
q2 = 0;
q3 = 0;
for (i=0; i<D; i++) {
w1[q1] = sine(D, i);
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);
}
Problem 8.7
An example program that exercises the wavetable routines is listed below. It generates three
wavetables: sinusoidal, square wave, and trapezoidal.
/* load wavetables */
/* might need the cast w1[(int)q1] */
Problem 8.8
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
Partial C code for this problem was given in the text, just before Figs. 8.1.20 and 8.1.21.
Problem 8.9
void gdelay2();
double wavgen();
double sine(), square(), trapez();
The zero patterns and magnitude responses |H()| of the four lters are shown in Fig. 8.9. The
rst lter has H(z)= 1 + z8 . Therefore, its zeros are the solutions of:
156
157
z8 = 1 = ej e2jk
zk = ej/8 ej2k/8 ,
k = 0, 1 , . . . , 7
That is, the 8th roots of unity rotated by /8 = 22.5 . The second lter has H(z)= 1 z8
and thus, its zeros are the 8th roots of unity.
/*
is not shown
|H()|
Typical output is shown in Fig. P8.6. For the recursive anger, we have the code fragment:
H(z) = 1 z8 + z16 =
1 + z24
1 + z8
H(z) = 1 + z8 + z16 =
1 z24
1 z8
The third has roots the 24th roots of unity shifted by /24 = 7.5o , but among them the roots
of the denominator 1 + z8 must be excluded. This results in 16 zeros. Similarly, the last lters
zeros are the 24th roots of unity with the 8th roots of unity excluded.
/* yd is y(n-d) */
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));
d2 =
D * (0.5 + ranl(Dran, u2, &q2, &iseed2));
a1 = 1 + ranl(Dran, u3, &q3, &iseed3);
a2 = 1 + ranl(Dran, u4, &q4, &iseed4);
x
= cos(2 * pi * F * n);
xd1 = tapi(D, w, p, d1);
xd2 = tapi(D, w, p, d2);
y = (x + a1 * xd1 + a2 * xd2) / 3;
*p = x;
cdelay(D, w, &p);
fprintf(fpx, "%lf\n", x);
/* u1 is 2-dim */
/* mean = D/2 */
/* mean = 1 */
/* input x(n) */
/* delay x(n-d1) */
/* output */
/* update delay */
/* declaration of fpx */
158
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
*/
Problem 8.12
A typical program is as follows:
Fig. P8.7 Recursive anger.
=
=
=
=
=
=
#define
#define
#define
#define
#define
#define
D1
D2
D3
D4
D5
D6
29
37
44
50
27
31
#define
#define
#define
#define
#define
#define
a1
a2
a3
a4
a5
a6
.75
.75
.75
.75
.75
.75
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
use D=20, Ntot=100
if (n<=5)
x=n;
else if (n<=10)
x = 10-n;
else
x=0;
160
161
p2 = w2;
Problem 8.14
where Bi = Ai pi /(pi ej ), as shown in Problem 6.29. It follows that the response to a delayed
sinusoid will be:
if(n==0)
x = 1;
else
x = 0;
plain(D1,
plain(D2,
plain(D3,
plain(D4,
D+
1
Bi pnL
u(n L)
i
i=1
Multiplying both sides by the factor ejL and subtracting from the undelayed result, we nd that
the response to the nite sinusoid:
=
=
=
=
Bi pni u(n)
i=1
y1
y2
y3
y4
D+
1
impulse
x(n)= ejn u(n)u(n L)
is
w1,
w2,
w3,
w4,
&p1,
&p2,
&p3,
&p4,
a1,
a2,
a3,
a4,
x);
x);
x);
x);
Problem 8.13
1
D+
Bi pni u(n)ejL pL
y(n)= H()ejn u(n)u(n L) +
i u(n L)
i=1
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>
v0 = sD a1 v1
u = b 0 v0 + b 1 v 1
v1 = v0
y =x+u
p = y
cdelay(D, w, & p)
162
a0
w,
pi
L,
= 0.75;
x, y1, y2, sD;
= 4*atan(1.0);
N, M=1, n;
163
end
end
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
L
N
w
=
=
=
=
w1
p1
w2
p2
atoi(argv[1]);
atoi(argv[2]);
atoi(argv[3]);
atof(argv[4]);
=
=
=
=
Then, the following MATLAB function calculates the residues Bi 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)));
in units of pi
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:
The analytical expression for y(n) can be obtained as follows. Using the MATLAB function
lprevb.m given below, we determine the poles pi and residues Ai 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)]
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
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
% a=[1,
a(2)]
164
165
double x, y;
int D, Ntot, M=1, n;
long iseed;
y(n) = cx(n)+bw(n D)
FILE *fpy;
w0
wD
z -D
D
= atoi(argv[1]);
Ntot = atoi(argv[2]);
iseed = atol(argv[2]);
initialize
y = cx + bwD
w0 = awD + x
delay(D, w)
p = w;
for (n=0; n<Ntot; n++) {
y = lowpass(D, w, &p, M, a, b, v, 0.0);
fprintf(fpy, "%.16lf\n", y);
}
}
y = cx + bsD
p = asD + x
cdelay(D, w, & p)
x=0
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 = fs /D.
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)
double *w, **p, a, x;
int D;
{
double y;
usage: y=plaindel(D,w,&p,a,x);
p is passed by address
return y;
}
Problem 8.17
A block diagram realization is given in Fig. P8.9. The difference equations are the system:
166
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);
**p = x + can(M, a, M, b, v, y);
cdelay(D, w, p);
return y;
}
The routines differ from plain and lowpass in that the lter outputs are taken after the delay
zD , instead of before.
Problem 8.19
/*
/*
/* plain */
/* lowpass */
y = b0 * x + b1 * x1 + b2 * x2;
/* output */
return y;
Typical output is shown in Fig. P8.11 and is obtained by the code segment:
/*
/*
/*
/*
/*
/*
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;
p2 = w2;
Problem 8.20
The sample processing routine is as follows. It can easily be generalized to more than two multitap delay segments:
168
Problem 8.21
From the pole equation, we have:
169
/* p passed by reference */
where
HLL (z) = cL +
HLR (z) =
HRL (z) =
D(z)
1
D(z)
HRR (z) = cR +
1 zR GR (z) bL zL
D(z)
dR bR zL zR
dL bL zR zL
D(z)
1 zL GL (z) bR zR
with
D(z)= 1 zR GR (z) 1 zL GL (z) dL dR zL zR
For the special case when the cross couplings are dL = 0 and dR = 0, we have:
D(z)= 1 zR GR (z) 1 zL GL (z)
(P8.1)
If a pole had |z| 1, then using the inequality |a1 | + |a2 | < 1, we would have:
|z|D1 +D2 |z|D2 > |a1 ||z|D2 + |a2 ||z|D2 |a1 ||z|D2 + |a2 |
which contradicts Eq. (P8.1). Thus, all poles must have |z| < 1.
HLL (z) = cL +
HLR (z) = 0
HRL (z) =
Problem 8.22
Working in the z-domain and denoting by WL (z) and WR (z) the inputs to the delays zL and
zR , the outputs of these delays will be zL WL (z) and zR WR (z). Thus, the I/O equations of
the block diagram will be:
dL bL zL zR
1 zL GL (z)
1 zR GR (z)
HRR (z) = cR +
bR zR
1 zR GR (z)
YR (z) = cR XR (z)+z
WR (z) = z
WR (z)
WL (z)
WL (z)= zL YL (z)cL XL (z) ,
WR (z)= zR YR (z)cR XR (z)
Inserting them into the second and fourth, we get the system:
YL (z)cL XL (z) dR zL YR (z)cR XR (z) = bL zL XL (z)
1 zR GR (z) YR (z)cR XR (z) dL zR YL (z)cL XL (z) = bR zR XR (z)
bL zL
1 zL GL (z)
1 zL GL (z)
which means that the left channel responds only to the left input (it does not receive any crossfeedback 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, dL = dR = 0, then the left
and right channels decouple completely, responding independently to their respective inputs. For
the case GL (z)= aL , GR (z)= aR , the sample processing algorithm is straightforward. Denote
the left and right delay-line buffers by
wL = [wL0 , wL1 , . . . , wLL ]= (L+1)-dimensional
wR = [wR0 , wR1 , . . . , wRR ]= (R+1)-dimensional
Let pL and pR be the circular pointers circulating over them, and let the corresponding delay
outputs be sL and sR . Then, the computational sample processing algorithm will be:
170
171
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
pL = wL;
pR = wR;
/* use xR = 0 */
Figures P8.12 and P8.13 show typical outputs. The left output does not start until n = L, therefore, the rst 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.
/* use N = 600 */
/* generate input */
/* use w0 = 0.15 * pi */
c = a * c1 + (1-a) * fabs(x);
c1 = c;
/* control signal */
/* update delay */
Problem 8.24
g = f(rho, c/c0);
/* gain function */
if (L > 1)
G = fir(L-1, h, v, g);
else
G = g;
/* no smoothing */
y = G * x;
/* compressor output */
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;
172
/* L-point smoother */
173
/* gain smoothing */
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 */
The compressing action takes place only above the threshold. For an expander, the gain function
is dened 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.27
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.
H(z)=
Ai
i=1
1 pi z1
hn =
Problem 8.26
Ai pni u(n)
i=1
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:
y = E[y(n) ]=
2
h20 x2
h21 x2
+ h n x = x
2
n
n=0
174
hm
i=1
i=1
i=1
)M
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.
175
Problem 8.28
For ideal lter shapes, the NRR is computed most conveniently using its frequency response
denition:
NRR =
y2v
v2
|H()|2
d
2
For a bandpass lter, H() is non-zero only over the interval a || b , where it is unity.
Thus,
NRR =
y2v
v2
a
b
d
+
1
2
b
a
b a
d
=
1
2
s2n+1 = s2n +
n+1
(xn mx )2 s2n
initialized with s20 = 0. The following program will calculate the input and output signals and
the experimental mean-square values. Any discrepancies are due to the lter transients and they
disappear with increasing L:
/* smoothex.c - filtering with 1st order smoother */
#include <stdio.h>
#include <math.h>
Problem 8.29
double gran();
if (argc != 4) {
puts("\nUsage: smoothex a iseed L");
exit(0);
}
if (argc != 2) {
fprintf(stderr, "usage: smooth1 a <x.dat >y.dat\n");
exit(0);
}
a = atof(argv[1]);
iseed = atol(argv[2]);
L = atoi(argv[3]);
a = atof(argv[1]);
fprintf(stderr, "%lf\n", a);
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 lter. Indeed, taking means of both sides of
Problem 8.31
my = amy + (1 a)mx
m y = mx
sn =
2
n1
1
(xk mx )
The requirement that the high-frequency signal s(1)n go through unchanged is that the lter
have unity gain at = or z = 1. This requires the value for the constant b:
b
b
=1
=
1 az1 z=1
1+a
k=0
176
177
b=1+a
Thus the lter transfer function and impulse response will be:
H(z)=
1+a
,
1 az1
NRR =
g2n = min,
subject to
n=0
N
1
gn = 1
n=0
whose solution was found in Example 8.3.4 to be gn = 1/N, n = 0, 1, . . . , N 1. Thus, the solution
of the highpass problem will be:
1+a
h(n) = (1 + a)
=
NRR =
2
1
a
1a
n=0
2
N
1
Thus, the NRR is magnied if 0 < a < 1. This can be understood in the frequency domain by the
Fig. P8.16.
hn = (1)n gn =
(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:
( 1+a
1- a (
J=
N
1
N
1
h2n + 2 1
hn (1)n
n=0
n=0
J
= 2hn 2(1)n = 0,
hn
1
0
|H(0)|2 =
1+a
1a
hn (1)n =
n=0
N
1
(1)2n = N = 1
n=0
Problem 8.33
Expand the transfer function into partial fractions:
2
,
n = 0, 1, . . . , N 1
|H()|2 = 1
H(z)=
A
A
G
=
+
1 p z1
(1 pz1 )(1 p z1 )
1 pz1
where
Problem 8.32
A=
H()=
N
1
hn ejn
NRR =
hn (1)n = 1
where we used the fact ejn = (1)n . Thus, the NRR must be minimized subject to this AC
condition:
NRR =
h2n = min,
h2n =
n=0
n=0
N
1
subject to
N
1
hn (1)n = 1
This can be solved by Lagrange multipliers or more simply by dening the quantities gn =
hn (1)n . Because g2n = h2n , the problem reduces to the following minimization problem:
178
n0
n=0
which sums up to
NRR =
n=0
n=0
Gp
jGej0
=
p p
2 sin 0
hn = Apn + a pn ,
n=0
H()=
G
1 p /p
A2
2|A|2
A2
+
+
2
2
1p
1p
1 |p|2
Inserting p = Rej0 , and A as given above, and replacing G2 by its normalized value G2 =
(1 R)2 1 2R cos(20 )+R2 gives the desired expression for NRR after some tedious algebra.
179
Problem 8.34
For the rst lter, we nd the transfer function:
0.0730(1 z2 )
1 1.7633z1 + 0.8541z2
H(z)=
Its pole radius is R =
a2 =
neff =
ln(0.05)
= 38
ln(R)
Its NRR can be computed by carrying out a partial fraction expansion of the form:
H(z)= B +
A
1 pz1
A
1 p z1
hn = Bn + Ap un + A p
un
h2n = B2 +
n=0
= B2 +
(Apn + A pn )2
n=1
n=1
= B2 +
A 2 p2
1 p2
A2 p2
2|A|2 |p|2
+
1 p2
1 |p|2
B=
G
,
|p|2
A=
G(1 p2 )
p2 |p|2
The numerical value of NRR is NRR = 1/13.4. For the second lter, we start with neff from which
we may solve for
R = (0.05)1/neff = 0.9901
where R is related to the 3-dB width by:
R 2 = a 2 = 2b 1 =
1 tan(/2)
1 + tan(/2)
H(z)=
0.0099(1 z2 )
1 1.8833z1 + 0.9802z2
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.85955z1 + z2
1 1.80289z1 + 0.93906z2
Its 1% time constant is neff = 146. For Q = 60, the lter is identical to that of Example 8.3.8.
Figures P8.19P8.21 show the input signal, lter responses, and output signals.
180
Problem 8.36
The designed lter has the form:
181
H(z)= b
1 zD
1 azD
neff = D
ln
ln a
where = 0.01 for the 1% time constant. The lter parameters are in the four cases:
neff
80
200
400
800
0.961481
0.984414
0.992177
0.996081
0.980741
0.992207
0.996088
0.998040
1172.4
2931.6
5863.7
11727.8
Problem 8.37
The following MATLAB m-le designs the 60 Hz notch lter, generates the noisy ECG and lters
it, and computes the lters magnitude response:
182
183
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-le designs the 60 Hz comb lter, generates the noisy ECG and lters
it, and computes the lters magnitude response:
Fig. P8.25 Filtered s(n) for Q = 400 and Q = 800. Problem 8.36.
fs = 600;
f0 = 60;
df = 0.75;
w0 = 2 * pi * f0 / fs;
dw = 2 * pi * df / fs;
% D=10 here
B = b * [1 0 0 0 0 0 0 0 0 0 -1];
A = [1 0 0 0 0 0 0 0 0 0 -a];
% numerator
% denominator
%
% assume 2 beats/sec => 0.5 sec/beat => 500 samples/beat => 1000 samples/sec
% f0=60; Q=60; df=f0/Q;
%
x0 = ecg(600);
x = [x0, x0];
x = sgfilt(0, 9, x);
m = max(x); x = x/m;
n = 0:1199;
% replicate three beats x=[x0,x0,x0] and smooth them with x=sglt(0, 5, x);
v0 = [1 1 1 1 1 -1 -1 -1 -1 -1];
v = v0;
184
for k=1:119,
v = [v, v0];
end
v = 2 + v;
xv = x + 0.5 * v;
yv = filter(B, A, xv);
% noisy ECG
w = (0:500)*pi/500; z = exp(-i*w);
h = abs(b * (1 - z.^10) ./ (1 - a * z.^10));
185
Problem 8.39
H(z)= b
B
1 + zD
=A+
= (A + B)+BazD + Bz2 z2D +
1 azD
1 azD
D
= atoi(argv[1]);
N
= atoi(argv[2]);
iseed = atol(argv[3]);
where
1
B=b 1+
,
a
b
A= ,
a
period
number of periods
initial seed
A+B=b
lter output
noise-free input
noisy input
h2n = b2 + B2
n=0
a 2m = b 2 + B 2
m=1
1 a2
b2 (1 a2 )+b2 a2 (1 + a2 )
2b2 (1 + a)
2(1 a)2 (1 + a)
=
=
1 a2
1 a2
4(1 a)(1 + a)
1a
2
generate N periods
for (i=0; i<N; i++)
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);
}
D
4
= (1 - tan(D*dw/4)) / (1 + tan(D*dw/4));
= (1 - a) / 2;
2
=
=
1
2 1
2Q
Problem 8.40
/* -------------------------------------------------------- */
The following program designs the comb lter, constructs 40 periods of length-50 of the noisy
triangular waveform, and lters them using the circular buffer implementation of the canonical
realization of the lter:
/* combex.c - IIR comb filter with noisy periodic input */
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
if (argc != 4) {
186
187
Problem 8.41
The complementarity properties may be veried for each pair. For example, for lter 2, we have
half-order M = 8/2 = 4. Thus, we must verify:
1
1
(1 + z2 )2 (1 + 6z2 z4 )+ (1 z2 )4 = z4
16
16
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);
}
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 fs /2 = 2fsc = 7.159 MHz, so that the subcarrier frequency shown in
the gure is only one-quarter of the Nyquist interval.
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));
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[qD ]. At each time instant, the content of w[q] is updated by
w[q]= w[qD ]+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 efcient in hardware implementations and for large values of D.
qD
w0
w1
w2
w3
s0
s1
s2
s0
s0
s0
s2
s1
s1
s0
s1
s2
s0
2s0
2s1
2s0
2s1
2s0
s2
s2
s2
s1
s1
2s 2
2s0 /4
s0
s1
s2
2s1
2s0
3s 0
2s 2
3s0 /4
2s1
3s1
3s 0
2s 2
3s1 /4
3s2
3s1
3s 0
2s 2
3s2 /4
3s2
3s1
3s 0
4s 0
3s2
3s1
4s 1
4s 0
3s2
4s2
4s 1
4s 0
s0
s1
s2
4s2
4s 1
4s 0
1
2
3
4
5
Problem 8.43
The following is a complete C program for 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:
y = w q /4
7
8
s0 /4
s1 /4
s2 /4
2s1 /4
2s2 /4
11
#include <stdio.h>
#include <stdlib.h>
s0
s1
s2
12
void cdelay();
double tap();
9
10
188
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 les y.dat and s.dat will
contain the averaged periods and the noise-free period:
/* sigavex.c - signal averaging example */
Problem 8.45
The following MATLAB function generates the noisy ECG and smoothes it once and twice by
Savitzky-Golay lter of length N and smoothing order d:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
x0 = ecg(L);
x = sgfilt(0, 15, x0);
mx = max(x);
x = x/mx;
period
number of periods
noise seed
% generate ECG
% unity max
% generate noise
xv = x + v;
N=11; d=2;
y1 = sgfilt(d, N, xv);
y2 = sgfilt(d, N, y2);
The ltering twice through the SG lter improves the smoothing operation but introduces longer
transients in the lters. The following gures should be compared with the single-pass cases of
Figs. 8.3.33 and 8.3.34.
accumulate N periods
each of length D
noisy input
D-th tap of averager
accumulate x
update delay line
save input sample
190
191
Chapter 9 Problems
Problem 9.1
Use the formula TR = LT = L/fs to solve for L = fs TR , 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 = fs /N = 8000/256 =
31.25 Hz. If the DFT is done directly, we would require L N = 1024 256 = 262144 multiplications. 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, N log2 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
Fig. P8.29 Double SG ltering; N = 11, 41 and d = 2.
The sinusoidal signal is something like x(t)= cos(2f t), where f = 10 kHz. Its spectrum will
have peaks at f . 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, 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=
40
fs
=
= 8 samples
f
5
N = kD = k
fs
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,
Fig. P8.30 Double SG ltering; N = 11, 41 and d = 4.
fk = k
fs
=f
N
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:
192
193
Problem 9.4
where
18
f
k = N = 16
= 36
fs
8
Because k is greater than N 1 = 15, it may be reduced mod-N down to:
%
% X = dtft(x, w);
%
% x = row vector of time samples
% w = row vector of frequencies in rads/sample
k = 36 2 16 = 4
It corresponds to the DFT frequency fk = kfs /N = 4 8/16 = 2 kHz. This is frequency within
the Nyquist interval that is aliased with f = 18 kHz; indeed, we have
%
% based on and replaces both dtft.c and dtftr.c
function X = dtft(x, w)
[L1, L] = size(x);
z = exp(-j*w);
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
fs
f
L
fs
f
or, in our case, L 8000/20 = 400 samples. 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, 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;
n = 0:(L-1);
wh = 0.54 - 0.46 * cos(2*pi*n/(L-1));
% Hamming window
% windowed data
xrec.dat
xham.dat
frec.dat
fham.dat
xrec
xham
Xrec
Xham
% frequency range
/ascii;
/ascii;
/ascii;
/ascii;
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));
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();
194
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 le
printf("enter L, N: ");
scanf("%d %d", &L, &N);
x = (double *) calloc(L, sizeof(double));
X = (complex *) calloc(N, sizeof(complex));
N-point DFT
Problem 9.9
See Example 9.2.1.
Problem 9.10
Using the relationship k = Nf /f s, we calculate the group-A and group-B DFT indices:
group A
group B
Problem 9.12
Acting on x by the 48 DFT matrix, we obtain:
group B:
kB = 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 kA and
N kB .)
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.
X(0)
X(1)
X=
X(2)
X(3)
j
1
j
1
=
1
1
1
1
1
j
1
j
1
1
1
1
j
1
j
1
1
1
1
j
1
j
1
2
2
1
2
1
1
2
X(0)
X(1)
X=
X(2)
X(3)
j
1
j
1
=
1
1
1
1
1
197
12
j
3 0
=
1
3
0
j
3
0
196
12
0
0
0
Problem 9.15
'(0)
x
x
'(1)
x
'=
x
'(2)
'(3)
x
j
1
j
1 1
=
4 1
12
j
0 3
=
1 0 3
j
0
3
Figure P9.3 shows the procedure. The (4N)-dimensional time data vector is shufed once into
two (2N)-dimensional subvectors by putting every other one of its entries on top and the remaining entries on the bottom. Then, each of the (2N)-dimensional vectors is shufed again into two
N-dimensional subvectors.
Problem 9.13
shuffling
x=
5
1
3
1
5
1
3
1
8FFT
N-FFT
16
X=
8
16
2N
2N
N
N-FFT
N W2N
4N
4N
It follows that the FFT spectrum will show peaks at the frequencies:
DFT merging
N-FFT
N
k
2N W4N
2N
N
X(4 )= 8
N-FFT
N W2Nk
Problem 9.14
Fig. P9.3 Performing large FFTs.
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
8FFT
16
8
0
8
16
8
0
8
x=
2
1
0
1
2
1
0
1
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 rst into
(2N)-point DFTs and then into the desired (4N)-point DFT. The rst merging stage require multiplication by the twiddle factors W2kN , k = 0, 1, . . . , N 1. The second stage uses the factors
W4kN , k = 0, 1, . . . , 2N 1. The buttery 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 rst
merging stage, and a (4N)-fold multiplication for the second stage:
1
cost = 4 N log2 N + 2N + 2N = 2N log2 N + 4N
2
x(n) =
7
1
1 j1 n
X(k)ejk n =
4e
4jej2 n + 4ej3 n + 4ej5 n + 4jej6 n + 4ej7 n
8 k=0
8
1 j2 n
1
1
1 j2 n
1
1
= ej1 n +
e
e
+ ej3 n + ej3 n
+ ej1 n
2j
2
2
2j
2
2
1 =
= ,
8
4
2 2
2 =
= ,
8
2
2 3
3
3 =
=
8
4
198
If the (4N)-point FFT could be done in one pass, we would have cost:
cost =
1
(4N)log2 (4N)= 2N log2 (4N)
2
It is easily veried 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
Problem 9.18
Consider the length-7 signal
= [2, 1, 1, 1],
x
[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 ] .
x
= [4, 6, 6, 9, 5, 3, 2],
h
= [ 9, 9 , 8, 9 ] .
and, nally, reduce that modulo 4 to get y
Problem 9.19
Using the nite geometric series and the denition WN = e2j/N , gives
Problem 9.17
N1
1
x=
4
2
4
6
4
2
4
6
X=
8FFT
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
kn
WN
=
n=0
Nk
1 1 WN
1 1 e2jk
=
k
N 1 WN
N 1 e2jk/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 denition 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:
p
p
WpN = e2j/(pN) = e2j/N = WN
The DTFT of a length-L signal and its N-point and (pN)-point DFTs are:
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, rst reduce the signal modulo 4 to
get
8
8
4
4FFT
16j
X=
x
24
8
12
16j
X()=
Noting that for an 8-point FFT, 0 = 0, 2 = /2, 4 = , and 6 = 3/2 /2, and using
Eulers formula we obtain:
n
x(n)= 1 + 4 sin(
)+3 cos(n)
2
which agrees with the given x, for n = 0, 1, , 7.
200
x(n)ejn
n=0
XN (k)=
L
1
kn
x(n)WN
n=0
XpN (k)=
L
1
kn
x(n)WpN
n=0
Putting the above 8-point FFT into the 8-point inverse FFT formula gives
7
1 j0 n
1
x(n)=
X(k)ejk n =
8e
16jej2 n + 24ej4 n + 16jej6 n
8 k=0
8
L
1
XpN (pk)=
L
1
pkn
x(n)WpN =
n=0
L
1
kn
x(n)WN
= XN (k)
n=0
Problem 9.21
This follows from the results of Problem 9.20 by setting N = 8 and p = 2, which implies:
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
Problem 9.24
Using a trig identity to write the product of sines as a sum of sines, we get the equivalent expression:
1 jn/2
8e
+ 8e3jn/2 + 16ejn/8 + 16e15jn/8
16
where, we shifted the negative frequency exponents by adding 2n to them, e.g., replaced n/8
by 2n n/8 = 15n/8. Now, comparing with the 16-point IDFT formula
x(n)=
8FFT
X(1)= 16,
X(4)= 8,
X(12)= 8,
X(15)= 16,
or,
The same DFT values can be determined without any computation by comparing x(n) with the
inverse DFT. Using Eulers formula, setting 4 = , 2 = /2, 6 = (/2)mod(2), and
multiplying and dividing by 8, we get:
15
1
X(k)ejk n
16 k=0
1
8jej2 n + 8ej4 n + 8jej6 n
8
Problem 9.25
Arguing in a similar fashion, we nd the (non-zero) values of the 32-point DFT:
X(2)= 32,
X(8)= 16,
X(24)= 16,
X(30)= 32
Comparing with the 8-point IDFT, gives the above DFT vector:
x(n)=
7
1
X(k)ejk n
8 k=0
Problem 9.26
Write x(n) in its complex sinusoidal form:
Problem 9.23
Using Eulers formula, we write:
x(n) = 1 + 2 sin(
n
4
)2 sin(
n
2
)+2 sin(
3n
)+3(1)n
4
1 j0 n
8e
8jej1 n + 8jej2 n 8jej3 n + 24ej4 n + 8jej5 n 8jej6 n + 8jej7 n
8
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
(P9.1)
where
W()=
sin(8) 15j/2
1 e16j
e
=
1 ej
sin(/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 frequencies. Taking every other 16-DFT point gives the 8-point DFT. The peak values are correctly
identied by the 16- and 8-point DFTs because the peak frequencies coincide with DFT frequencies.
203
|X()| = DTFT
= 16-point DFT
= 8-point DFT
24
Problem 9.29
First, compute the ordinary linear convolution:
16
y = h x = [ 2 , 1 , 2 , 2 , 2, 1, 2 ]
Problem 9.30
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 coefcients:
= [4, 4, 7, 1, 8, 7, 11, 2, 4, 2, 1, 1, 0, 1, 3]
and wrap it mod-8 to get
= [ 8, 6 , 8 , 2, 8 , 6 , 8 , 2 ]
y
Then, compute the FFTs of the two signals:
Problem 9.27
We will show that the product AA is proportional to the identity matrix. The ij-th matrix element
of the product is:
(AA )ij =
N
1
Ain A
nj =
n=0
N
1
jn
in
WN
WN
n=0
N
1
(ij)n
WN
n=0
1
where we used the fact that WN
= WN
. 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
(ij)n
WN
2
1
1
1
2
1
1
1
8FFT
10
0
2
0
2
0
2
0
2
3
8FFT
AA = NI
where I is the N N identity matrix.
Problem 9.28
10
0
2
0
2
0
2
0
40
0
0
8j 16j
0
0
12
24
0
0
8j 16j
0
X X
204
2j
2j
8
2
8FFT
205
8j
12
8j
0
= N(i j)
n=0
AA = A A = NIN ,
Problem 9.31
Problem 9.33
x = [ 6 , 1 , 0 , 1 , 6 , 1, 0 , 1 ]
b. Using x(n)=
N1
1
x(n)=
X(k)= A(k)+jB(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)ejk n ,
k=0
X(k) = A(k)+jB(k)
n
1
16 + 12ejn/2 + 8ejn + 12ejn/2 = 2 + 3 cos
+ (1)n
8
2
X(N k) = A(k)jB(k)
which can be solved for A(k) and B(k).
x = [6 a, 1 b, 0, 1, 6, 1, 0, 1, a, b]
Problem 9.32
Start with
A(k)=
N
1
Problem 9.34
The expressions for G(k) and H(k) follow from the results of Problem 9.33, except that the dimension of the FFTs is N/2. The nal expressions that construct X(k) are the standard Buttery
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
k
). Thus the total number of multiplications using this method
and 2j, and multiplications by WN
compared to a direct N-point FFT will be
3N
N
1N
log2 ( )+
2 = 1 + 2.5
2 2
2
1
2
log2 N
N log2 N
2
kn
WN
a(n)
n=0
and evaluate it at N k
A(N k)=
N
1
(Nk)n
WN
a(n)
If one takes into account the multiplications required for computing the Wk powers, then the
total becomes
n=0
N
Noting that WN
= 1, it can be written as
A(N k)=
N
1
kn
WN
a(n)
4N
)+
2
2 = 1 + 1 .5
N log2 N
2
log2 N
log2 (
n=0
Problem 9.35
A(k) =
N
1
kn
WN
a(n)
/* fftreal.c - FFT of a real-valued signal */
n=0
But,
kn
WN
kn
WN
Thus,
#include <math.h>
#include <cmplx.h>
#include <stdlib.h>
void fft();
206
void fftreal(N, x, X)
int N;
double *x;
complex *X;
{
int n, k, Nhalf=N/2;
double pi=4*atan(1.0);
time data
FFT array
207
Problem 9.37
In the denition of y, the reversed signal xR is delayed by N samples, that is, we have
N zeros
W = cexp(cmplx(0.0, -2*pi/N));
N zeros
Thus, using linear superposition, the delay property of z-transforms, and the results of Problem
9.36, we have in the z-domain:
where the factor zN represents the delay of xR by N samples. Replacing z by zk = ejk , and
using the result z2kN = 1, we get
fft(Nhalf, Y);
Wk = Wk
Yk = Y(k )= X(k )+ejk X(k )= ejk /2 ejk /2 X(k )+ejk /2 X(k )
= 2ejk /2 Re ejk /2 X(k )
where we used the hermitian property X()= X() . The quantity under the real part is
now:
G(k)
H(k)
Wk H(k)
next Wk = Wk+1
G(k) + Wk H(k)
G(k) Wk H(k)
N
1
xn ejk n =
N
1
xn ejk (n+1/2)
n=0
n=0
N
1
xn cos k (n + 1/2) = Ck
Re ejk /2 X(k ) =
n=0
Problem 9.36
It follows that
X(z)= x0 + x1 z
XR (z)= x3 + x2 z
Yk = 2ejk /2 Ck = 2ejk/2N Ck
+ x2 z
+ x1 z
+ x3 z
+ x0 z3
Because Yk is the (2N)-point DFT of a real-valued signal, it will satisfy the hermitian property
Y2Nk = Yk . In terms of Ck , we have:
It follows that
x(n) X(z)
Yk = 2ejk/2N Ck
Equating the right-hand sides and canceling the common factors gives the symmetry property
C2Nk = Ck ,
x(n) X(z1 )
k = 0, 1, . . . , 2N 1
(N1)k
k
X(k)= WN
X(N k)
1
where in the last step, we used X(z
k )= X(k )= X(k)= X(N k) by the periodicity of the
N-point DFT.
208
yn =
2N1
1
Yk ejk n ,
2N k=0
n = 0, 1, . . . , 2N 1
But the rst N samples of yn are precisely xn . Replacing Yk in terms of Ck gives for n =
0, 1, . . . , N 1:
xn =
2N1
2N1
1
1
2ejk /2 Ck ejk n =
Ck ejk (n+1/2)
2N k=0
N k=0
209
xn =
C0 +
N
1
2N
1
Ck ejk (n+1/2) +
k=1
Ck ejk (n+1/2)
Xi (z)= zi X0 (z),
Setting z = zk = e
k=N+1
jk
Ck ejk (n+1/2) =
N
1
N
1
m=1
jm (n+1/2)
m=1
Thus, the inverse DFT becomes (changing the summation from m back to k):
xn =
1
C0 +
N
1
N
1
Ck ejk (n+1/2) +
k=1
Ck ejk (n+1/2)
k=1
xn =
C0 + 2
N
1
Ck cos k (n + 1/2)
k=1
Using the convolution table, perform the ordinary linear convolution of the given signal and lter
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 overlapping by M = 3 points, as shown below:
By denition, we have
X2N (k)=
L
1
x(n)W2nk
N
X2N (2k)=
n=0
But,
k = 0, 1, 2 , 3
Problem 9.41
x=
Problem 9.38
nk
W22N
i = 1, 2 , 3 , 4
X1 (z) = x0 + x1 z1 + x2 z2 + x3 z3 + x4 z4 + x5 z5 + x6 z6 + x7 z7
C2Nm e
ik
Xi (zk )= zi
k X0 (zk )= W5 X0 (zk ),
Consider, for example, the rst and the third. Their z-transforms are
N
1
= W5 , we obtain
Problem 9.40
m=1
k=N+1
i = 1, 2 , 3 , 4
nk
x(n)W22N
n=0
L
1
L
1
nk
x(n)W22N
=
n=0
L
1
nk
WN
.
Thus,
n=0
Reducing these mod-8 and ignoring their rst M = 3 points (indicated by x), we obtain:
0 = [x, x, x, 0, 2, 0, 2, 0]
y
Problem 9.39
1 = [x, x, x, 2, 0, 2, 1, 0]
y
Observe that the ve 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
x4
x3
x2
x1
210
0
0
x4
x3
x2
0
0
0
x4
x3
0
0
0
0
x4
0
0
0
0
0
2 = [x, x, x, 1, 0, 1, 0, 1]
y
3 = [x, x, x, 0, 1, 0, 1, 0]
y
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 rst M points, the answer is correct.
211
Problem 9.42
At fs = 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 nd:
x(n)=
1
{ 0 , 0 . 5 , 1 , 0 .5 , 0 , 0 .5 , 1 , 0 .5 }
4
fast
=
slow
According to Eq. (9.7.4), the aliased coefcients 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=
4
0
0 .5
1
0.5
0
0.5
1
0.5
DFT
This is to be compared with the cost of L(M + 1) of linear convolution of the entire input array
with the lter (here, we treat these MACs as complex-valued.) Thus, the relative cost of the fast
versus slow convolution will be:
j(2 + 2)
j(
2
2
)
1
,
X=
0
4
j(2 2)
j(2 + 2)
b=
4
(2 + 2)/8j
0
(2 2)/8j
0
(2 2)/8j
0
(2 + 2)/8j
It can be veried easily that xal 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:
(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
NM
LN(1 + log2 N)
NM
212
#include <stdio.h>
#include <cmplx.h>
#include <stdlib.h>
calloc(), realloc()
#define MAX 64
2+ 2
2 2
sin(2t)
sin(6t)
16
16
L = (N M)K
Problem 9.44
LN(1 + log2 N)
N(1 + log2 N)
NM
=
L(M + 1)
(N M)(M + 1)
lter le
x = length-N block
N-point DFTs
if (argc != 3) {
fprintf(stderr, "usage: fastconv hfile N < xfile
exit(0);
}
> yfile\n");
preliminary allocation
M = lter order
if (N <= 2*M) {
fprintf(stderr, "must have N > 2M = %d", 2*M);
exit(0);
}
213
else
h
= (double *) realloc((char *) h, (M+1) * sizeof(double));
x
= (double *) calloc(N, sizeof(double));
head/tail of input block
xhead = (double *) calloc(M, sizeof(double));
H = (complex *) calloc(N, sizeof(complex));
X = (complex *) calloc(N, sizeof(complex));
Y = (complex *) calloc(N, sizeof(complex));
for (n=0; n<N; n++)
if (n <= M)
H[n] = cmplx(h[n], 0.0);
else
H[n] = cmplx(0.0, 0.0);
complexify(N, x, X);
circonv(N, H, X, Y);
fft(N, H);
for (;;) {
for (n=0; n<M; n++)
x[n] = xhead[n];
x[i] = 0;
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)
int N;
complex *H, *X, *Y;
{
int k;
complexify(N, x, X);
X = cmplx(x, 0)
circonv(N, H, X, Y);
done by fft
fft(N, X);
ifft(N, Y);
lastblocks:
}
n = index where EOF occurred
complexify(N, x, X);
circonv(N, H, X, Y);
for (i=M; i<N; i++)
printf("%lf\n", real(Y[i]));
if (n <= N-M) exit(0);
214
215
Chapter 10 Problems
Problem 10.2
Problem 10.1
For the bandpass example, we use the fact that D()= 1 over the passband a || b to
get:
b
d
d
+
=
D()ejk
2
2
b
a
a
b
b
ejk
ejk
d
d
+
=
ejk
+
2
2
2jk
2jk
a
a
Start with
D()=
d(k) =
d(k)ejk
k=
and assume that d(k) is real and even in k. Taking conjugates and replacing by , gives
D() =
d(k)ejk
k=
d(k)ejk = D()
D()=
d(k)ejk =
k=
a
b
ejk
d
=
2
d(k)ej(k) =
k=
jb k
2jk
d(k)ej()k = D()
d(k)ej(k) =
k=
d(k)=
k=1
k=
d(k)ejk = d(0)+
k=
D()= d(0)+2
d(k)ejk +
d(k)ejk
d(k)=
d(k)sin(k)
k=1
ejk
d(k)=
d
=
2
=
2
k
jejk
d
2
sin(c k)
c cos(c k)
sin(c k)
k
k2
d(k)=
cos(k)
sin(k)
k2
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)
(1)k
k
216
(symmetric case)
(antisymmetric case)
k=1
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()ejk
where the -integration gave the standard lowpass lter. Performing the differentiation, we get
the required expression for d(k):
k=1
D()= 2j
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.)
k=1
d(k)cos(k)
sin(a k)
Problem 10.3
d(k)=
In the symmetric case, we set d(k)= d(k) and combine the two sums with Eulers formula to
get:
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(k)ejk +
sin(k) sin(b k)
The rst 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)ej()k = D()
Setting a = 0, gives the lowpass case, and b = the highpass one. In the latter, we have:
D()= d(0)+
sin(b k) sin(a k)
2jk
For the differentiator and Hilbert transformer, see the more general cases of Problem 10.3.
which states that D() is both real and even in . In the antisymmetric case, we have d(k)=
d(k), and therefore
k=
ja k
d(k)= (k)
d(k)ejk =
jb k
k=
D()ejk
ja k
D()=
k=
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()ejk
217
(differentiator)
Problem 10.4
d(k)=
a
b
ejk
d
+
2
ejk
d
2
or,
d(k)=
sin(b k) sin(a k)
d
=
e2 (k)=
d2 (k)
2
k=
|k|>M
|E()|2
EM =
2
|D()D()|
d
=
d2 (k)
2
|k|>M
The right-hand side sum can be written with the help of Parsevals identity applied to D() itself:
b cos(b k)
a cos(a k)
sin(b k)
sin(a k)
+
d(k)=
k
k2
k
k2
d2 (k)=
|k|>M
d2 (k)
d2 (k)=
|k|M
k=
|D()|2
M
d
d(k)2
2
k=M
In the limit as M , the second term in the right-hand side tends to the Parseval limit, thus
canceling the rst term and resulting in EM 0.
Problem 10.5
For the rst-order differentiator, we have impulse response, transfer function, and frequency
response:
h = [ 1 , 1]
H(z)= 1 z
H()= 1 e
Problem 10.7
From Problem 10.3, we have d(k)= (1)k /k, k = 0, for the differentiator lter. Using Parsevals
identity we have
NRR =
h20
h21
=1+1=2
H()= 1 e
1 (1 j)= j
c
c
|D()|2
d
=
2
c
c
|j|2
d
=
2
d
2
=
2
3
1
1
=2
2
2
k
k
k=1
d2 (k)=
k=0
k=
Thus,
3
d
= c
2
3
Thus, it increases rapidly with c . Compared to the full-band maximum NRR obtained with
c = , we have NRRmax = 3 /3 = 2 /3 and therefore,
NRR
=
NRRmax
|D()|2
for small
For the ideal lowpass differentiator case, the NRR can be computed as:
NRR =
k=
Thus, the noise power doubles at the output. To see how closely it resembles the ideal differentiator, we expand the frequency response at low frequencies:
j
d2 (k)=
1
2
=
2
k
3
k=1
2
1
=
2
k
6
k=1
d(k)=
1 cos(k)
1 (1)k
k = 0
Thus, d(k) is nonzero only for odd k, and is in this case d(k)= 2/k. Parsevals identity applied
to this lter gives:
Problem 10.6
Let E()= D()D()
be the error in the designed lter. Then, we have
E()= D()D()=
d(k)ejk
k=
d(k)ejk =
k=M
k=
d(k)ejk
|k|>M
e(k)=
d(k)
218
if |k| M
if |k| > M
|D()|2
d
=
2
|jsign()|2
because the coefcients d(k) cancel for |k| M. Thus, the time-domain coefcients of the error
are:
d2 (k)=
k=
d2 (k)= 2
k=1
k=odd
Thus, we obtain
219
2 k2
d
=
2
d
=1
2
k=1
k=odd
2 k2
=1
k=1
k=odd
k2
1/z0*
z0
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
k2
2
8
z0*
1/z0
2
24
Problem 10.8
The sinusoidal response of D() in its steady-state form is:
jn
D()e
jn
= jsign()e
jn
1)=
D(
cos(n)
1
jsign()ejn + jsign()ejn = sign()sin(n)
2
Similarly, because sin(n)= [ejn ejn ]/2j, we have for the outputs:
D
sin(n)
1
jsign()ejn jsign()ejn = sign()cos(n)
2j
d(k)(1)k = 0
k=M
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 antisymmetry property and splitting the sum in two parts, we get:
M
D()=
d(k)ejk =
k=M
M
d(k) ejk ejk = 2j
d(k)sin(k)
k=1
k=1
vanishes.
Setting = 0, , corresponding to z = 1, we have sin(k)= 0, and therefore, D()
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.9
Problem 10.10
From the denition of D(z)
, we have:
D(z)=
d(k)zk
1 )=
D(z
k=M
d(k)zk =
k=M
d(k)zk
k=M
1 )=
D(z
d(k)zk = D(z)
From the reality of d(k), it follows that the zeros will come in conjugate pairs if they are complex.
Thus, if z0 is a complex zero, then z
0 is also a zero. From the symmetry or antisymmetry
properties, it follows that if z0 is a zero, then
1
D(z
0 )= D(z0 )= 0
z 0 z0
If z0 lies on the unit circle then because 1/z0 = z0 , the only other distinct zero is the complex
conjugate.
220
z
0 = 0.5 0.5j,
z0
= 1 j,
z
0
=1+j
H(z)= 1(0.5+0.5j)z1 1(0.50.5j)z1 1(1j)z1 1(1+j)z1 = 13z1 +4.5z2 3z3 +z4
In the time domain, we get the length-5 symmetric (about its middle) impulse response:
k=M
z0 = 0.5 + 0.5j,
h = [ 1 , 3 , 4. 5 , 3 , 1]
In the antisymmetric case, we have in addition two zeros at z = 1 contributing a factor (1 z2 )
to the transfer function. Thus,
221
The frequency response in the symmetric case is obtained by factoring out a factor of z2 and
using Eulers formula:
H(z)= z2 z2 + z2 3(z + z1 )+4.5
H()= 2e
2j
Problem 10.14
The transition width is inversely related to the lter length N:
cos(2)3 cos()+4.5
f =
Dfs
N1
H(z)= z3 (z3 z3 )3(z2 z2 )+3.5(z z1 )
f =
H()= 2je3j sin(3)3 sin(2)+3.5 sin()
5.017 10
Dfs
= 0.2007 kHz
=
N1
251 1
Problem 10.15
The windows width factor is D = 5.017 as in the previous problem. Thus,
Problem 10.11
f =
Proceeding as in the previous problem, we nd the transfer function of the symmetric case:
h = [1, 0, 4.25, 0, 1]
H(z)= (1z
)(1+4.25z
+z
Conversely, if f = 2 kHz, then we may solve for the D-factor and attenuation A:
D=
)= 1+3.25z
3.25z
Dfs
5.017 44.1
=
= 1.729 kHz
N1
129 1
A 7.95
f
= (N 1)
= 5.805
14.36
fs
Problem 10.12
We use the rst-order Taylor series approximation:
ln(1 x) x
Apass = 20 log10
1 + pass
1 pass
ln(1 x)
= 0.4343 x
ln(10)
D=
A 7.95
f
= (N 1)
= 3.6281
14.36
4f s
Problem 10.16
Problem 10.13
First, we calculate pass and stop from Eq. (10.2.5):
pass =
100.1/20 1
= 0.0058,
100.1/20 + 1
D=
A 7.95
= 5.017
14.36
The transition width is f = fstop fpass = 2 1.5 = 0.5 kHz; therefore, the lter length will be:
N =1+
5.017 10
Dfs
= 101.34
=1+
0. 5
f
222
Assuming that an N-tap lter requires approximately N instructions for processing each input
sample, the maximum lter length will correspond to the maximum number of instructions that
t within the sampling interval T, that is,
Nmax =
T
finstr
=
Tinstr
fs
Inserting this into the Kaiser design formula, we nd the minimum width (where we used N
instead of N 1 in the denominator):
2
f =
Dfs
Dfs
=
N
finstr
N = 103
223
Problem 10.17
Problem 10.20
Using N = finstr /fs for the maximum lter length, we obtain the maximum width parameter D
and attenuation A:
Use the design MATLAB routine kdiff, with fs = 2 so that = 2f /2 = f , that is, the f s are
the s in units of . The lter lengths depend only on the values of f and A, they are:
D=
A 7.95
f
finstr f
=N
=
= Finstr F
2
14.36
fs
fs
A = 14.36Finstr 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 corresponding frequency responses over NF equally spaced frequencies over the right half of the
Nyquist interval [0, ] with the help of the function dtft.m:
N
33
75
63
147
% cutoff frequency
% lter length
NF = 200;
omega = (0:NF-1) * pi / NF;
% Hamming window
H = dtft(h, omega);
NF = 200;
omega = (0:NF-1) * pi / NF;
A
30
60
30
60
For example, in the case c = 0.4, = 0.05, A = 60 dB, we have the MATLAB code:
wc = 0.3 * pi;
N = 81;
% windowed lter
f
0.10
0.10
0.05
0.05
% frequency response
Problem 10.19
As an example, the following MATLAB program segment computes the bandpass lter of Example
10.2.2 (alternative design):
fs = 20;
fpa = 4; fpb = 6; fsa = 3; fsb = 8;
Apass = 0.1; Astop = 80;
in dB
in kHz
NF = 200;
omega = (0:NF-1) * pi / NF;
H = dtft(h, omega);
in dB
% s = 1 for highpass
in kHz
NF = 200;
omega = (0:NF-1) * pi / NF;
H = dtft(h, omega);
224
225
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
Problem 10.23
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:
The following MATLAB segment computes the Kaiser and Hamming spectra in dB. The Kaiser
window parameters are determined by the function kparm2.m:
% Kaiser differentiator
[B,
F =
G =
g =
S] = sg(3, N);
S * S;
S * F^(-1);
G(:,2);
% units of fs
% amplitudes
% Kaiser parameters
% sidelobe level in dB
n = (0:L-1);
% frequency responses
Problem 10.22
Use the design MATLAB routine khilb, with fs = 2 so that = 2f /2 = f , that is, the f s are
the s in units of . The lter lengths depend only on the values of f and A, they are the
226
xk = kwind(alpha, L) .* x;
NF = 256;
omega = (0:NF-1) * pi / NF;
Xk = abs(dtft(xk, omega));
Xkmax = max(Xk);
Xk = 20 * log10(Xk / Xkmax);
% DTFT spectrum
% normalized and in dB
Xh = abs(dtft(xh, omega));
227
Xhmax = max(Xh);
Xh = 20 * log10(Xh / Xhmax);
228
229
Chapter 11 Problems
Problem 11.4
Problem 11.1
The analog transfer function and magnitude response squared are in the general boost or cut
case:
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 fs /4
in Hz. This range covers most practical applications. This condition implies that the poles are
complex conjugate and have radius
R2 =
1
1+
R=
ln
ln R
+
R=
G20
N(g, gB )= g2
1 + g2
,
2
gB = g ,
2
1 z2
1 2 cos 0 z1 + z2
+ (1 b)
1 2b cos 0 z1 + (2b 1)z2
1 2b cos 0 z1 + (2b 1)z2
For the magnitude responses squared we may use the equivalent analog expressions to get:
(2 20 )2
2 2
+
=1
(2 20 )2 +2 2 (2 20 )2 +2 2
G
,
G0
gB =
GB
G0
(2 20 )2 +N(g, gB )2 2
(2 20 )2 +D(g, gB )2 2
g2B 1
,
g2 g2B
D(g, gB )=
g2B 1
g2 g2B
For the arithmetic, geometric, and harmonic mean choices for g2B the functions N and D simplify
as follows:
g2B =
g=
1
1
1
(1 )(1 ) 1 1
1+
2
2
2
For the 3-dB case, the parameter b is the same for both lters. Adding the two transfer functions,
we recognize that the two numerators add up to become the denominator:
where
Then, we may express the magnitude squared response in the following form that explicitly shows
the gains:
Problem 11.3
,
,
- 2
- 2
2
2
. GB G0 . GB G0
2
2
2
2
2
G GB
G GB
,
- 2
- g 1
= . 2B
,
g g2B
(2 20 )2 +g2 2 2
,
(2 20 )2 +2 2
|H()|2 = G20
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).
G20 (2 20 )2 +G2 2 2
(2 20 )2 +2 2
where the last step denes the parameter , which does not depend on the gains. Normalizing
everything to the reference gain G0 , we have
= tan
Then, expanding R to rst-order in and thus to rst-order in , we have:
|H()|2 =
|H()| =
For small values of , we may use the rst-order Taylor expansion tan(x) x to write approximately:
= (1 + 20 ) = (1 + 20 )tan
Problem 11.2
G0 (s2 + 20 )+Gs
s2 + s + 20
where
1
1+
(If > 1, which happens when /2 < , then there are two real poles.) It follows that the
-level time constant will be
neff =
H(s)=
g2B =
2g 2
1 + g2
N(g, gB )= g2 ,
N(g, gB )= g ,
N(g, gB )= 1 ,
D(g, gB )= 1 ,
D(g, gB )=
D(g, gB )=
(arithmetic)
g2
(geometric)
(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 = 10A/20 . Thus, the substitution g g1
changes a boost into an equal and opposite cut, and vice versa. Even though the boost and
=1
cut gains are equal and opposite, the bandwidth levels g2B may be dened arbitrarily in the two
1
cases. However, if we take them also to be related by the substitution gB g
B , then we can
show that the boost and cut lters are inverses to each other. Indeed, under the substitutions
1
{g, gB } {g1 , g
B }, the boost and cut magnitude responses are:
(2 20 )2 +N(g, gB )2 2
,
(2 20 )2 +D(g, gB )2 2
1
2 2
(2 20 )2 +N(g1 , g
B )
1
2 2
)
(2 20 )2 +D(g1 , g
B
Under this substitution, the functions N and D interchange roles, that is, one can show easily
that
1
N(g1 , g
B )= D(g, gB ) ,
230
231
1
D(g1 , g
B )= N(g, gB )
(2 20 )2 +N(g, gB )2 2
,
(2 20 )2 +D(g, gB )2 2
(2 20 )2 +D(g, gB )2 2
(2 20 )2 +N(g, gB )2 2
Hence, their product will be identically equal to G40 . The geometric-mean and weighted geometric1
mean choices for g2B are special cases of the substitution {g, gB } {g1 , g
B }, and therefore,
satisfy the desired property. But, any other choice of gB will do, as long as one denes the boost
1
bandwidth to be gB and the cut bandwidth, g
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:
s2 + 20 + s N(g, gB )
,
Hboost (s)= G0 2
s + 20 + s D(g, gB )
h1
h2
h3
h4
=
=
=
=
filter(b1,
filter(b2,
filter(b3,
filter(b4,
a1,
a2,
a3,
a4,
w = (0:199)*pi/200;
H1 = dtft(b1, w) ./
H2 = dtft(b2, w) ./
H3 = dtft(b3, w) ./
H4 = dtft(b4, w) ./
x);
x);
x);
x);
dtft(a1,
dtft(a2,
dtft(a3,
dtft(a4,
impulse responses
w);
w);
w);
w);
argH1
argH2
argH3
argH4
=
=
=
=
angle(H1)
angle(H2)
angle(H3)
angle(H4)
*
*
*
*
180
180
180
180
/
/
/
/
pi;
pi;
pi;
pi;
Figure P11.1 shows the phase responses. Note the rapid variations in the vicinities of the center
1
frequencies.
s2 + 20 + s N(g1 , g
s2 + 20 + s D(g,
gB )
B )
= G0 2
Hcut (s)= G0
1
s + 20 + s N(g, gB )
)
s2 + 20 + s D(g1 , g
B
which implies for the analog and the bilinearly transformed digital transfer functions:
Hcut (s)=
G20
Hboost (s)
Hcut (z)=
G20
Hboost (z)
Problem 11.5
The following MATLAB code segment designs the three lters (two peaking and one complementary notch), computes their impulse responses, and their magnitude responses:
w0 = 0.35*pi; Dw = 0.1*pi;
in rads/sample
unit impulse
impulse responses
Problem 11.7
The following MATLAB function lheq.m implements the design of both the lowpass and highpass
shelving lters (the parameter s = 1 selects the two cases):
w = (0:199)*pi/200;
H1 = abs(dtft(b1, w) ./ dtft(a1, w)).^2;
H2 = abs(dtft(b2, w) ./ dtft(a2, w)).^2;
H3 = abs(dtft(b3, w) ./ dtft(a3, w)).^2;
magnitude responses
%
% [b, a, beta] = lheq(s, G0, G, Gc, wc)
%
% s = 1, 1 = lowpass, highpass
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 rst four lters of Example 11.4.1 and
computes their impulse response, frequency, and phase responses (in degrees):
[b1,
[b2,
[b3,
[b4,
a1,
a2,
a3,
a4,
beta1]
beta2]
beta3]
beta4]
=
=
=
=
parmeq(1,
parmeq(1,
parmeq(1,
parmeq(1,
10^(9/20),
10^(9/20),
10^(-9/20),
10^(-9/20),
10^(6/20),
10^(3/20),
10^(-6/20),
10^(-3/20),
0.35*pi,
0.35*pi,
0.60*pi,
0.60*pi,
0.1*pi);
0.1*pi);
0.2*pi);
0.2*pi);
232
The lters 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
lowpass cases
highpass cases
omega = (0:199)*pi/200;
Problem 11.8
The following MATLAB code generates the rst pair of comb and notch lters 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 rst lter in two ways: (a) using MATLABs function
filter and (b) the customized function combfilt.m that uses a circular buffer:
D = 10;
wc = 0.025 * pi;
s0
s0 = x + asD
y = bs0 csD
p = s0
cdelay(D, w, & p)
num1
den1
H1
magH1
angH1
=
=
=
=
=
numerator coefcients
num2
den2
H2
magH2
angH2
=
=
=
=
=
z-D
sD
a
-c
denominator coefcients
frequency response
magnitude response
phase response in degrees
void cdelay();
double tap();
double combfilt(a, b, c, D, w, p, x)
double a, b, c, *w, **p, x;
int D;
{
double s0, sD, y;
sD = tap(D, w, *p, D);
s0 = x + a * sD;
y = b * s0 - c * sD;
**p = s0;
cdelay(D, w, p);
w = zeros(1, D+1);
q = 0;
for n=0:199,
[y1(n+1), w, q] = combfilt(a1, b1, c1, D, w, q, x(n+1));
end
return y;
note: h1=y1
b czD
algorithm of the transfer function H(z)=
are given below:
1 azD
234
235
pass
stop
2N
< 10 log (1 + 2 )= Apass
10
pass
sD = tap2(D, w, q, D);
s0 = x + a * sD;
y = b * s0 - c * sD;
w(q+1) = s0;
q = cdelay2(D, q);
Problem 11.11
The call to the MATLAB function lhbutt.m:
It uses the following routine tap2.m that helps extract the components of the circular internal
state vector:
0.5001
B = 0.3821
0.2765
%
% si = tap2(D, w, q, i)
%
% w = (D + 1)-dimensional
% q = circular index into w
0.5001
2 0.3821
2 0.2765
0.3821 ,
0.2765
A= 1
1
0.0002
0.0007
0.0005
0.5279
0.1056
% delay amount i = 0, 1, . . . , D
% based on tap2.c
H(z)=
function si = tap2(D, w, q, i)
0.5001(1 + z1 )
0.3821(1 + z1 )2
0.2765(1 + z1 )2
1 + 0.0002z1
1 + 0.0007z1 + 0.5279z2 1 + 0.0005z1 + 0.1056z2
si = w(rem(q+i, D+1)+1);
Problem 11.9
In the FIR case of designing a lowpass lter, the limits 1 pass and stop represent the ripples
. These translate to the limits for the magnitude
of the (real-valued) frequency response D()
response 1 pass in the passband and [0, stop ] in the stopband.
In the IIR case, the denitions are motivated by the closed-form expressions of the magnitude
response squared in the Butterworth and Chebyshev cases.
where Astop is the actual stopband attenuation realized by the designed lter, and f0 is the 3dB cutoff frequency. The apparent discrepancy between the computed 3-dB frequency and the
given 3-dB passband specication is accounted for from the fact that the 3-dB frequency 0 or
f0 is dened 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
Problem 11.10
Because stop > pass , and N Nexact , we have the inequality
stop
pass
2N
>
stop
pass
2Nexact
=
2stop
2pass
1 + 2pass
stop
pass
stop = tan
2N
> 1 + 2stop
2N
stop
> 10 log (1 + 2 )= Astop
10
stop
pass
pass
stop
2N
<
pass
stop
2Nexact
=
2pass
2stop
1 + 2stop
pass
stop
2N
< 1 + 2pass
236
= tan
fpass
fs
fstop
fs
= tan
10
= tan(0.25)= 1
40
= tan
pass = 10Apass /10 1 = 103/10 1 = 0.9976,
15
40
= tan(0.375)= 2.4142
stop = 10Astop /10 1 = 1035/10 1 = 56.2252
ln(56.2252/0.9976)
= 4.57 ,
ln(2.4142/1.0000)
N=5
Then, we calculate the 3-dB Butterworth parameter 0 and invert it to get the 3-dB frequency f0 :
0 =
= tan
Nexact =
stop
pass
pass
/N
1pass
(0.9976)1/5
= 1.0005 ,
237
f0 =
fs
arctan(0 )= 1.0030 kHz
Problem 11.14
The coefcients 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
coefcients of all the sections will not be exactly zero. The Butterworth angles are computed by
i =
2N
(N 1 + 2i)=
(4 + 2i),
10
i = 1, 2
which gives
1 = 0.6,
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.
2 = 0 . 8
Problem 11.12
Problem 11.15
Here, the Butterworth lter order is given to be N = 3. Thus, there remains only the parameter
0 to be xed. The normalized passband frequencies are
B=
0.3414
0.2454
2 0.3414
2 0.2454
0.3414
0.2454
A=
1
1
0.0817
0.0587
0.4471
0.0404
pa =
2fpa
fs
2 2
= 0.2,
20
c=
0.3414(1 z1 )2
0.2454(1 z1 )2
H(z)=
sin(pa + pb )
sin pa + sin pb
pass =
where Astop is the actual stopband attenuation realized by the designed lter, and f0 is the 3-dB
cutoff frequency in kHz. The required closed-form expression for part (c) is:
1+
cot(/2)
z2 2cz + 1
(z2 2cz + 1)(z2 1)+(z2 2cz + 1)(z2 1)
z2 2cz + 1
1
+
=
(s + s )=
2(z2 1)
2(z2 1)
2(z2 1)(z2 1)
2
1 =
2N
1.3764
= 1.9543
0.34931/3
(N 1 + 2)=
2
3
cos 1 = 0.5
a02 = 0.3230
a11 = 0,
a12 = 0.8325,
a13 = 0,
a14 = 0.4230
a01 = 0,
G1 = 0.5639,
Therefore, the sign of Re s is the same as the sign of the factor (|z|2 1), and the desired result
follows.
238
/N
1pass
G0 = 0.6615,
pass
The coefcients of the second- and fourth-order digital lter sections are calculated from Eqs. (11.6.43)
and (11.6.41), where the there is only one Butterworth angle, namely,
= cot pb = 1.3764
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:
sin pb
=0
pass = 10Apass /10 1 = 100.5/10 1 = 0.3493
2N
0 =
2 8
= 0 .8
20
Problem 11.13
Re s =
1 + z2
1 z2
s=
fs
|H()|2 =
2fpb
Because they add up to , the bilinear transformation parameter c will be zero, as follows from
the equation
pb =
H(z)=
0.5639(1 z2 )2
0.6615(1 z2 )
2
1 0.8325z2 + 0.4230z4
1 0.3230z
The 3-dB frequencies are calculated from Eq. (11.6.44) with c = 0. We nd:
239
Problem 11.16
Problem 11.18
Matching the stopband specications exactly means that the stopband frequencies sa , sb map
onto stop and that at stop the attenuation is exactly Astop . The rst requirement implies
We have:
1
s2
s
12
cos i + 2
0
0
=
20
20 2s0 cos i + s2
20 2
1 z1
1 + z1
20
0 cos i +
1 z1
1 + z1
20 (1 + z1 )2
2
1
2
0 (1 + z ) 2(1 z1 )(1 + z1 )0 cos i + (1 z1 )2
20 (1 + z1 )2
= 2
0 (1 + 2z1 + z2 )2(1 z2 )0 cos i + (1 2z1 + z2 )
=
20 (1 + z1 )2
Gi (1 + z1 )2
=
1 + ai1 z1 + ai2 z2
(1 20 cos i + 20 )+2(20 1)z1 + (1 + 20 cos i + 20 )z2
c=
pa =
sin 0b =
2 tan(0b /2)
1 + tan2 (0b /2)
The above equation reduces to the quadratic equation in the variable t = tan(0b /2):
1 t2
1 + t2 =
0
2t
1+
c cos pb
sin pb
(1 + c)t2 20 t (1 c)= 0
N = Nexact ,
0 =
stop
/N
1stop
where the equation for 0 matches the stopband specication exactly. The digital lter coefcients 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:
0 +
20
% design parameters:
+ (1 c)(1 + c)
% P = [Wpass, Wstop, Wpa, Wpb, c, fc, epass, estop, Nex, N, Apass, W0, f0a, f0b];
1+c
f0b
fs
ln(stop /pass )
ln(stop /pass )
t2
t=
pb =
= tan
c cos pa
,
sin pa
Ideally, we would like have pb = pass and pa = pass . But this is impossible because c has
already been xed. Because the Butterworth magnitude response is a monotonically decreasing
function of , it is enough to choose the widest of the two passbands dened above. Thus, we
dene:
Nexact =
cos 0b =
sb
Given the value of c, we compute next the two candidates for pass :
0b
c cos sb
stop =
sin
Once we have computed pass and stop , we design our Butterworth analog lter; that is, compute
N and 0 from
c cos 0b
= 0
sin 0b
c cos sb
sin sb
pass = max |pa |, |pb |
tan
stop =
sin(sa + sb )
,
sin sa + sin sb
Problem 11.17
c cos sa
sin sa
where the nal result was obtained by dividing numerator and denominator by the factor (1
20 cos i + 20 ) in order to make the constant coefcient of the denominator unity.
The highpass case is obtained by replacing z1 by z1 , which effectively changes the sign of the
ai1 coefcient. The bandpass case can be done in a similar, but more tedious, fashion.
stop =
20 + 1 c2 + 0
1+c
f 0b
2
2
fs
0 + 1 c + 0
=
arctan
1+c
240
241
Nex
N =
r =
K =
= log(estop/epass) / log(Wstop/Wpass);
ceil(Nex);
rem(N,2);
(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));
Nex
N =
r =
K =
= acosh(estop/epass) / acosh(Wstop/Wpass);
ceil(Nex);
rem(N,2);
(N - r) / 2;
P = [Wpass, Wstop, Wpa, Wpb, c, fc, epass, estop, Nex, N, Apass, W0, f0a, f0b];
a = asinh(estop) / N;
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
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;
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
%
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;
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
% 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
242
243
% reciprocal of text
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:
double sos4();
1 + i 2 s2
2
1
2
1 2
)s2
0 cos i s + (0 + i
(1 + z1 )2 +i 2 (1 z1 )2
1
1
2
(1 + z ) 20 cos i (1 z1 )(1 + z1 )+(02 + i 2 )(1 z1 )2
+
i 2 )+2(1
)z1 + (1 + 202 cos i + 02 + i 2 )z2
i
0
0
0 i
Gi (1 + bi1 z1 + z2 )
1 + ai1 z1 + ai2 z2
double cas4(K, A, B, W, x)
int K;
double **A, **B, **W, x;
{
int i;
double y;
where the nal step follows by dividing the numerator by the factor (1 + i 2 ) and the denomi2
2
).
nator by (1 202 cos i +
0 + i
A, B, W are K5 matrices
y = x;
return y;
Problem 11.20
The s-domain poles are
The K 5 matrices A and B are generated by the lter design MATLAB functions, such as bpsbutt.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 les and then
invoking the following ltering 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>
Problem 11.21
The following C functions sos4.c and cas4.c implement the sample-by-sample processing algorithm of the cascade of fourth-order sections:
/* sos4.c - IIR filtering by single (canonical) fourth-order section */
double sos4(a, b, w, x)
double *a, *b, *w, x;
{
double y;
a, b, w are 5-dimensional
a[0]= 1 always
=
=
=
=
w[3];
w[2];
w[1];
w[0];
coefcient les
temporary coefcient array
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, "Cant open filter file: %s\n", argv[1]);
exit(0);
}
delay(4, w);
return y;
}
and
244
245
if (M%5 != 0) {
fprintf(stderr, "all rows of A must be 5-dimensional");
exit(0);
}
else
number of SOS4
K = M / 5;
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(5, sizeof(double));
B[i] = (double *) calloc(5, sizeof(double));
W[i] = (double *) calloc(5, sizeof(double));
}
allocate K rows
form A matrix
read B matrix
The MATLAB version of casfilt4 for ltering 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 = caslt4(B, A, x)
%
% B = Kx5 numerator matrix
% A = Kx5 denominator matrix
% x = row vector input
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 lters, and shows how to compute the phase response and impulse response of one
of the lters (the rst bandpass lter):
Apass = -10*log10(0.98);
Astop = -10*log10(0.02);
stringent case
lowpass
highpass
bandpass
% x = scalar input
% y = scalar output
246
247
lowpass
highpass
bandpass
bandstop
bandstop
om = (0:199) * pi / 200;
om = (0:199) * pi / 200;
a5 = cas2can(A5);
b5 = cas2can(B5);
H5 = dtft(b5, om)./dtft(a5, om);
argH5 = angle(H5) * 180 / pi;
bandpass case
a7 = cas2can(A7);
b7 = cas2can(B7);
H7 = dtft(b7, om) ./ dtft(a7, om);
argH7 = angle(H7) * 180 / pi;
bandpass case
frequency response
phase response (in degrees)
BS type 2
BS type 2
frequency response
phase response (in degrees)
The computed phase and impulse responses are shown in Fig. P11.3. Notice how the phase
response is almost linear within its passband.
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.3 Phase and impulse responses of (the less stringent) bandpass lter of Problem 11.22.
Fig. P11.4 Phase and impulse responses of (the less stringent) bandpass lter of Problem 11.23.
Problem 11.23
The following MATLAB code designs the pairs of lowpass, highpass, bandpass, and bandstop
Chebyshev lters, and shows how to compute the phase response and impulse response of one
of the lters (the rst bandpass lter):
Apass = -10*log10(0.98);
Astop = -10*log10(0.02);
stringent case
LP type 1
LP type 1
HP type 1
HP type 1
LP type 2
BP type 2
248
LP type 2
BP type 2
249
Chapter 12 Problems
d(k)
1
Problem 12.1
0.64
0.64
The low-rate transfer functions, Di (z) and Hi (z)= z2 Di (z), corresponding to Eq. (12.4.2) will
be:
-4
D0 (z) = 1
2
2
+ 0.90z
0.18z
+ 0.64z
0.21z3
D()=D0 ( 4 )+ 1 D1 ( 4 )+ 2 D2 ( 4 )+ 3 D3 ( 4 )
2
-0.21
-0.21
H0 (z) = z2
=1 +
3
-2 -1
-3
The interpolated samples between x(n)= xup (2n) and x(n+ 1)= xup (2n+ 2) are calculated from
Eqs. (12.2.18). The two sublters act on the time-advanced (by M = 2) low-rate input samples
{x(n + 2), x(n + 1), x(n), x(n 1)}, or, {xup (2n + 4), xup (2n + 2), xup (2n), xup (2n 2)}.
Equations (12.2.18) can be cast in a compact matrix form:
yup (2n)
yup (2n + 1)
=
0
0.21
0
0.64
1
0.64
0
0.21
xup (2n + 4)
x (2n + 2)
up
xup (2n)
xup (2n 2)
These ltering equations can also be obtained by superimposing the symmetric impulse response
of Fig. P12.1 on each of the contributing low-rate samples
{xup (2n + 4), xup (2n + 2), xup (2n), xup (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.
Problem 12.2
xup(2n+4)
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
n
2n-2
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 sublters are dened by Eq. (12.2.10), that is, for i = 0, 1,
2 k 1
They can be extracted from h by taking every second entry, starting with the ith entry:
2n
2n+2
2n+4
h0 = d0 = [0, 0, 1, 0]
h0 = [0, 0, 1, 0]
250
251
yup (2n)
yup (2n + 1)
=
0
0.05
0
0.55
1
0.55
0
0.05
xup (2n + 4)
x ( 2n + 2)
up
xup (2n)
xup (2n 2)
These ltering equations can also be obtained by superimposing the symmetric impulse response
of Fig. P12.3 on each of the contributing low-rate samples
{xup (3n + 6), xup (3n + 3), xup (3n), xup (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.
Problem 12.3
For the case of a 3-fold interpolator, we have L = 3 and choose again M = 2, corresponding to
lter length N = 2LM + 1 = 13. The ideal impulse response is:
sin(k
/3)
d(k
)=
,
k
/3
xup(3n)
xup(3n-3)
yup(3n+1)
xup(3n+3)
xup(3n+6)
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 sublters are dened by Eq. (12.2.10), that is, for i = 0, 1, 2,
2 k 1
They can be extracted from h by taking every third entry, starting with the ith entry:
3n-3
3n
The Hamming windowed version of the lter is obtained by multiplying the full length-13 lter
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 sublters are obtained by extracting every third entry:
h0 = [0, 0, 1, 0]
The interpolated samples between x(n)= xup (3n) and x(n + 1)= xup (3n + 3) are calculated
from Eqs. (12.2.18).
d(k)
1
0.83
0.83
0.41
yup (3n)
0
yup (3n + 1) = 0.02
0.06
yup (3n + 2)
0.41
-6 -5 -4
-0.17
4
0
-0.21
3
-0.21
0
0.41
0.83
252
1
0.83
0.41
1
0.78
0.32
xup (3n + 6)
0
xup (3n + 3)
0.06
xup (3n)
0.02
xup (3n 3)
Problem 12.4
All three sublters act on the time-advanced (by M = 2) low-rate input samples {x(n+2), x(n+1),
x(n), x(n 1)}, or, {xup (3n + 6), xup (3n + 3), xup (3n), xup (3n 3)}. Equations (12.2.18) can
be cast in a compact matrix form:
yup (3n)
0
0
0.32
0.78
-0.17
3n+6
h0 = d0 = [0, 0, 1, 0]
-3 -2 -1
3n+3
xup (3n + 6)
0
xup (3n + 3)
0.21
xup (3n)
0.17
xup (3n 3)
N = 2LM + 1
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
253
for
12 k
12
D
CX
d=
[ 0.000,
0.000,
0.000,
0.082,
0.300,
0.180,
0.127,
0.637,
0.212,
0.100,
0.900,
0.129,
0.000,
1.000,
0.000,
0.129,
0.900,
0.100,
0.212,
0.637,
0.127,
0.180,
0.300,
0.082,
B
0.90
0.000 ]
0.30
0.10
This impulse response is shown in Fig. P12.5 (where the values have been rounded to 2-digit
accuracy for convenience.)
n
-0.18
d(k)
0.90
0.64
0.30
0.13
0.30
E
0.64
0.64
0.13
0.08
0.13
0.10
-4 -3 -2 -1 0 1 2 3 4
-0.13
-0.13
-0.18 -0.21
-0.21 -0.18
-12
0.90
0.64
0.10
-0.13
D
C
0.08
0.13
n
0.08
12
-0.21
-0.21
C
E
B
0.90
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 ip-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 intersects 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
0.082
Y = 0.127
Z
0.100
0.129
0.212
0.180
0.300
0.637
0.900
0.900
0.637
0.300
0.180
0.212
0.129
0.100
0.127
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:
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
x(n + 1)
x(n)
Problem 12.6
The following complete C program interp.c implements the polyphase sample-by-sample processing algorithm of Eq. (12.2.20) and the initialization procedure of (12.2.19):
254
F
0.30
0.10
0.08
n
-0.13
-0.18
Fig. P12.6 Interpolated values are calculated by the ip-and-slide form of convolution.
/*
*
*
*
*
*
*
1)
*
*
*/
hamm
L
M
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
void delay();
double dot();
double d();
255
double d(L, k)
int L, k;
{
double t, pi = 4 * atan(1.0);
hamm = atoi(argv[1]);
L
= atoi(argv[2]);
M
= atoi(argv[3]);
P = 2*M - 1;
allocate L sublters
each of length 2M
d(0) = 1
if (k == 0)
return (1.0);
else {
if (k%L == 0)
return (0.0);
else {
t = pi * k / L;
return (sin(t)/t);
}
}
where the parameter hamm species a Hamming or rectangular window, L is the interpolation
factor, and M is the half-length of the polyphase sublters, so that the total lter length is
N = 2LM + 1.
The program designs the windowed length-N interpolation lter and then reads the low-rate input samples sequentially from a le xlow.dat or stdin, computes the high-rate interpolated
samples, and writes them to the le 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 sublters. The following program cinterp.c is the circular-buffer version of inkeep reading low-rate samples till EOF
terp.c:
process by Eq. (12.2.20)
256
input-off transients
zero input
257
fprintf(stderr,"
exit(0);
}
{
double t, pi = 4 * atan(1.0);
P = 2*M - 1;
allocate L sublters
d(0) = 1
if (k == 0)
return (1.0);
else {
if (k%L == 0)
return (0.0);
else {
t = pi * k / L;
return (sin(t)/t);
}
}
hamm = atoi(argv[1]);
L
= atoi(argv[2]);
M
= atoi(argv[3]);
each of length 2M
}
/* -------------------------------------------------------- */
/* cdot(P, h, w, p) - circular version of dot.c */
double tap();
double cdot(P, h, w, p)
double *h, *w, *p;
int P;
{
int i;
double y;
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:
p = x
(P12.1)
cdelay(P, w, & p)
for (n=0; n<M; n++) {
*p = 0.0;
for (i=0; i<L; i++) {
y[i] = cdot(P, h[i], w, p);
printf("%.12lf\n", y[i]);
}
cdelay(P, w, &p);
}
}
/* -------------------------------------------------------- */
/* d(L, k) - ideal L-fold interpolation coefficients */
double d(L, k)
int L, k;
258
input-off transients
zero input
circular version of dot()
and write it into stdout
update low-rate delay line
and
for each low-rate input sample x do:
p = x
for m = 0, 1, . . . , P determine internal states:
sm = tap(P, w, p, m)
for i = 0, 1, . . . , L 1 compute output of ith filter:
yi = dot(P, hi , s)
cdelay(P, w, & p)
(P12.2)
The length-17 rectangular and Hamming windowed lters for this problem were derived in Section
12.4.1. The given inputs were processed by interp.c. The upsampled versions of these inputs,
xup (n
), are shown in Fig. P12.7 together with the corresponding interpolated output signals
yup (n
), computed by the length-17 Hamming windowed version of the interpolation lter.
259
fs
2
H0
8fs
2fs
4
H1
L0
Rmulti
1
=
+
F = 0.50
Rsingle
L1
L0 1
Thus, the multistage realization requires only 54 percent the cost of the single-stage one. The
combined lter Htot (f )= H0 (f )H1 (f ) and the superimposed plots of the lters H0 (f ), H1 (f )
are shown in Fig. P12.9. Similarly, for the 42 case, shown in Fig. P12.10, we nd the lter lengths:
N0 = 169,
N1 = 17
Problem 12.7
We start with fs = 40 kHz, f = 5 kHz, and A = 80 for all the stages. The effective single stage
lter will have Kaiser length:
N1=
DL
= 321.08
F
M = 21
fs
4
H0
8fs
4fs
2
H1
N0 1 =
L0 D
= 80.27,
F
N1 1 =
8D
DF1
=
= 40.14
F0 1
21
N0 = 85 = 2L0 M0 + 1 = 4M0 + 1
M0 = 21
N1 = 49 = 2L1 M1 + 1 = 8M1 + 1
M1 = 6
Rmulti
N0 + N 1 F0
= 0.54
=
N
Rsingle
260
N0 + N1 F0
Rmulti
= 0.70
=
Rsingle
N
The combined lter Htot (f )= H0 (f )H1 (f ) and the superimposed plots of the lters H0 (f ),
H1 (f ) are shown in Fig. P12.11. Initially, we designed the lters with stopband attenuations
A0 = A1 = 80 dB. However, we found that in order to keep the overall stopband attenuation
261
below 80 dB, the attenuation of the second lter had to be increased to A1 = 84 dB. This did not
change the lter lengths, but it changed slightly the Kaiser parameters D1 and 1 for that factor.
Finally, in the 222 case, shown in Fig. P12.12, we nd the lter lengths
N0 = 85,
N1 = 25,
N2 = 17
N 0 + N 1 F0 + N 2 F 1
Rmulti
= 0.60
=
N
Rsingle
fs
2
H0
2fs
4fs
H1
8fs
2
H2
N1=
DL
5.0174 4
= 215.803
=
F
0.0930
N = 217,
M = (N 1)/(2L)= 27
Problem 12.8
In units of fs = 44.1 kHz, the transition width from the edge of the passband to the edge of the
stopband will be:
F =
24.1 20
f
= 0.0930
=
fs
44.1
N0 1 =
DL0
5.0174 2
= 107.9
=
F
0.0930
N0 = 109,
M0 = (N0 1)/(2L0 )= 27
The second stage H1 will have a wider transition width f1 = fs , or F1 = 1. Thus, the lter
length will be:
262
263
N1 1 =
DF1
5.0174 4
=
= 20.07
F0 1
1.000
N1 = 25,
M1 = (N1 1)/(2L1 )= 6
Rmulti
159fs
=
= 0.73
Rsingle
217fs
Problem 12.9
f1 = 28;
f2 = 16;
Butterworth
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 020 kHz passband. But its magnitude response is not as
at as the Butterworths.
Problem 12.10
The lter H0 has a cutoff frequency fc = fs /2. The linear, hold, and DAC magnitude responses
(normalized to 0 dB at DC) are in the general and the particular case of L0 = 4, L1 = L2 = 2:
sin(f /L f ) 2 sin(f /4f ) 2
0 s
s
=
|H1 (f )| =
2 sin(f /8fs )
L1 sin(f /L0 L1 fs )
sin(f /L L f ) sin(f /8f )
0 1 s
s
=
|H2 (f )| =
L2 sin(f /L0 L1 L2 fs ) 2 sin(f /16fs )
sin(f /L L L f ) sin(f /16f )
0 1 2 s
s
=
|Hdac (f )| =
f /L0 L1 L2 fs f /16fs
The lter H0 operates at rate 4fs and cancels all the images at multiples of fs which are not
multiples of 4fs . The linear interpolator H1 operates at rate 8fs and vanishes at multiples of 4fs
which are not multiples of 8fs . The lter H2 operates at rate 16fs and vanishes at multiples of 8fs
which are not multiples of 16fs . Finally, Hdac vanishes at all non-zero multiples of 16fs . Thus, the
combined effect of H0 , H1 , H2 , and Hdac is to (partially) remove all spectral images at multiples
of fs .
We note that the combined effect of the two hold transfer functions is an effective DAC operating
at 8fs :
sin(f /L L f ) sin(f /L L L f ) sin(f /L L f ) sin(f /8f )
0 1 s
0 1 2 s
0 1 s
s
=
=
|H2 (f )Hdac (f )| =
L2 sin(f /L0 L1 L2 fs ) f /L0 L1 L2 fs f /L0 L1 fs f /8fs
The reason for using H2 is that the higher the L, the more bits can be saved via the noise-shaping
requantizer.
Problem 12.11
Fig. P12.15 Phase responses of Bessel and Butterworth lters.
264
The proof of the result may be seen graphically in Fig. P12.17 for the case L = 4. The ideal interpolator has cutoff fs /2 and is periodic in f with period Lfs = 4fs . Thus, the passband replicates
at multiples of 4fs .
265
D(f)
-4fs -3fs -2fs
-fs
fs
2fs
3fs
4fs
-fs
fs
2fs
3fs
4fs
X()=
x(n)ejn ,
fs
2fs
3fs
-fs
fs
2fs
3fs
4fs
fs
-fs
fs
2fs
3fs
4fs
4fs
2mfs
Lfs
2m
s
(n
)=
L1
1
S
(
m )ejm n ,
m =
2(mfs )
fs
m=0
2(mfs /L)
fs
2m
where S
(
m ) is the L-point DFT of s
(n
) calculated from one period of s
(n
as follows:
for all f
S
(
m )=
L
1
s
(n
)ejm n
n
=0
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:
fs
L1
2m
1
=
X
X 2m)/L
L
L m=0
L m=0
Problem 12.12
2f
Problem 12.13
f
1
D(f )+D(f fs )+D(f 2fs )+D(f 3fs ) = 1,
4
L1
1
X()=
The terms D(f mfs ) correspond to the right shifts of D(f ) centered at mfs . It is evident from
the gure that the these shifted terms ll 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:
X(f ) =
Fig. P12.17 Sum of successive shifts of ideal lowpass interpolator with L = 4 in Problem 12.11.
x
(n
)ej
D(f-3fs)
-4fs -3fs -2fs
X
(
)=
2(f mfs )
-fs
X
(f mfs )
m=0
D(f-2fs)
-4fs -3fs -2fs
D(f-fs)
-4fs -3fs -2fs
L1
1
X(f )=
Xa (f kfs )=
k=
L
1
L
1
S
(
m )= 1,
Xa (f (k
L + m)fs )
Xa f (k
L + m)fs =
m=0 k
=
LT
L
1
s
(n
)=
Xa (f mfs k
fs )
m=0 k
=
where we replaced T = LT
and Lfs = fs . If in the denition of X
(f ) we replace f by f mfs ,
we have:
1
Xa (f mfs k
fs )
k
=
Thus the k
summation in the above double sum may be replaced by X
(f mfs ) resulting in the
desired result:
266
m = 0, 1, . . . , L 1
m=0 k
=
X
(f mfs )=
L1
1
ejm n =
m=0
L1
1
e2jmn
/L
m=0
xup (n
)=
L1
1
ejm n x
(n
)
Xup (
)=
m=0
L1
1
X
(
m )
m=0
But we have seen in Eq. (12.2.21) that the upsampled spectrum is the same as the original low-rate
spectrum, that is, Xup (f )= X(f ), or in units of and
, Xup (
)= X(). It follows that
X()= Xup (
)=
L1
1
X
(
m )=
m=0
267
L1
1
m=0
2m
X
L
Problem 12.14
Problem 12.16
Using the expression of the attenuation of Problem 12.15, we get at the passband and stopband
normalized frequencies Fpass = 0.5, Fstop = L 0.5:
L1
1
X
(f mfs )=
m=0
L1
1
m=0
L1
1
0 . 5 2 N
Apass = 10 log10 1 +
F0
L 0 . 5 2 N
Astop = 10 log10 1 +
F0
m=0
where we used the periodicity of X(f ) with period fs to write X(f mfs )= X(f ), and then we
used the result of Problem 12.11 to replace the sum of shifted D(f )s by unity.
L 0 .5
0 .5
2N
=
10Astop /10 1
10Apass /10 1
Problem 12.15
ln
N=
A(F)= 10 log10 1 +
F 2 N
F0
Apass = 10 log10 1 +
0 . 5 2 N
F0
F0 =
Let N0 = ceil(N). In order for the lter order to remain xed at N0 , the computed quantity N
must be in the range
0. 5
10Apass /10 1
1/2N
ln
N0 1 <
Astop = 10 log10 1 +
L 0 . 5 2 N
F0
1/2N
L = 0.5 + F0 10Astop /10 1
10Astop /10 1
10Apass /10 1
2 ln(2L 1)
The prelters stopband must begin at Fstop = fstop /fs = (Lfs fs /2)/fs = L 0.5. Thus, the
stopband attenuation will be
2 ln(2L 1)
where we used the normalized frequencies F = f /fs and F0 = f0 /fs . Given a required attenuation
of Apass dB over the passband Fpass = fpass /fs = (fs /2)/fs = 0.5, we obtain an equation for the
3-dB frequency F0 :
10Astop /10 1
10Apass /10 1
0 .5 + 0.5
10Astop /10 1
10Apass /10 1
1/2N0
L < 0 . 5 + 0 .5
10Astop /10 1
10Apass /10 1
1/2(N0 1)
N0
For the given numerical values, we nd N0 = 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 /fs = (24.41 20)/44.1 = 0.1. Using a Kaiser
design, the transition width parameter D and lter length N will be:
D=
95 7.95
A 7.95
=
= 6.0620,
14.36
14.36
N1 =
6.062 160
DL
= 9699.2
=
F
0.1
N = 9920
where the nal N is of the form N = 2LK + 1 = 320K + 1 with K = 31. Thus, the interpola
tion/decimation lter operating at rate fs = 160fs = 147fs = 7.056 MHz can be implemented
with 160 polyphase sublters, each of length 2K = 62 and operating at a rate fs = 44.1 kHz. The
overall sample rate conversion cost in MAC/sec can be calculated from Eq. (12.6.9):
268
269
Problem 12.18
32
2
fs < fs , the lters cutoff frequency will be fc = fs /2 = 16 kHz. Assuming a 1 kHz transition
width about fc , that is, f = 2 kHz, and a A = 60 dB stopband attenuation, we nd the Kaiser
parameter D and lter length N:
D=
A 7.95
60 7.95
=
= 3.6247,
14.36
14.36
3.6247 2 48
DLfs
=
= 173.98
f
2
N1 =
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 lter acts as an anti-image lter for the upsampler.
N = 177
x1
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 sublters of length 2K = 88. Fig. P12.19 shows the ideal specications
of such a lter. The lter operates at the fast rate fs = 3fs = 2fs = 96 kHz and acts as an
antialiasing lter for the downsampler, that is, it removes the high frequencies from the input
in the range [fs 2, fs /2]= [16, 24] kHz, so that the downshifted replicascaused by the 3-fold
downsampling operationwill not overlap.
x0
x2
x1
fs
y1
T/3=T
T/3=T
y2
T/2=T
y1
fs
2fs
f
0
1
2
min(fs , fs )
fs
2fs
3fs
3fs=fs
f
fs
2fs=fs
fs
2fs
f
1
2
min(fs , fs )
In this case, we have fs = 3fs /2 = 3 32/2 = 48. The fast rate is fs = 2fs = 3fs = 96 kHz. The
input- and output-rate sampling intervals are T = 3T
and T
= 2T
= 2T = 3T
. Thus, every group of two input samples {x0 , x1 } generates a group of
three output samples {y0 , y1 , y2 }. As can be seen in the gure, the polyphase selector sequence
is im = 2m % 3 = [0, 2, 1], for m = 0, 1, 2. Therefore, the three interpolated outputs {y0 , y1 , y2 }
will be computed by the sublters {h0 , h2 , h1 }. The corresponding sample processing algorithm
will be:
Because T = T
/2 and T
= T
=
3T = 2T
, containing 3 input-rate samples {x0 , x1 , x2 } and 2 output-rate samples {y0 , y1 }. The
interpolated output y1 that lies halfway between x1 and x2 is obtained by the polyphase lter h1 .
Indeed, the polyphase selector indices can be precomputed by
im = 3m % 2 = [0, 1],
2fs
6T=2T=3T
3fs=fs
t
6T=3T=2T
fs
t
T
y0
2fs=fs
fs
3fs
f
f
0
T/2=T
2fs
i= 0
2fs
t
1
fs
polyphase
selector
y0
polyphase
selector
f
0
t
T
filter
T
i= 0
filter
x0
w 0 = x0
y0 = dot(P, h0 , w)= x0
y1 = dot(P, h2 , w)
delay(P, w)
w0 = x1
y2 = dot(P, h1 , w)
delay(P, w)
for m = 0, 1
The sample processing algorithm of the 2/3 sample rate converter will be then:
for each input block {x0 , x1 , x2 } do:
w 0 = x0
y0 = dot(P, h0 , w)= x0
delay(P, w)
w0 = x1
y1 = dot(P, h1 , w)
delay(P, w)
w0 = x2
delay(P, w)
For the case L/M = 7/4, we have fs = 7fs /4 and fs = 4fs = 7fs , T
= T
/4 = T/7, Tblock =
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 {x0 , x1 , x2 , x3 } generates 28 fast-rate
interpolated samples, out of which 7 output-rate samples {y0 , y1 , y2 , y3 , y4 , y4 , y6 } are selected
and computed according to their polyphase indices:
270
271
Problem 12.19
x2
x1
x0
x3
y0
T/7=T
fs
2fs
3fs
4fs
5fs
t
4
T/4=T
t
y1
y2
y3
y4
y5
fs
2fs
3fs
fs
y6
4fs
2fs
5fs
3fs
t
T
28T=4T=7T
= T
/7 = T/4, Tblock =
= 4T
= 7T. Fig. P12.22 depicts the operation of the converter both in the time and
frequency domains.
f28T
t
T
polyphase
selector
i= 0
filter
0
1
2
min(fs , fs )
fs
2fs
6fs
7fs
f x2
x0 x1
6fs
7fs=fs
polyphase
f
selector
4fs=fs
i= 0
3
f
3fs
im = 4m % 7 = [0, 4, 1, 5, 2, 6, 3],
for m = 0, 1, . . . , 6
w0 = x0
y0 = dot(P, h0 , w)= x0
y1 = dot(P, h4 , w)
delay(P, w)
w0 = x1
y2 = dot(P, h1 , w)
y3 = dot(P, h5 , w)
delay(P, w)
w0 = x2
y4 = dot(P, h2 , w)
y5 = dot(P, h6 , w)
delay(P, w)
w0 = x3
y6 = dot(P, h3 , w)
delay(P, w)
For example, the two output samples y4 , y5 lie between the input samples x2 , x3 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 x3 is read into the delay line, and so on.
In the frequency domain, the SRC lter acts as an anti-image postlter for the upsampler, remov
ing the L 1 = 6 replicas between multiples of the fast rate fs . The downshifting of the replicas
caused by the downsampling operation will position replicas at the 3 multiples of the output rate
272
x4
x5
y1
filter
x6
t
T
T/4=T
fs
2fs
3fs
4fs
f
t
2
T/7=T
t
4fs
y0
x3
y2
2fs
4fs=fs
3fs
f
0
y3
fs
0
fs
2fs
3fs
4fs
5fs
6fs
7fs=fs
2fs
3fs
4fs
5fs
6fs
7fs
t
T
28T=7T=4T
fs
1 min(f , f )
s
s
2
im = 7m % 4 = [0, 3, 2, 1],
for m = 0, 1, . . . , 3
w0 = x0
y0 = dot(P, h0 , w)= x0
delay(P, w)
w0 = x1
y1 = dot(P, h3 , w)
delay(P, w)
w0 = x2
delay(P, w)
w0 = x3
y2 = dot(P, h2 , w)
delay(P, w)
w 0 = x4
delay(P, w)
w0 = x5
y3 = dot(P, h1 , w)
delay(P, w)
w0 = x6
delay(P, w)
273
In the frequency domain, the SRC lter acts as an antialiasing prelter for the downsampler, re
moving the 3 replicas between multiples of the fast rate fs . The downshifting of the replicas
caused by the downsampling operation will position replicas at the 6 multiples of the output rate
D=
80 7.95
A 7.95
= 5.0174 ,
=
14.36
14.36
N1 =
DL
5.0174 4
= 200.70
=
F
0.1
N = 209
where N the smallest odd integer of the form N = 2LK + 1; here, K = 26.
allocate polyphase
i-th polyphase
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));
Problem 12.20
A typical window depends 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
)= w(k
w (k )d (k )= w(k )d(k )
Problem 12.21
The polyphase Kaiser lter can be designed by the code fragment:
allocate w
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 endof-le 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));
D = (A - 7.95) / 14.36;
if (A > 50)
alpha
else if (A >
alpha
else
alpha
= 0.1102 * (A - 8.7);
21)
= 0.5842 * pow(A-21, 0.4) + 0.07886 * (A-21);
for-ever do:
read M inputs
compute L outputs
write L outputs
= 0;
transients:
N = 1 + ceil(D*L / DF);
K = ceil((N - 1) / (2.0*L));
N = 2*L*K + 1;
P = 2*K - 1;
LK = L*K;
Kaiser length
wc = pi / max(L, M);
I0alpha = I0(alpha);
cutoff frequency
round up
nal length
polyphase lter order
lter delay
window normalization
274
last K inputs
275
void delay();
void src(L, M, P, h, w, x, y)
double **h, *w, *x, *y;
{
int n, m, i;
double R = L / (double) M;
I0 ( n
(80 n
)/80) sin (n
40)/5
,
I0 ()
(n 40)
I0 ( n
(48 n
)/48) sin (n
24)/5
,
h3/5 (n
)= 3
I0 ()
(n
24)
h5/3 (n
)= 5
= 0, 1, . . . , 80
n
= 0, 1, . . . , 48
H(f )=
N
1
/f
h(n
)e2jf n
with fs
= 15 kHz
=0
With the values A = 30 dB, F = 0.1, the 5/3 lter has D = 1.536, = 2.117, N = 81, K = 8,
P = 2K 1 = 15. The reverse 3/5 lter has the same D, , K, and P, but its length is N = 49,
because N = 2LK + 1, where now L = 3. The lter 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.
Problem 12.22
Replacing the quantizer Q by its equivalent noise model, we can write the -domain input/output
equations:
Fig. P12.23 Frequency responses of SRC lters.
Both lters have a cutoff frequency of fc = min(fs /2, fs /2)= 3/2 = 1.5 kHz, or,
c = /5. The
passband ripple is = 10A/20 = 0.032. Their transition widths are different: the rst lter has
f = 0.13 = 0.3 kHz, and the second f = 0.15 = 0.5 kHz. Were they to be redesigned to
have the same f , say 0.3 kHz, then for the 3/5 lter we would have F = 0.06, resulting in the
lengths N = 79, K = 13, P = 25. In that case, the lters would be virtually identical (except for
the gain and the delay by 1 sample).
V
() = X
() 1 Y
()
W0
() = V
()+ 1 W0
()
Y
() = E
()+W0
()
Eliminating V
() and W0
(), we obtain:
Y
()= X
()+(1 1 )E
()
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,
Therefore, Hx ()= 1, and HNS ()= 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).
276
277
Problem 12.23
Using the signal labels indicated on the block diagram, we have the sample processing algorithm:
A block diagram realization is shown in Fig. P12.25. The corresponding sample processing algorithm can be stated as follows:
for each input x
do:
w0 = w1 + (x
u)
v0 = v1 + (w0 u)
y
= Q(v0 )
w1 = w0
v1 = v 0
u = y
v =xu
w0 = v + w1
y = Q(w0 )
w1 = w0
u=y
Iterating this algorithm 10 times, we get for x = 0.4 and x = 0.2:
0.40
0.40
0.40
0.40
0.40
0.40
0.40
0.40
0.40
0.40
x
0.20
0.20
0.20
0.20
0.20
0.20
0.20
0.20
0.20
0.20
1
1
1
1
1
1
1
1
1
1
H1()
y
1
H2()
+
w0
v0
-1
w1
1
1
v1
u
1
1
1
1
-1
quantizer
-1
Problem 12.25
Problem 12.24
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,
Working in the -domain, we note that the input and output of the lter H1 () will be:
X ()
Y ()
H1 () X ()
and
Y ()
H1 ()H2 ()
1 + H2 ()+H1 ()H2 ()
X
()+
1
E
()
1 + H2 ()+H1 ()H2 ()
Thus, we identify:
H1 () X
() 1 Y
() 1 Y
()
Y
()=
H2 () H1 () X
() 1 Y
() 1 Y
()
and
Hx ()=
H1 ()H2 ()
1 + H2 ()+1 ()H2 ()
HNS ()=
1
1 + H2 ()+H1 ()H2 ()
The requirement that Hx ()= 1 and HNS ()= (1 1 )2 is satised by the choices:
Adding E
() to this output will generate Y
(). Thus,
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 ()
H1 ()=
1
,
1 1
H2 ()=
1
1 1
Thus, we identify:
H1 ()H2 ()
,
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 satised by the choices:
H1 ()= H2 ()=
278
1
1 1
Problem 12.26
Once the decimation lters are designed, the 2-level quantization of the input by the delta-sigma
quantizer, and the subsequent ltering by the decimation lter 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
279
y = Q(w1);
v = x - y;
w0 = w1 + v;
w1 = w0;
yup[n] = fir(N-1, h, w, y);
}
w1 = v1 = u = 0;
quantizer output
sigma part
update quantizers delay
(upsampled) decimator output
where h and w are the N-dimensional impulse response and internal state arrays for the decimator. In the Kaiser and the rectangular window designs, the lter length is N = 2LM + 1. In the
rst-order comb case, it is N = 10, and the impulse response and transfer function are:
h=
1
[ 1, 1 , 1 , 1 , 1 , 1 , 1 , 1, 1 , 1 ] ,
10
H()=
1 1 10
10 1 1
For the second-order comb case, we obtain the impulse response by convolving the rst-order
combs impulse response with itself. This gives a length N = 19 response and transfer function:
h=
initialize delays
delta part
1
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1] ,
100
H()=
1 1 10
10 1 1
2
The magnitude response of the second-order comb case is the square of that of the rst-order
case:
sin(f /f ) 2
s
|H(f )| =
L sin(f /10fs )
It is plotted in dB in Fig. P12.26 together with the rst-order comb case and the rectangular
window design. The upsampled output yup (n
) of the second-order comb decimator is plotted
in the right graph of Fig. P12.26.
Fig. P12.27 High-rate input and output signals of second-order quantizer.
The upsampled outputs yup (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 rst stage. The input to H() is
X
() 1 Y1
(), Thus, adding the noise component, we have:
Y1
()= E1
()+H() X
() 1 Y1
()
which can be rearranged as:
Fig. P12.26 Length-19 second-order comb magnitude response and lter output.
Y1
()=
H()
1 + 1 H()
X
()+
1
E
()
1 + 1 H() 1
Problem 12.27
Y1
()= X
()+(1 1 )E1
()= X
()+D()E1
()
(P12.3)
The lter designs are the same as in the previous problems. The implementation of the secondorder 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 quantizer, and lters the quantized output with the decimation lter:
where D()= 1 1 . The input to the second stage is obtained by forming the difference of the
signals around the rst quantizer, that is, (Y
E1
)Y
= E1
. Applying the basic I/O equation
(P12.3) to this input and corresponding noise E2
, we obtain
280
281
Y
() = Y1
()+D() Y2
()+D()Y3
()
= X
()+D()E1
()+D() E1
()+D()E2
()+D() E2
()+D()E3
()
= X
()+D3 ()E3
()
1st stage
x +
e1
y1
H()
-1
2nd stage
e1
e2
D()
y2
H()
e3
-1
3d stage
e2
H()
D()
y3
-1
Fig. P12.29 MASH architecture of third-order delta-sigma quantizer.
Fig. P12.28
puts.
First- and second-order comb, and rectangular- and Kaiser-window decimator out-
Problem 12.30
Such an architecture is depicted in Fig. P12.30. The I/O relationship of the rst stage is
Y2
()= E1
()+D()E2
()
Y1
()= X
()+D()E1
()
(P12.4)
Y
() = Y1
()+D()Y2
()= X
()+D()E1
()+D() E1
()+D()E2
()
= X
()+D()E1
()D()E1
()+D2 ()E2
()= X
()+D2 ()E2
()
Thus, the quantization error from the rst stage is canceled, whereas the error of the second
stage gets ltered by the second-order highpass lter D2 ()= (1 1 )2 .
Y2
()= E1
()+D2 ()E2
()
The overall output is obtained by the linear combination:
Y
() = Y1
()+D()Y2
()= X
()+D()E1
()+D() E1
()+D2 ()E2
()
= X
()+D3 ()E2
()
Problem 12.29
Such an arrangement is shown in Fig. P12.29. The outputs of the three stages are:
Y1
() =
X
()+D()E1
()
Y2 () = E1 ()+D()E2 ()
Y3 () = E2 ()+D()E3 ()
Problem 12.31
The delay of (N 1)/2 = LM introduced by the decimation lter 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.
282
283
Appendix B Problems
Problem B.1
The input sequence is
x(n)=
ui (n iD d)
1
D
E[ui uj ](n + k iD d)(n jD d)p(d)
Rxx (k)= E x(n + k)x(n) =
j d=0
where the expectation values were taken with respect to both ui and d. Because the ui are mutually
independent and zero mean and d is uniform, we have E[ui uj ]= u2 (i j) and p(d)= 1/D. It
follows that:
Rxx (k)=
1st stage
x +
e1
y1
H()
-1
2nd stage
e1
H()
Changing variables to m = n iD d and noting that m runs over all the integers, we can replace
the double summation over i and d by the summation over m:
u2
2
(k + m)(m)= u (k)
D m
D
Rxx (k)=
e2
y2
D1
u2
(n + k iD d)(n iD d)
D i d=0
H()
D()
Thus, x(n) is stationary and has a delta-function autocorrelation. Sending this sequence into the
interpolation lter will generate a stationary output sequence y(n) with a noise reduction ratio:
-1
Fig. P12.30 MASH architecture of third-order delta-sigma quantizer.
NRR =
y2
2
h(n)2
y2
x2
D
1
1=D
y2 = Dx2 = D
n=0
u2
= u2
D
For the linear interpolator, we have h(n)= 1 |n|/D, for |n| D. This gives:
NRR =
NRR =
y2
2
y2
2
)D1
m=1
=1+2
n=0
m2 =
D
1
m=1
|n|
D
2
=1+2
n=1
n
D
D
1
D2
m=1
m2
1
D(D 1)(2D 1), we obtain:
6
m2 = 1 +
2D 2 + 1
D(D 1)(2D 1)
(D 1)(2D 1)
=
=1+
3D 2
3D
3D
Thus,
y2 =
284
=1+2
2D 2 + 1 2
2D 2 + 1 2
u
x =
3D 2
3D
285
Problem B.2
The power spectral density of the output sequence will be related to that of the input by:
u2
D
H(z)=
H(z1 )=
1 zD
1 zD D1
z
=
1z
1 z1
u2
1
=
D
D
1 zD
1 z1
2
zD1 u2
|k|
u2
Ryy (k)= 1
D
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));
R = (double *) calloc(M+1, sizeof(double));
N-dimensional
(M+1)-dimensional
u[0] = ran(&iseed)-0.5;
q = D * ran(&iseed);
initialize u
initialize q
zero mean
corr(N, y, y, M, R);
sample autocorrelation
Problem B.5
The random number generator C routine is:
Problem B.4
As was mentioned in the end of Section B.3, the averaged periodogram spectrum can be calculated
by the following loop:
fft(N, X);
286
if (*q==0)
w[0] = ran(iseed) - 0.5;
i = (L - *q) % L;
y = dot(P, h[i], w);
287
cdelay2(L-1, q);
if (*q==0)
delay(P, w);
return y;
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);
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 lters. 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):
K = ceil((N - 1) / (2.0*L));
N = 2 * L * K + 1;
P = 2 * K - 1;
LK = L * K;
lter length
lter order
lter delay
wc = pi / L;
I0al = I0(al);
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
double ran(), rani(), I0();
=
=
=
=
atoi(argv[1]);
atoi(argv[2]);
atoi(argv[3]);
atol(argv[4]);
Kaiser interpolator
if (k >= 2) {
fprintf(stderr, "enter A, DF (in units of fs): " );
scanf("%lf %lf", &A, &DF);
D = (A - 7.95) / 14.36;
288
windowed lter
for (n=0; n<N; n++)
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) {
N = L;
K = 0;
P = 0;
for (n=0; n<N; n++)
hd[n] = 1;
}
hold interpolator
if (k == 1) {
P = 1;
K = 1;
N = 2*L+1;
for (n=0; n<N; n++)
hd[n] = 1 - abs(n - L) / (double) L;
}
linear interpolator
polyphase sublters
allocate L sublters
ith sublter
initialize w
289
R(k)/R(0)
q = 0;
1.00
0.75
B=4
kmax=2B-1-1
0.50
0.25
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.
10
we nd
Ryy (k)=
B2
B
1
1 |k|2b u2
b=b(k)
and using the nite 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 kmax = 2B1 1 = 27 1 = 127. The sample
autocorrelation was computed by the program segment:
Problem B.6
Noting that the autocorrelation of a hold-interpolated sequence of period D is R(k)= (1
|k|/D)u2 , D k D, we have:
Ryy (k)=
B1
1
B2
b=0
Ryb yb (k)=
B1
1
B2
b=0
|k|
2b
u(2b |k|) u2
(P14.1)
N-dimensional
(M+1)-dimensional
zero-mean ys
corr(N, y, y, M, R);
use M=150
use N=2000
where the unit-step u(2b |k|) restricts the duration of the b-th term to be |k| 2b , or |k| 2b 1
for non-zero values of Ryy (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:
y2 = Ryy (0)=
B2
Bu2 =
u2
B
The increasing linear slopes in Ryy (k) cause it to have long-range correlations. Indeed, because
of the restriction |k| 2b 1, the maximum lag will be:
kmax = 2B1 1
(P14.2)
Given a lag k in the range |k| kmax , the expression of Eq. (P14.1) can be summed in closed form
as follows. The restriction |k| 2b 1 can be turned around into a restriction for the summation
index b log2 (|k| + 1). Denoting the ceiling of this quantity by
290
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 parameters are:
For max = 0.1, we have B = 3 and
c = 10,
c = 6.6943,
c = 3.5944,
Problem B.9
Solving the equation (0.99574)c = 0.94791, we nd c = 12.5309. Then, the lter of Eq. (B.30)
becomes:
H(z)= G
u1 = u 0
v0 = x1 + 0.94791 v1
x2 = v0 0.83392 v1
v1 = v 0
w0 = x2 + 0.53568 w1
y = w0 0.07568 w1
w1 = w0
The NRR = hT h of the lter (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/ hT 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 corresponding sample processing algorithm will be:
292
293
x1
0.57534
u0
z-1
u1
0.99574 -0.98444
x2
v0
z-1
v1
0.94791 -0.83392
y
w0
z-1
w1
0.53568 -0.07568
294