BooksAudiobooksComicsSheet Music### Categories

### Categories

### Categories

Editors' Picks Books

Hand-picked favorites from

our editors

our editors

Editors' Picks Audiobooks

Hand-picked favorites from

our editors

our editors

Editors' Picks Comics

Hand-picked favorites from

our editors

our editors

Editors' Picks Sheet Music

Hand-picked favorites from

our editors

our editors

Top Books

What's trending, bestsellers,

award-winners & more

award-winners & more

Top Audiobooks

What's trending, bestsellers,

award-winners & more

award-winners & more

Top Comics

What's trending, bestsellers,

award-winners & more

award-winners & more

Top Sheet Music

What's trending, bestsellers,

award-winners & more

award-winners & more

Welcome to Scribd! Start your free trial and access books, documents and more.Find out more

Signal Processing

Solutions Manual

Sophocles J. Orfanidis

Department of Electrical & Computer Engineering

Rutgers University, Piscataway, NJ 08855

orfanidi@ece.rutgers.edu

Copyright © 2010 by Sophocles J. Orfanidis

Web page: www.ece.rutgers.edu/~orfanidi/i2sp

Chapter 1 Problems

Problem 1.1

The Nyquist interval is [−f

s

/2, f

s

/2]= [−4, 4] Hz. The 6 Hz frequency of the wheel lies outside

it, therefore, it will be aliased with f − f

s

= 6 − 8 = −2 Hz. Thus, the wheel will appear to be

turning at 2 Hz in the opposite direction.

If f

s

= 12, the Nyquist interval is [−6, 6]. Points on the wheel will appear to be moving up and

down, with either positive or negative sense of rotation.

For the other two sampling frequencies, the Nyquist interval is [−8, 8] or [−12, 12] Hz, and

therefore, the original 6 Hz frequency lies in it and no aliasing will be perceived.

Problem 1.2

The three terms of the signal correspond to frequencies f

1

= 1, f

2

= 4, and f

3

= 6 Hz. Of

these, f

2

and f

3

lie outside the Nyquist interval [−2.5, 2.5]. Therefore, they will be aliased with

f

2

−f

s

= 4 −5 = −1 and f

3

−f

s

= 6 −5 = 1 and the aliased signal will be:

x

a

(t)= 10sin(2πt)+10sin(2π(−1)t)+5sin(2πt)= 5sin(2πt)

To show that they have the same sample values, we set t = nT, with T = 1/f

s

= 1/5 sec. Then,

x(nT)= 10sin(2πn/5)+10sin(8πn/5)+5sin(12πn/5)

But,

sin(8πn/5)= sin(2πn −2πn/5)= −sin(2πn/5)

and

sin(12πn/5)= sin(2πn +2πn/5)= sin(2πn/5)

Thus,

x(nT) = 10sin(2πn/5)−10sin(2πn/5)+5sin(2πn/5)

= 5sin(2πn/5)= x

a

(nT).

If f

s

= 10 Hz, then the Nyquist interval is [−5, 5] Hz and only f

3

lies outside it. It will be aliased

with f

3

−f

s

= 6 −10 = −4 resulting in the aliased signal:

x

a

(t)= 10sin(2πt)+10sin(8πt)+5sin(2π(−4)t)= 10sin(2πt)+5sin(8πt)

Problem 1.3

Using the trig identity 2sinαsinβ = cos(α−β)−cos(α+β), we ﬁnd:

x(t) = cos(5πt)+4sin(2πt)sin(3πt)= cos(5πt)+2[cos(πt)−cos(5πt)]

= 2cos(πt)−cos(5πt)

The frequencies in the signal are f

1

= 0.5 and f

2

= 2.5 kHz. The Nyquist interval is [−1.5, 1.5]

kHz, and f

2

lies outside it. Thus, it will be aliased with f

2a

= 2.5 − 3 = −0.5 giving rise to the

signal:

1

x

a

(t)= 2cos(2πf

1

t)−cos(2πf

2a

t)= 2cos(πt)−cos(−πt)= cos(πt)

A class of signals aliased with x(t) and x

a

(t) is obtained by replacing f

1

and f

2

by their shifted

versions: f

1

+mf

s

, f

2

+nf

s

resulting in:

x

mn

(t)= 2cos(πt +6πmt)−cos(πt −6πnt)

Problem 1.4

Using a trig identity, we write x(t)= cos(8πt)+cos(10πt)+cos(2πt). The frequencies con-

tained in x(t) are thus, 1 Hz, 4 Hz, and 5 Hz. If the sampling rate is 5 Hz, then the Nyquist

interval is [−2.5, 2.5] Hz, and therefore, the 4 Hz and 5 Hz components lie outside it and will be

aliased with the frequencies 4 −5 = −1 Hz and 5 −5 = 0 Hz, etc.

Problem 1.5

Using trig identities we ﬁnd:

x(t)= sin(6πt)

_

1 +2cos(4πt)

_

= sin(6πt)+sin(10πt)+sin(2πt)

with frequency content: f

1

= 3, f

2

= 5, f

3

= 1 kHz. The Nyquist interval is [−2, 2] kHz, and the

aliased frequencies are:

f

1a

= f

1

−f

s

= 3 −4 = −1, f

2a

= f

2

−f

s

= 5 −4 = 1, f

3a

= f

3

= 1

Thus,

x

a

(t)= sin(−2πt)+sin(2πt)+sin(2πt)= sin(2πt)

Problem 1.6

Use the trigonometric identity 2cos acos b = cos(a +b)+cos(a −b) three times to get

x(t) = 2[cos(10πt)+cos(6πt)]cos(12πt)

= cos(22πt)+cos(2πt)+cos(18πt)+cos(6πt)

The frequencies present in this signal are f

1

= 11, f

2

= 1, f

3

= 9, and f

4

= 3 Hz. With a sampling

rate of 10 Hz, only f

1

and f

3

lie outside the Nyquist interval [−5, 5] Hz, and they will be aliased

with f

1

−f

s

= 11 −10 = 1 Hz and f

3

−f

s

= 9 −10 = −1 Hz. The aliased signal will be:

x

a

(t) = cos(2π(1)t)+cos(2πt)+cos(2π(−1)t)+cos(6πt)

= 3cos(2πt)+cos(6πt)

To prove the equality of the samples, replace t = nT = n/10, because T = 1/f

s

= 1/10. Then,

x(nT)= cos(22πn/10)+cos(2πn/10)+cos(18πn/10)+cos(6πn/10)

But, cos(22πn/10)= cos(2πn+2πn/10)= cos(2πn/10) and similarly, cos(18πn/10)= cos(2πn−

2πn/10)= cos(2πn/10). Therefore, the sample values become

2

x(nT) = cos(2πn/10)+cos(2πn/10)+cos(2πn/10)+cos(6πn/10)

= 3cos(2πn/10)+cos(6πn/10)= x

a

(nT)

If f

s

= 12 Hz, then f

1

and f

3

will lie outside of [−6, 6] and will be aliased with 11 −12 = −1 and

9 −12 = −3. The aliased signal will be:

x

a

(t) = cos(2π(−1)t)+cos(2πt)+cos(2π(−3)t)+cos(6πt)

= 2cos(2πt)+2cos(6πt)

Problem 1.7

We use the same technique as in the square-wave Example 1.4.6. At a sampling rate of 8 Hz, the

signal frequencies of

¦1, 3, 5, 7, 9, 11, 13, 15, . . . ¦

will be aliased with:

¦1, 3, −3, −1, 1, 3, −3, −1, . . . ¦

Therefore only sin(2πt) and sin(6πt) terms will appear in the aliased signal. Thus, we write it

in the form:

x

a

(t)= Bsin(2πt)+Csin(6πt)

To determine B and C, we demand that x

a

(t) and x(t) agree at the sampling instants t = nT =

n/8, because T = 1/f

s

= 1/8 sec. Therefore, we demand

Bsin(2πn/8)+Csin(6πn/8)= x(n/8)

Setting n = 1, 2, we get two equations

Bsin(2π/8)+Csin(6π/8)= x(1/8)= 0.5

Bsin(4π/8)+Csin(12π/8)= x(2/8)= 1

⇒

B

1

√

2

+C

1

√

2

= 0.5

B −C = 1

The values for x(1/8) and x(2/8) were obtained by inspecting the triangular waveform. Solving

for B and C, we ﬁnd:

B =

√

2 +2

4

, C =

√

2 −2

4

Problem 1.8

For f

s

= 5 kHz, we have:

x

a

(t)= sin(2πf

1

t)

For f

s

= 10 kHz, we have:

x

a

(t)= 2sin(2πf

1

t)+sin(2πf

2

t)

3

Fig. P1.1 Parts (a,b) of Problem 1.8.

Problem 1.9

The audible and inaudible parts are:

x(t)= sin(10πt)+sin(20πt)

. ¸, .

audible

+sin(60πt)+sin(90πt)

. ¸, .

inaudible

The frequencies of the four terms and their aliased versions are:

f

A

= 5

f

B

= 10

f

C

= 30

f

D

= 45

⇒

f

Aa

= 5

f

Ba

= 10

f

Ca

= 30 −40 = −10

f

Da

= 45 −40 = 5

a. When there is no preﬁlter the aliased signal at the output of the reconstructor will be:

y

a

(t)= sin(10πt)+sin(20πt)+sin(−20πt)+sin(10πt)= 2sin(10πt)

b. When there is a perfect preﬁlter, the f

C

, f

D

components are removed prior to sampling

thus, the sampled and reconstructed signal will remain unchanged, that is, the audible

part of x(t):

y

a

(t)= sin(10πt)+sin(20πt)

c. The attenuations introduced by the practical preﬁlter shown in Fig. P1.2 are obtained by

determining the number of octaves to the frequencies f

C

, f

D

and multiplying by the ﬁlter’s

attenuation of 48 dB/octave:

log

2

_

f

C

f

s

/2

_

= log

2

_

30

20

_

= 0.585 ⇒ A

C

= 48 ×0.585 = 28.08 dB

log

2

_

f

D

f

s

/2

_

= log

2

_

45

20

_

= 1.170 ⇒ A

D

= 48 ×1.170 = 56.16 dB

and in absolute units:

4

¦H

C

¦ = 10

−A

C

/20

= 10

−28.08/20

= 0.0394

¦H

D

¦ = 10

−A

D

/20

= 10

−56.16/20

= 0.0016

Thus, the resulting reconstructed signal will be:

y

a

(t) = sin(10πt)+sin(20πt)+¦H

C

¦ sin(−20πt)+¦H

D

¦ sin(10πt)

= 1.0016sin(10πt)+0.9606sin(20πt)

which agrees closely with the audible part of x(t).

10 30 20 45

48 dB/octave

Analog Prefilter

kHz

f

H(f)

0

A B

C

D

Fig. P1.2 Preﬁlter speciﬁcations of Problem 1.9.

Problem 1.10

The Fourier series expansion of the periodic function s(t) is:

s(t)=

∞

_

m=−∞

c

m

e

2πjmt/T

, c

m

=

1

T

_

T/2

−T/2

s(t)e

−2πjmt/T

dt

But within the basic period [−T/2, T/2], s(t) equals δ(t). Thus,

c

m

=

1

T

_

T/2

−T/2

δ(t)e

−2πjmt/T

dt =

1

T

Using the delta function integral representation:

_

∞

−∞

e

−2πjft

dt = δ(f)

we ﬁnd:

S(f) =

_

∞

−∞

s(t)e

−2πjft

dt =

1

T

∞

_

m=−∞

_

∞

−∞

s(t)e

−2πj(f−mfs)t

dt

=

1

T

∞

_

m=−∞

δ(f −mf

s

)

Problem 1.11

This is simply the Fourier series expansion of the periodic function

X(f) in the variable f, and

x(nT) are the Fourier series expansion coefﬁcients calculated by integrating over one period,

that is, over [−f

s

/2, f

s

/2].

5

Problem 1.12

Write x(t)= 0.5e

2πjf0t

+0.5e

−2πjf0t

, with Fourier transform:

X(f)= 0.5δ(f −f

0

)+0.5δ(f +f

0

)

Its replication gives the spectrum of the sampled signal:

X(f) =

1

T

∞

_

m=−∞

X(f −mf

s

)=

1

2T

∞

_

m=−∞

_

δ(f −mf

s

−f

0

)+δ(f −mf

s

+f

0

)

_

=

1

2T

∞

_

m=−∞

_

δ(f −mf

s

−f

0

)+δ(f +mf

s

+f

0

)

_

where in the second term, we changed the summation index from m to −m.

Problem 1.13

We have for the complex sinusoid, the Laplace, Fourier, and magnitude spectra:

x(t)= e

−at

e

2πjf0t

= e

−(a−2πjf0)t

, t ≥ 0

X(s)=

1

s +a −2πjf

0

X(f)=

1

a +2πj(f −f

0

)

⇒ ¦X(f)¦

2

=

1

a

2

+4π

2

(f −f

0

)

2

The length-L sampled signal x(nT)= e

−(a−2πjf0)nT

, n = 0, 1, . . . , L −1 has spectrum:

X

L

(f) =

L−1

_

n=0

x(nT)e

−2πjfnT

=

L−1

_

n=0

e

−(a+2πj(f−f0))nT

=

1 −e

−(a+2πj(f−f0))LT

1 −e

−(a+2πj(f−f0))T

with magnitude spectrum:

¦

X

L

(f)¦

2

=

1 −2e

−aLT

cos

_

2π(f −f

0

)LT

_

+e

−2aLT

1 −2e

−aT

cos

_

2π(f −f

0

)T

_

+e

−2aT

In the limit L → ∞, we have e

−aLT

→ 0 and obtain the sampled spectrum of the inﬁnitely long

signal:

X(f)=

∞

_

n=0

x(nT)e

−2πjfnT

=

1

1 −e

−(a+2πj(f−f0))T

with magnitude spectrum:

¦

X(f)¦

2

=

1

1 −2e

−aT

cos

_

2π(f −f

0

)T

_

+e

−2aT

The continuous time limit T →0 of

X(f) gives rise to the analog spectrum:

6

lim

T→0

T

X(f)= lim

T→0

T

1 −e

−(a+2πj(f−f0))T

=

1

a +2πj(f −f

0

)

= X(f)

Fig. P1.3 shows the required spectra. From the left graph, we see that as f

s

increases, the sampled

spectrum agrees more closely with the analog spectrum within the Nyquist interval. From the

right graph, we see that the spectrum of the truncated sampled signal has ripples that follow the

general shape of

X(f). As L →∞, the sampled spectrum

X

L

(f) will tend to

X(f), which is only

an approximation of the true spectrum even within the Nyquist interval.

Fig. P1.3 Spectra of analog, sampled, and windowed signals of Problem 1.13.

In the case of real-valued signals, we will also get the spectral peaks at the negative frequency

−f

0

. If f

0

is small, the peaks at :f

0

will inﬂuence each other somewhat, but apart from that the

same conclusions can be drawn about the sampled signals.

Problem 1.14

This is the same as Example 1.5.4. In units of dB per decade, the attenuations due to the signal

and ﬁlter combine to give:

A(f)= αlog

10

_

f

f

max

_

+βlog

10

_

f

f

max

_

= γlog

10

_

f

f

max

_

where γ = α+β. The requirement A(f

s

−f

max

)≥ A gives:

γlog

10

_

f

s

−f

max

f

max

_

≥ A ⇒ f

s

≥ f

max

+f

max

10

A/γ

Problem 1.15

The ﬁrst replica of X

in

(f), shifted to f

s

, will have spectrum:

¦X

in

(f −f

s

)¦ =

1

_

1 +

_

0.1(f −f

s

)

_

8

Its value at the passband frequency f

pass

= f

max

= 20 kHz will be:

7

¦X

in

(f

max

−f

s

)¦ =

1

_

1 +

_

0.1(f

max

−f

s

)

_

8

This must be suppressed by A = 60 dB relative to ¦X

in

(f

max

)¦, thus, we require:

−10log

10

¸

¸

¸

¸

¸

X

in

(f

max

−f

s

)

X

in

(f

max

)

¸

¸

¸

¸

¸

2

= A ⇒ 10log

10

_

1 +

_

0.1(f

max

−f

s

)

_

8

1 +(0.1f

max

)

8

_

= 60

which can be solved for f

s

to give f

s

= 132.52 kHz. Using the preﬁlter, we require that its

passband attenuation be A

pass

= 1 dB at f

pass

= f

max

= 20 kHz, that is,

−10log

10

¦H(f

max

)¦

2

= 10log

10

_

1 +(f

max

/f

0

)

6

_

= A

pass

which can be solved for f

0

to give f

0

= 25.05 kHz. The preﬁltered signal that gets sampled is now

¦X(f)¦ = ¦H(f)X

in

(f)¦ =

1

_

1 +(f/f

0

)

6

1

_

1 +(0.1f)

8

Its ﬁrst replica ¦X(f −f

s

)¦ is required to be suppressed by A = 60 dB at f

max

−10log

10

¸

¸

¸

¸

¸

X(f

max

−f

s

)

X(f

max

)

¸

¸

¸

¸

¸

2

= A,

f f

s

f

s

-f

max f

max

A

|X( f

max

)|

0

|X( f

s

-f

max

)| |X( f

max

-f

s

)| =

which gives the condition

10log

10

_

1 +

_

(f

max

−f

s

)/f

0

_

6

1 +(f

max

/f

0

)

6

·

1 +

_

0.1(f

max

−f

s

)

_

8

1 +(0.1f

max

)

8

_

= A (P1.1)

It can be solved approximately by ignoring the +1 in the numerators, that is,

10log

10

__

(f

max

−f

s

)/f

0

_

6

1 +(f

max

/f

0

)

6

·

_

0.1(f

max

−f

s

)

_

8

1 +(0.1f

max

)

8

_

= 60 dB (P1.2)

which gives f

s

= 80.1 kHz. The exact solution of Eq. (P1.1) is f

s

= 80.0633 kHz. The ﬁrst factor

in Eq. (P1.2) represents the stopband attenuation due to the ﬁlter, and the second the attenuation

due to the signal. With f

s

= 80.1 kHz, we have

10log

10

_

1 +

_

(f

max

−f

s

)/f

0

_

6

1 +(f

max

/f

0

)

6

_

= A

stop

= 21.8 dB

10log

10

_

1 +

_

0.1(f

max

−f

s

)

_

8

1 +(0.1f

max

)

8

_

= A−A

stop

= 38.2 dB

Thus, the use of the preﬁlter enables us to reduce the sampling rate from 132 kHz to 80 kHz.

Note also, that for large f, the spectrum ¦X(f)¦ follows the power law

¦X(f)¦

2

=

1

1 +(f/f

0

)

6

·

1

1 +(0.1f)

8

≈

const.

f

6

·

const.

f

8

=

const.

f

14

giving rise to an effective attenuation

8

−10log

10

¦X(f)¦

2

= γlog

10

f +const.

where γ = 140 dB/decade, of which 60 dB/decade is due to the ﬁ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

f

s

= f

max

+10

A/γ

f

max

= 20+20· 10

60/140

= 73.65 kHz, which is fairly close to the more accurate

value of 80 kHz.

Problem 1.16

The passband condition at f = f

max

= 20 kHz is:

10log

10

_

1 +(f

max

/f

0

)

2N

_

= A

pass

(P1.3)

which can be solved for f

0

in terms of N as follows:

f

2N

0

=

f

2N

max

r −1

, where r = 10

Apass/10

The antialiasing condition, replacing Eq. (P1.1), is now

10log

10

_

1 +

_

(f

max

−f

s

)/f

0

_

2N

1 +(f

max

/f

0

)

2N

·

1 +

_

0.1(f

max

−f

s

)

_

8

1 +(0.1f

max

)

8

_

= A

or,

1 +

_

(f

max

−f

s

)/f

0

_

2N

1 +(f

max

/f

0

)

2N

·

1 +

_

0.1(f

max

−f

s

)

_

8

1 +(0.1f

max

)

8

= 10

A/10

Replacing f

2N

0

by its expression above, we obtain

1 +

_

(f

max

−f

s

)/f

max

_

2N

(r −1)

r

·

1 +

_

0.1(f

max

−f

s

)

_

8

1 +(0.1f

max

)

8

= 10

A/10

and solving for N, we have

N =

ln

_

10

A/10

rR(f

s

)−1

r −1

_

2ln

_

f

s

−f

max

f

max

_ (P1.4)

where R(f

s

) is deﬁned by

R(f

s

)=

1 +(0.1f

max

)

8

1 +

_

0.1(f

max

−f

s

)

_

8

Eq. (P1.4) gives the minimum preﬁlter order for a desired suppression level A and rate f

s

. With

f

s

= 70 kHz, A = 60 dB, A

pass

= 1 dB, we ﬁnd

r = 10

Apass/10

= 10

0.1

= 1.259, 10

A/10

R(f

s

)= 657.918

and

N =

ln(3194.281)

2ln(50/20)

= 4.403 ⇒ N = 5

We calculate also f

0

= f

max

/(r −1)

1/2N

= 22.9 kHz.

9

Fig. P1.4 Butterworth order versus sampling rate.

Problem 1.17

Figure P1.4 shows a plot of N given by Eq. (P1.4) as a function of f

s

for different choices of A.

Notice the two data points on the A = 60 curve at f

s

= 70 and f

s

= 80 kHz that were computed

in this and the last example. It is evident from this graph that the complexity of the preﬁlter

increases with A, at any ﬁxed f

s

; and that it decreases with f

s

, for ﬁxed A.

Problem 1.18

Using the results of Problem1.14, we solve for the combined attenuation γ of signal and preﬁlter:

A = γlog

10

_

f

s

−f

max

f

max

_

⇒

where A = 60 dB, f

s

= 30 kHz and f

max

= 10 kHz. We ﬁnd:

γ =

A

log

10

_

f

f

max

_ =

60

log

10

_

30 −10

10

_ = 200

Because the signal has α = 80 dB/decade, we ﬁnd the ﬁlter’s attenuation:

β = γ −α = 200 −80 = 120 dB/decade

which translates into a ﬁlter order:

β = 20N ⇒ N = β/20 = 120/20 = 6

If we increase the sampling rate to 50 kHz, the combined attenuation will be γ = 100, which gives

β = 100 −80 = 20 dB/decade and order N = β/20 = 1.

Problem 1.19

This problem is the generalization of Prob. 1.15. If we do not use a preﬁlter, the requirement

that the aliased components (of the 1st replica) be suppressed by A dB relative to the signal

components can be expressed in the form:

10

¦X

in

(f

s

−f

max

)¦

2

¦X

in

(f

max

)¦

2

= 10

−A/10

Inserting the given expression for ¦X

in

(f)¦, we get the desired equation for f

s

in terms of A and

f

max

:

1 +(f

max

/f

a

)

2Na

1 +

_

(f

s

−f

max

)/f

a

_

2Na

= 10

−A/10

If we use a Butterworth preﬁlter of order N:

¦H(f)¦

2

=

1

1 +(f/f

0

)

2N

then, the 3-dB frequency f

0

is determined by requiring that at the edge of the passband the

attenuation be B dB:

¦H(f

max

)¦

2

=

1

1 +(f

max

/f

0

)

2N

= 10

−B/10

The ﬁltered input that gets sampled will now have spectrum X(f)= H(f)X

in

(f), which gives:

¦X(f)¦

2

= ¦H(f)¦

2

¦X

in

(f)¦

2

=

1

1 +(f/f

0

)

2N

·

1

1 +(f/f

a

)

2Na

The antialiasing condition ¦X(f

s

−f

max

)¦

2

= 10

−A/10

¦X(f)¦

2

gives now:

1

1 +

_

(f

s

−f

max

)/f

0

_

2N

·

1

1 +

_

(f

s

−f

max

)/f

a

_

2Na

= 10

−A/10

·

1

1 +(f

max

/f

0

)

2N

·

1

1 +(f

max

/f

a

)

2Na

Using the asymptotic forms of the spectra, valid for large f’s, that is,

¦X

in

(f)¦

2

=

1

(f/f

a

)

2Na

, ¦H(f)¦

2

=

1

(f/f

0

)

2N

the antialiasing condition would read:

(f

s

−f

max

)

2N

f

2N

0

·

(f

s

−f

max

)

2Na

f

2Na

a

= 10

−A/10

f

2N

max

f

2N

0

·

f

2Na

max

f

2Na

a

which simpliﬁes into:

_

f

s

−f

max

f

max

_

2(N+Na)

= 10

A/10

or,

f

s

= f

max

+f

max

10

A/20(N+Na)

It agrees with the results of Problem 1.14, with γ = α+β = 20N

a

+20N. For any ﬁxed desired

value of A, the limit N →∞ gives

f

s

= f

max

+f

max

10

A/20(N+Na)

→f

max

+f

max

= 2f

max

In this case, the Butterworth ﬁlter resembles more and more a brick-wall ﬁlter with cutoff f

max

.

11

Problem 1.20

The linear relationship between N and A follows from the approximation of Problem 1.19:

_

f

s

−f

max

f

max

_

2(N+Na)

= 10

A/10

or,

2(N+N

a

)log

10

_

f

s

−f

max

f

max

_

=

A

10

Problem 1.21

The presence of P(f) is called the aperture effect. The replicas of X(f) embedded in

X(f) will

still be present, but they will be weighted by P(f). The need for using antialiasing preﬁlters to

avoid overlapping of replicas remains the same. For a pulse of width τ, we have:

¦P(f)¦ = τ

¸

¸

¸

¸

¸

sin(πfτ)

πfτ

¸

¸

¸

¸

¸

Therefore, the narrower the width τ the ﬂatter the spectrum P(f). If τ < T, then P(f) will be

essentially ﬂat within the Nyquist interval, thus, leaving the central replica almost unchanged.

Fig. P1.5 shows P(f) relative to the replicas of

X(f) for the case τ = T/5.

|P(f)|

f

s

5f

s

-5f

s

-f

s

0

f

Fig. P1.5 Butterworth order versus sampling rate.

Problem 1.22

The stopband frequency of the postﬁlter is: f

stop

= f

s

− f

c

= 6 − 1 = 5 kHz. At this frequency,

the attenuation of the staircase DAC is

A

DAC

= −20log

10

¸

¸

¸

¸

¸

sin(πf

stop

/f

s

)

πf

stop

/f

s

¸

¸

¸

¸

¸

= 14.4 dB

Thus, the stopband attenuation of the postﬁlter at f = f

stop

must be:

A

stop

= A−A

DAC

= 40 −14.4 = 25.6 dB

Problem 1.23

Using convolution in the time domain, we get:

x

a

(t) =

_

∞

−∞

h(t −t

¹

)ˆ x(t

¹

) dt

¹

=

_

n

x(nT)

_

∞

−∞

h(t −t

¹

)δ(t

¹

−nT) dt

¹

=

_

n

x(nT)h(t −nT)

12

Working in the frequency domain we have:

X

a

(f)= H(f)

X(f)=

_

n

x(nT)

_

e

−2πjfnT

H(f)

_

Using the delay theorem of Fourier transforms, we recognize the term in the bracket as the FT of

h(t −nT). Thus, going to the time domain, we get:

x

a

(t)=

_

n

x(nT)h(t −nT)

Problem 1.24

Start with a complex sinusoid x(t)= e

2πjf0t

. Its sampled spectrum will be:

X(f)=

1

T

∞

_

m=−∞

X(f −mf

s

)=

1

T

∞

_

m=−∞

δ(f −f

0

−mf

s

)

The spectrum of the reconstructed analog signal will be then:

X

rec

(f)= H(f)

X(f)=

1

T

∞

_

m=−∞

H(f)δ(f −f

0

−mf

s

)=

1

T

∞

_

m=−∞

H(f

0

+mf

s

)δ(f −f

0

−mf

s

)

Taking inverse Fourier transforms, we ﬁnd:

x

rec

(t)=

1

T

∞

_

m=−∞

H(f

0

+mf

s

)e

2πj(f0+mfs)t

Thus, f

m

= f

0

+mf

s

. Writing

1

T

H(f

m

)= A

m

e

jθm

, so that A

m

=

1

T

¦H(f

m

)¦, θ

m

= arg H(f

m

)

we have:

x

rec

(t)=

∞

_

m=−∞

A

m

e

2πj(f0+mfs)t+jθm

Taking imaginary parts, we ﬁnd for the real sinusoidal case:

x

rec

(t)=

∞

_

m=−∞

A

m

sin

_

2π(f

0

+mf

s

)t +θ

m

_

Assuming ¦f

0

¦ < f

s

/2, for the staircase reconstructor we have:

1

T

H(f

m

)=

sin(πf

m

T)

πf

m

T

e

−jπfmT

and because πf

m

T = πf

0

T +mπ, we have:

1

T

H(f

m

)=

sin(πf

0

T)

πf

m

T

e

−jπf0T

Thus,

A

m

=

sin(πf

0

T)

πf

m

T

, θ

m

= −πf

0

T

For the ideal reconstructor, we have θ

m

= 0 and A

m

= 0 except at m= 0 where A

0

= 1, that is,

A

m

= δ

m

. Thus,

x

rec

(t)=

∞

_

m=−∞

δ

m

sin

_

2π(f

0

+mf

s

)t

_

= sin(2πf

0

t)

13

Problem 1.25

Take the linear combination of the results of the single sinusoid case of Eq. (1.6.12).

14

Chapter 2 Problems

Problem 2.1

The quantized values are:

analog value quantized value DAC output

2.9 2 0 0 1

3.1 4 0 1 0

3.7 4 0 1 0

4 4 0 1 0

-2.9 -2 1 1 1

-3.1 -4 1 1 0

-3.7 -4 1 1 0

-4 -4 1 1 0

For the offset binary case, complement the ﬁrst bit in this table.

Problem 2.2

Filling the table, we have

n x(n) x

Q

(n) offset binary 2’s complement

0 0.000 0.000 1 0 0 0 0 0 0 0

1 1.243 1.000 1 0 0 1 0 0 0 1

2 2.409 2.000 1 0 1 0 0 0 1 0

3 3.423 3.000 1 0 1 1 0 0 1 1

4 4.222 4.000 1 1 0 0 0 1 0 0

5 4.755 5.000 1 1 0 1 0 1 0 1

6 4.990 5.000 1 1 0 1 0 1 0 1

7 4.911 5.000 1 1 0 1 0 1 0 1

8 4.524 5.000 1 1 0 1 0 1 0 1

9 3.853 4.000 1 1 0 0 0 1 0 0

10 2.939 3.000 1 0 1 1 0 0 1 1

11 1.841 2.000 1 0 1 0 0 0 1 0

12 0.627 1.000 1 0 0 1 0 0 0 1

13 -0.627 -1.000 0 1 1 1 1 1 1 1

14 -1.841 -2.000 0 1 1 0 1 1 1 0

15 -2.939 -3.000 0 1 0 1 1 1 0 1

16 -3.853 -4.000 0 1 0 0 1 1 0 0

17 -4.524 -5.000 0 0 1 1 1 0 1 1

18 -4.911 -5.000 0 0 1 1 1 0 1 1

19 -4.990 -5.000 0 0 1 1 1 0 1 1

Problem 2.3

With R = 10 volts and e

rms

≤ 10

−3

volts, we have using Q =

√

12e

rms

:

2

B

=

R

Q

=

R

√

12e

rms

≥

10

√

12 · 10

−3

which gives

15

B ≥ log

2

_

10

√

12 · 10

−3

_

= 11.495

Therefore, B = 12. The actual rms error will be

e

rms

=

R

2

B

√

12

=

10

2

12

√

12

= 0.705 mvolt.

The dynamic range will be 6B = 6 · 12 = 72 dB.

Problem 2.4

At 44.1 kHz sampling rate, one minute of music has 60 sec containing 60×44100 samples. And,

for two stereo channels, 2 × 60 × 44100 samples. If each sample is quantized with 16 bits, the

total number of bits will be

2 ×60 ×44100 ×16 bits

or, dividing by 8 we get the total number of bytes:

2 ×60 ×44100 ×16

8

bytes

Dividing by 1024, we get kbytes and by another 1024, Mbytes:

2 ×60 ×44100 ×16

8 ×1024 ×1024

= 10.09 Mbytes

Problem 2.5

Following similar steps as in the previous problem, we have for part (a):

(3 ×60 sec)(16 channels)(48000 samples/sec)(20 bits/sample)

(8 bits/byte)(1024

2

bytes/Mbyte)

= 330 Mbytes

that is, practically the entire hard disk of a typical home PC. For part (b), if in each channel we

must perform N

MAC

= 35 operations on each sample, then these operations must be ﬁnished

during the sampling interval T = 1/f

s

between samples:

N

MAC

T

MAC

≤ T ⇒ T

MAC

≤

T

N

MAC

=

1

N

MAC

f

s

which gives for the time per MAC:

T

MAC

=

1

35 · 48 kHz

= 0.595 · 10

−3

msec = 595 nsec

This is plenty of time for today’s DSP chips, which can perform a MAC operation within 30–80

nsec. If a single DSP chip handles all 16 channels, then the total number of MACs that must be

performed within the sampling interval T are 16N

MAC

. This gives:

T

MAC

=

1

16 · 35 · 48 kHz

=

595

16

= 37 nsec

which is just within the capability of the fastest DSP chips.

In practice, a typical professional digital recording system would require the processing and

mixing of at least 32 channels. The above results suggest that one use at least two DSPs to

multiplex the required operations.

16

Problem 2.6

The mean is

m

e

=

_

0

−Q

ep(e) de =

1

Q

_

0

−Q

ede = −

Q

2

and the variance:

σ

2

e

= E[(e −m

e

)

2

]=

_

0

−Q

(e −m

e

)

2

p(e) de =

1

Q

_

0

−Q

_

e +

Q

2

_

2

de =

Q

2

12

Problem 2.7

Solving Eq. (2.2.10) for L in terms of ΔB, we ﬁnd:

L =

_

2

2ΔB

π

2p

2p +1

_ 1

2p+1

(P2.1)

With ΔB = 15 and p = 1, 2, 3, we ﬁnd:

L = 1523, 116, 40

The oversampled audio rates will be, with f

s

= 44.1 kHz:

Lf

s

= 67.164, 5.114, 1.764 MHz

Problem 2.8

Using Eq. (P2.1) with ΔB = 7 bits and p = 1, 2, 3, we ﬁnd:

L = 38, 13, 8

The oversampled speech rates will be, with f

s

= 8 kHz:

Lf

s

= 304, 104, 48 kHz

Problem 2.9

Replacing b

1

= 1 −b

1

, we have:

x

Q

= R(b

1

2

−1

+b

2

2

−2

+· · · +b

B

2

−B

−0.5)

= R

_

(1 −b

1

)2

−1

+b

2

2

−2

+· · · +b

B

2

−B

−0.5

_

= R

_

−b

1

2

−1

+b

2

2

−2

+· · · +b

B

2

−B

_

where the ﬁrst 2

−1

canceled the last −0.5.

Problem 2.10

As an example, consider the polynomial of degree M = 3: B(z)= b

0

+b

1

z+b

2

z

2

+b

3

z

3

. Iterating

the algorithm for i = 3, 2, 1, 0, we ﬁnd:

p = 0

p = ap +b

3

= b

3

p = ap +b

2

= ab

3

+b

2

p = ap +b

1

= a(ab

3

+b

2

)+b

1

= a

2

b

3

+ab

2

+b

1

p = ap +b

0

= a(a

2

b

3

+ab

2

+b

1

)+b

0

= a

3

b

3

+a

2

b

2

+ab

1

+b

0

= B(a)

17

Problem 2.11

/* pol.c - polynomial evaluator */

double pol(M, b, a)

int M;

double *b, a;

int i;

double p = 0;

for (i=M; i>=0; i--)

p = a * p + b[i];

return p;

Problem 2.12

Consider the division of B(z) by (z −a):

B(z)= (z −a)Q(z)+R

where the quotient polynomial Q(z) must have degree M− 1, and the remainder R must be a

constant. Indeed, setting z = a, gives R = b(a). So the objective of the algorithm is to compute

R iteratively. Inserting the polynomial expressions we have:

b

M

z

M

+b

M−1

z

M−1

+· · · +b

1

z +b

0

= (z −a)(q

M−1

z

M−1

+q

M−2

z

M−2

+· · · +q

1

z +q

0

)+R

Equating like powers of z, we ﬁnd:

b

M

= q

M−1

b

M−1

= q

M−2

−aq

M−1

b

M−2

= q

M−3

−aq

M−2

· · ·

b

1

= q

0

−aq

1

b

0

= R−aq

0

⇒

q

M−1

= b

M

q

M−2

= aq

M−1

+b

M−1

q

M−3

= aq

M−2

+b

M−2

· · ·

q

0

= aq

1

+b

1

R = aq

0

+b

0

Problem 2.13

For a polynomial of degree M = 3, B(z)= b

1

z +b

2

z

2

+b

3

z

3

, we iterate the algorithm for i = 3,

2, 1:

p = 0

p = a(p +b

3

)= ab

3

p = a(p +b

2

)= a(ab

3

+b

2

)= a

2

b

3

+ab

2

p = a(p +b

1

)= a(a

2

b

3

+ab

2

+b

1

)= a

3

b

3

+a

2

b

2

+ab

1

= B(a)

18

natural binary offset binary 2’s C

b

1

b

2

b

3

b

4

m x

Q

= Qm m

¹

x

Q

= Qm

¹

b

1

b

2

b

3

b

4

— 16 8.0 8 4.0 —

1 1 1 1 15 7.5 7 3.5 0 1 1 1

1 1 1 0 14 7.0 6 3.0 0 1 1 0

1 1 0 1 13 6.5 5 2.5 0 1 0 1

1 1 0 0 12 6.0 4 2.0 0 1 0 0

1 0 1 1 11 5.5 3 1.5 0 0 1 1

1 0 1 0 10 5.0 2 1.0 0 0 1 0

1 0 0 1 9 4.5 1 0.5 0 0 0 1

1 0 0 0 8 4.0 0 0.0 0 0 0 0

0 1 1 1 7 3.5 −1 −0.5 1 1 1 1

0 1 1 0 6 3.0 −2 −1.0 1 1 1 0

0 1 0 1 5 2.5 −3 −1.5 1 1 0 1

0 1 0 0 4 2.0 −4 −2.0 1 1 0 0

0 0 1 1 3 1.5 −5 −2.5 1 0 1 1

0 0 1 0 2 1.0 −6 −3.0 1 0 1 0

0 0 0 1 1 0.5 −7 −3.5 1 0 0 1

0 0 0 0 0 0.0 −8 −4.0 1 0 0 0

Table P2.1 Converter codes for B = 4 bits, R = 8 volts.

Problem 2.14

The quantization width is Q = R/2

B

= 8/2

4

= 0.5 volts. Table P2.1 shows the quantization

levels and their binary codes.

To convert x = 1.2 by rounding, we shift it by half the quantization spacing y = x + Q/2 =

1.2 +0.25 = 1.45. The following tables show the successive approximation tests for the natural

and offset binary cases. The 2’s complement case is obtained by complementing the MSB of the

offset case.

test b

1

b

2

b

3

b

4

x

Q

C = u(y −x

Q

)

b

1

1 0 0 0 4.0 0

b

2

0 1 0 0 2.0 0

b

3

0 0 1 0 1.0 1

b

4

0 0 1 1 1.5 0

0 0 1 0 1.0

test b

1

b

2

b

3

b

4

x

Q

C = u(y −x

Q

)

b

1

1 0 0 0 0.0 1

b

2

1 1 0 0 2.0 0

b

3

1 0 1 0 1.0 1

b

4

1 0 1 1 1.5 0

1 0 1 0 1.0

The natural binary and 2’C cases agree because x lies in the positive range of both quantizers.

For x = 5.2, we have y = x +Q/2 = 5.45. The tests are shown below:

test b

1

b

2

b

3

b

4

x

Q

C = u(y −x

Q

)

b

1

1 0 0 0 4.0 1

b

2

1 1 0 0 6.0 0

b

3

1 0 1 0 5.0 1

b

4

1 0 1 1 5.5 0

1 0 1 0 5.0

test b

1

b

2

b

3

b

4

x

Q

C = u(y −x

Q

)

b

1

1 0 0 0 0.0 1

b

2

1 1 0 0 2.0 1

b

3

1 1 1 0 3.0 1

b

4

1 1 1 1 3.5 1

1 1 1 1 3.5

For the 2’C case, the quantizer saturates to its maximum positive value. Finally, for x = −3.2, we

have y = −2.95, and the following testing tables:

19

test b

1

b

2

b

3

b

4

x

Q

C = u(y −x

Q

)

b

1

1 0 0 0 4.0 0

b

2

0 1 0 0 2.0 0

b

3

0 0 1 0 1.0 0

b

4

0 0 0 1 0.5 0

0 0 0 0 0.0

test b

1

b

2

b

3

b

4

x

Q

C = u(y −x

Q

)

b

1

1 0 0 0 0.0 0

b

2

0 1 0 0 −2.0 0

b

3

0 0 1 0 −3.0 1

b

4

0 0 1 1 −2.5 0

0 0 1 0 −3.0

In this case, the natural binary scale saturates to its minimum positive value.

Problem 2.15

Similar to the testing tables of Examples 2.4.1 and 2.4.2.

Problem 2.16

These versions are straight forward. To implement truncation instead of rounding, replace the

statement within adc:

y = x + Q/2;

by

y = x;

Problem 2.17

This problem is basically the same as Example 2.4.5. The same program segment of that example

applies here for generating the codes and quantized values. Only the full-scale range is different,

R = 32 volts. In part (c), the amplitude of the sinusoid A = 20 exceeds the quantizer range

R/2 = 16, and therefore both the positive and negative peaks of the sinusoid will saturate to the

positive and negative maxima of the quantizer.

Problem 2.18

The following C program carries out all the required operations. It uses the routine corr of

Appendix A.1 to compute all the sample autocorrelations and cross-correlations.

/* exmpl246.c - quantization noise model

*

* default values:

* N=10 bits

* R=1024

* L=1000, iseed=10, M=50

*/

#include <stdio.h>

#include <math.h>

#include <stdlib.h>

void adc(), corr();

double dac();

20

double ran();

void main()

{

int n, i, L, N, M, *b;

long iseed;

double *x, xq, *e, R, Q, *Ree, *Rex, *Rxx;

double normee, normex;

double v, pi = 4 * atan(1.0);

FILE *fpe, *fpx;

FILE *fpRee, *fpRex, *fpRxx;

printf("enter N, R = ");

scanf("%d %lf", &N, &R);

printf("enter L, iseed, M = ");

scanf("%d %ld %d", &L, &iseed, &M);

fpe = fopen("e", "w");

fpx = fopen("x", "w");

fpRee = fopen("Ree", "w");

fpRex = fopen("Rex", "w");

fpRxx = fopen("Rxx", "w");

b = (int *) calloc(N, sizeof(int));

x = (double *) calloc(L, sizeof(double));

e = (double *) calloc(L, sizeof(double));

Ree = (double *) calloc(M+1, sizeof(double));

Rex = (double *) calloc(M+1, sizeof(double));

Rxx = (double *) calloc(M+1, sizeof(double));

Q = R / (1 << N);

for (n=0; n<L; n++) {

v = 0.25 * R * (2 * ran(&iseed) - 1);

x[n] = 0.25 * R * cos(2 * pi * n / sqrt(131.)) + v;

adc(x[n], b, N, R);

xq = dac(b, N, R);

e[n] = x[n] - xq;

fprintf(fpx, "% lf\n", x[n]);

fprintf(fpe, "% lf\n", e[n]);

}

corr(L, e, e, M, Ree);

corr(L, e, x, M, Rex);

corr(L, x, x, M, Rxx);

normee = Ree[0];

normex = sqrt(Ree[0] * Rxx[0]);

for (i=0; i<=M; i++) {

fprintf(fpRee, "%lf\n", Ree[i]/normee);

fprintf(fpRex, "%lf\n", Rex[i]/normex);

fprintf(fpRxx, "%lf\n", Rxx[i]/Rxx[0]);

}

21

printf("erms = Q/sqrt(12) = %lf\n", Q/sqrt(12.0));

printf("Ree(0) = %lf\n", sqrt(normee));

}

Problem 2.19

The mean of v is zero because E[u]= 0.5:

E[v]= 0.5R(E[u]−0.5)= 0

The variance of v is related to the variance of u as follows:

σ

2

v

= E[v

2

]= (0.5R)

2

E[(u −0.5)

2

]= (0.5R)

2

σ

2

u

= (0.5R)

2

1

12

=

R

2

48

Problem 2.20

Inserting x(n)= Acos(2πf

0

n+φ)+v(n) into the deﬁnition of the autocorrelation function, we

ﬁnd:

R

xx

(k) = E[x(n +k)x(n)]

= A

2

E[cos

_

2πf

0

(n +k)+φ

_

cos(2πf

0

n +φ)]

+AE[cos

_

2πf

0

(n +k)+φ

_

v(n)]+AE[v(n +k)cos(2πf

0

n +φ)]

+E[v(n +k)v(n)]

assuming φand v(n) are independent random variables, the cross terms will vanish. Indeed, by

the independence assumption the expectation value of the product becomes the product of the

expectation values:

E[v(n +k)cos(2πf

0

n +φ)]= E[v(n +k)]·E[cos(2πf

0

n +φ)]= 0

where the last zero follows either from the zero-mean property of v(n) and/or from the zero

mean property of E[cos(2πf

0

n +φ)]= 0. The latter follows from uniformity of φ whose prob-

ability density will be: p(φ)= 1/(2π). We have:

E[cos(a +φ)]=

_

2π

0

cos(a +φ)p(φ) dφ =

1

2π

_

2π

0

cos(a +φ) dφ = 0

Similarly, we have the property:

E[cos(a +φ)cos(b +φ)] =

_

2π

0

cos(a +φ)cos(b +φ)p(φ) dφ

=

1

2π

_

2π

0

cos(a +φ)cos(b +φ) dφ

=

1

2

cos(a −b)

Thus, we ﬁnd

E[cos

_

2πf

0

(n +k)+φ

_

cos(2πf

0

n +φ)]=

1

2

cos(2πf

0

(n +k)−2πf

0

n)=

1

2

cos(2πf

0

k)

Finally, because v(n) is assumed to be zero-mean white noise, we will have:

22

E[v(n +k)v(n)]= σ

2

v

δ(k)

It follows that the autocorrelation of the noisy sinusoid will be:

R

xx

(k)=

1

2

A

2

cos(2πf

0

k)+σ

2

v

δ(k)

At lag k = 0, we have:

R

xx

(0)=

1

2

A

2

+σ

2

v

Therefore, the normalized autocorrelation function becomes:

ρ

xx

(k)=

R

xx

(k)

R

xx

(0)

=

A

2

/2

A

2

/2 +σ

2

v

cos(2πf

0

k)+

σ

2

v

A

2

/2 +σ

2

v

δ(k)

Deﬁning the parameter:

a =

A

2

/2

A

2

/2 +σ

2

v

⇒ 1 −a =

σ

2

v

A

2

/2 +σ

2

v

we ﬁnally have:

ρ

xx

(k)= acos(2πf

0

k)+(1 −a)δ(k)

Deﬁning the signal to noise ratio as the relative strength of the sinusoid versus the noise in the

autocorrelation function, that is,

SNR =

A

2

/2

σ

2

v

we may express the parameter a as:

a =

SNR

SNR+1

⇒ 1 −a =

1

SNR+1

Problem 2.21

The quantization width of the ﬁrst ADC will be Q

1

= R

1

/2

B1

. The residual signal formed at the

output of the ﬁrst DAC, x

2

= x−x

1

, is the quantization error, and therefore, it varies of the limits

−

Q

1

2

≤ x

2

≤

Q

1

2

These limits must serve as the full scale range of the second ADC. Thus, we must choose:

R

2

= Q

1

=

R

1

2

B1

, Q

2

=

R

2

2

B2

=

R

1

2

B1+B2

The following program segment illustrates the sequence of operations:

23

R2 = R1 / (1 << B1);

b1 = (int *) calloc(B1, sizeof(int));

b2 = (int *) calloc(B2, sizeof(int));

for (n=0; n<L; n++) {

x = A * cos(2 * pi * f0 * n);

adc(x, b1, B1, R1);

x1 = dac(b1, B1, R1);

x2 = x - x1;

adc(x2, b2, B2, R2);

}

When there is a third B

3

-bit stage, the total number of bits will be

B = B

1

+B

2

+B

3

The B

2

-bit output of the second ADC must be passed into a second DAC to get the corresponding

analog value and subtracted from the input x − x

1

to get the third error output, which is then

quantized to B

3

bits with a full scale range and quantization width:

R

3

= Q

2

=

R

2

2

B2

, Q

3

=

R

3

2

B3

=

R

1

2

B1+B2+B3

The following loop shows these operations:

R2 = R1 / (1 << B1);

R3 = R2 / (1 << B2);

b1 = (int *) calloc(B1, sizeof(int));

b2 = (int *) calloc(B2, sizeof(int));

b3 = (int *) calloc(B3, sizeof(int));

for (n=0; n<L; n++) {

x = A * cos(2 * pi * f0 * n);

adc(x, b1, B1, R1);

x1 = dac(b1, B1, R1);

adc(x-x1, b2, B2, R2);

x2 = dac(b2, B2, R2);

x3 = x - x1 - x2;

adc(x3, b3, B3, R3);

}

Problem 2.22

The quantized triangularly-dithered signals were generated by the for-loop given in Example 2.5.1.

24

Chapter 3 Problems

Problem 3.1

(a) If the input is doubled the output is not doubled. Thus, the system is not linear. Indeed,

the output due to x

1

(n)= 2x(n) will be y

1

(n)= 3x

1

(n)+5 = 6x(n)+5 }= 2(3x(n)+5).

The system is, however, time-invariant since it has constant-in-time coefﬁcients.

(b) The quadratic term x

2

(n − 1) breaks linearity because it quadruples whenever the input

doubles. The term x(2n) will break time-invariance. Indeed, let x

D

(n)= x(n − D) be

a delayed input. The corresponding output y

D

(n) can be computed from the given I/O

equation:

y

D

(n)= x

2

D

(n −1)+x

D

(2n)= x

2

(n −1 −D)+x(2n −D)

but, this is not the same as the delayed (shifted) y(n) obtained by replacing n by n −D:

y(n −D)= x

2

(n −D−1)+x(2(n −D))= x

2

(n −D−1)+x(2n −2D)

Thus, the system is neither linear nor time-invariant.

(c) System is time-invariant, but not linear since the output does not double whenever the

input doubles.

(d) The system is linear, but the term nx(n −3) breaks time-invariance.

(e) The time-dependent term n breaks both time invariance and linearity.

Problem 3.2

Picking out the coefﬁcients of the x-terms, we ﬁnd:

(a) h = [3, −2, 0, 4]

(b) h = [4, 1, 0, −3]

(c) h = [1, 0, 0, −1]

Problem 3.3

(a,b) These problems are of the general form:

y(n)= ay(n −1)+x(n)

with a = −0.9 for (a), and a = 0.9 for (b). Setting x(n)= δ(n) we ﬁnd the difference

equation for the impulse response:

h(n)= ah(n −1)+δ(n)

Iterating forward in time with zero initial condition h(−1)= 0, we obtain the causal solu-

tion:

h(0)= ah(−1)+δ(0)= a · 0 +1 = 1

h(1)= ah(0)+δ(1)= a · 1 +0 = a

h(2)= ah(1)+δ(2)= a · a +0 = a

2

h(3)= ah(2)+δ(3)= a · a

2

+0 = a

3

· · ·

h(n)= ah(n −1)+δ(n)= a · a

n−1

= a

n

, for n ≥ 1

25

Thus, h(n) will be the geometric series:

h = [1, a, a

2

, a

3

, . . . ]

(c,d) These problems are similar to

y(n)= ay(n −2)+x(n)

with a = 0.64 = (0.8)

2

for (c), and a = −0.81 = −(0.9)

2

for (d). The impulse response

will satisfy the difference equation:

h(n)= ah(n −2)+δ(n)

A few iterations (with zero initial conditions) give:

h(0)= 1

h(1)= 0

h(2)= ah(0)= a

h(3)= ah(1)= 0

h(4)= ah(2)= a

2

h(5)= ah(3)= 0, etc.

Thus, all the odd-indexed h(n) are zero:

h = [1, 0, a, 0, a

2

, 0, a

3

, 0, a

4

, 0, . . . ]

(e) The impulse response satisﬁes:

h(n)= 0.5h(n −1)+4δ(n)+δ(n −1)

A few iterations give:

h(0)= 4

h(1)= 0.5h(0)+1 = 3

h(2)= 0.5h(1)= 3(0.5)

h(3)= 0.5h(2)= 3(0.5)

2

, etc.

Thus,

h(n)=

⎧

⎨

⎩

4 if n = 0

3(0.5)

n−1

if n ≥ 1

Problem 3.4

We have seen that if h(n)= a

n

u(n), then the I/O difference equation is

y(n)= ay(n −1)+x(n)

In cases (a) and (b), we apply this result with a = 0.9 and a = −0.9. In cases (c) and (d), we apply

this result twice and verify that h(n)= a

n

u(n)+(−a)

n

u(n) leads to the difference equation

y(n)= a

2

y(n −2)+2x(n)

26

Thus, for (c) we have a = 0.9, a

2

= 0.81, and

y(n)= 0.81y(n −2)+2x(n)

And, for (d) we have a = 0.9j, a

2

= −0.81, and

y(n)= −0.81y(n −2)+2x(n)

A systematic and simpler way of solving this type of problem will be presented after we cover

z-transforms.

Problem 3.5

The impulse response sequence is explicitly:

h = [4, 3, 3(0.5), 3(0.5)

2

, 3(0.5)

3

, . . . ]

Replacing these values into the convolutional equation, we get:

y

n

= h

0

x

n

+h

1

x

n−1

+h

2

x

n−2

+h

3

x

n−3

+h

4

x

n−4

+· · ·

= 4x

n

+3

_

x

n−1

+0.5x

n−2

+0.5

2

x

n−3

+0.5

3

x

n−4

+· · ·

_

It follows that:

0.5y

n−1

= 2x

n−1

+3

_

0.5x

n−2

+0.5

2

x

n−3

+0.5

3

x

n−4

· · ·

_

Subtracting, we have:

y

n

−0.5y

n−1

= 4x

n

+3x

n−1

−2x

n−1

or,

y

n

= 0.5y

n−1

= 4x

n

+x

n−1

Problem 3.6

We may write the given impulse response in the form:

h(n)= 5δ(n)+6(0.8)

n−1

u(n −1)= [5, 6, 6(0.8), 6(0.8)

2

, . . . ]

Proceeding as in the previous problem we have:

y

n

= 5x

n

+6

_

x

n−1

+0.8x

n−2

+0.8

2

x

n−3

+· · ·

_

0.8y

n−1

= 4x

n−1

+6

_

0.8x

n−2

+0.8

2

x

n−3

+· · ·

_

which gives

y

n

−0.8y

n−1

= 5x

n

+2x

n−1

27

Problem 3.7

It is evident from the deﬁnition that for n ≥ 2, h(n) satisﬁes the recursions h(n)= ah(n −1).

Instead of manipulating the I/Oconvolutional equation into a difference equation as we did above,

let us determine directly the difference equation satisﬁed by h(n) and from that determine the

difference equation for y(n).

The given expression for h(n) can be rewritten in the more compact form, which is valid for all

n:

h(n)= c

0

δ(n)+c

1

a

n−1

u(n −1)

where the shifted unit-step u(n − 1) vanishes for n = 0 and equals one for all n ≥ 1. Because

h(n) satisﬁes h(n)= ah(n−1) for n ≥ 2, we are led to consider the delayed function h(n−1)

and multiply it by a:

h(n −1)= c

0

δ(n −1)+c

1

a

n−2

u(n −2)

and

ah(n −1)= ac

0

δ(n −1)+c

1

a

n−1

u(n −2)

Subtracting, we have

h(n)−ah(n −1)= c

0

δ(n)−ac

0

δ(n −1)+c

1

a

n−1

_

u(n −1)−u(n −2)

_

But the difference u(n−1)−u(n−2)= δ(n−1) as follows fromthe standard result u(n)−u(n−

1)= δ(n), which was essentially derived in Example 3.4.4. Therefore, we have

h(n)−ah(n −1)= c

0

δ(n)−ac

0

δ(n −1)+c

1

a

n−1

δ(n −1)

But note that a

n−1

δ(n − 1)= δ(n − 1) because it is nonzero only at n = 1 for which we have

a

1−1

δ(0)= a

0

δ(0)= δ(0). Then,

h(n)−ah(n −1)= c

0

δ(n)−ac

0

δ(n −1)+c

1

δ(n −1)= c

0

δ(n)+(c

1

−ac

0

)δ(n −1)

Or, setting b

0

= c

0

and b

1

= c

1

−ac

0

and solving for h(n) we ﬁnd

h(n)= ah(n −1)+b

0

δ(n)+b

1

δ(n −1)

Example 3.4.7 had b

0

= c

0

= 2 and b

1

= c

1

−ac

0

= 4 −2 · 0.5 = 3. Next, we map this difference

equation for h(n) into a difference equation for y(n). To do this we start with the convolutional

equation and replace h(m) by its difference equation expression, that is,

y(n) =

_

m

h(m)x(n −m)

=

_

m

_

ah(m−1)+b

0

δ(m)+b

1

δ(m−1)

_

x(n −m)

= a

_

m

h(m−1)x(n −m)+

_

m

_

b

0

δ(m)+b

1

δ(m−1)

_

x(n −m)

In the second sum, the presence of δ(m) extracts only the m= 0 term, that is, b

0

x(n), whereas

the presence of δ(m− 1) extracts only the m = 1 term, that is, b

1

x(n − 1). Moreover, with a

change of variables of summation from m to k = m−1 or m = k +1, the a-term is recognized

to be ay(n −1); indeed,

28

a

_

m

h(m−1)x(n −m)= a

_

k

h(k)x(n −k −1)= ay(n −1)

the last equation following from the convolution equation by replacing n by n −1:

y(n)=

_

k

h(k)x(n −k) ⇒ y(n −1)=

_

k

h(k)x(n −1 −k)

We ﬁnally ﬁnd the I/O difference equation for y(n):

y(n)= ay(n −1)+b

0

x(n)+b

1

x(n −1)

which is exactly the same as that satisﬁed by h(n).

Problem 3.8

First, note that if f

n

= a

n

u(n) then for n ≥ 1

(1 −aD)f

n

= f

n

−af

n−1

= a

n

−aa

n−1

= 0

where D is the delay operator deﬁned by (Df)

n

= f

n−1

. It follows that the ﬁrst term p

n

1

u(n) of

h

n

will be annihilated by (1 −p

1

D), the second term of h

n

will be annihilated by (1 −p

2

D), etc.

Therefore, all the terms in h

n

will be annihilated by the product

(1 −p

1

D)(1 −p

2

D)· · · (1 −p

M

D)= 1 +a

1

D+a

2

D

2

+· · · +a

M

D

M

Problem 3.9

The C

i

p

n

i

terms are annihilated by the same product as in the previous problem. However, the

δ(n) term will contain the delayed terms:

a

M

δ(n −M)+a

M−1

δ(n −M+1)+· · ·

But, if n ≥ M+1, then these terms vanish too. Thus, the difference equation satisﬁed by h

n

will

be:

h

n

+a

1

h

n−1

+· · · +a

M

h

n−M

= 0, n ≥ M+1

Problem 3.10

Deﬁne the polynomial with roots p

1

, p

2

:

1 +a

1

z

−1

+a

2

z

−2

= (1 −p

1

z

−1

)(1 −p

2

z

−1

)

so that

a

1

= −(p

1

+p

2

), a

2

= p

1

p

2

Then, the p

n

i

terms in h

n

will be annihilated by the delay polynomial:

h

n

+a

1

h

n−1

+a

2

h

n−2

= (1 +a

1

D+a

2

D

2

)h

n

= (1 −p

1

D)(1 −p

2

D)h

h

29

for n ≥ 2. The coefﬁcients b

0

, b

1

may be found by explicitly calculating the right-hand side of

this difference equation using the expression for h

n

, for n = 0, 1:

b

0

= h

0

+a

1

h

−1

+a

2

h

−2

= h

0

= C

1

+C

2

b

1

= h

1

+a

1

h

0

+a

2

h

−1

= h

1

+a

1

h

0

= C

1

p

1

+C

2

p

2

+a

1

(C

1

+C

2

)

Using the expression for a

1

, we ﬁnd:

b

0

= C

1

+C

2

b

1

= C

1

p

1

+C

2

p

2

−(p

1

+p

2

)(C

1

+C

2

)= −(C

1

p

2

+C

2

p

1

)

To summarize, h

n

will satisfy the difference equation:

h

n

+a

1

h

n−1

+a

2

h

n−2

= b

0

δ(n)+b

1

δ(n −1) (P3.1)

Inserting this into the convolutional equation, we obtain the I/O difference equation:

y

n

+a

1

y

n−1

+a

2

y

n−2

= b

0

x

n

+b

1

x

n−1

These results can be obtained quickly using z-transforms:

H(z)=

C

1

1 −p

1

z

−1

+

C

2

1 −p

2

z

−1

=

(C

1

+C

2

)−(C

1

p

2

+C

2

p

1

)z

−1

(1 −p

1

z

−1

)(1 −p

2

z

−1

)

which may be rewritten as

H(z)=

b

0

+b

1

z

−1

1 +a

1

z

−1

+a

2

z

−2

and leads to the desired difference equations for h

n

and y

n

.

Problem 3.11

Now the difference equation Eq. (P3.1) will be satisﬁed for n ≥ 3. To determine the coefﬁcients

b

0

, b

1

, b

2

, we evaluate the right hand side for n = 0, 1, 2:

b

0

= h

0

b

1

= h

1

+a

1

h

0

b

2

= h

2

+a

1

h

1

+a

2

h

0

which give:

b

0

= C

0

+C

1

+C

2

b

1

= C

1

p

1

+C

2

p

2

+a

1

(C

0

+C

1

+C

2

)= −(p

1

+p

2

)C

0

−(C

1

p

2

+C

2

p

1

)

b

2

= C

1

p

2

1

+C

2

p

2

2

+a

1

(C

1

p

1

+C

2

p

2

)+a

2

(C

0

+C

1

+C

2

)= C

0

p

1

p

2

In b

2

, the coefﬁcient of C

1

is p

2

1

+a

1

p

1

+a

2

, which is zero because p

1

is a root of the polynomial

z

2

+a

1

z +a

2

. Similarly, the coefﬁcient of C

2

is zero.

Again, the results can be justiﬁed quickly using z-transforms:

H(z) = C

0

+

C

1

1 −p

1

z

−1

+

C

2

1 −p

2

z

−1

=

(C

0

+C

1

+C

2

)−

_

C

1

p

2

+C

2

p

1

+C

0

(p

1

+p

2

)

_

z

−1

+C

0

p

1

p

2

z

−2

(1 −p

1

z

−1

)(1 −p

2

z

−1

)

30

Problem 3.12

Deﬁne the polynomial with roots p

1

, p

2

, p

3

:

1 +a

1

z

−1

+a

2

z

−2

+a

3

z

−3

= (1 −p

1

z

−1

)(1 −p

2

z

−1

)(1 −p

3

z

−1

)

so that

a

1

= −(p

1

+p

2

+p

3

), a

2

= p

1

p

2

+p

2

p

3

+p

3

p

1

, a

3

= −p

1

p

2

p

3

Then, the p

n

i

terms in h

n

will be annihilated by the delay polynomial:

(1 +a

1

D+a

2

D

2

+a

3

D

3

)h

n

= (1 −p

1

D)(1 −p

2

D)(1 −p

3

D)h

h

= 0

for n ≥ 3, or,

h

n

+a

1

h

n−1

+a

2

h

n−2

+a

3

h

n−3

= 0, n ≥ 3

The coefﬁcients b

0

, b

1

, b

2

may be found by explicitly calculating the right-hand side of this dif-

ference equation using the expression for h

n

, for n = 0, 1, 2:

b

0

= h

0

b

1

= h

1

+a

1

h

0

b

2

= h

2

+a

1

h

1

+a

2

h

0

or,

b

0

= C

1

+C

2

+C

3

b

1

= C

1

p

1

+C

2

p

2

+C

3

p

3

+a

1

(C

1

+C

2

+C

3

)

b

2

= C

1

p

2

1

+C

2

p

2

2

+C

3

p

2

3

+a

1

(C

1

p

1

+C

2

p

2

+C

3

p

3

)+a

2

(C

1

+C

2

+C

3

)

which simplify into:

b

0

= C

1

+C

2

+C

3

b

1

= −

_

C

1

(p

2

+p

3

)+C

2

(p

3

+p

1

)+C

3

(p

1

+p

2

)

_

b

2

= C

1

p

2

p

3

+C

2

p

3

p

1

+C

3

p

1

p

2

Problem 3.13

For (a), we have with n ≥ 2:

(1 −0.5D)(1 −0.8D)= 1 −1.3D+0.4D

2

⇒

h

n

−1.3h

n−1

+0.4h

n−2

= 0

For (b), we have with n ≥ 2:

(1 −0.5jD)(1 +0.5jD)= 1 +0.25D

2

⇒

h

n

+0.25h

n−2

= 0

For (c), we have with n ≥ 3:

(1 −0.4D)(1 −0.5D)(1 +0.5D)= 1 −0.4D−0.25D

2

+0.1D

3

⇒

h

n

−0.4h

n−1

−0.25h

n−2

+0.1h

n−3

= 0

31

Problem 3.14

From the convolutional I/O equation we get:

¦y(n)¦ = ¦

_

m

h(m)x(n −m)¦ ≤

_

m

¦h(m)¦¦x(n −m)¦ ≤

_

m

¦h(m)¦B = AB

Problem 3.15

Starting with

y(n)=

_

m

h(m)x(n −m)

we obtain at n = 0:

y(0)=

_

m

h(m)x(−m)

But, x(m)= sign

_

h(−m)

_

. Therefore, x(−m)= sign

_

h(m)

_

. It follows:

y(0)=

_

m

h(m)x(−m)=

_

m

h(m)sign

_

h(m)

_

Recognizing that in general xsign(x)= ¦x¦, we ﬁnd

y(0)=

_

m

¦h(m)¦

Because x(n) was bounded, y(n) and, hence y(0), must be bounded. If at some m, h(m)= 0,

then this term would not contribute to the convolutional sum.

Problem 3.16

Working with the convolutional I/O equation, we have:

y

D

(n) =

_

m

h

D

(m)x(n −m)=

_

m

h(m−D)x(n −m)

=

_

k

h(k)x(n −D−k)= y(n −D)

where we changed summation variables frommto k = m−D, and evaluated y(n) at n−D, that

is,

y(n)=

_

k

h(k)x(n −k) ⇒ y(n −D)=

_

k

h(k)x(n −D−k)

Problem 3.17

We have:

_

m

h

D

(m)x

A

(n −m)=

_

m

h(m−D)x(n −m+D)=

_

k

h(k)x(n −k)

where we changed variables of summation from m to k = m−D.

32

Problem 3.18

Because

˜

h(n) agrees with h(n) for n ≥ −D, we have:

y(n) =

∞

_

m=−∞

h(m)x(n −m)

˜ y(n) =

∞

_

m=−D

˜

h(m)x(n −m)=

∞

_

m=−D

h(m)x(n −m)

Subtracting, the terms m≥ −D cancel and we get:

y(n)−˜ y(n)=

−D−1

_

m=−∞

h(m)x(n −m)

Assuming x(n) is bounded by A, we have:

¦y(n)−˜ y(n)¦ = ¦

−D−1

_

m=−∞

h(m)x(n −m)¦ ≤

−D−1

_

m=−∞

¦h(m)¦¦x(n −m)¦ ≤

−D−1

_

m=−∞

¦h(m)¦A

This summation is ﬁnite because it is a subsum of the stability condition:

−D−1

_

m=−∞

¦h(m)¦ ≤

∞

_

m=−∞

¦h(m)¦ < ∞

In the limit of large D, the number of terms shrinks to zero giving:

lim

D→∞

−D−1

_

m=−∞

¦h(m)¦ →0

33

Chapter 4 Problems

Problem 4.1

The convolution table is:

h\x 1 2 1 1 2 1 1 1

1 1 2 1 1 2 1 1 1

1 1 2 1 1 2 1 1 1

2 2 4 2 2 4 2 2 2

1 1 2 1 1 2 1 1 1

Folding the table, we get

y = [1, 3, 5, 7, 7, 6, 7, 6, 4, 3, 1]

The ﬁ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:

n 0 1 2 3 4 5 6 7 8 9 10

x\h 1 1 2 1 partial output

1 1 1 2 1 x(0)h(n −0)

2 2 2 4 2 x(1)h(n −1)

1 1 1 2 1 x(2)h(n −2)

1 1 1 2 1 x(3)h(n −3)

2 2 2 4 2 x(4)h(n −4)

1 1 1 2 1 x(5)h(n −5)

1 1 1 2 1 x(6)h(n −6)

1 1 1 2 1 x(7)h(n −7)

y(n) 1 3 5 7 7 6 7 6 4 3 1

_

m

x(m)h(n −m)

For the overlap-add method, the input is divided into the following three contiguous blocks:

x = [ 1, 2, 1

. ¸, .

x0

, 1, 2, 1

. ¸, .

x1

, 1, 1, 0

. ¸, .

x2

]

where we padded an extra zero at the end to get a length-3 block. Convolving each block separately

with h gives:

y

0

= h ∗x

0

= [1, 3, 5, 6, 4, 1]

y

1

= h ∗x

1

= [1, 3, 5, 6, 4, 1]

y

2

= h ∗x

2

= [1, 2, 3, 3, 1, 0]

These convolutions can be done by separately folding the three convolution subtables:

block 0 block 1 block 2

h\x 1 2 1 1 2 1 1 1 0

1 1 2 1 1 2 1 1 1 0

1 1 2 1 1 2 1 1 1 0

2 2 4 2 2 4 2 2 2 0

1 1 2 1 1 2 1 1 1 0

34

The three subblocks begin at the absolute times n = 0, 3, 6, respectively. It follows from time-

invariance that the corresponding output blocks will also begin at the same absolute times. Thus,

aligning the output blocks according to their absolute timings and adding them up gives the ﬁnal

result:

n 0 1 2 3 4 5 6 7 8 9 10

y

0

1 3 5 6 4 1

y

1

1 3 5 6 4 1

y

2

1 2 3 3 1

y 1 3 5 7 7 6 7 6 4 3 1

In practice this method is implemented efﬁciently 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 N

1

= N − M.

The computational gain of this “fast” convolution method versus the conventional time-domain

“slow” method is approximately

fast

slow

=

log

2

N

M

If the input is divided into length-5 subblocks, the last subblock will have length 3:

x = [ 1, 2, 1, 1, 2

. ¸, .

x0

, 1, 1, 1

. ¸, .

x1

]

The convolutions of the subblocks with the ﬁlter are:

y

0

= h ∗x

0

= [1, 3, 5, 7, 7, 5, 5, 2]

y

1

= h ∗x

1

= [1, 2, 4, 4, 3, 1]

Aligning them at multiples of n = 5, we have:

n 0 1 2 3 4 5 6 7 8 9 10

y

0

1 3 5 7 7 5 5 2

y

1

1 2 4 4 3 1

y 1 3 5 7 7 6 7 6 4 3 1

Problem 4.2

The convolution table is:

h\x 2 2 0 1 -1 0 1 2

2 4 4 0 2 -2 0 2 4

-2 -4 -4 0 -2 2 0 -2 -4

-1 -2 -2 0 -1 1 0 -1 -2

1 2 2 0 1 -1 0 1 2

Folding the table, we get

y = [4, 0, −6, 2, −2, 1, 4, 1, −5, −1, 2]

The ﬁ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 0 1 2 3 4 5 6 7 8 9 10

x\h 2 -2 -1 1 partial output

2 4 -4 -2 2 x(0)h(n −0)

2 4 -4 -2 2 x(1)h(n −1)

0 0 0 0 0 x(2)h(n −2)

1 2 -2 -1 1 x(3)h(n −3)

-1 -2 2 1 -1 x(4)h(n −4)

0 0 0 0 0 x(5)h(n −5)

1 2 -2 -1 1 x(6)h(n −6)

2 4 -4 -2 2 x(7)h(n −7)

y(n) 4 0 -6 2 -2 1 4 1 -5 -1 2

_

m

x(m)h(n −m)

For the overlap-add method, the input is divided into the following three contiguous blocks:

x = [ 2, 2, 0

. ¸, .

x0

, 1, −1, 0

. ¸, .

x1

, 1, 2, 0

. ¸, .

x2

]

where we padded an extra zero at the end to get a length-3 block. Convolving each block separately

with h gives:

y

0

= h ∗x

0

= [4, 0, −6, 0, 2]

y

1

= h ∗x

1

= [2, −4, 1, 2, −1, 0]

y

2

= h ∗x

2

= [2, −2, −5, −1, 2]

These convolutions can be done by separately folding the three convolution subtables:

block 0 block 1 block 2

h\x 2 2 0 1 -1 0 1 2

2 4 4 0 2 -2 0 2 4

-2 -4 -4 0 -2 2 0 -2 -4

-1 -2 -2 0 -1 1 0 -1 -2

1 2 2 0 1 -1 0 1 2

Aligning the output subblocks at multiples of n = 3, we get:

n 0 1 2 3 4 5 6 7 8 9 10

y

0

4 0 -6 0 2 1

y

1

2 -4 1 2 -1 0

y

2

2 2 -5 -1 2

y 4 0 -6 2 -2 1 4 1 -5 -1 2

If the input is divided into length-5 subblocks, the last subblock will have length 3:

x = [ 2, 2, 0, 1, −1

. ¸, .

x0

, 0, 1, 2

. ¸, .

x1

]

The convolutions of the subblocks with the ﬁlter are:

y

0

= h ∗x

0

= [4, 0, −6, 2, −2, 1, 2, −1]

y

1

= h ∗x

1

= [0, 2, 2, −5, −1, 2]

Aligning them at multiples of n = 5, we have:

36

n 0 1 2 3 4 5 6 7 8 9 10

y

0

4 0 -6 2 -2 1 2 -1

y

1

0 2 2 -5 -1 2

y 4 0 -6 2 -2 1 4 1 -5 -1 2

Problem 4.3

Figure P4.1 shows the ﬁlter, input, and computed output signals.

0 3 6 10 13 16 20 23 26

0

1

1

2

3

4

3 6 10 13 16 20 23 26

n

n

h(n) x(n)

y(n)

on steady off

Fig. P4.1 h(n), x(n), and y(n) signals of Problem 4.3.

For the direct form, the indices of h

m

and x

n−m

are restricted to lie within their respective ranges:

3 ≤ m≤ 6

10 ≤ n −m≤ 20

(P4.1)

Solving the second with respect to n, we have:

10 +m≤ n ≤ 20 +m

Using the ﬁrst of Eq. (P4.1), we extend the range to:

10 +3 ≤ 10 +m≤ n ≤ 20 +m≤ 20 +6 ⇒ 13 ≤ n ≤ 26

This is the range of index n of the output y

n

. To ﬁ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

Thus, the inequalities in Eq. (P4.1) are equivalent to

3 ≤ m≤ 6

n −20 ≤ m≤ n −10

⇒ max(3, n −20)≤ m≤ min(6, n −10)

The ﬁnal expression for the direct form will be:

37

y

n

=

min(6,n−10)

_

m=max(3,n−20)

h

m

x

n−m

, for 13 ≤ n ≤ 26

The transition from the input-on transients to the steady state takes place at time 6 = n −10 or

n = 16 at which the upper limit switches from n −10 to 6. Similarly, the transition from steady

state to the input-off transients occurs at 3 = n − 20 or n = 23 when the lower limit switches

from 3 to n −10. In summary, the three ranges are:

input-on: 13 ≤ n ≤ 15 y

n

=

n−10

_

m=3

h

m

x

n−m

steady-state: 16 ≤ n ≤ 23 y

n

=

6

_

m=3

h

m

x

n−m

input-off: 24 ≤ n ≤ 26 y

n

=

6

_

m=n−20

h

m

x

n−m

In particular, if the ﬁlter and input signals are unity over the ranges (P4.1), the output can be

expressed compactly as:

y

n

=

min(6,n−10)

_

m=max(3,n−20)

1 · 1 = min(6, n −10)−max(3, n −20)+1 (P4.2)

for 13 ≤ n ≤ 26. Or, more explicitly:

input-on: 13 ≤ n ≤ 15 y

n

= n −10 −3 +1 = n −12

steady-state: 16 ≤ n ≤ 23 y

n

= 6 −3 +1 = 4

input-off: 24 ≤ n ≤ 26 y

n

= 6 −(n −20)+1 = 27 −n

With numerical values:

y = ¦1, 2, 3, 4, 4, 4, 4, 4, 4, 4, 4, 3, 2, 1¦

The ﬁ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:

y

DC

=

_

m

h

m

= 1 +1 +1 +1 = 4

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

10 ≤ m≤ 20

3 ≤ n −m≤ 6

This leads to the same range for the output index n, but to the summation limits:

38

y

n

=

min(20,n−3)

_

m=max(10,n−6)

x

m

h

n−m

, for 13 ≤ n ≤ 26

For part (b), we have:

y

n

=

min(20,n−3)

_

m=max(10,n−6)

1 · 1 = min(10, n −6)−max(20, n −3)+1 (P4.3)

Note that Eq. (P4.3) is equivalent to Eq. (P4.2).

Problem 4.4

Because both the input and ﬁlter are causal and have inﬁnite duration, we use the formula:

y(n)=

n

_

m=0

h(m)x(n −m)=

n

_

m=0

a

m

u(m)u(n −m) or,

y(n)=

n

_

m=0

a

m

=

1 −a

n+1

1 −a

The steady-state response is the large-n limit of this formula; that is,

y(n)−→

1

1 −a

for n −→∞

If x(n)= (−1)

n

u(n), we have

y(n)=

n

_

m=0

a

m

(−1)

n−m

= (−1)

n

n

_

m=0

(−a)

m

= (−1)

n

1 −(−a)

n+1

1 +a

Problem 4.5

Consider the IIR ﬁlter h(n)= a

n

u(n), where 0 < a < 1. The square pulse x(n)= u(n)−u(n−L)

of duration L is applied as input. Using the time-domain convolution formula determine a closed-

form expression for the output signal y(n) for the two time ranges: 0 ≤ n ≤ L − 1 and n ≥ L.

Because the ﬁlter is inﬁnite (M = ∞), Eq. (4.1.16) becomes:

y(n)=

n

_

m=max(0,n−L+1)

h(m)x(n −m), 0 ≤ n < ∞

Inserting the given signals for h(n) and x(n), we ﬁnd:

y(n)=

n

_

m=max(0,n−L+1)

a

m

· 1

Using the geometric series identity

M2

_

m=M1

a

m

=

a

M1

−a

M2+1

1 −a

we ﬁnd:

39

y(n)=

a

max(0,n−L+1)

−a

n+1

1 −a

In particular, for 0 ≤ n ≤ L −1, we have max(0, n −L +1)= 0, and

y(n)=

1 −a

n+1

1 −a

(input-on transients and steady state)

whereas for n ≥ L, we have max(0, n −L +1)= n −L +1, and

y(n)=

a

n−L+1

−a

n+1

1 −a

= a

n−L+1

1 −a

L

1 −a

= a

n−L+1

y(L −1), (input-off)

Thus, after the input is turned off, the output decays exponentially to zero.

Problem 4.6

From the previous problem, we have at n = 0,

y(0)−ay(−1)=

1 −a

0+1

1 −a

−a · 0 = 1 = x(0)

Then, for 1 ≤ n ≤ L −1, we have x(n)= 1 and

y(n)−ay(n −1)=

1 −a

n+1

1 −a

−a

1 −a

n

1 −a

=

1 −a

n+1

−a +a

n+1

1 −a

= 1 = x(n)

Finally, for n ≥ L, we have x(n)= 0 and

y(n)−ay(n −1)= a

n−L+1

y

L−1

−aa

n−1−L+1

y

L−1

= 0 = x(n)

Problem 4.7

For example, the LTI form is obtained by interchanging the roles played by x and h and their

lengths L and M+1. The following routine is an implementation of Eq. (4.1.19):

/* convlti.c - convolution in LTI form */

#include <stdlib.h> deﬁnes max( ) and min( )

void convlti(M, h, L, x, y)

double *h, *x, *y; h=ﬁlter, x=input block, y=output block

int M, L; M=ﬁlter order, L=input length

{

int n, m;

for (n = 0; n < L+M; n++)

for (y[n] = 0, m = max(0, n-M); m <= min(n, L-1); m++)

y[n] += x[m] * h[n-m];

}

40

Problem 4.8

The following C program computes the output signals of the two ﬁlters (a) and (b) of Example

4.1.8:

/* convex.c - convolution example 4.1.8 */

#include <stdio.h>

#include <stdlib.h>

#include <math.h>

#define Ma 14

#define Mb 5

void conv();

void main()

{

int K = 50, L = 200, n;

double *x, *ya, *yb;

double ha[Ma+1], hb[Mb+1] = {0.2, -1, 2, -2, 1, -0.2};

x = (double *) calloc(L, sizeof(double));

ya = (double *) calloc(L+Ma, sizeof(double)); Ex. 4.1.8 (a)

yb = (double *) calloc(L+Mb, sizeof(double)); Ex. 4.1.8.(b)

for (n=0; n<=Ma; n++) deﬁne ﬁlter (a)

ha[n] = 0.25 * pow(0.75, n);

for (n=0; n<L; n++) deﬁne input

if (n%K < K/2)

x[n] = 1;

else

x[n] = 0;

conv(Ma, ha, L, x, ya); compute outputs

conv(Mb, hb, L, x, yb);

for (n=0; n<L+Ma; n++)

printf("%lf\n", ya[n]);

printf("\n\n");

for (n=0; n<L+Mb; n++)

printf("%lf\n", yb[n]);

}

Problem 4.9

A complete such program is included below.

/* blkfilt.c - FIR filtering by block convolution */

#include <stdio.h>

#include <stdlib.h>

#define MAX 64 memory allocation size

41

void blockcon();

void main(int argc, char **argv)

{

FILE *fph; ﬁlter ﬁle

double *h, *x, *y, *ytemp;

int M, N, L, i; M = ﬁlter order, L = blocksize

int max = MAX, dmax = MAX; initial allocation & increment

if (argc != 3) {

fprintf(stderr, "usage: blkfilt hfile L <xfile >yfile\n");

exit(0);

}

if ((fph = fopen(argv[1], "r")) == NULL) {

fprintf(stderr, "can’t open filter file: %s\n", argv[1]);

exit(0);

}

L = atoi(argv[2]); block length

h = (double *) calloc(max + 1, sizeof(double));

for (M=0;; M++) { read h

if (M == max) { if necessary, reallocate h

max += dmax;

h = (double *) realloc((char *) h, (max + 1) * sizeof(double));

}

if (fscanf(fph, "%lf", h + M) == EOF) break;

}

M--; M is ﬁ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 (;;) { read input block

for (N=0; N<L; N++) N=L except for last

if (scanf("%lf", x+N) == EOF) goto last;

blockcon(M, h, L, x, y, ytemp); process block

for (i=0; i<L; i++) write output block

printf("%lf\n", y[i]);

}

last: process last block

blockcon(M, h, N, x, y, ytemp); last block has N<=L

42

for (i=0; i<N+M; i++) write entire y block

printf("%lf\n", y[i]);

}

The dimension of the ﬁlter array h is determined on the ﬂy by reading the ﬁle of ﬁlter coefﬁ-

cients. Because the length of this ﬁle is not known in advance, the program keeps reallocating

the length of h in increments of MAX coefﬁcients 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.

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 programoutputs the corresponding group of L outputs, and so on. At

the end, one must enter a <CTRL-Z> (for MSDOS) in order for the programto process the input-off

transients.

Problem 4.10

A complete such program is included below.

/* firfilt.c - FIR filtering by sample-by-sample processing */

#include <stdlib.h>

#include <stdio.h>

#define MAX 64 initial allocation size

double fir();

void main(int argc, char **argv)

{

FILE *fph; ﬁlter ﬁle

double *h, *w, x, y; ﬁlter, states, input, output samples

int M, i;

int max = MAX, dmax = MAX; allocation for h and increment

if (argc != 2) {

fprintf(stderr, "usage: firfilt hfile <xfile >yfile\n");

exit(0);

}

if ((fph = fopen(argv[1], "r")) == NULL) {

fprintf(stderr, "can’t open filter file: %s\n", argv[1]);

exit(0);

}

h = (double *) calloc(max + 1, sizeof(double)); preliminary allocation

for (M=0;; M++) { read h

if (M == max) { reallocate h, if necessary

max += dmax;

h = (double *) realloc((char *) h, (max + 1) * sizeof(double));

}

if (fscanf(fph, "%lf", h + M) == EOF) break;

43

}

M--; M is ﬁlter order

h = (double *) realloc((char *) h, (M + 1) * sizeof(double)); ﬁnal allocation

w = (double *) calloc(M + 1, sizeof(double));

start ﬁltering:

while(scanf("%lf", &x) != EOF) { keep reading input samples

y = fir(M, h, w, x); compute output sample

printf("%lf\n", y); write output sample

}

for (i=0; i<M; i++) { input-off transients

y = fir(M, h, w, 0.0);

printf("%lf\n", y);

}

}

As in the case of blkfilt.c, the dimension of the ﬁlter array h is determined on the ﬂy by reading

the ﬁle of ﬁlter coefﬁcients. The program keeps reallocating the length of h in increments of MAX

coefﬁcients 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.

The program can receive its input from stdin with the user entering the input one sample at a

time. After each input is entered followed by a <CR>, the program computes and outputs the

corresponding output sample. (One can also enter a few input samples at a time, followed by a

<CR>, and the program will produce the corresponding outputs.) At the end, one must enter a

<CTRL-Z> (for MSDOS) in order for the program to process the input-off transients.

Problem 4.11

A complete such program is included below.

/* cfirfilt.c - FIR filtering using circular delay-line buffer */

#include <stdlib.h>

#include <stdio.h>

#define MAX 64 initial allocation size

double cfir();

void main(int argc, char **argv)

{

FILE *fph; ﬁlter ﬁle

double *h, *w, *p; ﬁlter, states, circular pointer

double x, y; input and output samples

int M, i;

int max = MAX, dmax = MAX; allocation for h and increment

if (argc != 2) {

fprintf(stderr, "usage: cfirfilt hfile <xfile >yfile\n");

exit(0);

}

44

if ((fph = fopen(argv[1], "r")) == NULL) {

fprintf(stderr, "can’t open filter file: %s\n", argv[1]);

exit(0);

}

h = (double *) calloc(max + 1, sizeof(double)); preliminary allocation

for (M=0;; M++) { read h

if (M == max) { reallocate h, if necessary

max += dmax;

h = (double *) realloc((char *) h, (max + 1) * sizeof(double));

}

if (fscanf(fph, "%lf", h + M) == EOF) break;

}

M--; M is ﬁlter order

h = (double *) realloc((char *) h, (M + 1) * sizeof(double));

w = (double *) calloc(M + 1, sizeof(double));

p = w; initialize p

start ﬁltering:

while(scanf("%lf", &x) != EOF) { keep reading input samples

y = cfir(M, h, w, &p, x); compute output sample

printf("%lf\n", y); write output sample

}

for (i=0; i<M; i++) { input-off transients

y = cfir(M, h, w, &p, 0);

printf("%lf\n", y);

}

}

It is identical to firfilt.c, except it uses the circular version cfir instead of fir to do the ﬁl-

tering. In addition, the circular pointer p is deﬁned and initialized by the program. This program

must be compiled and linked with cfir.c and wrap.c. The version using the routine cfir1 is

identical.

The following version is based on the routine cfir2 and uses the circular pointer index q instead

of the pointer p. It must be linked with the routines cfir2 and wrap2.

/* cfirfil2.c - FIR filtering using circular delay-line buffer */

#include <stdlib.h>

#include <stdio.h>

#define MAX 64 initial allocation size

double cfir2();

void main(int argc, char **argv)

{

FILE *fph; ﬁlter ﬁle

double *h, *w; ﬁlter, states, circular pointer

double x, y; input and output samples

int M, i, q; circular pointer index

int max = MAX, dmax = MAX; allocation for h and increment

45

if (argc != 2) {

fprintf(stderr, "usage: cfirfil2 hfile <xfile >yfile\n");

exit(0);

}

if ((fph = fopen(argv[1], "r")) == NULL) {

fprintf(stderr, "can’t open filter file: %s\n", argv[1]);

exit(0);

}

h = (double *) calloc(max + 1, sizeof(double)); preliminary allocation

for (M=0;; M++) { read h

if (M == max) { reallocate h, if necessary

max += dmax;

h = (double *) realloc((char *) h, (max + 1) * sizeof(double));

}

if (fscanf(fph, "%lf", h + M) == EOF) break;

}

M--; M is ﬁlter order

h = (double *) realloc((char *) h, (M + 1) * sizeof(double));

w = (double *) calloc(M + 1, sizeof(double));

q = 0; initialize q

start ﬁltering:

while(scanf("%lf", &x) != EOF) { keep reading input samples

y = cfir2(M, h, w, &q, x); compute output sample

printf("%lf\n", y); write output sample

}

for (i=0; i<M; i++) { input-off transients

y = cfir2(M, h, w, &q, 0);

printf("%lf\n", y);

}

}

Problem 4.12

The following C program is an implementation:

/* cdelfilt.c - Implementation of delay using circular buffer */

#include <stdlib.h>

#include <stdio.h>

double cdelay();

double tap();

void main(int argc, char **argv)

{

double *w, *p; linear buffer & circular pointer

double x, y; input and output samples

int D, i, j;

46

if (argc != 3) {

fprintf(stderr, "usage: cdelfilt i D <xfile >yfile\n");

exit(0);

}

i = atoi(argv[1]);

D = atoi(argv[2]);

if (i>D) {

fprintf(stderr, "i must be in the range {0, 1, ..., D}\n");

exit(0);

}

w = (double *) calloc(D + 1, sizeof(double));

p = w; initialize p

while(scanf("%lf", &x) != EOF) { keep reading input samples

*p = x; store in circular buffer

y = tap(D, w, p, i); y(n) = x(n-i) = i-th delay

cdelay(D, w, &p); update delay line

printf("%lf\n", y); write output sample

}

for (j=0; j<i; j++) { input-off transients

*p = 0; zero input

y = tap(D, w, p, i);

cdelay(D, w, &p);

printf("%lf\n", y);

}

}

Problem 4.13

Consider a 3d order ﬁlter with internal states w

i

(n)= x(n − i), i = 0, 1, 2, 3. They are delayed

replicas of each other:

w

3

(n) = w

2

(n −1)

w

2

(n) = w

1

(n −1)

w

1

(n) = w

0

(n −1)

w

0

(n) = x(n)

Thus, the current states are obtained from the previous ones by shifting the previous contents

of the delay line and reading x(n) into w

0

(n). Once this shift is done, the ﬁlter’s output is

computed by the dot product:

y(n)= h

0

w

0

(n)+h

1

w

1

(n)+h

2

w

2

(n)+h

3

w

3

(n)

The following routine firalt.c implements this alternative procedure:

/* firalt.c - Alternative version of FIR filter in direct form */

double firalt(M, h, w, x) Usage: y=ﬁralt(M, h, w, x);

double *h, *w, x; h=ﬁlter, w=state, x=input

int M; M=ﬁlter order

{

47

int i;

double y; y=output sample

for (i=M; i>=1; i--) update states from previous call

w[i] = w[i-1]; done in reverse order

w[0] = x; read current input sample x

for (y=0, i=0; i<=M; i++)

y += h[i] * w[i]; process current output sample

return y;

}

Note that the previous state vector is updated ﬁrst into its current value, the current input is read

into w

0

, and only then is the output y computed. Upon exit, the states are left at their current

values and not updated. They will be updated by the next call. The vector w must be initialized

to zero prior to the ﬁrst call, just like the fir.c case.

Problem 4.14

Introduce the internal states:

w

0

(n) = x(n)

w

1

(n) = x(n −1)= w

0

(n −1)

w

2

(n) = x(n −2)= w

1

(n −1)

w

3

(n) = x(n −3)= w

2

(n −1)

Then, the I/O equation together with the state-updating equations will read:

w

0

(n)= x(n)

y(n)= w

0

(n)+w

1

(n)+2w

2

(n)+w

3

(n)

and

w

3

(n +1) = w

2

(n)

w

2

(n +1) = w

1

(n)

w

1

(n +1) = w

0

(n)

This leads to the following sample processing algorithm and block diagram:

x y

w

0

z

-1

z

-1

z

-1

w

1

w

2

w

3

2

for each input sample x do:

w

0

= x

y = w

0

+w

1

+2w

2

+w

3

w

3

= w

2

w

2

= w

1

w

1

= w

0

The sample processing algorithm generates the following output samples:

48

n x w

0

w

1

w

2

w

3

y = w

0

+w

1

+2w

2

+w

3

0 1 1 0 0 0 1

1 2 2 1 0 0 3

2 1 1 2 1 0 5

3 1 1 1 2 1 7

4 2 2 1 1 2 7

5 1 1 2 1 1 6

6 1 1 1 2 1 7

7 1 1 1 1 2 6

8 0 0 1 1 1 4

9 0 0 0 1 1 3

10 0 0 0 0 1 1

The ﬁ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:

#include <stdio.h>

#include <malloc.h> declares calloc()

double x[8] = {1,2,1,1,2,1,1,1};

double filter2();

void main()

{

int n;

double y, *w;

w = (double *) calloc(4, sizeof(double)); allocates & initializes w to zero

for (n=0; n<8; n++) { input-on transients & steady-state

y = filter2(x[n], w);

printf("%lf\n", y);

}

for (n=8; n<11; n++) { input-off transients

y = filter2(0.0, w);

printf("%lf\n", y);

}

}

double filter2(x, w) usage: y = ﬁlter2(x, w);

double x, *w;

{

double y;

w[0] = x; read input sample

y = w[0] + w[1] + 2 * w[2] + w[3]; compute output sample

w[3] = w[2]; update internal states

w[2] = w[1];

w[1] = w[0];

49

return y;

}

Problem 4.15

We deﬁne the state-variables w

i

(n), i = 0, 1, 2, 3 as follows:

w

0

(n) = x(n)

w

1

(n) = x(n −1)= w

0

(n −1)

w

2

(n) = x(n −2)= w

1

(n −1)

w

3

(n) = x(n −3)= w

2

(n −1)

Then, the I/O equation y(n)= x(n)−x(n − 3) together with the state-updating equations will

read:

w

0

(n)= x(n)

y(n)= w

0

(n)−w

3

(n)

and

w

3

(n +1) = w

2

(n)

w

2

(n +1) = w

1

(n)

w

1

(n +1) = w

0

(n)

Note that the output y(n) at time n and the next internal states at time n + 1 are computable

from the knowledge of the present input x(n) and the present states at time n. This leads to the

following sample processing algorithm and block diagram realization:

x

y

w

0

z

-1

z

-1

z

-1

w

1

w

2

w

3

-1

for each input sample x do:

w

0

= x

y = w

0

−w

3

w

3

= w

2

w

2

= w

1

w

1

= w

0

The sample processing algorithmcan be applied to the given input samples to generate the output

samples:

n x w

0

w

1

w

2

w

3

y = w

0

−w

3

0 1 1 0 0 0 1

1 1 1 1 0 0 1

2 2 2 1 1 0 2

3 2 2 2 1 1 1

4 4 4 2 2 1 3

Problem 4.16

We deﬁne the internal state:

w

1

(n)= y(n −1)

50

Then, the difference equation y(n)= 0.8y(n − 1)+x(n) and the state updating equation will

read:

y(n)= 0.8w

1

(n)+x(n) and w

1

(n +1)= y(n)

This leads to the following sample processing algorithm and block diagram realization:

x

0.8

y

y

z

-1

w

1

for each input sample x do:

y = 0.8w

1

+x

w

1

= y

The table of computations is:

n x w

1

y = 0.8w

1

+x

0 1 0.0000 1.0000

1 1 1.0000 1.8000

2 2 1.8000 3.4400

3 2 3.4400 4.7520

4 4 4.7520 7.8016

Problem 4.17

We deﬁne the internal states:

w

1

(n) = y(n −1)

w

2

(n) = y(n −2)= w

1

(n −1)

⇒

w

1

(n +1) = y(n)

w

2

(n +1) = y(n −1)= w

1

(n)

The difference equation y(n)= 0.25y(n −2)+x(n) and state updating equations become:

y(n)= 0.25w

2

(n)+x(n) and

w

2

(n +1) = w

1

(n)

w

1

(n +1) = y(n)

This leads to the following sample processing algorithm and block diagram realization:

x

0.25

y

y

z

-1

z

-1

w

2

w

1

for each input sample x do:

y = 0.25w

2

+x

w

2

= w

1

w

1

= y

General versions of such routines will be considered in Chapter 7. The sample processing algo-

rithm can be cranked on the given input samples to generate the output:

n x y = 0.25w

2

+x w

1

w

2

0 1 1 0 0

1 1 1 1 0

2 2 2.25 1 1

3 2 2.25 2.25 1

4 4 4.5625 2.25 2.25

51

Notice how the computed y becomes the next w

1

and w

1

shifts into w

2

.

Problem 4.18

The impulse response is read off from the coefﬁcients of the I/O equation:

h = [1, 0, −1, 2]

The LTI form is implemented by the following table:

n 0 1 2 3 4 5 6 7 8 9 10

x\h 1 0 -1 2 partial output

1 1 0 -1 2 x(0)h(n −0)

1 1 0 -1 2 x(1)h(n −1)

2 2 0 -2 4 x(2)h(n −2)

2 2 0 -2 4 x(3)h(n −3)

2 2 0 -2 4 x(4)h(n −4)

2 2 0 -2 4 x(5)h(n −5)

1 1 0 -1 2 x(6)h(n −6)

1 1 0 -1 2 x(7)h(n −7)

y(n) 1 1 1 3 2 4 3 3 3 1 2

_

m

x(m)h(n −m)

For the overlap-add method, the input is divided into the following length-4 contiguous blocks:

x = [ 1, 1, 2, 2

. ¸, .

x0

, 2, 2, 1, 1

. ¸, .

x1

, ]

Convolving each block separately with h gives:

y

0

= h ∗x

0

= [1, 1, 1, 3, 0, 2, 4]

y

1

= h ∗x

1

= [2, 2, −1, 3, 3, 1, 2]

These convolutions can be done by separately folding the two convolution subtables:

block 0 block 1

h\x 1 1 2 2 2 2 1 1

1 1 2 2 2 2 2 1 1

0 0 0 0 0 0 0 0 0

-1 -1 -1 -2 -2 -2 -2 -1 -1

2 2 2 4 4 4 4 2 2

The two subblocks begin at the absolute times n = 0, 4, respectively. It follows from time-

invariance that the corresponding output blocks will also begin at the same absolute times. Thus,

aligning the output blocks according to their absolute timings and adding them up gives the ﬁnal

result:

n 0 1 2 3 4 5 6 7 8 9 10

y

0

1 1 1 3 0 2 4

y

1

2 2 -1 3 3 1 2

y 1 1 1 3 2 4 3 3 3 1 2

52

The block diagram and sample processing algorithm are:

x

y

w

0

z

-1

z

-1

z

-1

w

1

w

2

w

3 2

-1

for each input sample x do:

w

0

= x

y = w

0

−w

2

+2w

3

w

3

= w

2

w

2

= w

1

w

1

= w

0

The corresponding circular-buffer version will be:

for each input sample x do:

s

0

= ∗p = x

s

2

= tap(3, w, p, 2)

s

3

= tap(3, w, p, 3)

y = s

0

−s

2

+2s

3

cdelay(3, w, &p)

where tap-1 is not needed, but tap-2 and tap-3 are. Tap-0 s

0

is the content of the current location

pointed to by p, which receives the input sample x. After y is computed, the call to cdelay

circularly decrements the pointer p.

Problem 4.19

Figure P4.2 shows the contents of the registers w = [w

0

, w

1

, w

1

] at successive time instants. Each

time the circular pointer p = p

in

points to the w-register that receives the current input, whereas

the pointer p

out

points to the w-register containing the current output, that is, y(n)= x(n −2).

Therefore, p

out

is shifted clockwise by 2 with respect to p

in

:

p

out

= p

in

+2 (modulo 3)

As p

in

gets decremented circularly, so does p

out

. If p

in

points to w[q

in

] and p

out

to w[q

out

], then

p

in

= w+q

in

p

out

= w+q

out

where

q

out

= (q

in

+2)%3

Thus, the input and output circular indices take on the sequence of values:

q

in

= 0, 2, 1, 0, 2, 1, 0, 2, 1, 0, 2

q

out

= 2, 1, 0, 2, 1, 0, 2, 1, 0, 2, 1

The following table lists the contents of w for both the linear and circular buffer implementa-

tions. In the linear case, w

0

, w

1

and w

2

are simply the input signal delayed by i = 0, 1, 2 units.

In the circular case, the down-arrow indicates the w-register receiving the current input, that is,

w[q

in

], whereas the up-arrow indicates the corresponding output sample, that is, w[q

out

]. In

the circular case, only one w-register changes value at each time instant.

53

p

in

w

0

w

1

w

2

p

out

0

0

n=0

p

in

p

out

p

in

p

out

p

in

p

out

p

in

p

out

0

n=1

p

in

p

out

p

in

p

out

p

in

p

out

n=2

p

in

p

out

p

in

p

out

p

in

p

out

n=3

n=4 n=5 n=6 n=7

n=8 n=9 n=10

8 8 8

7 7 7

6 6

6

5

5 5

4 4 4

3 3 3

2 2

2

1

1 1

0 0 0

0 0

0

Fig. P4.2 Circular delay-line buffer contents.

linear circular

n x w

0

w

1

w

2

w

0

w

1

w

2

q

in

q

out

y

0 8 8 0 0 8↓ 0 0↑ 0 2 0

1 7 7 8 0 8 0↑ 7↓ 2 1 0

2 6 6 7 8 8↑ 6↓ 7 1 0 8

3 5 5 6 7 5↓ 6 7↑ 0 2 7

4 4 4 5 6 5 6↑ 4↓ 2 1 6

5 3 3 4 5 5↑ 3↓ 4 1 0 5

6 2 2 3 4 2↓ 3 4↑ 0 2 4

7 1 1 2 3 2 3↑ 1↓ 2 1 3

8 0 0 1 2 2↑ 0↓ 1 1 0 2

9 0 0 0 1 0↓ 0 1↑ 0 2 1

10 0 0 0 0 0 0↑ 0↓ 2 1 0

Problem 4.20

The transposed form is obtained by the following rules:

1. Exchange input with output.

2. Reverse all signal ﬂows.

4. Replace all adders by nodes.

3. Replace all nodes by adders.

For example, in Fig. 4.2.7, the output adder will be replaced by a node with the signals ﬂ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.

54

x(n) y(n)

v

1

(n)

v

2

(n)

v

3

(n)

z

-1

z

-1

z

-1

h

0

h

1

h

2

h

3

Fig. P4.3 Transposed direct form realization.

Let v

1

(n), v

2

(n), and v

3

(n) be the contents of the three delays at time n. They can be thought

of as the internal states of the realization. Because of the intervening adders between the delays,

the v

i

(n) are no longer the delayed versions of each other. Rather, each is a delayed version of

its input. These inputs will become the contents of the delays at the next time instant. Therefore,

the I/O equations describing the ﬁlter are in this case:

y(n)= v

1

(n)+h

0

x(n) and

v

1

(n +1) = v

2

(n)+h

1

x(n)

v

2

(n +1) = v

3

(n)+h

2

x(n)

v

3

(n +1) = h

3

x(n)

This system is equivalent to the original I/O equation (4.2.6). Indeed, down-shifting v

1

(n + 1),

we have

v

1

(n)= v

2

(n −1)+h

1

x(n −1)

Therefore,

y(n)= h

0

x(n)+v

1

(n)= h

0

x(n)+

_

h

1

x(n −1)+v

2

(n −1)

_

Similarly, down-shifting v

2

(n+1) twice, that is, v

2

(n−1)= v

3

(n−2)+h

2

x(n−2), and v

3

(n+1)

three times, that is, v

3

(n −2)= h

3

x(n −3), we get

y(n) = h

0

x(n)+h

1

x(n −1)+v

2

(n −1)

= h

0

x(n)+h

1

x(n −1)+

_

h

2

x(n −2)+v

3

(n −2)

_

= h

0

x(n)+h

1

x(n −1)+h

2

x(n −2)+h

3

x(n −3)

which is equivalent to Eq. (4.2.6). The I/O system leads then to the following sample by sample

processing algorithm:

55

for each input sample x do:

y = v

1

+h

0

x

v

1

= v

2

+h

1

x

v

2

= v

3

+h

2

x

v

3

= h

3

x

For Example 4.2.1, Table P4.1 shows the contents of the v

i

registers at each time instant. The v

i

are initialized to zero. The v

1

and v

2

entries in each row are obtained by forming v

2

+h

1

x and

v

3

+ h

2

x of the previous row. The v

3

column is the delayed (down-shifted) version of the h

3

x

column. The ﬁnal result is the same as in Example 4.2.1.

n x h

0

x h

1

x h

2

x h

3

x v

1

v

2

v

3

y = v

1

+h

0

x

0 1 1 2 −1 1 0 0 0 1

1 1 1 2 −1 1 2 −1 1 3

2 2 2 4 −2 2 1 0 1 3

3 1 1 2 −1 1 4 −1 2 5

4 2 2 4 −2 2 1 1 1 3

5 2 2 4 −2 2 5 −1 2 7

6 1 1 2 −1 1 3 0 2 4

7 1 1 2 −1 1 2 1 1 3

8 0 0 0 0 0 3 0 1 3

9 0 0 0 0 0 0 1 0 0

10 0 0 0 0 0 1 0 0 1

Table P4.1 Computations in Problem 4.20.

Problem 4.21

The generalization of the transposed algorithm to order M is straightforward:

for each input sample x do:

for i = 0, 1, . . . , M−1 do:

v

i

= v

i+1

+h

i

x

v

M

= h

M

x

y = v

0

where for indexing convenience we introduced v

0

(n)= y(n)= v

1

(n)+h

0

x(n). The following C

routine firtr.c is an implementation:

/* firtr.c - FIR filter in transposed direct form */

double firtr(M, h, v, x) Usage: y=ﬁrtr(M, h, v, x);

double *h, *v, x; h=ﬁlter, v=state, x=input

int M; M=ﬁlter order

{

int i;

56

for (i=0; i<=M-1; i++)

v[i] = v[i+1] + h[i] * x; output & update states

v[M] = h[M] * x; last state

return v[0]; y = v

0

= v

1

+h

0

x

}

The following stand-alone C program firfiltr.c is the corresponding version of firfilt.c.

The only difference is that it uses the routine firtr.c instead of fir.c:

/* firfiltr.c - FIR filtering in transposed form */

#include <stdlib.h>

#include <stdio.h>

#define MAX 64 initial allocation size

double firtr();

void main(int argc, char **argv)

{

FILE *fph; ﬁlter ﬁle

double *h, *v, x, y; ﬁlter array, input, output samples

int M, i;

int max = MAX, dmax = MAX; allocation for h and increment

if (argc != 2) {

fprintf(stderr, "usage: firfilt hfile <xfile >yfile\n");

exit(0);

}

if ((fph = fopen(argv[1], "r")) == NULL) {

fprintf(stderr, "can’t open filter file: %s\n", argv[1]);

exit(0);

}

h = (double *) calloc(max + 1, sizeof(double)); preliminary allocation

for (M=0;; M++) { read h

if (M == max) { reallocate h, if necessary

max += dmax;

h = (double *) realloc((char *) h, (max + 1) * sizeof(double));

}

if (fscanf(fph, "%lf", h + M) == EOF) break;

}

M--; M is ﬁlter order

h = (double *) realloc((char *) h, (M + 1) * sizeof(double)); ﬁnal allocation

v = (double *) calloc((M + 1), sizeof(double));

while(scanf("%lf", &x) != EOF) { keep reading input samples

y = firtr(M, h, v, x); compute output sample

printf("%lf\n", y); write output sample

}

for (i=0; i<M; i++) { input-off transients

57

y = firtr(M, h, v, 0.0); compute output sample

printf("%lf\n", y);

}

}

Transposed forms are convenient in some applications, such as in the implementation of FIR

decimators and interpolators in multirate applications. MATLAB uses this form to implement its

built-in ﬁltering routines.

58

Chapter 5 Problems

Problem 5.1

The linearity property follows from:

∞

_

n=−∞

[a

1

x

1

(n)+a

2

x

2

(n)]z

−n

= a

1

∞

_

n=−∞

x

1

(n)z

−n

+a

2

∞

_

n=−∞

x

2

(n)z

−n

The delay property follows from:

X

D

(z) =

∞

_

n=−∞

x

D

(n)z

−n

=

∞

_

n=−∞

x(n −D)z

−n

=

=

∞

_

k=−∞

x(k)z

−(k+D)

= z

−D

∞

_

k=−∞

x(k)z

−k

= z

−D

X(z)

where we changed summation index from n to k = n − D, so that n = k + D. The convolution

property follows from the linearity and delay properties. Writing y(n) in terms of the delayed

replicas of x(n), we have:

y(n)=

∞

_

m=−∞

h(m)x(n −m)=

∞

_

m=−∞

h(m)x

m

(n)

Taking z-transforms of both sides and using the linearity and delay properties, we get:

Y(z)=

∞

_

m=−∞

h(m)X

m

(z)=

∞

_

m=−∞

h(m)z

−m

X(z)=

_

∞

_

m=−∞

h(m)z

−m

_

X(z)

or,

Y(z)= H(z)X(z)

Problem 5.2

a. From the delay property of z-transforms, X(z)= z

−5

Δ(z), where Δ(z)= 1 is the z-

transform of δ(n). Thus, X(z)= z

−5

. The ROC is the entire z-plane with the exception of

the point z = 0.

b. Similarly, X(z)= z

5

Δ(z)= z

5

, but now the ROC must only exclude the point at inﬁnity

z = ∞.

c. The unit-step has z-transform: U(z)= 1/(1 −z

−1

). Thus,

X(z)= z

−5

U(z)=

z

−5

1 −z

−1

with ROC ¦z¦ > 1.

d. We may work with the deﬁnition:

X(z) =

∞

_

n=−∞

u(−n +5)z

−n

=

5

_

n=−∞

1 · z

−n

= z

−5

+z

−4

+z

−3

+z

−2

+z

−1

+1 +z +z

2

+z

3

+· · ·

= z

−5

_

1 +z +z

2

+z

3

+· · ·

_

=

z

−5

1 −z

= z

−5

U(z

−1

)

59

The convergence of the series requires the ROC ¦z¦ < 1.

Alternatively, we recognize that x(n) is the delayed version of u(−n), that is, x(n)=

u(−n +5)= u(−(n −5)). Using the general property that

g(n)

Z

−→G(z) ⇒ g(−n)

Z

−→G(z

−1

)

we ﬁnd X(z)= z

−5

U(z

−1

).

Problem 5.3

a. Using the general result: a

n

u(n)−→ 1/(1 − az

−1

), ROC ¦z¦ > ¦a¦, we obtain: X(z)=

1/(1 −(−0.5)z

−1

)= 1/(1 +0.5z

−1

), with ROC ¦z¦ > ¦ −0.5¦ = 0.5.

b. Method 1: Let w(n)= u(n)−u(n − 10) with z-transform W(z). Using the linearity and

delay properties, we have

W(z)= U(z)−z

−10

U(z)= (1 −z

−10

)U(z)=

1 −z

−10

1 −z

−1

Using the modulation property of z-transforms, we have

a

n

w(n)−→W(z/a)=

1 −(z/a)

−10

1 −(z/a)

−1

=

1 −a

10

z

−10

1 −az

−1

With a = −0.5, we have X(z)= (1 −(−0.5)

10

z

−10

)/(1 +0.5z

−1

).

ROC is the whole z-plane minus the point z = 0.

Method 2: We recognize that x(n) is the ﬁnite sequence

x(n)= [1, a, a

2

, a

3

, a

4

, a

5

, a

6

, a

7

, a

8

, a

9

, 0, 0, 0, · · · ]

and use the deﬁnition of z-transforms:

X(z)= 1 +az

−1

+a

2

z

−2

+· · · +a

9

z

−9

=

1 −a

10

z

−10

1 −az

−1

where in the last step we used the ﬁnite geometric series:

1 +x +x

2

+· · · +x

m

=

1 −x

m+1

1 −x

, with x = az

−1

and m= 9

c. X(z)=

1

1 −0.5z

−1

+

1

1 +0.5z

−1

=

2

(1 −0.5z

−1

)(1 +0.5z

−1

)

=

2

1 −0.25z

−2

, ROC ¦z¦ >

0.5.

Problem 5.4

Using Euler, 2cos θ = e

jθ

+e

−jθ

, with θ = πn/2 and also the fact that e

jπ/2

= j and e

−jπ/2

= −j,

we rewrite

2(0.8)

n

cos(πn/2) = (0.8)

n

[e

jπn/2

+e

−jπn/2

]

= (0.8)

n

[j

n

+(−j)

n

]= (0.8j)

n

+(−0.8j)

n

Thus, the signals in questions (a) and (b) are the same. Their z-transform is

60

X(z)=

1

1 −0.8jz

−1

+

1

1 +0.8jz

−1

=

2

(1 −0.8jz

−1

)(1 +0.8jz

−1

)

=

2

1 +0.64z

−2

ROC is ¦z¦ > ¦0.8j¦ = 0.8. An alternative method is to list a few of the signal values and then use

the inﬁnite geometric series to sum them up, that is, with a = 0.8:

x(n)= 2[1, 0, −a

2

, 0, a

4

, 0, −a

6

, 0, a

8

, 0, −a

10

, 0, · · · ]

we obtain

X(z)= 2[1 −a

2

z

−2

+a

4

z

−4

−a

6

z

−6

+a

8

z

−8

−a

10

z

−10

+· · · ]=

2

1 +a

2

z

−2

where we applied the inﬁnite geometric series

1 +x +x

2

+x

3

+· · · =

1

1 −x

with x = −a

2

z

−2

. Convergence of the geometric series requires that ¦x¦ < 1 or ¦ −a

2

z

−2

¦ < 1 or

¦z¦ > ¦a¦ or in our case ¦z¦ > 0.8.

Problem 5.5

The three signals in parts (a,b,c) all have the same z-transform, namely,

X(z)=

1

1 −0.25z

−1

+

1

1 −4z

−1

=

2 −4.25z

−1

1 −4.25z

−1

+z

−2

They differ only in their region of convergence: In case (a), both terms are causal, therefore

¦z¦ > 0.25 and ¦z¦ > 4. Thus, ROC is ¦z¦ > 4. In case (b), the ﬁ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

X(z)= −

−1

_

n=−∞

(0.25)

n

z

−n

+

∞

_

n=0

4

n

z

−n

would require ROC ¦z¦ < 0.25 and the second ¦z¦ > 4. The intersection of the two ROC sets is

empty, that is, there is no set of z’s for which the z-transform would converge.

Problem 5.6

Method 1: List the values of x(n) and sum the geometric series:

x(n) = [1, 0, −1, 0, 1, 0, −1, 0, 1, 0, −1, 0, . . . ]

X(z) = 1 −z

−2

+z

−4

−z

−6

+z

−8

−· · ·

= 1 +x +x

2

+x

3

+x

4

+· · ·

¸

¸

x=−z

−2 =

1

1 −x

¸

¸

¸

¸

x=−z

−2

=

1

1 +z

−2

where convergence of the geometric series requires:

61

¦x¦ < 1 ⇒ ¦ −z

−2

¦ < 1 ⇒ ¦z¦ > 1

Method 2: Use Euler’s formula to split x(n) as the sum of two terms of the form a

n

u(n):

x(n)= cos(πn/2)u(n)=

1

2

_

e

πjn/2

+e

−πjn/2

_

u(n)=

1

2

[j

n

+(−j)

n

]u(n)

where we used e

πj/2

= j. Taking z-transforms, we ﬁnd:

X(z)=

1/2

1 −jz

−1

+

1/2

1 +jz

−1

=

1

(1 −jz

−1

)(1 +jz

−1

)

=

1

1 +z

−2

where we applied the result

a

n

u(n)

Z

−→

1

1 −az

−1

for a = j and a = −j.

Method 3: Recognize that x(n) is periodic with period 4. Deﬁning the length-4 sequence

g = [1, 0, −1, 0], we see that x(n) will be the periodic replication of g(n):

x = [g, g, g, . . . ] or,

x(n)= g(n)+g(n −4)+g(n −8)+g(n −12)+· · ·

Taking z-transforms of both sides gives

X(z)= G(z)+z

−4

G(z)+z

8

G(z)+· · · =

_

1 +z

−4

+z

−8

+z

−12

+· · ·

_

G(z)

Summing up the series and using G(z)= 1 −z

−2

, we get:

X(z)=

G(z)

1 −z

−4

=

1 −z

−2

1 −z

−4

=

1 −z

−2

(1 −z

−2

)(1 +z

−2

)

=

1

1 +z

−2

Problem 5.7

Whenever X(z) is a polynomial, the best method to invert is to just pick out the coefﬁcients of

the polynomial. For (a), we have:

X(z) = (1 −4z

−2

)(1 +3z

−1

)= 1 +3z

−1

−4z

−2

−12z

−3

⇒ x(n) = [1, 3, −4, −12]

For (b), the signal is non-zero only at n = −3, 0, 2:

x(n)= 5δ(n)+3δ(n +3)+2δ(n −2)

62

Problem 5.8

a. Carry out a partial fraction expansion:

X(z)=

3(1 +0.3z

−1

)

1 −0.81z

−2

=

3(1 +0.3z

−1

)

(1 −0.9z

−1

)(1 +0.9z

−1

)

=

A

1 −0.9z

−1

+

B

1 +0.9z

−1

where

A =

_

3(1 +0.3z

−1

)

1 +0.9z

−1

_

z=0.9

= 2, B =

_

3(1 +0.3z

−1

)

1 −0.9z

−1

_

z=−0.9

= 1

The ﬁrst ROC is ¦z¦ > ¦0.9¦ = ¦ −0.9¦, thus both terms will be inverted causally:

x(n)= A(0.9)

n

u(n)+B(−0.9)

n

u(n)

As expected, the answer is stable because the ROC contains the unit circle. The second

ROC is ¦z¦ < ¦0.9¦ = ¦ −0.9¦, thus both terms will be inverted anticausally:

x(n)= −A(0.9)

n

u(−n −1)−B(−0.9)

n

u(−n −1)

The answer is unstable, because the ROC does not contain the unit circle.

b. Ordinary partial fraction expansion is not valid in this case because the degree of the

numerator is the same as the degree of the denominator. However, we may still have an

expansion of the form:

X(z) =

6 −3z

−1

−2z

−2

1 −0.25z

−2

=

6 −3z

−1

−2z

−2

(1 −0.5z

−1

)(1 +0.5z

−1

)

= A+

B

1 −0.5z

−1

+

C

1 +0.5z

−1

where B and C are determined in the usual manner and A is determined by evaluating

X(z) at z = 0:

A =

_

6 −3z

−1

−2z

−2

1 −0.25z

−2

_

z=0

=

_

6z

2

−3z −2

z

2

−0.25

_

z=0

=

−2

−0.25

= 8

B =

_

6 −3z

−1

−2z

−2

1 +0.5z

−1

_

z=0.5

= −4, C =

_

6 −3z

−1

−2z

−2

1 −0.5z

−1

_

z=−0.5

= 2

For the ﬁrst ROC, ¦z¦ > 0.5, the last two terms will be inverted causally:

x(n)= Aδ(n)+B(0.5)

n

u(n)+C(−0.5)

n

u(n)

For the second ROC, ¦z¦ < 0.5, the two terms will be inverted anticausally:

x(n)= Aδ(n)−B(0.5)

n

u(−n −1)−C(−0.5)

n

u(−n −1)

As expected, only the ﬁrst inverse is stable because its ROC contains the unit circle.

63

c. The degree of the numerator is strictly greater than the degree of the denominator. The

simplest approach in such cases is to use the “remove/restore” method, that is, ignore

the numerator completely, do a partial fraction on the denominator, get its inverse z-

transform, and ﬁnally restore the effect of the numerator. To show these steps, write

X(z) =

6 +z

−5

1 −0.64z

−2

= (6 +z

−5

)·

_

1

1 −0.64z

−2

_

≡ (6 +z

−5

)W(z)= 6W(z)+z

−5

W(z)

In the time-domain, we have then

x(n)= 6w(n)+w(n −5)

Thus, the problem is reduced to the problem of ﬁnding w(n). Doing a partial fraction

expansion on W(z), we ﬁnd

W(z)=

1

1 −0.64z

−2

=

1

(1 −0.8z

−1

)(1 +0.8z

−1

)

=

A

1 −0.8z

−1

+

B

1 +0.8z

−1

where A = B = 0.5. For the ROC ¦z¦ > 0.8, the two terms are inverted causally:

w(n)= A(0.8)

n

u(n)+B(−0.8)

n

u(n)

Inserting in x(n)= 6w(n)+w(n −5), we ﬁnd

x(n) = 6A(0.8)

n

u(n)+6B(−0.8)

n

u(n)+A(0.8)

n−5

u(n −5)

+B(−0.8)

n−5

u(n −5)

Note that the last two terms are active only for n ≥ 5. For the ROC ¦z¦ < 0.8, we have the

anticausal/unstable answer:

w(n)= −A(0.8)

n

u(−n −1)−B(−0.8)

n

u(−n −1)

which gives for x(n):

x(n) = −6A(0.8)

n

u(−n −1)−6B(−0.8)

n

u(−n −1)

−A(0.8)

n−5

u(−n +4)−B(−0.8)

n−5

u(−n +4)

The u(−n+4) was obtained as u(−(n−5)−1). Note also that the last two terms are now

active for −n + 4 ≥ 0 or n ≤ 4, that is, x(n) has a slightly causal part extending to the

right up to n = 4. This happened because the strictly anticausal signal w(n) was delayed

(shifted to the right) by 5 time units by the term w(n −5).

d. The minor new feature of this problem is that the poles are complex-valued. When the

poles are complex, they come in conjugate pairs. In this case, the corresponding residues

are complex conjugates, too. Thus, only half of the residues need be computed:

X(z) =

10 +z

−2

1 +0.25z

−2

=

10 +z

−2

(1 −0.5jz

−1

)(1 +0.5jz

−1

)

= A+

B

1 −0.5jz

−1

+

B

∗

1 +0.5jz

−1

64

Again, the A-term is needed because the degrees of numerator and denominator polyno-

mials are equal. We ﬁnd

A =

_

10 +z

−2

10.25z

−2

_

z=0

=

_

10z

2

+1

z

2

+0.25

_

z=0

=

1

0.25

= 4

B =

_

10 +z

−2

1 +0.5jz

−1

_

z=0.5j

= 3

We only needed to calculate B, and use B

∗

for the conjugate pole. For the causal case, we

have

x(n)= Aδ(n)+B(0.5j)

n

u(n)+B

∗

(−0.5j)

n

u(n)

Now, because the last two terms are complex conjugates of each other, we may use the

general identity 2Re(z)= z +z

∗

to write

B(0.5j)

n

u(n)+B

∗

(−0.5j)

n

u(n)= 2Re[B(0.5j)

n

u(n)]= 6(0.5)

n

Re[j

n

]u(n)

But, Re[j

n

]= Re[e

jπn/2

]= cos(πn/2) Thus,

B(0.5j)

n

u(n)+B

∗

(−0.5j)

n

u(n)= 6(0.5)

n

cos(πn/2)u(n)

and the ﬁnal result is

x(n)= 4δ(n)+6(0.5)

n

cos(πn/2)u(n)

For the anticausal case, we obtain the anticausal version of the second term, namely,

x(n)= 4δ(n)−6(0.5)

n

cos(πn/2)u(−n −1)

e. The partial fraction expansion is:

X(z)=

6 −2z

−1

−z

−2

(1 −z

−1

)(1 −0.25z

−2

)

=

4

1 −z

−1

+

1

1 −0.5z

−1

+

1

1 +0.5z

−1

Because ROC is ¦z¦ > 1 > 0.5, all terms are inverted causally to give:

x(n)= 4u(n)+(0.5)

n

u(n)+(−0.5)

n

u(n)

The answer is marginally stable because the pole z = 1 is on the unit circle.

f. The PF expansion gives:

X(z) = −4 +

1

1 +4z

−2

= −4 +

1

(1 −2jz

−1

)(1 +2jz

−1

)

= −4 +

1/2

1 −2jz

−1

+

1/2

1 +2jz

−1

The two regions of convergence are:

¦z¦ > 2 and ¦z¦ < 2

65

They correspond to the causal and anticausal inverses:

x

1

(n) = −4δ(n)+0.5(2j)

n

u(n)+0.5(−2j)

n

u(n)

x

2

(n) = −4δ(n)−0.5(2j)

n

u(−n −1)+0.5(−2j)

n

u(−n −1)

Using Euler’s formula, we may write:

0.5

_

(2j)

n

+(−2j)

n

] = 2

n

1

2

[j

n

+(−j)

n

]= 2

n

1

2

[e

jπn/2

+e

−jπn/2

]

= 2

n

cos(πn/2)

Thus, we can rewrite:

x

1

(n) = −4δ(n)+2

n

cos(πn/2)u(n)

x

2

(n) = −4δ(n)−2

n

cos(πn/2)u(−n −1)

Only x

2

(n) is stable because its ROC contains the unit circle, or, because in the second

termn is effectively negative and causes it to decay exponentially for large negative n, that

is, writing n = −¦n¦, we have:

2

n

cos(πn/2)u(−n −1)= 2

−¦n¦

cos(πn/2)u(−n −1)→0 as n →−∞

g. The PF expansion is in this case:

X(z)=

4 −0.6z

−1

+0.2z

−2

(1 −0.5z

−1

)(1 +0.4z

−1

)

= A+

B

1 −0.5z

−1

+

C

1 +0.4z

−1

where

A =

_

4 −0.6z

−1

+0.2z

−2

(1 −0.5z

−1

)(1 +0.4z

−1

)

_

z=0

=

0.2

−0.5 · 0.4

= −1

B =

_

4 −0.6z

−1

+0.2z

−2

1 +0.4z

−1

_

z=0.5

= 2

C =

_

4 −0.6z

−1

+0.2z

−2

1 −0.5z

−1

_

z=−0.4

= 3

The three ROC’s are:

¦z¦ > 0.5, 0.5 > ¦z¦ > 0.4, 0.4 > ¦z¦

The corresponding inverses are:

x

1

(n) = Aδ(n)+B(0.5)

n

u(n)+C(−0.4)

n

u(n)

x

2

(n) = Aδ(n)−B(0.5)

n

u(−n −1)+C(−0.4)

n

u(n)

x

3

(n) = Aδ(n)−B(0.5)

n

u(−n −1)−C(−0.4)

n

u(−n −1)

Only x

1

(n) is stable. Its ROC contains the unit circle. The B-term in x

2

(n) and both the B

and C terms of x

3

(n) diverge exponentially for large negative n.

66

Problem 5.9

Consider the z-transform pair:

x

a

(n)= a

n

u(n) X

a

(z)=

1

1 −az

−1

Applying the derivative operator ∂/∂a to the pair, derive the z-transform of the sequence x(n)=

na

n

u(n).

Noting that

∂

∂a

x

a

(n)= na

n−1

u(n)

we get

∂

∂a

X

a

(z)=

∂

∂a

_

1

1 −az

−1

_

=

z

−1

(1 −az

−1

)

2

Thus,

na

n−1

u(n)

Z

−→

z

−1

(1 −az

−1

)

2

Multiplying by a, we get:

na

n

u(n)

Z

−→

az

−1

(1 −az

−1

)

2

Problem 5.10

We note that each application of D brings down a factor of n:

D(a

n

) = a

∂

∂a

(a

n

)= ana

n−1

= na

n

D

2

(a

n

) = D(D(a

n

))= D(na

n

)= nD(a

n

)= n(na

n

)= n

2

a

n

D

3

(a

n

) = D(D

2

(a

n

))= D(n

2

a

n

)= n

2

D(a

n

)= n

2

(na

n

)= n

3

a

n

· · ·

D

k

(a

n

) = n

k

a

n

Thus, in the z-domain:

n

k

a

n

u(n)

Z

−→

_

a

∂

∂a

_

k

_

1

1 −az

−1

_

In particular, for k = 1, we have:

_

a

∂

∂a

__

1

1 −az

−1

_

=

az

−1

(1 −az

−1

)

2

Therefore,

na

n

u(n)

Z

−→

az

−1

(1 −az

−1

)

2

67

which agrees with the previous problem. For k = 2, we apply D again to get:

_

a

∂

∂a

_

2

_

1

1 −az

−1

_

=

_

a

∂

∂a

_

_

az

−1

(1 −az

−1

)

2

_

= az

−1

_

1

(1 −az)

2

+

2az

−1

(1 −az

−1

)

3

_

=

az

−1

(1 +az

−1

)

(1 −az

−1

)

3

Therefore,

n

2

a

n

u(n)

Z

−→

az

−1

(1 +az

−1

)

(1 −az

−1

)

3

Adding the results of the k = 1 and k = 2 cases, we also get:

n(n +1)a

n

u(n)

Z

−→

2az

−1

(1 −az

−1

)

3

For the cases k = 3, 4, we ﬁnd after some tedious algebra:

n

3

a

n

u(n)

Z

−→

az

−1

(1 +4az

−1

+a

2

z

−2

)

(1 −az

−1

)

4

n

4

a

n

u(n)

Z

−→

az

−1

(1 +11az

−1

+11a

2

z

−2

+a

3

z

−3

)

(1 −az

−1

)

5

Problem 5.11

Deﬁning the square pulses

g

1

(n) = u(n)−u(n −L)

g

2

(n) = g

1

(n +L −1)= u(n +L −1)−u(n −1)

and using the z-transform

u(n)

Z

−→U(z)=

1

1 −z

−1

we ﬁnd the z-transforms:

G

1

(z) = U(z)−z

−L

U(z)=

1 −z

−L

1 −z

−1

G

2

(z) = U(z)z

L−1

−z

−1

U(z)=

1 −z

−L

1 −z

−1

z

L−1

Therefore, the right-hand-side of the desired z-transform is the product:

X(z)=

1

L

_

1 −z

−L

1 −z

−1

_

2

z

L−1

=

1

L

G

1

(z)G

2

(z)

Thus, in the time domain we have the convolution:

x(n)=

1

L

g

1

(n)∗g

2

(n)=

1

L

_

m

g

1

(m)g

2

(n −m)

68

Because g

1

(n) is non-zero only over 0 ≤ n ≤ L −1 and g

2

(n) over −(L −1)≤ n ≤ 0, we obtain

the restrictions on the convolution summation indices:

0 ≤ m≤ L −1

−(L −1) ≤ n −m≤ 0

By adding them, we obtain the overall range of the index n of x(n), that is,

−(L −1)≤ n ≤ L −1

For any n in this range, we obtain the range of the summation in m:

0 ≤ m≤ L −1

0 ≤ m−n ≤ L −1 ⇒ n ≤ m≤ n +L −1

which combine into the single inequality:

max(0, n)≤ m≤ min(L −1, n +L −1)

The convolution sum becomes then:

x(n)=

1

L

min(L−1,n+L−1)

_

m=max(0,n)

g

1

(m)g

2

(n −m), −(L −1)≤ n ≤ L −1

Because over this range, both g

1

(n) and g

2

(n) are unity, we obtain:

x(n)=

1

L

min(L−1,n+L−1)

_

m=max(0,n)

1 · 1 =

1

L

_

max(L −1, n +L −1)−min(0, n)+1

_

By checking separately the ranges −(L − 1)≤ n ≤ 0 and 0 ≤ n ≤ L − 1, it is easily veriﬁed that

the above expression is equivalent to:

x(n)=

1

L

_

max(L −1, n +L −1)−min(0, n)+1

_

= 1 −

¦n¦

L

, −(L −1)≤ n ≤ L −1

At all other n, including the end-points n = :L, x(n) is zero.

Problem 5.12

Start with the result

a

n

u(n)

Z

−→

1

1 −az

−1

and apply it for a = Re

jω0

and a

∗

= Re

−jω0

:

R

n

e

jω0n

u(n)

Z

−→

1

1 −Re

jω0

z

−1

R

n

e

−jω0n

u(n)

Z

−→

1

1 −Re

−jω0

z

−1

The cosine and sine signals are obtained from the above as the following linear combinations:

R

n

cos(ω

0

n)u(n) = R

n

1

2

_

e

jω0n

u(n)+e

−jω0n

u(n)

_

R

n

sin(ω

0

n)u(n) = R

n

1

2j

_

e

jω0n

u(n)−e

−jω0n

u(n)

_

69

Therefore, the corresponding linear combinations of z-transforms will be:

R

n

cos(ω

0

n)u(n)

Z

−→

1

2

_

1

1 −Re

jω0

z

−1

+

1

1 −Re

−jω0

z

−1

_

R

n

sin(ω

0

n)u(n)

Z

−→

1

2j

_

1

1 −Re

jω0

z

−1

−

1

1 −Re

−jω0

z

−1

_

which simplify into:

R

n

cos(ω

0

n)u(n)

Z

−→

1 −Rcos ω

0

z

−1

1 −2Rcos ω

0

z

−1

+R

2

z

−2

R

n

sin(ω

0

n)u(n)

Z

−→

Rsinω

0

z

−1

1 −2Rcos ω

0

z

−1

+R

2

z

−2

Problem 5.13

Deﬁne the z-transform of one period:

A(z)= a

0

+a

1

z

−1

+a

2

z

−2

+a

3

z

−3

Then, the z-transform of the periodic signal is recognized as the sum of the delayed replicas of

A(z), that is,

X(z) = a

0

+a

1

z

−1

+a

2

z

−2

+a

3

z

−3

+a

0

z

−4

+a

1

z

−5

+a

2

z

−6

+a

3

z

−7

+a

0

z

−8

+a

1

z

−9

+a

2

z

−10

+a

3

z

−11

+· · ·

= (a

0

+a

1

z

−1

+a

2

z

−2

+a

3

z

−3

)+z

−4

(a

0

+a

1

z

−1

+a

2

z

−2

+a

3

z

−3

)

+z

−8

(a

0

+a

1

z

−1

+a

2

z

−2

+a

3

z

−3

)+· · ·

= A(z)+z

−4

A(z)+z

−8

A(z)+· · ·

= (1 +z

−4

+z

−8

+· · · )A(z)=

A(z)

1 −z

−4

=

a

0

+a

1

z

−1

+a

2

z

−2

+a

3

z

−3

1 −z

−4

where the convergence of the geometric series requires the ROC ¦z¦ > 1.

Problem 5.14

Factoring the denominator 1 −z

−4

, we obtain the PF expansion:

X(z) =

a

0

+a

1

z

−1

+a

2

z

−2

+a

3

z

−3

1 −z

−4

=

a

0

+a

1

z

−1

+a

2

z

−2

+a

3

z

−3

(1 −z

−1

)(1 +z)(1 −jz

−1

)(1 +jz

−1

)

=

A

1 −z

−1

+

B

1 +z

−1

+

C

1 −jz

−1

+

C

∗

1 +jz

−1

where the coefﬁcients C and C

∗

are conjugates because they correspond to the conjugate poles

:j (this follows from the fact that the denominator has real coefﬁcients.)

The PFE coefﬁcients are determined as follows:

70

A =

_

a

0

+a

1

z

−1

+a

2

z

−2

+a

3

z

−3

(1 +z)(1 −jz

−1

)(1 +jz

−1

)

_

z=1

=

a

0

+a

1

+a

2

+a

3

4

B =

_

a

0

+a

1

z

−1

+a

2

z

−2

+a

3

z

−3

(1 −z

−1

)(1 −jz

−1

)(1 +jz

−1

)

_

z=−1

=

a

0

−a

1

+a

2

−a

3

4

C =

_

a

0

+a

1

z

−1

+a

2

z

−2

+a

3

z

−3

(1 −z

−1

)(1 +z)(1 +jz

−1

)

_

z=j

=

(a

0

−a

2

)−j(a

1

−a

3

)

4

≡ C

R

−jC

I

Taking (causal) inverse z-transforms of the PF expansion, we obtain for n ≥ 0:

x(n) = A+B(−1)

n

+Cj

n

+C

∗

(−j)

n

= A+B(−1)

n

+Ce

jπn/2

+C

∗

e

−jπn/2

= A+B(−1)

n

+2Re

_

Ce

jπn/2

_

= A+B(−1)

n

+2Re

_

(C

R

−jC

I

)e

jπn/2

_

= A+B(−1)

n

+2C

R

cos(πn/2)+2C

I

sin(πn/2)

So that ﬁnally:

x(n) =

a

0

+a

1

+a

2

+a

3

4

+

a

0

−a

1

+a

2

−a

3

4

(−1)

n

+

a

0

−a

2

2

cos(πn/2)+

a

1

−a

3

2

sin(πn/2)

Setting n = 0, 1, 2, 3, we can verify the ﬁrst four values ¦a

0

, a

1

, a

2

, a

3

¦.

Problem 5.15

Summing the geometric series, we have:

X(z)= 1 −z

−2

+z

−4

−z

−6

+z

−8

−· · · =

1

1 +z

−2

Alternatively, we have:

X(z)= 1−z

−2

+z

−4

−z

−6

+z

−8

−· · · = 1−z

−2

(1−z

−2

+z

−4

−z

−6

+z

−8

−· · · )= 1−z

−2

X(z)

which gives

(1 +z

−2

)X(z)= 1 ⇒ X(z)=

1

1 +z

−2

The inverse z-transform is causal and can be obtained from the PFE:

X(z)=

1

1 +z

−2

=

0.5

1 −jz

−1

+

0.5

1 +jz

−1

which gives:

x(n)=

_

0.5j

n

+0.5(−j)

n

_

u(n)= cos(πn/2)u(n)

71

Problem 5.16

In all cases, we expand in the appropriate geometric series and pick out the coefﬁcients of the

expansion.

a. The z-transform and its inverse are:

X(z) =

1

1 +z

−4

= 1 −z

−4

+z

−8

−z

−12

+z

−16

−· · ·

x(n) = [1, 0, 0, 0, −1, 0, 0, 0, 1, 0, 0, 0, −1, 0, 0, 0, 1, . . . ]

b. The z-transform and its inverse are:

X(z) =

1

1 −z

−4

= 1 +z

−4

+z

−8

+z

−12

+z

−16

+· · ·

x(n) = [1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, . . . ]

c. The z-transform and its inverse are:

X(z) =

1

1 +z

−8

= 1 −z

−8

+z

−16

−z

−24

+· · ·

x(n) = [1, 0, 0, 0, 0, 0, 0, 0, −1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, −1, . . . ]

d. The z-transform and its inverse are:

X(z) =

1

1 −z

−8

= 1 +z

−8

+z

−16

+z

−24

+· · ·

x(n) = [1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, . . . ]

Problem 5.17

For case (a), the roots of the denominator are the solutions of 1 +z

−4

= 0 or, z

4

= −1. They are

obtained as follows:

z

4

= −1 = e

jπ

= e

jπ+2jπk

⇒ z = e

(jπ+2jπk)/4

, k = 0, 1, 2, 3

that is, the four numbers

z = e

jπ/4

, e

3jπ/4

, e

5jπ/4

, e

7jπ/4

which are the conjugate pairs:

z = e

:jπ/4

, e

:3jπ/4

Thus, the z-transform factors as follows and has the PF expansion:

X(z) =

1

1 +z

−3

=

1

(1 −e

jπ/4

z

−1

)(1 −e

−jπ/4

z

−1

)(1 −e

3jπ/4

z

−1

)(1 −e

−3jπ/4

z

−1

)

=

A

1 −e

jπ/4

z

−1

+

A

∗

1 −e

−jπ/4

z

−1

+

B

1 −e

3jπ/4

z

−1

+

B

∗

1 −e

−3jπ/4

z

−1

where the coefﬁcients are:

72

A =

_

1

(1 −e

−jπ/4

z

−1

)(1 −e

3jπ/4

z

−1

)(1 −e

−3jπ/4

z

−1

)

_

z=e

πj/4

=

1

4

B =

_

1

(1 −e

jπ/4

z

−1

)(1 −e

−jπ/4

z

−1

)(1 −e

−3jπ/4

z

−1

)

_

z=e

3πj/4

=

1

4

Thus, we ﬁnd the causal inverse for n ≥ 0:

x(n) =

1

4

e

jπn/4

+

1

4

e

−jπn/4

+

1

4

e

3jπn/4

+

1

4

e

−jπn/4

=

1

2

cos(πn/4)+

1

2

cos(3πn/4)

Cases (b,c,d) are done in a similar fashion. See the solution of Problem 5.19 for the denominator

zeros.

Problem 5.18

Let Q(z) and R(z) be the quotient and remainder polynomials of the division of N(z) by D(z).

Then, Q(z) will have degree L −M, R(z) degree M−1. Thus,

N(z)= Q(z)D(z)+R(z)

It follows that:

H(z)=

N(z)

D(z)

=

Q(z)D(z)+R(z)

D(z)

= Q(z)+

R(z)

D(z)

Because the degree of R(z) is strictly less than the degree of D(z), the term R(z)/D(z) will

admit a PF expansion of the form:

R(z)

D(z)

=

M

_

i=1

A

i

1 −p

i

z

−1

where p

i

are the M zeros of D(z) or the poles of H(z). Any truly complex poles will come in

conjugate pairs, that is, of the type:

A

i

1 −p

i

z

−1

+

A

∗

i

1 −p

∗

i

z

−1

which can be assembled into the 2nd order section:

A

i

1 −p

i

z

−1

+

A

∗

i

1 −p

∗

i

z

−1

=

(A

i

+A

∗

i

)−(A

i

p

∗

i

+A

∗

i

p

i

)z

−1

1 −(p

i

+p

∗

i

)z

−1

+p

i

p

∗

i

z

−2

where the numerator and denominator coefﬁcients are all real.

73

Problem 5.19

The roots of the polynomial 1 − z

−D

are the solutions of the equation z

D

= 1, that is, the D-th

roots of unity. To ﬁnd them, replace 1 by e

2πjk

= 1, where k is an integer, and take D-th roots of

both sides:

z

D

= 1 = e

2πjk

⇒ z

k

= e

j2πk/D

, k = 0, 1, . . . D−1

They lie on the unit circle at the angles ω

k

= 2πk/D, k = 0, 1, . . . , D−1 obtained by dividing the

circle into Dequal parts. The product of the 1st order zero factors must make up the polynomial

1 −z

−D

:

D−1

k=0

(1 −z

k

z

−1

)= 1 −z

−D

This identity follows from a theorem of algebra that states that if two polynomials have the same

set of roots and unity constant coefﬁcient, then they must be identically equal to each other.

For the other case, we have the solutions of 1+z

−D

= 0 or z

D

= −1. Now, we replace −1 = e

πj

=

e

jπ+j2πk

with any integer k, and ﬁnd the roots

z

D

= −1 = e

jπ(2k+1)

⇒ z

k

= e

jπ(2k+1)/D

, k = 0, 1, . . . , D−1

They also lie on the unit circle at D equal divisions, but they are shifted as a whole with respect

to the standard D-th roots of unity by a rotation angle of π/D. Fig. P5.1 shows the two cases for

D = 8.

z

8

= 1 z

8

= -1

Fig. P5.1 Roots of 1 −z

−8

and 1 +z

−8

.

Problem 5.20

The roots of 1 −az

−D

are the solutions of the equation

z

D

= a = ae

j2πk

⇒ z

k

= a

1/D

e

j2πk/D

, k = 0, 1, . . . , D−1

They all lie on a circle of radius a

1/D

at the D-th root of unity angles. Similarly, the roots of

1 +az

−D

, lie on the same circle, but at the shifted D-th root of unity angles.

Problem 5.21

Let y(n)= a

n

x(n). Its z-transform is:

Y(z)=

_

n

y(n)z

−n

=

_

n

a

n

x(n)z

−n

=

_

n

x(n)(z/a)

−n

74

Comparing with

X(z)=

_

n

x(n)z

−n

we see that

Y(z)= X(z/a)

Since the spectrum X(ω) is obtained by replacing z = e

jω

, the scaled z will be

z/a = e

jω

/e

jω0

= e

j(ω−ω0)

Thus, the relationship Y(e

jω

)= X(e

j(ω−ω0)

) may be written as

Y(ω)= X(ω−ω

0

)

Alternatively, we may work directly with the deﬁnition of the DTFT:

Y(ω)=

_

n

y(n)e

−jωn

=

_

n

e

jω0n

x(n)e

−jωn

=

_

n

x(n)e

−j(ω−ω0)n

= X(ω−ω

0

)

Problem 5.22

We use the identity

1

2π

_

π

−π

e

jω(n−m)

dω= δ(n −m)

for n, m integers. Indeed, for n = m the left hand side is unity. And, for n }= m, we have:

1

2π

_

π

−π

e

jω(n−m)

dω=

cos

_

π(n −m)

_

−cos

_

−π(n −m)

_

2πj(n −m)

= 0

Inserting the deﬁnition of the DTFT into the inversion formula, we get

1

2π

_

π

−π

X(ω)e

jωn

dω=

1

2π

_

π

−π

_

_

m

x(m)e

−jωm

_

e

jωn

dω

=

_

m

x(m)

1

2π

_

π

−π

e

jω(n−m)

dω=

_

m

x(m)δ(n −m)

= x(n)

where we interchanged the series with the integral (this step is justiﬁed by assuming that the

series is convergent, that is, the unit circle lies in the ROC or that the signal x(n) is strictly

stable).

Problem 5.23

We may assume in general that x(n) is complex-valued. Then, we have:

X(ω) =

_

n

x(n)e

−jωn

X

∗

(ω) =

_

n

x

∗

(n)e

jωn

75

Using the inverse DTFT formula, it follows that

1

2π

_

π

−π

X(ω)X

∗

(ω) dω=

1

2π

_

π

−π

X(ω)

_

_

n

x

∗

(n)e

jωn

_

dω

=

_

n

x

∗

(n)

_

1

2π

_

π

−π

X(ω)e

jωn

dω

_

=

_

n

x

∗

(n)x(n)

Problem 5.24

For a real-valued signal x(n), we have:

X(ω) =

_

n

x(n)e

−jωn

X

∗

(ω) =

_

n

x(n)e

jωn

X

∗

(−ω) =

_

n

x(n)e

−jωn

where in the third equation, we replaced ω by −ω. Comparing the ﬁrst and third equations, we

obtain:

X

∗

(−ω)= X(ω)

Writing X(ω) in its polar form, e.g., X(ω)= ¦X(ω)¦e

j arg X(ω)

, the hermitian property reads:

_

¦X(−ω)¦e

j arg X(−ω)

_

∗

= ¦X(ω)¦e

j arg X(ω)

or,

¦X(−ω)¦e

−j arg X(−ω)

= ¦X(ω)¦e

j arg X(ω)

Equating magnitudes and phases, we get the conditions:

¦X(−ω)¦ = ¦X(ω)¦ , arg X(−ω)= −arg X(ω)

that is, the magnitude spectrum is even in ω and the phase spectrum is odd.

76

Chapter 6 Problems

Problem 6.1

a. From Y(z)= −0.8z

−1

Y(z)+X(z) it follows:

H(z)=

1

1 +0.8z

−1

⇒ H(ω)=

1

1 +0.8e

−jω

The causal inverse z-transform of H(z) is h(n)= (−0.8)

n

u(n). There is only one pole

at z = −0.8, that is, near the “high frequency” part of the unit circle. Thus, the ﬁlter will

tend to enhance high frequencies, i.e., it will behave as a high pass ﬁlter:

= pole

z-plane

-0.8

1

π

ω

0

5

0.55

|H(ω)|

Block diagram realization and the sample-by-sample processing algorithm:

x

-0.8

y

y

z

-1

w

1

for each input sample x do:

y = −0.8w

1

+x

w

1

= y

b. Change −0.8 to 0.8 in the above problem. Now the pole at z = 0.8 is in the “low frequency”

part of the unit circle and the ﬁlter is acting as a low pass ﬁlter.

c. The I/O equation Y(z)= 0.8z

−1

Y(z)+X(z)+z

−1

X(z) gives

H(z)=

1 +z

−1

1 −0.8z

−1

= A+

B

1 −0.8z

−1

⇒ h(n)= Aδ(n)+B(0.8)

n

u(n)

where

A =

_

1 +z

−1

1 −0.8z

−1

_

z=0

= −1.25, B =

_

1 +z

−1

_

z=0.8

= 2.25

The ﬁlter enhances lowfrequencies for two reasons: ﬁrst, it has a pole in the lowfrequency

range, z = 0.8, and it has a zero in the high frequency range, z = −1. Its frequency

response will be

H(ω)=

1 +e

−jω

1 −0.8e

−jω

77

z-plane

0.8

-1

= poles

= zeros

π

ω

0

10

exact

zero

|H(ω)|

The canonical form realization and its sample processing algorithm are:

x

0.8

y

w

0

z

-1

w

1

for each input sample x do:

w

0

= 0.8w

1

+x

y = w

0

+w

1

w

1

= w

0

The direct form realization and its sample processing algorithm are:

x

0.8

y

z

-1

z

-1

v

1

w

1

for each input sample x do:

y = 0.8w

1

+x +v

1

v

1

= x

w

1

= y

d. The I/O equation Y(z)= 0.8z

−1

Y(z)+X(z)−0.5z

−1

X(z) gives

H(z)=

1 −0.5z

−1

1 −0.8z

−1

= A+

B

1 −0.8z

−1

⇒ h(n)= Aδ(n)+B(0.8)

n

u(n)

where

A =

_

1 −0.5z

−1

1 −0.8z

−1

_

z=0

= 0.625, B =

_

1 −0.5z

−1

_

z=0.8

= 0.375

The ﬁ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

0.5

= poles

= zeros

π

ω

0

2.5

0.833

|H(ω)|

The canonical form realization and its sample processing algorithm are:

78

x

0.8 -0.5

y

w

0

z

-1

w

1

for each input sample x do:

w

0

= 0.8w

1

+x

y = w

0

−0.5w

1

w

1

= w

0

The direct form realization and its sample processing algorithm are:

x

0.8 -0.5

y

z

-1

z

-1

v

1

w

1

for each input sample x do:

y = 0.8w

1

+x −0.5v

1

v

1

= x

w

1

= y

e. Y(z)= 0.8z

−1

Y(z)+X(z)+0.25z

−2

X(z) ⇒ H(z)=

1 +0.25z

−2

1 −0.8z

−1

.

Using the “remove/restore numerator” method of problem (2h), we ﬁnd

h(n)= (0.8)

n

u(n)+0.25(0.8)

n−2

u(n −2)

The ﬁlter has two conjugate zeros at midrange, z = :0.5j = 0.5e

:jπ/2

, and a lowfrequency

pole at z = 0.8. Thus, the ﬁlter will enhance low frequencies and suppress midrange

frequencies:

z-plane

0.8

0.5j

-0.5j

= poles

= zeros

π

ω

0

|H(ω)|

The canonical form realization and its sample processing algorithm are:

x

0.8

0.25

y

w

0

z

-1

z

-1

w

1

w

2

for each input sample x do:

w

0

= 0.8w

1

+x

y = w

0

+0.25w

2

w

2

= w

1

w

1

= w

0

The direct form realization and its sample processing algorithm are:

79

x

0.8

0.25

y

z

-1

z

-1

z

-1

v

1

v

2

w

1

for each input sample x do:

y = x +0.25v

2

+0.8w

1

v

2

= v

1

v

1

= x

w

1

= y

f. Y(z)= 0.9z

−1

Y(z)−0.2z

−2

Y(z)+X(z)+z

−1

X(z)−6z

−2

X(z), which implies

H(z)=

1 +z

−1

−6z

−2

1 −0.9z

−1

+0.2z

−2

Factor numerator and denominator and expand in partial fractions:

H(z)=

(1 +3z

−1

)(1 −2z

−1

)

(1 −0.4z

−1

)(1 −0.5z

−1

)

= A+

B

1 −0.4z

−1

+

C

1 −0.5z

−1

where

A =

_

(1 +3z

−1

)(1 −2z

−1

)

(1 −0.4z

−1

)(1 −0.5z

−1

)

_

z=0

= −30

B =

_

(1 +3z

−1

)(1 −2z

−1

)

1 −0.5z

−1

_

z=0.4

= 136

C =

_

(1 +3z

−1

)(1 −2z

−1

)

1 −0.4z

−1

_

z=0.5

= −105

Thus, h(n)= Aδ(n)+B(0.4)

n

u(n)+C(0.5)

n

u(n). The two zeros at z = −3 and z = 2 are

too far from the unit circle to have any signiﬁcant 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.

z-plane

0.5

0.4

-3

2

= poles

= zeros

π

ω

0

13.33

2.86

|H(ω)|

The canonical form realization and its sample processing algorithm are:

80

x

0.9

-6

-0.2

y

w

0

z

-1

z

-1

w

1

w

2

for each input sample x do:

w

0

= x +0.9w

1

−0.2w

2

y = w

0

+w

1

−6w

2

w

2

= w

1

w

1

= w

0

The direct form realization and its sample processing algorithm are:

x

0.9

-6

-0.2

y

z

-1

z

-1

z

-1

z

-1

v

1

v

2

w

1

w

2

for each input sample x do:

y = x +v

1

−6v

2

+0.9w

1

−0.2w

2

v

2

= v

1

v

1

= x

w

2

= w

1

w

1

= y

Problem 6.2

a. Setting x(n)= u(n) in the I/O difference equation, we ﬁnd

y(n)= u(n)+6u(n −1)+11u(n −2)+6u(n −3)

The 4th term is active only for n ≥ 3, the 3d term is active only n ≥ 2, and the 2nd term

only for n ≥ 2. Thus, evaluating at a few n’s we ﬁnd:

y(n)= [1, 7, 18, 24, 24, 24, 24, . . . ]

The ﬁrst 3 outputs are the initial transients, the remaining constant values are the steady

part. Note that when you send in a unit step, the output always settles to a constant value

(for a stable ﬁlter). That constant value can be easily precalculated as H(1). In the present

case, H(1)= 1 +6 +11 +6 = 24. For the alternating step, we have:

Y(z) =

1 +6z

−1

+11z

−2

+6z

−3

1 +z

−1

= 1 +5z

−1

+6z

−2

y(n) = [1, 5, 6, 0, 0, 0, · · · ]

There is a pole zero cancellation: the ﬁlter has a zero at z = −1, cutting off the high-

frequency input.

b. Noting that the input z-transform is X(z)= 1/(1 −z

−1

), we ﬁnd

Y(z)= H(z)X(z)=

1 −z

−4

1 −z

−1

= 1 +z

−1

+z

−2

+z

−3

where we used the ﬁnite geometric series. Inverting, we get

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:

Y(z)=

1 −z

−4

1 +z

−1

= 1 −z

−1

+z

−2

−z

−3

⇒ y(n)= [1, −1, 1, −1, 0, 0, 0, · · · ]

Again, the ﬁlter has a high frequency zero at z = −1, cutting off the high frequency input.

Problem 6.3

For ﬁlter (a), we have:

Y(z) =

1

(1 −z

−1

)(1 −0.25z

−2

)

=

1

(1 −z

−1

)(1 −0.5z

−1

)(1 +0.5z

−1

)

=

A

1 −z

−1

+

B

1 −0.5z

−1

+

C

1 +0.5z

−1

y(n) = Au(n)+B(0.5)

n

u(n)+C(−0.5)

n

u(n)

where A = H(1)= 4/3, B = −0.5, C = 1/6. The A-term is the steady part. For the alternating

step, we have:

Y(z) =

1

(1 +z

−1

)(1 −0.25z

−2

)

=

1

(1 +z

−1

)(1 −0.5z

−1

)(1 +0.5z

−1

)

=

A

1 +z

−1

+

B

1 −0.5z

−1

+

C

1 +0.5z

−1

y(n) = A(−1)

n

u(n)+B(0.5)

n

u(n)+C(−0.5)

n

u(n)

where A = H(−1)= 4/3, B = 1/6, C = −0.5. The A-term is the steady part. For (b), we have:

Y(z) =

1

(1 −z

−1

)(1 +0.25z

−2

)

=

1

(1 −z

−1

)(1 −0.5jz

−1

)(1 +0.5jz

−1

)

=

A

1 −z

−1

+

B

1 −0.5jz

−1

+

B

∗

1 +0.5jz

−1

y(n) = Au(n)+B(0.5j)

n

u(n)+B

∗

(−0.5j)

n

u(n)

where A = H(1)= 4/5 and

B =

_

1

(1 −z

−1

)(1 +0.5jz

−1

)

_

z=0.5j

= 0.1 −0.2j

And, for the alternating step:

Y(z) =

1

(1 +z

−1

)(1 +0.25z

−2

)

=

1

(1 +z

−1

)(1 −0.5jz

−1

)(1 +0.5jz

−1

)

=

A

1 +z

−1

+

B

1 −0.5jz

−1

+

B

∗

1 +0.5jz

−1

y(n) = A(−1)

n

u(n)+B(0.5j)

n

u(n)+B

∗

(−0.5j)

n

u(n)

82

where A = H(−1)= 4/5 and

B =

_

1

(1 +z

−1

)(1 +0.5jz

−1

)

_

z=0.5j

= 0.1 +0.2j

Problem 6.4

For a unit-step input and the ﬁlter (a) of Problem 6.1, we have:

Y(z) = H(z)X(z)=

1

(1 +0.8z

−1

)(1 −z

−1

)

=

A

1 +0.8z

−1

+

B

1 −z

−1

y(n) = A(−0.8)

n

u(n)+Bu(n)

where A = 1/2.25, B = H(1)= 1/1.8. The B-term represents the steady part. For ﬁlter (b):

Y(z) = H(z)X(z)=

1

(1 −0.8z

−1

)(1 −z

−1

)

=

A

1 −0.8z

−1

+

B

1 −z

−1

y(n) = A(0.8)

n

u(n)+Bu(n)

where A = −4, B = H(1)= 5. The B-term represents the steady part. For ﬁlter (c):

Y(z) =

1 +z

−1

(1 −z

−1

)(1 −0.8z

−1

)

=

A

1 −z

−1

+

B

1 −0.8z

−1

y(n) = Au(n)+B(0.8)

n

u(n)

with A = H(1)= 10, B = −9. For ﬁlter (d):

Y(z) =

1 −0.5z

−1

(1 −z

−1

)(1 −0.8z

−1

)

=

A

1 −z

−1

+

B

1 −0.8z

−1

y(n) = Au(n)+B(0.8)

n

u(n)

with A = H(1)= 2.5, B = −1.5. For ﬁlter (e):

Y(z) =

1 +0.25z

−2

(1 −z

−1

)(1 −0.8z

−1

)

= A+

B

1 −z

−1

+

C

1 −0.8z

−1

y(n) = Aδ(n)+Bu(n)+C(0.8)

n

u(n)

where A = Y(0)= 0.3125, B = H(1)= 6.25, C = −5.5625. The B-term is the steady part. For

ﬁlter (f):

Y(z) =

1 +z

−1

−6z

−2

(1 −z

−1

)(1 −0.4z

−1

)(1 −0.5z

−1

)

=

A

1 −z

−1

+

B

1 −0.4z

−1

+

C

1 −0.5z

−1

y(n) = Au(n)+B(0.4)

n

u(n)+C(0.5)

n

u(n)

For the alternating step and ﬁlter (a) of Problem 6.1, we have:

Y(z) =

1

(1 +0.8z

−1

)(1 +z

−1

)

=

A

1 +0.8z

−1

+

B

1 +z

−1

y(n) = A(−0.8)

n

u(n)+B(−1)

n

u(n)

83

where A = −4, B = H(−1)= 5. The B-term represents the steady part. For ﬁlter (b):

Y(z) =

1

(1 −0.8z

−1

)(1 +z

−1

)

=

A

1 −0.8z

−1

+

B

1 +z

−1

y(n) = A(0.8)

n

u(n)+B(−1)

n

u(n)

where A = 1/2.25, B = H(−1)= 1/1.8. The B-term represents the steady part. For ﬁlter (c):

Y(z) =

1 +z

−1

(1 +z

−1

)(1 −0.8z

−1

)

=

1

1 −0.8z

−1

y(n) = (0.8)

n

u(n)

The high frequency zero at z = −1 of the ﬁlter canceled the high frequency input signal. The

output is only transient — it decays to zero exponentially. For ﬁlter (d):

Y(z) =

1 −0.5z

−1

(1 +z

−1

)(1 −0.8z

−1

)

=

A

1 +z

−1

+

B

1 −0.8z

−1

y(n) = A(−1)

n

u(n)+B(0.8)

n

u(n)

For ﬁlter (e):

Y(z) =

1 +0.25z

−2

(1 +z

−1

)(1 −0.8z

−1

)

= A+

B

1 +z

−1

+

C

1 −0.8z

−1

y(n) = Aδ(n)+B(−1)

n

u(n)+C(0.8)

n

u(n)

The B-term is the steady part. For ﬁlter (f):

Y(z) =

1 +z

−1

−6z

−2

(1 +z

−1

)(1 −0.4z

−1

)(1 −0.5z

−1

)

=

A

1 +z

−1

+

B

1 −0.4z

−1

+

C

1 −0.5z

−1

y(n) = A(−1)

n

u(n)+B(0.4)

n

u(n)+C(0.5)

n

u(n)

For question (c), the input z-transform is X(z)= 1/(1−0.5z

−1

). Thus, applied to Problem 6.1(d)

gives:

Y(z) =

1 −0.5z

−1

(1 −0.5z

−1

)(1 −0.8z

−1

)

=

1

1 −0.8z

−1

y(n) = (0.8)

n

u(n)

The ﬁlter zero canceled the signal pole. For question (d), we have x(n)= (0.5)

n

cos(πn/2)u(n)

Z

−→

X(z)= 1/(1 +0.25z

−2

). Thus,

Y(z) =

1 +0.25z

−2

(1 +0.25z

−2

)(1 −0.8z

−1

)

=

1

1 −0.8z

−1

y(n) = (0.8)

n

u(n)

Again, the signal poles were canceled by the ﬁlter zeros. For question (e), the input has X(z)=

1/(1 −2z

−1

). Therefore,

84

Y(z) =

(1 +3z

−1

)(1 −2z

−1

)

(1 −2z

−1

)(1 −0.4z

−1

)(1 −0.5z

−1

)

=

1 +3z

−1

(1 −0.4z

−1

)(1 −0.5z

−1

)

=

A

1 −0.4z

−1

+

B

1 −0.5z

−1

y(n) = A(0.4)

n

u(n)+B(0.5)

n

u(n)

The unstable input was canceled by a ﬁlter zero to give a stable output.

Problem 6.5

Filter (a): H(z)= z

−5

with I/O equation Y(z)= H(z)X(z)= z

−5

X(z) and in the time domain

y(n)= x(n − 5). H(ω)= e

−5jω

and ¦H(ω)¦ = 1, i.e., ﬂat in ω. Block diagram realization and

sample-by-sample processing algorithm:

x

y

z

-1

z

-1

z

-1

z

-1

z

-1

w

1

w

2

w

5

w

3

w

4

for each input sample x do:

y = w

5

w

5

= w

4

w

4

= w

3

w

3

= w

2

w

2

= w

1

w

1

= x

Filter (b): H(z)= z

−5

U(z)= z

−5

/(1 −z

−1

) and the I/O equation gives

Y(z)= H(z)X(z)=

z

−5

X(z)

1 −z

−1

⇒ (1 −z

−1

)Y(z)= z

−5

X(z) ⇒

Y(z)= z

−1

Y(z)+z

−5

X(z) ⇒ y(n)= y(n −1)+x(n −5)

Its frequency response is

H(ω)=

e

−5jω

1 −e

−jω

⇒ ¦H(ω)¦ =

1

2¦ sin(ω/2)¦

The pole at z = 1 or ω= 0 dominates the frequency response. The ﬁlter acts as a lowpass ﬁlter

(it is actually an accumulator with delay).

85

z-plane

1

= poles

π

ω

0

0.5

|H(ω)|

The canonical form realization and its sample processing algorithm are:

x

y

w

0

z

-1

z

-1

z

-1

z

-1

z

-1

w

1

w

2

w

5

w

3

w

4

for each input sample x do:

w

0

= x +w

1

y = w

5

w

5

= w

4

w

4

= w

3

w

3

= w

2

w

2

= w

1

w

1

= w

0

The direct form realization and its sample processing algorithm are:

x

y

z

-1

z

-1

z

-1

z

-1

z

-1

z

-1

v

1

w

1

v

2

v

5

v

3

v

4

for each input sample x do:

y = w

1

+v

5

w

1

= y

v

5

= v

4

v

4

= v

3

v

3

= v

2

v

2

= v

1

v

1

= x

Filter (c): H(z)= 1/(1 −0.8z

−1

) and the I/O equation becomes:

Y(z)= H(z)X(z)=

X(z)

1 −0.8z

−1

⇒ (1 −0.8z

−1

)Y(z)= X(z) ⇒

Y(z)= 0.8z

−1

Y(z)+X(z)

86

and in the time domain

y(n)= 0.8y(n −1)+x(n)

The rest is as in problem (3d). Filter (d): H(z)= 1/(1 +0.8z

−1

) and the I/O equation becomes:

Y(z)= H(z)X(z)=

X(z)

1 +0.8z

−1

⇒ (1 +0.8z

−1

)Y(z)= X(z) ⇒

Y(z)= −0.8z

−1

Y(z)+X(z) ⇒ y(n)= −0.8y(n −1)+x(n)

The rest is as in problem (3c). Filter (e): With a = −0.8, the impulse response is ﬁnite:

h(n)= [1, a, a

2

, a

3

, a

4

, a

5

, a

6

, a

7

, 0, 0, 0, · · · ]

Its z-transform is

H(z)= 1 +az

−1

+a

2

z

−2

+a

3

z

−3

+a

4

z

−4

+a

5

z

−5

+a

6

z

−6

+a

7

z

−7

=

1 −a

8

z

−8

1 −az

−1

The point z = a is not really a pole of H(z) because it is canceled by a numerator zero — H(z)

has seven zeros. To ﬁnd them, solve the equation z

8

= a

8

and exclude the solution z = a, that

is,

z = ae

2πjk/8

= −0.8e

2πjk/8

= 0.8e

jπ

e

2πjk/8

, k = 1, 2, 3, 4, 5, 6, 7

They are shown below

z-plane

= zeros

z=a=-0.8

1

The I/O equation in the time domain is

y(n)= x(n)+ax(n −1)+a

2

x(n −2)+· · · +a

7

x(n −7)

Sample-by-sample processing algorithm and block diagram realization:

for each input sample x do:

y = x +aw

1

+a

2

w

2

+a

3

w

3

+a

4

w

4

+a

5

w

5

+a

6

w

6

+a

7

w

7

w

7

= w

6

w

6

= w

5

w

5

= w

4

w

4

= w

3

w

3

= w

2

w

2

= w

1

w

1

= x

87

x

y

a

0

a

1

w

1

a

2

w

2

a

3

w

3

a

4

w

4

a

5

w

5

a

6

w

6

a

7

w

7

z

-1

z

-1

z

-1

z

-1

z

-1

z

-1

z

-1

Filter (f): H(z)=

1

1 −0.8z

−1

+

1

1 +0.8z

−1

=

2

1 −0.64z

−2

Y(z) = H(z)X(z)=

2X(z)

1 −0.64z

−2

⇒ Y(z)= 0.64z

−2

Y(z)+2X(z)

y(n) = 0.64y(n −2)+2x(n)

There is a low frequency pole at z = 0.8 and a high frequency pole at z = −0.8. Thus, the ﬁlter

will emphasize both the low and high frequencies:

z-plane

0.8 -0.8

= poles

π π/2

ω

0

|H(ω)|

The direct form realization and its sample processing algorithm are:

x

0.64

y

y

z

-1

z

-1

w

2

w

1

2

for each input sample x do:

y = 2x +0.64w

2

w

2

= w

1

w

1

= y

Filters (g,h):

h(n) = 2(0.8)

n

cos(πn/2)u(n)= (0.8)

n

2Re[j

n

]u(n)

= (0.8j)

n

u(n)+(−0.8j)

n

u(n)

H(z) =

1

1 −0.8jz

−1

+

1

1 +0.8jz

−1

=

2

1 +0.64z

−2

Y(z) = H(z)X(z)=

2X(z)

1 +0.64z

−2

⇒ Y(z)= −0.64z

−2

Y(z)+2X(z)

y(n) = −0.64y(n −2)+2x(n)

88

There is a conjugate pair of poles at midfrequency, z = :0.8j = 0.8e

:π/2

. Thus, the ﬁlter will

emphasize mid frequencies:

z-plane

0.8j

-0.8j

= poles

π π/2

ω

0

|H(ω)|

The direct form realization and its sample processing algorithm are:

x

-0.64

y

y

z

-1

z

-1

w

2

w

1

2

for each input sample x do:

y = 2x −0.64w

2

w

2

= w

1

w

1

= y

Problem 6.6

Taking z-transforms, we ﬁnd:

H(z)= 1 +0.5z

−8

+0.5

2

z

−16

+0.5

3

z

−24

+· · · =

1

1 −0.5z

−8

where convergence requires ¦z¦

8

> 0.5, or, ¦z¦ > (0.5)

1/8

. The block diagram and sample pro-

cessing algorithm are:

x

0.5

y

z

-8

w

8

w

0

for each input sample x do:

y = w

0

= x +0.5w

8

delay(8, w)

where the call to delay updates the 9-dimensional state vector of the eightfold delay w = [w

0

,

w

1

, . . . , w

8

].

Problem 6.7

Because z = e

jω

, we can deduce the transfer function from H(ω):

H(z)=

−0.5 +z

−8

1 −0.5z

−8

It can be written in a form that can be expanded in powers of z

−8

:

H(z)= −0.5 +

0.75z

−8

1 −0.5z

−8

= −0.5 +0.75z

−8

_

1 +0.5z

−8

+0.5

2

z

−16

+0.5

3

z

−24

+· · ·

_

89

Thus, the impulse response will be

h = [−0.5, 0, 0, 0, 0, 0, 0, 0, 0.75, 0, 0, 0, 0, 0, 0, 0, 0.75(0.5), 0, 0, 0, 0, 0, 0, 0, 0.75(0.5)

2

, . . . ]

It is depicted below:

-0.5

0

0.75

0.75/2

0.75/4

n

h(n)

...

Problem 6.8

a. The impulse response h(n) satisﬁes the difference equation:

h(n)= h(n −1)+h(n −2)+δ(n −1) (P6.1)

Indeed, for n ≥ 2 the δ(n − 1) term is absent and each h(n) is the sum of the previous

two. The sequence is properly initialized at n = 0, 1:

h(0) = h(−1)+h(−2)+δ(−1)= 0 +0 +0 = 0

h(1) = h(0)+h(−1)+δ(0)= 0 +0 +1 = 1

Next, we take z-transforms of both sides of Eq. (P6.1) to get H(z):

H(z)= z

−1

H(z)+z

−2

H(z)+z

−1

because the z-transform of δ(n −1) is z

−1

. Solving for H(z):

H(z)=

z

−1

1 −z

−1

−z

−2

b. The poles of H(z) are the roots of 1 −z

−1

−z

−2

= 0 or

z

2

−z −1 = 0 ⇒ z =

1 :

√

5

2

Denoting the ﬁrst one by φ, the other one will be:

φ =

1 +

√

5

2

, −

1

φ

=

1 −

√

5

2

Indeed, we have

−

1

φ

= −

2

1 +

√

5

= −

2(1 −

√

5)

(1 +

√

5)(1 −

√

5)

= −

2(1 −

√

5)

1 −5

=

1 −

√

5

2

Performing a partial fraction expansion on H(z), we get:

H(z)=

z

−1

1 −z

−1

−z

−2

=

z

−1

(1 −φz

−1

)(1 +φ

−1

z

−1

)

=

A

1 −φz

−1

+

B

1 +φ

−1

z

−1

90

where

A =

_

z

−1

1 +φ

−1

z

−1

_

z=φ

=

φ

−1

1 +φ

−2

=

1

√

5

B =

_

z

−1

1 −φz

−1

_

z=−φ

−1

= −

φ

1 +φ

2

= −

1

√

5

Taking the causal inverse z-transform, we obtain a closed-form solution for the nth Fi-

bonacci number:

h(n)= Aφ

n

+B(−φ)

−n

, n ≥ 0

It is unstable because φ is greater than 1 (note, φ = 1.618).

c. For large n, the exponentially increasing term φ

n

dominates the expression. Therefore,

the ratio of two successive Fibonacci numbers will tend to:

h(n +1)

h(n)

→

Aφ

n+1

Aφ

n

= φ

This can also be seen from the difference equation of h(n). For n ≥ 1, we have

h(n +1)= h(n)+h(n −1)

Dividing by h(n −1), we have:

h(n +1)

h(n −1)

=

h(n)

h(n −1)

+1 or,

h(n +1)

h(n)

·

h(n)

h(n −1)

=

h(n)

h(n −1)

+1

If we denote the ratio r(n)= h(n +1)/h(n), we may write this as:

r(n)r(n −1)= r(n −1)+1

The limiting value r(n)→r will satisfy the limiting equation:

r

2

= r +1

which is the same as that satisﬁed by φ. Thus, r = φ because they are the positive

solutions.

d. The sequence y(n) satisﬁes the recursion y(n)= y(n − 1)+y(n − 2) for n ≥ 3. Indeed,

using the property φ

2

= φ+1 and successively multiplying it by powers of φ, we get

y(3) = φ

2

= φ+1 = y(2)+y(1)

y(4) = φ

3

= φ

2

+φ = y(3)+y(2)

y(5) = φ

4

= φ

3

+φ

2

= y(4)+y(3)

· · ·

91

The z-transform of y(n) will be the once-delayed z-transform of the geometric series, that

is,

Y(z)=

z

−1

1 −φz

−1

Thinking of Y(z) as the output of H(z) for a particular input X(z), we have Y(z)=

H(z)X(z), which may be solved for X(z):

X(z)=

Y(z)

H(z)

=

z

−1

1 −φz

−1

z

−1

(1 −φz

−1

)(1 +φ

−1

z

−1

)

= 1 +φ

−1

z

−1

which gives the sequence:

x(n)= δ(n)+φ

−1

δ(n −1) or x = [1, φ

−1

, 0, 0, 0, 0. . . ]

Problem 6.9

As in the previous problem, the impulse response satisﬁes the difference equation:

h(n)= 2h(n −1)+h(n −2)+δ(n −1)

with zero initial conditions. That is, the two start-up values are:

h(0) = 2h(−1)+h(−2)+δ(−1)= 0 +0 +0 = 0

h(1) = 2h(0)+h(−1)+δ(0)= 0 +0 +1 = 1

Taking z-transforms, we ﬁnd H(z):

H(z)= 2z

−1

H(z)+z

−2

H(z)+z

−1

⇒ H(z)=

z

−1

1 −2z

−1

−z

−2

The roots of the denominator polynomial are the solutions of

z

2

= 2z +1 ⇒ z = 1 :

√

2 = ¦θ, −θ

−1

¦

The PF expansion is then

H(z)=

z

−1

1 −2z

−1

−z

−2

=

z

−1

(1 −θz

−1

)(1 +θ

−1

z

−1

)

=

A

1 −θz

−1

+

B

1 +θ

−1

z

−1

where

A = −B =

θ

θ

2

+1

=

1

2

√

2

Thus, the nth Pell number will be:

h(n)= Aθ

n

+B(−θ)

−n

, n ≥ 0

Because the exponentially diverging term θ

n

dominates the sum, the ratio of two successive

numbers will converge to

92

h(n +1)

h(n)

→

Aθ

n+1

Aθ

n

= θ

The y(n) sequence has z-transform

Y(z)=

z

−1

1 −θz

−1

=

z

−1

(1 −θz

−1

)(1 +θ

−1

z

−1

)

· (1 +θ

−1

z

−1

)= H(z)(1 +θ

−1

z

−1

)

and therefore, it may be thought of as the output when the input is:

X(z)= 1 +θ

−1

z

−1

or,

x(n)= δ(n)+θ

−1

δ(n −1) ⇒ x = [1, θ

−1

, 0, 0, 0, 0. . . ]

Problem 6.10

The input and output z-transforms are:

X

1

(z)=

1

1 −0.5z

−1

, Y

1

(z)=

1

1 −0.5z

−1

+

1

1 −0.4z

−1

=

2(1 −0.45z

−1

)

(1 −0.5z

−1

)(1 −0.4z

−1

)

It follows that transfer function is:

H(z)=

Y

1

(z)

X

1

(z)

=

2(1 −0.45z

−1

)

1 −0.4z

−1

Therefore, the second output, having z-transform

Y

2

(z)=

1

1 −0.4z

−1

will be produced by

X

2

(z)=

Y

2

(z)

H(z)

=

0.5

1 −0.45z

−1

⇒ x

2

(n)= 0.5(0.45)

n

u(n)

Problem 6.11

The input and output z-transforms are:

X

1

(z) =

1

1 −az

−1

Y

1

(z) =

1

1 −az

−1

+

1

1 −bz

−1

=

2 −(a +b)z

−1

)

(1 −az

−1

)(1 −bz

−1

)

=

2(1 −cz

−1

)

(1 −az

−1

)(1 −bz

−1

)

where c = (a +b)/2. Therefore, the transfer function is

H(z)=

Y

1

(z)

X

1

(z)

=

2(1 −cz

−1

)

1 −bz

−1

If the input x

2

(n)= c

n

u(n) is applied it will have z-transform X

2

(z)= 1/(1 − cz

−1

) and will

cause the output:

Y

2

(z)= H(z)X

2

(z)=

2(1 −cz

−1

)

1 −bz

−1

·

1

1 −cz

−1

=

2

1 −bz

−1

and in the time domain:

y

2

(n)= 2b

n

u(n)

93

Problem 6.12

The input and output z-transforms are:

X(z) =

1

1 −0.7z

−1

Y(z) =

1

1 −0.7z

−1

+

1

1 −0.5z

−1

=

2(1 −0.6z

−1

)

(1 −0.7z

−1

)(1 −0.5z

−1

)

Therefore the transfer function will be:

H(z)=

Y(z)

X(z)

=

2(1 −0.6z

−1

)

1 −0.5z

−1

Expanding in partial fractions, we have:

H(z)=

2(1 −0.6z

−1

)

1 −0.5z

−1

= 2.4 −

0.4

1 −0.5z

−1

which has the causal inverse:

h(n)= 2.4δ(n)−0.4(0.5)

n

u(n)

Problem 6.13

The normalized peak and width frequencies are:

ω

0

=

2πf

0

f

s

=

2π250

5000

= 0.1π [rads/sample]

Δω=

2πΔf

f

s

=

2π20

5000

= 0.008π [rads/sample]

Therefore, the Q-factor of the ﬁlter will be:

Q =

ω

0

Δω

=

0.1π

0.008π

= 12.5

We take the ﬁlter poles to be at locations:

p = Re

jω0

, p

∗

= Re

−jω0

The pole radius R may be determined from the approximate relationship

Δω= 2(1 −R)

which gives:

R = 1 −

1

2

Δω= 1 −

1

2

0.008π = 0.9874

The denominator polynomial will be:

1 +a

1

z

−1

+a

2

z

−2

= (1 −pz

−1

)(1 −p

∗

z

−1

)= 1 −(p +p

∗

)z

−1

+p

∗

pz

−2

which gives:

a

1

= −(p +p

∗

)= −2Rcos ω

0

= −2 · 0.9874 · cos(0.1π)= −1.8781

a

2

= p

∗

p = R

2

= 0.9750

94

Therefore, the designed ﬁlter will be:

H(z)=

1

1 −1.8781z

−1

+0.9750z

−2

The time constant of the resonator is given in terms of the maximum pole radius (there is only

one radius here):

n

eff

=

ln

lnR

=

ln(0.01)

ln(0.9874)

= 363.18

The approximate expression is obtained by replacing R in terms of Δω:

n

eff

=

ln

lnR

=

ln

ln(1 −Δω/2)

=

ln

−Δω/2

= −

2ln

Δω

where we used the small-x approximation ln(1 − x)= −x. The approximate numerical value of

the time constant will be:

n

eff

= −

2ln

Δω

= −

2ln(0.01)

0.008π

= 366.47

which compares well with the exact value.

Problem 6.14

The -level time constant of a ﬁlter is (in sampling instants):

n

eff

=

ln

lnρ

where ρ = max

i

¦p

i

¦ is the maximum pole radius. In seconds, the time constant is:

τ = n

eff

T =

ln

lnρ

T

where T = 1/f

s

is the interval between samples. It follows that the

1

and

2

level time constants

will be

τ

1

=

ln

1

lnρ

T, τ

2

=

ln

2

lnρ

T

And therefore,

τ

1

=

ln

1

ln

2

τ

2

In particular, for the 60 versus 40 dB time constants, the scale factor is:

ln

1

ln

2

=

ln(0.001)

ln(0.01)

=

3

2

= 1.5

Problem 6.15

Using the approximate expression of Problem 6.13 and = 0.001, we have:

τ = n

eff

T = −

2ln

Δω

T = −

2ln

2πΔfT

T = −

ln

πΔf

which gives:

τ = −

ln

πΔf

−

ln(0.001)

πΔf

=

2.2

Δf

95

Problem 6.16

The periodic impulse response may be thought of as the sumof the delayed replicas of one period,

that is,

h(n)= g(n)+g(n −8)+g(n −16)+· · ·

where g(n)= [1, 2, 3, 4, 0, 0, 0, 0] is the basic period of length 8. Taking z-transforms we obtain:

H(z)= G(z)+z

−8

G(z)+z

−16

G(z)+· · · = (1 +z

−8

+z

−16

+· · · )G(z)

where G(z)= 1 +2z

−1

+3z

−2

+4z

−3

. Using the geometric series on the ﬁrst factor we obtain:

H(z)=

G(z)

1 −z

−8

=

1 +2z

−1

+3z

−2

+4z

−3

1 −z

−8

The direct and canonical realizations are shown in Fig. P6.1. Note that in the canonical realization

the total number of delays is 8, but the last 5 are lumped together into a ﬁvefold delay z

−5

. The

sample processing algorithm for the canonical case is:

x y

2

3

4

z

-1

z

-1

z

-1

x y

2

3

4

w

0

w

1

w

2

w

3

w

4

z

-1

z

-1

z

-1

z

-1

w

5

w

6

w

7

w

8

z

-1

z

-1

z

-1

z

-1

z

-1

z

-1

z

-1

z

-1

z

-1

z

-1

z

-1

z

-1

Fig. P6.1 Filter realizations of Problem 6.16.

for each input x do:

w

0

= x +w

8

y = w

0

+2w

1

+3w

2

+4w

3

delay(8, w)

where the call to delay(8, w) implements the updating of the delay line, that is, w

8

= w

7

, w

7

= w

6

,

. . . , w

1

= w

0

.

Problem 6.17

The solution is similar to that of Problem 6.16. Here, the repetition period is 4 and we have:

h(n)= g(n)+g(n −4)+g(n −8)+g(n −12)+· · ·

96

where g(n)= [0, 1, 2, 3]. In the z-domain, we have:

H(z)= G(z)+z

−4

G(z)+z

−8

G(z)+· · · = (1 +z

−4

+z

−8

+· · · )G(z)=

G(z)

1 −z

−4

where G(z)= z

−1

+2z

−2

+3z

−3

. Thus,

H(z)=

z

−1

+2z

−2

+3z

−3

1 −z

−4

The direct and canonical realizations are shown in Fig. P6.2.

x

y

2

3

z

-1

z

-1

z

-1

x

y

2

3

w

0

w

1

w

2

w

3

w

4

z

-1

z

-1

z

-1

z

-1

z

-1

z

-1

z

-1

z

-1

Fig. P6.2 Direct and canonical realizations of Problem 6.17.

The sample processing algorithm for the canonical case is:

for each input x do:

w

0

= x +w

4

y = w

1

+2w

2

+3w

3

delay(4, w)

where the call to delay(4, w) implements the updating of the delay line, that is, w

4

= w

3

, w

3

= w

2

,

. . . , w

1

= w

0

. The cascade realization is obtained by factoring the numerator and denominator

into (up to) 2nd order polynomials:

H(z)=

z

−1

+2z

−2

+3z

−3

1 −z

−4

=

_

z

−1

1 −z

−2

__

1 +2z

−1

+3z

−2

1 +z

−2

_

≡ H

0

(z)H

1

(z)

The block diagram is shown in Fig. P6.3. The corresponding sample processing algorithm is:

for each input x do:

w

0

= x +w

2

x

1

= w

1

w

2

= w

1

w

1

= w

0

v

0

= x

1

−v

2

y = v

0

+2v

1

+3v

3

v

2

= v

1

v

1

= v

0

Using partial fractions, we may write:

97

x

w

0

w

1

w

2

z

-1

z

-1

x

1

y

3

-1

2

v

0

v

1

v

2

z

-1

z

-1

H

0

(z) H

1

(z)

Fig. P6.3 Cascade realization of Problem 6.17.

H(z) =

z

−1

+2z

−2

+3z

−3

1 −z

−4

=

z

−1

+2z

−2

+3z

−3

(1 −z

−1

)(1 +z

−1

)(1 −jz

−1

)(1 +jz

−1

)

=

A

1 −z

−1

+

B

1 +z

−1

+

C−jD

1 −jz

−1

+

C+jD

1 +jz

−1

where the PFE coefﬁcients C:jD are conjugates. The numerical values are:

A =

_

z

−1

+2z

−2

+3z

−3

(1 +z

−1

)(1 −jz

−1

)(1 +jz

−1

)

_

z=1

= 1.5

B =

_

z

−1

+2z

−2

+3z

−3

(1 −z

−1

)(1 −jz

−1

)(1 +jz

−1

)

_

z=−1

= −0.5

C−jD =

_

z

−1

+2z

−2

+3z

−3

(1 −z

−1

)(1 +z

−1

)(1 +jz

−1

)

_

z=j

= −0.5 +j0.5

Taking (causal) inverse z-transforms, we ﬁnd for n ≥ 0:

h(n) = A+B(−1)

n

+(C−jD)j

n

+(C+jD)(−j)

n

= A+B(−1)

n

+2Re

_

(C−jD)e

jπn/2

_

= A+B(−1)

n

+2Ccos(πn/2)+2Dsin(πn/2)

= 1.5 −0.5(−1)

n

−cos(πn/2)−sin(πn/2)

Evaluating at the ﬁrst couple of periods, we ﬁnd:

h(n)= [0, 1, 2, 3, 0, 1, 2, 3, . . . ]

Problem 6.18

Expand the denominator in powers of z

−7

and pick out the coefﬁcients of the powers of z

−1

. We

have:

H(z)=

1 +z

−1

+z

−2

+z

−3

1 −z

−7

= (1 +z

−1

+z

−2

+z

−3

)(1 +z

−7

+z

−14

+· · · )

The powers of z

−7

cause the period-7 replication of the basic period G(z)= 1 +z

−1

+z

−2

+z

−3

:

h(n)= [1, 1, 1, 1, 0, 0, 0

. ¸, .

, 1, 1, 1, 1, 0, 0, 0

. ¸, .

, 1, 1, 1, 1, 0, 0, 0

. ¸, .

, . . . ]

98

x y

w

0

w

1

w

2

w

3

w

4

z

-1

z

-1

z

-1

z

-1

w

5

w

6

w

7

z

-1

z

-1

z

-1

Fig. P6.4 Canonical realizations of Problem 6.18.

The canonical realization is shown in Fig. P6.4.

The sample processing algorithm is:

for each input x do:

w

0

= x +w

7

y = w

0

+w

1

+w

2

+w

3

delay(7, w)

where the call to delay implements the delay-line updates w

7

= w

6

, w

6

= w

5

, . . . , w

1

= w

0

. The

output due to the input x = [3, 2, 1] may be obtained by using the LTI form of convolution, that

is, summing up the delayed replicas of the impulse response, scaled by the input samples:

x

0

h

n

= [3, 3, 3, 3, 0, 0, 0, 3, 3, 3, 3, 0, 0, 0, 3, 3, 3, 3, 0, 0, 0, . . . ]

x

0

h

n−1

= [0, 2, 2, 2, 2, 0, 0, 0, 2, 2, 2, 2, 0, 0, 0, 2, 2, 2, 2, 0, 0, . . . ]

x

0

h

n−2

= [0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, . . . ]

y

n

= [3, 5, 6, 6, 3, 1, 0, 3, 5, 6, 6, 3, 1, 0, 3, 5, 6, 6, 3, 1, 0, . . . ]

Thus, the output also has period 7. The same conclusion can be reached working with z-transforms.

We have for the output z-transform:

Y(z)= H(z)X(z) =

(1 +z

−1

+z

−2

+z

−3

)(3 +2z

−1

+z

−2

)

1 −z

−7

=

3 +5z

−1

+6z

−2

+6z

−3

+3z

−4

+z

−5

1 −z

−7

The expansion of the denominator in powers of z

−7

will cause the period-7 replication of the

numerator.

Problem 6.19

The expansion of the denominator, will cause the period-2 replication of the numerator. Because

the numerator has length 4, its period-2 replicas will overlap with each other and must be added

together:

99

H(z)=

1 +z

−1

+z

−2

+z

−3

1 −z

−2

= (1 +z

−1

+z

−2

+z

−3

)(1 +z

−2

+z

−4

+· · · )

or, in the time domain:

h =[1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, . . . ]

+[0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, . . . ]

+[0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, . . . ]+· · ·

=[1, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, . . . ]

The canonical realization and sample processing algorithm are:

x y

w

0

w

1

w

2

w

3

z

-1

z

-1

z

-1

for each input x do:

w

0

= x +w

2

y = w

0

+w

1

+w

2

+w

3

w

3

= w

2

w

2

= w

1

w

1

= w

0

Problem 6.20

Writing the sample processing algorithm in terms of the time index n, we have

w

0

(n) = x(n)+w

1

(n)

y(n) = w

0

(n)+w

2

(n)

w

2

(n +1) = w

1

(n)

w

1

(n +1) = w

0

(n)

or, in the z-domain

W

0

(z) = X(z)+W

1

(z)

Y(z) = W

0

(z)+W

2

(z)

zW

2

(z) = W

1

(z)

zW

1

(z) = W

0

(z)

Eliminating W

0

(z), W

1

(z), W

2

(z) in favor of Y(z) and X(z), we obtain:

W

1

(z)= z

−1

W

0

(z), W

2

(z)= z

−1

W

1

(z)= z

−2

W

0

(z)

W

0

(z)= X(z)+z

−1

W

0

(z) ⇒ W

0

(z)=

X(z)

1 −z

−1

Y(z)= W

0

(z)+z

−2

W

0

(z)= (1 +z

−2

)W

0

(z)= (1 +z

−2

)

X(z)

1 −z

−1

100

which gives:

H(z)=

Y(z)

X(z)

=

1 +z

−2

1 −z

−1

Multiplying numerator and denominator by 1 +z

−1

, we get:

H(z)=

(1 +z

−2

)(1 +z

−1

)

(1 −z

−1

)(1 +z

−1

)

=

1 +z

−1

+z

−2

+z

−3

1 −z

−2

which is the same as that of Problem 6.19.

Problem 6.21

The number of harmonics ﬁtting within the Nyquist interval are:

f

s

f

1

=

240

60

= 4

Therefore, the harmonics will lie at the fourth roots of unity around the unit circle:

ω

k

= kω

1

=

2πk

4

, k = 0, 1, 2, 3

The numerator polynomial 1 − z

−4

will have e

jω

k

as roots. Putting the poles just behind the

zeros, we get the desired multinotch ﬁlter:

H(z)=

1 −z

−4

1 −az

−4

where 0 < a < 1 must be chosen to be very near 1.

Problem 6.22

The zeros are at the 16th roots of unity, that is,

z

k

= e

jω

k

= e

2πjk/16

, k = 0, 1, . . . , 15

The poles are just behind the zeros at the same angles:

p

k

= a

1/16

e

jω

k

= a

1/16

e

2πjk/16

, k = 0, 1, . . . , 15

The zeros and poles are shown in Fig. P6.5. If a is very near 1, the magnitude response will vanish

at the harmonics ω

k

= kω

1

= 2πk/16, and be essentially ﬂat between zeros. Fig. P6.6 shows a

sketch of ¦H(ω)¦.

The impulse response is obtained by expanding H(z) into powers of z

−16

. We have with A = 1/a

and B = 1 −A = 1 −1/a:

H(z)=

1 −z

−16

1 −az

−16

= A+

B

1 −az

−16

= A+B(1 +az

−16

+a

2

z

−32

+· · · )

Thus, the causal impulse response will be h(n):

h(n)=

⎧

⎪

⎪

⎪

⎨

⎪

⎪

⎪

⎩

A+B = 1, if n = 0

Ba

n/16

, if n is a non-zero multiple of 16

0, otherwise

101

z-plane

= zeros

= zeros

1

Fig. P6.5 Pole/zero pattern of Problem 6.22.

ω

1

ω

1

= 2π/16

ω

2ω

1

3ω

1

4ω

1

15ω

1

16ω

1

=2π 0

...

|H(ω)|

Fig. P6.6 Magnitude response of Problem 6.22.

The canonical realization and sample processing algorithm are:

y

x

a -1

w

0

w

16

z

-16

for each input x do:

w

0

= x +w

16

y = w

0

−aw

16

delay(16, w)

where the call to delay updates the 17-dimensional delay line.

Problem 6.23

H(z)= −0.3 +

0.6

1 −0.5z

−1

. It follows that h(n)= −0.3δ(n)+0.6(0.5)

n

u(n).

Problem 6.24

The gain factor 1 − a normalizes the magnitude response to unity at DC. The direct form I/O

difference equation is obtained from:

H(z)=

Y(z)

X(z)

=

1 −a

1 −az

−1

⇒ (1 −az

−1

)Y(z)= (1 −a)X(z)

or,

Y(z)= az

−1

Y(z)+(1 −a)X(z)= X(z)+a(z

−1

Y(z)−X(z))

and in the time domain:

102

y(n)= x(n)+a(y(n −1)−x(n))

A realization based on this expression, as well as the canonical realization, are shown in Fig. 6.24.

The corresponding sample processing algorithm will be:

for each input x do:

y = x +a(w

1

−x)

w

1

= y

y

x

a

w

1

z

-1

y

x

a

1−a

w

1

w

0

z

-1

− +

Fig. P6.7 Realizations of Problem 6.24.

Problem 6.25

The ﬁlter poles are at z = 2, −0.5. Thus,

H(z)=

3 −3z

−1

−z

−2

1 −1.5z

−1

−z

−2

=

3 −3z

−1

−z

−2

(1 −2z

−1

)(1 +0.5z

−1

)

Expanding in partial fractions, we have:

H(z)=

3 −3z

−1

−z

−2

(1 −2z

−1

)(1 +0.5z

−1

)

= A+

B

1 −2z

−1

+

C

1 +0.5z

−1

where

A =

_

3 −3z

−1

−z

−2

1 −1.5z

−1

−z

−2

_

z=0

= 1

B =

_

3 −3z

−1

−z

−2

1 +0.5z

−1

_

z=2

= 1

C =

_

3 −3z

−1

−z

−2

1 −2z

−1

_

z=−0.5

= 1

The three possible ROCs and corresponding inverses are:

¦z¦ > 2 , h(n)= Aδ(n)+B2

n

u(n)+C(−0.5)

n

u(n)

2 > ¦z¦ > 0.5, h(n)= Aδ(n)−B2

n

u(−n −1)+C(−0.5)

n

u(n)

¦z¦ < 0.5, h(n)= Aδ(n)−B2

n

u(−n −1)−C(−0.5)

n

u(−n −1)

Only the second one is stable. Its ROC contains the unit circle.

103

Problem 6.26

The transfer function is obtained fromthe I/Odifference equation by taking z-transforms of both

sides and solving for the ratio Y(z)/X(z):

Y(z)= 2.5z

−1

Y(z)−z

−2

Y(z)+3X(z)+3z

−2

X(z) ⇒ H(z)=

Y(z)

X(z)

=

3(1 +z

−2

)

1 −2.5z

−1

+z

−2

Factoring the denominator into its poles and expanding in partial fractions, we get:

H(z)=

3(1 +z

−2

)

1 −2.5z

−1

+z

−2

=

3(1 +z

−2

)

(1 −2z

−1

)(1 −0.5z

−1

)

= A+

B

1 −2z

−1

C

1 −0.5z

−1

where

A =

_

3(1 +z

−2

)

1 −2.5z

−1

+z

−2

_

z=0

= 3

B =

_

3(1 +z

−2

)

1 −0.5z

−1

_

z=2

= 5

C =

_

3(1 +z

−2

)

1 −2z

−1

_

z=0.5

= −5

Thus, the ROCs and corresponding inverses are:

¦z¦ > 2 , h(n)= Aδ(n)+B2

n

u(n)+C0.5

n

u(n)

2 > ¦z¦ > 0.5, h(n)= Aδ(n)−B2

n

u(−n −1)+C0.5

n

u(n)

¦z¦ < 0.5, h(n)= Aδ(n)−B2

n

u(−n −1)−C0.5

n

u(−n −1)

The z-transform of the signal g(n) is:

g(n)= cos(πn/2)u(n)

Z

−→G(z)=

1

1 +z

−2

Therefore, the z-transform of the input x(n) will be:

x(n)= g(n)−2g(n −1)

Z

−→X(z)= G(z)−2z

−1

G(z)= (1 −2z

−1

)G(z)=

1 −2z

−1

1 +z

−2

Thus, the output z-transform will be:

Y(z)= H(z)X(z)=

3(1 +z

−2

)

(1 −2z

−1

)(1 −0.5z

−1

)

·

1 −2z

−1

1 +z

−2

=

3

1 −0.5z

−1

Inverting causally, we ﬁnd:

y(n)= 3(0.5)

n

u(n)

Problem 6.27

Using the inverse DTFT formula of Eq. (6.3.5), we have:

y(n)=

1

2π

_

π

−π

H(ω)X(ω)e

jωn

dω

Similarly, for the input signal, assuming its spectrum is restricted to be only over the range

[−ω

c

, ω

c

]:

104

x(n)=

1

2π

_

ωc

−ωc

X(ω)e

jωn

dω

Using d(ω)= D, the deﬁnition of H(ω) over one Nyquist interval will be:

H(ω)=

⎧

⎨

⎩

Ge

−jDω

, for 0 ≤ ¦ω¦ ≤ ω

c

0, for ω

c

< ¦ω¦ ≤ π

where G is its passband gain. Thus, the integration range for y(n) also collapses to [−ω

c

, ω

c

],

giving:

y(n)=

1

2π

_

ωc

−ωc

Ge

−jDω

X(ω)e

jωn

dω= G

1

2π

_

ωc

−ωc

X(ω)e

jω(n−D)

dω

Comparing this with the expression of x(n), we recognize that

y(n)= Gx(n −D)

Problem 6.28

The PF expansion of H(z) is of the form:

H(z)=

N(z)

M

i=1

(1 −p

i

z

−1

)

=

M

_

i=1

A

i

1 −p

i

z

−1

where the i-th coefﬁcient is obtained by deleting the factor (1 − p

i

z

−1

) from the left-hand side

and evaluating the remainder at z = p

i

, that is,

A

i

=

⎡

⎢

⎢

⎢

⎣

N(z)

j}=i

(1 −p

j

z

−1

)

⎤

⎥

⎥

⎥

⎦

z=p

i

=

N(p

i

)

j}=i

(1 −p

j

p

−1

i

)

Taking causal inverse z-transforms, we ﬁnd for h(n):

h(n)=

M

_

i=1

A

i

p

n

i

u(n)

Problem 6.29

The z-transforms of the causal and anticausal sinusoidal inputs are the same up to a negative

sign:

e

jω0n

u(n)

Z

−→

1

1 −e

jω0

z

−1

e

jω0n

u(−n −1)

Z

−→−

1

1 −e

jω0

z

−1

with ROCs ¦z¦ > 1 and ¦z¦ < 1, respectively. The output z-transform will be Y(z)= H(z)X(z).

Thus, in the two cases:

105

Y(z)= :

N(z)

(1 −e

jω0

z

−1

)

M

i=1

(1 −p

i

z

−1

)

The partial fraction expansion leads to

Y(z)= :

C

1 −e

jω0

z

−1

:

M

_

i=1

B

i

1 −p

i

z

−1

where C = H(ω

0

), as we sawin Eq. (6.3.10), and B

i

are obtained by deleting the factor (1−p

i

z

−1

)

and evaluating the rest at z = p

i

:

B

i

=

⎡

⎢

⎢

⎢

⎣

N(z)

(1 −e

jω0

z

−1

)

j}=i

(1 −p

j

z

−1

)

⎤

⎥

⎥

⎥

⎦

z=p

i

=

N(p

i

)

(1 −e

jω0

p

−1

i

)

M

j}=i

(1 −p

j

p

−1

i

)

Comparing with the result of the previous problem, we have:

B

i

=

A

i

1 −e

jω0

p

−1

i

To get the inverse z-transform y(n), we must assume a particular ROC. For the causal case, we

take the ROC to be ¦z¦ > 1, so that all the PFE terms will be inverted causally. For the anticausal

case, we take the ﬁ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:

max

i

¦p

i

¦ < ¦z¦ < 1

In this case the C term will be inverted anticausally and the B

i

terms causally. These choices for

the ROCs, give:

y(n) = H(ω

0

)e

jω0n

u(n)+

M

_

i=1

B

i

p

n

i

u(n)

y(n) = H(ω

0

)e

jω0n

u(−n −1)−

M

_

i=1

B

i

p

n

i

u(n)

Adding up the right-sided and left-sided sinusoidal inputs gives rise to the double-sided input:

e

jω0n

u(n)+e

jω0n

u(−n −1)= e

jω0n

_

u(n)+u(−n −1)

_

= e

jω0n

, −∞< n < ∞

where, we used the property u(n)+u(−n − 1)= 1 for all n. It follows from the linearity of the

ﬁlter that the corresponding output will be the sum of the two outputs obtained above. This

gives:

y(n) = H(ω

0

)e

jω0n

u(n)+

M

_

i=1

B

i

p

n

i

u(n)+H(ω

0

)e

jω0n

u(−n −1)−

M

_

i=1

B

i

p

n

i

u(n)

= H(ω

0

)e

jω0n

u(n)+H(ω

0

)e

jω0n

u(−n −1)

= H(ω

0

)e

jω0n

which is recognized as the standard steady-state sinusoidal response of the ﬁlter.

106

Problem 6.30

The PF expansion of H(z) gives:

H(z)=

3 −5z

−1

+z

−2

(1 −0.5z

−1

)(1 −2z

−1

)

= 1 +

1

1 −0.5z

−1

+

1

1 −2z

−1

The stable ROC containing the unit circle will be 0.5 < ¦z¦ < 2. Therefore, the 0.5-pole term will

be inverted causally and the 2-pole anticausally:

h(n)= δ(n)+0.5

n

u(n)−2

n

u(−n −1)

The truncated impulse response agrees with h(n) for n ≥ −D and is zero otherwise, that is:

`

h(n)=

⎧

⎪

⎪

⎪

⎨

⎪

⎪

⎪

⎩

δ(n)+0.5

n

, n ≥ 0

−2

n

, −D ≤ n ≤ −1

0, n ≤ −D−1

The corresponding z-transform is by deﬁnition:

`

H(z)=

∞

_

n=0

[δ(n)+0.5

n

]z

−n

−

−1

_

n=−D

2

n

z

−n

The last term can be summed by changing summation variables from n to m= −n:

−1

_

n=−D

2

n

z

−n

=

D

_

m=1

2

−m

z

m

=

2

−1

z(1 −2

−D

z

D

)

1 −2

−1

z

= −

1 −2

−D

z

D

1 −2z

−1

where we used the ﬁnite geometric series:

D

_

m=1

x

m

= x +x

2

+· · · x

D

= x(1 +x +x

2

+· · · x

D−1

)=

x(1 −x

D

)

1 −x

Thus,

`

H(z)= 1 +

1

1 −0.5z

−1

+

1 −2

−D

z

D

1 −2z

−1

Comparing with the exact H(z) we have:

`

H(z)= H(z)−

2

−D

z

D

1 −2z

−1

or, the error transfer function:

H(z)−

`

H(z)=

2

−D

z

D

1 −2z

−1

The given input has z-transform:

x(n)= δ(n)−2δ(n −1)

Z

−→X(z)= 1 −2z

−1

The error output will be

E(z)= Y(z)−

`

Y(z)= H(z)X(z)−

`

H(z)X(z)=

_

H(z)−

`

H(z)

_

X(z)

or,

E(z)=

2

−D

z

D

1 −2z

−1

· (1 −2z

−1

)= 2

−D

z

D

and in the time domain:

e(n)= 2

−D

δ(n +D)

By choosing D large enough, the factor 2

−D

can be made as small as desired.

107

Chapter 7 Problems

Problem 7.1

Expanding the denominator in powers of z

−5

will replicate the numerator periodically with period

5. But because the numerator itself has length 5, the replicas will not overlap, and we will get the

repetition of the numerator coefﬁcients:

h = [0, 1, 2, 3, 4

. ¸, .

, 0, 1, 2, 3, 4

. ¸, .

, 0, 1, 2, 3, 4

. ¸, .

, . . . ]

The direct and canonical realizations are shown in Fig. P7.1.

x

y

x

y

z

-1

z

-1

z

-1

z

-1

z

-1

z

-1

2

3

4

z

-1

z

-1

z

-1

w

5

w

0

w

1

w

2

w

3

w

4

w

5

w

0

w

1

w

2

w

3

w

4

v

0

v

1

v

2

v

3

v

4

z

-1

2

3

4

z

-1

z

-1

z

-1

z

-1

Fig. P7.1 Direct and canonical realizations of Problem 7.1.

The sample processing algorithms are expressed with the help of the routine delay, which updates

the ﬁlter’s internal state vectors.

for each input x do:

v

0

= x

w

0

= w

5

+v

1

+2v

2

+3v

3

+4v

4

y = w

0

delay(4, v)

delay(5, w)

for each input x do:

w

0

= x +w

5

y = w

1

+2w

2

+3w

3

+4w

4

delay(5, w)

where v = [v

0

, v

1

, v

2

, v

4

], w = [w

0

, w

1

, w

2

, w

3

, w

4

.w

5

] are the 5- and 6-dimensional state vec-

tors needed for the numerator and denominator polynomials. The calls to the delay routines

update the delay line, e.g., the call delay(5, w) is equivalent to the shifts: w

5

= w

4

, w

4

= w

3

,

w

3

= w

2

, w

2

= w

1

, w

1

= w

0

.

Factoring the denominator as 1−z

−5

= (1−z

−1

)(1+z

−1

+z

−2

+z

−3

+z

−4

), we get the cascaded

transfer functions:

H(z)=

z

−1

+2z

−2

+3z

−3

+4z

−4

1 −z

−5

=

z

−1

1 −z

−1

·

1 +2z

−1

+3z

−2

+4z

−3

1 +z

−1

+z

−2

+z

−3

+z

−4

Figure P7.2 shows the cascade of these two ﬁlters, with each ﬁlter realized in its canonical form.

The corresponding sample processing algorithm is as follows:

108

x

1

y

2 -1

-1

-1

-1

3

4

z

-1

z

-1

w

0

w

1

w

2

z

-1

w

3

z

-1

w

4

x

z

-1

v

0

v

1

Fig. P7.2 Cascade realization of Problem 7.1.

for each input x do:

v

0

= x +v

1

x

1

= v

1

delay(1, v)

w

0

= x

1

−w

1

−w

2

−w

3

−w

4

y = w

0

+2w

1

+3w

2

+4w

3

delay(4, w)

where v = [v

0

, v

1

], w = [w

0

, w

1

, w

2

, w

3

, w

4

] are the internal state vectors for the two ﬁlter

sections.

Problem 7.2

In the z-domain, the input to H

1

(z) is X(z)−Y(z). Therefore, its output will be H

1

(z)

_

Y(z)

−X(z)

_

. The input and output of H

2

(z) will be then :

H

1

(z)

_

Y(z)−X(z)

_

−Y(z)−→H

2

(z)

_

H

1

(z)

_

Y(z)−X(z)

_

−Y(z)

_

Adding the noise component E(z) to the output of H

2

(z) will generate Y(z), resulting in:

Y(z)= H

2

(z)

_

H

1

(z)

_

Y(z)−X(z)

_

−Y(z)

_

+E(z)

Moving the Y-dependent terms to the left, we get:

_

1 +H

2

(z)+H

1

(z)H

2

(z)

_

Y(z)= H

1

(z)H

2

(z)X(z)+E(z)

and solving for Y(z):

Y(z)=

H

1

(z)H

2

(z)

1 +H

2

(z)+H

1

(z)H

2

(z)

X(z)+

1

1 +H

2

(z)+H

1

(z)H

2

(z)

E(z)

Thus, the desired transfer functions are identiﬁed to be:

H

x

(z) =

H

1

(z)H

2

(z)

1 +H

2

(z)+H

1

(z)H

2

(z)

H

e

(z) =

1

1 +H

2

(z)+H

1

(z)H

2

(z)

109

The conditions that H

x

(z) be a plain delay and H

e

(z) a double differentiator, gives the two

equations:

H

1

(z)H

2

(z)

1 +H

2

(z)+H

1

(z)H

2

(z)

= z

−1

1

1 +H

2

(z)+H

1

(z)H

2

(z)

= (1 −z

−1

)

2

which can be solved for H

1

(z) and H

2

(z) giving:

H

1

(z) =

1

1 −z

−1

H

2

(z) =

z

−1

1 −z

−1

They are both integrators. The presence of z

−1

in the numerator of H

2

(z) is necessary to make

the overall closed loop computable. See also Problems 12.24 and 12.25.

Problem 7.3

Multiplying the numerator factors, we get the transfer function:

H(z)=

z

−1

(1 +2z

−2

)(1 +3z

−2

)

1 −z

−6

=

z

−1

+5z

−3

+6z

−5

1 −z

−6

The direct and canonical realizations are shown in Fig. P7.3.

x

y

x

y

z

-1

z

-1

z

-1

z

-1

z

-1

w

5

w

6

w

0

w

1

w

2

w

3

w

4

z

-1

z

-1

z

-1

z

-1

z

-1

z

-1

w

5

w

6

w

0

w

1

w

2

w

3

w

4

z

-1

z

-1

z

-1

z

-1

z

-1

v

5

v

0

v

1

v

2

v

3

v

4

z

-1

5

6

5

6

Fig. P7.3 Direct and canonical realizations of Problem 7.3.

The sample processing algorithms are expressed with the help of the routine delay, which updates

the ﬁlter’s internal state vectors.

for each input x do:

v

0

= x

w

0

= v

1

+5v

3

+6v

5

+w

6

y = w

0

delay(5, v)

delay(6, w)

for each input x do:

w

0

= x +w

6

y = w

1

+5w

3

+6w

5

delay(6, w)

110

where v = [v

0

, v

1

, v

2

, v

4

, v

5

], w = [w

0

, w

1

, w

2

, w

3

.w

4

, w

5

, w

6

] are the 6- and 7-dimensional state

vectors needed for the numerator and denominator polynomials. The calls to the delay routines

update the delay line, e.g., the call delay(6, w) is equivalent to the shifts: w

6

= w

5

, w

5

= w

4

,

w

4

= w

3

, w

3

= w

2

, w

2

= w

1

, w

1

= w

0

. Factoring the denominator as

1 −z

−6

= (1 −z

−2

)(1 +z

−2

+z

−4

)= (1 −z

−2

)(1 +z

−1

+z

−2

)(1 −z

−1

+z

−2

)

we get the cascade transfer function:

H(z)=

z

−1

1 −z

−2

·

1 +2z

−2

1 +z

−1

+z

−2

·

1 +3z

−2

1 −z

−1

+z

−2

Figure P7.4 shows the cascade of these three ﬁlters, with each ﬁlter realized in its canonical form.

z

-1

z

-1

u

0

u

1

u

2

x x

1

x

2

y

z

-1

z

-1

v

0

v

1

v

2

2 -1

-1

z

-1

z

-1

w

0

w

1

w

2

3 -1

Fig. P7.4 Cascade realization of Problem 7.3.

The corresponding sample processing algorithm is as follows:

for each input x do:

u

0

= x +u

2

x

1

= u

1

delay(2, u)

v

0

= x

1

−v

1

−v

2

x

2

= v

0

+2v

2

delay(2, v)

w

0

= x

2

+w

1

−w

2

y = w

0

+3w

2

delay(2, w)

where u = [u

0

, u

1

, u

2

], v = [v

0

, v

1

, v

2

], w = [w

0

, w

1

, w

2

], are the internal state vectors for the

three ﬁ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 z

−6

will replicate the numerator

periodically with period 6. But because the numerator itself has length 6, the replicas will not

overlap, and we will get the repetition of the numerator coefﬁcients:

h = [0, 1, 0, 3, 0, 5

. ¸, .

, 0, 1, 0, 3, 0, 5

. ¸, .

, 0, 1, 0, 3, 0, 5

. ¸, .

, . . . ]

Problem 7.4

The z-domain versions of the time domain difference equations are:

v(n) = x(n)+v(n −1)

y(n) = v(n)+v(n −2)+v(n −4)

⇒

V(z) = X(z)+z

−1

V(z)

Y(z) = V(z)+z

−2

V(z)+z

−4

V(z)

111

Eliminating V(z) in favor of Y(z), X(z), gives:

V(z)=

X(z)

1 −z

−1

, Y(z)= (1 +z

−2

+z

−4

)V(z)=

1 +z

−2

+z

−4

1 −z

−1

X(z)

Therefore, the transfer function is:

H(z)=

1 +z

−2

+z

−4

1 −z

−1

=

1 +z

−1

+z

−2

1 −z

−1

· (1 −z

−1

+z

−2

)

where we factored the numerator as

1 +z

−2

+z

−4

= (1 +z

−1

+z

−2

)(1 −z

−1

+z

−2

)

The direct, canonical, and cascade realizations are shown in Fig. P7.5.

x

y

z

-1

z

-1

z

-1

w

0

w

1

w

2

w

3

w

4

z

-1

x

y

z

-1

w

0

w

1

z

-1

z

-1

z

-1

v

0

v

1

v

2

v

3

v

4

z

-1

x

x

1

z

-1

z

-1

v

0

v

1

v

2

y

z

-1

z

-1

w

0

w

1

w

2

-1

Fig. P7.5 Direct, canonical, and cascade realizations of Problem 7.4.

The direct and canonical sample processing algorithms are:

for each input x do:

v

0

= x

w

0

= v

0

+v

2

+v

4

+w

1

y = w

0

delay(4, v)

delay(1, w)

for each input x do:

w

0

= x +w

1

y = w

0

+w

2

+w

4

delay(4, w)

And for the cascade realization:

112

for each input x do:

v

0

= x +v

1

x

1

= v

0

+v

1

+v

2

delay(2, v)

w

0

= x

1

y = w

0

−w

1

+w

2

delay(2, w)

Problem 7.5

Factoring the denominator, we may write the transfer function as:

H(z)=

2 −3z

−1

1 −0.5z

−2

·

1 +z

−2

1 +0.5z

−2

=

2 −3z

−1

+2z

−2

−3z

−3

1 −0.25z

−4

The direct and canonical realizations are shown in Fig. P7.6. Their sample processing algorithms

are:

for each input x do:

v

0

= x

w

0

= 2v

0

−3v

1

+2v

2

−3v

3

+0.25w

4

y = w

0

delay(3, v)

delay(4, w)

for each input x do:

w

0

= x +0.25w

4

y = 2w

0

−3w

1

+2w

2

−3w

3

delay(4, w)

x

y

z

-1

z

-1

z

-1

w

0

w

1

w

2

w

3

w

4

z

-1

x

y

z

-1

z

-1

z

-1

v

0

v

1

v

2

v

3

z

-1

z

-1

z

-1

w

0

w

1

w

2

w

3

w

4

z

-1

2

2

-3

-3

2

2

-3

-3

0.25 0.25

Fig. P7.6 Direct and canonical realizations of Problem 7.5.

The cascade realization is shown in Fig. P7.7. Its sample processing algorithm is:

for each input x do:

v

0

= x +0.5v

2

x

1

= 2v

0

−3v

1

delay(2, v)

w

0

= x

1

−0.5w

2

y = w

0

+w

2

delay(2, w)

113

x

z

-1

z

-1

v

0

v

1

x

1

v

2

2

-3

0.5

y

z

-1

z

-1

w

0

w

1

w

2 -0.5

Fig. P7.7 Cascade realization of Problem 7.5.

Problem 7.6

The direct and canonical realizations are shown in Fig. P7.8. Their sample processing algorithms

are:

for each input x do:

v

0

= x

w

0

= v

0

−2.25v

2

+0.0625w

4

y = w

0

delay(2, v)

delay(4, w)

for each input x do:

w

0

= x +0.0625w

4

y = w

0

−2.25w

2

delay(4, w)

x

y

z

-1

z

-1

z

-1

w

0

w

1

w

2

w

3

w

4

z

-1

x

y

z

-1

z

-1

v

0

v

1

v

2

z

-1

z

-1

z

-1

w

0

w

1

w

2

w

3

w

4

z

-1

-2.25 -2.25

0.0625 0.0625

Fig. P7.8 Direct and canonical realizations of Problem 7.6.

The cascade realization is shown in Fig. P7.9. Its sample processing algorithm is:

for each input x do:

v

0

= x −0.25v

2

x

1

= v

0

−2.25v

2

delay(2, v)

y = w

0

= x

1

+0.25w

2

delay(2, w)

Expanding H(z) in partial fractions, we have:

H(z)=

2.5

1 −0.5jz

−1

+

2.5

1 +0.5jz

−1

+

2

1 −0.5z

−1

+

2

1 +0.5z

−1

114

x

z

-1

z

-1

v

0

v

1

x

1

v

2 -2.25 -0.25

y

z

-1

z

-1

w

0

w

1

w

2 0.25

Fig. P7.9 Cascade realization of Problem 7.6.

The four poles z = :0.5, :0.5j, deﬁne only two ROCs, namely, the causal case ¦z¦ > 0.5 and the

anticausal one ¦z¦ < 0.5. For example, in the causal case, the impulse response will be:

h(n)= 2.5(0.5j)

n

u(n)+2.5(−0.5j)

n

u(n)+2(0.5)

n

u(n)+2(−0.5)

n

u(n)

Writing j

n

+(−j)

n

= e

jπn/2

+e

−jπn/2

= 2cos(πn/2), we have:

h(n)= 5(0.5)

n

cos(2πn/2)+2(0.5)

n

u(n)+2(−0.5)

n

u(n)

Problem 7.7

The direct and canonical realizations are shown in Fig. P7.10. Their sample processing algorithms

are:

for each input x do:

v

0

= x

y = w

0

= v

0

−2v

2

+v

4

+0.4096w

4

delay(4, v)

delay(4, w)

for each input x do:

w

0

= x +0.4096w

4

y = w

0

−2w

2

+w

4

delay(4, w)

x

y

z

-1

z

-1

z

-1

w

0

w

1

w

2

w

3

w

4

z

-1

x

y

z

-1

z

-1

v

0

v

1

v

2

v

3

v

4

z

-1

z

-1

w

0

w

1

w

2

w

4

z

-1

w

3

z

-1

z

-1

z

-1

-2 -2

0.4096 0.4096

Fig. P7.10 Direct and canonical realizations of Problem 7.7.

The cascade realization is shown in Fig. P7.11. It corresponds the factorization:

H(z)=

1 −2z

−2

+z

−4

1 −0.4096z

−4

=

1 −z

−2

1 −0.64z

−2

·

1 −z

−2

1 +0.64z

−2

115

Note that the numerator could also have been factored as:

1 −2z

−2

+z

−4

= (1 −z

−2

)

2

= (1 −z

−1

)

2

(1 +z

−1

)

2

= (1 −2z

−1

+z

−2

)(1 +2z

−1

+z

−2

)

But the chosen one has the simplest coefﬁcients. Its sample processing algorithm is:

for each input x do:

v

0

= x +0.64v

2

x

1

= v

0

−v

2

delay(2, v)

w

0

= x

1

−0.64w

2

y = w

0

−w

2

delay(2, w)

x

z

-1

z

-1

v

0

v

1

x

1

v

2 -1 0.64

z

-1

z

-1

w

0

w

1

w

2 -1 -0.64

y

Fig. P7.11 Cascade realization of Problem 7.7.

Problem 7.8

The given difference equations describe the canonical realization form of the ﬁlter:

H(z)=

−0.75 +z

−10

1 −0.75z

−10

Its block diagram realization and sample processing algorithm are given below:

x

z

-10

w

0

w

10

0.75

-0.75 y

for each input sample x do:

w

0

= x +0.75w

10

y = −0.75w

0

+w

10

delay(10, w)

The C version of the algorithm is as follows:

double reverb(x, w)

double x, w[11];

{

int i;

double y;

w[0] = x + 0.75 * w[10];

y = - 0.75 * w[0] + w[10];

116

for (i=10; i>=1; i--)

w[i] = w[i-1];

return y;

}

From the transfer function, we obtain the frequency response:

H(ω)=

−0.75 +e

−10jω

1 −0.75e

−10jω

=

1 −0.75e

10jω

1 −0.75e

−10jω

e

−10jω

=

(1 −0.75e

−10jω

)

∗

(1 −0.75e

−10jω

)

e

−10jω

Noting that the ratio of two conjugate complex numbers has unit magnitude, it follows that H(ω)

will have unit magnitude.

Problem 7.9

The given sample processing algorithm corresponds to the canonical realization of the ﬁlter:

H(z)=

1 +z

−3

1 −0.64z

−4

Factoring the numerator in the form:

1 +z

−4

= (1 +z

−1

)(1 −z

−1

+z

−2

)

we obtain the cascade factors:

H(z)=

1 +z

−3

1 −0.64z

−4

=

1 +z

−1

1 −0.8z

−2

·

1 −z

−1

+z

−2

1 +0.8z

−2

The cascade realization is shown in Fig. P7.12. Its sample processing algorithm is:

for each input x do:

v

0

= x +0.8v

2

x

1

= v

0

+v

1

delay(2, v)

w

0

= x

1

−0.8w

2

y = w

0

−w

1

+w

2

delay(2, w)

x

z

-1

z

-1

v

0

v

1

x

1

v

2

0.8

z

-1

z

-1

w

0

w

1

w

2 -0.8

-1

y

Fig. P7.12 Cascade realization of Problem 7.9.

117

Problem 7.10

The ﬁrst ﬁlter is an FIR ﬁlter with transfer function and impulse response:

H(z)= (1 +z

−2

)

3

= 1 +3z

−2

+3z

−4

+z

−6

⇒ h = [1, 0, 3, 0, 3, 0, 1]

The causal impulse response of the third ﬁlter is obtained by the remove restore method, that is,

h(n)= w(n)−w(n −4), where w(n)= (0.9)

n

u(n)]

The ﬁ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

j

-j

-0.9j

-j

0.9j

j

0.9

1 -1

π

ω

|H(ω)| |H(ω)| |H(ω)|

ω ω

π π

Fig. P7.13 Pole/zero patterns of Problem 7.10.

Problem 7.11

Multiplying the transfer function factors, we obtain:

H(z)=

(1 −

√

2z

−1

+z

−2

)(1 +

√

2z

−1

+z

−2

)

(1 +0.81z

−2

)(1 −0.81z

−2

)

=

1 +z

−4

1 −0.6561z

−4

Therefore, the zeros will be at the roots of 1 +z

−4

= 0, that is,

z

4

= −1 ⇒ z = e

jπ(2k+1)/4

, k = 0, 1, 2, 3

that is, the 4th roots of unity rotated by 45

o

. The poles are at z = :0.9m, :0.9j. Fig. P7.14 shows

the pole/zero locations and the corresponding magnitude response.

The direct and canonical realizations are shown in Fig. P7.15. Their sample processing algorithms

are:

118

= zeros

= poles

-0.9j

0.9j

0.9 -0.9

|H(ω)|

ω

π

Fig. P7.14 Pole/zero plot of Problem 7.11.

for each input x do:

v

0

= x

y = w

0

= v

0

+v

4

+0.6561w

4

delay(4, v)

delay(4, w)

for each input x do:

w

0

= x +0.6561w

4

y = w

0

+w

4

delay(4, w)

x

y

z

-1

z

-1

z

-1

w

0

w

1

w

2

w

3

w

4

z

-1

x

y

z

-1

z

-1

v

0

v

1

v

2

v

3

v

4

z

-1

z

-1

w

0

w

1

w

2

w

4

z

-1

w

3

z

-1

z

-1

z

-1

0.6561 0.6561

Fig. P7.15 Direct and canonical realizations of Problem 7.11.

The cascade realization is shown in Fig. P7.16. Its sample processing algorithm is:

for each input x do:

v

0

= x −0.81v

2

x

1

= v

0

−

√

2v

1

+v

2

delay(2, v)

w

0

= x

1

+0.81w

2

y = w

0

+

√

2w

1

+w

2

delay(2, w)

Problem 7.12

The zeros are at the roots of 1 +16z

−4

= 0, that is,

119

x

z

-1

z

-1

v

0

v

1

x

1

v

2 -0.81

z

-1

z

-1

w

0

w

1

w

2 0.81

y

- 2 2

Fig. P7.16 Cascade realization of Problem 7.11.

z

4

= −16 ⇒ z = 2e

jπ(2k+1)/4

, k = 0, 1, 2, 3

that is, the 4th roots of unity rotated by 45

o

and scaled in magnitude by a factor of 2. Similarly,

the poles are at:

z

4

= −

1

16

⇒ z = 0.5e

jπ(2k+1)/4

, k = 0, 1, 2, 3

Fig. P7.17 shows the pole/zero locations.

= zeros

= poles

|H(ω)|

ω

π

unit

circle

1

Fig. P7.17 Pole/zero plot of Problem 7.12.

The magnitude response is constant in ω. Indeed, setting c = 1/16, we have:

H(ω)=

c +e

−4jω

1 +ce

−4jω

=

e

−4jω

(1 +ce

4jω

)

1 +ce

−4jω

= e

−4jω

(1 +ce

−4jω

)

∗

(1 +ce

−4jω

)

The ratio of the two conjugate factors will have unity magnitude, giving

¦H(ω)¦ = ¦e

−4jω

¦ ·

¸

¸

¸

¸

¸

(1 +ce

−4jω

)

∗

(1 +ce

−4jω

)

¸

¸

¸

¸

¸

= 1 · 1 = 1

To get the cascade form, we may factor the numerator and denominator using the identity:

1 +a

4

z

−4

= (1 −

√

2az

−1

+a

2

z

−2

)(1 +

√

2az

−1

+a

2

z

−2

)

Thus the numerator becomes:

1

16

+z

−4

=

1

16

(1 +2

4

z

−4

)=

1

16

(1 −2

√

2z

−1

+4z

−2

)(1 +2

√

2z

−1

+4z

−2

)

120

Noting that 1/16 = 0.0625, the transfer function is then:

H(z)=

0.0625 +z

−4

1 +0.0625z

−4

= 0.0625 ·

1 −2

√

2z

−1

+4z

−2

1 −0.5

√

2z

−1

+0.25z

−2

·

1 +2

√

2z

−1

+4z

−2

1 +0.5

√

2z

−1

+0.25z

−2

The direct and canonical realizations are shown in Fig. P7.18. Their sample processing algorithms

are:

for each input x do:

v

0

= x

y = w

0

= 0.0625v

0

+v

4

−0.0625w

4

delay(4, v)

delay(4, w)

for each input x do:

w

0

= x −0.0625w

4

y = 0.0625w

0

+w

4

delay(4, w)

x

y

z

-1

z

-1

z

-1

w

0

w

1

w

2

w

3

w

4

z

-1

x

y

z

-1

z

-1

v

0

v

1

v

2

v

3

v

4

z

-1

z

-1

w

0

w

1

w

2

w

4

z

-1

w

3

z

-1

z

-1

z

-1

-0.0625 -0.0625

0.0625 0.0625

Fig. P7.18 Direct and canonical realizations of Problem 7.12.

The cascade realization is shown in Fig. P7.19. Its sample processing algorithm is:

for each input x do:

v

0

= 0.0625x +0.5

√

2v

1

−0.25v

2

x

1

= v

0

−2

√

2v

1

+4v

2

delay(2, v)

w

0

= x

1

−0.5

√

2w

1

−0.25w

2

y = w

0

+2

√

2w

1

+4w

2

delay(2, w)

Finally, the impulse response may be obtained by writing:

H(z)=

c +z

−4

1 +cz

−4

= c +

(1 −c

2

)z

−4

1 +cz

−4

= c +(1 −c

2

)

_

z

−4

−cz

−8

+c

2

z

−12

−c

3

z

−16

+· · ·

_

Extracting the coefﬁcients of z

−1

, we ﬁnd:

h(n)=

⎧

⎪

⎪

⎪

⎪

⎪

⎨

⎪

⎪

⎪

⎪

⎪

⎩

c if n = 0

−(1 −c

2

)c

(n−4)/4

if n is an even multiple of 4

(1 −c

2

)c

(n−4)/4

if n is an odd multiple of 4

0 otherwise

121

x

0.0625

w

0

w

1

w

2

y

z

-1

z

-1

v

0

v

1

x

1

v

2

-0.25 4

-2 2 0.5 2

z

-1

z

-1

-0.25 4

2 2 -0.5 2

Fig. P7.19 Cascade realization of Problem 7.12.

Problem 7.13

The following program implements this computer experiment:

/* iirfilt.c - IIR filtering experiments */

#include <stdio.h>

#include <stdlib.h>

void cas2can();

double dir(), can(), cas();

void main()

{

int i, j, K, M;

double x, ydir, ycan, ycas;

double *vdir, *wdir, *wcan, **W;

double **A, **B, *a, *b;

FILE *fpx;

fpx = fopen("x.dat", "r"); /* input data */

printf("no. sections K = ");

scanf("%d", &K);

M=2*K;

wdir = (double *) calloc(M+1, sizeof(double));

vdir = (double *) calloc(M+1, sizeof(double));

wcan = (double *) calloc(M+1, sizeof(double));

a = (double *) calloc(M+1, sizeof(double));

b = (double *) calloc(M+1, sizeof(double));

A = (double **) calloc(K, sizeof(double *));

B = (double **) calloc(K, sizeof(double *));

W = (double **) calloc(K, sizeof(double *));

for (i=0; i<K; i++) {

A[i] = (double *) calloc(3, sizeof(double));

B[i] = (double *) calloc(3, sizeof(double));

W[i] = (double *) calloc(3, sizeof(double));

}

for(i=0; i<K; i++) {

122

printf("enter A[%d] = ", i);

for(j=0; j<3; j++)

scanf("%lf", A[i]+j);

}

for(i=0; i<K; i++) {

printf("enter B[%d] = ", i);

for(j=0; j<3; j++)

scanf("%lf", B[i]+j);

}

cas2can(K, A, a);

cas2can(K, B, b);

printf("\n\n");

while(fscanf(fpx, "%lf", &x) != EOF) {

ydir = dir(M, a, M, b, vdir, wdir, x);

ycan = can(M, a, M, b, wcan, x);

ycas = cas(K, A, B, W, x);

printf("% .6f % .6f % .6f % .6f\n", x, ydir, ycan, ycas);

}

printf("\n a, b = \n"); /* direct form coefficients */

for (i=0;i<=M;i++)

printf("% .6lf % .6lf\n", a[i], b[i]);

}

The program must be linked with the routines cas2can, dir, can, cas, and also conv required

by cas2can and sos required by cas. The number of sections K and the corresponding rows of

the matrices A and B are entered interactively. For example, the user input for the given transfer

functions will be (starting with K = 4):

4

1 -0.373 0

1 -1.122 0.712

1 -0.891 0.360

1 -0.780 0.190

0.313 0.313 0

0.147 0.294 0.147

0.117 0.234 0.117

0.103 0.206 0.103

These inputs may also be saved in a ﬁle, say, input.dat, and piped into the program by

iirfilt < input.dat

The input signal x

n

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:

123

x(n) y

dir

(n) y

can

(n) y

cas

(n)

1.000000 0.000554 0.000554 0.000554

1.000000 0.006191 0.006191 0.006191

1.000000 0.032979 0.032979 0.032979

1.000000 0.112201 0.112201 0.112201

1.000000 0.275606 0.275606 0.275606

1.000000 0.524036 0.524036 0.524036

1.000000 0.807624 0.807624 0.807624

1.000000 1.043772 1.043772 1.043772

1.000000 1.164600 1.164600 1.164600

1.000000 1.157457 1.157457 1.157457

The outputs computed by dir, can, and cas are of course the same. Fig. P7.20 shows the full

output, plotted together with the input. The impulse response h(n), 0 ≤ n < 50 can be computed

by running this program on a ﬁ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) h

dir

(n) h

can

(n) h

cas

(n)

1.000000 0.000554 0.000554 0.000554

0.000000 0.005637 0.005637 0.005637

0.000000 0.026788 0.026788 0.026788

0.000000 0.079222 0.079222 0.079222

0.000000 0.163405 0.163405 0.163405

0.000000 0.248430 0.248430 0.248430

0.000000 0.283588 0.283588 0.283588

0.000000 0.236148 0.236148 0.236148

0.000000 0.120828 0.120828 0.120828

0.000000 −0.007142 −0.007142 −0.007142

The given ﬁ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 coefﬁcients:

a b

1.000000 0.000554

−3.166000 0.003881

4.873631 0.011644

−4.465987 0.019407

2.592519 0.019407

−0.941724 0.011644

0.196860 0.003881

−0.018165 0.000554

0.000000 0.000000

124

Fig. P7.20 Input, output, and impulse response of Problem 7.13.

Problem 7.14

An example of such program is given below. It is patterned after firfilt.c of Problem 4.10.

The program reads and allocates the ﬁlter coefﬁcient 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 initial allocation size

double can();

void main(int argc, char **argv)

{

FILE *fpa, *fpb; coefﬁcient ﬁles

double *a, *b, *w, x, y; coeffs., state, input, output

int L, M, K, i;

int max = MAX, dmax = MAX; initial allocation and increment

if (argc != 3) {

fprintf(stderr, "Usage: canfilt a.dat b.dat <x.dat >y.dat\n");

exit(0);

}

if ((fpa = fopen(argv[1], "r")) == NULL) {

fprintf(stderr, "Can’t open filter file: %s\n", argv[1]);

exit(0);

}

if ((fpb = fopen(argv[2], "r")) == NULL) {

fprintf(stderr, "Can’t open filter file: %s\n", argv[2]);

exit(0);

}

a = (double *) calloc(max + 1, sizeof(double));

for (M=0;; M++) {

if (M == max) {

125

max += dmax;

a = (double *) realloc((char *) a, (max + 1) * sizeof(double));

}

if (fscanf(fpa, "%lf", a + M) == EOF) break;

}

M--;

a = (double *) realloc((char *) a, (M + 1) * sizeof(double));

b = (double *) calloc(max + 1, sizeof(double));

for (L=0;; L++) {

if (L == max) {

max += dmax;

b = (double *) realloc((char *) b, (max + 1) * sizeof(double));

}

if (fscanf(fpb, "%lf", b + L) == EOF) break;

}

L--;

b = (double *) realloc((char *) b, (L + 1) * sizeof(double));

K = (L <= M) ? M : L;

w = (double *) calloc((K + 1), sizeof(double));

while(scanf("%lf", &x) != EOF) { process input samples

y = can(M, a, L, b, w, x);

printf("%lf\n", y);

}

}

Problem 7.15

An example of such programis given below. The programreads and allocates the ﬁlter coefﬁcient

matrices A and B. To facilitate the initial allocation of A, a temporary array a is used to read the

rows of A.dat in a concatenated form, and then it reshapes it into the K×3 matrix A. The last

while loop performs the actual ﬁltering:

/* casfilt.c - IIR filtering in cascade form */

#include <stdlib.h>

#include <stdio.h>

#define MAX 64 initial allocation size

double cas();

void main(int argc, char **argv)

{

FILE *fpa, *fpb; coefﬁcient ﬁles

double **A, **B, **W, x, y;

double *a; temporary coefﬁcient array

int M, K, i, j, m;

int max = MAX, dmax = MAX; allocation and increment

if (argc != 3) {

fprintf(stderr, "Usage: casfilt A.dat B.dat <x.dat >y.dat\n");

exit(0);

}

126

if ((fpa = fopen(argv[1], "r")) == NULL) {

fprintf(stderr, "Can’t open filter file: %s\n", argv[1]);

exit(0);

}

if ((fpb = fopen(argv[2], "r")) == NULL) {

fprintf(stderr, "Can’t open filter file: %s\n", argv[2]);

exit(0);

}

a = (double *) calloc(max + 1, sizeof(double));

for (M=0;; M++) {

if (M == max) {

max += dmax;

a = (double *) realloc((char *) a, (max + 1) * sizeof(double));

}

if (fscanf(fpa, "%lf", a + M) == EOF) break;

}

a = (double *) realloc((char *) a, (M + 1) * sizeof(double));

if (M%3 != 0) {

fprintf(stderr, "all rows of A must be 3-dimensional");

exit(0);

}

else

K = M / 3;

A = (double **) calloc(K, sizeof(double *));

B = (double **) calloc(K, sizeof(double *));

W = (double **) calloc(K, sizeof(double *));

for (i=0; i<K; i++) {

A[i] = (double *) calloc(3, sizeof(double));

B[i] = (double *) calloc(3, sizeof(double));

W[i] = (double *) calloc(3, sizeof(double));

}

for(i=0; i<K; i++)

for(j=0; j<3; j++)

A[i][j] = a[3*i + j];

for(i=0; i<K; i++)

for(j=0; j<3; j++)

fscanf(fpb, "%lf", B[i] + j);

while(scanf("%lf", &x) != EOF) { process input samples

y = cas(K, A, B, W, x);

printf("%lf\n", y);

}

}

The MATLAB version casfilt.m is given below. It calls cas.m N times, where N is the input

length:

% casfilt.m - IIR filtering in cascade form

%

% y = casﬁlt(B, A, x);

%

127

% B = Kx3 numerator matrix (K = number of sections)

% A = Kx3 denominator matrix

% x = row vector input

% y = row vector output

function y = casfilt(B, A, x)

[K, K1] = size(A);

[N1, N] = size(x);

W = zeros(K,3);

for n = 1:N,

[y(n), W] = cas(K, B, A, W, x(n));

end

Problem 7.16

The two ﬁlters are:

H

1

(z)= 0.70849 ·

1 +z

−8

1 −0.0625z

−8

, H

2

(z)= 0.98021 ·

1 +z

−8

1 +0.94z

−8

·

1 −0.96z

−8

1 −0.98z

−8

The scale factors, were chosen such that the magnitude responses are unity at ω= ω

0

= 0.5π/8,

that is,

¦H

1

(ω

0

)¦ = ¦H

2

(ω

0

)¦ = 1

The following programimplements this computer experiment. The sample processing algorithms

of Examples 7.4.3 and 7.4.4 remain the same, except the input sample x gets multiplied by the

corresponding normalization gains:

/* combex.c - comb filtering examples */

#include <stdio.h>

#include <stdlib.h>

#include <math.h>

#define A0 1.0

#define A1 0.5

#define A2 0.5

#define A3 0.5

#define G1 0.70849

#define G2 0.98021

void delay();

void main()

{

int n, N;

double s, x, y1, x1, y2;

double *w, *v, *u;

double pi = 4*atan(1.0), w0, w1, w2, w3;

FILE *fps, *fpx, *fpy1, *fpy2;

fps = fopen("s.dat", "w");

128

fpx = fopen("x.dat", "w");

fpy1 = fopen("y1.dat", "w");

fpy2 = fopen("y2.dat", "w");

w = (double *) calloc(9, sizeof(double)); /* filter 1 */

u = (double *) calloc(9, sizeof(double)); /* filter 2, section 1 */

v = (double *) calloc(9, sizeof(double)); /* filter 2, section 2 */

w0 = 0.50 * pi / 8;

w1 = 0.75 * pi / 8;

w2 = 1.00 * pi / 8;

w3 = 3.00 * pi / 8;

printf("enter input length N = ");

scanf("%d", &N);

for (n=0; n<N; n++) {

s = A0 * cos(w0*n) + A1 * cos(w1*n);

x = s + A2 * cos(w2*n) + A3 * cos(w3*n);

w[0] = G1 * x + 0.0625 * w[8]; /* filter 1 */

y1 = w[0] + w[8];

delay(8, w);

u[0] = G2 * x - 0.94 * u[8]; /* filter 2 */

x1 = u[0] + u[8]; /* section 1 output */

delay(8, u);

v[0] = x1 + 0.98 * v[8];

y2 = v[0] - 0.96 * v[8]; /* section 2 output */

delay(8, v);

fprintf(fps, "%.8lf\n", s);

fprintf(fpx, "%.8lf\n", x);

fprintf(fpy1, "%.8lf\n", y1);

fprintf(fpy2, "%.8lf\n", y2);

}

}

Fig. P7.21 shows the desired, noise-free, signal s(n) and the noisy signal x(n), which serves as

the input to the comb ﬁlters. The corresponding output signals y

1

(n) and y

2

(n) from H

1

(z)

and H

2

(z) are shown in Fig. P7.22.

The ﬁ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.

Problem 7.17

Performing a partial fraction expansion on H

1

(z) and H

2

(z), we ﬁnd (where the PFE coefﬁcients

are given with 5-digit accuracy):

H

1

(z) = −11.33584 +

12.04433

1 −0.0625z

−8

H

2

(z) = 1.02150 −

0.06191

1 +0.94z

−8

+

0.02063

1 −0.98z

−8

Expanding in powers of z

−8

and extracting coefﬁcients, we ﬁnd the impulse responses, for 0 ≤

n ≤ 16:

129

Fig. P7.21 Desired and noisy inputs of Problem 7.16.

Fig. P7.22 Outputs of comb ﬁlters 1 and 2 of Problem 7.16.

n h

1

(n) h

2

(n)

0 0.70849 0.98021

1 0 0

2 0 0

3 0 0

4 0 0

5 0 0

6 0 0

7 0 0

8 0.75277 0.07841

9 0 0

10 0 0

11 0 0

12 0 0

13 0 0

14 0 0

15 0 0

16 0.04705 −0.03489

130

The impulse responses of the two ﬁ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

Fig. P7.23 Impulse responses of comb ﬁlters 1 and 2 of Problem 7.17.

Problem 7.18

The following program replaces iirfilt.c of Problem 7.13. For comparison, dir.c is left in the

program as before.

/* iirfilt.c - IIR filtering experiments - circular buffer versions */

#include <stdio.h>

#include <stdlib.h>

void cas2can();

double dir(), ccan(), ccas();

void main()

{

int i, j, K, M;

double x, ydir, ycan, ycas;

double *vdir, *wdir, *wcan, **W;

double **A, **B, *a, *b;

double *p, **P; /* circular pointers */

FILE *fpx;

fpx = fopen("x.dat", "r");

printf("no. sections K = ");

scanf("%d", &K);

M=2*K;

wdir = (double *) calloc(M+1, sizeof(double));

vdir = (double *) calloc(M+1, sizeof(double));

wcan = (double *) calloc(M+1, sizeof(double));

p = wcan; /* initialize */

131

a = (double *) calloc(M+1, sizeof(double));

b = (double *) calloc(M+1, sizeof(double));

A = (double **) calloc(K, sizeof(double *));

B = (double **) calloc(K, sizeof(double *));

W = (double **) calloc(K, sizeof(double *));

P = (double **) calloc(K, sizeof(double *)); /* allocate */

for (i=0; i<K; i++) {

A[i] = (double *) calloc(3, sizeof(double));

B[i] = (double *) calloc(3, sizeof(double));

W[i] = (double *) calloc(3, sizeof(double));

P[i] = W[i]; /* initialize */

}

for(i=0; i<K; i++) {

printf("enter A[%d] = ", i);

for(j=0; j<3; j++)

scanf("%lf", A[i]+j);

}

for(i=0; i<K; i++) {

printf("enter B[%d] = ", i);

for(j=0; j<3; j++)

scanf("%lf", B[i]+j);

}

cas2can(K, A, a);

cas2can(K, B, b);

printf("\n\n");

while(fscanf(fpx, "%lf", &x) != EOF) {

ydir = dir(M, a, M, b, vdir, wdir, x);

ycan = ccan(M, a, b, wcan, &p, x);

ycas = ccas(K, A, B, W, P, x);

printf("% .6f % .6f % .6f % .6f\n", x, ydir, ycan, ycas);

}

printf("a, b = \n");

for (i=0;i<=M;i++)

printf("% .6lf % .6lf\n", a[i], b[i]);

}

One minor difference in ccan is that it assumes the same order M for both vectors a and b;

Therefore its usage is:

ycan = ccan(M, a, b, wcan, &p, x);

whereas the usage of can was:

ycan = can(M, a, M, b, wcan, x);

Problem 7.19

The canonical realization is shown in Fig. P7.24.

The linear and circular buffer versions of the sample processing algorithm are as follows:

132

x

0.5 -2

6

y

z

-3

s

3

w

3

s

0

w

0

Fig. P7.24 Canonical realization of Problem 7.19.

for each input x do:

w

0

= x +0.5w

3

y = 6w

0

−2w

3

delay(3, w)

for each input x do:

s

3

= tap(3, w, p, 3)

s

0

= x +0.5s

3

y = 6s

0

−2s

3

∗p = s

0

cdelay(3, w, &p)

The impulse response can be obtained by dividing out the numerator and writing

H(z)=

6 −2z

−3

1 −0.5z

−3

= 4 +

2

1 −0.5z

−3

Expanding in powers of z

−3

, we have:

H(z)= 4 +2

_

1 +(0.5)z

−3

+(0.5)

2

z

−6

+(0.5)

3

z

−9

+· · ·

_

which gives the impulse response:

h =

_

6, 0, 0, 2(0.5), 0, 0, 2(0.5)

2

, 0, 0, 2(0.5)

3

, 0, 0, . . .

_

= [6, 0, 0, 1, 0, 0, 0.5, . . . ]

n x w

0

w

1

w

2

w

3

s

0

s

1

s

2

s

3

y = 6s

0

−2s

3

0 1 1 0 0 0 1 0 0 0 6

1 0 1 0 0 0 0 1 0 0 0

2 0 1 0 0 0 0 0 1 0 0

3 0 1 0.5 0 0 0.5 0 0 1 1

4 0 0 0.5 0 0 0 0.5 0 0 0

5 0 0 0.5 0 0 0 0 0.5 0 0

6 0 0 0.5 0.5

2

0 0.5

2

0 0 0.5 0.5

The states s

i

represent the delay-line outputs:

s(n)=

⎡

⎢

⎢

⎢

⎣

s

0

(n)

s

1

(n)

s

2

(n)

s

3

(n)

⎤

⎥

⎥

⎥

⎦

=

⎡

⎢

⎢

⎢

⎣

w(n)

w(n −1)

w(n −2)

w(n −3)

⎤

⎥

⎥

⎥

⎦

that is, they are the successively delayed versions of w(n), which is the intermediate signal

obtained at the output of the input adder. It has z-transform:

W(z)=

1

D(z)

X(z)=

1

1 −0.5z

−3

X(z)

133

For a delta-function input, we have X(z)= 1, giving:

W(z)=

1

1 −0.5z

−3

= 1 +(0.5)z

−3

+(0.5)

2

z

−6

+(0.5)

3

z

−9

+· · ·

and in the time domain:

w(n)= [1, 0, 0, 0.5, 0, 0, 0.5

2

, 0, 0, . . . ]

For the input x = [1, 2, 3], we have:

n x w

0

w

1

w

2

w

3

s

0

s

1

s

2

s

3

y = 6s

0

−2s

3

0 1 1 0 0 0 1 0 0 0 6

1 2 1 0 0 2 2 1 0 0 12

2 3 1 0 3 2 3 2 1 0 18

3 0 1 0.5 3 2 0.5 3 2 1 1

4 0 1 0.5 3 2 1 0.5 3 2 2

5 0 1 0.5 3 1.5 1.5 1 0.5 3 3

6 0 1 0.5 0.25 1.5 0.25 1.5 1 0.5 0.5

Problem 7.20

The full precision direct form denominator is:

a = [1, a

1

, a

2

, a

3

, a

4

]= [1, −3.502, 5.024, −3.464, 0.979] (P7.1)

The full precision cascade coefﬁcients are:

a

0

= [1, a

01

, a

02

]= [1, −1.8955, 0.9930]

a

1

= [1, a

11

, a

12

]= [1, −1.6065, 0.9859]

(P7.2)

The poles are at:

p

0

= R

0

e

jω0

, R

0

= 0.9965, ω

0

= 0.1π

p

1

= R

1

e

jω1

, R

1

= 0.9929, ω

1

= 0.2π

(P7.3)

If we round the direct form coefﬁcient vector a to 2-digit accuracy, we obtain:

ˆa = [1, ˆ a

1

, ˆ a

2

, ˆ a

3

, ˆ a

4

]= [1, −3.50, 5.02, −3.46, 0.98] (P7.4)

and the corresponding direct form transfer function:

ˆ

H

dir

(z)=

1

1 + ˆ a

1

z

−1

+ ˆ a

2

z

−2

+ ˆ a

3

z

−3

+ ˆ a

4

z

−4

(P7.5)

This ﬁlter is unstable. Indeed, its four poles, the roots of the denominator polynomial, are:

ˆ p

0

=

ˆ

R

0

e

j ˆ ω0

,

ˆ

R

0

= 1.0045, ˆ ω

0

= 0.1045π

ˆ p

1

=

ˆ

R

1

e

j ˆ ω1

,

ˆ

R

1

= 0.9860, ˆ ω

1

= 0.1989π

(P7.6)

and their conjugates. Thus, the p

0

pole has moved outside the unit circle, rendering the ﬁ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.

134

Fig. P7.25 Full and 2-digit precision ﬁlters.

The cascade realization, on the other hand, is more robust, in the sense that if we round its coefﬁ-

cients also to 2-digit accuracy, the ﬁlter will remain stable. Indeed, rounding the SOS coefﬁcients

(P7.2) to 2-digits gives:

ˆa

0

= [1, ˆ a

01

, ˆ a

02

]= [1, −1.90, 0.99]

ˆa

1

= [1, ˆ a

11

, ˆ a

12

]= [1, −1.61, 0.99]

(P7.7)

The roots of these sections are:

ˆ p

0

=

ˆ

R

0

e

j ˆ ω0

,

ˆ

R

0

= 0.9950 ˆ ω

0

= 0.0961π

ˆ p

1

=

ˆ

R

1

e

j ˆ ω1

,

ˆ

R

1

= 0.9950, ˆ ω

1

= 0.2000π

(P7.8)

and their conjugates. They are both inside the unit circle, therefore, the ﬁlter remains stable. The

corresponding cascade transfer function will be:

ˆ

H

cas

(z)=

1

1 + ˆ a

01

z

−1

+ ˆ a

02

z

−2

·

1

1 + ˆ a

11

z

−1

+ ˆ a

12

z

−2

(P7.9)

The ﬁlters

ˆ

H

dir

(z) and

ˆ

H

cas

(z) are not equal. Rounding the cascade coefﬁcients to 2-digit ac-

curacy is not equivalent to rounding the direct form coefﬁcients, because rounding does not

preserve products—the rounded product of two numbers is not equal to the product of the two

rounded numbers. Therefore, rounding does not preserve convolution, that is,

ˆa = a

0

∗a

1

≠ ˆa

0

∗ˆa

1

Indeed, carrying out the convolution of the two vectors in Eq. (P7.7) gives the following direct

form vector, which is not quite the same as that given by Eq. (P7.4):

ˆa

0

∗ˆa

1

= [1, −3.5100, 5.0390, −3.4749, 0.9801]

The impulse response and the magnitude response of the cascaded ﬁlter (P7.9) are shown in

Fig. P7.26, together with the exact magnitude response. The magnitude responses are plotted in

dB, that is, 20log

10

¦H(ω)¦, over 0 ≤ ω ≤ 0.5π, which is the right half of the Nyquist interval.

Thus, in the cascade case the rounding operation changed the magnitude response somewhat,

but has not affected the stability of the ﬁlter.

The sensitivity of the direct form and the robustness of the cascade form can be understood ana-

lytically in the following way. The zeros of a polynomial are indirect functions of the coefﬁcients

135

Fig. P7.26 Impulse and magnitude responses of 2-digit-precision cascade form.

of the polynomial, therefore, small changes in the latter will induce changes in the former. For the

direct form, the induced changes in the zeros can be large, thus, causing them to move outside

the unit circle. In the cascade form, the induced changes remain small. For example, consider

the above fourth order denominator vector a. The relationship of the zeros to the coefﬁcients is

established via the polynomial identity:

(1 −p

0

z

−1

)(1 −p

∗

0

z

−1

)(1 −p

1

z

−1

)(1 −p

∗

1

z

−1

)= 1 +a

1

z

−1

+a

2

z

−2

+a

3

z

−3

+a

4

z

−4

A small change in the coefﬁcients will induce a small change in the zeros p

0

and p

1

, that is,

a →a +da ⇒ p

i

→p

i

+dp

i

, i = 0, 1

To determine dp

0

and dp

1

in terms of da, we take differentials of both sides of the above poly-

nomial identity to get:

−dp

0

z

−1

(1 −p

∗

0

z

−1

)(1 −p

1

z

−1

)(1 −p

∗

1

z

−1

)

−(1 −p

0

z

−1

)dp

∗

0

z

−1

(1 −p

1

z

−1

)(1 −p

∗

1

z

−1

)

−(1 −p

0

z

−1

)(1 −p

∗

0

z

−1

)dp

1

z

−1

(1 −p

∗

1

z

−1

)

−(1 −p

0

z

−1

)(1 −p

∗

0

z

−1

)(1 −p

1

z

−1

)dp

∗

1

z

−1

= da

1

z

−1

+da

2

z

−2

+da

3

z

−3

+da

4

z

−4

which is still an identity in z. Setting z = p

0

will remove all but the ﬁrst termin the left-hand-side,

giving the relationship:

−dp

0

p

−1

0

(1 −p

∗

0

p

−1

0

)(1 −p

1

p

−1

0

)(1 −p

∗

1

p

−1

0

)= da

1

p

−1

0

+da

2

p

−2

0

+da

3

p

−3

0

+da

4

p

−4

0

Multiplying by p

4

0

and solving for dp

0

, we obtain

dp

0

= −

p

3

0

da

1

+p

2

0

da

2

+p

0

da

3

+da

4

(p

0

−p

∗

0

)(p

0

−p

1

)(p

0

−p

∗

1

)

(P7.10)

Similarly, setting z = p

1

, we ﬁnd for dp

1

:

dp

1

= −

p

3

1

da

1

+p

2

1

da

2

+p

1

da

3

+da

4

(p

1

−p

∗

0

)(p

1

−p

0

)(p

1

−p

∗

1

)

(P7.11)

136

Because, the denominator involves the differences between poles, that is, the distances from all

the other poles, it follows that if the poles are closely clustered, the induced changes in the poles

dp

i

will be large even if the coefﬁcient changes da

i

are small. The above sensitivity formulas

generalize easily [2,3,246] to the case of an order-M ﬁlter a = [1, a

1

, a

2

, . . . , a

M

] with M zeros

p

1

, p

2

, . . . , p

M

:

dp

i

=

∂p

i

∂a

1

da

1

+

∂p

i

∂a

2

da

2

+· · · +

∂p

i

∂a

M

da

M

where the partial derivatives are:

∂p

i

∂a

m

= −

p

M−m

i

M

j=1

j≠i

(p

i

−p

j

)

(P7.12)

In the cascade realization, p

0

is associated with the ﬁrst SOS and p

1

with the second. The depen-

dence of p

0

on a

0

and p

1

on a

1

is established through the identities

(1 −p

0

z

−1

)(1 −p

∗

0

z

−1

) = 1 +a

01

z

−1

+a

02

z

−2

(1 −p

1

z

−1

)(1 −p

∗

1

z

−1

) = 1 +a

11

z

−1

+a

12

z

−2

Using the above procedure of taking differentials of both sides and setting z = p

0

in the ﬁrst and

z = p

1

in the second, we obtain the induced changes in the poles due to small changes in the

coefﬁcients of the sections:

dp

0

= −

p

0

da

01

+da

02

(p

0

−p

∗

0

)

, dp

1

= −

p

1

da

11

+da

12

(p

1

−p

∗

1

)

(P7.13)

The sensitivity of each pole depends only on the SOS it belongs to, not on the other sections. In

Eqs. (P7.10) and (P7.11), the sensitivity of each pole is coupled to the other poles, through the

denominator factors of the form (p

0

−p

1

); if p

0

is near p

1

, such factors cause large shifts in the

pole locations.

Even though the sensitivity formulas (P7.10) and (P7.11) involve differential changes, we may

actually apply themto the above example and estimate the pole shifts for the 2-digit case. Writing

the rounded ˆa of Eq. (P7.4) in the form ˆa = a +da, we obtain subtracting (P7.4) and (P7.1):

da = ˆa −a = [0, da

1

, da

2

, da

3

, da

4

]= [0, 0.002, −0.004, 0.004, 0.001]

Using the numerical values given in Eq. (P7.3), we have

p

0

= 0.9965e

j0.1π

= 0.9477 +j0.3079

p

1

= 0.9929e

j0.2π

= 0.8033 +j0.5836

With these values of the poles and da

i

, we can calculate the pole shifts using (P7.10) and (P7.11).

We ﬁnd:

dp

0

= 0.0023 +j0.0159, dp

1

= −0.0033 −j0.0066

Therefore, the new pole locations will be:

ˆ p

0

= p

0

+dp

0

= 0.9501 +j0.3238 = 1.0037e

j0.1046π

ˆ p

1

= p

1

+dp

1

= 0.7999 +j0.5770 = 0.9863e

j0.1989π

which compare well with the actual values of Eq. (P7.6). A similar calculation can be made based

on Eq. (P7.13).

137

Problem 7.21

The numerical values of a are shown in the ﬁ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 ˆa ˆa

cas

1.00000000 1.00000000 1.00000000 1.00000000

−5.56573395 −5.56573000 −5.56570000 −5.56570000

13.05062482 13.05062000 13.05060000 13.05046030

−16.49540451 −16.49540000 −16.49540000 −16.49508213

11.84993647 11.84994000 11.84990000 11.84961490

−4.58649943 −4.58650000 −4.58650000 −4.58633537

0.74713457 0.74713000 0.74710000 0.74710016

relative error 3.2580×10

−7

1.6487×10

−6

1.9240×10

−5

Table P7.1 Exact, 5-digit, and 4-digit coefﬁcients.

The fourth column of Table P7.1 shows the equivalent direct-form coefﬁcient vector ˆa

cas

arising

from the cascade of the quantized second order section coefﬁcients, rounded to 4-digit accuracy.

The rounded a

i

are:

ˆa

0

= [1, −1.8671, 0.9623]

ˆa

1

= [1, −1.8468, 0.8992]

ˆa

2

= [1, −1.8518, 0.8634]

(P7.14)

The table also shows the relative error in each case, deﬁned as the ratio

relative error =

|da|

|a|

=

|ˆa −a|

|a|

where |a| denotes the length of the vector a. As expected, the error in the 5-digit case is less than

that in the 4-digit case. But, the error of the cascade case is larger. However, as we see below, the

4-digit cascade form gives an adequate approximation of the exact ﬁ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 denomi-

nator polynomials a, 5- and 4-digit ˆa, and of the rounded SOS polynomials ˆa

0

, ˆa

1

, and ˆa

2

.

For the 5-digit direct form, the ﬁ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 coefﬁcients ˆa correspond

to an unstable ﬁlter. By contrast, the roots of the 4-digit quantized cascaded form ˆa

cas

remain

inside the unit circle, and in fact they are practically equal to the unquantized ones. Figure P7.27

shows the impulse responses of the exact ﬁ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 ˆa

cas

are shown

in Fig. P7.28. The magnitude responses of the full precision, 5-digit direct, and 4-digit cascade

cases are shown in Fig. P7.29. Note that the 5-digit direct no longer meets the passband specs; it

has a passband ripple of almost 2 dB instead of the required 1 dB. The 4-digit cascade response,

on the other hand, meets the speciﬁcations.

138

full precision magnitude

0.933557 :j0.301259 0.980962

0.923398 :j0.215739 0.948265

0.925911 :j0.078311 0.929217

5-digit direct magnitude

0.931610 :j0.300414 0.978849

0.927787 :j0.216576 0.952730

0.923469 :j0.079185 0.926857

4-digit direct magnitude

0.967208 :j0.284105 1.008071

0.888774 :j0.266869 0.927976

0.999999 0.999999

0.853736 0.853736

4-digit cascade magnitude

0.933552 :j0.301303 0.980971

0.923396 :j0.215719 0.948258

0.925902 :j0.078152 0.929194

Table P7.2 Filter poles.

Fig. P7.27 Impulse responses of full-precision and 4-digit-precision ﬁ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

Fig. P7.28 Impulse responses of 5-digit direct and 4-digit cascade ﬁlters. Problem 7.21.

Fig. P7.29 Magnitude responses of exact, 5-digit direct, and 4-digit cascade. Problem 7.21.

Problem 7.24

The transfer function is:

H(z)=

b

0

+b

1

z

−1

+b

2

z

−2

+b

3

z

−3

1 +a

1

z

−1

+a

2

z

−2

+a

3

z

−3

(P7.15)

Transposed realizations of FIR ﬁ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.

The I/O difference equations describing the time-domain operation of the realization and the

corresponding sample processing algorithm can be obtained by introducing as internal states the

contents of the three delay registers at time n: v

1

(n), v

2

(n), v

3

(n). For indexing convenience,

we also introduce the quantity v

0

(n) which is the overall output obtained at the top adder, that

is,

v

0

(n)= y(n)= b

0

x(n)+v

1

(n)

The output of each delay is the delayed version of the output of the adder below it, for example,

v

1

(n)= b

1

x(n −1)−a

1

v

0

(n −1)+v

2

(n −1)= b

1

x(n −1)−a

1

y(n −1)+v

2

(n −1)

140

or, advancing it to the next time instant:

v

1

(n +1)= b

1

x(n)−a

1

v

0

(n)+v

2

(n)= b

1

x(n)−a

1

y(n)+v

2

(n)

Therefore, the overall I/O system, which includes the updating of the internal states, will be:

y(n)= v

0

(n)= b

0

x(n)+v

1

(n)

v

1

(n +1)= b

1

x(n)−a

1

y(n)+v

2

(n)

v

2

(n +1)= b

2

x(n)−a

2

y(n)+v

3

(n)

v

3

(n +1)= b

3

x(n)−a

3

y(n)

(P7.16)

which leads to the sample processing algorithm:

for each input sample x do:

y = v

0

= b

0

x +v

1

v

1

= b

1

x −a

1

y +v

2

v

2

= b

2

x −a

2

y +v

3

v

3

= b

3

x −a

3

y

Problem 7.25

In the case of a general transfer function of the type of Eq. (7.1.4), we have the sample processing

algorithm, where we assumed L = M for simplicity:

for each input sample x do:

y = v

0

= b

0

x +v

1

for i = 1, 2, . . . , M−1 do:

v

i

= b

i

x −a

i

v

0

+v

i+1

v

M

= b

M

x −a

M

v

0

(P7.17)

The following C function transp.c is an implementation.

/* transp.c - IIR filtering in transposed of canonical form */

double transp(M, a, b, v, x) usage: y = transp(M, a, b, v, x);

double *a, *b, *v, x; v = internal state vector

int M; a,b have same order M

{

int i;

v[0] = b[0] * x + v[1]; output y(n)= v

0

(n)

for (i=1; i<=M-1; i++) state updating

v[i] = b[i] * x - a[i] * v[0] + v[i+1];

v[M] = b[M] * x - a[M] * v[0];

return v[0];

}

Its usage is the same as that of can or dir. The (M+1)-dimensional array v = [v

0

, v

1

, . . . , v

M

]

must be declared and allocated in the main program, for example, by

141

double *v;

v = (double *) calloc(M+1, sizeof(double));

Transposed realizations are not intuitively obvious, but their overall implementation in terms of

Eq. (P7.17) has a certain simplicity and elegance. It corresponds to writing the transfer function

of the ﬁlter in a nested form, which is similar to H¨orner’s rule of evaluating a polynomial. For

example, the transfer function (P7.15) can be written as:

H(z)= −(a

1

z

−1

+a

2

z

−2

+a

3

z

−3

)H(z)+b

0

+b

1

z

−1

+b

2

z

−2

+b

3

z

−3

which can be written in the nested form:

H = b

0

+z

−1

_

(b

1

−a

1

H)+z

−1

_

(b

2

−a

2

H)+z

−1

(b

3

−a

3

H)

_

_

Multiplying both sides by the z-transform X(z) of the input x(n), and using Y(z)= H(z)X(z),

we obtain the following nested form for the computation of the output, which is basically the

transposed form:

Y = b

0

X +z

−1

_

(b

1

X −a

1

Y)+z

−1

_

(b

2

X −a

2

Y)+z

−1

(b

3

X −a

3

Y)

_

_

The transposed formcan also be used in the cascade realization, where each second order section

will be realized in its transposed form. The sample processing algorithm of a 2nd order section

is simply:

for each input sample x do:

y = v

0

= b

0

x +v

1

v

1

= b

1

x −a

1

y +v

2

v

2

= b

2

x −a

2

y

which can replace Eq. (7.2.2).

Problem 7.26

The following programimplements ﬁ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 initial allocation size

double transp();

void main(int argc, char **argv)

{

FILE *fpa, *fpb; coefﬁcient ﬁles

double *a, *b, *v, x, y; coeffs., state, input, output

int M, L, i;

int max = MAX, dmax = MAX; initial allocation and increment

if (argc != 3) {

142

fprintf(stderr, "Usage: trspfilt a.dat b.dat <x.dat >y.dat\n");

fprintf(stderr, "coefficient vectors a,b must have same length");

exit(0);

}

if ((fpa = fopen(argv[1], "r")) == NULL) {

fprintf(stderr, "Can’t open filter file: %s\n", argv[1]);

exit(0);

}

if ((fpb = fopen(argv[2], "r")) == NULL) {

fprintf(stderr, "Can’t open filter file: %s\n", argv[2]);

exit(0);

}

a = (double *) calloc(max + 1, sizeof(double));

for (M=0;; M++) {

if (M == max) {

max += dmax;

a = (double *) realloc((char *) a, (max + 1) * sizeof(double));

}

if (fscanf(fpa, "%lf", a + M) == EOF) break;

}

M--;

a = (double *) realloc((char *) a, (M + 1) * sizeof(double));

b = (double *) calloc(max + 1, sizeof(double));

for (L=0;; L++) {

if (L == max) {

max += dmax;

b = (double *) realloc((char *) b, (max + 1) * sizeof(double));

}

if (fscanf(fpb, "%lf", b + L) == EOF) break;

}

L--;

b = (double *) realloc((char *) b, (L + 1) * sizeof(double));

if (M != L) {

fprintf(stderr, "coefficient vectors a,b must have same length");

exit(0);

}

v = (double *) calloc(M + 1, sizeof(double));

while(scanf("%lf", &x) != EOF) { process input samples

y = transp(M, a, b, v, x);

printf("%lf\n", y);

}

}

Problem 7.27

The transfer function is:

H(z)=

9 −4z

−2

+4z

−4

1 +0.84z

−2

+0.25z

−4

=

3 −4z

−1

+2z

−2

1 −0.4z

−1

+0.5z

−2

·

3 +4z

−1

+2z

−2

1 +0.4z

−1

+0.5z

−2

The transpose of the canonical form is shown in Fig. P7.30. The I/O difference equations are:

143

y(n)= 9x(n)+v

1

(n)

v

1

(n +1)= v

2

(n)

v

2

(n +1)= −4x(n)−0.84y(n)+v

3

(n)

v

3

(n +1)= v

4

(n)

v

4

(n +1)= 4x(n)−0.25y(n)

and the corresponding sample processing algorithm:

for each input sample x do:

y = 9x +v

1

v

1

= v

2

v

2

= −4x −0.84y +v

3

v

3

= v

4

v

4

= 4x −0.25y

The cascade form with both 2nd order sections realized in their transposed form is shown in

Fig. P7.31. The I/O difference equations are in this case:

x

1

(n)= 3x(n)+v

01

(n)

v

01

(n +1)= −4x(n)+0.4x

1

(n)+v

02

(n)

v

02

(n +1)= 2x(n)−0.5x

1

(n)

y(n)= 3x

1

(n)+v

11

(n)

v

11

(n +1)= 4x

1

(n)−0.4y(n)+v

12

(n)

v

12

(n +1)= 2x

1

(n)−0.5y(n)

The sample processing algorithm will be:

for each input sample x do:

x

1

= 3x +v

01

v

01

= −4x +0.4x

1

+v

02

v

02

= 2x −0.5x

1

y = 3x

1

+v

11

v

11

= 4x

1

−0.4y +v

12

v

12

= 2x

1

−0.5y

Problem 7.28

The overall, closed-loop, transfer function of the feedback system can be worked out easily using

z-transforms. The general approach to analyzing this, and any other, block diagram is to assign

names to all signal lines that do not already have names and then set up the various adder and

ﬁltering equations.

Consider case A, with signal names assigned as in Fig. P7.32 Then, the adder and ﬁltering equa-

tions are in the time and z domains:

144

v

1

(n)

v

0

(n)

z

-1

x(n)

9

-0.84

-0.25

-4

4

y(n)

v

2

(n)

z

-1

v

3

(n)

z

-1

v

4

(n)

z

-1

Fig. P7.30 Transposed of canonical form.

x(n) x

1

(n)

v

01

(n)

v

00

(n)

v

02

(n)

z

-1

z

-1

3

0.4

-0.5

-4

2

y(n)

v

11

(n)

v

10

(n)

v

12

(n)

z

-1

z

-1

3

-0.4

-0.5

4

2

Fig. P7.31 Cascade form with transposed sections.

x(n) e(n)

f(n)

g(n) y(n)

z

-1

H

1

(z)

H

2

(z)

Fig. P7.32 Case A of Problem 7.28

e(n) = x(n)+f(n)

g(n) = e(n −1)

y(n) = h

1

(n)∗g(n)

f(n) = h

2

(n)∗y(n)

⇒

E(z) = X(z)+F(z)

G(z) = z

−1

E(z)

Y(z) = H

1

(z)G(z)

F(z) = H

2

(z)Y(z)

145

Eliminating F(z) and E(z) in favor of X(z) and Y(z) gives:

Y(z)= z

−1

H

1

(z)E(z)= z

−1

H

1

(z)

_

X(z)+F(z)

_

= z

−1

H

1

(z)

_

X(z)+H

2

(z)Y(z)

_

and

_

1 −z

−1

H

1

(z)H

2

(z)

_

Y(z)= z

−1

H

1

(z)X(z)

Solving for the closed-loop transfer function H(z)= Y(z)/X(z), we ﬁnd:

H(z)=

z

−1

H

1

(z)

1 −z

−1

H

1

(z)H

2

(z)

Case B has the same transfer function H(z). Cases C and D have:

H(z)=

H

1

(z)

1 −z

−1

H

1

(z)H

2

(z)

Problem 7.29

The overall transfer function of this system can be computed using the results of Problem 7.28

and the individual transfer functions:

H

1

(z)=

1 +z

−1

1 −0.5z

−1

, H

2

(z)= z

−1

0.4(1 −z

−1

)

1 −0.4z

−1

H(z)=

H

1

(z)

1 −H

1

(z)H

2

(z)

=

1 +z

−1

1 −0.5z

−1

1 −

1 +z

−1

1 −0.5z

−1

·

0.4(1 −z

−1

)z

−1

1 −0.4z

−1

which gives

H(z)=

1 +0.6z

−1

−0.4z

−2

1 −1.3z

−1

+0.2z

−2

+0.4z

−3

In case A, we assign internal state variables as shown in Fig. P7.33.

The difference equations and sample processing algorithm, written in the right computational

order, are:

e(n) = x(n)+f(n −1)

w(n) = 0.5w(n −1)+e(n)

y(n) = w(n)+w(n −1)

v(n) = 0.4v(n −1)+y(n)

f(n) = 0.4v(n)−0.4v(n −1)

for each input sample x do:

e = x +f

1

w

0

= 0.5w

1

+e

y = w

0

+w

1

v

0

= 0.4v

1

+y

f

0

= 0.4(v

0

−v

1

)

f

1

= f

0

(update delays)

w

1

= w

0

v

1

= v

0

Notice how the extra delay factor z

−1

in H

2

(z) delays the output f(n) and allows the start of the

computational cycle with e(n)= x(n)+f(n−1). The output f(n) is computed last. If this delay

were not there, we would have e(n)= x(n)+f(n), which is not possible because f(n) is not yet

146

x(n)

e(n) w(n)

w

0

f

0

v

0

w

1

v

1

f

1

v(n)

w(n-1)

v(n-1)

f(n) f(n-1)

y(n)

0.5

z

-1

0.4

z

-1

z

-1

-0.4

0.4

Fig. P7.33 Case A of Problem 7.29.

computed.

In case B, shown in Fig. P7.34, the overall transfer function remains the same. The change causes

a re-ordering of the computational cycle. The difference equations and corresponding sample

processing algorithm are now:

v(n) = 0.4v(n −1)+y(n −1)

f(n) = 0.4v(n)−0.4v(n −1)

e(n) = x(n)+f(n)

w(n) = 0.5w(n −1)+e(n)

y(n) = w(n)+w(n −1)

for each input sample x do:

v

0

= 0.4v

1

+y

1

f = 0.4(v

0

−v

1

)

e = x +f

w

0

= 0.5w

1

+e

y = w

0

+w

1

y

1

= y (update delays)

w

1

= w

0

v

1

= v

0

x(n)

e(n)

f(n)

w(n)

w

0

v

0

w

1

v

1

y

1

v(n)

w(n-1)

v(n-1)

y(n-1)

y(n)

0.5

z

-1

0.4

z

-1

-0.4

0.4

z

-1

Fig. P7.34 Case B of Problem 7.29.

Now, the start of the computational cycle is v(n)= 0.4v(n−1)+y(n−1), where both quantities

147

v(n − 1) and y(n − 1) are available from the previous time step. Note that y(n) is computed

last and then put into the feedback delay to be used in the next time step.

Problem 7.30

The ﬁlter G(z) can be implemented by the input/output sample processing algorithm of its

canonical form:

for each x do:

y = 0.2x +0.8w

1

w

1

= y

where w

1

is its internal state, that is, w

1

(n)= y(n − 1) in the difference equation: y(n)=

0.2x(n)+0.8y(n − 1). Fig. P7.35 shows the three cases with explicitly assigned signal labels.

Identifying the proper input and output to the ﬁ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

w

1

= u

y = v

0

= x +u

delay(4, v)

for each x do:

y = x +v

4

v

0

= 0.2y +0.8w

1

w

1

= v

0

delay(4, v)

for each x do:

y = u

0

= x +v

2

v

0

= 0.2u

2

+0.8w

1

w

1

= v

0

delay(2, v), delay(2, u)

z

-4

G(z)

z

-4

G(z)

z

-2 z

-2

G(z)

(a) (b) (c)

x

u

v

0

v

4

y

x x

v

0

v

0

u

0

u

2

v

4

v

2

y y

Fig. P7.35 Feedback systems of Problem 7.30.

148

Chapter 8 Problems

Problem 8.1

The transfer function is obtained by the period-3 repetition of the sequence b(n)= [0, 1, 2], that

is, in the time- and z-domains:

h(n) = b(n)+b(n −3)+b(n −6)+· · ·

H(z) = B(z)+z

−3

B(z)+z

−6

B(z)+· · · =

B(z)

1 −z

−3

=

z

−1

+2z

−2

1 −z

−3

The direct and canonical realizations are shown in Fig. P8.1. Their sample processing algorithms

are:

for each input x do:

v

0

= x

y = w

0

= v

1

+2v

2

+w

3

delay(2, v)

delay(3, w)

for each input x do:

w

0

= x +w

3

y = w

1

+2w

2

delay(3, w)

x

y

x

y

z

-1

z

-1

z

-1

z

-1

z

-1

z

-1

w

0

w

0

w

1

w

1

w

2

w

2

w

3

w

3

z

-1

z

-1

v

0

v

1

v

2

2 2

Fig. P8.1 Direct and canonical realizations of Problem 8.1.

For the direct form realization, if the input is a unit impulse so that x = 1 at the ﬁrst iteration of

the algorithm and zero for all other iterations, then the ﬁrst three iterations will ﬁll the feedback

delay buffer w with the desired waveform samples. From then on, the feed-forward part of the

algorithm will be zero, giving rise to the following generation algorithm, expressed in its of the

linear and circular buffer versions:

repeat forever:

w

0

= w

3

delay(3, w)

repeat forever:

∗p = tap(3, w, p, 3)

cdelay(3, w, &p)

The following table shows the initialization and steady part of the linear buffer case. The columns

v

0

, v

1

, v

2

are the input impulse and its delays: δ(n), δ(n−1), δ(n−2). At each iteration, w

0

is

replaced by the value of w

3

and only then is the row of w’s shifted to the right to give the values

of w

1

, w

2

, w

3

of the next row. The w-columns are the successively delayed output signals y(n),

y(n −1), y(n −2), y(n −3):

149

n v

0

v

1

v

2

w

0

w

1

w

2

w

3

y = w

0

0 1 0 0 0 0 0 0 0

1 0 1 0 1 0 0 0 1

2 0 0 1 2 1 0 0 2

3 0 0 0 0 2 1 0 0

4 0 0 0 1 0 2 1 1

5 0 0 0 2 1 0 2 2

6 0 0 0 0 2 1 0 0

7 0 0 0 1 0 2 1 1

8 0 0 0 2 1 0 2 2

The circular version is given in the following table. The buffer entry that contains the current

output sample is shown with an up-arrow symbol and it corresponds to the entry w

q

deﬁned by

the circulating value of q:

n q w

0

w

1

w

2

w

3

y

0 0 ↑0 0 0 0 0

1 3 0 0 0 ↑1 1

2 2 0 0 ↑2 1 2

3 1 0 ↑0 2 1 0

n q w

0

w

1

w

2

w

3

y

4 0 ↑1 0 2 1 1

5 3 1 0 2 ↑2 2

6 2 1 0 ↑0 2 0

7 1 1 ↑1 0 2 1

n q w

0

w

1

w

2

w

3

y

8 0 ↑2 1 0 2 2

9 3 2 1 0 ↑0 0

10 2 2 1 ↑1 0 1

11 1 2 ↑2 1 0 2

n q w

0

w

1

w

2

w

3

y

12 0 ↑0 2 1 0 0

13 3 0 2 1 ↑1 1

14 2 0 2 ↑2 1 2

15 1 0 ↑0 2 1 0

The table entries circulate every D(D + 1)= 12 iterations. Thus, entry n = 3 and n = 15 will

be the same. We used 15 iterations because they contain one complete cycle of the table entries

after the ﬁrst 3 initializing iterations.

Problem 8.2

Expanding the denominator in powers of z

−5

, will cause the period-5 replication of the numerator

sequence b = [1, 2, 3, −4, −5]. The direct and canonical realizations are shown in Fig. P8.2. Their

sample processing algorithms are:

for each input x do:

v

0

= x

w

0

= v

0

+2v

1

+3v

2

−4v

3

−5v

4

+w

5

y = w

0

delay(4, v)

delay(5, w)

for each input x do:

w

0

= x +w

5

y = w

0

+2w

1

+3w

2

−4w

3

−5w

4

delay(5, w)

The steady parts of the linear and circular buffer generation algorithms are:

repeat forever:

w

0

= w

5

delay(5, w)

repeat forever:

∗p = tap(5, w, p, 5)

cdelay(5, w, &p)

150

x

y

x

y

z

-1

z

-1

z

-1

z

-1

w

5

w

0

w

1

w

2

w

3

w

4

z

-1

z

-1

z

-1

z

-1

z

-1

w

5

w

0

w

1

w

2

w

3

w

4

z

-1

z

-1

z

-1

z

-1

v

0

v

1

v

2

v

3

v

4

z

-1

-5

-5

-4 -4

2 2

3 3

Fig. P8.2 Direct and canonical realizations of Problem 8.2.

The following table shows the initialization and steady parts of the linear buffer case:

n v

0

v

1

v

2

v

3

v

4

w

0

w

1

w

2

w

3

w

4

w

5

y

0 1 0 0 0 0 1 0 0 0 0 0 1

1 0 1 0 0 0 2 1 0 0 0 0 2

2 0 0 1 0 0 3 2 1 0 0 0 3

3 0 0 0 1 0 −4 3 2 1 0 0 −4

4 0 0 0 0 1 −5 −4 3 2 1 0 −5

5 0 0 0 0 0 1 −5 −4 3 2 1 1

6 0 0 0 0 0 2 1 −5 −4 3 2 2

7 0 0 0 0 0 3 2 1 −5 −4 3 3

8 0 0 0 0 0 −4 3 2 1 −5 −4 −4

9 0 0 0 0 0 −5 −4 3 2 1 −5 −5

10 0 0 0 0 0 1 −5 −4 3 2 1 1

11 0 0 0 0 0 2 1 −5 −4 3 2 2

12 0 0 0 0 0 3 2 1 −5 −4 3 3

13 0 0 0 0 0 −4 3 2 1 −5 −4 −4

14 0 0 0 0 0 −5 −4 3 2 1 −5 −5

The circular version is given in the following table. The buffer entry that contains the current

output sample is shown with an up-arrow symbol and it corresponds to the entry w

q

deﬁned by

the circulating value of q:

n q w

0

w

1

w

2

w

3

w

4

w

5

y

0 0 1↑ 0 0 0 0 0 1

1 5 1 0 0 0 0 2↑ 2

2 4 1 0 0 0 3↑ 2 3

3 3 1 0 0 −4↑ 3 2 −4

4 2 1 0 −5↑ −4 3 2 −5

5 1 1 1↑ −5 −4 3 2 1

151

n q w

0

w

1

w

2

w

3

w

4

w

5

y

6 0 2↑ 1 −5 −4 3 2 2

7 5 2 1 −5 −4 3 3↑ 3

7 4 2 1 −5 −4 −4↑ 3 −4

9 3 2 1 −5 −5↑ −4 3 −5

10 2 2 1 1↑ −5 −4 3 1

11 1 2 2↑ 1 −5 −4 3 2

n q w

0

w

1

w

2

w

3

w

4

w

5

y

12 0 3↑ 2 1 −5 −4 3 3

13 5 3 2 1 −5 −4 −4↑ −4

14 4 3 2 1 −5 −5↑ −4 −5

15 3 3 2 1 1↑ −5 −4 1

16 2 3 2 2↑ 1 −5 −4 2

17 1 3 3↑ 2 1 −5 −4 3

n q w

0

w

1

w

2

w

3

w

4

w

5

y

18 0 −4↑ 3 2 1 −5 −4 −4

19 5 −4 3 2 1 −5 −5↑ −5

20 4 −4 3 2 1 1↑ −5 1

21 3 −4 3 2 2↑ 1 −5 2

22 2 −4 3 3↑ 2 1 −5 3

23 1 −4 −4↑ 3 2 1 −5 −4

n q w

0

w

1

w

2

w

3

w

4

w

5

y

24 0 −5↑ −4 3 2 1 −5 −5

25 5 −5 −4 3 2 1 1↑ 1

26 4 −5 −4 3 2 2↑ 1 2

27 3 −5 −4 3 3↑ 2 1 3

28 2 −5 −4 −4↑ 3 2 1 −4

29 1 −5 −5↑ −4 3 2 1 −5

n q w

0

w

1

w

2

w

3

w

4

w

5

y

30 0 1↑ −5 −4 3 2 1 1

31 5 1 −5 −4 3 2 2↑ 2

32 4 1 −5 −4 3 3↑ 2 3

33 3 1 −5 −4 −4↑ 3 2 −4

34 2 1 −5 −5↑ −4 3 2 −5

35 1 1 1↑ −5 −4 3 2 1

The table entries circulate every D(D + 1)= 30 iterations. Thus, entry n = 5 and n = 35 will

be the same. We used 35 iterations because they contain one complete cycle of the table entries

after the ﬁrst 5 initializing iterations.

152

Problem 8.3

The shift is c = D/d = 8/5 = 1.6. The d = 5 possible values of the offset index q are obtained

by iterating Eq. (8.1.36):

q

0

= 0

q

1

= q

0

−c = −

8

5

≡ 8 −

8

5

=

32

5

= 6

2

5

q

2

= q

1

−c =

32

5

−

8

5

=

24

5

= 4

4

5

q

3

= q

2

−c =

24

5

−

8

5

=

16

5

= 3

1

5

q

4

= q

3

−c =

16

5

−

8

5

=

8

5

= 1

3

5

Fig. P8.3 shows the relative locations of the q’s with respect to the circular buffer. The ﬁve

q-arrows are now at relative angles ω= 2π/5.

w

0

q

0

q

4

w

4

w

5

w

6

w

7

w

2

w

3 w

1

q

1

q

3

q

2

b

0

b

7

b

6

b

5

b

4

b

3

b

2

b

1

Fig. P8.3 Successive positions of q when d = 5.

Down-truncation gives the following integer values for the q’s and corresponding buffer entries:

[q

0

, q

1

, q

2

, q

3

, q

4

]= [0, 6, 4, 3, 1]

_

w[0], w[6], w[4], w[3], w[1]

_

= [b

0

, b

2

, b

4

, b

5

, b

7

]

Up-truncation gives:

[q

0

, q

1

, q

2

, q

3

, q

4

]= [0, 7, 5, 4, 2]

_

w[0], w[7], w[5], w[4], w[2]

_

= [b

0

, b

1

, b

3

, b

4

, b

6

]

Rounding to the nearest integer gives:

[q

0

, q

1

, q

2

, q

3

, q

4

]= [0, 6, 5, 3, 2]

_

w[0], w[6], w[5], w[3], w[2]

_

= [b

0

, b

2

, b

3

, b

5

, b

6

]

For the linear interpolation case, we have the outputs:

153

q

0

= 0 ⇒ y

0

= w[0]= b

0

6 < q

1

< 7 ⇒ y

1

= w[6]+(q

1

−6)(w[7]−w[6])=

2

5

b

1

+

3

5

b

2

4 < q

2

< 5 ⇒ y

2

= w[4]+(q

2

−4)(w[5]−w[4])=

4

5

b

3

+

1

5

b

4

3 < q

3

< 4 ⇒ y

3

= w[3]+(q

3

−3)(w[4]−w[3])=

1

5

b

4

+

4

5

b

5

1 < q

4

< 2 ⇒ y

4

= w[1]+(q

4

−1)(w[2]−w[1])=

3

5

b

6

+

2

5

b

7

Thus, depending on the output method, the following period-5 subsequences will be produced:

[b

0

, b

2

, b

4

, b

5

, b

7

, b

0

, b

2

, b

4

, b

5

, b

7

, . . . ] (truncate down)

[b

0

, b

1

, b

3

, b

4

, b

6

, b

0

, b

1

, b

3

, b

4

, b

6

, . . . ] (truncate up)

[b

0

, b

2

, b

3

, b

5

, b

6

, b

0

, b

2

, b

3

, b

5

, b

6

, . . . ] (round)

[y

0

, y

1

, y

2

, y

3

, y

4

, y

0

, y

1

, y

2

, y

3

, y

4

, . . . ] (interpolation)

where the y’s were given above.

Problem 8.4

The shift is c = D/d = 8/6 = 4/3. The d = 6 possible values of the offset index q are obtained

by iterating Eq. (8.1.36):

q

0

= 0

q

1

= q

0

−c = −

4

3

≡ 8 −

4

3

=

20

3

= 6

2

3

q

2

= q

1

−c =

20

3

−

4

3

=

16

3

= 5

1

3

q

3

= q

2

−c =

16

3

−

4

3

=

12

3

= 4

q

4

= q

3

−c =

12

3

−

4

3

=

8

3

= 2

2

3

q

5

= q

4

−c =

8

3

−

4

3

=

4

3

= 1

1

3

Fig. P8.4 shows the relative locations of the q’s with respect to the circular buffer. The six q-arrows

are now at relative angles ω= 2π/6.

Down-truncation gives the following integer values for the q’s and corresponding buffer entries:

[q

0

, q

1

, q

2

, q

3

, q

4

, q

5

]= [0, 6, 5, 4, 2, 1]

_

w[0], w[6], w[5], w[4], w[2], w[1]

_

= [b

0

, b

2

, b

3

, b

4

, b

6

, b

7

]

Up-truncation gives:

[q

0

, q

1

, q

2

, q

3

, q

4

, q

5

]= [0, 7, 6, 4, 3, 2]

_

w[0], w[7], w[6], w[4], w[3], w[2]

_

= [b

0

, b

1

, b

2

, b

4

, b

5

, b

6

]

154

w

0

q

0

q

1

q

2

q

3

q

4

q

5

w

4

w

5

w

6

w

7

w

2

w

3 w

1

b

0

b

7

b

6

b

5

b

4

b

3

b

2

b

1

Fig. P8.4 Successive positions of q when d = 6.

Rounding to the nearest integer gives:

[q

0

, q

1

, q

2

, q

3

, q

4

, q

5

]= [0, 7, 5, 4, 3, 1]

_

w[0], w[7], w[5], w[4], w[3], w[1]

_

= [b

0

, b

1

, b

3

, b

4

, b

5

, b

7

]

For the linear interpolation case, we have the outputs:

q

0

= 0 ⇒ y

0

= w[0]= b

0

6 < q

1

< 7 ⇒ y

1

= w[6]+(q

1

−6)(w[7]−w[6])=

2

3

b

1

+

1

3

b

2

5 < q

2

< 6 ⇒ y

2

= w[5]+(q

2

−5)(w[6]−w[5])=

1

3

b

2

+

2

3

b

3

q

3

= 4 ⇒ y

3

= w[4]= b

4

2 < q

4

< 3 ⇒ y

4

= w[2]+(q

4

−2)(w[3]−w[2])=

2

3

b

5

+

1

3

b

6

1 < q

5

< 2 ⇒ y

5

= w[1]+(q

5

−1)(w[2]−w[1])=

1

3

b

6

+

2

3

b

7

Thus, depending on the output method, the following period-5 subsequences will be produced:

[b

0

, b

2

, b

3

, b

4

, b

6

, b

7

, b

0

, b

2

, b

3

, b

4

, b

6

, b

7

, . . . ] (truncate down)

[b

0

, b

1

, b

2

, b

4

, b

5

, b

6

, b

0

, b

1

, b

2

, b

4

, b

5

, b

6

, . . . ] (truncate up)

[b

0

, b

1

, b

3

, b

4

, b

5

, b

7

, b

0

, b

1

, b

3

, b

4

, b

5

, b

7

, . . . ] (round)

[y

0

, y

1

, y

2

, y

3

, y

4

, y

5

, y

0

, y

1

, y

2

, y

3

, y

4

, y

5

, . . . ] (interpolate)

where the y’s are given above.

Problem 8.5

This problem is similar to Example 8.1.2. Referring to Fig. 8.1.14, we have for the cases of trun-

cating down, up, and rounding:

[b

0

, b

3

, b

6

, b

0

, b

3

, b

6

, . . . ]= [1, 4, 7, 1, 4, 7, . . . ] (truncate down)

[b

0

, b

2

, b

5

, b

0

, b

2

, b

5

, . . . ]= [1, 3, 6, 1, 3, 6, . . . ] (truncate up)

[b

0

, b

3

, b

5

, b

0

, b

3

, b

5

, . . . ]= [1, 4, 6, 1, 4, 6, . . . ] (round)

155

If we interpolate linearly, we get the sequence:

y

0

= b

0

= 1

y

1

=

1

3

b

2

+

2

3

b

3

=

1

3

3 +

2

3

4 =

11

3

= 3.667

y

2

=

1

3

b

5

+

2

3

b

6

=

1

3

6 +

2

3

7 =

20

3

= 6.667

so that the period-3 sequence is:

[1, 3.667, 6.667, 1, 3.667, 6.667, . . . ]

Problem 8.6

This problemis similar to Problem8.3. Inserting the numerical values for the wavetable contents:

b = [b

0

, b

1

, b

2

, b

4

, b

5

, b

6

, b

7

]= [1, 2, 3, 4, 5, 6, 7, 8]

we ﬁnd for the period-5 sequences:

[b

0

, b

2

, b

4

, b

5

, b

7

, . . . ]= [1, 3, 4, 5, 7. . . ] (truncate down)

[b

0

, b

1

, b

3

, b

4

, b

6

, . . . ]= [1, 2, 3, 5, 7, . . . ] (truncate up)

[b

0

, b

2

, b

3

, b

5

, b

6

, . . . ]= [1, 3, 4, 6, 7, . . . ] (round)

[y

0

, y

1

, y

2

, y

3

, y

4

, . . . ]= [1, 2.6, 4.2, 5.8, 7.4, . . . ] (interpolation)

where

y

0

= b

0

= 1

y

1

=

2

5

b

1

+

3

5

b

2

=

2

5

2 +

3

5

3 = 2.6

y

2

=

4

5

b

3

+

1

5

b

4

=

4

5

4 +

1

5

5 = 4.2

y

3

=

1

5

b

4

+

4

5

b

5

=

1

5

5 +

1

5

6 = 5.8

y

4

=

3

5

b

6

+

2

5

b

7

=

3

5

7 +

2

5

8 = 7.4

The case d = 6 is similar to Problem 8.4.

Problem 8.7

An example program that exercises the wavetable routines is listed below. It generates three

wavetables: sinusoidal, square wave, and trapezoidal.

/* wavgenex.c - circular wavetable example */

#include <stdio.h>

#include <stdlib.h>

#include <math.h>

void gdelay2();

double wavgen();

double sine(), square(), trapez();

156

void main(int argc, char **argv)

{

int i, n, D;

double *w1, q1, *w2, q2, *w3, q3, c, A, F;

FILE *fp1, *fp2, *fp3;

if (argc != 4) {

fprintf(stderr, "usage: wavgenex A, c, D\n");

fprintf(stderr, "A = wavetable amplitude\n");

fprintf(stderr, "c = no. of periods in D samples, F=c/D\n");

fprintf(stderr, "D = wavetable size\n");

exit(0);

}

A = atof(argv[1]);

c = atof(argv[2]);

D = atoi(argv[3]);

F = c / D;

fp1 = fopen("y1.dat", "w");

fp2 = fopen("y2.dat", "w");

fp3 = fopen("y3.dat", "w");

w1 = (double *) calloc(D, sizeof(double));

w2 = (double *) calloc(D, sizeof(double));

w3 = (double *) calloc(D, sizeof(double));

q1 = 0;

q2 = 0;

q3 = 0;

for (i=0; i<D; i++) { /* load wavetables */

w1[q1] = sine(D, i); /* might need the cast w1[(int)q1] */

w2[q2] = square(D/2, i);

w3[q3] = trapez(D, 3*D/4, 0, i);

gdelay2(D-1, 1.0, &q1);

gdelay2(D-1, 1.0, &q2);

gdelay2(D-1, 1.0, &q3);

}

for (n=0; n<D; n++) {

fprintf(fp1, "%lf\n", wavgen(D, w1, A, F, &q1));

fprintf(fp2, "%lf\n", wavgen(D, w2, A, F, &q2));

fprintf(fp3, "%lf\n", wavgen(D, w3, A, F, &q3));

}

}

Problem 8.8

Partial C code for this problem was given in the text, just before Figs. 8.1.20 and 8.1.21.

Problem 8.9

The zero patterns and magnitude responses ¦H(ω)¦ of the four ﬁlters are shown in Fig. 8.9. The

ﬁrst ﬁlter has H(z)= 1 +z

−8

. Therefore, its zeros are the solutions of:

157

z

8

= −1 = e

jπ

e

2πjk

⇒ z

k

= e

jπ/8

e

j2πk/8

, k = 0, 1, . . . , 7

That is, the 8th roots of unity rotated by π/8 ≡= 22.5

o

. The second ﬁlter has H(z)= 1 − z

−8

and thus, its zeros are the 8th roots of unity.

2 2

ω

2π 2π

|H(ω)|

ω

3

2π

ω

3

2π

ω

Fig. P8.5 Comb ﬁlters of Problem 8.9.

The third and fourth ﬁlters can be written as follows, using the ﬁnite geometric series:

H(z) = 1 −z

−8

+z

−16

=

1 +z

−24

1 +z

−8

H(z) = 1 +z

−8

+z

−16

=

1 −z

−24

1 −z

−8

The third has roots the 24th roots of unity shifted by π/24 = 7.5

o

, but among them the roots

of the denominator 1 +z

−8

must be excluded. This results in 16 zeros. Similarly, the last ﬁlter’s

zeros are the 24th roots of unity with the 8th roots of unity excluded.

Problem 8.10

Typical C code for generating Fig. 8.2.9 and 8.2.11 is given in the text. For the double chorus case,

we have the code segment:

for (n=0; n<Ntot; n++) {

d1 = D * (0.5 + ranl(Dran, u1, &q1, &iseed1)); /* u1 is 2-dim */

d2 = D * (0.5 + ranl(Dran, u2, &q2, &iseed2)); /* mean = D/2 */

a1 = 1 + ranl(Dran, u3, &q3, &iseed3); /* mean = 1 */

a2 = 1 + ranl(Dran, u4, &q4, &iseed4);

x = cos(2 * pi * F * n); /* input x(n) */

xd1 = tapi(D, w, p, d1); /* delay x(n-d1) */

xd2 = tapi(D, w, p, d2);

y = (x + a1 * xd1 + a2 * xd2) / 3; /* output */

*p = x;

cdelay(D, w, &p); /* update delay */

fprintf(fpx, "%lf\n", x); /* declaration of fpx */

158

fprintf(fpy, "%lf\n", y); /* is not shown */

fprintf(fpd, "%lf\n", 2*d1/D);

fprintf(fpa, "%lf\n", a1);

}

Typical output is shown in Fig. P8.6. For the recursive ﬂanger, we have the code fragment:

Fig. P8.6 Double chorusing of sinusoidal signal.

for (n=0; n<Ntot; n++) {

d = 0.50 * D * (1 - cos(2 * pi * Fd * n));

x = cos(2 * pi * F * n);

yd = tapi(D, w, p, d);

y = a * yd + x; /* yd is y(n-d) */

*p = y;

cdelay(D, w, &p);

fprintf(fpx, "%lf\n", x);

fprintf(fpy, "%lf\n", y);

fprintf(fpd, "%lf\n", d/D);

}

Typical output for D = 100 and D = 10 is shown in Fig. P8.7.

Problem 8.11

A typical program is as follows:

/* reverb.c - plain, allpass, and lowpass reverb */

#include <stdio.h>

#include <stdlib.h>

#include <math.h>

double plain(), allpass(), lowpass();

void main(int argc, char **argv)

{

double *w1, *p1;

double *w2, *p2;

159

Fig. P8.7 Recursive ﬂanger.

double *w3, *p3;

double v[2] = {0., 0.};

double a[2] = {1, -0.5};

double b[2] = {0.3, 0.15};

double a0 = 0.75;

double x, y1, y2, y3, sD;

int D, Ntot, M=1, n;

FILE *fp1, *fp2, *fp3;

fp1 = fopen("y1.dat", "w");

fp2 = fopen("y2.dat", "w");

fp3 = fopen("y3.dat", "w");

if (argc != 3) {

fprintf(stderr, "usage: reverb D Ntot"); use D=20, Ntot=100

exit(0);

}

D = atoi(argv[1]);

Ntot = atoi(argv[2]);

w1 = (double *) calloc(D+1, sizeof(double));

p1 = w1;

w2 = (double *) calloc(D+1, sizeof(double));

p2 = w2;

w3 = (double *) calloc(D+1, sizeof(double));

p3 = w3;

for (n=0; n<Ntot; n++) {

triangular pulse

if (n<=5)

x=n;

else if (n<=10)

x = 10-n;

else

x=0;

160

y1 = plain(D, w1, &p1, a0, x);

y2 = allpass(D, w2, &p2, a0, x);

y3 = lowpass(D, w3, &p3, M, a, b, v, x);

fprintf(fp1, "%lf\n", y1);

fprintf(fp2, "%lf\n", y2);

fprintf(fp3, "%lf\n", y3);

}

}

Problem 8.12

A typical program is as follows:

/* reverb.c - Schroeder’s plain/allpass reverb system */

#define D1 29

#define D2 37

#define D3 44

#define D4 50

#define D5 27

#define D6 31

#define a1 .75

#define a2 .75

#define a3 .75

#define a4 .75

#define a5 .75

#define a6 .75

#include <stdio.h>

#include <stdlib.h>

#include <math.h>

double plain(), allpass();

void main()

{

double *w1, *p1;

double *w2, *p2;

double *w3, *p3;

double *w4, *p4;

double *w5, *p5;

double *w6, *p6;

double y1, y2, y3, y4, y5, y, x;

int Ntot=500, n;

FILE *fpy;

fpy = fopen("y.dat", "w");

w1 = (double *) calloc(D1+1, sizeof(double));

p1 = w1;

w2 = (double *) calloc(D2+1, sizeof(double));

161

p2 = w2;

w3 = (double *) calloc(D3+1, sizeof(double));

p3 = w3;

w4 = (double *) calloc(D4+1, sizeof(double));

p4 = w4;

w5 = (double *) calloc(D5+1, sizeof(double));

p5 = w5;

w6 = (double *) calloc(D6+1, sizeof(double));

p6 = w6;

for (n=0; n<Ntot; n++) {

if(n==0) impulse

x = 1;

else

x = 0;

y1 = plain(D1, w1, &p1, a1, x);

y2 = plain(D2, w2, &p2, a2, x);

y3 = plain(D3, w3, &p3, a3, x);

y4 = plain(D4, w4, &p4, a4, x);

y = y1 + 0.9*y2 + 0.8*y3 + 0.7*y4;

y5 = allpass(D5, w5, &p5, a5, y);

y = allpass(D6, w6, &p6, a6, y5);

fprintf(fpy, "%lf\n", y);

}

}

Problem 8.13

The difference equations are:

v(n) = y(n −D)−a

1

v(n −1)

u(n) = b

0

v(n)+b

1

v(n −1)

y(n) = x(n)+u(n)

The corresponding circular version of the sample processing algorithm is

for each input x do:

s

D

= tap(D, w, p, D)

v

0

= s

D

−a

1

v

1

u = b

0

v

0

+b

1

v

1

v

1

= v

0

y = x +u

∗p = y

cdelay(D, w, &p)

162

Problem 8.14

The response to a causal sinusoid will be of the form:

e

jωn

u(n)−→H(ω)e

jωn

u(n)+

D+1

_

i=1

B

i

p

n

i

u(n)

where B

i

= A

i

p

i

/(p

i

−e

jω

), as shown in Problem 6.29. It follows that the response to a delayed

sinusoid will be:

e

jω(n−L)

u(n −L)−→H(ω)e

jω(n−L)

u(n −L)+

D+1

_

i=1

B

i

p

n−L

i

u(n −L)

Multiplying both sides by the factor e

jωL

and subtracting from the undelayed result, we ﬁnd that

the response to the ﬁnite sinusoid:

x(n)= e

jωn

_

u(n)−u(n −L)

_

is

y(n)= H(ω)e

jωn

_

u(n)−u(n −L)

_

+

D+1

_

i=1

B

i

p

n

i

_

u(n)−e

jωL

p

−L

i

u(n −L)

_

Problem 8.15

A typical C program that utilizes the routines plain and lowpass is given below:

/* reverbex.c - plain and lowpass reverberation of sinusoid */

*

* run with:

* D=300, L=150, N=300, w=0.2pi, w=pi

*

*/

#include <stdio.h>

#include <stdlib.h>

#include <math.h>

double plain(), lowpass();

void main(int argc, char **argv)

{

double *w1, *p1;

double *w2, *p2;

double v[2] = {0., 0.};

double a[2] = {1, -0.5};

double b[2] = {0.3, 0.15};

double a0 = 0.75;

double w, x, y1, y2, sD;

double pi = 4*atan(1.0);

int D, L, N, M=1, n;

FILE *fp1, *fp2;

163

fp1 = fopen("ypl.dat", "w");

fp2 = fopen("ylp.dat", "w");

if (argc != 5) {

puts("usage: reverbex D L N w\n\n"

"D = delay period\n"

"L = time to turn off input\n"

"N = total duration of input \n"

"w = in units of pi \n");

exit(0);

}

D = atoi(argv[1]);

L = atoi(argv[2]);

N = atoi(argv[3]);

w = atof(argv[4]); in units of pi

w1 = (double *) calloc(D+1, sizeof(double));

p1 = w1;

w2 = (double *) calloc(D+1, sizeof(double));

p2 = w2;

for (n=0; n<N; n++) {

if (n < L) sinusoid on for L samples

x = cos(pi*w*n);

else

x = 0;

y1 = plain(D, w1, &p1, a0, x);

y2 = lowpass(D, w2, &p2, M, a, b, v, x);

fprintf(fp1, "%.16lf\n", y1);

fprintf(fp2, "%.16lf\n", y2);

}

}

The analytical expression for y(n) can be obtained as follows. Using the MATLAB function

lprevb.m given below, we determine the poles p

i

and residues A

i

of the transfer function:

function [p, A] = lprvb(b, a, D)

% returns poles and residues of lowpass reverberator (delay D)

% [p, A] = lprvb(b, a, D)

%

% b=[b(1), b(2)]

% a=[1, a(2)]

c = [a, zeros(1,D-2), -b];

p=roots(c);

for i=1:D+1,

A(i) = 1 + a(2) / p(i);

for j=1:D+1,

if j ~= i,

A(i) = A(i) * p(i) / (p(i) - p(j));

end

164

end

end

Then, the following MATLAB function calculates the residues B

i

and computes N samples of the

output signal y(n):

function [y, p, A] = yon(N, L, w, b, a, D)

% calculate y(n) for a finite-duration sinusoidal input.

[p, A] = lprvb(b, a, D);

z = exp(j * w);

H = 1 / (1 - z^(-D) * (b(1) + z^(-1)*b(2)) / (1 + a(2)*z^(-1)));

for i=1:D+1,

B(i) = A(i) * p(i) / (p(i) - z);

end

for n=0:N-1,

if (n<L),

y(n+1) = H * z^n;

for i=1:D+1,

y(n+1) = y(n+1) + B(i) * p(i)^n;

end

else

y(n+1) = 0;

for i=1:D+1,

y(n+1) = y(n+1) + B(i) * p(i)^n * (1 - z^L / p(i)^L);

end

end

end

Problem 8.16

A typical C program is as follows:

/* karplus.c - Karplus-Strong String Algorithm */

*

* run with:

* D=25, Ntot=500, iseed=1234567

* D=50, Ntot=500, iseed=1234567

*

/*

#include <stdio.h>

#include <stdlib.h>

#include <math.h>

double ran(), lowpass();

void main(int argc, char **argv)

{

double *w, *p;

double v[2] = {0., 0.};

double a[2] = {1, 0.0};

165

double b[2] = {0.5, 0.5};

double x, y;

int D, Ntot, M=1, n;

long iseed;

FILE *fpy;

fpy = fopen("y.dat", "w");

if (argc != 4) {

fprintf(stderr, "usage: karplus D Ntot iseed");

exit(0);

}

D = atoi(argv[1]);

Ntot = atoi(argv[2]);

iseed = atol(argv[2]);

w = (double *) calloc(D+1, sizeof(double));

for (n=0; n<=D; n++) initialize

w[n] = ran(&iseed) - 0.5;

p = w;

for (n=0; n<Ntot; n++) {

y = lowpass(D, w, &p, M, a, b, v, 0.0); x=0

fprintf(fpy, "%.16lf\n", y);

}

}

The output signals corresponding to D = 25 and D = 50 are shown in Fig. P8.8. Note how

the initial random numbers get smoothed at each D-cycle resulting in a decaying quasi-periodic

signal tuned to the frequency f = f

s

/D.

Fig. P8.8 Karplus-Strong string algorithm outputs.

Problem 8.17

A block diagram realization is given in Fig. P8.9. The difference equations are the system:

166

w(n) = aw(n −D)+x(n)

y(n) = cx(n)+bw(n −D)

x y

b

c

a

z

-D

w

0

w

D

Fig. P8.9 Prototypical delay effect.

The sample processing algorithm is in its linear and circular buffer forms:

for each input x do:

y = cx +bw

D

w

0

= aw

D

+x

delay(D, w)

for each input x do:

s

D

= tap(D, w, p, D)

y = cx +bs

D

∗p = as

D

+x

cdelay(D, w, &p)

Problem 8.18

The block diagrams and sample processing algorithms are essentially given in Section 8.2.4. The

C routines are:

/* plaindel.c - plain reverberating delay */

double tap();

void cdelay();

double plaindel(D, w, p, a, x) usage: y=plaindel(D,w,&p,a,x);

double *w, **p, a, x; p is passed by address

int D;

{

double y;

y = tap(D, w, *p, D); D-th tap delay output

**p = x + a * y; delay input

cdelay(D, w, p); update delay line

return y;

}

/* lpdel.c - lowpass reverberating delay */

double tap(), can();

void cdelay();

double lpdel(D, w, p, M, a, b, v, x)

double *w, **p, *a, *b, *v, x;

167

int D;

{

double y;

y = tap(D, w, *p, D); D-th tap delay output

**p = x + can(M, a, M, b, v, y); delay input

cdelay(D, w, p); update delay line

return y;

}

The routines differ from plain and lowpass in that the ﬁlter outputs are taken after the delay

z

−D

, instead of before.

Problem 8.19

Typical C code for this problem is:

for (n=0; n<Ntot; n++) {

if (n<L) /* use if (n<1) for impulse response */

x = 1;

else

x = 0;

x1 = plaindel(D1, w1, &p1, a0, x); /* plain */

x2 = plaindel(D2, w2, &p2, a0, x1);

/* x1 = lpdel(D1, w1, &p1, 1, a, b, v1, x); */ /* lowpass */

/* x2 = lpdel(D2, w2, &p2, 1, a, b, v2, x1); */

y = b0 * x + b1 * x1 + b2 * x2; /* output */

fprintf(fpx, "%.16lf\n", x);

fprintf(fpy, "%.16lf\n", y);

}

where the initializations are:

double x, x1, x2, y, *w1, *w2, *p1, *p2;

double v1[2] = {0., 0.}; /* state of LP filter 1 */

double v2[2] = {0., 0.}; /* state of LP filter 2 */

double a[2] = {1, -0.5}; /* G(z) denominator */

double b[2] = {0.3, 0.15}; /* G(z) numerator */

double b0=1, b1=0.8, b2=0.6 /* feed-forward coefficients */

double a0 = 0.75; /* feedback for plain delay */

w1 = (double *) calloc(D1+1, sizeof(double)); p1 = w1;

w2 = (double *) calloc(D2+1, sizeof(double)); p2 = w2;

Typical output is as in Fig. P8.10.

Problem 8.20

The sample processing routine is as follows. It can easily be generalized to more than two multi-

tap delay segments:

168

Fig. P8.10 Multi-delay effects processor outputs.

/* mlttap.c - multi-tap delay line */

double tap();

void cdelay();

double mlttap(D1, D2, b, a, w, p, x)

int D1, D2;

double b[3], a[3], *w, **p, x;

{

double s[3], y;

s[1] = tap(D1+D2, w, *p, D1);

s[2] = tap(D1+D2, w, *p, D1+D2);

s[0] = x + a[1] * s[1] + a[2] * s[2];

y = b[0] * x + b[1] * s[1] + b[2] * s[2];

**p = s[0];

cdelay(D1+D2, w, p);

return y;

}

Typical output is shown in Fig. P8.11 and is obtained by the code segment:

for (n=0; n<Ntot; n++) {

if (n < L) /* use L=1 or L=200 */

x = 1;

else

x = 0;

y = mlttap(D1, D2, b, a, w, &p, x); /* p passed by reference */

fprintf(fpx, "%.8lf\n", x);

fprintf(fpy, "%.8lf\n", y);

}

Problem 8.21

From the pole equation, we have:

169

Fig. P8.11 Multi-Tap Delay Line.

z

D1+D2

= a

1

z

D2

+a

2

⇒

¦z¦

D1+D2

= ¦a

1

z

D2

+a

2

¦ ≤ ¦a

1

¦¦z¦

D2

+¦a

2

¦

(P8.1)

If a pole had ¦z¦ ≥ 1, then using the inequality ¦a

1

¦ +¦a

2

¦ < 1, we would have:

¦z¦

D1+D2

≥ ¦z¦

D2

> ¦a

1

¦¦z¦

D2

+¦a

2

¦¦z¦

D2

≥ ¦a

1

¦¦z¦

D2

+¦a

2

¦

which contradicts Eq. (P8.1). Thus, all poles must have ¦z¦ < 1.

Problem 8.22

Working in the z-domain and denoting by W

L

(z) and W

R

(z) the inputs to the delays z

−L

and

z

−R

, the outputs of these delays will be z

−L

W

L

(z) and z

−R

W

R

(z). Thus, the I/O equations of

the block diagram will be:

Y

L

(z) = c

L

X

L

(z)+z

−L

W

L

(z)

W

L

(z) = z

−L

G

L

(z)W

L

(z)+b

L

X

L

(z)+d

R

z

−R

W

R

(z)

Y

R

(z) = c

R

X

R

(z)+z

−R

W

R

(z)

W

R

(z) = z

−R

G

L

(z)W

R

(z)+b

R

X

R

(z)+d

L

z

−L

W

L

(z)

Solving the ﬁrst and third for the Ws, we get:

W

L

(z)= z

L

_

Y

L

(z)−c

L

X

L

(z)

_

, W

R

(z)= z

R

_

Y

R

(z)−c

R

X

R

(z)

_

Inserting them into the second and fourth, we get the system:

_

1 −z

−L

G

L

(z)

__

Y

L

(z)−c

L

X

L

(z)

_

−d

R

z

−L

_

Y

R

(z)−c

R

X

R

(z)

_

= b

L

z

−L

X

L

(z)

_

1 −z

−R

G

R

(z)

__

Y

R

(z)−c

R

X

R

(z)

_

−d

L

z

−R

_

Y

L

(z)−c

L

X

L

(z)

_

= b

R

z

−R

X

R

(z)

Solving for Y

L

(z), Y

R

(z) in terms of X

L

(z), X

R

(z), we get:

Y

L

(z) = H

LL

(z)X

L

(z)+H

LR

(z)X

R

(z)

Y

R

(z) = H

RL

(z)X

L

(z)+H

RR

(z)X

R

(z)

170

where

H

LL

(z) = c

L

+

1

D(z)

_

1 −z

−R

G

R

(z)

_

b

L

z

−L

H

LR

(z) =

1

D(z)

d

R

b

R

z

−L

z

−R

H

RL

(z) =

1

D(z)

d

L

b

L

z

−R

z

−L

H

RR

(z) = c

R

+

1

D(z)

_

1 −z

−L

G

L

(z)

_

b

R

z

−R

with

D(z)=

_

1 −z

−R

G

R

(z)

__

1 −z

−L

G

L

(z)

_

−d

L

d

R

z

−L

z

−R

For the special case when the cross couplings are d

L

}= 0 and d

R

= 0, we have:

D(z)=

_

1 −z

−R

G

R

(z)

__

1 −z

−L

G

L

(z)

_

and therefore, the transfer functions simplify to:

H

LL

(z) = c

L

+

b

L

z

−L

1 −z

−L

G

L

(z)

H

LR

(z) = 0

H

RL

(z) =

d

L

b

L

z

−L

z

−R

_

1 −z

−R

G

R

(z)

__

1 −z

−L

G

L

(z)

_

H

RR

(z) = c

R

+

b

R

z

−R

1 −z

−R

G

R

(z)

The corresponding I/O system is then:

Y

L

(z) = H

LL

(z)X

L

(z)

Y

R

(z) = H

RL

(z)X

L

(z)+H

RR

(z)X

R

(z)

which means that the left channel responds only to the left input (it does not receive any cross-

feedback from the right channel), but the right channel responds to both the right input and the

cross feedback from the left output. If both cross-feedbacks are zero, d

L

= d

R

= 0, then the left

and right channels decouple completely, responding independently to their respective inputs. For

the case G

L

(z)= a

L

, G

R

(z)= a

R

, the sample processing algorithm is straightforward. Denote

the left and right delay-line buffers by

w

L

= [w

L0

, w

L1

, . . . , w

LL

]= (L+1)-dimensional

w

R

= [w

R0

, w

R1

, . . . , w

RR

]= (R+1)-dimensional

Let p

L

and p

R

be the circular pointers circulating over them, and let the corresponding delay

outputs be s

L

and s

R

. Then, the computational sample processing algorithm will be:

171

for each input pair ¦x

L

, x

R

¦ do:

s

L

= tap(L, w

L

, p

L

, L)

s

R

= tap(R, w

R

, p

R

, R)

y

L

= c

L

x

L

+s

L

y

R

= c

R

x

R

+s

R

∗p

L

= b

L

x

L

+a

L

s

L

+d

R

s

R

∗p

R

= b

R

x

R

+a

R

s

R

+d

L

s

L

cdelay(L, w

L

, &p

L

)

cdelay(R, w

R

, &p

R

)

Problem 8.23

The sample processing algorithm is implemented by the C code segment:

int L = 30, R = 70;

double *wL, *wR, *pL, *pR;

wL = (double *) calloc(L+1, sizeof(double)); pL = wL;

wR = (double *) calloc(R+1, sizeof(double)); pR = wR;

for (n=0; n<Ntot; n++) {

if (n < P)

xL = 1;

else

xL = 0;

sL = tap(L, wL, pL, L);

sR = tap(R, wR, pR, R);

yL = cL * xL + sL;

yR = cR * xR + sR; /* use xR = 0 */

*pL = bL * xL + aL * sL + dR * sR;

*pR = bR * xR + aR * sR + dL * sL;

cdelay(L, wL, &pL);

cdelay(R, wR, &pR);

fprintf(fp1, "%.16lf\n", yL);

fprintf(fp2, "%.16lf\n", yR);

}

Figures P8.12 and P8.13 show typical outputs. The left output does not start until n = L, there-

fore, the ﬁ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.

Problem 8.24

The sample processing algorithm is implemented by the C code segment:

if (L > 1) { /* L-point smoother */

h = (double *) calloc(L, sizeof(double));

v = (double *) calloc(L, sizeof(double));

for (n=0; n<L; n++)

h[n] = 1.0 / L;

172

Fig. P8.12 Stereo delays, with d

L

= d

R

= 0.3.

Fig. P8.13 Stereo delays, with d

L

= 0.3, d

R

= 0.

}

for (n=0; n<N; n++) { /* use N = 600 */

if (n < N/3) /* generate input */

x = A1 * cos(w0 * n); /* use w0 = 0.15 * pi */

else if (n < 2*N/3)

x = A2 * cos(w0 * n);

else

x = A3 * cos(w0 * n);

c = a * c1 + (1-a) * fabs(x); /* control signal */

c1 = c; /* update delay */

g = f(rho, c/c0); /* gain function */

if (L > 1)

G = fir(L-1, h, v, g); /* gain smoothing */

else

G = g; /* no smoothing */

y = G * x; /* compressor output */

173

fprintf(fpx, "%.16lf\n", x); /* save input */

fprintf(fpy, "%.16lf\n", y); /* save output */

fprintf(fpc, "%.16lf\n", c); /* save control */

fprintf(fpg, "%.16lf\n", G); /* save gain */

}

where the compressor function is deﬁned by f(x)= x

ρ−1

, for x ≥ 1:

/* compressor function with 1:rho compressor ratio */

#include <math.h>

double f(rho, x)

double rho, x;

{

if (x >= 1)

return pow(x, rho-1);

else

return 1;

}

The compressing action takes place only above the threshold. For an expander, the gain function

is deﬁned as follows, where now ρ > 1, but it takes effect only below the threshold:

/* expander gain function with 1:rho expander ratio */

#include <math.h>

double f(rho, x)

double rho, x;

{

if (x <= 1)

return pow(x, rho-1);

else

return 1;

}

Problem 8.25

Increasing the threshold to c

0

will cause both A

1

and A

3

to be attenuated. However, A

3

because

it is further from c

0

than in the case of Fig. 8.2.38, it will be attenuated more. Fig. P8.14 shows

the results.

The noise gate with threshold c

0

= 1.5, will suppress both A

1

and A

3

, but A

3

by much more, for

the same reasons explained above. Fig. P8.15 shows the results.

Problem 8.26

Assuming the causal sequence ¦x(0), x(1), . . . ¦ is zero-mean white, then the terms in the convo-

lutional sum will be mutually uncorrelated and zero-mean:

y(n)= h

0

x(n)+h

1

x(n −1)+· · · +h(n)x(0)

Thus, the output will have zero mean and its variance will be the sum of the variances of the

successive terms:

σ

2

y

= E[y(n)

2

]= h

2

0

σ

2

x

+h

2

1

σ

2

x

+· · · h

2

n

σ

2

x

= σ

2

x

n

_

n=0

h

2

m

174

Fig. P8.14 Expander output and gain with increased threshold.

Fig. P8.15 Noise gate output and gain with increased threshold.

Problem 8.27

Assuming a partial fraction expansion of the form:

H(z)=

M

_

i=1

A

i

1 −p

i

z

−1

we have for the impulse response:

h

n

=

M

_

i=1

A

i

p

n

i

u(n)

It follows that we have the bound:

¦h

n

¦ =

¸

¸

M

_

i=1

A

i

p

n

i

¸

¸

≤

M

_

i=1

¦A

i

¦¦p

i

¦

n

≤

M

_

i=1

¦A

i

¦¦p

max

¦

n

= C¦p

max

¦

n

where C =

M

i=1

¦A

i

¦ and we used the inequality ¦p

i

¦ ≤ ¦p

max

¦. The NRR inequality follows now

by squaring and summing the above inequality for ¦h

n

¦ and applying the geometric series on the

right-hand side.

175

Problem 8.28

For ideal ﬁlter shapes, the NRR is computed most conveniently using its frequency response

deﬁnition:

NRR =

σ

2

yv

σ

2

v

=

_

π

−π

¦H(ω)¦

2

dω

2π

For a bandpass ﬁlter, H(ω) is non-zero only over the interval ω

a

≤ ¦ω¦ ≤ ω

b

, where it is unity.

Thus,

NRR =

σ

2

yv

σ

2

v

=

_

−ωa

−ω

b

1 ·

dω

2π

+

_

ω

b

ωa

1 ·

dω

2π

=

ω

b

−ω

a

π

Problem 8.29

The following program is an implementation:

/* smooth1.c - 1st-order exponential smoother */

#include <stdio.h>

#include <math.h>

void main(int argc, char **argv)

{

double a, x, y, w1 = 0;

if (argc != 2) {

fprintf(stderr, "usage: smooth1 a <x.dat >y.dat\n");

exit(0);

}

a = atof(argv[1]);

fprintf(stderr, "%lf\n", a);

while(scanf("%lf", &x) != EOF) {

y = a * w1 + (1-a) * x;

w1 = y;

printf("%lf\n", y);

}

}

Problem 8.30

The mean of x(n) is m

x

= s = 5. The mean of y(n) is the same because it is preserved through

the ﬁlter. Indeed, taking means of both sides of

y(n)= ay(n −1)+(1 −a)x(n)

gives

m

y

= am

y

+(1 −a)m

x

⇒ m

y

= m

x

The mean-square values may be determine recursively as follows: If we deﬁne

s

2

n

=

1

n

n−1

_

k=0

(x

k

−m

x

)

2

176

then we have the recursion:

s

2

n+1

= s

2

n

+

1

n +1

_

(x

n

−m

x

)

2

−s

2

n

_

initialized with s

2

0

= 0. The following program will calculate the input and output signals and

the experimental mean-square values. Any discrepancies are due to the ﬁlter transients and they

disappear with increasing L:

/* smoothex.c - filtering with 1st order smoother */

#include <stdio.h>

#include <math.h>

double gran();

void main(int argc, char **argv)

{

int n, L;

long iseed;

double s=5, x, y, w1, a, m=0, sigma=1;

double sx2=0, sy2=0;

FILE *fpx, *fpy;

if (argc != 4) {

puts("\nUsage: smoothex a iseed L");

exit(0);

}

a = atof(argv[1]);

iseed = atol(argv[2]);

L = atoi(argv[3]);

fpx = fopen("ttx", "w");

fpy = fopen("tty", "w");

for (w1=0, n=0; n<L; n++) {

x = s + gran(m, sigma, &iseed);

y = (1 - a) * x + a * w1;

w1 = y;

fprintf(fpx, "%lf\n", x);

fprintf(fpy, "%lf\n", y);

sx2 += ((x-s)*(x-s) - sx2) / (n+1);

sy2 += ((y-s)*(y-s) - sy2) / (n+1);

}

printf("theoretical 1/NRR = %lf\n", (1+a)/(1-a));

printf("experimental 1/NRR = %lf\n", sx2/sy2);

}

Problem 8.31

The requirement that the high-frequency signal s(−1)

n

go through unchanged is that the ﬁlter

have unity gain at ω= π or z = −1. This requires the value for the constant b:

b

1 −az

−1

¸

¸

¸

¸

z=−1

=

b

1 +a

= 1 ⇒ b = 1 +a

177

Thus the ﬁlter transfer function and impulse response will be:

H(z)=

1 +a

1 −az

−1

, h(n)= (1 +a)a

n

u(n)

The NRR is:

NRR =

∞

_

n=0

h(n)

2

= (1 +a)

2

1

1 −a

2

=

1 +a

1 −a

Thus, the NRR is magniﬁed if 0 < a < 1. This can be understood in the frequency domain by the

Fig. P8.16.

π

ω

0

1

input noise spectrum

output noise spectrum

1+a

1- a

( (

2

Fig. P8.16 Lowpass ﬁlter for extracting high-frequency signal.

The magnitude response is normalized to unity at high frequencies, and therefore it must be

larger at low frequencies because it is a lowpass ﬁlter. Indeed, its values at DC and AC are:

¦H(0)¦

2

=

_

1 +a

1 −a

_

2

, ¦H(π)¦

2

= 1

Problem 8.32

For an FIR ﬁlter of length N, its frequency response will be:

H(ω)=

N−1

_

n=0

h

n

e

−jωn

The condition that the gain is unity at AC is:

H(π)=

N−1

_

n=0

h

n

(−1)

n

= 1

where we used the fact e

jπn

= (−1)

n

. Thus, the NRR must be minimized subject to this AC

condition:

NRR =

N−1

_

n=0

h

2

n

= min, subject to

N−1

_

n=0

h

n

(−1)

n

= 1

This can be solved by Lagrange multipliers or more simply by deﬁning the quantities g

n

=

h

n

(−1)

n

. Because g

2

n

= h

2

n

, the problem reduces to the following minimization problem:

178

NRR =

N−1

_

n=0

g

2

n

= min, subject to

N−1

_

n=0

g

n

= 1

whose solution was found in Example 8.3.4 to be g

n

= 1/N, n = 0, 1, . . . , N−1. Thus, the solution

of the highpass problem will be:

h

n

= (−1)

n

g

n

=

1

N

(−1)

n

, n = 0, 1, . . . , N−1

The Lagrange multiplier method is as follows. Introducing a Lagrange multiplier, say λ, that

enforces the constraint, we modify the NRR to be minimized into the effective performance index:

J =

N−1

_

n=0

h

2

n

+2λ

_

1 −

N−1

_

n=0

h

n

(−1)

n

_

The minimization condition with respect to the unknowns h

n

are:

∂J

∂h

n

= 2h

n

−2λ(−1)

n

= 0, n = 0, 1, . . . , N−1

This gives h

n

= λ(−1)

n

, and the AC constraint then ﬁxes λ to be:

N−1

_

n=0

h

n

(−1)

n

= λ

N−1

_

n=0

(−1)

2n

= λN = 1 ⇒ λ =

1

N

Problem 8.33

Expand the transfer function into partial fractions:

H(z)=

G

(1 −pz

−1

)(1 −p

∗

z

−1

)

=

A

1 −pz

−1

+

A

∗

1 −p

∗

z

−1

where

A =

G

1 −p

∗

/p

=

Gp

p −p

∗

= −

jGe

jω0

2sinω

0

The corresponding impulse response and NRR will be then

h

n

= Ap

n

+a

∗

p

∗n

, n ≥ 0

NRR =

∞

_

n=0

h

2

n

=

∞

_

n=0

_

A

2

p

2n

+A

∗2

p

∗2n

+2AA

∗

¦p¦

2n

_

which sums up to

NRR =

A

2

1 −p

2

+

A

∗2

1 −p

∗2

+

2¦A¦

2

1 −¦p¦

2

Inserting p = Re

jω0

, and A as given above, and replacing G

2

by its normalized value G

2

=

(1−R)

2

_

1−2Rcos(2ω

0

)+R

2

_

gives the desired expression for NRR after some tedious algebra.

179

Problem 8.34

For the ﬁrst ﬁlter, we ﬁnd the transfer function:

H(z)=

0.0730(1 −z

−2

)

1 −1.7633z

−1

+0.8541z

−2

Its pole radius is R =

√

a

2

=

√

0.8541 = 0.9242, which gives the 5% time constant:

n

eff

=

ln(0.05)

ln(R)

= 38

Its NRR can be computed by carrying out a partial fraction expansion of the form:

H(z)= B +

A

1 −pz

−1

+

A

∗

1 −p

∗

z

−1

which gives the impulse response:

h

n

= Bδ

n

+Ap

n

u

n

+A

∗

p

∗n

u

n

from which we can calculate the NRR:

NRR =

∞

_

n=0

h

2

n

= B

2

+

∞

_

n=1

(Ap

n

+A

∗

p

∗n

)

2

= B

2

+

∞

_

n=1

_

A

2

p

2n

+A

∗2

p

∗2n

+2¦A¦

2

¦p¦

2n

_

= B

2

+

A

2

p

2

1 −p

2

+

A

∗2

p

∗2

1 −p

∗2

+

2¦A¦

2

¦p¦

2

1 −¦p¦

2

The parameters B and A are:

B = −

G

¦p¦

2

, A = −

G(1 −p

2

)

p

2

−¦p¦

2

The numerical value of NRR is NRR = 1/13.4. For the second ﬁlter, we start with n

eff

from which

we may solve for

R = (0.05)

1/n

eff

= 0.9901

where R is related to the 3-dB width by:

R

2

= a

2

= 2b −1 =

1 −tan(Δω/2)

1 +tan(Δω/2)

which gives Δω= 0.0064π. Then, the design equations give:

H(z)=

0.0099(1 −z

−2

)

1 −1.8833z

−1

+0.9802z

−2

and NRR = 1/101.1. The required graphs are shown in Figs. P8.17 and P8.18.

Problem 8.35

For Q = 6, the transfer function is designed using Eqs. (8.2.22) and (8.2.23):

H(z)= 0.96953

1 −1.85955z

−1

+z

−2

1 −1.80289z

−1

+0.93906z

−2

Its 1% time constant is n

eff

= 146. For Q = 60, the ﬁlter is identical to that of Example 8.3.8.

Figures P8.19–P8.21 show the input signal, ﬁlter responses, and output signals.

180

Fig. P8.17 Magnitude responses and noisy input of Problem 8.34.

Fig. P8.18 Filter outputs of Problem 8.34.

Fig. P8.19 Noisy input and desired signal of Problem 8.35.

Problem 8.36

The designed ﬁlter has the form:

181

Fig. P8.20 Magnitude responses, for Q = 6 and Q = 60. Problem 8.35.

Fig. P8.21 Filter outputs, for Q = 6 and Q = 60. Problem 8.35.

H(z)= b

1 −z

−D

1 −az

−D

The time constant is computed as:

n

eff

= D

ln

lna

where = 0.01 for the 1% time constant. The ﬁlter parameters are in the four cases:

Q a b n

eff

80 0.961481 0.980741 1172.4

200 0.984414 0.992207 2931.6

400 0.992177 0.996088 5863.7

800 0.996081 0.998040 11727.8

The relevant graphs are shown in Figs. P8.22–P8.26.

182

Fig. P8.22 Desired signal and noisy input. Problem 8.36.

Fig. P8.23 Filtered output y(n) when Q = 80. Problem 8.36.

Fig. P8.24 Filtered s(n) for Q = 80 and Q = 200. Problem 8.36.

Problem 8.37

The following MATLAB m-ﬁle designs the 60 Hz notch ﬁlter, generates the noisy ECG and ﬁlters

it, and computes the ﬁlter’s magnitude response:

183

Fig. P8.25 Filtered s(n) for Q = 400 and Q = 800. Problem 8.36.

Fig. P8.26 Magnitude responses for Q = 80 and Q = 800. Problem 8.36.

% ecgex1.m - simulated ECG + 60Hz noise example

%

% assume 2 beats/sec => 0.5 sec/beat => 500 samples/beat => 1000 samples/sec

% f0=60; Q=60; df=f0/Q;

%

% compute notch ﬁlter coefﬁcients

% generate length-500 ecg by calling x0=ecg(500); normalize it to 1.

% replicate three beats x=[x0,x0,x0] and smooth them with x=sgﬁlt(0, 5, x);

% add 80 percent 60-Hz noise

% and ﬁlter it yv=ﬁlter(B,A,xv)

% ﬁnally, compute ﬁlter’s magnitude response.

f0 = 60/1000; Q = 60; df = f0/Q;

w0 = 2 * pi * f0; dw = 2 * pi * df;

b = 1 / (1+tan(dw/2));

B = b * [1, -2*cos(w0), 1];

A = [1, B(2), 2*b-1];

x0 = ecg(500);

x = [x0, x0, x0];

x = sgfilt(0, 5, x); m = max(x); x = x/m;

184

n = 0:1499;

xv = x + 0.5 * cos(w0 * n);

yv = filter(B, A, xv);

w = (0:499)*pi/500; z = exp(-i*w);

h = abs((B(1) + B(2)*z + B(3)*z.^2) ./ (1 + A(2)*z + A(3)*z.^2));

Problem 8.38

The following MATLAB m-ﬁle designs the 60 Hz comb ﬁlter, generates the noisy ECG and ﬁlters

it, and computes the ﬁlter’s magnitude response:

% ecgex2.m - simulated ECG + 60Hz square-wave noise example

%

% assume 1 beats/sec => 1 sec/beat => 600 samples/beat => 600 samples/sec

%

% compute notch ﬁlter coefﬁcients

% generate length-600 ecg by calling x0=ecg(600); normalize it to 1.

% replicate three beats x=[x0,x0,x0] and smooth them with x=sgﬁlt(0, 9, x);

% add shifted square wave

% and ﬁlter it yv=ﬁlter(B,A,xv)

% ﬁnally, compute ﬁlter’s magnitude response.

fs = 600; f0 = 60; df = 0.75;

w0 = 2 * pi * f0 / fs;

dw = 2 * pi * df / fs;

beta = tan(dw * 10 / 4); % D=10 here

a = (1 - beta) / (1 + beta);

b = (1 + a) / 2;

B = b * [1 0 0 0 0 0 0 0 0 0 -1]; % numerator

A = [1 0 0 0 0 0 0 0 0 0 -a]; % denominator

x0 = ecg(600);

x = [x0, x0];

x = sgfilt(0, 9, x); m = max(x); x = x/m;

n = 0:1199;

v0 = [1 1 1 1 1 -1 -1 -1 -1 -1]; v = v0; % one noise period

for k=1:119, % 120 noise periods

v = [v, v0];

end

v = 2 + v; % noise baseline shift

xv = x + 0.5 * v; % noisy ECG

yv = filter(B, A, xv);

w = (0:500)*pi/500; z = exp(-i*w);

h = abs(b * (1 - z.^10) ./ (1 - a * z.^10));

185

Problem 8.39

Using partial fractions, we expand

H(z)= b

1 +z

−D

1 −az

−D

= A+

B

1 −az

−D

= (A+B)+Baz

−D

+Bz

2

z

−2D

+· · ·

where

A = −

b

a

, B = b

_

1 +

1

a

_

, A+B = b

Thus, the impulse response is

h = [b, 0, 0, . . . , 0, Ba, 0, 0, . . . , 0, Ba

2

, 0, 0, . . . , 0, Ba

3

, . . . ]

with the nonzero entries separated by D−1 zeros. The sum of the squares is

NRR =

∞

_

n=0

h

2

n

= b

2

+B

2

∞

_

m=1

a

2m

= b

2

+B

2

a

2

1 −a

2

=

b

2

(1 −a

2

)+b

2

a

2

(1 +a

−2

)

1 −a

2

=

2b

2

(1 +a)

1 −a

2

=

2(1 −a)

2

(1 +a)

4(1 −a)(1 +a)

=

1 −a

2

In the ﬁlter design parameter β = tan(ΔωD/4), the tangent has argument:

ΔωD

4

=

Δω

4

·

2π

ω

1

=

πΔω

2ω

1

=

π

2Q

where we used ω

1

= 2π/D, or D = 2π/ω

1

.

Problem 8.40

The following program designs the comb ﬁ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>

double gran(), tap();

void cdelay(), triang();

void main(int argc, char **argv)

{

int n, i, N, D;

long iseed;

double a, b, pi=4*atan(1.0), dw = 0.0008 * pi;

double *s, *w, *p;

double x, y, sD;

FILE *fpy, *fps, *fpx;

if (argc != 4) {

186

puts("\nUsage: combex D N iseed");

exit(0);

}

D = atoi(argv[1]); period

N = atoi(argv[2]); number of periods

iseed = atol(argv[3]); initial seed

fpy = fopen("y.dat", "w"); ﬁlter output

fps = fopen("s.dat", "w"); noise-free input

fpx = fopen("x.dat", "w"); noisy input

a = (1 - tan(D*dw/4)) / (1 + tan(D*dw/4));

b = (1 - a) / 2;

s = (double *) calloc(D, sizeof(double));

triang(D, s); one period of triangular wave

w = (double *) calloc(D+1, sizeof(double));

p = w;

for (i=0; i<N; i++) generate N periods

for (n=0; n<D; n++) {

x = s[n] + 0.5 * gran(0., 1., &iseed);

sD = tap(D, w, p, D);

*p = b * x + a * sD;

y = (*p) + sD;

cdelay(D, w, &p);

fprintf(fps, "%lf\n", s[n]);

fprintf(fpx, "%lf\n", x);

fprintf(fpy, "%lf\n", y);

}

}

/* -------------------------------------------------------- */

/* triang.c - triangular wave */

void triang(D, s)

int D;

double *s;

{

int i;

double D4 = D/4.0;

for (i = 0; i<D4; i++)

s[i] = i / D4;

for (i=D4; i<3*D4; i++)

s[i] = 1 + (D4 - i) / D4;

for (i=3*D4; i<D; i++)

s[i] = -1 + (i - 3*D4) / D4;

}

187

Problem 8.41

The complementarity properties may be veriﬁed for each pair. For example, for ﬁlter 2, we have

half-order M = 8/2 = 4. Thus, we must verify:

H

LP

(z)+H

BP

(z)=

1

16

(1 +z

−2

)

2

(−1 +6z

−2

−z

−4

)+

1

16

(1 −z

−2

)

4

= z

−4

which follows by expanding out the terms. Fig. P8.27 shows the frequency responses in the four

cases. The frequency scale is in MHz and extends only up to about 4.5 MHz. For reference, the

Nyquist frequency here is f

s

/2 = 2f

sc

= 7.159 MHz, so that the subcarrier frequency shown in

the ﬁgure is only one-quarter of the Nyquist interval.

Fig. P8.27 Lowpass/bandpass and highpass/bandstop responses. Problem 8.41.

Problem 8.42

See Table P8.1. Note that the circular pointer p points to the buffer entry w[q], whereas the D-th

tap output is the content of w[q

D

]. At each time instant, the content of w[q] is updated by

w[q]= w[q

D

]+x, where the scaling by N is done afterwards. Table P8.1 shows the results. The

advantage of the circular implementation is that only one entry of w, namely, w[q], is changed

at each time instant. This is efﬁcient in hardware implementations and for large values of D.

Problem 8.43

The following is a complete Cprogramfor performing signal averaging. The inputs to the program

are the period D and the number N of periods to be averaged. The input data are taken from

stdin and the averaged period is output to the stdout:

/* sigav.c - signal averaging */

#include <stdio.h>

#include <stdlib.h>

void cdelay();

double tap();

188

void main(int argc, char **argv)

{

double x, *w, *p;

int D, N, i, k;

if (argc != 3) {

fprintf(stderr, "usage: sigav D N < x.dat > y.dat\n");

fprintf(stderr, "x.dat must contain N periods of length D\n");

exit(0);

}

D = atoi(argv[1]);

N = atoi(argv[2]);

w = (double *) calloc(D+1, sizeof(double));

p = w;

for (k=0; k<N; k++)

for (i=0; i<D; i++)

if (scanf("%lf", &x) != EOF) { /* keep reading input samples */

*p = tap(D, w, p, D) + x / N;

cdelay(D, w, &p);

}

else {

fprintf(stderr, "Input must have %d periods of length %d\n", N, D);

exit(0);

}

for (i=0; i<D; i++)

printf("%.12lf\n", tap(D, w, p, D-i));

}

n x q

D

q w

0

w

1

w

2

w

3

y = w

q

/4

0 s

0

3 0 s

0

0 0 0 s

0

/4

1 s

1

2 3 s

0

0 0 s

1

s

1

/4

2 s

2

1 2 s

0

0 s

2

s

1

s

2

/4

3 s

0

0 1 s

0

2s

0

s

2

s

1

2s

0

/4

4 s

1

3 0 2s

1

2s

0

s

2

s

1

2s

1

/4

5 s

2

2 3 2s

1

2s

0

s

2

2s

2

2s

2

/4

6 s

0

1 2 2s

1

2s

0

3s

0

2s

2

3s

0

/4

7 s

1

0 1 2s

1

3s

1

3s

0

2s

2

3s

1

/4

8 s

2

3 0 3s

2

3s

1

3s

0

2s

2

3s

2

/4

9 s

0

2 3 3s

2

3s

1

3s

0

4s

0

s

0

10 s

1

1 2 3s

2

3s

1

4s

1

4s

0

s

1

11 s

2

0 1 3s

2

4s

2

4s

1

4s

0

s

2

12 − − − − 4s

2

4s

1

4s

0

−

Table P8.1 Signal averager with circular delay for D = 3, N = 4.

189

Problem 8.44

The following program generates N periods of length D of the noisy signal, and averages these

periods using the circular buffer form of the averager. After processing the ND input samples,

it writes out the contents of the delay line in reverse order, so that the ﬁles y.dat and s.dat will

contain the averaged periods and the noise-free period:

/* sigavex.c - signal averaging example */

#include <stdio.h>

#include <stdlib.h>

#include <math.h>

double gran(), tap();

void cdelay();

void main(int argc, char **argv)

{

int n, i, N, D;

long iseed;

double *s, x, *w, *p;

double sD;

FILE *fpx, *fpy, *fps;

if (argc != 4) {

puts("\nUsage: sigavex D N iseed");

exit(0);

}

D = atoi(argv[1]); period

N = atoi(argv[2]); number of periods

iseed = atol(argv[3]); noise seed

fpx = fopen("x.dat", "w");

fpy = fopen("y.dat", "w");

fps = fopen("s.dat", "w");

s = (double *) calloc(D, sizeof(double));

for (i=0; i<D; i++)

if (i < D/2)

s[i] = 1;

else

s[i] = -1;

w = (double *) calloc(D+1, sizeof(double));

p = w;

for (i=0; i<N; i++) accumulate N periods

for (n=0; n<D; n++) { each of length D

x = s[n] + gran(0., 1., &iseed); noisy input

sD = tap(D, w, p, D); D-th tap of averager

*p = sD + x; accumulate x

cdelay(D, w, &p); update delay line

fprintf(fpx, "%.12lf\n", x); save input sample

}

for (n=0; n<D; n++) { write averaged period

190

fprintf(fps, "%lf\n", s[n]);

fprintf(fpy, "%.12lf\n", tap(D, w, p, D-n)/N);

}

}

Problem 8.45

The following MATLAB function generates the noisy ECG and smoothes it once and twice by

Savitzky-Golay ﬁlter of length N and smoothing order d:

% sgecgex.m - SG filtering of noisy ECG

L=500;

x0 = ecg(L)’; % generate ECG

x = sgfilt(0, 15, x0);

mx = max(x);

x = x/mx; % unity max

rand(’normal’); rand(’seed’, 10033);

v = 0.3 * rand(L, 1); % generate noise

xv = x + v; % generate noisy ECG

N=11; d=2;

y1 = sgfilt(d, N, xv); % ﬁrst pass through SG

y2 = sgfilt(d, N, y2); % second pass

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.

Fig. P8.28 Double SG ﬁltering; N = 11, 41 and d = 0.

191

Fig. P8.29 Double SG ﬁltering; N = 11, 41 and d = 2.

Fig. P8.30 Double SG ﬁltering; N = 11, 41 and d = 4.

192

Chapter 9 Problems

Problem 9.1

Use the formula T

R

= LT = L/f

s

to solve for L = f

s

T

R

, or in words

no. of samples = (no. of samples per second) x (no. of seconds)

Thus, L = 8 kHz×128 msec = 1024 samples. The frequency spacing is Δf = f

s

/N = 8000/256 =

31.25 Hz. If the DFT is done directly, we would require L · N = 1024 · 256 = 262144 mul-

tiplications. If the signal is reduced mod-256, then the number of multiplications would be

N· N = 256 · 256 = 65536. And if the FFT is used, Nlog

2

N/2 = 256 · 8/2 = 1024.

The cost of performing the mod-256 reduction is N(M − 1)= 256 · 3 = 768 additions, where

M = L/N = 1024/256 = 4 is the number of segments. This cost may be added to the costs of

FFT or reduced DFT.

Problem 9.2

The sinusoidal signal is something like x(t)= cos(2πft), where f = 10 kHz. Its spectrum will

have peaks at :f. Is there a DFT index k such that the kth DFT frequency f

k

equals :f?

:f = f

k

=

f

s

N

k ⇒ k = :N

f

f

s

= :64

10

80

= :8

Thus, we expect to see a peak at k = 8 and another one at k = −8. Because the DFT X(k) is

periodic in k with period N and because we always list the indices in the positive range k =

0, 1, · · · , N−1, we shift the negative index by one period N to get the positive index:

−k →N−k = 64 −8 = 56

Thus, the second peak will be at k = 56.

Problem 9.3

The number of samples in one period is given by:

D =

f

s

f

=

40

5

= 8 samples

Therefore, if k periods are collected , the total signal length will be

N = kD = k

f

s

f

which gives for k = 16, N = 16 · 8 = 128 samples. If we perform an N-point DFT, then because

of the choice of N, the k-th DFT frequency will coincide with f, that is,

f

k

= k

f

s

N

= f

Thus, we expect to see a peak at the kth DFT bin. We will also get a peak at the negative index

−k, which translates mod-N to N−k. In summary, we expect to see peaks at the DFT indices:

k = 16 and N−k = 128 −16 = 112

193

Problem 9.4

The expected DFT index will be at

k = N

f

f

s

= 16 ·

18

8

= 36

Because k is greater than N−1 = 15, it may be reduced mod-N down to:

k = 36 −2 ×16 = 4

It corresponds to the DFT frequency f

k

= kf

s

/N = 4 · 8/16 = 2 kHz. This is frequency within

the Nyquist interval that is aliased with f = 18 kHz; indeed, we have

f

alias

= f modf

s

= 18mod8 = 18 −2 ×8 = 2 kHz

The −2 kHz or −18 kHz component will be represented by the DFT index N−k = 16 −4 = 12.

Problem 9.5

To be able to resolve a peak, the width of the main lobe of the data window must be equal or

smaller than the width of the peak. This gives the condition

f

s

L

≤ Δf ⇒ L ≥

f

s

Δf

or, in our case, L ≥ 8000/20 = 400 samples. The duration of these 400 samples will be

T

R

= LT ≥

L

f

s

=

1

Δf

=

1

20

= 50 msec

To avoid wrap-around errors in the inverse FFT, the FFT length must be at least L, i.e., N ≥ L =

400. The next power of two is N = 512. We must pad 112 zeros to the end of the length-400

signal before the FFT is taken.

Problem 9.6

The following MATLAB function generates the time data and computes the required DTFTs with

the help of the function dtft.m, included below, which replaces the C functions dtft.c and

dtftr.c:

% dtftexp.m - rectangular/hamming windowed sinsuoids

L = 200; N = 200;

w0 = 0.1*pi;

w = (0:N-1) * 0.2 * pi / N; % frequency range

n = 0:(L-1);

wh = 0.54 - 0.46 * cos(2*pi*n/(L-1)); % Hamming window

xrec = cos(w0 * n);

xham = wh .* xrec; % windowed data

Xrec = abs(dtft(xrec, w)); % DTFT of rectangular data

Xham = abs(dtft(xham, w)); % DTFT of Hamming data

save xrec.dat xrec /ascii;

save xham.dat xham /ascii;

save frec.dat Xrec /ascii;

save fham.dat Xham /ascii;

194

where

% dtft.m - DTFT of a signal at a frequency vector w

%

% X = dtft(x, w);

%

% x = row vector of time samples

% w = row vector of frequencies in rads/sample

% X = row vector of DTFT values

%

% based on and replaces both dtft.c and dtftr.c

function X = dtft(x, w)

[L1, L] = size(x);

z = exp(-j*w);

X = 0;

for n = L-1:-1:0,

X = x(n+1) + z .* X;

end

Problem 9.7

The following MATLAB function generates the time data and computes the required DTFTs:

% sinexp.m - 3 sinusoids of length L=10

L=10; N=256;

f1 = 0.2; f2 = 0.25; f3 = 0.3;

n = 0:(L-1);

x = cos(2*pi*f1*n) + cos(2*pi*f2*n) + cos(2*pi*f3*n);

w = 0.54 - 0.46 * cos(2*pi*n/(L-1));

xham = w.*x;

X = abs(fft(x,N));

Xham = abs(fft(xham,N));

For the other cases, use L = 10, 40, 100.

Problem 9.8

The following C program generates the length-L time signal and computes its N-point DFT, with

L = 10, 20, 100 and N = 256. Instead of the DFT routine dft.c, one could use fft.c. The

32-point DFT is extracted by keeping one out of every 256/32 = 8 points of the 256-point DFT.

/* dtftex.c - physical vs. computational resolution example */

#include <stdio.h>

#include <cmplx.h>

#include <stdlib.h>

void dtftr();

195

main()

{

int L, N, n, k;

double *x, pi = 4 * atan(1.0);

double f1 = 0.20, f2 = 0.25, f3 = 0.30;

complex *X;

FILE *fpdtft;

fpdtft= fopen("dtft.dat", "w"); DTFT ﬁle

printf("enter L, N: ");

scanf("%d %d", &L, &N);

x = (double *) calloc(L, sizeof(double));

X = (complex *) calloc(N, sizeof(complex));

for (n=0; n<L; n++)

x[n] = cos(2*pi*f1*n) + cos(2*pi*f2*n) + cos(2*pi*f3*n);

dft(L, x, N, X); N-point DFT

for (k=0; k<N; k++)

fprintf(fpdtft, "%lf\n", cabs(X[k]));

}

Problem 9.9

See Example 9.2.1.

Problem 9.10

Using the relationship k = Nf/fs, we calculate the group-A and group-B DFT indices:

group A k

A

= 22.3, 24.6, 27.3, 30.1

group B k

B

= 38.7, 42.8, 47.3

and their rounded versions:

group A: k

A

= 22, 25, 27, 30

group B: k

B

= 39, 43, 47

Because each keypress generates one tone from group A and one from group B, the DTFT will

have peaks at the corresponding pair of DFT indices (and their negatives, that is, N − k

A

and

N−k

B

.)

Problem 9.11

The time signal and its DTFT are shown in Figs. P9.1 and P9.2, both for the rectangular and

Hamming windows.

196

Fig. P9.1 Rectangularly and Hamming windowed DTMF sinusoids.

Fig. P9.2 Spectra of DTMF sinusoids.

Problem 9.12

Acting on x by the 4×8 DFT matrix, we obtain:

X =

⎡

⎢

⎢

⎢

⎣

X(0)

X(1)

X(2)

X(3)

⎤

⎥

⎥

⎥

⎦

=

⎡

⎢

⎢

⎢

⎣

1 1 1 1 1 1 1 1

1 −j −1 j 1 −j −1 j

1 −1 1 −1 1 −1 1 −1

1 j −1 −j 1 j −1 −j

⎤

⎥

⎥

⎥

⎦

⎡

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎣

1

2

2

1

2

1

1

2

⎤

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎦

=

⎡

⎢

⎢

⎢

⎣

12

0

0

0

⎤

⎥

⎥

⎥

⎦

The mod-4 wrapped version of x is ˜ x = [3, 3, 3, 3]. Its 4-point DFT is

X =

⎡

⎢

⎢

⎢

⎣

X(0)

X(1)

X(2)

X(3)

⎤

⎥

⎥

⎥

⎦

=

⎡

⎢

⎢

⎢

⎣

1 1 1 1

1 −j −1 j

1 −1 1 −1

1 j −1 −j

⎤

⎥

⎥

⎥

⎦

⎡

⎢

⎢

⎢

⎣

3

3

3

3

⎤

⎥

⎥

⎥

⎦

=

⎡

⎢

⎢

⎢

⎣

12

0

0

0

⎤

⎥

⎥

⎥

⎦

For the IDFT we use the formula IDFT(X)= [DFT(X

∗

)]

∗

/N:

197

` x =

⎡

⎢

⎢

⎢

⎣

` x(0)

` x(1)

` x(2)

` x(3)

⎤

⎥

⎥

⎥

⎦

=

1

4

⎡

⎢

⎢

⎢

⎣

1 1 1 1

1 −j −1 j

1 −1 1 −1

1 j −1 −j

⎤

⎥

⎥

⎥

⎦

⎡

⎢

⎢

⎢

⎣

12

0

0

0

⎤

⎥

⎥

⎥

⎦

=

⎡

⎢

⎢

⎢

⎣

3

3

3

3

⎤

⎥

⎥

⎥

⎦

Problem 9.13

The 8-point FFT is:

x =

⎡

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎣

5

−1

−3

−1

5

−1

−3

−1

⎤

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎦

8−FFT

−→ X =

⎡

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎣

0

0

16

0

8

0

16

0

⎤

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎦

It follows that the FFT spectrum will show peaks at the frequencies:

X(ω

2

)= X(ω

6

)

∗

= X(−ω

2

)

∗

= 16, X(ω

4

)= 8

Problem 9.14

The IFFT is obtained by conjugating X, computing its FFT, and dividing by 8. The required FFT of

X

∗

is:

X

∗

=

⎡

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎣

0

4

4j

4

0

4

−4j

4

⎤

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎦

8−FFT

−→

⎡

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎣

16

8

0

−8

−16

8

0

−8

⎤

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎦

⇒ x =

⎡

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎣

2

1

0

−1

−2

1

0

−1

⎤

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎦

Using the inverse DFT formula, we express x(n) as a sum of sinusoids:

x(n) =

1

8

7

_

k=0

X(k)e

jω

k

n

=

1

8

_

4e

jω1n

−4je

jω2n

+4e

jω3n

+4e

jω5n

+4je

jω6n

+4e

jω7n

_

=

1

2

e

jω1n

+

1

2j

e

jω2n

+

1

2

e

jω3n

+

1

2

e

−jω3n

−

1

2j

e

−jω2n

+

1

2

e

−jω1n

= cos(ω

1

n)+sin(ω

2

n)+cos(ω

3

n)= cos(πn/4)+sin(πn/2)+cos(3πn/4)

which agrees with the above IFFT values at n = 0, 1, . . . , 7. We used the values of the DFT fre-

quencies:

ω

1

=

2π

8

=

π

4

, ω

2

=

2π2

8

=

π

2

, ω

3

=

2π3

8

=

3π

4

The DFT frequencies ω

7

, ω

6

, ω

5

are the negatives (modulo-2π) of ω

1

, ω

2

, ω

3

, respectively.

198

Problem 9.15

Figure P9.3 shows the procedure. The (4N)-dimensional time data vector is shufﬂed once into

two (2N)-dimensional subvectors by putting every other one of its entries on top and the remain-

ing entries on the bottom. Then, each of the (2N)-dimensional vectors is shufﬂed again into two

N-dimensional subvectors.

shuffling

N-FFT

N-FFT

N-FFT

N-FFT

DFT merging

4N 4N

2N 2N

2N 2N

N N

N N

N N

N N

W

2N

k

W

2N

k

W

4N

k

Fig. P9.3 Performing large FFTs.

The four N-dimensional vectors are then shipped over to the FFT processor, one at a time, and

their FFTs are returned into four N-dimensional DFT vectors. These are then merged ﬁrst into

(2N)-point DFTs and then into the desired (4N)-point DFT. The ﬁrst merging stage require mul-

tiplication by the twiddle factors W

k

2N

, k = 0, 1, . . . , N − 1. The second stage uses the factors

W

k

4N

, k = 0, 1, . . . , 2N − 1. The butterﬂy 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:

cost = 4

1

2

Nlog

2

N+2N+2N = 2Nlog

2

N+4N

If the (4N)-point FFT could be done in one pass, we would have cost:

cost =

1

2

(4N)log

2

(4N)= 2Nlog

2

(4N)

It is easily veriﬁed that the costs of the two methods are the same. The indirect method is of

course much slower because of all the I/O time for shipping data back and forth from secondary

storage to the FFT processor.

Problem 9.16

The ordinary convolution is

y = h ∗x = [1, 3, 4, 6, 7, 6, 4, 3, 1]

199

Reducing this mod-4 gives: ˜ y = [9, 9, 8, 9]. The alternative method is to reduce ﬁrst x and h

mod-4:

˜

h = [2, 2, 1, 2], ˜ x = [2, 1, 1, 1],

then, compute their ordinary convolution:

˜

h ∗˜ x = [4, 6, 6, 9, 5, 3, 2],

and, ﬁnally, reduce that modulo 4 to get ˜ y = [9, 9, 8, 9].

Problem 9.17

Carrying out the 8-point FFT gives:

x =

⎡

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎣

4

2

4

−6

4

2

4

−6

⎤

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎦

8−FFT

−→ X =

⎡

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎣

8

0

−16j

0

24

0

16j

0

⎤

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎦

Taking every other entry of the result gives the 4-point FFT, namely,

X =

⎡

⎢

⎢

⎢

⎣

8

−16j

24

16j

⎤

⎥

⎥

⎥

⎦

And, taking every other entry of that gives the 2-point FFT:

X =

_

8

24

_

Can we get these results directly? Yes. To do the 4-point FFT, ﬁrst reduce the signal modulo 4 to

get

˜ x =

⎡

⎢

⎢

⎢

⎣

8

4

8

−12

⎤

⎥

⎥

⎥

⎦

4−FFT

−→ X =

⎡

⎢

⎢

⎢

⎣

8

−16j

24

16j

⎤

⎥

⎥

⎥

⎦

Putting the above 8-point FFT into the 8-point inverse FFT formula gives

x(n)=

1

8

7

_

k=0

X(k)e

jω

k

n

=

1

8

_

8e

jω0n

−16je

jω2n

+24e

jω4n

+16je

jω6n

_

Noting that for an 8-point FFT, ω

0

= 0, ω

2

= π/2, ω

4

= π, and ω

6

= 3π/2 ≡ −π/2, and using

Euler’s formula we obtain:

x(n)= 1 +4sin(

πn

2

)+3cos(πn)

which agrees with the given x, for n = 0, 1, · · · , 7.

200

Problem 9.18

Consider the length-7 signal

[1 −a, 2 −b, 3, 4, 5, a, b]

It should be evident that, for any values of the parameters a and b, its mod-5 reduction is

[1, 2, 3, 4, 5].

Problem 9.19

Using the ﬁnite geometric series and the deﬁnition W

N

= e

−2πj/N

, gives

1

N

N−1

_

n=0

W

kn

N

=

1

N

1 −W

Nk

N

1 −W

k

N

=

1

N

1 −e

−2πjk

1 −e

−2πjk/N

If k }= 0, the numerator vanishes but not the denominator. Thus, in this case the answer is zero.

If k = 0, we have a ratio of 0/0, but in this case, we can just go back to the series deﬁnition and

set k = 0. All of the N terms in the sum become unity, giving N/N = 1.

In conclusion, the answer is zero if k }= 0, and unity if k = 0. Note, that these arguments break

down if k is allowed to go beyond the range 0 ≤ k ≤ N−1, because whenever it is a multiple of

N, we would get unity as an answer (and zero otherwise).

Problem 9.20

For a general power p, we have:

W

p

pN

=

_

e

−2πj/(pN)

_

p

= e

−2πj/N

= W

N

The DTFT of a length-L signal and its N-point and (pN)-point DFTs are:

X(ω)=

L−1

_

n=0

x(n)e

−jωn

X

N

(k)=

L−1

_

n=0

x(n)W

kn

N

X

pN

(k)=

L−1

_

n=0

x(n)W

kn

pN

Replacing k by pk in the third and using part (a), we have:

X

pN

(pk)=

L−1

_

n=0

x(n)W

pkn

pN

=

L−1

_

n=0

x(n)W

kn

N

= X

N

(k)

Problem 9.21

This follows from the results of Problem 9.20 by setting N = 8 and p = 2, which implies:

X

8

(k)= X

16

(2k), k = 0, 1, . . . , 15

A geometrical way to understand this is to recognize that the 8th roots of unity are a subset of

the 16th roots of unity and are obtained by taking every other one of the latter.

201

Problem 9.22

Using a trig identity to write the product of sines as a sum of sines, we get the equivalent expres-

sion:

x(t)= cos(24πt)+2sin(12πt)cos(8πt)= cos(24πt)+sin(20πt)+sin(4πt)

The frequencies of the three terms are 12, 10, and 2 kHz. Their aliased versions that lie inside

the Nyquist interval [−4, 4] kHz are, respectively, 4, 2, and 2 kHz. Thus, the aliased signal that

would be reconstructed by an ideal reconstructor will be:

x(t)= cos(8πt)+sin(4πt)+sin(4πt)= cos(8πt)+2sin(4πt)

Setting t = nT = n/8, we get the time samples:

x(n)= cos(πn)+2sin(πn/2)

Evaluating it at n = 0, 1, . . . , 7 gives the values, and their FFT:

x = [1, 1, 1, −3, 1, 1, 1, −3]

8−FFT

−→ X = [0, 0, −8j, 0, 8, 0, 8j, 0]

The same DFT values can be determined without any computation by comparing x(n) with the

inverse DFT. Using Euler’s formula, setting ω

4

= π, ω

2

= π/2, ω

6

= −(π/2)mod(2π), and

multiplying and dividing by 8, we get:

x(n)= e

jπn

−je

jπn/2

+je

−jπn/2

=

1

8

_

−8je

jω2n

+8e

jω4n

+8je

jω6n

_

Comparing with the 8-point IDFT, gives the above DFT vector:

x(n)=

1

8

7

_

k=0

X(k)e

jω

k

n

Problem 9.23

Using Euler’s formula, we write:

x(n) = 1 +2sin(

πn

4

)−2sin(

πn

2

)+2sin(

3πn

4

)+3(−1)

n

= 1 −je

jπn/4

+je

−jπn/4

+je

jπn/2

−je

−jπn/2

−je

j3πn/4

+je

−j3πn/4

+3e

jπn

=

1

8

_

8e

jω0n

−8je

jω1n

+8je

jω2n

−8je

jω3n

+24e

jω4n

+8je

jω5n

−8je

jω6n

+8je

jω7n

_

where we reordered the terms according to increasing DFT index. Comparing with the IDFT

formula, we get:

X = [8, −8j, 8j, −8j, 24, 8j, −8j, 8j]

202

Problem 9.24

Using Euler’s formula, we write

x(n) = 0.5e

πjn/2

+0.5e

−πjn/2

+e

πjn/8

+e

−πjn/8

=

1

16

_

8e

πjn/2

+8e

3πjn/2

+16e

πjn/8

+16e

15πjn/8

_

where, we shifted the negative frequency exponents by adding 2πn to them, e.g., replaced −πn/8

by 2πn −πn/8 = 15πn/8. Now, comparing with the 16-point IDFT formula

x(n)=

1

16

15

_

k=0

X(k)e

jω

k

n

and noting that π/2 = 8π/16 = ω

4

, 3π/2 = 24π/16 = ω

12

, π/8 = 2π/16 = ω

1

, and

15π/8 = 30π/16 = ω

15

, we may identify the (non-zero) values of X(k) as follows:

X(1)= 16, X(4)= 8, X(12)= 8, X(15)= 16, or,

X = [0, 16, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 16]

Problem 9.25

Arguing in a similar fashion, we ﬁnd the (non-zero) values of the 32-point DFT:

X(2)= 32, X(8)= 16, X(24)= 16, X(30)= 32

Problem 9.26

Write x(n) in its complex sinusoidal form:

x(n)= 0.5e

jω0n

−je

jω4n

+jω

jω12n

+1.5e

jω8n

(P9.1)

where ω

0

= 0, ω

4

= 2π4/16 = π/2, ω

12

= −ω

4

mod(2π), ω

8

= 2π8/16 = π are the signal

frequencies expressed as 16-point DFT frequencies. The DTFT of each complex sinusoid is given

by the shifted spectrum of the rectangular window W(ω) of length-16:

X(ω)= 0.5W(ω)−jW(ω−ω

4

)+jW(ω−ω

12

)+1.5W(ω−ω

8

)

where

W(ω)=

1 −e

−16jω

1 −e

−jω

=

sin(8ω)

sin(ω/2)

e

−15jω/2

The magnitude spectrum ¦X(ω)¦ is plotted versus 0 ≤ ω≤ 2π in Fig. P9.4. The spectral peaks

at the signal frequencies are evident. Dividing the Nyquist interval into 16 equal bins, gives the

16-point DFT.

It so happens that the zeros of the sidelobes of the W(ω−ω

i

) coincide with 16-point DFT fre-

quencies. Taking every other 16-DFT point gives the 8-point DFT. The peak values are correctly

identiﬁed by the 16- and 8-point DFTs because the peak frequencies coincide with DFT frequen-

cies.

203

ω

π 0 2π

|X(ω)| = DTFT = 16-point DFT

= 8-point DFT 24

16

8

Fig. P9.4 DTFT, 16-point and 8-point DFTs.

The 16-point DFT can be determined from the expression of x(n) by comparing it with 16-point

IDFT formula. Multiplying and dividing Eq. (P9.1) by 16, we may extract the DFT coefﬁcients:

X = [8, 0, 0, 0, −16j, 0, 0, 0, 24, 0, 0, 0, 16j, 0, 0, 0]

Every other entry is the 8-point DFT:

X = [8, 0, −16j, 0, 24, 0, 16j, 0]

Problem 9.27

We will showthat the product AA

∗

is proportional to the identity matrix. The ij-th matrix element

of the product is:

(AA

∗

)

ij

=

N−1

_

n=0

A

in

A

∗

nj

=

N−1

_

n=0

W

in

N

W

−jn

N

=

N−1

_

n=0

W

(i−j)n

N

where we used the fact that W

∗

N

= W

−1

N

. Using the results of Problem 9.19, we note that the above

sum will be zero if i }= j. And, it will be equal to N if i = j. Thus, we can write compactly:

(AA

∗

)

ij

=

N−1

_

n=0

W

(i−j)n

N

= Nδ(i −j)

which is equivalent to the matrix relationship

AA

∗

= NI

where I is the N×N identity matrix.

Problem 9.28

Vectorially, the desired equation reads

x

†

x =

1

N

X

†

X

where † denotes conjugate transpose. Using X = Ax and the property

AA

†

= A

†

A = NI

N

, (I

N

= N×N identity matrix)

of the N×N DFT matrix, we obtain

X

†

X = x

†

A

†

Ax = x

†

NI

N

x = Nx

†

x

204

Problem 9.29

First, compute the ordinary linear convolution:

y = h ∗x = [2, −1, −2, 2, −2, −1, 2]

The mod-4 reduction of this is ` y = [0, −2, 0, 2]. The mod-5 reduction is ` y = [1, 1, −2, 2, −2],

the mod-6 reduction is ` y = [4, −1, −2, 2, −2, −1]. Finally, the mod-7 and mod-8 reductions of

y leave it unchanged. One minor detail is that in the mod-8 case, the length should be N = 8, thus,

strictly speaking ` yis ywith one zero padded at the end, that is, ` y = [2, −1, −2, 2, −2, −1, 2, 0].

The minimal N is N = L

y

= L

x

+L

h

−1 = 4 +4 −1 = 7.

Problem 9.30

First, compute the linear convolution of the given signals:

y = h ∗x = [2, 1, 1, 1, 2, 1, 1, 1]∗[2, 1, 2, −3, 2, 1, 2, −3]

= [4, 4, 7, −1, 8, 7, 11, −2, 4, 2, 1, −1, 0, −1, −3]

and wrap it mod-8 to get

˜ y = [8, 6, 8, −2, 8, 6, 8, −2]

Then, compute the FFTs of the two signals:

⎡

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎣

2

1

1

1

2

1

1

1

⎤

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎦

8−FFT

−→

⎡

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎣

10

0

2

0

2

0

2

0

⎤

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎦

,

⎡

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎣

2

1

2

−3

2

1

2

−3

⎤

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎦

8−FFT

−→

⎡

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎣

4

0

−8j

0

12

0

8j

0

⎤

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎦

Multiply them point-wise:

⎡

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎣

10

0

2

0

2

0

2

0

⎤

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎦

×

⎡

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎣

4

0

−8j

0

12

0

8j

0

⎤

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎦

=

⎡

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎣

40

0

−16j

0

24

0

16j

0

⎤

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎦

Divide by N = 8, conjugate every entry, and take an 8-point FFT:

⎡

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎣

5

0

2j

0

3

0

−2j

0

⎤

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎦

8−FFT

−→

⎡

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎣

8

6

8

−2

8

6

8

−2

⎤

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎦

205

Problem 9.31

a. The 8-FFT algorithm gives

x = [6, 1, 0, 1, 6, 1, 0, 1] ⇒ X = [16, 0, 12, 0, 8, 0, 12, 0]

b. Using x(n)=

1

N

N−1

_

k=0

X(k)e

jω

k

n

,

x(n)=

1

8

_

16 +12e

jπn/2

+8e

jπn

+12e

−jπn/2

_

= 2 +3cos

_πn

2

_

+(−1)

n

c. With arbitrary values of a and b:

x = [6 −a, 1, 0, 1, 6, 1, 0, 1, a], x = [6 −a, 1 −b, 0, 1, 6, 1, 0, 1, a, b]

d. Reduce x mod-4 to get ˜ x = [12, 2, 0, 2]. Its 4-FFT is easily found to be X = [16, 12, 8, 12].

It can also be obtained by picking every other entry of the 8-point DFT.

Problem 9.32

Start with

A(k)=

N−1

_

n=0

W

kn

N

a(n)

and evaluate it at N−k

A(N−k)=

N−1

_

n=0

W

(N−k)n

N

a(n)

Noting that W

N

N

= 1, it can be written as

A(N−k)=

N−1

_

n=0

W

−kn

N

a(n)

On the other hand, because a(n) is real

A(k)

∗

=

N−1

_

n=0

_

W

kn

N

_

∗

a(n)

But,

_

W

kn

N

_

∗

= W

−kn

N

Thus,

A(N−k)= A(k)

∗

206

Problem 9.33

Using linearity, we have

X(k)= A(k)+jB(k) ⇒ X(N−k)

∗

= A(N−k)

∗

−jB(N−k)

∗

Using the results of Problem 9.32, A(N−k)

∗

= A(k) and B(N−k)

∗

= B(k), we obtain X(N−

k)

∗

= A(k)−jB(k). Thus, we have the system of equations:

X(k) = A(k)+jB(k)

X(N−k)

∗

= A(k)−jB(k)

which can be solved for A(k) and B(k).

Problem 9.34

The expressions for G(k) and H(k) follow from the results of Problem 9.33, except that the di-

mension of the FFTs is N/2. The ﬁnal expressions that construct X(k) are the standard Butterﬂy

operations for merging G(k) and H(k).

The additional multiplications to build X(k) from Y(k) are 3N/2, (that is, the divisions by 2

and 2j, and multiplications by W

k

N

). Thus the total number of multiplications using this method

compared to a direct N-point FFT will be

1

2

N

2

log

2

(

N

2

)+

3N

2

1

2

Nlog

2

N

=

1

2

+

2.5

log

2

N

If one takes into account the multiplications required for computing the W

k

powers, then the

total becomes

N

2

log

2

(

N

2

)+

4N

2

Nlog

2

N

=

1

2

+

1.5

log

2

N

Typically, 65% of the standard cost for N = 1024.

Problem 9.35

/* fftreal.c - FFT of a real-valued signal */

#include <math.h>

#include <cmplx.h>

#include <stdlib.h>

void fft();

void fftreal(N, x, X)

int N;

double *x; time data

complex *X; FFT array

{

int n, k, Nhalf=N/2;

double pi=4*atan(1.0);

207

complex one, half, halfj, W;

complex *Y, temp, Wk, Gk, Hk;

one = cmplx(1.0, 0.0);

half = cmplx(0.5, 0.0);

halfj = cmplx(0.0, -0.5);

W = cexp(cmplx(0.0, -2*pi/N));

Y = (complex *) calloc(Nhalf, sizeof(complex));

for (n=0; n<Nhalf; n++)

Y[n] = cmplx(x[2*n], x[2*n+1]);

fft(Nhalf, Y);

for (Wk=one, k=0; k<Nhalf; k++) { Wk = W

k

if (k==0)

temp = conjg(Y[0]); note: Y(0) = Y(N/2)

else

temp = conjg(Y[Nhalf-k]);

Gk = cmul(half, cadd(Y[k], temp)); G(k)

Hk = cmul(halfj, csub(Y[k], temp)); H(k)

temp = cmul(Wk, Hk); W

k

H(k)

Wk = cmul(W, Wk); next Wk = W

k+1

X[k] = cadd(Gk, temp); G(k) + W

k

H(k)

X[k+Nhalf] = csub(Gk, temp); G(k) − W

k

H(k)

}

}

Problem 9.36

An example will demonstrate the result. For N = 4, we have:

x = [x

0

, x

1

, x

2

, x

3

] ⇒ X(z)= x

0

+x

1

z

−1

+x

2

z

−2

+x

3

z

−3

x

R

= [x

3

, x

2

, x

1

, x

0

] ⇒ X

R

(z)= x

3

+x

2

z

−1

+x

1

z

−2

+x

0

z

−3

It follows that

X

R

(z)= z

−3

[x

3

z

3

+x

2

z

2

+x

1

z +x

0

]= z

−3

X(z

−1

)

In the time domain, the operation of reﬂection leads to the z-transform pairs:

x(n)

Z

−→X(z) ⇒ x(−n)

Z

−→X(z

−1

)

The operation of delay on the reﬂected signal then gives:

x

R

(n)= x(N−1 −n)= x(−(n −N+1))

Z

−→z

−(N−1)

X(z

−1

)

The N-point DFT of the reversed signal is obtained by setting z = z

k

= e

2πjk/N

= W

−k

N

. Using

the property W

N

N

= 1, we ﬁnd:

X

R

(k)= z

−N+1

k

X(z

−1

k

)= W

(N−1)k

N

X(−k)= W

−k

N

X(N−k)

where in the last step, we used X(z

−1

k

)= X(−ω

k

)= X(−k)= X(N−k) by the periodicity of the

N-point DFT.

208

Problem 9.37

In the deﬁnition of y, the reversed signal x

R

is delayed by N samples, that is, we have

x = [x, x

R

]= [x, 0, 0, . . . , 0

. ¸, .

N zeros

]+[0, 0, . . . , 0

. ¸, .

N zeros

, x

R

]

Thus, using linear superposition, the delay property of z-transforms, and the results of Problem

9.36, we have in the z-domain:

Y(z)= X(z)+z

−N

X

R

(z)= X(z)+z

−2N+1

X(z

−1

)

where the factor z

−N

represents the delay of x

R

by N samples. Replacing z by z

k

= e

jω

k

, and

using the result z

2N

k

= 1, we get

Y

k

= Y(ω

k

)= X(ω

k

)+e

jω

k

X(−ω

k

)= e

jω

k

/2

_

e

−jω

k

/2

X(ω

k

)+e

jω

k

/2

X(−ω

k

)

_

= 2e

jω

k

/2

Re

_

e

−jω

k

/2

X(ω

k

)

_

where we used the hermitian property X(−ω)= X(ω)

∗

. The quantity under the real part is

now:

e

−jω

k

/2

X(ω

k

)= e

−jω

k

/2

N−1

_

n=0

x

n

e

−jω

k

n

=

N−1

_

n=0

x

n

e

−jω

k

(n+1/2)

Thus, its real part is the cosine transform:

Re

_

e

−jω

k

/2

X(ω

k

)

_

=

N−1

_

n=0

x

n

cos

_

ω

k

(n +1/2)

_

= C

k

It follows that

Y

k

= 2e

jω

k

/2

C

k

= 2e

jπk/2N

C

k

Because Y

k

is the (2N)-point DFT of a real-valued signal, it will satisfy the hermitian property

Y

2N−k

= Y

∗

k

. In terms of C

k

, we have:

Y

2N−k

= 2e

jπ(2N−k)/2N

C

2N−k

= 2e

jπ

e

−jπk/2N

C

2N−k

= −2e

−jπk/2N

C

2N−k

Y

∗

k

= 2e

−jπk/2N

C

k

Equating the right-hand sides and canceling the common factors gives the symmetry property

C

2N−k

= −C

k

, k = 0, 1, . . . , 2N−1

At k = N, it gives C

2N−N

= −C

N

or C

N

= −C

N

which implies C

N

= 0. Next, considering the

inverse DFT for Y

k

, we have:

y

n

=

1

2N

2N−1

_

k=0

Y

k

e

jω

k

n

, n = 0, 1, . . . , 2N−1

But the ﬁrst N samples of y

n

are precisely x

n

. Replacing Y

k

in terms of C

k

gives for n =

0, 1, . . . , N−1:

x

n

=

1

2N

2N−1

_

k=0

2e

jω

k

/2

C

k

e

jω

k

n

=

1

N

2N−1

_

k=0

C

k

e

jω

k

(n+1/2)

209

Next, we split the summation into three terms:

x

n

=

1

N

_

C

0

+

N−1

_

k=1

C

k

e

jω

k

(n+1/2)

+

2N−1

_

k=N+1

C

k

e

jω

k

(n+1/2)

_

where the second summation starts at k = N+1 because C

N

= 0. If we change variables from k

to m= 2N−k, we can write

2N−1

_

k=N+1

C

k

e

jω

k

(n+1/2)

=

N−1

_

m=1

C

2N−m

e

jω

2N−m

(n+1/2)

Using the symmetry property C

2N−m

= −C

m

, and the trig identity

e

jω

2N−m

(n+1/2)

= e

jπ(2N−m)(n+1/2)/N

= e

2jπ(n+1/2)

e

−jπm(n+1/2)/N

= −e

−jωm(n+1/2)

we have (with the two minus signs canceling):

N−1

_

m=1

C

2N−m

e

jω

2N−m

(n+1/2)

=

N−1

_

m=1

C

m

e

−jωm(n+1/2)

Thus, the inverse DFT becomes (changing the summation from m back to k):

x

n

=

1

N

_

C

0

+

N−1

_

k=1

C

k

e

jω

k

(n+1/2)

+

N−1

_

k=1

C

k

e

−jω

k

(n+1/2)

_

The two summations now combine with Euler’s formula to give:

x

n

=

1

N

_

C

0

+2

N−1

_

k=1

C

k

cos

_

ω

k

(n +1/2)

__

Problem 9.38

By deﬁnition, we have

X

2N

(k)=

L−1

_

n=0

x(n)W

nk

2N

⇒ X

2N

(2k)=

L−1

_

n=0

x(n)W

2nk

2N

But, W

2nk

2N

= exp

_

−2πj2nk/2N

_

= exp

_

−2πjnk/N

_

= W

nk

N

. Thus,

X

2N

(2k)=

L−1

_

n=0

x(n)W

2nk

2N

=

L−1

_

n=0

x(n)W

nk

N

= X

N

(k)

Problem 9.39

Observe that the ﬁve length-5 sequences are the mod-5 wrapped versions of the following “linearly

shifted” sequences:

x

0

x

1

x

2

x

3

x

4

0 0 0 0 0

0 x

0

x

1

x

2

x

3

x

4

0 0 0 0

0 0 x

0

x

1

x

2

x

3

x

4

0 0 0

0 0 0 x

0

x

1

x

2

x

3

x

4

0 0

0 0 0 0 x

0

x

1

x

2

x

3

x

4

0

210

Their z-transforms differ by a simple delay factor, that is,

X

i

(z)= z

−i

X

0

(z), i = 1, 2, 3, 4

Setting z = z

k

= e

jω

k

= W

−k

5

, we obtain

X

i

(z

k

)= z

−i

k

X

0

(z

k

)= W

ik

5

X

0

(z

k

), i = 1, 2, 3, 4

Problem 9.40

Consider, for example, the ﬁrst and the third. Their z-transforms are

X

1

(z) = x

0

+x

1

z

−1

+x

2

z

−2

+x

3

z

−3

+x

4

z

−4

+x

5

z

−5

+x

6

z

−6

+x

7

z

−7

X

3

(z) = x

0

+x

1

z

−1

+(x

2

+x

6

)z

−2

+(x

3

+x

7

)z

−3

+x

4

z

−4

+x

5

z

−5

Subtracting, we have

X

3

(z)−X

1

(z)= x

6

z

−2

(1 −z

−4

)+x

7

z

−3

(1 −z

−4

)= (x

6

z

−2

+x

7

z

−3

)(1 −z

−4

)

Evaluating at the 4th roots of unity, z = z

k

= e

2πjk/4

, we obtain

X

3

(z

k

)−X

1

(z

k

)= 0, k = 0, 1, 2, 3

Problem 9.41

Using the convolution table, perform the ordinary linear convolution of the given signal and ﬁ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 over-

lapping by M = 3 points, as shown below:

x =

_

1, 1, 1, 1, 3, (3, 3, 3

_

, 1, 1,

_

1, 2, 2), 2, 2, (1, 1, 1

_

, 1, 0, 0, 0, 0)

Convolving these segments with the ﬁlter gives:

y

0

= [1, −1, −1, 1]∗[1, 1, 1, 1, 3, 3, 3, 3] = [1, 0, −1, 0, 2, 0, −2, 0, −3, 0, 3]

y

1

= [1, −1, −1, 1]∗[3, 3, 3, 1, 1, 1, 2, 2] = [3, 0, −3, −2, 0, 2, 1, 0, −3, 0, 2]

y

2

= [1, −1, −1, 1]∗[1, 2, 2, 2, 2, 1, 1, 1] = [1, 1, −1, −1, 0, −1, 0, 1, −1, 0, 1]

y

3

= [1, −1, −1, 1]∗[1, 1, 1, 1, 0, 0, 0, 0] = [1, 0, −1, 0, −1, 0, 1, 0, 0, 0, 0]

Reducing these mod-8 and ignoring their ﬁrst M = 3 points (indicated by x), we obtain:

˜ y

0

= [x, x, x, 0, 2, 0, −2, 0]

˜ y

1

= [x, x, x, −2, 0, 2, 1, 0]

˜ y

2

= [x, x, x, −1, 0, −1, 0, 1]

˜ y

3

= [x, x, x, 0, −1, 0, 1, 0]

Abutting the rest of the points, we get

y = [x, x, x, 0, 2, 0, −2, 0][−2, 0, 2, 1, 0][−1, 0, −1, 0, 1][0, −1, 0, 1, 0]

With the exception of the ﬁrst M points, the answer is correct.

211

Problem 9.42

At f

s

= 8 Hz, there are 8 samples per period. These samples can be evaluated by setting t =

nT = n/8 in the expression for x(t). We ﬁnd:

x(n)=

1

4

¦0, 0.5, 1, 0.5, 0, −0.5, −1, −0.5¦

According to Eq. (9.7.4), the aliased coefﬁcients can be obtained by computing the 8-point DFT

of one period and dividing by 8. This DFT can be done quickly by an 8-point FFT by hand, which

gives:

x =

1

4

⎡

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎣

0

0.5

1

0.5

0

−0.5

−1

−0.5

⎤

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎦

DFT

−→ X =

1

4

⎡

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎣

0

−j(2 +

√

2)

0

j(2 −

√

2)

0

−j(2 −

√

2)

0

j(2 +

√

2)

⎤

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎦

, b =

1

4

⎡

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎣

0

(2 +

√

2)/8j

0

−(2 −

√

2)/8j

0

(2 −

√

2)/8j

0

−(2 +

√

2)/8j

⎤

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎦

The coefﬁcients b

1

and b

7

correspond to frequencies :f

1

= :1 Hz, whereas b

3

and b

5

correspond

to :f

2

= :3 Hz. Thus, we ﬁnd from Eq. (9.7.5) and after using Euler’s formula:

x

al

(t)= 2jb

1

sin(2πf

1

t)+2jb

3

sin(2πf

2

t)=

2 +

√

2

16

sin(2πt)−

2 −

√

2

16

sin(6πt)

It can be veriﬁed easily that x

al

and x(t) agree at the sampling instants t = nT = n/8.

Problem 9.43

In the overlap-add method, the input blocks have length N−M and are non-overlapping. Thus,

if there are K blocks in the total length, we will have:

L = (N−M)K (P9.2)

In Fig. 9.9.1, the input blocks overlap by M points, but again if there are K segments, the total

length will be (N − M)K plus an extra M points at the end. Thus, we have in the overlap-save

method:

L = (N−M)K +M = (N−M)K

which is essentially the same as in Eq. (P9.2) for large L. Thus, in both cases, the total number of

segments can be estimated to be:

K =

L

N−M

Per segment, we are doing two FFTs and N multiplications, namely,

Nlog

2

N+N = N(1 +log

2

N) per segment

Thus, for K segments, we have cost:

KN(1 +log

2

N)=

LN(1 +log

2

N)

N−M

212

This is to be compared with the cost of L(M+1) of linear convolution of the entire input array

with the ﬁlter (here, we treat these MACs as complex-valued.) Thus, the relative cost of the fast

versus slow convolution will be:

fast

slow

=

LN(1 +log

2

N)

N−M

L(M+1)

=

N(1 +log

2

N)

(N−M)(M+1)

Problem 9.44

An example of such a program is given below:

/* ovsave.c - FIR filtering by overlap-save method and FFT */

#include <stdio.h>

#include <cmplx.h>

#include <stdlib.h> calloc(), realloc()

#define MAX 64 initial allocation size

void circonv(), complexify(), fft(), ifft();

void main(int argc, char **argv)

{

FILE *fph; ﬁlter ﬁle

double *h, *x, *xhead; x = length-N block

complex *H, *X, *Y; N-point DFTs

int M, N, n, i;

int max = MAX, dmax = MAX;

if (argc != 3) {

fprintf(stderr, "usage: fastconv hfile N < xfile > yfile\n");

exit(0);

}

if ((fph = fopen(argv[1], "r")) == NULL) {

fprintf(stderr, "can’t open filter file: %s\n", argv[1]);

exit(0);

}

N = atoi(argv[2]);

h = (double *) calloc(max + 1, sizeof(double)); preliminary allocation

for (M=0;; M++) { read h

if (M == max) { reallocate h, if necessary

max += dmax;

h = (double *) realloc((char *) h, (max + 1) * sizeof(double));

}

if (fscanf(fph, "%lf", h + M) == EOF) break;

}

M--; M = ﬁlter order

if (N <= 2*M) {

fprintf(stderr, "must have N > 2M = %d", 2*M);

exit(0);

}

213

h = (double *) realloc((char *) h, (M+1) * sizeof(double));

x = (double *) calloc(N, sizeof(double));

xhead = (double *) calloc(M, sizeof(double)); head/tail of input block

H = (complex *) calloc(N, sizeof(complex)); allocate DFT arrays

X = (complex *) calloc(N, sizeof(complex));

Y = (complex *) calloc(N, sizeof(complex));

for (n=0; n<N; n++) complexify/extend to length N

if (n <= M)

H[n] = cmplx(h[n], 0.0);

else

H[n] = cmplx(0.0, 0.0);

fft(N, H); H = FFT(h), done once

for (n=0; n<M; n++)

xhead[n] = 0; pad M zeros in front of ﬁrst block

for (;;) { keep reading input in blocks x

for (n=0; n<M; n++) previous tail is head of present block x

x[n] = xhead[n];

for (n=M; n<N; n++) read rest of x from input stream

if (scanf("%lf", x + n) == EOF) goto lastblocks;

for (n=0; n<M; n++) tail of present block x

xhead[n] = x[n + N - M]; will be head of next block

complexify(N, x, X); X = cmplx(x, 0)

circonv(N, H, X, Y); done by fft

for (n=M; n<N; n++) discard ﬁrst M points, save the rest

printf("%lf\n", real(Y[n]));

}

lastblocks:

n = index where EOF occurred

for (i=n; i<N; i++) pad rest of x with zeros

x[i] = 0; if n <= N-M there is only

one last block to consider

complexify(N, x, X); otherwise, there are two last blocks

circonv(N, H, X, Y);

for (i=M; i<N; i++)

printf("%lf\n", real(Y[i]));

if (n <= N-M) exit(0); exit, if only one last block

otherwise, process very last block

for (i=0; i<M; i++) if n > N-M, the tail of previous

xhead[i] = x[i + N - M]; block will be non-zero

for (i=0; i<N; i++)

if (i < M)

x[i] = xhead[i]; head of very last block

214

else

x[i] = 0; rest of block is zero

complexify(N, x, X);

circonv(N, H, X, Y);

for (i=M; i<N; i++)

printf("%lf\n", real(Y[i]));

}

——————————————————————–

void complexify(N, x, X)

int N;

double *x;

complex *X;

{

int n;

for (n=0; n<N; n++)

X[n] = cmplx(x[n], 0.0);

}

——————————————————————–

void circonv(N, H, X, Y) circular convolution via FFT

int N;

complex *H, *X, *Y; H = FFT(h), must be done previously

{

int k;

fft(N, X);

for (k=0; k<N; k++)

Y[k] = cmul(H[k], X[k]);

ifft(N, Y);

}

215

Chapter 10 Problems

Problem 10.1

Start with

D(ω)=

∞

_

k=−∞

d(k)e

−jωk

and assume that d(k) is real and even in k. Taking conjugates and replacing ω by −ω, gives

D(−ω)

∗

=

_

∞

_

k=−∞

d(k)e

jωk

_

∗

=

∞

_

k=−∞

d(k)e

−jωk

= D(ω)

This result uses only the reality of d(k) and is the usual hermitian property for transfer functions

of real-valued impulse responses. Because d(k)= d(−k), we can change the summation from k

to −k to get:

D(ω)=

∞

_

k=−∞

d(k)e

−jωk

=

∞

_

k=−∞

d(−k)e

−jω(−k)

=

∞

_

k=−∞

d(k)e

−j(−ω)k

= D(−ω)

Thus, the reality and evenness conditions imply together:

D(ω)= D(−ω)

∗

= D(−ω)

which states that D(ω) is both real and even in ω. In the antisymmetric case, we have d(−k)=

−d(k), and therefore

D(ω)=

∞

_

k=−∞

d(k)e

−jωk

=

∞

_

k=−∞

d(−k)e

−jω(−k)

= −

∞

_

k=−∞

d(k)e

−j(−ω)k

= −D(−ω)

Together with the reality condition, we get

D(ω)= D(−ω)

∗

= −D(−ω)

which implies that D(ω) is pure imaginary and odd in ω. Separating the negative- and positive-k

terms, we can rewrite D(ω) in the form:

D(ω)= d(0)+

∞

_

k=1

d(k)e

−jωk

+

−1

_

k=−∞

d(k)e

−jωk

= d(0)+

∞

_

k=1

d(k)e

−jωk

+

∞

_

k=1

d(−k)e

jωk

In the symmetric case, we set d(−k)= d(k) and combine the two sums with Euler’s formula to

get:

D(ω)= d(0)+2

∞

_

k=1

d(k)cos(ωk) (symmetric case)

For the antisymmetric case, d(0)= 0 because it must satisfy d(−0)= −d(0). Setting d(−k)=

−d(k) in the sum, we obtain:

D(ω)= −2j

∞

_

k=1

d(k)sin(ωk) (antisymmetric case)

216

Problem 10.2

For the bandpass example, we use the fact that D(ω)= 1 over the passband ω

a

≤ ¦ω¦ ≤ ω

b

to

get:

d(k) =

_

π

−π

D(ω)e

jωk

dω

2π

=

_

−ωa

−ω

b

D(ω)e

jωk

dω

2π

+

_

ω

b

ωa

D(ω)e

jωk

dω

2π

=

=

_

−ωa

−ω

b

e

jωk

dω

2π

+

_

ω

b

ωa

e

jωk

dω

2π

=

_

e

jωk

2πjk

_

−ωa

−ω

b

+

_

e

jωk

2πjk

_

ω

b

ωa

=

e

−jωak

−e

−jω

b

k

2πjk

+

e

jω

b

k

−e

jωak

2πjk

=

sin(ω

b

k)−sin(ω

a

k)

πk

Setting ω

a

= 0, gives the lowpass case, and ω

b

= π the highpass one. In the latter, we have:

d(k)=

sin(πk)−sin(ω

b

k)

πk

The ﬁ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)= δ(k)−

sin(ω

a

k)

πk

For the differentiator and Hilbert transformer, see the more general cases of Problem 10.3.

Problem 10.3

For the lowpass differentiator, we have

d(k)=

_

π

−π

D(ω)e

jωk

dω

2π

=

_

ωc

−ωc

jωe

jωk

dω

2π

It can be evaluated either by parts, or by recognizing the integrand as the derivative with respect

to k (treating k initially as a real variable and at the end restricting it to integer values.)

d(k)=

∂

∂k

_

ωc

−ωc

e

jωk

dω

2π

=

∂

∂k

_

sin(ω

c

k)

πk

_

where the ω-integration gave the standard lowpass ﬁlter. Performing the differentiation, we get

the required expression for d(k):

d(k)=

ω

c

cos(ω

c

k)

πk

−

sin(ω

c

k)

πk

2

Setting ω

c

= π gives the full-band differentiator:

d(k)=

cos(πk)

k

−

sin(πk)

πk

2

Because d(k) belongs to the antisymmetric class, it will have d(0)= 0. The second term vanishes

for nonzero integer ks. Thus, we have for k }= 0:

d(k)=

cos(πk)

k

=

(−1)

k

k

(differentiator)

The Hilbert transformer case is similar.

217

Problem 10.4

Using the differentiation argument, we have in this case:

d(k)=

∂

∂k

_

_

−ωa

−ω

b

e

jωk

dω

2π

+

_

ω

b

ωa

e

jωk

dω

2π

_

The integrations give the bandpass ﬁlter case. Thus,

d(k)=

∂

∂k

_

sin(ω

b

k)−sin(ω

a

k)

πk

_

which becomes the difference of two lowpass differentiators:

d(k)=

ω

b

cos(ω

b

k)

πk

−

sin(ω

b

k)

πk

2

−

ω

a

cos(ω

a

k)

πk

+

sin(ω

a

k)

πk

2

Problem 10.5

For the ﬁrst-order differentiator, we have impulse response, transfer function, and frequency

response:

h = [1, −1] ⇒ H(z)= 1 −z

−1

⇒ H(ω)= 1 −e

−jω

Thus, the NRR will be

NRR = h

2

0

+h

2

1

= 1 +1 = 2

Thus, the noise power doubles at the output. To see how closely it resembles the ideal differen-

tiator, we expand the frequency response at low frequencies:

H(ω)= 1 −e

−jω

= 1 −(1 −jω)= jω for small ω

For the ideal lowpass differentiator case, the NRR can be computed as:

NRR =

_

ωc

−ωc

¦D(ω)¦

2

dω

2π

=

_

ωc

−ωc

¦jω¦

2

dω

2π

=

ω

3

c

3π

Thus, it increases rapidly with ω

c

. Compared to the full-band maximum NRR obtained with

ω

c

= π, we have NRR

max

= π

3

/3π = π

2

/3 and therefore,

NRR

NRR

max

=

_

ω

c

π

_

3

Problem 10.6

Let E(ω)= D(ω)−

**D(ω) be the error in the designed ﬁlter. Then, we have
**

E(ω)= D(ω)−

D(ω)=

∞

_

k=−∞

d(k)e

−jωk

−

M

_

k=−M

d(k)e

−jωk

=

_

¦k¦>M

d(k)e

−jωk

because the coefﬁcients d(k) cancel for ¦k¦ ≤ M. Thus, the time-domain coefﬁcients of the error

are:

e(k)=

_

0 if ¦k¦ ≤ M

d(k) if ¦k¦ > M

218

Parseval’s identity applied to e(k) gives then

_

π

−π

¦E(ω)¦

2

dω

2π

=

∞

_

k=−∞

e

2

(k)=

_

¦k¦>M

d

2

(k)

or,

E

M

=

_

π

−π

¦D(ω)−

D(ω)¦

2

dω

2π

=

_

¦k¦>M

d

2

(k)

The right-hand side sumcan be written with the help of Parseval’s identity applied to D(ω) itself:

_

¦k¦>M

d

2

(k)=

∞

_

k=−∞

d

2

(k)−

_

¦k¦≤M

d

2

(k)=

_

π

−π

¦D(ω)¦

2

dω

2π

−

M

_

k=−M

d(k)

2

In the limit as M → ∞, the second term in the right-hand side tends to the Parseval limit, thus

canceling the ﬁrst term and resulting in E

M

→0.

Problem 10.7

From Problem 10.3, we have d(k)= (−1)

k

/k, k }= 0, for the differentiator ﬁlter. Using Parseval’s

identity we have

∞

_

k=−∞

d

2

(k)=

_

π

−π

¦D(ω)¦

2

dω

2π

=

_

π

−π

ω

2

dω

2π

=

π

2

3

But the left-hand side is twice the required sum:

∞

_

k=−∞

d

2

(k)=

_

k}=0

1

k

2

= 2

∞

_

k=1

1

k

2

Thus,

2

∞

_

k=1

1

k

2

=

π

2

3

⇒

∞

_

k=1

1

k

2

=

π

2

6

For the full-band Hilbert transformer, we have

d(k)=

1 −cos(πk)

πk

=

1 −(−1)

k

πk

, k }= 0

Thus, d(k) is nonzero only for odd k, and is in this case d(k)= 2/πk. Parseval’s identity applied

to this ﬁlter gives:

∞

_

k=−∞

d

2

(k)=

_

π

−π

¦D(ω)¦

2

dω

2π

=

_

π

−π

¦jsign(ω)¦

2

dω

2π

=

_

π

−π

1

dω

2π

= 1

The left-hand side on the other hand becomes:

∞

_

k=−∞

d

2

(k)= 2

∞

_

k=1

k=odd

4

π

2

k

2

Thus, we obtain

219

2

∞

_

k=1

k=odd

4

π

2

k

2

= 1 ⇒

∞

_

k=1

k=odd

1

k

2

=

π

2

8

If the sum for all integers k is π

2

/6 and for odd ones π

2

/8, it follows by subtraction that the

sum over even integers will be:

∞

_

k=2

k=even

1

k

2

=

π

2

6

−

π

2

8

=

π

2

24

Problem 10.8

The sinusoidal response of D(ω) in its steady-state form is:

e

jωn

D

−→D(ω)e

jωn

= −jsign(ω)e

jωn

Replacing ω by −ω, and using the odd symmetry property of D(ω), we have:

e

−jωn

D

−→D(−ω)e

−jωn

= jsign(ω)e

−jωn

But cos(ωn)= [e

jωn

+ e

−jωn

]/2. Thus, forming the same linear combination of outputs, we

have:

cos(ωn)

D

−→

1

2

_

−jsign(ω)e

jωn

+jsign(ω)e

−jωn

_

= sign(ω)sin(ωn)

Similarly, because sin(ωn)= [e

jωn

−e

−jωn

]/2j, we have for the outputs:

sin(ωn)

D

−→

1

2j

_

−jsign(ω)e

jωn

−jsign(ω)e

−jωn

_

= −sign(ω)cos(ωn)

Problem 10.9

From the deﬁnition of

D(z), we have:

D(z)=

M

_

k=−M

d(k)z

−k

⇒

D(z

−1

)=

M

_

k=−M

d(k)z

k

=

M

_

k=−M

d(−k)z

−k

where in the last step we changed summation from k to −k. In the symmetric/antisymmetric

cases, we have d(k)= :d(k). Therefore,

D(z

−1

)= :

M

_

k=−M

d(k)z

−k

= :

D(z)

Fromthe reality of d(k), it follows that the zeros will come in conjugate pairs if they are complex.

Thus, if z

0

is a complex zero, then z

∗

0

is also a zero. From the symmetry or antisymmetry

properties, it follows that if z

0

is a zero, then

D(z

−1

0

)= :

D(z

0

)= 0

Thus, 1/z

0

and 1/z

∗

0

are both zeros. The four zeros ¦z

0

, z

∗

0

,

1

z

0

,

1

z

∗

0

¦ are shown in Fig. P10.1.

If z

0

lies on the unit circle then because 1/z

∗

0

= z

0

, the only other distinct zero is the complex

conjugate.

220

z

0

1/z

0

*

1/z

0

z

0

*

Fig. P10.1 Pattern of zeros of linear phase ﬁlters.

In the antisymmetric case, we have in particular for z = :1,

D(:1)=

M

_

k=−M

d(k)(:1)

k

= 0

This follows because d(k) is odd and summed over symmetric limits and because the factor

(:1)

k

is even in k. The same conclusion follows from the frequency response. Using the anti-

symmetry property and splitting the sum in two parts, we get:

D(ω)=

M

_

k=−M

d(k)e

−jωk

=

M

_

k=1

d(k)

_

e

−jωk

−e

jωk

_

= −2j

M

_

k=1

d(k)sin(ωk)

Setting ω= 0, π, corresponding to z = :1, we have sin(ωk)= 0, and therefore,

D(ω) vanishes.

Finally, we note that if d(k) is windowed by a window w(k), that is, d

¹

(k)= w(k)w(k), then

because the window w(k) is symmetric with respect to the origin, the symmetry/antisymmetry

properties of d(k) will be preserved and will imply similar results on the locations of the zeros.

Problem 10.10

For the symmetric case, the following must necessarily be zeros:

z

0

= 0.5 +0.5j, z

∗

0

= 0.5 −0.5j,

1

z

0

= 1 −j,

1

z

∗

0

= 1 +j

Thus, the transfer function will be

H(z)=

_

1−(0.5+0.5j)z

−1

__

1−(0.5−0.5j)z

−1

__

1−(1−j)z

−1

__

1−(1+j)z

−1

_

= 1−3z

−1

+4.5z

−2

−3z

−3

+z

−4

In the time domain, we get the length-5 symmetric (about its middle) impulse response:

h = [1, −3, 4.5, −3, 1]

In the antisymmetric case, we have in addition two zeros at z = :1 contributing a factor (1−z

−2

)

to the transfer function. Thus,

H(z)= (1 −z

−2

)(1 −3z

−1

+4.5z

−2

−3z

−3

+z

−4

)= 1 −3z

−1

+3.5z

−2

−3.5z

−4

+3z

−5

−z

−6

and in the time domain:

h = [1, −3, 3.5, 0, −3.5, 3, −1]

221

The frequency response in the symmetric case is obtained by factoring out a factor of z

−2

and

using Euler’s formula:

H(z)= z

−2

_

z

2

+z

−2

−3(z +z

−1

)+4.5

_

⇒

H(ω)= 2e

−2jω

_

cos(2ω)−3cos(ω)+4.5

_

For the antisymmetric case, we have:

H(z)= z

−3

_

(z

3

−z

−3

)−3(z

2

−z

−2

)+3.5(z −z

−1

)

_

⇒

H(ω)= −2je

−3jω

_

sin(3ω)−3sin(2ω)+3.5sin(ω)

_

Problem 10.11

Proceeding as in the previous problem, we ﬁnd the transfer function of the symmetric case:

H(z)= (1−0.5jz

−1

)(1+0.5jz

−1

)(1−2jz

−1

)(1+2jz

−1

)= 1+4.25z

−2

+z

−4

⇒ h = [1, 0, 4.25, 0, 1]

and for the antisymmetric case:

H(z)= (1−z

−2

)(1+4.25z

−2

+z

−4

)= 1+3.25z

−2

−3.25z

−4

−z

−6

⇒ h = [1, 0, 3.25, 0, −3.25, 0, −1]

Problem 10.12

We use the ﬁrst-order Taylor series approximation:

ln(1 :x)= :x

Changing to base-10, we have:

log

10

(1 :x)=

ln(1 :x)

ln(10)

= :0.4343x

It follows that

A

pass

= 20log

10

_

1 +δ

pass

1 −δ

pass

_

= 20log

10

(1 +δ

pass

)−20log

10

(1 −δ

pass

)

= 20 · 0.4343δ

pass

+20 · 0.4343δ

pass

= 17.372δ

pass

Problem 10.13

First, we calculate δ

pass

and δ

stop

from Eq. (10.2.5):

δ

pass

=

10

0.1/20

−1

10

0.1/20

+1

= 0.0058, δ

stop

= 10

−80/20

= 0.0001

Therefore, δ = min(δ

pass

, δ

stop

)= δ

stop

= 0.0001, which in dB is A = −20log

10

δ = A

stop

= 80.

The D and α parameters are computed by:

α = 0.1102(A−8.7)= 0.1102(80 −8.7)= 7.857, D =

A−7.95

14.36

= 5.017

The transition width is Δf = f

stop

−f

pass

= 2 −1.5 = 0.5 kHz; therefore, the ﬁlter length will be:

N = 1 +

Df

s

Δf

= 1 +

5.017 · 10

0.5

= 101.34 ⇒ N = 103

222

Problem 10.14

The transition width is inversely related to the ﬁlter length N:

Δf =

Df

s

N−1

As in the previous problem, we ﬁnd D = 5.017. Thus,

Δf =

Df

s

N−1

=

5.017 · 10

251 −1

= 0.2007 kHz

Problem 10.15

The window’s width factor is D = 5.017 as in the previous problem. Thus,

Δf =

Df

s

N−1

=

5.017 · 44.1

129 −1

= 1.729 kHz

Conversely, if Δf = 2 kHz, then we may solve for the D-factor and attenuation A:

D =

A−7.95

14.36

= (N−1)

Δf

f

s

= 5.805 ⇒ A = 14.36D+7.95 = 91.31 dB

The corresponding ripple will be

δ = 10

−A/20

= 10

−91.31/20

= 0.000027

which gives the passband attenuation:

A

pass

= 17.372δ = 0.000472 dB

In the 4-times oversampling case, the transition width is required to be:

Δf = 24.55 −19.55 = 5 kHz

This gives the width factor and attenuation:

D =

A−7.95

14.36

= (N−1)

Δf

4f

s

= 3.6281 ⇒ A = 14.36D+7.95 = 60.05 dB

Problem 10.16

Assuming that an N-tap ﬁ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,

N

max

=

T

T

instr

=

f

instr

f

s

Inserting this into the Kaiser design formula, we ﬁnd the minimum width (where we used N

instead of N−1 in the denominator):

Δf =

Df

s

N

=

Df

s

2

f

instr

223

Problem 10.17

Using N = f

instr

/f

s

for the maximum ﬁlter length, we obtain the maximum width parameter D

and attenuation A:

D =

A−7.95

14.36

= N

Δf

f

s

=

f

instr

Δf

f

s

2

= F

instr

ΔF ⇒ A = 14.36F

instr

ΔF +7.95

Problem 10.18

The following MATLAB program segment computes the rectangularly and Hamming windowed

impulse responses with the help of the MATLAB function dlh.m, and then it computes the cor-

responding frequency responses over N

F

equally spaced frequencies over the right half of the

Nyquist interval [0, π] with the help of the function dtft.m:

wc = 0.3 * pi; % cutoff frequency

N = 81; % ﬁlter length

w = 0.54 - 0.46 * cos(2 * pi * (0:N-1) / (N-1)); % Hamming window

hrec = dlh(1, wc, N); % ideal lowpass ﬁlter

hham = w .* hrec; % windowed ﬁlter

NF = 200; % 200 frequencies in rads/sample

omega = (0:NF-1) * pi / NF; % over the interval [0, π]

Hrec = dtft(hrec, omega); % frequency response

Hham = dtft(hham, omega);

Problem 10.19

As an example, the following MATLAB programsegment computes the bandpass ﬁlter of Example

10.2.2 (alternative design):

fs = 20; in kHz

fpa = 4; fpb = 6; fsa = 3; fsb = 8;

Apass = 0.1; Astop = 80; in dB

h = kbp(fs, fpa, fpb, fsa, fsb, Apass, Astop, -1); % s = −1 for alternative design

NF = 200;

omega = (0:NF-1) * pi / NF;

H = dtft(h, omega);

Similarly, the highpass ﬁlter can be designed by:

fs = 20; in kHz

fpass = 5; fstop = 4;

Apass = 0.1; Astop = 80; in dB

h = klh(-1, fs, fpass, fstop, Apass, Astop); % s = −1 for highpass

NF = 200;

omega = (0:NF-1) * pi / NF;

H = dtft(h, omega);

224

Problem 10.20

Use the design MATLAB routine kdiff, with f

s

= 2 so that ω= 2πf/2 = πf, that is, the f’s are

the ω’s in units of π. The ﬁlter lengths depend only on the values of Δf and A, they are:

Δf A N

0.10 30 33

0.10 60 75

0.05 30 63

0.05 60 147

For example, in the case ω

c

= 0.4π, Δω= 0.05π, A = 60 dB, we have the MATLAB code:

h = kdiff(2, 0.4, 0.05, 60);

NF = 200;

omega = (0:NF-1) * pi / NF;

H = dtft(h, omega);

The magnitude responses are shown in Figs. P10.2 and P10.3.

Fig. P10.2 Lowpass differentiator with ω

c

= 0.4π.

225

Fig. P10.3 Lowpass differentiator with ω

c

= 0.8π.

Problem 10.21

For example, in the case ω

c

= 0.4π, Δω= 0.05π, A = 60 dB, we have the MATLAB segment that

computes the Kaiser differentiator and the Savitzky-Golay differentiators of polynomial order

d = 3:

h = kdiff(2, 0.4, 0.05, 60); % Kaiser differentiator

[B, S] = sg(3, N); % Savitzky-Golay smoothing ﬁlters

F = S’ * S; % polynomial basis matrix

G = S * F^(-1); % Savitzky-Golay differentiator ﬁlters

g = G(:,2)’; % ﬁrst-order derivative ﬁlter

NF = 500;

omega = (0:NF-1) * pi / NF;

H = dtft(h, omega); % frequency responses

G = dtft(g, omega);

The magnitude responses are shown in Fig. P10.4.

Problem 10.22

Use the design MATLAB routine khilb, with f

s

= 2 so that ω= 2πf/2 = πf, that is, the f’s are

the ω’s in units of π. The ﬁlter lengths depend only on the values of Δf and A, they are the

226

Fig. P10.4 Comparison of Kaiser and SG differentiators.

same as in Problem 10.20. For example, the Hilbert transformer with ω

c

= 0.8π, Δω = 0.05π,

and A = 60 dB, can be designed by the MATLAB segment:

h = khilb(2, 0.8, 0.05, 60);

NF = 200;

omega = (0:NF-1) * pi / NF;

H = dtft(h, omega); % frequency responses

The magnitude responses are shown in Figs. P10.5 and P10.6.

Problem 10.23

The following MATLAB segment computes the Kaiser and Hamming spectra in dB. The Kaiser

window parameters are determined by the function kparm2.m:

F1 = 0.20; F2 = 0.25; F3 = 0.30; DF = (F2-F1)/3; % units of fs

A1 = 1; A2 = 10^(-50/20); A3 = 1; % amplitudes

R = 70; % sidelobe level in dB

[alpha, L] = kparm2(DF, R); % Kaiser parameters

n = (0:L-1);

x = A1 * cos(2*pi*F1*n) + A2 * cos(2*pi*F2*n) + A3 * cos(2*pi*F3*n);

xk = kwind(alpha, L) .* x; % Kaiser windowed signal

xh = (0.54 - 0.46 * cos(2*pi*n/(L-1))) .* x; % Hamming windowed signal

NF = 256;

omega = (0:NF-1) * pi / NF;

Xk = abs(dtft(xk, omega)); % DTFT spectrum

Xkmax = max(Xk);

Xk = 20 * log10(Xk / Xkmax); % normalized and in dB

Xh = abs(dtft(xh, omega));

227

Fig. P10.5 Lowpass Hilbert transformer with ω

c

= 0.8π.

Xhmax = max(Xh);

Xh = 20 * log10(Xh / Xhmax);

228

Fig. P10.6 Full-band Hilbert transformer.

229

Chapter 11 Problems

Problem 11.1

Here, we assume that the parameter β = tan(Δω/2) remains positive and less than one, 0 ≤

β ≤ 1. This is guaranteed if the bandwidth is 0 ≤ Δω≤ π/2 in rads/sample, or, 0 ≤ Δf ≤ f

s

/4

in Hz. This range covers most practical applications. This condition implies that the poles are

complex conjugate and have radius

R

2

=

1 −β

1 +β

⇒ R =

¸

1 −β

1 +β

(If β > 1, which happens when π/2 < Δω≤ π, then there are two real poles.) It follows that the

-level time constant will be

n

eff

=

ln

lnR

Problem 11.2

For small values of Δω, we may use the ﬁrst-order Taylor expansion tan(x)= x to write approx-

imately:

β = tan

_Δω

2

_

=

Δω

2

Then, expanding R to ﬁrst-order in β and thus to ﬁrst-order in Δω, we have:

R =

¸

1 −β

1 +β

= (1 −

1

2

β)(1 −

1

2

β)= 1 −β = 1 −

Δω

2

where we used the Taylor expansions (1 ∓ x)

:1/2

= 1 − x/2 and (1 − x/2)

2

= 1 − x. Solving for

Δω, we obtain the approximate expression Δω= 2(1 −R).

Problem 11.3

For the 3-dB case, the parameter b is the same for both ﬁlters. Adding the two transfer functions,

we recognize that the two numerators add up to become the denominator:

H

notch

(z)+H

peak

(z) = b

1 −2cos ω

0

z

−1

+z

−2

1 −2bcos ω

0

z

−1

+(2b −1)z

−2

+(1 −b)

1 −z

−2

1 −2bcos ω

0

z

−1

+(2b −1)z

−2

=

b(1 −2cos ω

0

z

−1

+z

−2

)+(1 −b)(1 −z

−2

)

1 −2bcos ω

0

z

−1

+(2b −1)z

−2

=

1 −2bcos ω

0

z

−1

+(2b −1)z

−2

1 −2bcos ω

0

z

−1

+(2b −1)z

−2

= 1

For the magnitude responses squared we may use the equivalent analog expressions to get:

¦H

notch

(ω)¦

2

+¦H

peak

(ω)¦

2

= ¦H

notch

(Ω)¦

2

+¦H

peak

(Ω)¦

2

=

(Ω

2

−Ω

2

0

)

2

(Ω

2

−Ω

2

0

)

2

+α

2

Ω

2

+

α

2

Ω

2

(Ω

2

−Ω

2

0

)

2

+α

2

Ω

2

= 1

230

Problem 11.4

The analog transfer function and magnitude response squared are in the general boost or cut

case:

H(s)=

G

0

(s

2

+Ω

2

0

)+Gαs

s

2

+αs +Ω

2

0

⇒ ¦H(Ω)¦

2

=

G

2

0

(Ω

2

−Ω

2

0

)

2

+G

2

α

2

Ω

2

(Ω

2

−Ω

2

0

)

2

+α

2

Ω

2

where

α = (1 +Ω

2

0

)β = (1 +Ω

2

0

)tan

_

Δω

2

_

¸

¸

¸

_

G

2

B

−G

2

0

G

2

−G

2

B

≡ γ

¸

¸

¸

_

G

2

B

−G

2

0

G

2

−G

2

B

where the last step deﬁnes the parameter γ, which does not depend on the gains. Normalizing

everything to the reference gain G

0

, we have

¦H(Ω)¦

2

= G

2

0

(Ω

2

−Ω

2

0

)

2

+g

2

α

2

Ω

2

(Ω

2

−Ω

2

0

)

2

+α

2

Ω

2

, α = γ

¸

¸

¸

_

g

2

B

−1

g

2

−g

2

B

, where g =

G

G

0

, g

B

=

G

B

G

0

Then, we may express the magnitude squared response in the following formthat explicitly shows

the gains:

¦H(Ω)¦

2

= G

2

0

(Ω

2

−Ω

2

0

)

2

+N(g, g

B

)γ

2

Ω

2

(Ω

2

−Ω

2

0

)

2

+D(g, g

B

)γ

2

Ω

2

where the numerator and denominator gain functions are deﬁned by

N(g, g

B

)= g

2

g

2

B

−1

g

2

−g

2

B

, D(g, g

B

)=

g

2

B

−1

g

2

−g

2

B

For the arithmetic, geometric, and harmonic mean choices for g

2

B

the functions N and Dsimplify

as follows:

g

2

B

=

1 +g

2

2

, N(g, g

B

)= g

2

, D(g, g

B

)= 1, (arithmetic)

g

2

B

= g, N(g, g

B

)= g, D(g, g

B

)=

1

g

, (geometric)

g

2

B

=

2g

2

1 +g

2

, N(g, g

B

)= 1, D(g, g

B

)=

1

g

2

, (harmonic)

Now, if we consider an equal and opposite boost and cut by, say by A dB (with respect to the

reference), then the boost and cut gains will be g = 10

:A/20

. Thus, the substitution g → g

−1

changes a boost into an equal and opposite cut, and vice versa. Even though the boost and

cut gains are equal and opposite, the bandwidth levels g

2

B

may be deﬁned arbitrarily in the two

cases. However, if we take them also to be related by the substitution g

B

→ g

−1

B

, then we can

show that the boost and cut ﬁlters are inverses to each other. Indeed, under the substitutions

¦g, g

B

¦ →¦g

−1

, g

−1

B

¦, the boost and cut magnitude responses are:

¦H

boost

(Ω)¦

2

= G

2

0

(Ω

2

−Ω

2

0

)

2

+N(g, g

B

)γ

2

Ω

2

(Ω

2

−Ω

2

0

)

2

+D(g, g

B

)γ

2

Ω

2

, ¦H

cut

(Ω)¦

2

= G

2

0

(Ω

2

−Ω

2

0

)

2

+N(g

−1

, g

−1

B

)γ

2

Ω

2

(Ω

2

−Ω

2

0

)

2

+D(g

−1

, g

−1

B

)γ

2

Ω

2

Under this substitution, the functions N and D interchange roles, that is, one can show easily

that

N(g

−1

, g

−1

B

)= D(g, g

B

) , D(g

−1

, g

−1

B

)= N(g, g

B

)

231

Therefore, the boost and cut ﬁlters will be:

¦H

boost

(Ω)¦

2

= G

2

0

(Ω

2

−Ω

2

0

)

2

+N(g, g

B

)γ

2

Ω

2

(Ω

2

−Ω

2

0

)

2

+D(g, g

B

)γ

2

Ω

2

, ¦H

cut

(Ω)¦

2

= G

2

0

(Ω

2

−Ω

2

0

)

2

+D(g, g

B

)γ

2

Ω

2

(Ω

2

−Ω

2

0

)

2

+N(g, g

B

)γ

2

Ω

2

Hence, their product will be identically equal to G

4

0

. The geometric-mean and weighted geometric-

mean choices for g

2

B

are special cases of the substitution ¦g, g

B

¦ → ¦g

−1

, g

−1

B

¦, and therefore,

satisfy the desired property. But, any other choice of g

B

will do, as long as one deﬁnes the boost

bandwidth to be g

B

and the cut bandwidth, g

−1

B

, that is, equal and opposite bandwidth gains in

dB. Note, also that the transfer functions themselves are inverses to each other, not just their

magnitudes. Indeed, we can write them in the form:

H

boost

(s)= G

0

s

2

+Ω

2

0

+γs

_

N(g, g

B

)

s

2

+Ω

2

0

+γs

_

D(g, g

B

)

, H

cut

(s)= G

0

s

2

+Ω

2

0

+γs

_

N(g

−1

, g

−1

B

)

s

2

+Ω

2

0

+γs

_

D(g

−1

, g

−1

B

)

= G

0

s

2

+Ω

2

0

+γs

_

D(g, g

B

)

s

2

+Ω

2

0

+γs

_

N(g, g

B

)

which implies for the analog and the bilinearly transformed digital transfer functions:

H

cut

(s)=

G

2

0

H

boost

(s)

⇒ H

cut

(z)=

G

2

0

H

boost

(z)

Problem 11.5

The following MATLAB code segment designs the three ﬁlters (two peaking and one complemen-

tary notch), computes their impulse responses, and their magnitude responses:

w0 = 0.35*pi; Dw = 0.1*pi; in rads/sample

[b1, a1, beta1] = parmeq(0, 1, 1/sqrt(2), w0, Dw); peaking 3-dB width

[b2, a2, beta2] = parmeq(0, 1, sqrt(0.1), w0, Dw); peaking 10-dB width

[b3, a3, beta3] = parmeq(1, 0, 1/sqrt(2), w0, Dw); notching 3-dB width

x = [1, zeros(1, 99)]; unit impulse

h1 = filter(b1, a1, x); impulse responses

h2 = filter(b2, a2, x);

h3 = filter(b3, a3, x);

w = (0:199)*pi/200; 200 frequencies over [0, π]

H1 = abs(dtft(b1, w) ./ dtft(a1, w)).^2; magnitude responses

H2 = abs(dtft(b2, w) ./ dtft(a2, w)).^2;

H3 = abs(dtft(b3, w) ./ dtft(a3, w)).^2;

The 5-percent time constants can be calculated as in Problem 11.1, with = 0.05.

Problem 11.6

For example, the following MATLAB code designs the ﬁrst four ﬁlters of Example 11.4.1 and

computes their impulse response, frequency, and phase responses (in degrees):

[b1, a1, beta1] = parmeq(1, 10^(9/20), 10^(6/20), 0.35*pi, 0.1*pi);

[b2, a2, beta2] = parmeq(1, 10^(9/20), 10^(3/20), 0.35*pi, 0.1*pi);

[b3, a3, beta3] = parmeq(1, 10^(-9/20), 10^(-6/20), 0.60*pi, 0.2*pi);

[b4, a4, beta4] = parmeq(1, 10^(-9/20), 10^(-3/20), 0.60*pi, 0.2*pi);

x = [1, zeros(1, 49)]; length-50 unit impulse

232

h1 = filter(b1, a1, x); impulse responses

h2 = filter(b2, a2, x);

h3 = filter(b3, a3, x);

h4 = filter(b4, a4, x);

w = (0:199)*pi/200;

H1 = dtft(b1, w) ./ dtft(a1, w); argH1 = angle(H1) * 180 / pi;

H2 = dtft(b2, w) ./ dtft(a2, w); argH2 = angle(H2) * 180 / pi;

H3 = dtft(b3, w) ./ dtft(a3, w); argH3 = angle(H3) * 180 / pi;

H4 = dtft(b4, w) ./ dtft(a4, w); argH4 = angle(H4) * 180 / pi;

Figure P11.1 shows the phase responses. Note the rapid variations in the vicinities of the center

frequencies.

Fig. P11.1 Phase responses of Problem 11.6.

Problem 11.7

The following MATLAB function lheq.m implements the design of both the lowpass and highpass

shelving ﬁlters (the parameter s = :1 selects the two cases):

% lheq.m - lowpass/highpass first-order shelving EQ filter design

%

% [b, a, beta] = lheq(s, G0, G, Gc, wc)

%

% s = 1, −1 = lowpass, highpass

% b = [b

0

, b

1

] = numerator coefﬁcients

% a = [1, a

1

] = denominator coefﬁcients

% G

0

, G, Gc = reference, boost/cut, and cutoff gains

% wc = cutoff frequency in [rads/sample]

% beta = design parameter β

function [b, a, beta] = lheq(s, G0, G, Gc, wc)

beta = (tan(wc/2))^s * sqrt(abs(Gc^2 - G0^2)) / sqrt(abs(G^2 - Gc^2));

b = [(G0 + G*beta), -s*(G0 - G*beta)] / (1+beta);

a = [1, -s*(1-beta)/(1+beta)];

The ﬁ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

[b1, a1, beta1] = lheq(1, 0, 1, 1/sqrt(2), 0.2*pi); lowpass cases

[b2, a2, beta2] = lheq(1, 0, 1, sqrt(0.9), 0.2*pi);

[b3, a3, beta3] = lheq(1, 0, 1, 1/sqrt(2), 0.7*pi);

[b4, a4, beta4] = lheq(1, 0, 1, sqrt(0.9), 0.7*pi);

[b5, a5, beta5] = lheq(-1, 0, 1, 1/sqrt(2), 0.2*pi); highpass cases

[b6, a6, beta6] = lheq(-1, 0, 1, sqrt(0.9), 0.2*pi);

omega = (0:199)*pi/200; 200 frequencies in [0, π]

H1 = abs(dtft(b1, omega)./dtft(a1, omega)).^2; magnitude response squared

H5 = abs(dtft(b5, omega)./dtft(a5, omega)).^2;

Problem 11.8

The following MATLAB code generates the ﬁ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 MATLAB’s function

filter and (b) the customized function combfilt.m that uses a circular buffer:

D = 10;

wc = 0.025 * pi;

[a1, b1, c1, beta1] = combeq(1, 10^(9/20), 10^(3/20), D, wc, 1);

[a2, b2, c2, beta2] = combeq(1, 10^(-12/20), 10^(-3/20), D, wc, 1);

omega = (0:399)*2*pi/ 400; 400 frequencies in [0, 2π]

num1 = [b1, zeros(1, D-1), -c1]; numerator coefﬁcients

den1 = [1, zeros(1, D-1), -a1]; denominator coefﬁcients

H1 = dtft(num1, omega) ./ dtft(den1, omega); frequency response

magH1 = 20 * log10(abs(H1)); magnitude response

angH1 = angle(H1) * 180 / pi; phase response in degrees

num2 = [b2, zeros(1, D-1), -c2];

den2 = [1, zeros(1, D-1), -a2];

H2 = dtft(num2, omega) ./ dtft(den2, omega);

magH2 = 20 * log10(abs(H2));

angH2 = angle(H2) * 180 / pi;

x = [1, zeros(1, 199)]; length-200 unit impulse

h1 = filter(num1, den1, x); impulse response

w = zeros(1, D+1); (D+1)-dimensional state vector

q = 0; circular pointer index

for n=0:199,

[y1(n+1), w, q] = combfilt(a1, b1, c1, D, w, q, x(n+1)); note: h1=y1

end

The phase responses of the comb and notch ﬁlters and the impulse response of the comb are

shown in Fig. P11.2.

The canonical realization and the corresponding circular buffer version of the sample processing

algorithm of the transfer function H(z)=

b −cz

−D

1 −az

−D

are given below:

234

Fig. P11.2 Phase responses and impulse response of Problem 11.8.

for each input sample x do:

s

D

= tap(D, w, p, D)

s

0

= x +as

D

y = bs

0

−cs

D

∗p = s

0

cdelay(D, w, &p)

x

y b

a -c

z

-D

s

D

s

0

The following C function combfilt.c is an implementation:

/* combfilt.c - comb filtering with circular buffer */

void cdelay();

double tap();

double combfilt(a, b, c, D, w, p, x)

double a, b, c, *w, **p, x; p passed by address as in cfir.c

int D;

{

double s0, sD, y;

sD = tap(D, w, *p, D); Dth tap output

s0 = x + a * sD; input to D-fold delay

y = b * s0 - c * sD; output sample

**p = s0; update circular delay line

cdelay(D, w, p);

return y;

}

The MATLAB version is the function combfilt.m given below:

% combfilt.m - comb filtering with circular buffer

%

% [y, w, q] = combﬁlt(a, b, c, D, w, q, x);

%

% The ﬁlter parameters [a, b, c] can be obtained from combeq.m

235

%

% It uses cdelay2.m, wrap2.m, tap2.m

% based on combfilt.c

function [y, w, q] = combfilt(a, b, c, D, w, q, x)

sD = tap2(D, w, q, D);

s0 = x + a * sD;

y = b * s0 - c * sD;

w(q+1) = s0;

q = cdelay2(D, q);

It uses the following routine tap2.m that helps extract the components of the circular internal

state vector:

% tap2.m - read ith tap of circular delay-line buffer

%

% si = tap2(D, w, q, i)

%

% w = (D+1)-dimensional

% q = circular index into w

% delay amount i = 0, 1, . . . , D

% based on tap2.c

function si = tap2(D, w, q, i)

si = w(rem(q+i, D+1)+1); % s

i

is delayed output s(n −i)

Problem 11.9

In the FIR case of designing a lowpass ﬁlter, the limits 1 :δ

pass

and :δ

stop

represent the ripples

of the (real-valued) frequency response

D(ω). These translate to the limits for the magnitude

response 1 :δ

pass

in the passband and [0, δ

stop

] in the stopband.

In the IIR case, the deﬁnitions are motivated by the closed-form expressions of the magnitude

response squared in the Butterworth and Chebyshev cases.

Problem 11.10

Because Ω

stop

> Ω

pass

, and N ≥ N

exact

, we have the inequality

_

Ω

stop

Ω

pass

_

2N

>

_

Ω

stop

Ω

pass

_

2Nexact

=

ε

2

stop

ε

2

pass

⇒ 1 +ε

2

pass

_

Ω

stop

Ω

pass

_

2N

> 1 +ε

2

stop

Thus, using Eq. (11.6.14) we have:

A(Ω

stop

)= 10log

10

⎡

⎣

1 +ε

2

pass

_

Ω

stop

Ω

pass

_

2N

⎤

⎦

> 10log

10

(1 +ε

2

stop

)= A

stop

Similarly, if we ﬁx Ω

0

by the stopband speciﬁcation, then we have:

_

Ω

pass

Ω

stop

_

2N

<

_

Ω

pass

Ω

stop

_

2Nexact

=

ε

2

pass

ε

2

stop

⇒ 1 +ε

2

stop

_

Ω

pass

Ω

stop

_

2N

< 1 +ε

2

pass

Then, using Eq. (11.6.15), we have:

236

A(Ω

pass

)= 10log

10

⎡

⎣

1 +ε

2

stop

_

Ω

pass

Ω

stop

_

2N

⎤

⎦

< 10log

10

(1 +ε

2

pass

)= A

pass

Thus, in either case, the speciﬁcations are more than satisﬁed.

Problem 11.11

The call to the MATLAB function lhbutt.m:

[A, B, P] = lhbutt(1, 40, 10, 15, 3, 35);

produces the following cascade matrices

B =

⎡

⎢

⎣

0.5001 0.5001 0

0.3821 2 ×0.3821 0.3821

0.2765 2 ×0.2765 0.2765

⎤

⎥

⎦, A =

⎡

⎢

⎣

1 0.0002 0

1 0.0007 0.5279

1 0.0005 0.1056

⎤

⎥

⎦

Thus, the designed transfer function will be:

H(z)=

0.5001(1 +z

−1

)

1 +0.0002z

−1

·

0.3821(1 +z

−1

)

2

1 +0.0007z

−1

+0.5279z

−2

·

0.2765(1 +z

−1

)

2

1 +0.0005z

−1

+0.1056z

−2

The parameter vector P is:

P = [Ω

pass

, Ω

stop

, ε

pass

, ε

stop

, N

exact

, N, A

stop

, Ω

0

, f

0

]

= [1, 2.4142, 0.9976, 56.2252, 4.57, 5, 38.26, 1.0005, 10.0030]

where A

stop

is the actual stopband attenuation realized by the designed ﬁlter, and f

0

is the 3-

dB cutoff frequency. The apparent discrepancy between the computed 3-dB frequency and the

given 3-dB passband speciﬁcation is accounted for from the fact that the 3-dB frequency Ω

0

or

f

0

is deﬁned to be the frequency where the magnitude squared response drops to one-half its

DC value; this is almost a 3-dB drop, but not exactly. By hand, the design is as follows. First, we

prewarp the physical frequencies:

Ω

pass

= tan

_

ω

pass

2

_

= tan

_

πf

pass

f

s

_

= tan

_

π10

40

_

= tan(0.25π)= 1

Ω

stop

= tan

_

ω

stop

2

_

= tan

_

πf

stop

f

s

_

= tan

_

π15

40

_

= tan(0.375π)= 2.4142

Then, we compute the -parameters:

ε

pass

=

_

10

Apass/10

−1 =

_

10

3/10

−1 = 0.9976, ε

stop

=

_

10

Astop/10

−1 =

_

10

35/10

−1 = 56.2252

and the exact and up-rounded value of N:

N

exact

=

ln(ε

stop

/ε

pass

)

ln(Ω

stop

/Ω

pass

)

=

ln(56.2252/0.9976)

ln(2.4142/1.0000)

= 4.57, N = 5

Then, we calculate the 3-dB Butterworth parameter Ω

0

and invert it to get the 3-dB frequency f

0

:

Ω

0

=

Ω

pass

ε

1/N

pass

=

1

(0.9976)

1/5

= 1.0005, f

0

=

f

s

π

arctan(Ω

0

)= 1.0030 kHz

237

The coefﬁcients of the 2nd-order sections are computed by Eq. (11.6.24). Note that because of

the small discrepancy mentioned above, Ω

0

is not exactly equal to unity, and therefore, the a

1

coefﬁcients of all the sections will not be exactly zero. The Butterworth angles are computed by

θ

i

=

π

2N

(N−1 +2i)=

π

10

(4 +2i), i = 1, 2

which gives

θ

1

= 0.6π, θ

2

= 0.8π

Problem 11.12

The call to lhbutt.m:

[A, B, P] = lhbutt(-1, 10, 3, 2, 0.5, 35);

produces the following cascade matrices

B =

_

0.3414 −2 ×0.3414 0.3414

0.2454 −2 ×0.2454 0.2454

_

, A =

_

1 0.0817 0.4471

1 0.0587 0.0404

_

Thus, the designed transfer function will be:

H(z)=

0.3414(1 −z

−1

)

2

1 +0.0817z

−1

+0.4471z

−2

·

0.2454(1 −z

−1

)

2

1 +0.0587z

−1

+0.0404z

−2

The parameter vector P is:

P = [Ω

pass

, Ω

stop

, ε

pass

, ε

stop

, N

exact

, N, A

stop

, Ω

0

, f

0

]

= [0.7265, 1.3764, 0.3493, 3.0000, 3.37, 4, 13.27, 0.9451, 2.5899]

where A

stop

is the actual stopband attenuation realized by the designed ﬁlter, and f

0

is the 3-dB

cutoff frequency in kHz. The required closed-form expression for part (c) is:

¦H(ω)¦

2

=

1

1 +

_

cot(ω/2)

Ω

0

_

2N

Problem 11.13

The real part of s can be expressed as follows:

Re s =

1

2

(s +s

∗

)=

z

2

−2cz +1

2(z

2

−1)

+

z

∗2

−2cz

∗

+1

2(z

∗2

−1)

=

(z

2

−2cz +1)(z

∗2

−1)+(z

∗2

−2cz

∗

+1)(z

2

−1)

2(z

2

−1)(z

2

−1)

∗

=

¦z¦

4

−1 −c(z +z

∗

)(¦z¦

2

−1)

¦z

2

−1¦

2

=

(¦z¦

2

−1)(¦z¦

2

−c(z +z

∗

)+1)

¦z

2

−1¦

2

where in the last step we factored ¦z¦

4

− 1 = (¦z¦

2

− 1)(¦z¦

2

+ 1). Because ¦c¦ ≤ 1, the second

factor of the numerator is non-negative. Indeed, noting that (z +z

∗

) is real-valued, we have:

¦c(z +z

∗

)¦ ≤ ¦z +z

∗

¦ ≤ ¦z¦ +¦z

∗

¦ = 2¦z¦ ⇒ −2¦z¦ ≤ c(z +z

∗

)≤ 2¦z¦

Adding ¦z¦

2

+1 to both sides we get the inequality:

¦z¦

2

−2¦z¦+1 ≤ ¦z¦

2

−c(z+z

∗

)+1 ≤ ¦z¦

2

+2¦z¦+1 ⇒ 0 ≤ (¦z¦−1)

2

≤ ¦z¦

2

−c(z+z

∗

)+1 ≤ (¦z¦+1)

2

Therefore, the sign of Re s is the same as the sign of the factor (¦z¦

2

−1), and the desired result

follows.

238

Problem 11.14

Using a trig identity, we obtain:

¦ sin(ω

1

+ω

2

)¦ = ¦ sinω

1

cos ω

2

+sinω

2

cos ω

1

¦ ≤ ¦ sinω

1

¦¦ cos ω

2

¦ +¦ sinω

2

¦¦ cos ω

1

¦

≤ ¦ sinω

1

¦ +¦ sinω

2

¦ = sinω

1

+sinω

2

where we used the inequalities ¦ cos ω

1

¦ ≤ 1 and ¦ cos ω

2

¦ ≤ 1 and the fact that sinω

1

and sinω

2

are non-negative for values of their arguments in the range [0, π]. Thus, the above inequality

implies ¦c¦ ≤ 1.

Problem 11.15

Here, the Butterworth ﬁlter order is given to be N = 3. Thus, there remains only the parameter

Ω

0

to be ﬁxed. The normalized passband frequencies are

ω

pa

=

2πf

pa

f

s

=

2π2

20

= 0.2π, ω

pb

=

2πf

pb

f

s

=

2π8

20

= 0.8π

Because they add up to π, the bilinear transformation parameter c will be zero, as follows from

the equation

c =

sin(ω

pa

+ω

pb

)

sinω

pa

+sinω

pb

= 0

Thus, the bilinear transformation will be here:

s =

1 +z

−2

1 −z

−2

The analog passband frequency will be:

Ω

pass

=

c −cos ω

pb

sinω

pb

= −cot ω

pb

= 1.3764

The ε

pass

parameter is calculated to be:

ε

pass

=

_

10

Apass/10

−1 =

_

10

0.5/10

−1 = 0.3493

which implies for Ω

0

:

Ω

0

=

Ω

pass

ε

1/N

pass

=

1.3764

0.3493

1/3

= 1.9543

The coefﬁcients of the second- and fourth-order digital ﬁlter sections are calculated fromEqs. (11.6.43)

and (11.6.41), where the there is only one Butterworth angle, namely,

θ

1

=

π

2N

(N−1 +2)=

2π

3

⇒ cos θ

1

= −0.5

We ﬁnd for the second-order section:

G

0

= 0.6615, a

01

= 0, a

02

= −0.3230

and the fourth-order section:

G

1

= 0.5639, a

11

= 0, a

12

= −0.8325, a

13

= 0, a

14

= 0.4230

resulting in the transfer function:

H(z)=

0.6615(1 −z

−2

)

1 −0.3230z

−2

·

0.5639(1 −z

−2

)

2

1 −0.8325z

−2

+0.4230z

−4

The 3-dB frequencies are calculated from Eq. (11.6.44) with c = 0. We ﬁnd:

f

0a

= 1.5054 kHz, f

0b

= 8.4946 kHz

239

Problem 11.16

We have:

1

1 −2

s

Ω

0

cos θ

i

+

s

2

Ω

2

0

=

Ω

2

0

Ω

2

0

−2sΩ

0

cos θ

i

+s

2

=

Ω

2

0

Ω

2

0

−2

_

1 −z

−1

1 +z

−1

_

Ω

0

cos θ

i

+

_

1 −z

−1

1 +z

−1

_

2

=

Ω

2

0

(1 +z

−1

)

2

Ω

2

0

(1 +z

−1

)

2

−2(1 −z

−1

)(1 +z

−1

)Ω

0

cos θ

i

+(1 −z

−1

)

2

=

Ω

2

0

(1 +z

−1

)

2

Ω

2

0

(1 +2z

−1

+z

−2

)−2(1 −z

−2

)Ω

0

cos θ

i

+(1 −2z

−1

+z

−2

)

=

Ω

2

0

(1 +z

−1

)

2

(1 −2Ω

0

cos θ

i

+Ω

2

0

)+2(Ω

2

0

−1)z

−1

+(1 +2Ω

0

cos θ

i

+Ω

2

0

)z

−2

=

G

i

(1 +z

−1

)

2

1 +a

i1

z

−1

+a

i2

z

−2

where the ﬁnal result was obtained by dividing numerator and denominator by the factor (1 −

2Ω

0

cos θ

i

+Ω

2

0

) in order to make the constant coefﬁcient of the denominator unity.

The highpass case is obtained by replacing z

−1

by −z

−1

, which effectively changes the sign of the

a

i1

coefﬁcient. The bandpass case can be done in a similar, but more tedious, fashion.

Problem 11.17

The right 3-dB frequency is obtained by solving the equation

c −cos ω

0b

sinω

0b

= Ω

0

Using the trig identities

cos ω

0b

=

1 −tan

2

(ω

0b

/2)

1 +tan

2

(ω

0b

/2)

, sinω

0b

=

2tan(ω

0b

/2)

1 +tan

2

(ω

0b

/2)

The above equation reduces to the quadratic equation in the variable t = tan(ω

0b

/2):

c −

1 −t

2

1 +t

2

2t

1 +t

2

= Ω

0

⇒ (1 +c)t

2

−2Ω

0

t −(1 −c)= 0

which has positive solution:

t =

Ω

0

+

_

Ω

2

0

+(1 −c)(1 +c)

1 +c

implying for the 3-dB frequency

tan

_

ω

0b

2

_

= tan

_

πf

0b

f

s

_

=

_

Ω

2

0

+1 −c

2

+Ω

0

1 +c

⇒ f

0b

=

f

s

π

arctan

⎛

⎜

⎝

_

Ω

2

0

+1 −c

2

+Ω

0

1 +c

⎞

⎟

⎠

The left 3-dB frequency is obtained by replacing Ω

0

by −Ω

0

in the above solution.

240

Problem 11.18

Matching the stopband speciﬁcations exactly means that the stopband frequencies ω

sa

, ω

sb

map

onto :Ω

stop

and that at Ω

stop

the attenuation is exactly A

stop

. The ﬁrst requirement implies

−Ω

stop

=

c −cos ω

sa

sinω

sa

Ω

stop

=

c −cos ω

sb

sinω

sb

which can be solve for c and Ω

stop

:

c =

sin(ω

sa

+ω

sb

)

sinω

sa

+sinω

sb

, Ω

stop

=

¸

¸

¸

¸

c −cos ω

sb

sinω

sb

¸

¸

¸

¸

Given the value of c, we compute next the two candidates for Ω

pass

:

Ω

pa

=

c −cos ω

pa

sinω

pa

, Ω

pb

=

c −cos ω

pb

sinω

pb

Ideally, we would like have Ω

pb

= Ω

pass

and Ω

pa

= −Ω

pass

. But this is impossible because c has

already been ﬁxed. Because the Butterworth magnitude response is a monotonically decreasing

function of Ω, it is enough to choose the widest of the two passbands deﬁned above. Thus, we

deﬁne:

Ω

pass

= max

_

¦Ω

pa

¦, ¦Ω

pb

¦

_

Once we have computed Ω

pass

and Ω

stop

, we design our Butterworth analog ﬁlter; that is, compute

N and Ω

0

from

N

exact

=

ln(ε

stop

/ε

pass

)

ln(Ω

stop

/Ω

pass

)

, N = ¦N

exact

|, Ω

0

=

Ω

stop

ε

1/N

stop

where the equation for Ω

0

matches the stopband speciﬁcation exactly. The digital ﬁlter coef-

ﬁcients are then computed in terms of N and Ω

0

as usual. The following MATLAB function

bpbutt2.m implements the above procedure and is an alternative to bpsbutt.m:

% bpbutt2.m - bandpass Butterworth digital filter design

%

% [A, B, P] = bpbutt2(fs, fpa, fpb, fsa, fsb, Apass, Astop)

%

% alternative to bpsbutt.m

% it matches stopbands and uses worst passband.

%

% design parameters:

% P = [Wpass, Wstop, Wpa, Wpb, c, fc, epass, estop, Nex, N, Apass, W0, f0a, f0b];

% A,B are Kx5 matrices of cascade of 4th/2nd order sections

function [A, B, P] = bpbutt2(fs, fpa, fpb, fsa, fsb, Apass, Astop)

c = sin(2*pi*(fsa + fsb) / fs) / (sin(2*pi*fsa / fs) + sin(2*pi*fsb / fs));

fc = 0.5 * (fs/pi) * acos(c);

Wstop = abs((c - cos(2*pi*fsb / fs)) / sin(2*pi*fsb / fs));

Wpa = (c - cos(2*pi*fpa / fs)) / sin(2*pi*fpa / fs);

Wpb = (c - cos(2*pi*fpb / fs)) / sin(2*pi*fpb / fs);

241

Wpass = max(abs(Wpa), abs(Wpb));

epass = sqrt(10.0^(Apass/10) - 1);

estop = sqrt(10.0^(Astop/10) - 1);

Nex = log(estop/epass) / log(Wstop/Wpass);

N = ceil(Nex);

r = rem(N,2);

K = (N - r) / 2;

W0 = Wstop * (estop^(-1/N));

Apass = 10 * log10(1 + (Wpass/W0)^(2*N));

f0a = (fs/pi) * atan((sqrt(W0^2 - c^2 + 1) - W0)/(c+1));

f0b = (fs/pi) * atan((sqrt(W0^2 - c^2 + 1) + W0)/(c+1));

P = [Wpass, Wstop, Wpa, Wpb, c, fc, epass, estop, Nex, N, Apass, W0, f0a, f0b];

if r==1,

G = W0 / (1 + W0);

a1 = -2 * c / (1 + W0);

a2 = (1 - W0) / (1 + W0);

B(1,:) = G * [1, 0, -1, 0, 0];

A(1,:) = [1, a1, a2, 0, 0];

else

B(1,:) = [1, 0, 0, 0, 0];

A(1,:) = [1, 0, 0, 0, 0];

end

for i=1:K,

th = pi * (N - 1 + 2 * i) / (2 * N);

D = 1 - 2 * W0 * cos(th) + W0^2;

G = W0^2 / D;

a1 = 4 * c * (W0 * cos(th) - 1) / D;

a2 = 2 * (2*c^2 + 1 - W0^2) / D;

a3 = - 4 * c * (W0 * cos(th) + 1) / D;

a4 = (1 + 2 * W0 * cos(th) + W0^2) / D;

B(i+1,:) = G * [1, 0, -2, 0, 1];

A(i+1,:) = [1, a1, a2, a3, a4];

end

Similarly, the function bpcheb2a.m is an alternative to the bandpass Chebyshev type-2 design

function bpcheb2.m:

% bpcheb2a.m - alternative bandpass Chebyshev type 2 digital filter design

%

% [A, B, P] = bpcheb2a(fs, fpa, fpb, fsa, fsb, Apass, Astop)

%

% alternative to bpcheb2.m

% matches stopbands instead of passbands

%

% design parameters:

% P = [Wpass, Wstop, Wpa, Wpb, c, epass, estop, Nex, N, f3a, f3b, a];

% A, B are Kx5 matrices of cascade 4th/2nd order sections

function [A, B, P] = bpcheb2a(fs, fpa, fpb, fsa, fsb, Apass, Astop)

242

c = sin(2*pi*(fsa + fsb) / fs) / (sin(2*pi*fsa / fs) + sin(2*pi*fsb / fs));

Wstop = abs((c - cos(2*pi*fsb / fs)) / sin(2*pi*fsb / fs));

Wpa = (c - cos(2*pi*fpa / fs)) / sin(2*pi*fpa / fs);

Wpb = (c - cos(2*pi*fpb / fs)) / sin(2*pi*fpb / fs);

Wpass = max(abs(Wpa), abs(Wpb));

epass = sqrt(10.0^(Apass/10) - 1);

estop = sqrt(10.0^(Astop/10) - 1);

Nex = acosh(estop/epass) / acosh(Wstop/Wpass);

N = ceil(Nex);

r = rem(N,2);

K = (N - r) / 2;

a = asinh(estop) / N;

W3 = Wstop / cosh(acosh(estop)/N);

f3a = (fs/pi) * atan((sqrt(W3^2 - c^2 + 1) - W3)/(c+1));

f3b = (fs/pi) * atan((sqrt(W3^2 - c^2 + 1) + W3)/(c+1));

P = [Wpass, Wstop, Wpa, Wpb, c, epass, estop, Nex, N, f3a, f3b, a];

W0 = sinh(a) / Wstop;

if r==1,

G = 1 / (1 + W0);

a1 = -2 * c * W0 / (1 + W0);

a2 = -(1 - W0) / (1 + W0);

B(1,:) = G * [1, 0, -1, 0, 0];

A(1,:) = [1, a1, a2, 0, 0];

else

B(1,:) = [1, 0, 0, 0, 0];

A(1,:) = [1, 0, 0, 0, 0];

end

for i=1:K,

th = pi * (N - 1 + 2 * i) / (2 * N);

Wi = sin(th) / Wstop; % reciprocal of text

D = 1 - 2 * W0 * cos(th) + W0^2 + Wi^2;

G = (1 + Wi^2) / D;

b1 = - 4 * c * Wi^2 / (1 + Wi^2);

b2 = 2 * (Wi^2 * (2*c*c+1) - 1) / (1 + Wi^2);

a1 = 4 * c * (W0 * cos(th) - W0^2 - Wi^2) / D;

a2 = 2 * ((2*c*c + 1)*(W0^2 + Wi^2) - 1) / D;

a3 = - 4 * c * (W0 * cos(th) + W0^2 + Wi^2) / D;

a4 = (1 + 2 * W0 * cos(th) + W0^2 + Wi^2) / D;

B(i+1,:) = G * [1, b1, b2, b1, 1];

A(i+1,:) = [1, a1, a2, a3, a4];

end

243

Problem 11.19

We work with the type-2 design since it has more complicated numerator. The transformation of

the analog second-order sections is as follows:

1 +Ω

i

−2

s

2

1 −2Ω

−1

0

cos θ

i

s +(Ω

−2

0

+Ω

i

−2

)s

2

=

(1 +z

−1

)

2

+Ω

i

−2

(1 −z

−1

)

2

(1 +z

−1

)

2

−2Ω

−1

0

cos θ

i

(1 −z

−1

)(1 +z

−1

)+(Ω

−2

0

+Ω

i

−2

)(1 −z

−1

)

2

=

(1 +Ω

i

−2

)+2(1 −Ω

i

−2

)z

−1

+(1 +Ω

i

−2

)z

−2

(1 −2Ω

−2

0

cos θ

i

+Ω

−2

0

+Ω

i

−2

)+2(1 −Ω

−2

0

−Ω

i

−2

)z

−1

+(1 +2Ω

−2

0

cos θ

i

+Ω

−2

0

+Ω

i

−2

)z

−2

=

G

i

(1 +b

i1

z

−1

+z

−2

)

1 +a

i1

z

−1

+a

i2

z

−2

where the ﬁnal step follows by dividing the numerator by the factor (1 +Ω

i

−2

) and the denomi-

nator by (1 −2Ω

−2

0

cos θ

i

+Ω

−2

0

+Ω

i

−2

).

Problem 11.20

The s-domain poles are

s

i

= Ω

pass

sinha cos θ

i

+jΩ

pass

cosha sinθ

i

= Ω

0

cos θ

i

+jΩ

i

cosha

It follows that

¦s

i

¦

2

= Ω

2

0

cos

2

θ

i

+Ω

i

2

cosh

2

a = Ω

2

0

(1 −sin

2

θ

i

)+Ω

i

2

(1 +sinh

2

a)

= Ω

2

0

+Ω

i

2

+(Ω

2

0

sin

2

θ

i

−Ω

i

2

sinh

2

a)= Ω

2

0

+Ω

i

2

where the last two terms canceled because

Ω

0

sinθ

i

= Ω

pass

sinhasinθ

i

= Ω

i

sinha

Problem 11.21

The following C functions sos4.c and cas4.c implement the sample-by-sample processing al-

gorithm of the cascade of fourth-order sections:

/* sos4.c - IIR filtering by single (canonical) fourth-order section */

double sos4(a, b, w, x) a, b, w are 5-dimensional

double *a, *b, *w, x; a[0]= 1 always

{

double y;

w[0] = x - a[1]*w[1] - a[2]*w[2] - a[3]*w[3] - a[4]*w[4];

y = b[0]*w[0] + b[1]*w[1] + b[2]*w[2] + b[3]*w[3] + b[4]*w[4];

w[4] = w[3]; could replace these updates by

w[3] = w[2]; the single call to

w[2] = w[1]; delay(4, w);

w[1] = w[0];

return y;

}

and

244

/* cas4.c - IIR filtering in cascade of fourth-order sections */

double sos4(); single 4th-order section

double cas4(K, A, B, W, x)

int K;

double **A, **B, **W, x; A, B, W are K×5 matrices

{

int i;

double y;

y = x; initial input to ﬁrst SOS4

for (i=0; i<K; i++)

y = sos4(A[i], B[i], W[i], y); output of ith section

return y; ﬁnal output from last SOS4

}

The K ×5 matrices A and B are generated by the ﬁlter design MATLAB functions, such as bps-

butt.m, bpcheb2.m, or bscheb2.m, and can be passed as inputs to the above C functions. This

can be done by saving the A and B outputs of the MATLAB functions into ASCII ﬁ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>

#define MAX 64 initial allocation size

double cas4();

void main(int argc, char **argv)

{

FILE *fpa, *fpb; coefﬁcient ﬁles

double **A, **B, **W, x, y;

double *a; temporary coefﬁcient array

int M, K, i, j, m;

int max = MAX, dmax = MAX; allocation and increment

if (argc != 3) {

fprintf(stderr, "Usage: casfilt4 A.dat B.dat <x.dat >y.dat\n");

exit(0);

}

if ((fpa = fopen(argv[1], "r")) == NULL) {

fprintf(stderr, "Can’t open filter file: %s\n", argv[1]);

exit(0);

}

if ((fpb = fopen(argv[2], "r")) == NULL) {

fprintf(stderr, "Can’t open filter file: %s\n", argv[2]);

exit(0);

}

a = (double *) calloc(max + 1, sizeof(double));

245

for (M=0;; M++) {

if (M == max) {

max += dmax;

a = (double *) realloc((char *) a, (max + 1) * sizeof(double));

}

if (fscanf(fpa, "%lf", a + M) == EOF) break;

}

a = (double *) realloc((char *) a, (M + 1) * sizeof(double));

if (M%5 != 0) {

fprintf(stderr, "all rows of A must be 5-dimensional");

exit(0);

}

else

K = M / 5; number of SOS4

A = (double **) calloc(K, sizeof(double *)); allocate K rows

B = (double **) calloc(K, sizeof(double *));

W = (double **) calloc(K, sizeof(double *)); states of each SOS4

for (i=0; i<K; i++) {

A[i] = (double *) calloc(5, sizeof(double)); each row is 5-dim

B[i] = (double *) calloc(5, sizeof(double));

W[i] = (double *) calloc(5, sizeof(double));

}

for(i=0; i<K; i++) form A matrix

for(j=0; j<5; j++)

A[i][j] = a[5*i + j];

for(i=0; i<K; i++) read B matrix

for(j=0; j<5; j++)

fscanf(fpb, "%lf", B[i] + j);

while(scanf("%lf", &x) != EOF) { process input samples

y = cas4(K, A, B, W, x);

printf("%lf\n", y);

}

}

The MATLAB version of sos4 is as follows:

% sos4.m - fourth order section

%

% [y, w] = sos4(b, a, w, x)

%

% b = [b0, b1, b2, b3, b4] = 5-dim numerator (row vector)

% a = [1, a1, a2, a3, a4] = 5-dim denominator (row vector)

% w = [w0, w1, w2, w3, w4] = 5-dim ﬁlter state (row vector)

% x = scalar input

% y = scalar output

function [y, w] = sos4(b, a, w, x)

w(1) = x - a(2:5) * w(2:5)’;

y = b * w’;

w = delay(4, w);

The MATLAB version of cas4:

246

% cas4.m - cascade of fourth order sections

%

% [y, W] = cas4(K, B, A, W, x)

%

% B = Kx5 numerator matrix

% A = Kx5 denominator matrix

% W = Kx5 state matrix

% x = scalar input

% y = scalar output

function [y, W] = cas4(K, B, A, W, x)

y = x;

for i = 1:K,

[y, W(i,:)] = sos4(B(i,:), A(i,:), W(i,:), y);

end

The MATLAB version of casfilt4 for ﬁ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 = casﬁlt4(B, A, x)

%

% B = Kx5 numerator matrix

% A = Kx5 denominator matrix

% x = row vector input

% y = row vector output

function y = casfilt4(B, A, x)

[K, K1] = size(A);

[N1, N] = size(x);

W = zeros(K,5);

for n = 1:N,

[y(n), W] = cas4(K, B, A, W, x(n));

end

Problem 11.22

The following MATLAB code designs the pairs of lowpass, highpass, bandpass, and bandstop

Butterworth ﬁ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); stringent case

Astop = -10*log10(0.02);

[A1, B1, P1] = lhbutt(1, 20, 4, 5, 0.5, 10); lowpass

[A2, B2, P2] = lhbutt(1, 20, 4, 5, Apass, Astop); lowpass

[A3, B3, P3] = lhbutt(-1, 20, 5, 4, 0.5, 10); highpass

[A4, B4, P4] = lhbutt(-1, 20, 5, 4, Apass, Astop); highpass

[A5, B5, P5] = bpsbutt(1, 20, 2, 4, 1.5, 4.5, 0.5, 10); bandpass

[A6, B6, P6] = bpsbutt(1, 20, 2, 4, 1.5, 4.5, Apass, Astop); bandpass

247

[A7, B7, P7] = bpsbutt(-1, 20, 1.5, 4.5, 2, 4, 0.5, 10); bandstop

[A8, B8, P8] = bpsbutt(-1, 20, 1.5, 4.5, 2, 4, Apass, Astop); bandstop

om = (0:199) * pi / 200; 200 frequencies in [0, π]

a5 = cas2can(A5); bandpass case

b5 = cas2can(B5);

H5 = dtft(b5, om)./dtft(a5, om); frequency response

argH5 = angle(H5) * 180 / pi; phase response (in degrees)

x = [1, zeros(1, 99)]; length-100 unit impulse

h5 = casfilt4(B5, A5, x); impulse response

y5 = filter(b5, a5, x); conventional method. Note, y5=h5

The computed phase and impulse responses are shown in Fig. P11.3. Notice how the phase

response is almost linear within its passband.

Fig. P11.3 Phase and impulse responses of (the less stringent) bandpass ﬁlter of Problem 11.22.

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); stringent case

Astop = -10*log10(0.02);

[A1, B1, P1] = lhcheb1(1, 20, 4, 5, 0.5, 10); LP type 1

[A2, B2, P2] = lhcheb1(1, 20, 4, 5, Apass, Astop); LP type 1

[A3, B3, P3] = lhcheb1(-1, 20, 5, 4, 0.5, 10); HP type 1

[A4, B4, P4] = lhcheb1(-1, 20, 5, 4, Apass, Astop); HP type 1

[A5, B5, P5] = lhcheb2(1, 20, 4, 5, 0.5, 10); LP type 2

[A6, B6, P6] = lhcheb2(1, 20, 4, 5, Apass, Astop); LP type 2

[A7, B7, P7] = bpcheb2(20, 2, 4, 1.5, 4.5, 0.5, 10); BP type 2

[A8, B8, P8] = bpcheb2(20, 2, 4, 1.5, 4.5, Apass, Astop); BP type 2

248

[A9, B9, P9] = bscheb2(20, 1.5, 4.5, 2, 4, 0.5, 10); BS type 2

[A10, B10, P10] = bscheb2(20, 1.5, 4.5, 2, 4, Apass, Astop); BS type 2

om = (0:199) * pi / 200; 200 frequencies in [0, π]

a7 = cas2can(A7); bandpass case

b7 = cas2can(B7);

H7 = dtft(b7, om) ./ dtft(a7, om); frequency response

argH7 = angle(H7) * 180 / pi; phase response (in degrees)

x = [1, zeros(1, 99)]; length-100 unit impulse

h7 = casfilt4(B7, A7, x); impulse response

y7 = filter(b7, a7, x); conventional method. Note, y7=h7

The computed phase and impulse responses are shown in Fig. P11.4. Note that the Chebyshev

phase response is not as linear within its passband.

Fig. P11.4 Phase and impulse responses of (the less stringent) bandpass ﬁlter of Problem 11.23.

249

Chapter 12 Problems

Problem 12.1

The low-rate transfer functions, D

i

(z) and H

i

(z)= z

−2

D

i

(z), corresponding to Eq. (12.4.2) will

be:

D

0

(z) = 1

D

1

(z) = −0.13z

2

+0.30z +0.90 −0.18z

−1

D

2

(z) = −0.21z

2

+0.64z +0.64 −0.21z

−1

D

3

(z) = −0.18z

2

+0.90z +0.30 −0.13z

−1

H

0

(z) = z

−2

H

1

(z) = −0.13 +0.30z

−1

+0.90z

−2

−0.18z

−3

H

2

(z) = −0.21 +0.64z

−1

+0.64z

−2

−0.21z

−3

H

3

(z) = −0.18 +0.90z

−1

+0.30z

−2

−0.13z

−3

Setting z = ζ

4

and using Eq. (12.2.15), we obtain the transfer function D(ζ), which is recognized

as the double-sided ζ-transform of the sequence d given in Eq. (12.4.1):

D(ζ)=D

0

(ζ

4

)+ζ

−1

D

1

(ζ

4

)+ζ

−2

D

2

(ζ

4

)+ζ

−3

D

3

(ζ

4

)

=1 +ζ

−1

(−0.13ζ

8

+0.30ζ

4

+0.90 −0.18ζ

−4

)

+ζ

−2

(−0.21ζ

8

+0.64ζ

4

+0.64 −0.21ζ

−4

)

+ζ

−3

(−0.18ζ

8

+0.90ζ

4

+0.30 −0.13ζ

−4

)

=1 +0.90(ζ +ζ

−1

)+0.64(ζ

2

+ζ

−2

)+0.30(ζ

3

+ζ

−3

)

−0.18(ζ

5

+ζ

−5

)−0.21(ζ

6

+ζ

−6

)−0.13(ζ

7

+ζ

−7

)

Problem 12.2

In this case, L = 2 and we choose M = 2, so that N = 2LM+1 = 9. The ideal impulse response

is:

d(k

¹

)=

sin(πk

¹

/2)

πk

¹

/2

, −4 ≤ k

¹

≤ 4

or, numerically,

h = d = [0, −0.21, 0, 0.64, 1, 0.64, 0, −0.21, 0 ]

It is depicted in Fig. P12.1.

The two polyphase subﬁlters are deﬁned by Eq. (12.2.10), that is, for i = 0, 1,

d

i

(k)= d(2k +i), −2 ≤ k ≤ 1

They can be extracted from h by taking every second entry, starting with the ith entry:

h

0

= d

0

= [0, 0, 1, 0]

h

1

= d

1

= [−0.21, 0.64, 0.64, −0.21]

250

0

4 -4

2 -2 1 -1

3 -3

d(k′)

k′

1

0.64 0.64

-0.21 -0.21

L=2, M=2, N=9

Fig. P12.1 Length-9 symmetric impulse response of 2-fold FIR interpolator.

The interpolated samples between x(n)= x

up

(2n) and x(n+1)= x

up

(2n+2) are calculated from

Eqs. (12.2.18). The two subﬁlters act on the time-advanced (by M = 2) low-rate input samples

¦x(n + 2), x(n + 1), x(n), x(n − 1)¦, or, ¦x

up

(2n + 4), x

up

(2n + 2), x

up

(2n), x

up

(2n − 2)¦.

Equations (12.2.18) can be cast in a compact matrix form:

_

y

up

(2n)

y

up

(2n +1)

_

=

_

0 0 1 0

−0.21 0.64 0.64 −0.21

_

⎡

⎢

⎢

⎢

⎣

x

up

(2n +4)

x

up

(2n +2)

x

up

(2n)

x

up

(2n −2)

⎤

⎥

⎥

⎥

⎦

These ﬁltering equations can also be obtained by superimposing the symmetric impulse response

of Fig. P12.1 on each of the contributing low-rate samples

¦x

up

(2n +4), x

up

(2n +2), x

up

(2n), x

up

(2n −2)¦

and adding up their contributions at each of the intermediate sampling instants 2n +i, i = 0, 1,

as shown in Fig. P12.2.

x

up

(2n-2)

2n-2

x

up

(2n+2)

y

up

(2n+1)

2n+2

x

up

(2n+4)

2n+4

x

up

(2n)

2n

n′

Fig. P12.2 Superposition of impulse responses.

The Hamming windowed version of the ﬁlter is obtained by multiplying the full length-9 ﬁlter

response h by a length-9 Hamming window. The resulting impulse response will be:

h = [0, −0.05, 0, 0.55, 1, 0.55, 0, −0.05, 0 ]

The corresponding polyphase subﬁlters are obtained by extracting every second entry:

h

0

= [0, 0, 1, 0]

h

1

= [−0.05, 0.55, 0.55, −0.05]

251

The interpolation equations will be in this case:

_

y

up

(2n)

y

up

(2n +1)

_

=

_

0 0 1 0

−0.05 0.55 0.55 −0.05

_

⎡

⎢

⎢

⎢

⎣

x

up

(2n +4)

x

up

(2n +2)

x

up

(2n)

x

up

(2n −2)

⎤

⎥

⎥

⎥

⎦

Problem 12.3

For the case of a 3-fold interpolator, we have L = 3 and choose again M = 2, corresponding to

ﬁlter length N = 2LM+1 = 13. The ideal impulse response is:

d(k

¹

)=

sin(πk

¹

/3)

πk

¹

/3

, −6 ≤ k

¹

≤ 6

or, numerically,

h = d = [0, −0.17, −0.21, 0, 0.41, 0.83, 1, 0.83, 0.41, 0, −0.21, −0.17, 0]

where h is the causal version, with time origin at the left of the vector, and d is the symmetric

one, with time origin at the middle of the vector. This impulse response is shown in Fig. P12.3.

The three polyphase subﬁlters are deﬁned by Eq. (12.2.10), that is, for i = 0, 1, 2,

d

i

(k)= d(3k +i), −2 ≤ k ≤ 1

They can be extracted from h by taking every third entry, starting with the ith entry:

h

0

= d

0

= [0, 0, 1, 0]

h

1

= d

1

= [−0.17, 0.41, 0.83, −0.21]

h

2

= d

2

= [−0.21, 0.83, 0.41, −0.17]

The interpolated samples between x(n)= x

up

(3n) and x(n + 1)= x

up

(3n + 3) are calculated

from Eqs. (12.2.18).

0

5 -5 4 -4

2 -2 1 -1

6 -6

3 -3

d(k′)

k′

1

0.83 0.83

0.41 0.41

-0.17 -0.17

-0.21 -0.21

L=3, M=2, N=13

Fig. P12.3 Length-13 symmetric impulse response of 3-fold FIR interpolator.

All three subﬁlters act on the time-advanced (by M = 2) low-rate input samples ¦x(n+2), x(n+1),

x(n), x(n −1)¦, or, ¦x

up

(3n +6), x

up

(3n +3), x

up

(3n), x

up

(3n −3)¦. Equations (12.2.18) can

be cast in a compact matrix form:

⎡

⎢

⎣

y

up

(3n)

y

up

(3n +1)

y

up

(3n +2)

⎤

⎥

⎦ =

⎡

⎢

⎣

0 0 1 0

−0.17 0.41 0.83 −0.21

−0.21 0.83 0.41 −0.17

⎤

⎥

⎦

⎡

⎢

⎢

⎢

⎣

x

up

(3n +6)

x

up

(3n +3)

x

up

(3n)

x

up

(3n −3)

⎤

⎥

⎥

⎥

⎦

252

These ﬁltering equations can also be obtained by superimposing the symmetric impulse response

of Fig. P12.3 on each of the contributing low-rate samples

¦x

up

(3n +6), x

up

(3n +3), x

up

(3n), x

up

(3n −3)¦

and adding up their contributions at each of the intermediate sampling instants 3n+i, i = 0, 1, 2,

as shown in Fig. P12.4.

x

up

(3n-3)

3n-3

x

up

(3n+3)

y

up

(3n+1)

3n+3

x

up

(3n+6)

3n+6

x

up

(3n)

3n

n′

Fig. P12.4 Superposition of impulse responses.

The Hamming windowed version of the ﬁ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 subﬁlters are obtained by extracting every third entry:

h

0

= [0, 0, 1, 0]

h

1

= [−0.02, 0.32, 0.78, −0.06]

h

2

= [−0.06, 0.78, 0.32, −0.02]

The interpolation equations will be in this case:

⎡

⎢

⎣

y

up

(3n)

y

up

(3n +1)

y

up

(3n +2)

⎤

⎥

⎦ =

⎡

⎢

⎣

0 0 1 0

−0.02 0.32 0.78 −0.06

−0.06 0.78 0.32 −0.02

⎤

⎥

⎦

⎡

⎢

⎢

⎢

⎣

x

up

(3n +6)

x

up

(3n +3)

x

up

(3n)

x

up

(3n −3)

⎤

⎥

⎥

⎥

⎦

Problem 12.4

For interpolation factor L = 4 and ﬁlter length N = 25, we ﬁnd:

N = 2LM+1 ⇒ M = (N−1)/2L = (25 −1)/8 = 3

Thus, we use 3 low-rate samples above and three below every interpolated value to be computed.

The length-25 ideal interpolation impulse response is calculated from:

d(k

¹

)=

sin(πk

¹

/4)

πk

¹

/4

, for −12 ≤ k

¹

≤ 12

This generates the numerical values:

253

d = [ 0.000, 0.082, 0.127, 0.100, 0.000, −0.129, −0.212, −0.180,

0.000, 0.300, 0.637, 0.900, 1.000, 0.900, 0.637, 0.300,

0.000, −0.180, −0.212, −0.129, 0.000, 0.100, 0.127, 0.082, 0.000 ]

This impulse response is shown in Fig. P12.5 (where the values have been rounded to 2-digit

accuracy for convenience.)

0 4 -4 2 -2 1 -1 3 -3

d(k′)

k′

1

0.90 0.90

0.64 0.64

0.30

-0.18

-0.21

-0.13

12 -12

0.13

0.10 0.08

0.13

0.10 0.08

-0.13

-0.21

-0.18

0.30

L=4, M=3, N=25

Fig. P12.5 Length-25 symmetric impulse response of 4-fold FIR interpolator.

Given 2M = 6 low-rate samples ¦A, B, C, D, E, F¦ as shown in Fig. 12.1.11, the three values

¦X, Y, Z¦ interpolated between C and D are calculated by convolving d with the upsampled

low-rate samples. Using the ﬂ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 inter-

sects with the low-rate samples, and add up the results. This procedure is shown in Fig. P12.6.

The corresponding linear combinations of low-rate samples are precisely those of Eq. (12.1.3).

They may be rewritten in the polyphase matrix form (with the low-rate samples listed from the

latest down to the earliest):

⎡

⎢

⎣

X

Y

Z

⎤

⎥

⎦ =

⎡

⎢

⎣

0.082 −0.129 0.300 0.900 −0.180 0.100

0.127 −0.212 0.637 0.637 −0.212 0.127

0.100 −0.180 0.900 0.300 −0.129 0.082

⎤

⎥

⎦

⎡

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎢

⎣

F

E

D

C

B

A

⎤

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎥

⎦

Problem 12.5

The ideal 3-fold interpolation case with M = 2, so that N = 2LM+ 1 = 2 · 3 · 2 + 1 = 13, was

discussed in Problem 12.3. For the linear interpolator, using Eq. (12.3.7), we have:

⎡

⎢

⎣

y

up

(3n)

y

up

(3n +1)

y

up

(3n +2)

⎤

⎥

⎦ =

⎡

⎢

⎣

0 0 1 0

0 1/3 2/3 0

0 2/3 1/3 0

⎤

⎥

⎦

⎡

⎢

⎢

⎢

⎣

x(n +2)

x(n +1)

x(n)

x(n −1)

⎤

⎥

⎥

⎥

⎦

=

_

1/3 2/3

2/3 1/3

__

x(n +1)

x(n)

_

Problem 12.6

The following complete C program interp.c implements the polyphase sample-by-sample pro-

cessing algorithm of Eq. (12.2.20) and the initialization procedure of (12.2.19):

254

n′

A

B

C

D

X

E

F

0.90

0.30

0.10 0.08

-0.13

-0.18

n′

A

B

C

D

Y

E

F

0.64 0.64

0.13 0.13

-0.21 -0.21

n′

A

B

C

D

Z

E

F

0.30

0.90

0.08 0.10

-0.18

-0.13

Fig. P12.6 Interpolated values are calculated by the ﬂip-and-slide form of convolution.

/* interp.c - L-fold FIR interpolator (rectangular and Hamming window design)

*

* Usage: interp hamm L M < xlow.dat > yhigh.dat

*

* hamm = 0/1 for rectangular/Hamming window

* L = interpolation factor

* M = half-length of polyphase subfilters (length = 2M, order = P = 2M-

1)

* xlow.dat = file containing low-rate input samples

* yhigh.dat = file containing high-rate interpolated output samples

*/

#include <stdio.h>

#include <math.h>

#include <stdlib.h>

void delay();

double dot();

double d(); ideal interpolation ﬁlter

void main(int argc, char ** argv)

{

int i, n, L, M, P, hamm;

double x, *y, *w, **h, pi = 4 * atan(1.0);

if (argc != 4) {

255

fprintf(stderr,"\nUsage: interp hamm L M < xlow.dat > yhigh.dat\n\n");

fprintf(stderr,"where: hamm = 0/1 for rectangular/hamm window\n");

fprintf(stderr," L = interpolation factor\n");

fprintf(stderr," M = half-length of polyphase subfilters\n");

fprintf(stderr," xlow.dat = file for low-rate input samples\n");

fprintf(stderr," yhigh.dat = file for high-rate interpolated output samples\n");

exit(0);

}

hamm = atoi(argv[1]);

L = atoi(argv[2]);

M = atoi(argv[3]);

P = 2*M - 1; polyphase ﬁlter order

h = (double **) calloc(L, sizeof(double *)); allocate L subﬁlters

for (i=0; i<L; i++)

h[i] = (double *) calloc(2*M, sizeof(double)); each of length 2M

y = (double *) calloc(L, sizeof(double)); allocate L polyphase outfprintf(stderr,

w = (double *) calloc(2*M, sizeof(double)); allocate low-rate internal state

for (i=0; i<L; i++) construct polyphase subﬁlters

for (n=0; n<2*M; n++)

if (hamm == 0) rectangular window

h[i][n] = d(L, L*n+i-L*M);

else Hamming window

h[i][n] = d(L, L*n+i-L*M) * (0.54 - 0.46*cos((L*n+i)*pi/(L*M)));

initialize by Eq. (12.2.19)

for (i=M; i>=1; i--) initialize state w by reading

scanf("%lf", w + i); ﬁrst M low-rate input samples

process by Eq. (12.2.20)

while(scanf("%lf", &x) != EOF) { keep reading low-rate samples till EOF

w[0] = x;

for (i=0; i<L; i++) {

y[i] = dot(P, h[i], w); ith interpolated output sample

printf("%.12lf\n", y[i]); and write it into stdout

}

delay(P, w); update low-rate delay line

}

for (n=0; n<M; n++) { input-off transients

w[0] = 0.0; zero input

for (i=0; i<L; i++) {

y[i] = dot(P, h[i], w); ith interpolated output sample

printf("%.12lf\n", y[i]); and write it into stdout

}

delay(P, w); update low-rate delay line

}

}

/* -------------------------------------------------------- */

/* d(L, k) - ideal L-fold interpolation coefficients */

256

double d(L, k)

int L, k;

{

double t, pi = 4 * atan(1.0);

if (k == 0) d(0) = 1

return (1.0);

else {

if (k%L == 0) d(k) vanishes at non-zero multiples of L

return (0.0);

else {

t = pi * k / L;

return (sin(t)/t); typical sin x/x impulse response

}

}

}

The program has usage:

interp hamm L M < xlow.dat > yhigh.dat

where the parameter hamm speciﬁes a Hamming or rectangular window, L is the interpolation

factor, and M is the half-length of the polyphase subﬁlters, 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 in-

put 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 subﬁlters. The following program cinterp.c is the circular-buffer version of in-

terp.c:

/* cinterp.c - circular-buffer version of interp.c */

#include <stdio.h>

#include <math.h>

#include <stdlib.h>

void cdelay(), wrap();

double cdot(); circular version of dot.c

double d(); ideal interpolation ﬁlter

void main(int argc, char ** argv)

{

int i, n, L, M, P, hamm;

double x, *y, *w, *p, **h, pi = 4 * atan(1.0);

if (argc != 4) {

fprintf(stderr,"\nUsage: cinterp hamm L M < xlow.dat > yhigh.dat\n\n");

fprintf(stderr,"where: hamm = 0/1 for rectangular/hamm window\n");

fprintf(stderr," L = interpolation factor\n");

fprintf(stderr," M = half-length of polyphase subfilters\n");

fprintf(stderr," xlow.dat = file for low-rate input samples\n");

257

fprintf(stderr," yhigh.dat = file for high-rate interpolated output samples\n");

exit(0);

}

hamm = atoi(argv[1]);

L = atoi(argv[2]);

M = atoi(argv[3]);

P = 2*M - 1; polyphase ﬁlter order

h = (double **) calloc(L, sizeof(double *)); allocate L subﬁlters

for (i=0; i<L; i++)

h[i] = (double *) calloc(2*M, sizeof(double)); each of length 2M

y = (double *) calloc(L, sizeof(double)); allocate L polyphase outfprintf(stderr,

w = (double *) calloc(2*M, sizeof(double)); allocate low-rate internal state

p = w; initialize circular pointer

for (i=0; i<L; i++) construct polyphase subﬁlters

for (n=0; n<2*M; n++)

if (hamm == 0) rectangular window

h[i][n] = d(L, L*n+i-L*M);

else Hamming window

h[i][n] = d(L, L*n+i-L*M) * (0.54 - 0.46*cos((L*n+i)*pi/(L*M)));

initialize by Eq. (P12.1)

for (i=M; i>=1; i--) { initialize state w by reading

scanf("%lf", p); ﬁrst M low-rate input samples

cdelay(P, w, &p);

}

process by Eq. (P12.2)

while(scanf("%lf", &x) != EOF) { keep reading low-rate samples till EOF

*p = x; beginning of state vector

for (i=0; i<L; i++) {

y[i] = cdot(P, h[i], w, p); circular version of dot()

printf("%.12lf\n", y[i]); and write it into stdout

}

cdelay(P, w, &p); update low-rate delay line

}

for (n=0; n<M; n++) { input-off transients

*p = 0.0; zero input

for (i=0; i<L; i++) {

y[i] = cdot(P, h[i], w, p); circular version of dot()

printf("%.12lf\n", y[i]); and write it into stdout

}

cdelay(P, w, &p); update low-rate delay line

}

}

/* -------------------------------------------------------- */

/* d(L, k) - ideal L-fold interpolation coefficients */

double d(L, k)

int L, k;

258

{

double t, pi = 4 * atan(1.0);

if (k == 0) d(0) = 1

return (1.0);

else {

if (k%L == 0) d(k) vanishes at non-zero multiples of L

return (0.0);

else {

t = pi * k / L;

return (sin(t)/t); typical sin x/x impulse response

}

}

}

/* -------------------------------------------------------- */

/* cdot(P, h, w, p) - circular version of dot.c */

double tap();

double cdot(P, h, w, p) computes dot product of h with

double *h, *w, *p; current internal state vector

int P; pointed to by pointer p

{

int i;

double y;

for (y=0, i=0; i<=P; i++)

y += h[i] * tap(P, w, p, i);

return y;

}

It uses a circular pointer p that circulates over the low-rate buffer w. The circular-buffer version

of Eqs. (12.2.19) and (12.2.20), implemented by cinterp.c, can be stated as follows:

for m= M down to m= 1 do:

read low-rate input sample x

∗p = x

cdelay(P, w, &p)

(P12.1)

and

for each low-rate input sample x do:

∗p = x

for m= 0, 1, . . . , P determine internal states:

s

m

= tap(P, w, p, m)

for i = 0, 1, . . . , L −1 compute output of ith ﬁlter:

y

i

= dot(P, h

i

, s)

cdelay(P, w, &p)

(P12.2)

The length-17 rectangular and Hamming windowed ﬁlters for this problemwere derived in Section

12.4.1. The given inputs were processed by interp.c. The upsampled versions of these inputs,

x

up

(n

¹

), are shown in Fig. P12.7 together with the corresponding interpolated output signals

y

up

(n

¹

), computed by the length-17 Hamming windowed version of the interpolation ﬁlter.

259

Fig. P12.7 Interpolation of triangular and sinusoidal signals.

Problem 12.7

We start with f

s

= 40 kHz, Δf = 5 kHz, and A = 80 for all the stages. The effective single stage

ﬁlter will have Kaiser length:

N−1 =

DL

ΔF

= 321.08

which is rounded up to:

N = 337 = 2LM+1 = 16M+1 ⇒ M = 21

The 2×4 multistage ﬁlters, shown in Fig. P12.8, have Kaiser lengths:

N

0

−1 =

L

0

D

ΔF

= 80.27, N

1

−1 =

DF

1

F

0

−1

=

8D

2 −1

= 40.14

and are rounded up to:

N

0

= 85 = 2L

0

M

0

+1 = 4M

0

+1 ⇒ M

0

= 21

N

1

= 49 = 2L

1

M

1

+1 = 8M

1

+1 ⇒ M

1

= 6

The relative computational rate will be

R

multi

R

single

=

N

0

+N

1

F

0

N

= 0.54

260

H

0

H

1

2f

s

8f

s

f

s

2 4

Fig. P12.8 2x4=8-fold oversampling ﬁlter.

which compares well with the approximation:

R

multi

R

single

=

1

L

1

+

L

0

L

0

−1

ΔF = 0.50

Thus, the multistage realization requires only 54 percent the cost of the single-stage one. The

combined ﬁlter H

tot

(f)= H

0

(f)H

1

(f) and the superimposed plots of the ﬁlters H

0

(f), H

1

(f)

are shown in Fig. P12.9. Similarly, for the 4×2 case, shown in Fig. P12.10, we ﬁnd the ﬁlter lengths:

N

0

= 169, N

1

= 17

Fig. P12.9 Combined ﬁlter H

0

(f)H

1

(f), and individual ﬁlters H

0

(f), H

1

(f).

H

0

H

1

4f

s

8f

s

f

s

2 4

Fig. P12.10 4x2=8-fold oversampling ﬁlter.

The relative computational rate is in this case:

R

multi

R

single

=

N

0

+N

1

F

0

N

= 0.70

The combined ﬁlter H

tot

(f)= H

0

(f)H

1

(f) and the superimposed plots of the ﬁlters H

0

(f),

H

1

(f) are shown in Fig. P12.11. Initially, we designed the ﬁlters with stopband attenuations

A

0

= A

1

= 80 dB. However, we found that in order to keep the overall stopband attenuation

261

below 80 dB, the attenuation of the second ﬁlter had to be increased to A

1

= 84 dB. This did not

change the ﬁlter lengths, but it changed slightly the Kaiser parameters D

1

and α

1

for that factor.

Finally, in the 2×2×2 case, shown in Fig. P12.12, we ﬁnd the ﬁlter lengths

Fig. P12.11 Combined ﬁlter H

0

(f)H

1

(f), and individual ﬁlters H

0

(f), H

1

(f).

N

0

= 85, N

1

= 25, N

2

= 17

resulting in the relative computational rate

R

multi

R

single

=

N

0

+N

1

F

0

+N

2

F

1

N

= 0.60

H

0

H

1

H

2

2f

s

4f

s

f

s

8f

s

2 2 2

Fig. P12.12 2x2x2=8-fold oversampling ﬁlter.

The combined ﬁlter H

tot

(f)= H

0

(f)H

1

(f)H

2

(f) and individual ﬁlters H

0

(f), H

1

(f), H

2

(f) are

shown in Fig. P12.13. For reference, we also show in Fig. P12.14 the magnitude response of the

single stage 8-fold oversampling ﬁlter. Again, the nominal attenuation of the last factor H

2

had

to be increased to A

2

= 84 dB, whereas the ﬁrst two were A

0

= A

1

= 80 dB.

Problem 12.8

In units of f

s

= 44.1 kHz, the transition width from the edge of the passband to the edge of the

stopband will be:

ΔF =

Δf

f

s

=

24.1 −20

44.1

= 0.0930

The Kaiser window width parameter is D = (A − 7.95)/14.36 = (80 − 7.95)/14.36 = 5.0174.

Thus, for a single-stage design with oversampling ratio L = 4, we ﬁnd the Kaiser length:

262

Fig. P12.13 Combined ﬁlter H

0

(f)H

1

(f)H

2

(f), and individual ﬁlters H

0

(f), H

1

(f), H

2

(f).

Fig. P12.14 Single-stage 8-fold oversampling ﬁlter.

N−1 =

DL

ΔF

=

5.0174 · 4

0.0930

= 215.803 ⇒ N = 217, M = (N−1)/(2L)= 27

The corresponding computational rate of the polyphase realization is

R

single

= Nf

s

= 217 · 44.1 = 9569.7 MAC/msec = 9.5697 MIPS

(assuming that each MAC is done with one instruction.) Thus, a 20-MIPS DSP chip can easily

handle it.

For the two-stage case, the design speciﬁcations are depicted in Fig. 12.2.9 of Section 12.2.5. Stage

H

0

operating at 2f

s

will have the narrow transition width Δf = 4.1 kHz, or ΔF = 0.0930. This

gives the Kaiser length:

N

0

−1 =

DL

0

ΔF

=

5.0174 · 2

0.0930

= 107.9 ⇒ N

0

= 109, M

0

= (N

0

−1)/(2L

0

)= 27

The second stage H

1

will have a wider transition width Δf

1

= f

s

, or ΔF

1

= 1. Thus, the ﬁlter

length will be:

263

N

1

−1 =

DΔF

1

F

0

−1

=

5.0174 · 4

1.000

= 20.07 ⇒ N

1

= 25, M

1

= (N

1

−1)/(2L

1

)= 6

The polyphase computational rate of the two sections combined will be

R

multi

= N

0

f

s

+N

1

(2f

s

)= 159f

s

= 159 · 44.1 = 7011.9 MAC/msec = 7.0119 MIPS

Thus, the relative computational cost of the two-stage versus the single stage design will be:

R

multi

R

single

=

159f

s

217f

s

= 0.73

Problem 12.9

The frequency responses can be computed by the MATLAB code:

f = (0:399) * 160 /400; 400 frequencies in [0,160] kHz

f1 = 28; normalization frequency for Butterworth

f2 = 16; normalization frequency for Bessel

H1 = 1 ./ (1 + 2*j*(f/f1) - 2*(f/f1).^2 - j*(f/f1).^3); Butterworth

H2 = 15 ./ (15 + 15*j*(f/f2) - 6*(f/f2).^2 - j*(f/f2).^3); Bessel

magH1 = 20 * log10(abs(H1));

magH2 = 20 * log10(abs(H2));

argH1 = angle(H1) * 180 / pi;

argH2 = angle(H2) * 180 / pi;

The phase and magnitude responses are shown in Figs. P12.15 and P12.16. The Bessel phase

response is essentially linear over the 0–20 kHz passband. But its magnitude response is not as

ﬂat as the Butterworth’s.

Fig. P12.15 Phase responses of Bessel and Butterworth ﬁlters.

264

Fig. P12.16 Magnitude responses of Bessel and Butterworth ﬁlters.

Problem 12.10

The ﬁlter H

0

has a cutoff frequency f

c

= f

s

/2. The linear, hold, and DAC magnitude responses

(normalized to 0 dB at DC) are in the general and the particular case of L

0

= 4, L

1

= L

2

= 2:

¦H

1

(f)¦ =

¸

¸

¸

¸

¸

sin(πf/L

0

f

s

)

L

1

sin(πf/L

0

L

1

f

s

)

¸

¸

¸

¸

¸

2

=

¸

¸

¸

¸

¸

sin(πf/4f

s

)

2sin(πf/8f

s

)

¸

¸

¸

¸

¸

2

¦H

2

(f)¦ =

¸

¸

¸

¸

¸

sin(πf/L

0

L

1

f

s

)

L

2

sin(πf/L

0

L

1

L

2

f

s

)

¸

¸

¸

¸

¸

=

¸

¸

¸

¸

¸

sin(πf/8f

s

)

2sin(πf/16f

s

)

¸

¸

¸

¸

¸

¦H

dac

(f)¦ =

¸

¸

¸

¸

¸

sin(πf/L

0

L

1

L

2

f

s

)

πf/L

0

L

1

L

2

f

s

¸

¸

¸

¸

¸

=

¸

¸

¸

¸

¸

sin(πf/16f

s

)

πf/16f

s

¸

¸

¸

¸

¸

The ﬁlter H

0

operates at rate 4f

s

and cancels all the images at multiples of f

s

which are not

multiples of 4f

s

. The linear interpolator H

1

operates at rate 8f

s

and vanishes at multiples of 4f

s

which are not multiples of 8f

s

. The ﬁlter H

2

operates at rate 16f

s

and vanishes at multiples of 8f

s

which are not multiples of 16f

s

. Finally, H

dac

vanishes at all non-zero multiples of 16f

s

. Thus, the

combined effect of H

0

, H

1

, H

2

, and H

dac

is to (partially) remove all spectral images at multiples

of f

s

.

We note that the combined effect of the two hold transfer functions is an effective DAC operating

at 8f

s

:

¦H

2

(f)H

dac

(f)¦ =

¸

¸

¸

¸

¸

sin(πf/L

0

L

1

f

s

)

L

2

sin(πf/L

0

L

1

L

2

f

s

)

¸

¸

¸

¸

¸

·

¸

¸

¸

¸

¸

sin(πf/L

0

L

1

L

2

f

s

)

πf/L

0

L

1

L

2

f

s

¸

¸

¸

¸

¸

=

¸

¸

¸

¸

¸

sin(πf/L

0

L

1

f

s

)

πf/L

0

L

1

f

s

¸

¸

¸

¸

¸

=

¸

¸

¸

¸

¸

sin(πf/8f

s

)

πf/8f

s

¸

¸

¸

¸

¸

The reason for using H

2

is that the higher the L, the more bits can be saved via the noise-shaping

requantizer.

Problem 12.11

The proof of the result may be seen graphically in Fig. P12.17 for the case L = 4. The ideal inter-

polator has cutoff f

s

/2 and is periodic in f with period Lf

s

= 4f

s

. Thus, the passband replicates

at multiples of 4f

s

.

265

4f

s

f 0 3f

s

2f

s

-2f

s

-3f

s

-4f

s

f

s

-f

s

D(f -f

s

)

D(f)

D(f -2f

s

)

D(f -3f

s

)

D(f ) + D(f -f

s

) + D(f -2f

s

) + D(f -3f

s

)

4f

s

f 0 3f

s

2f

s

-2f

s

-3f

s

-4f

s

f

s

-f

s

4f

s

f 0 3f

s

2f

s

-2f

s

-3f

s

-4f

s

f

s

-f

s

4f

s

f 0 3f

s

2f

s

-2f

s

-3f

s

-4f

s

f

s

-f

s

4f

s

f 0 3f

s

2f

s

-2f

s

-3f

s

-4f

s

f

s

-f

s

Fig. P12.17 Sum of successive shifts of ideal lowpass interpolator with L = 4 in Problem 12.11.

The terms D(f −mf

s

) correspond to the right shifts of D(f) centered at mf

s

. It is evident from

the ﬁ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:

1

4

_

D(f)+D(f −f

s

)+D(f −2f

s

)+D(f −3f

s

)

_

= 1, for all f

Problem 12.12

Writing k = Lk

¹

+ m, m = 0, 1, . . . , L − 1, corresponds to the quotient and remainder of the

division of k by L, and as such the integers ¦k

¹

, m¦ are uniquely determined by k. Therefore, we

may change the summation over k into a double summation over k

¹

and m:

X(f) =

1

T

∞

_

k=−∞

X

a

(f −kf

s

)=

1

T

L−1

_

m=0

∞

_

k

¹

=−∞

X

a

(f −(k

¹

L +m)f

s

)

=

1

T

L−1

_

m=0

∞

_

k

¹

=−∞

X

a

_

f −(k

¹

L +m)f

s

_

=

1

LT

¹

L−1

_

m=0

∞

_

k

¹

=−∞

X

a

(f −mf

s

−k

¹

f

s

¹

)

where we replaced T = LT

¹

and Lf

s

= f

s

¹

. If in the deﬁnition of X

¹

(f) we replace f by f −mf

s

,

we have:

X

¹

(f −mf

s

)=

1

T

¹

∞

_

k

¹

=−∞

X

a

(f −mf

s

−k

¹

f

s

¹

)

Thus the k

¹

summation in the above double sum may be replaced by X

¹

(f −mf

s

) resulting in the

desired result:

266

X(f)=

1

L

L−1

_

m=0

X

¹

(f −mf

s

)

If we use the variables ω and ω

¹

, then X(f) and X

¹

(f) are given by

X(ω)=

_

n

x(n)e

−jωn

, X

¹

(ω

¹

)=

_

n

¹

x

¹

(n

¹

)e

−jω

¹

n

¹

The shifted frequency f −mf

s

is in units of ω

¹

:

2π(f −mf

s

)

f

s

¹

=

2πf

f

s

¹

−

2πmf

s

Lf

s

= ω

¹

−

2πm

L

Thus, using ω

¹

= ω/L, we may write

X(ω)=

1

L

L−1

_

m=0

X

¹

_

ω

¹

−

2πm

L

_

=

1

L

L−1

_

m=0

X

¹

_

ω−2πm)/L

_

Problem 12.13

The discrete-time sampling function s

¹

(n

¹

) consists of a periodic train of unit impulses at mul-

tiples of L, that is, at n

¹

= nL, and separated by L − 1 zeros between. Thus, the product

of s

¹

(n

¹

) with x

¹

(n

¹

) will insert such zeros. But at the sampling times n

¹

= nL we will have

x

up

(n

¹

)= x

¹

(n

¹

)= x

¹

(nL)= x(n).

Because of its periodicity in n

¹

with period L, the sampling function admits a DFS expansion, that

is, and inverse DFT expansion of the form of Eq. (9.7.1):

s

¹

(n

¹

)=

1

L

L−1

_

m=0

S

¹

(ω

¹

m

)e

jω

¹

m

n

¹

, ω

¹

m

=

2π(mf

s

)

f

s

¹

=

2π(mf

s

¹

/L)

f

s

¹

=

2πm

L

= mth DFT frequency

where S

¹

(ω

¹

m

) is the L-point DFT of s

¹

(n

¹

) calculated from one period of s

¹

(n

¹

as follows:

S

¹

(ω

¹

m

)=

L−1

_

n

¹

=0

s

¹

(n

¹

)e

−jω

¹

m

n

¹

But within the ﬁrst period 0 ≤ n

¹

≤ L −1, the sampling function acts as a unit impulse, s

¹

(n

¹

)=

δ(n

¹

). Therefore, the n

¹

-summation collapses to the term n

¹

= 0, which is unity:

S

¹

(ω

¹

m

)= 1, m= 0, 1, . . . , L −1

which gives for the inverse DFT:

s

¹

(n

¹

)=

1

L

L−1

_

m=0

e

jω

¹

m

n

¹

=

1

L

L−1

_

m=0

e

2πjmn

¹

/L

To transform the relationship x

up

(n

¹

)= s

¹

(n

¹

)x

¹

(n

¹

) to the frequency domain, we replace s

¹

(n

¹

)

by its IDFT expression and use the modulation theorem of DTFTs to get:

x

up

(n

¹

)=

1

L

L−1

_

m=0

e

jω

¹

m

n

¹

x

¹

(n

¹

) ⇒ X

up

(ω

¹

)=

1

L

L−1

_

m=0

X

¹

(ω

¹

−ω

¹

m

)

But we have seen in Eq. (12.2.21) that the upsampled spectrumis the same as the original low-rate

spectrum, that is, X

up

(f)= X(f), or in units of ω and ω

¹

, X

up

(ω

¹

)= X(ω). It follows that

X(ω)= X

up

(ω

¹

)=

1

L

L−1

_

m=0

X

¹

(ω

¹

−ω

¹

m

)=

1

L

L−1

_

m=0

X

¹

_

ω

¹

−

2πm

L

_

267

Problem 12.14

Starting with the ﬁltering equation X

¹

(f)= D(f)X(f), we form the sum of shifted high-rate

spectra:

1

L

L−1

_

m=0

X

¹

(f −mf

s

)=

1

L

L−1

_

m=0

D(f −mf

s

)X(f −mf

s

)=

1

L

L−1

_

m=0

D(f −mf

s

)X(f)= X(f)

where we used the periodicity of X(f) with period f

s

to write X(f − mf

s

)= X(f), and then we

used the result of Problem 12.11 to replace the sum of shifted D(f)’s by unity.

Problem 12.15

The attenuation of an Nth order Butterworth ﬁlter in dB is given by

A(F)= 10log

10

_

1 +

_ F

F

0

_

2N

_

where we used the normalized frequencies F = f/f

s

and F

0

= f

0

/f

s

. Given a required attenuation

of A

pass

dB over the passband F

pass

= f

pass

/f

s

= (f

s

/2)/f

s

= 0.5, we obtain an equation for the

3-dB frequency F

0

:

A

pass

= 10log

10

_

1 +

_0.5

F

0

_

2N

_

⇒ F

0

=

0.5

_

10

Apass/10

−1

_

1/2N

The preﬁlter’s stopband must begin at F

stop

= f

stop

/f

s

= (Lf

s

− f

s

/2)/f

s

= L − 0.5. Thus, the

stopband attenuation will be

A

stop

= 10log

10

_

1 +

_L −0.5

F

0

_

2N

_

⇒ L = 0.5 +F

0

_

10

Astop/10

−1

_

1/2N

For large A

stop

we may ignore the −1 to get

L = 0.5 +F

0

10

Astop/20N

With the values A

pass

= 0.1 and N = 3, we ﬁnd F

0

= 0.94. Fig. P12.18 shows a plot of L versus

A

stop

.

Fig. P12.18 Decimation ratio versus stopband attenuation in Problem 12.15.

268

Problem 12.16

Using the expression of the attenuation of Problem 12.15, we get at the passband and stopband

normalized frequencies F

pass

= 0.5, F

stop

= L −0.5:

A

pass

= 10log

10

_

1 +

_0.5

F

0

_

2N

_

A

stop

= 10log

10

_

1 +

_L −0.5

F

0

_

2N

_

⇒

_

L −0.5

0.5

_

2N

=

10

Astop/10

−1

10

Apass/10

−1

which may be solved for N, giving:

N =

ln

_

10

Astop/10

−1

10

Apass/10

−1

_

2ln(2L −1)

Let N

0

= ceil(N). In order for the ﬁlter order to remain ﬁxed at N

0

, the computed quantity N

must be in the range

N

0

−1 <

ln

_

10

Astop/10

−1

10

Apass/10

−1

_

2ln(2L −1)

Solving this inequality for L, we ﬁnd the limits on L:

0.5 +0.5

_

10

Astop/10

−1

10

Apass/10

−1

_

1/2N0

≤ L < 0.5 +0.5

_

10

Astop/10

−1

10

Apass/10

−1

_

1/2(N0−1)

≤ N

0

For the given numerical values, we ﬁnd N

0

= 3 and the range 9.86 ≤ L < 40.97, which gives the

integer range 10 ≤ L ≤ 40.

Problem 12.17

The normalized transition width is ΔF = Δf/f

s

= (24.41 − 20)/44.1 = 0.1. Using a Kaiser

design, the transition width parameter D and ﬁlter length N will be:

D =

A−7.95

14.36

=

95 −7.95

14.36

= 6.0620, N−1 =

DL

ΔF

=

6.062 · 160

0.1

= 9699.2 ⇒ N = 9920

where the ﬁnal N is of the form N = 2LK + 1 = 320K + 1 with K = 31. Thus, the interpola-

tion/decimation ﬁlter operating at rate f

s

¹¹

= 160f

s

= 147f

s

¹

= 7.056 MHz can be implemented

with 160 polyphase subﬁlters, each of length 2K = 62 and operating at a rate f

s

= 44.1 kHz. The

overall sample rate conversion cost in MAC/sec can be calculated from Eq. (12.6.9):

R = 2Kf

s

¹

= 61f

s

¹

= 61 · 48 = 2928 kMAC/sec = 2.928 MIPS

The computational speed is easily handled by today’s DSP chips. Memory, however, to store the

N FIR coefﬁcients is high—of the order of 10k words.

269

Problem 12.18

Here, we have the conversion ratio f

s

¹

= 32 =

32

48

· 48 =

2

3

f

s

, so that L = 2, M = 3. Because

f

s

¹

< f

s

, the ﬁlter’s cutoff frequency will be f

c

= f

s

¹

/2 = 16 kHz. Assuming a :1 kHz transition

width about f

c

, that is, Δf = 2 kHz, and a A = 60 dB stopband attenuation, we ﬁnd the Kaiser

parameter D and ﬁlter length N:

D =

A−7.95

14.36

=

60 −7.95

14.36

= 3.6247, N−1 =

DLf

s

Δf

=

3.6247 · 2 · 48

2

= 173.98 ⇒ N = 177

where we rounded N to the next odd integer of the form N = 2LK +1. Thus, K = 44, and there

will be L = 2 polyphase subﬁlters of length 2K = 88. Fig. P12.19 shows the ideal speciﬁcations

of such a ﬁlter. The ﬁlter operates at the fast rate f

s

¹¹

= 3f

s

¹

= 2f

s

= 96 kHz and acts as an

antialiasing ﬁlter for the downsampler, that is, it removes the high frequencies from the input

in the range [f

s

¹

2, f

s

/2]= [16, 24] kHz, so that the downshifted replicas—caused by the 3-fold

downsampling operation—will not overlap.

0

0

f

s

′ 2f

s

′ 3f

s

′

f

s

′ 2f

s

′ 3f

s

′=f

s

′′

2f

s

=f

s

′′

0

f

s

2f

s

f

s

0

filter

polyphase

selector

T′/3=T′′

T/2=T′′

6T′′=3T=2T′

T

x

0

x

1

x

2

y

0

y

1

t

t

t

t

f

f

f

f

T′

min(f

s

, f

s

′ )

1

2

0 1 i =

Fig. P12.19 Ideal SRC ﬁlter with conversion ratio 2/3.

Because T = T

¹¹

/2 and T

¹

= T

¹¹

/3, it follows that the basic block interval will be T

block

= 6T

¹¹

=

3T = 2T

¹

, containing 3 input-rate samples ¦x

0

, x

1

, x

2

¦ and 2 output-rate samples ¦y

0

, y

1

¦. The

interpolated output y

1

that lies halfway between x

1

and x

2

is obtained by the polyphase ﬁlter h

1

.

Indeed, the polyphase selector indices can be precomputed by

i

m

= 3m%2 = [0, 1], for m= 0, 1

The sample processing algorithm of the 2/3 sample rate converter will be then:

for each input block ¦x

0

, x

1

, x

2

¦ do:

w

0

= x

0

y

0

= dot(P, h

0

, w)= x

0

delay(P, w)

w

0

= x

1

y

1

= dot(P, h

1

, w)

delay(P, w)

w

0

= x

2

delay(P, w)

270

where P = 2K − 1 is the order of the polyphase subﬁlters h

0

, h

1

, and w is the length-(P + 1)

input-rate delay-line buffer. Note that there is no interpolated output after x

2

(the next two out-

puts come from the next group of three inputs), and therefore, x

2

is simply read into the buffer

w and the delay line is updated.

For reference, we also show in Fig. P12.20 the reverse converter by a ratio 3/2, converting from

32 kHz up to 48 kHz. Here, the SRC ﬁlter acts as an anti-image ﬁlter for the upsampler.

polyphase

selector

T′/2=T′′

T/3=T′′

6T′′=2T=3T′

y

0

y

1

y

2

T

x

0

x

1

t

t

t

t

f

f

f

f

T′

min(f

s

, f

s

′ )

1

2

0 2 1 i = f

s

2f

s

3f

s

=f

s

′′ 0

f

s

2f

s

3f

s

0

filter

0 f

s

′ 2f

s

′

0 2f

s

′=f

s

′′ f

s

′

Fig. P12.20 Ideal SRC ﬁlter with conversion ratio 3/2.

In this case, we have f

s

¹

= 3f

s

/2 = 3 · 32/2 = 48. The fast rate is f

s

¹¹

= 2f

s

¹

= 3f

s

= 96 kHz. The

input- and output-rate sampling intervals are T = 3T

¹¹

and T

¹

= 2T

¹¹

, and the basic time block

T

block

= 6T

¹¹

= 2T = 3T

¹

. Thus, every group of two input samples ¦x

0

, x

1

¦ generates a group of

three output samples ¦y

0

, y

1

, y

2

¦. As can be seen in the ﬁgure, the polyphase selector sequence

is i

m

= 2m%3 = [0, 2, 1], for m = 0, 1, 2. Therefore, the three interpolated outputs ¦y

0

, y

1

, y

2

¦

will be computed by the subﬁlters ¦h

0

, h

2

, h

1

¦. The corresponding sample processing algorithm

will be:

for each input block ¦x

0

, x

1

¦ do:

w

0

= x

0

y

0

= dot(P, h

0

, w)= x

0

y

1

= dot(P, h

2

, w)

delay(P, w)

w

0

= x

1

y

2

= dot(P, h

1

, w)

delay(P, w)

Problem 12.19

For the case L/M = 7/4, we have f

s

¹

= 7f

s

/4 and f

s

¹¹

= 4f

s

¹

= 7f

s

, T

¹¹

= T

¹

/4 = T/7, T

block

=

28T

¹¹

= 7T

¹

= 4T. Fig. P12.21 depicts the operation of the converter both in the time and

frequency domains.

In the time domain, each input block of 4 input-rate samples ¦x

0

, x

1

, x

2

, x

3

¦ generates 28 fast-rate

interpolated samples, out of which 7 output-rate samples ¦y

0

, y

1

, y

2

, y

3

, y

4

, y

4

, y

6

¦ are selected

and computed according to their polyphase indices:

271

0

0

0

0

filter

polyphase

selector

T′/4=T′′

T/7=T′′

28T′′=4T=7T′

y

0

y

1

y

3 y

5

y

2

y

4

y

6

x

0

x

1

x

2

x

3

t

t

t

t

f

f

f

f

T′

T

min(f

s

, f

s

′ )

1

2

0 4 1 2 5 6 3 i = f

s

2f

s

3f

s

4f

s

5f

s

6f

s

7f

s

=f

s

′′

f

s

2f

s

3f

s

4f

s

5f

s

6f

s

7f

s

4f

s

′=f

s

′′ 2f

s

′ 3f

s

′ f

s

′

4f

s

′ 2f

s

′ 3f

s

′ f

s

′

Fig. P12.21 Ideal SRC ﬁlter with conversion ratio 7/4.

i

m

= 4m%7 = [0, 4, 1, 5, 2, 6, 3], for m= 0, 1, . . . , 6

n

m

= (4m−i

m

)/7 = [0, 0, 1, 1, 2, 2, 3]

whenever the index n

m

is repeated, the input-rate polyphase delay line is not updated. The

sample processing conversion algorithm is as follows:

for each input block ¦x

0

, x

1

, x

2

, x

3

¦ do:

w

0

= x

0

y

0

= dot(P, h

0

, w)= x

0

y

1

= dot(P, h

4

, w)

delay(P, w)

w

0

= x

1

y

2

= dot(P, h

1

, w)

y

3

= dot(P, h

5

, w)

delay(P, w)

w

0

= x

2

y

4

= dot(P, h

2

, w)

y

5

= dot(P, h

6

, w)

delay(P, w)

w

0

= x

3

y

6

= dot(P, h

3

, w)

delay(P, w)

For example, the two output samples y

4

, y

5

lie between the input samples x

2

, x

3

and correspond

to the i = 2 and i = 6 interpolated samples. The delay line is updated after both outputs are

computed, and then the next input sample x

3

is read into the delay line, and so on.

In the frequency domain, the SRC ﬁlter acts as an anti-image postﬁlter for the upsampler, remov-

ing the L−1 = 6 replicas between multiples of the fast rate f

s

¹¹

. The downshifting of the replicas

caused by the downsampling operation will position replicas at the 3 multiples of the output rate

f

s

¹

, 2f

s

¹

, and 3f

s

¹

.

272

In the L/M = 4/7 case, we have f

s

¹

= 4f

s

/7 and f

s

¹¹

= 7f

s

¹

= 4f

s

, T

¹¹

= T

¹

/7 = T/4, T

block

=

28T

¹¹

= 4T

¹

= 7T. Fig. P12.22 depicts the operation of the converter both in the time and

frequency domains.

0

0

f

s

′ 2f

s

′ 3f

s

′ 4f

s

′ 5f

s

′ 6f

s

′ 7f

s

′

f

s

′ 2f

s

′ 3f

s

′ 4f

s

′ 5f

s

′ 6f

s

′ 7f

s

′=f

s

′′

4f

s

=f

s

′′

0

4f

s

2f

s

3f

s

f

s

2f

s

3f

s

f

s

0

filter

polyphase

selector

T′/7=T′′

T/4=T′′

28T′′=7T=4T′

T

x

0

x

1

x

3 x

5

x

2

x

4

x

6

y

0

y

1

y

2

y

3

t

t

t

t

f

f

f

f

T′

min(f

s

, f

s

′ )

1

2

0 3 2 1 i =

Fig. P12.22 Ideal SRC ﬁlter with conversion ratio 4/7.

In the time domain, each input block of 7 input-rate samples ¦x

0

, x

1

, x

2

, x

3

, x

4

, x

5

, x

6

¦ generates

28 fast-rate interpolated samples, out of which 4 output-rate samples ¦y

0

, y

1

, y

2

, y

3

¦ are selected

and computed according to their polyphase indices:

i

m

= 7m%4 = [0, 3, 2, 1], for m= 0, 1, . . . , 3

n

m

= (7m−i

m

)/4 = [0, 1, 3, 5]

so that only the input samples x

0

, x

1

, x

3

, x

5

will produce output samples. However, for the

remaining input samples the delay line must be updated. Thus, the sample processing conversion

algorithm will be as follows:

for each input block ¦x

0

, x

1

, x

2

, x

3

, x

4

, x

5

, x

6

¦ do:

w

0

= x

0

y

0

= dot(P, h

0

, w)= x

0

delay(P, w)

w

0

= x

1

y

1

= dot(P, h

3

, w)

delay(P, w)

w

0

= x

2

delay(P, w)

w

0

= x

3

y

2

= dot(P, h

2

, w)

delay(P, w) w

0

= x

4

delay(P, w)

w

0

= x

5

y

3

= dot(P, h

1

, w)

delay(P, w)

w

0

= x

6

delay(P, w)

273

In the frequency domain, the SRC ﬁlter acts as an antialiasing preﬁlter for the downsampler, re-

moving the 3 replicas between multiples of the fast rate f

s

¹¹

. The downshifting of the replicas

caused by the downsampling operation will position replicas at the 6 multiples of the output rate

f

s

¹

, 2f

s

¹

, . . . , 6f

s

¹

, without overlapping.

As a design example, consider the 4/7 case and assume a Kaiser design with a stopband attenu-

ation of 80 dB and normalized transition width ΔF = Δf/f

s

= 0.1. The width parameter D and

ﬁlter length N will be:

D =

A−7.95

14.36

=

80 −7.95

14.36

= 5.0174, N−1 =

DL

ΔF

=

5.0174 · 4

0.1

= 200.70 ⇒ N = 209

where N the smallest odd integer of the form N = 2LK +1; here, K = 26.

Problem 12.20

Atypical windowdepends on the time variable k through the ratio k/(N−1). The effective length

of the stretched impulse response is N

ρ

− 1 = 2LK

ρ

= 2LK/ρ. A symmetric window of such

length will depend on the variable k

¹¹

/(2LK

ρ

)= ρk

¹¹

/(2LK). Thus, the window of length 2LK

ρ

can be expressed in terms of the same window of length 2LK, via the stretching relationship

w

ρ

(k

¹¹

)= w(ρk

¹¹

). It follows that the corresponding windowed impulse responses will be

w

ρ

(k

¹¹

)d

ρ

(k

¹¹

)= ρw(ρk

¹¹

)d(ρk

¹¹

)

Problem 12.21

The polyphase Kaiser ﬁlter can be designed by the code fragment:

double *hd, **h, *w, *x, *y, wind, pi = 4 * atan(1.0);

D = (A - 7.95) / 14.36;

if (A > 50)

alpha = 0.1102 * (A - 8.7);

else if (A > 21)

alpha = 0.5842 * pow(A-21, 0.4) + 0.07886 * (A-21);

else

alpha = 0;

N = 1 + ceil(D*L / DF); Kaiser length

K = ceil((N - 1) / (2.0*L)); round up

N = 2*L*K + 1; ﬁnal length

P = 2*K - 1; polyphase ﬁlter order

LK = L*K; ﬁlter delay

hd = (double *) calloc(N, sizeof(double)); allocate direct form

wc = pi / max(L, M); cutoff frequency

I0alpha = I0(alpha); window normalization

for (n=0; n<N; n++) compute ﬁlter

if (n==LK) middle value

hd[n] = L /(double) max(L, M);

else {

wind = I0(alpha * sqrt(n*(2.0*LK-n)) / LK) / I0alpha;

274

hd[n] = wind * L * (sin(wc*(n-LK))) / (pi*(n-LK));

}

h = (double **) calloc(L, sizeof(double *)); allocate polyphase

for (i = 0; i < L; i++)

h[i] = (double *) calloc(P+1, sizeof(double)); i-th polyphase

for (i=0; i<L; i++) deﬁne polyphase ﬁlters

for (n=0; n<=P; n++)

h[i][n] = hd[L*n+i];

Assuming the input data are being read from stdin, we allocate and initialize the polyphase

delay-line buffer w as follows:

w = (double *) calloc(P+1, sizeof(double)); allocate w

for (i=K; i>=1; i--) read K input samples

if (scanf("%lf", w+i) == EOF) {

printf("must have at least K = %d input samples\n", K);

exit(0);

}

Then, allocate the input/output blocks for the algorithm Eq. (12.6.13) and keep processing input

samples in groups of M. The computed outputs go into stdout. Upon encountering the end-

of-ﬁ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));

for (;;) { for-ever do:

for (n=0; n<M; n++) read M inputs

if (scanf("%lf", x+n) == EOF)

goto transients;

src(L, M, P, h, w, x, y); compute L outputs

for (m=0; m<L; m++) write L outputs

printf("%.12lf\n", y[m]);

}

transients:

for (i=0; i <= K/M; i++) { last K inputs

for (n=0; n<M; n++)

x[n] = 0;

src(L, M, P, h, w, x, y);

for (m=0; m<L; m++)

printf("%.12lf\n", y[m]);

}

The sample processing algorithm (12.6.13) is implemented by the routine:

/* src.c - sample rate converter processing algorithm */

#include <math.h>

double dot();

275

void delay();

void src(L, M, P, h, w, x, y) h is Lx(P+1) polyphase ﬁlter matrix

double **h, *w, *x, *y; w is (P+1)-dimensional delay buffer

{ x,y are M- and L-dimensional vectors

int n, m, i;

double R = L / (double) M; conversion ratio

for (n = 0; n < M; n++) {

w[0] = x[n];

for (m = ceil(R*n); m <= floor(R*(n+1)); m++) {

i = (M * m) % L; polyphase selector

y[m] = dot(P, h[i], w);

}

delay(P, w);

}

}

With the values A = 30 dB, ΔF = 0.1, the 5/3 ﬁ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.

Fig. P12.23 Frequency responses of SRC ﬁlters.

Both ﬁlters have a cutoff frequency of f

c

= min(f

s

/2, f

s

¹

/2)= 3/2 = 1.5 kHz, or, ω

¹¹

c

= π/5. The

passband ripple is δ = 10

−A/20

= 0.032. Their transition widths are different: the ﬁrst ﬁlter has

Δf = 0.1×3 = 0.3 kHz, and the second Δf = 0.1×5 = 0.5 kHz. Were they to be redesigned to

have the same Δf, say 0.3 kHz, then for the 3/5 ﬁ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).

The impulse responses are obtained from Eq. (12.6.5), with LK = 5×8 = 40 and LK = 3×8 = 24

in the two cases, that is,

276

h

5/3

(n

¹¹

)= 5

I

0

(α

_

n

¹¹

(80 −n

¹¹

)/80)

I

0

(α)

sin

_

π(n

¹¹

−40)/5

_

π(n

¹¹

−40)

, n

¹¹

= 0, 1, . . . , 80

h

3/5

(n

¹¹

)= 3

I

0

(α

_

n

¹¹

(48 −n

¹¹

)/48)

I

0

(α)

sin

_

π(n

¹¹

−24)/5

_

π(n

¹¹

−24)

, n

¹¹

= 0, 1, . . . , 48

The frequency responses were computed by direct evaluation of:

H(f)=

N−1

_

n

¹¹

=0

h(n

¹¹

)e

−2πjfn

¹¹

/fs

¹¹

, with f

s

¹¹

= 15 kHz

Figure P12.24 shows the output y(n

¹

) of the 5/3 ﬁlter and compares it with the signal x

¹

(n

¹

) that

would have been obtained had the analog signal been sampled at 3 kHz. On the right, it shows

the effect of the reverse 3/5 ﬁlter on y(n

¹

), and compares it with the original x(n).

Fig. P12.24 Comparison of y(n

¹

) and x

¹

(n

¹

), and of x(n) and reconverted y(n

¹

).

Problem 12.22

Replacing the quantizer Q by its equivalent noise model, we can write the ζ-domain input/output

equations:

V

¹

(ζ) = X

¹

(ζ)−ζ

−1

Y

¹

(ζ)

W

¹

0

(ζ) = V

¹

(ζ)+ζ

−1

W

¹

0

(ζ)

Y

¹

(ζ) = E

¹

(ζ)+W

¹

0

(ζ)

Eliminating V

¹

(ζ) and W

¹

0

(ζ), we obtain:

Y

¹

(ζ)= X

¹

(ζ)+(1 −ζ

−1

)E

¹

(ζ)

Therefore, H

x

(ζ)= 1, and H

NS

(ζ)= 1 −ζ

−1

. The main advantage of this form is that the input

signal X

¹

(ζ) appears unchanged at the output (as opposed to being delayed as in the conventional

case).

277

Problem 12.23

Using the signal labels indicated on the block diagram, we have the sample processing algorithm:

for each input x do:

v = x −u

w

0

= v +w

1

y = Q(w

0

)

w

1

= w

0

u = y

Iterating this algorithm 10 times, we get for x = 0.4 and x = −0.2:

x y

0.40 1

0.40 −1

0.40 1

0.40 1

0.40 1

0.40 −1

0.40 1

0.40 1

0.40 −1

0.40 1

x y

−0.20 −1

−0.20 1

−0.20 −1

−0.20 1

−0.20 −1

−0.20 −1

−0.20 1

−0.20 −1

−0.20 1

−0.20 −1

The averages of the y values are 0.4 and −0.2, respectively.

Problem 12.24

Working in the ζ-domain, we note that the input and output of the ﬁlter H

1

(ζ) will be:

X

¹

(ζ)−ζ

−1

Y

¹

(ζ) and H

1

(ζ)

_

X

¹

(ζ)−ζ

−1

Y

¹

(ζ)

_

Similarly, the input and output of H

2

(ζ) are:

H

1

(ζ)

_

X

¹

(ζ)−ζ

−1

Y

¹

(ζ)

_

−ζ

−1

Y

¹

(ζ) and H

2

(ζ)

_

H

1

(ζ)

_

X

¹

(ζ)−ζ

−1

Y

¹

(ζ)

_

−ζ

−1

Y

¹

(ζ)

_

Adding E

¹

(ζ) to this output will generate Y

¹

(ζ). Thus,

Y

¹

(ζ = E

¹

(ζ)+H

2

(ζ)

_

H

1

(ζ)

_

X

¹

(ζ)−ζ

−1

Y

¹

(ζ)

_

−ζ

−1

Y

¹

(ζ)

_

Moving the Y

¹

(ζ) to the left-hand side and solving for Y

¹

(ζ) gives the transfer relationship:

Y

¹

(ζ)=

H

1

(ζ)H

2

(ζ)

1 +ζ

−1

H

2

(ζ)+ζ

−1

H

1

(ζ)H

2

(ζ)

X

¹

(ζ)+

1

1 +ζ

−1

H

2

(ζ)+ζ

−1

H

1

(ζ)H

2

(ζ)

E

¹

(ζ)

Thus, we identify:

H

x

(ζ)=

H

1

(ζ)H

2

(ζ)

1 +ζ

−1

H

2

(ζ)+ζ

−1

H

1

(ζ)H

2

(ζ)

, H

NS

(ζ)=

1

1 +ζ

−1

H

2

(ζ)+ζ

−1

H

1

(ζ)H

2

(ζ)

The requirement that H

x

(ζ)= 1 and H

NS

(ζ)= (1 −ζ

−1

)

2

is satisﬁed by the choices:

H

1

(ζ)= H

2

(ζ)=

1

1 −ζ

−1

278

A block diagram realization is shown in Fig. P12.25. The corresponding sample processing algo-

rithm can be stated as follows:

for each input x

¹

do:

w

0

= w

1

+(x

¹

−u)

v

0

= v

1

+(w

0

−u)

y

¹

= Q(v

0

)

w

1

= w

0

v

1

= v

0

u = y

¹

+ +

− −

H

2

(ζ) H

1

(ζ)

ζ

-1

ζ

-1

ζ

-1

x′ w

0

v

0

w

1

v

1

u

y′

quantizer

Q

Fig. P12.25 Discrete-time model of second-order delta-sigma quantizer.

Problem 12.25

Without the feedback delay, we get a similar transfer relationship as in the previous problem, but

without the ζ

−1

delays in the denominators, that is,

Y

¹

(ζ)=

H

1

(ζ)H

2

(ζ)

1 +H

2

(ζ)+H

1

(ζ)H

2

(ζ)

X

¹

(ζ)+

1

1 +H

2

(ζ)+H

1

(ζ)H

2

(ζ)

E

¹

(ζ)

Thus, we identify:

H

x

(ζ)=

H

1

(ζ)H

2

(ζ)

1 +H

2

(ζ)+

1

(ζ)H

2

(ζ)

, H

NS

(ζ)=

1

1 +H

2

(ζ)+H

1

(ζ)H

2

(ζ)

The requirement that H

x

(ζ)= ζ

−1

and H

NS

(ζ)= (1 −ζ

−1

)

2

is satisﬁed by the choices:

H

1

(ζ)=

1

1 −ζ

−1

, H

2

(ζ)=

ζ

−1

1 −ζ

−1

(This problem is similar to Problem 7.2.)

Problem 12.26

Once the decimation ﬁ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

for (n=0; n<Ntot; n++) {

x = 0.5 * sin(2 * pi * f0 * n); high-rate input sample

279

y = Q(w1); ΔΣ quantizer output

v = x - y; delta part

w0 = w1 + v; sigma part

w1 = w0; update quantizer’s delay

yup[n] = fir(N-1, h, w, y); (upsampled) decimator output

}

where h and w are the N-dimensional impulse response and internal state arrays for the decima-

tor. In the Kaiser and the rectangular window designs, the ﬁ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

10

[1, 1, 1, 1, 1, 1, 1, 1, 1, 1] , H(ζ)=

1

10

1 −ζ

−10

1 −ζ

−1

For the second-order comb case, we obtain the impulse response by convolving the ﬁrst-order

comb’s impulse response with itself. This gives a length N = 19 response and transfer function:

h =

1

100

[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1] , H(ζ)=

_

1

10

1 −ζ

−10

1 −ζ

−1

_

2

The magnitude response of the second-order comb case is the square of that of the ﬁrst-order

case:

¦H(f)¦ =

¸

¸

¸

¸

¸

sin(πf/f

s

)

Lsin(πf/10f

s

)

¸

¸

¸

¸

¸

2

It is plotted in dB in Fig. P12.26 together with the ﬁrst-order comb case and the rectangular

window design. The upsampled output y

up

(n

¹

) of the second-order comb decimator is plotted

in the right graph of Fig. P12.26.

Fig. P12.26 Length-19 second-order comb magnitude response and ﬁlter output.

Problem 12.27

The ﬁlter designs are the same as in the previous problems. The implementation of the second-

order delta-sigma quantizer is given by the sample processing algorithm discussed in Problem

12.24. The following for-loop generates the high-rate input, quantizes it by the 2nd-order quan-

tizer, and ﬁlters the quantized output with the decimation ﬁlter:

280

w1 = v1 = u = 0; initialize delays

for (n=0; n<Ntot; n++) {

x = 0.5 * sin(2 * pi * f0 * n); high-rate input sample

w0 = w1 + x - u; output of H

1

v0 = v1 + w0 - u; output of H

2

y = Q(v0); ΔΣ quantizer output

w1 = w0; update quantizer’s delays

v1 = v0; update quantizer’s delays

u = y; update quantizer’s delays

yup[n] = fir(N-1, h, w, y); (upsampled) decimator output

}

Figure P12.27 shows the signal x

¹

(n

¹

) and the 2-level quantized output y

¹

(n

¹

) of the second-order

quantizer.

Fig. P12.27 High-rate input and output signals of second-order ΔΣ quantizer.

The upsampled outputs y

up

(n

¹

) of the averaging, second-order comb, rectangular, and Kaiser

window decimators are shown in Fig. P12.28.

Problem 12.28

Working in the ζ-domain, we obtain the I/O equation of the ﬁrst stage. The input to H(ζ) is

X

¹

(ζ)−ζ

−1

Y

¹

1

(ζ), Thus, adding the noise component, we have:

Y

¹

1

(ζ)= E

¹

1

(ζ)+H(ζ)

_

X

¹

(ζ)−ζ

−1

Y

¹

1

(ζ)

_

which can be rearranged as:

Y

¹

1

(ζ)=

H(ζ)

1 +ζ

−1

H(ζ)

X

¹

(ζ)+

1

1 +ζ

−1

H(ζ)

E

¹

1

(ζ)

Inserting H(ζ)= 1/(1 −ζ

−1

), we obtain the transfer relationship of one stage:

Y

¹

1

(ζ)= X

¹

(ζ)+(1 −ζ

−1

)E

¹

1

(ζ)= X

¹

(ζ)+D(ζ)E

¹

1

(ζ) (P12.3)

where D(ζ)= 1−ζ

−1

. The input to the second stage is obtained by forming the difference of the

signals around the ﬁrst quantizer, that is, (Y

¹

−E

¹

1

)−Y

¹

= −E

¹

1

. Applying the basic I/O equation

(P12.3) to this input and corresponding noise E

¹

2

, we obtain

281

Fig. P12.28 First- and second-order comb, and rectangular- and Kaiser-window decimator out-

puts.

Y

¹

2

(ζ)= −E

¹

1

(ζ)+D(ζ)E

¹

2

(ζ) (P12.4)

The overall output is obtained by the linear combination:

Y

¹

(ζ) = Y

¹

1

(ζ)+D(ζ)Y

¹

2

(ζ)= X

¹

(ζ)+D(ζ)E

¹

1

(ζ)+D(ζ)

_

−E

¹

1

(ζ)+D(ζ)E

¹

2

(ζ)

_

= X

¹

(ζ)+D(ζ)E

¹

1

(ζ)−D(ζ)E

¹

1

(ζ)+D

2

(ζ)E

¹

2

(ζ)= X

¹

(ζ)+D

2

(ζ)E

¹

2

(ζ)

Thus, the quantization error from the ﬁrst stage is canceled, whereas the error of the second

stage gets ﬁltered by the second-order highpass ﬁlter D

2

(ζ)= (1 −ζ

−1

)

2

.

Problem 12.29

Such an arrangement is shown in Fig. P12.29. The outputs of the three stages are:

Y

¹

1

(ζ) = X

¹

(ζ)+D(ζ)E

¹

1

(ζ)

Y

¹

2

(ζ) = −E

¹

1

(ζ)+D(ζ)E

¹

2

(ζ)

Y

¹

3

(ζ) = −E

¹

2

(ζ)+D(ζ)E

¹

3

(ζ)

The overall output is obtained by the linear combination:

282

Y

¹

(ζ) = Y

¹

1

(ζ)+D(ζ)

_

Y

¹

2

(ζ)+D(ζ)Y

¹

3

(ζ)

_

= X

¹

(ζ)+D(ζ)E

¹

1

(ζ)+D(ζ)

_

−E

¹

1

(ζ)+D(ζ)E

¹

2

(ζ)+D(ζ)

_

−E

¹

2

(ζ)+D(ζ)E

¹

3

(ζ)

__

= X

¹

(ζ)+D

3

(ζ)E

¹

3

(ζ)

x +

−

ζ

-1

H(ζ)

y

1

y

2

e

1

−e

1

−e

2

+

+

+

−

−

−

ζ

-1

H(ζ)

e

2

y

1st stage

2nd stage

y

3 +

−

ζ

-1

H(ζ)

e

3

3d stage

D(ζ)

D(ζ)

Fig. P12.29 MASH architecture of third-order delta-sigma quantizer.

Problem 12.30

Such an architecture is depicted in Fig. P12.30. The I/O relationship of the ﬁrst stage is

Y

¹

1

(ζ)= X

¹

(ζ)+D(ζ)E

¹

1

(ζ)

The input to the second-order quantizer is −E

¹

1

(ζ). Therefore, its I/O relationship is (from

Problem 12.8.3):

Y

¹

2

(ζ)= −E

¹

1

(ζ)+D

2

(ζ)E

¹

2

(ζ)

The overall output is obtained by the linear combination:

Y

¹

(ζ) = Y

¹

1

(ζ)+D(ζ)Y

¹

2

(ζ)= X

¹

(ζ)+D(ζ)E

¹

1

(ζ)+D(ζ)

_

−E

¹

1

(ζ)+D

2

(ζ)E

¹

2

(ζ)

_

= X

¹

(ζ)+D

3

(ζ)E

¹

2

(ζ)

Problem 12.31

The delay of (N−1)/2 = LM introduced by the decimation ﬁ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.

283

x +

−

ζ

-1

H(ζ)

y

1

y

2

e

1

−e

1

+

+

− −

−

ζ

-1

H(ζ) H(ζ)

e

2

D(ζ)

y

1st stage

2nd stage

Fig. P12.30 MASH architecture of third-order delta-sigma quantizer.

284

Appendix B Problems

Problem B.1

The input sequence is

x(n)=

_

i

u

i

δ(n −iD−d)

Its autocorrelation function is

R

xx

(k)= E

_

x(n +k)x(n)

_

=

_

i

_

j

D−1

_

d=0

E[u

i

u

j

]δ(n +k −iD−d)δ(n −jD−d)p(d)

where the expectation values were taken with respect to both u

i

and d. Because the u

i

are mutually

independent and zero mean and d is uniform, we have E[u

i

u

j

]= σ

2

u

δ(i −j) and p(d)= 1/D. It

follows that:

R

xx

(k)=

σ

2

u

D

_

i

D−1

_

d=0

δ(n +k −iD−d)δ(n −iD−d)

Changing variables to m= n−iD−d and noting that mruns over all the integers, we can replace

the double summation over i and d by the summation over m:

R

xx

(k)=

σ

2

u

D

_

m

δ(k +m)δ(m)=

σ

2

u

D

δ(k)

Thus, x(n) is stationary and has a delta-function autocorrelation. Sending this sequence into the

interpolation ﬁlter will generate a stationary output sequence y(n) with a noise reduction ratio:

NRR =

σ

2

y

σ

2

x

=

_

n

h(n)

2

For the particular case of a hold interpolator, h(n) consists of D ones:

NRR =

σ

2

y

σ

2

x

=

D−1

_

n=0

1 = D ⇒ σ

2

y

= Dσ

2

x

= D

σ

2

u

D

= σ

2

u

For the linear interpolator, we have h(n)= 1 −¦n¦/D, for ¦n¦ ≤ D. This gives:

NRR =

σ

2

y

σ

2

x

=

D

_

n=0

_

1 −

¦n¦

D

_

2

= 1 +2

D

_

n=1

_

1 −

n

D

_

2

= 1 +2

1

D

2

D−1

_

m=1

m

2

Using the identity

D−1

m=1

m

2

=

1

6

D(D−1)(2D−1), we obtain:

NRR =

σ

2

y

σ

2

x

= 1 +2

D−1

_

m=1

m

2

= 1 +

D(D−1)(2D−1)

3D

2

= 1 +

(D−1)(2D−1)

3D

=

2D

2

+1

3D

Thus,

σ

2

y

=

2D

2

+1

3D

σ

2

x

=

2D

2

+1

3D

2

σ

2

u

285

Problem B.2

The power spectral density of the output sequence will be related to that of the input by:

S

yy

(z)= H(z)H(z

−1

)S

xx

(z)= H(z)H(z

−1

)σ

2

x

= H(z)H(z

−1

)

σ

2

u

D

For the hold interpolator, we have:

H(z)=

1 −z

−D

1 −z

−1

, H(z

−1

)=

1 −z

D

1 −z

=

1 −z

−D

1 −z

−1

z

D−1

Thus, the output psd becomes:

S

yy

(z)= H(z)H(z

−1

)

σ

2

u

D

=

1

D

_

1 −z

−D

1 −z

−1

_

2

z

D−1

σ

2

u

Taking inverse z-transforms with the help of Problem 5.11, we ﬁnd:

R

yy

(k)=

_

1 −

¦k¦

D

_

σ

2

u

Problem B.3

The generation of the held signal and the computation of its autocorrelation is illustrated by the

following C program segment:

double *u, *y, *R;

long iseed;

y = (double *) calloc(N, sizeof(double)); N-dimensional

R = (double *) calloc(M+1, sizeof(double)); (M+1)-dimensional

u[0] = ran(&iseed)-0.5; initialize u

q = D * ran(&iseed); initialize q

for (n=0; n<N; n++)

y[n] = ranh(D, u, &q, &iseed); zero mean

corr(N, y, y, M, R); sample autocorrelation

A typical sample autocorrelation is shown in Fig. P14.1

Problem B.4

As was mentioned in the end of Section B.3, the averaged periodogramspectrumcan be calculated

by the following loop:

for (k=0; k<K; k++) { generate K = 200 blocks

u[0] = ran(&iseed); initialize kth block

q = D * ran(&iseed);

for (n=0; n<N; n++) generate kth block

X[n] = cmplx(ranh(D, u, &q, &iseed), 0.0);

fft(N, X); compute its FFT

for(n=0; n<N; n++) accumulate its periodogram

S[i] += cabs(X[i]) * cabs(X[i]);

}

A typical averaged spectrum is shown in Fig. P14.2, for the case D = 5.

286

Fig. P14.1 Sample autocorrelation of length-100 hold noise.

Fig. P14.2 Averaged periodogram spectrum of held noise.

Problem B.5

The random number generator C routine is:

/* rani.c - low-frequency random number generator using interpolation */

double ran(), dot();

void delay(), cdelay2();

double rani(L, P, h, w, q, iseed) usage: y=rani(L, P, h, w, & q, & iseed);

int L, P, *q; q and iseed passed by reference

double **h, *w; h = polyphase ﬁlter matrix

long *iseed; required long by ran()

{

int i;

double y;

if (*q==0) every L calls get new random number

w[0] = ran(iseed) - 0.5; zero mean

i = (L - *q) % L; current polyphase index

y = dot(P, h[i], w); compute interpolated value

287

cdelay2(L-1, q); decrement q for next call

if (*q==0) every L calls update delay line

delay(P, w);

return y;

}

For the hold and linear interpolators, it generates the same output as ranh.c and ranl.c.

The following program raniex.c is an example C program that invokes rani. Most of it is

concerned with designing and allocating the polyphase ﬁ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):

/* raniex.c - interpolated random number generator example */

run with:

k = 0, 1, 2 = hold, linear, Kaiser interpolators

L = 10, Ntot = 150, iseed = 1234567

A = 30 dB, ΔF = 0.3

#include <stdio.h>

#include <math.h>

#include <stdlib.h>

double ran(), rani(), I0(); I0.c was given in Ch.10

void main(int argc, char ** argv)

{

double pi = 4 * atan(1.0);

double **h, *w, *hd;

double I0al, wind, A, D, wc, DF, al;

int L, P, K, N, LK;

int q, i, k, n, Ntot;

long iseed;

if (argc != 5) {

puts("\nUsage: raniex k L Ntot iseed > y.dat\n"

" k = 0,1,2 for hold,linear,general interpolator\n"

" L = upsampling ratio\n"

" Ntot = total random numbers\n"

" iseed = initial seed\n");

exit(0);

}

k = atoi(argv[1]);

L = atoi(argv[2]);

Ntot = atoi(argv[3]);

iseed = atol(argv[4]);

if (k >= 2) { Kaiser interpolator

fprintf(stderr, "enter A, DF (in units of fs): " );

scanf("%lf %lf", &A, &DF);

D = (A - 7.95) / 14.36;

288

if (A > 50)

al = 0.1102 * (A - 8.7);

else if (A > 21)

al = 0.5842 * pow(A-21, 0.4) + 0.07886 * (A-21);

else

al = 0;

N = 1 + ceil(D * L / DF);

K = ceil((N - 1) / (2.0*L));

N = 2 * L * K + 1; ﬁlter length

P = 2 * K - 1; ﬁlter order

LK = L * K; ﬁlter delay

hd = (double *) calloc(N, sizeof(double)); direct form ﬁlter

wc = pi / L; ideal cutoff frequency

I0al = I0(al);

for (n=0; n<N; n++) windowed ﬁlter

if (n==LK)

hd[n] = 1;

else {

wind = I0(al * sqrt(n*(2.0*LK-n)) / LK) / I0al;

hd[n] = wind * L * (sin(wc*(n-LK)))/(pi*(n-LK));

}

}

if (k == 0) { hold interpolator

N = L;

K = 0;

P = 0;

for (n=0; n<N; n++)

hd[n] = 1;

}

if (k == 1) { linear interpolator

P = 1;

K = 1;

N = 2*L+1;

for (n=0; n<N; n++)

hd[n] = 1 - abs(n - L) / (double) L;

}

h = (double **) calloc(L, sizeof(double *)); polyphase subﬁlters

for (i = 0; i < L; i++) allocate L subﬁlters

h[i] = (double *) calloc(P+1, sizeof(double));

for (i=0; i<L; i++)

for (n=0; n<=P; n++)

h[i][n] = hd[L*n+i]; ith subﬁlter

w = (double *) calloc(P+1, sizeof(double)); low-rate delay-line buffer

for (i=K; i>=1; i--)

w[i] = ran(&iseed) - 0.5; initialize w

289

q = 0;

for (n=0; n<Ntot; n++) generate interpolated noise

printf("%.12lf\n", rani(L, P, h, w, &q, &iseed));

}

With the choices A = 30 dB, ΔF = 0.3, the Kaiser parameters become D = 1.536, α = 2.117.

The generated sequences are shown in Fig. P14.3.

Fig. P14.3 Kaiser, hold, and linearly interpolated random sequences.

Problem B.6

Noting that the autocorrelation of a hold-interpolated sequence of period D is R(k)= (1 −

¦k¦/D)σ

2

u

, −D ≤ k ≤ D, we have:

R

yy

(k)=

1

B

2

B−1

_

b=0

R

y

b

y

b

(k)=

1

B

2

B−1

_

b=0

_

1 −

¦k¦

2

b

_

u(2

b

−¦k¦) σ

2

u

(P14.1)

where the unit-step u(2

b

−¦k¦) restricts the duration of the b-th termto be ¦k¦ ≤ 2

b

, or ¦k¦ ≤ 2

b

−1

for non-zero values of R

yy

(k). The resulting autocorrelation function is piece-wise linear, where

the linear segments have geometrically increasing slopes. This is shown in Fig. P14.4 for the case

B = 4. At lag k = 0, Eq. (P14.1) gives the expected result:

σ

2

y

= R

yy

(0)=

1

B

2

· Bσ

2

u

=

σ

2

u

B

The increasing linear slopes in R

yy

(k) cause it to have long-range correlations. Indeed, because

of the restriction ¦k¦ ≤ 2

b

−1, the maximum lag will be:

k

max

= 2

B−1

−1 (P14.2)

Given a lag k in the range ¦k¦ ≤ k

max

, the expression of Eq. (P14.1) can be summed in closed form

as follows. The restriction ¦k¦ ≤ 2

b

−1 can be turned around into a restriction for the summation

index b ≥ log

2

(¦k¦ +1). Denoting the ceiling of this quantity by

b(k)= ¦log

2

(¦k¦ +1)|

290

k

k

max

=2

B-1

-1

R(k)/R(0)

1 3 5 7 9 4 6 8 10 2

1.00

0.75

0.50

0.25

0

B=4

Fig. P14.4 Theoretical autocorrelation of 1/f-noise model.

we ﬁnd

R

yy

(k)=

1

B

2

B−1

_

b=b(k)

_

1 −¦k¦2

−b

_

σ

2

u

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 k

max

= 2

B−1

− 1 = 2

7

− 1 = 127. The sample

autocorrelation was computed by the program segment:

double *y, *R;

y = (double *) calloc(N, sizeof(double)); N-dimensional

R = (double *) calloc(M+1, sizeof(double)); (M+1)-dimensional

for (n=0; n<N; n++) use N=2000

y[n] = ran1f(B, u, q, &iseed); zero-mean y’s

corr(N, y, y, M, R); use M=150

Fig. P14.5 Theoretical and sample autocorrelations for B = 8.

291

The reason for using N = 2000 was because we wanted to evaluate the sample autocorrelation

at M = 150 lags. Thus, the number of lags is 150/2000 ≡ 7.5% of the block length, which falls

within the recommended range for getting statistically reliable lags using the routine corr, as

was mentioned in Section A.1.

Problem B.8

We look at the cases ω

min

= 0.001π and ω

max

= 0.1π, 0.3π, 0.6π. The designed model param-

eters are:

For ω

max

= 0.1π, we have B = 3 and

c = 10, a = [0.6858, 0.9686, 0.9969]

For ω

max

= 0.3π, we have B = 4 and

c = 6.6943, a = [0.0575, 0.8592, 0.9790, 0.9969]

For ω

max

= 0.6π, we have B = 6 and

c = 3.5944, a = [−0.8850, 0.4756, 0.8541, 0.9594, 0.9887, 0.9969]

The spectra are shown in Figs. P14.6—P14.8.

Fig. P14.6 Model spectrum and periodogram estimate. ω

max

= 0.1π.

Problem B.9

Solving the equation (0.99574)

c

= 0.94791, we ﬁnd c = 12.5309. Then, the ﬁlter of Eq. (B.30)

becomes:

H(z)= G

(1 −0.98444z

−1

)(1 −0.82159z

−1

)(1 −0.08522z

−1

)

(1 −0.99574z

−1

)(1 −0.94791z

−1

)(1 −0.51153z

−1

)

The NRR = h

T

h of the ﬁ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/

_

h

T

h. The magnitude response squared of Eqs. (B.29)

and (B.30) are shown in Fig. P14.9. The cascade realization is shown in Fig. P14.10. The corre-

sponding sample processing algorithm will be:

292

Fig. P14.7 Model spectrum and periodogram estimate. ω

max

= 0.3π.

Fig. P14.8 Model spectrum and periodogram estimate. ω

max

= 0.6π.

for each white noise input sample x do:

u

0

= 0.57534x +0.99574u

1

x

1

= u

0

−0.98444u

1

u

1

= u

0

v

0

= x

1

+0.94791v

1

x

2

= v

0

−0.83392v

1

v

1

= v

0

w

0

= x

2

+0.53568w

1

y = w

0

−0.07568w

1

w

1

= w

0

293

Fig. P14.9 1/f noise ﬁlters for Problem B.9.

z

-1

x

u

0

v

0

w

0

u

1

x

1

x

2

v

1

w

1

y

z

-1

z

-1

0.57534

0.99574 -0.98444 0.94791 -0.83392 0.53568 -0.07568

Fig. P14.10 Cascade realization of 1/f noise ﬁlter.

294

**xa (t)= 2 cos(2πf1 t)− cos(2πf2a t)= 2 cos(πt)− cos(−πt)= cos(πt)
**

A class of signals aliased with x(t) and xa (t) is obtained by replacing f1 and f2 by their shifted versions: f1 + mfs , f2 + nfs resulting in:

**x(nT) = cos(2πn/10)+ cos(2πn/10)+ cos(2πn/10)+ cos(6πn/10) = 3 cos(2πn/10)+ cos(6πn/10)= xa (nT)
**

If fs = 12 Hz, then f1 and f3 will lie outside of [−6, 6] and will be aliased with 11 − 12 = −1 and 9 − 12 = −3. The aliased signal will be:

xmn (t)= 2 cos(πt + 6πmt)− cos(πt − 6πnt)

xa (t) = cos(2π(−1)t)+ cos(2πt)+ cos(2π(−3)t)+ cos(6πt)

Problem 1.4

Using a trig identity, we write x(t)= cos(8πt)+ cos(10πt)+ cos(2πt). The frequencies contained in x(t) are thus, 1 Hz, 4 Hz, and 5 Hz. If the sampling rate is 5 Hz, then the Nyquist interval is [−2.5, 2.5] Hz, and therefore, the 4 Hz and 5 Hz components lie outside it and will be aliased with the frequencies 4 − 5 = −1 Hz and 5 − 5 = 0 Hz, etc.

= 2 cos(2πt)+2 cos(6πt)

Problem 1.7

We use the same technique as in the square-wave Example 1.4.6. At a sampling rate of 8 Hz, the signal frequencies of

Problem 1.5

Using trig identities we ﬁnd: will be aliased with:

{1, 3, 5, 7, 9, 11, 13, 15, . . . }

**x(t)= sin(6πt) 1 + 2 cos(4πt) = sin(6πt)+ sin(10πt)+ sin(2πt)
**

with frequency content: f1 = 3, f2 = 5, f3 = 1 kHz. The Nyquist interval is [−2, 2] kHz, and the aliased frequencies are:

{ 1, 3, − 3, − 1, 1, 3, − 3, − 1 , . . . }

Therefore only sin(2πt) and sin(6πt) terms will appear in the aliased signal. Thus, we write it in the form:

f 1a = f 1 − f s = 3 − 4 = − 1,

Thus,

f 2a = f 2 − f s = 5 − 4 = 1,

f 3a = f 3 = 1

**xa (t)= B sin(2πt)+C sin(6πt)
**

To determine B and C, we demand that xa (t) and x(t) agree at the sampling instants t = nT = n/8, because T = 1/fs = 1/8 sec. Therefore, we demand

xa (t)= sin(−2πt)+ sin(2πt)+ sin(2πt)= sin(2πt)

**B sin(2πn/8)+C sin(6πn/8)= x(n/8)
**

Setting n = 1, 2, we get two equations

Problem 1.6

Use the trigonometric identity 2 cos a cos b = cos(a + b)+ cos(a − b) three times to get

B sin(2π/8)+C sin(6π/8)= x(1/8)= 0.5 B sin(4π/8)+C sin(12π/8)= x(2/8)= 1

x(t) = 2[cos(10πt)+ cos(6πt)]cos(12πt) = cos(22πt)+ cos(2πt)+ cos(18πt)+ cos(6πt)

The frequencies present in this signal are f1 = 11, f2 = 1, f3 = 9, and f4 = 3 Hz. With a sampling rate of 10 Hz, only f1 and f3 lie outside the Nyquist interval [−5, 5] Hz, and they will be aliased with f1 − fs = 11 − 10 = 1 Hz and f3 − fs = 9 − 10 = −1 Hz. The aliased signal will be:

⇒

B√ + C√

2

1

1 2

= 0.5

B−C=1

The values for x(1/8) and x(2/8) were obtained by inspecting the triangular waveform. Solving for B and C, we ﬁnd:

√ B=

2+2 , 4

√ C=

2−2 4

**xa (t) = cos(2π(1)t)+ cos(2πt)+ cos(2π(−1)t)+ cos(6πt) = 3 cos(2πt)+ cos(6πt)
**

To prove the equality of the samples, replace t = nT = n/10, because T = 1/fs = 1/10. Then,

Problem 1.8

For fs = 5 kHz, we have:

**x(nT)= cos(22πn/10)+ cos(2πn/10)+ cos(18πn/10)+ cos(6πn/10)
**

But, cos(22πn/10)= cos(2πn+2πn/10)= cos(2πn/10) and similarly, cos(18πn/10)= cos(2πn− 2πn/10)= cos(2πn/10). Therefore, the sample values become For fs = 10 kHz, we have:

xa (t)= sin(2πf1 t)

xa (t)= 2 sin(2πf1 t)+ sin(2πf2 t)

2

3

**|HC | = 10−AC /20 = 10−28.08/20 = 0.0394 |HD | = 10−AD /20 = 10−56.16/20 = 0.0016
**

Thus, the resulting reconstructed signal will be:

ya (t) = sin(10πt)+ sin(20πt)+|HC | sin(−20πt)+|HD | sin(10πt) = 1.0016 sin(10πt)+0.9606 sin(20πt)

which agrees closely with the audible part of x(t).

Fig. P1.1 Parts (a,b) of Problem 1.8.

H(f)

Analog Prefilter

AB

C D

48 dB/octave

Problem 1.9

The audible and inaudible parts are:

f

0 10 20 30 45 kHz

**x(t)= sin(10πt)+ sin(20πt) + sin(60πt)+ sin(90πt)
**

audible inaudible

Fig. P1.2 Preﬁlter speciﬁcations of Problem 1.9.

The frequencies of the four terms and their aliased versions are:

fA = 5 fB = 10 fC = 30 fD = 45 ⇒

fAa = 5 fBa = 10 fCa = 30 − 40 = −10 fDa = 45 − 40 = 5

Problem 1.10

The Fourier series expansion of the periodic function s(t) is:

∞ T/2 −T/2

s(t)=

m=−∞

cm e2πjmt/T ,

cm =

1

T

s(t)e−2πjmt/T dt

a. When there is no preﬁlter the aliased signal at the output of the reconstructor will be:

But within the basic period [−T/2, T/2], s(t) equals δ(t). Thus,

**ya (t)= sin(10πt)+ sin(20πt)+ sin(−20πt)+ sin(10πt)= 2 sin(10πt)
**

b. When there is a perfect preﬁlter, the fC , fD components are removed prior to sampling thus, the sampled and reconstructed signal will remain unchanged, that is, the audible part of x(t):

cm =

1

T/2 −T/2

T

δ(t)e−2πjmt/T dt =

1

T

**Using the delta function integral representation:
**

∞ −∞

e−2πjf t dt = δ(f )

**ya (t)= sin(10πt)+ sin(20πt)
**

c. The attenuations introduced by the practical preﬁlter shown in Fig. P1.2 are obtained by determining the number of octaves to the frequencies fC , fD and multiplying by the ﬁlter’s attenuation of 48 dB/octave: log2

we ﬁnd:

S(f ) = =

∞ −∞

s(t)e−2πjf t dt =

∞

1

∞ m=−∞

∞ −∞

T

s(t)e−2πj(f −mfs )t dt

1

fC fs / 2 fD fs / 2

= log2 = log2

30 20 45 20

= 0.585 = 1.170

⇒ ⇒

AC = 48 × 0.585 = 28.08 dB

T

δ(f − mfs )

m=−∞

Problem 1.11

AD = 48 × 1.170 = 56.16 dB

This is simply the Fourier series expansion of the periodic function X(f ) in the variable f , and x(nT) are the Fourier series expansion coefﬁcients calculated by integrating over one period, that is, over [−fs /2, fs /2].

log2

and in absolute units:

4

5

13. we will also get the spectral peaks at the negative frequency X(f )= 1 a + 2πj(f − f0 ) ⇒ |X(f )|2 = a2 + 4π2 (f − f0 )2 −f0 . In the case of real-valued signals. . with Fourier transform: T→0 lim TX(f )= lim T 1 − e−(a+2πj(f −f0 ))T T→0 = 1 a + 2πj(f − f0 ) = X(f ) X(f )= 0. and windowed signals of Problem 1. . L − 1 has spectrum: L−1 L−1 XL (f ) = n=0 x(nT)e−2πjf nT = n=0 −(a+2πj(f −f0 ))LT e−(a+2πj(f −f0 ))nT = with magnitude spectrum: 1−e 1 − e−(a+2πj(f −f0 ))T Problem 1.5e2πjf0 t + 0. If f0 is small.5δ(f + f0 ) Its replication gives the spectrum of the sampled signal: X(f ) = = 1 ∞ T X(f − mfs )= m=−∞ ∞ 1 2T ∞ δ(f − mfs − f0 )+δ(f − mfs + f0 ) m=−∞ Fig. 1 t≥0 X(s)= s + a − 2πjf0 1 Fig. P1. The requirement A(fs − fmax )≥ A gives: γ log10 X(f )= n=0 x(nT)e−2πjf nT = 1 1 − e−(a+2πj(f −f0 ))T fs − fmax fmax ≥A ⇒ fs ≥ fmax + fmax 10A/γ Problem 1. and magnitude spectra: x(t)= e−at e2πjf0 t = e−(a−2πjf0 )t . The length-L sampled signal x(nT)= e−(a−2πjf0 )nT .4. Fourier.14 This is the same as Example 1. As L → ∞. we have e−aLT → 0 and obtain the sampled spectrum of the inﬁnitely long signal: ∞ where γ = α + β. which is only an approximation of the true spectrum even within the Nyquist interval. the peaks at ±f0 will inﬂuence each other somewhat.15 The ﬁrst replica of Xin (f ).13 We have for the complex sinusoid.3 shows the required spectra. 1 2T δ(f − mfs − f0 )+δ(f + mfs + f0 ) m=−∞ where in the second term. Problem 1.5. the sampled spectrum XL (f ) will tend to X(f ).5δ(f − f0 )+0.1(f − fs ) 8 The continuous time limit T → 0 of X(f ) gives rise to the analog spectrum: Its value at the passband frequency fpass = fmax = 20 kHz will be: 6 7 . In units of dB per decade. . will have spectrum: with magnitude spectrum: |X(f )| = 2 1 1 − 2e−aT cos 2π(f − f0 )T + e−2aT |Xin (f − fs )| = 1 1 + 0. we changed the summation index from m to −m. but apart from that the same conclusions can be drawn about the sampled signals. the Laplace.3 Spectra of analog. . shifted to fs . the attenuations due to the signal and ﬁlter combine to give: |XL (f )|2 = 1 − 2e−aLT cos 2π(f − f0 )LT + e−2aLT 1 − 2e−aT cos 2π(f − f0 )T + e−2aT A(f )= α log10 f fmax + β log10 f fmax = γ log10 f fmax In the limit L → ∞. the sampled spectrum agrees more closely with the analog spectrum within the Nyquist interval. we see that as fs increases. 1. From the right graph. we see that the spectrum of the truncated sampled signal has ripples that follow the general shape of X(f ).5e−2πjf0 t .12 Write x(t)= 0. From the left graph. n = 0.Problem 1. P1. sampled.

A 0 fmax fs-fmax f s f 1 + (fmax − fs )/f0 1 + (fmax /f0 )2N 2N · 1 + 0. The exact solution of Eq.1fmax )8 8 =A = A. This must be suppressed by A = 60 dB relative to |Xin (fmax )|.1fmax )8 8 = 60 dB ln (P1.1(fmax − fs ) 1 + (0. With fs = 80. 10 log10 (fmax − fs )/f0 1 + (fmax /f0 )6 6 0. const. we require: −10 log10 Xin (fmax − fs ) Xin (fmax ) 2 =A ⇒ 10 log10 1 + 0.1(fmax − fs ) 8 −10 log10 |X(f )|2 = γ log10 f + const. and the second the attenuation due to the signal. const. where γ = 140 dB/decade.1fmax )8 1 + 0.1(fmax − fs ) 1 + (0. the spectrum |X(f )| follows the power law 1 const. of which 60 dB/decade is due to the ﬁlter and 80 dB/decade due to the signal. (P1. 8 9 . is now 10 log10 or. The approximate method of Example 1.1(fmax − fs ) 1 + (0.65 kHz.2) represents the stopband attenuation due to the ﬁlter.1) and solving for N.1fmax )8 8 = 60 which can be solved for fs to give fs = 132. The ﬁrst factor in Eq.|Xin (fmax − fs )| = 1 1 + 0. With fs = 70 kHz.16 The passband condition at f = fmax = 20 kHz is: 10 log10 1 + (fmax /f0 )2N = Apass which can be solved for f0 in terms of N as follows: 2 f0 N = 2N fmax .1 kHz.0633 kHz.9 kHz.259. that for large f .1fmax )8 8 1 + (fmax − fs )/fmax 2N (r − 1) =A (P1. |X(f )|2 = · ≈ · = 1 + (f /f0 )6 1 + (0.1(fmax − fs ) · 1 + (0.1(fmax − fs ) 1 + (0. thus.4) where R(fs ) is deﬁned by = Astop = 21. Problem 1.1 = 1.14 would have given here fs = fmax + 10A/γ fmax = 20 + 20 · 1060/140 = 73. Using the preﬁlter.2 dB Eq. and 10A/10 R(fs )= 657.8 dB 8 R(fs )= 1 + (0.281) = 4.403 2 ln(50/20) ⇒ N=5 We calculate also f0 = fmax /(r − 1)1/2N = 22. 1 + (fmax − fs )/f0 1 + (fmax /f0 )2N 2N |X( fmax )| |X( fs-fmax )| =|X( fmax-fs)| −10 log10 X(fmax − fs ) X(fmax ) 2 · 1 + 0.4 or Problem 1. we ﬁnd Thus. (P1.1f )8 f6 f8 f 14 giving rise to an effective attenuation 1 r = 10Apass /10 = 100.4) gives the minimum preﬁlter order for a desired suppression level A and rate fs .1). A = 60 dB.05 kHz.918 N= ln(3194.1fmax )8 6 fs − fmax fmax (P1.1fmax )8 8 = 10A/10 which gives the condition 10 log10 1 + (fmax − fs )/f0 1 + (fmax /f0 )6 6 2 Replacing f0 N by its expression above. (P1. The preﬁltered signal that gets sampled is now |X(f )| = |H(f )Xin (f )| = 1 1 + (f /f0 )6 1 1 + ( 0 .3) which can be solved for f0 to give f0 = 25.1(fmax − fs ) · 1 + (0.52 kHz. r−1 −10 log10 |H(fmax )| = 10 log10 1 + (fmax /f0 ) 2 6 = Apass (P1.1fmax )8 8 = 10A/10 It can be solved approximately by ignoring the +1 in the numerators. that is. Note also. replacing Eq. that is.1 kHz. we have r · 1 + 0. Apass = 1 dB. we obtain 1 + 0. we require that its passband attenuation be Apass = 1 dB at fpass = fmax = 20 kHz. we have 10 log10 1 + (fmax − fs )/f0 1 + (fmax /f0 )6 1 + 0.1(fmax − fs ) 8 10 log10 = A − Astop = 38. the use of the preﬁlter enables us to reduce the sampling rate from 132 kHz to 80 kHz. 1f ) 8 where r = 10Apass /10 Its ﬁrst replica |X(f − fs )| is required to be suppressed by A = 60 dB at fmax The antialiasing condition. (P1.5.1(fmax − fs ) 1 + (0.1) is fs = 80. which is fairly close to the more accurate value of 80 kHz.2) N= 10A/10 rR(fs )−1 r−1 2 ln which gives fs = 80.

We ﬁnd: γ= log10 A f fmax = log10 60 30 − 10 10 |Xin (f )|2 = 200 1 (f /fa )2Na . fs = 30 kHz and fmax = 10 kHz. |H(f )|2 1 (f /f0 )2N the antialiasing condition would read: a f 2N fmax (fs − fmax )2N (fs − fmax )2Na = 10−A/10 max · 2Na · 2N 2N 2Na f0 f0 fa fa 2N Because the signal has α = 80 dB/decade. the combined attenuation will be γ = 100. (P1. where A = 60 dB. If we do not use a preﬁlter.19 This problem is the generalization of Prob.4) as a function of fs for different choices of A. It is evident from this graph that the complexity of the preﬁlter increases with A.4 Butterworth order versus sampling rate. valid for large f ’s.17 Figure P1. the Butterworth ﬁlter resembles more and more a brick-wall ﬁlter with cutoff fmax . the requirement that the aliased components (of the 1st replica) be suppressed by A dB relative to the signal components can be expressed in the form: fs = fmax + fmax 10A/20(N+Na ) → fmax + fmax = 2fmax In this case. with γ = α + β = 20Na + 20N. the 3-dB frequency f0 is determined by requiring that at the edge of the passband the attenuation be B dB: Problem 1.15. that is. fs = fmax + fmax 10A/20(N+Na ) It agrees with the results of Problem 1.|Xin (fs − fmax )|2 = 10−A/10 |Xin (fmax )|2 Inserting the given expression for |Xin (f )|. P1.4 shows a plot of N given by Eq. which gives: |X(f )|2 = |H(f )|2 |Xin (f )|2 = 1 1 · 1 + (f /f0 )2N 1 + (f /fa )2Na The antialiasing condition |X(fs − fmax )|2 = 10−A/10 |X(f )|2 gives now: 1 1 + (fs − fmax )/f0 2N Problem 1. we solve for the combined attenuation γ of signal and preﬁlter: · 1 1 + (fs − fmax )/fa 2Na A = γ log10 fs − fmax fmax = 10−A/10 · ⇒ 1 1 · 1 + (fmax /f0 )2N 1 + (fmax /fa )2Na Using the asymptotic forms of the spectra. 1. we ﬁnd the ﬁlter’s attenuation: β = γ − α = 200 − 80 = 120 dB/decade which translates into a ﬁlter order: which simpliﬁes into: β = 20N ⇒ N = β/20 = 120/20 = 6 fs − fmax fmax or. 10 11 . then. For any ﬁxed desired value of A.14. 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.18 Using the results of Problem 1.14. the limit N → ∞ gives Problem 1. which gives β = 100 − 80 = 20 dB/decade and order N = β/20 = 1. for ﬁxed A. and that it decreases with fs . 2(N+Na ) = 10A/10 If we increase the sampling rate to 50 kHz. we get the desired equation for fs in terms of A and fmax : 1 + (fmax /fa )2Na 1 + (fs − fmax )/fa If we use a Butterworth preﬁlter of order N: 2Na = 10−A/10 |H(f )|2 = 1 1 + (f /f0 )2N Fig. at any ﬁxed fs . |H(fmax )|2 = 1 = 10−B/10 1 + (fmax /f0 )2N The ﬁltered input that gets sampled will now have spectrum X(f )= H(f )Xin (f ).

6 dB Thus. we get: xa (t)= 2(N + Na )log10 fs − fmax fmax x(nT)h(t − nT) n = A 10 Problem 1. The replicas of X(f ) embedded in X(f ) will still be present.20 The linear relationship between N and A follows from the approximation of Problem 1. Writing 1 ∞ m=−∞ T H(f0 + mfs )e2πj(f0 +mfs )t |P(f)| f -5fs -fs 0 1 T we have: H(fm )= Am ejθm . but they will be weighted by P(f ). Its sampled spectrum will be: ∞ ∞ Problem 1. P1. thus. T H(fm )= sin(πf0 T) πfm T e−jπf0 T Problem 1. Am = δm .22 The stopband frequency of the postﬁlter is: fstop = fs − fc = 6 − 1 = 5 kHz. fm = f0 + mfs . = 10A/10 Using the delay theorem of Fourier transforms. we get: ∞ −∞ ∞ Am = sin(πf0 T) πfm T . we ﬁnd for the real sinusoidal case: Problem 1.Problem 1. θm = −πf0 T xa (t) = = ˆ h(t − t )x(t ) dt = n x(nT) −∞ h(t − t )δ(t − nT) dt For the ideal reconstructor. the narrower the width τ the ﬂatter the spectrum P(f ).4 dB T H(fm )= sin(πfm T) πfm T e−jπfm T Thus. For a pulse of width τ. At this frequency. The need for using antialiasing preﬁlters to avoid overlapping of replicas remains the same. we have: 1 Astop = A − ADAC = 40 − 14.24 Start with a complex sinusoid x(t)= e2πjf0 t . Thus. the attenuation of the staircase DAC is ∞ xrec (t)= m=−∞ Am sin 2π(f0 + mfs )t + θm Assuming |f0 | < fs /2. we ﬁnd: xrec (t)= Thus.21 The presence of P(f ) is called the aperture effect. going to the time domain. ∞ x(nT)h(t − nT) n xrec (t)= m=−∞ δm sin 2π(f0 + mfs )t = sin(2πf0 t) 12 13 .5 shows P(f ) relative to the replicas of X(f ) for the case τ = T/5. Thus. for the staircase reconstructor we have: 1 ADAC = −20 log10 sin(πfstop /fs ) πfstop /fs = 14.23 Using convolution in the time domain. then P(f ) will be essentially ﬂat within the Nyquist interval.5 Butterworth order versus sampling rate. we have: X(f )= 1 T X(f − mfs )= m=−∞ 1 T δ(f − f0 − mfs ) m=−∞ The spectrum of the reconstructed analog signal will be then: |P(f )| = τ sin(πf τ) πf τ Xrec (f )= H(f )X(f )= 1 ∞ T H(f )δ(f − f0 − mfs )= m=−∞ 1 ∞ T H(f0 + mfs )δ(f − f0 − mfs ) m=−∞ Therefore. If τ T. Fig. so that Am = 1 T |H(fm )|. we recognize the term in the bracket as the FT of h(t − nT). the stopband attenuation of the postﬁlter at f = fstop must be: and because πfm T = πf0 T + mπ.19: 2(N+Na ) Working in the frequency domain we have: Xa (f )= H(f )X(f )= n x(nT) e−2πjf nT H(f ) fs − fmax fmax or. that is. we have θm = 0 and Am = 0 except at m = 0 where A0 = 1. Taking inverse Fourier transforms.4 = 25. leaving the central replica almost unchanged. θm = arg H(fm ) fs 5fs ∞ Fig. P1. xrec (t)= m=−∞ Am e2πj(f0 +mfs )t+jθm Taking imaginary parts.

000 -5.524 3.000 2.243 2. complement the ﬁrst bit in this table. Chapter 2 Problems Problem 2.627 -1.000 3.000 -5.409 3.000 1.000 5.1 The quantized values are: analog value 2.25 Take the linear combination of the results of the single sinusoid case of Eq.2 Filling the table.7 4 -2.000 offset binary 1000 1001 1010 1011 1100 1101 1101 1101 1101 1100 1011 1010 1001 0111 0110 0101 0100 0011 0011 0011 2’s complement 0000 0001 0010 0011 0100 0101 0101 0101 0101 0100 0011 0010 0001 1111 1110 1101 1100 1011 1011 1011 Problem 2.000 1.000 -5.755 4.1 3.000 5.853 2.853 -4.990 4.000 -2.000 1. Problem 2.3 With R = 10 volts and erms ≤ 10−3 volts.12).000 5. we have n 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 x(n) 0. (1.990 xQ (n) 0.911 -4.000 5.1 -3.000 -1.939 -3.000 -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.524 -4.911 4.841 -2.000 -4.939 1.000 2.000 3.222 4.423 4.000 4.000 4.9 3.627 -0. we have using Q = 2B = which gives √ 12erms : 10 R R = √ ≥ √ Q 12erms 12 · 10−3 14 15 .841 0.9 -3.6.Problem 1.

(P2. For part (b).164. Mbytes: 2 × 60 × 44100 × 16 = 10. practically the entire hard disk of a typical home PC.595 · 10−3 msec = 595 nsec 35 · 48 kHz This is plenty of time for today’s DSP chips.10) for L in terms of ΔB. p=0 p = ap + b3 p = ap + b2 p = ap + b1 p = ap + b0 = b3 = ab3 + b2 = a(ab3 + b2 )+b1 = a2 b3 + ab2 + b1 = a(a2 b3 + ab2 + b1 )+b0 = a3 b3 + a2 b2 + ab1 + b0 = B(a) 16 17 . 3.5 = R −b1 2−1 + b2 2−2 + · · · + bB 2−B where the ﬁrst 2−1 canceled the last −0. 2.5 Following similar steps as in the previous problem. if in each channel we must perform NMAC = 35 operations on each sample. we ﬁnd: Problem 2. In practice. 3.Problem 2. we get kbytes and by another 1024.1) L = 1523.114. The actual rms error will be me = = 0. consider the polynomial of degree M = 3: B(z)= b0 +b1 z+b2 z2 +b3 z3 . then these operations must be ﬁnished during the sampling interval T = 1/fs between samples: Lfs = 304. we have: NMAC TMAC ≤ T which gives for the time per MAC: ⇒ TMAC ≤ 1 T = NMAC NMAC fs xQ = R(b1 2−1 + b2 2−2 + · · · + bB 2−B − 0.1) with ΔB = 7 bits and p = 1.764 MHz Problem 2. −Q (e − me )2 p(e) de = 1 0 Q −Q e+ Q 2 de = Q2 12 Problem 2. 0.6 B ≥ log2 √ 10 12 · 10−3 = 11.2. we have for part (a): L = 38. with fs = 8 kHz: (3 × 60 sec)(16 channels)(48000 samples/sec)(20 bits/sample) = 330 Mbytes (8 bits/byte)(10242 bytes/Mbyte) that is. one minute of music has 60 sec containing 60 × 44100 samples. a typical professional digital recording system would require the processing and mixing of at least 32 channels. then the total number of MACs that must be performed within the sampling interval T are 16NMAC . 40 The oversampled audio rates will be. 1. 5.1 kHz sampling rate. the total number of bits will be 2 × 60 × 44100 × 16 bits or. 1. and the variance: −Q ep(e) de = 1 0 Q −Q e de = − Q 2 2 erms = 2B 12 R √ = 10 212 12 √ 0 2 σe = E[(e − me )2 ]= The dynamic range will be 6B = 6 · 12 = 72 dB. 2.1 kHz: Lfs = 67. dividing by 8 we get the total number of bytes: 2 × 60 × 44100 × 16 bytes 8 Dividing by 1024. 2.5. for two stereo channels.9 Replacing b1 = 1 − b1 .705 mvolt. If each sample is quantized with 16 bits. we ﬁnd: TMAC = 1 595 = = 37 nsec 16 · 35 · 48 kHz 16 which is just within the capability of the fastest DSP chips.09 Mbytes 8 × 1024 × 1024 Problem 2. B = 12. which can perform a MAC operation within 30–80 nsec.4 At 44. (2. 13. we ﬁnd: (P2. This gives: Problem 2.5) = R (1 − b1 )2−1 + b2 2−2 + · · · + bB 2−B − 0. 48 kHz Problem 2. with fs = 44.10 As an example.495 The mean is 0 Therefore. 8 The oversampled speech rates will be. 104. Iterating the algorithm for i = 3. 2 × 60 × 44100 samples. The above results suggest that one use at least two DSPs to multiplex the required operations. 116. we ﬁnd: 22ΔB π2p 2p + 1 1 2p+1 L= With ΔB = 15 and p = 1.8 Using Eq. TMAC = 1 = 0.7 Solving Eq. And. If a single DSP chip handles all 16 channels.

return p. 5 C = u(y − xQ ) 1 1 1 1 b1 b2 b3 b4 b1 b2 b3 b4 1010 1111 For the 2’C case.0 1. R = 8 volts.5 4.0 3.0 b1 b2 b 3 b 4 — 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 — 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 Problem 2.5 5. 0 2. we ﬁnd: Problem 2. The following tables show the successive approximation tests for the natural and offset binary cases.5 volts. 0 3.0 −2.5 3.0 1.0 −3.5 −2.polynomial evaluator */ natural binary offset binary 2’s C b 1 b2 b3 b 4 double pol(M.45.0 1. double *b. 2.1 Converter codes for B = 4 bits.2 + 0. The 2’s complement case is obtained by complementing the MSB of the offset case. 0 C = u(y − xQ ) 1 0 1 0 b1 b2 b3 b4 b1 b2 b3 b4 Problem 2. 0 2.5 0. bM zM + bM−1 zM−1 + · · · + b1 z + b0 = (z − a)(qM−1 zM−1 + qM−2 zM−2 + · · · + q1 z + q0 )+R Equating like powers of z. we iterate the algorithm for i = 3. Table P2.14 The quantization width is Q = R/2B = 8/24 = 0.0 5. 0 1. we have y = x + Q/2 = 5. we shift it by half the quantization spacing y = x + Q/2 = 1. For x = 5.0 6.5 6.25 = 1.0 m 8 7 6 5 4 3 2 1 0 −1 −2 −3 −4 −5 −6 −7 −8 xQ = Qm 4. setting z = a.95.5 −3. for (i=M.5 1.5 0. Finally.5 2. the quantizer saturates to its maximum positive value.5 1. test bM = qM−1 bM−1 = qM−2 − aqM−1 bM−2 = qM−3 − aqM−2 ··· b1 = q0 − aq1 b0 = R − aq0 ⇒ qM−1 = bM qM−2 = aqM−1 + bM−1 qM−3 = aqM−2 + bM−2 ··· q0 = aq1 + b1 R = aq0 + b0 b 1 b2 b3 b4 1 0 0 0 0 1 0 0 0 0 1 1 0 0 0 1 xQ 4.2.5 3.0 2.0 −0.2 by rounding.0 0.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.5 −4. for x = −3. So the objective of the algorithm is to compute R iteratively.0 −1.5 2. Indeed. 5 1.0 2.0 0.5 7. 0 1.5 5.0 5. double p = 0. we have y = −2.0 C = u(y − xQ ) 1 0 1 0 test b 1 b2 b 3 b4 1 1 1 1 0 1 1 1 0 0 1 1 0 0 0 1 xQ 0.5 1. i>=0.0 C = u(y − xQ ) 0 0 1 0 test b 1 b2 b 3 b4 1 1 1 1 0 1 0 0 0 0 1 1 0 0 0 1 xQ 0.0 3.45. a.0 4.Problem 2.13 For a polynomial of degree M = 3.0 5.0 2. 0 3. Inserting the polynomial expressions we have: 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 Table P2. gives R = b(a). B(z)= b1 z + b2 z2 + b3 z3 .c . i--) p = a * p + b[i]. m 16 xQ = Qm 8.1 shows the quantization levels and their binary codes.0 1. int i. b.5 −1.0 6.2.0 7. 5 3. 1: 0010 1010 The natural binary and 2’C cases agree because x lies in the positive range of both quantizers. and the remainder R must be a constant. To convert x = 1. The tests are shown below: test p=0 p = a(p + b3 )= ab3 p = a(p + b2 )= a(ab3 + b2 )= a2 b3 + ab2 p = a(p + b1 )= a(a2 b3 + ab2 + b1 )= a3 b3 + a2 b2 + ab1 = B(a) b 1 b2 b3 b4 1 1 1 1 0 1 0 0 0 0 1 1 0 0 0 1 xQ 4. and the following testing tables: 18 19 .11 /* pol. a) int M.

5 C = u(y − xQ ) 0 0 1 0 b1 b2 b3 b4 b1 b2 b3 b4 0000 0010 −3. "%lf\n". normee = Ree[0].quantization noise model * * default values: * N=10 bits * R=1024 * L=1000. printf("enter L.c . and therefore both the positive and negative peaks of the sinusoid will saturate to the positive and negative maxima of the quantizer. for (n=0. } Problem 2.0 1.4. Q = R / (1 << N).15 Similar to the testing tables of Examples 2. *e. Ree[i]/normee). M.0 0. Rxx = (double *) calloc(M+1. FILE *fpe. fprintf(fpRex. scanf("%d %lf". Rex). corr(L. e[n] = x[n] . n++) { v = 0. fprintf(fpe. "w"). &M). iseed. M = "). fprintf(fpRxx. Q. fpRxx = fopen("Rxx". *b. test b1 b2 b3 b4 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 xQ 4. e[n]). sizeof(int)). M=50 */ #include <stdio.h> #include <math.4. "%lf\n". It uses the routine corr of Appendix A.)) + v. double normee. R). *Rxx. i++) { fprintf(fpRee. the amplitude of the sinusoid A = 20 exceeds the quantizer range R/2 = 16. x. Rex = (double *) calloc(M+1. *Ree. M. Ree). sizeof(double)). Problem 2. &N. x. sizeof(double)).xq.2. b = (int *) calloc(N. sizeof(double)). N.0 C = u(y − xQ ) 0 0 0 0 test b1 b2 b3 b4 1 0 0 0 0 1 0 0 0 0 1 1 0 0 0 1 xQ 0 . /* exmpl246. 20 21 .17 This problem is basically the same as Example 2. for (i=0.0 void main() { int n. Rxx[i]/Rxx[0]). e. "% lf\n". R = 32 volts. L.5.0 −3. Problem 2. "w"). In this case. xq. = fopen("x". To implement truncation instead of rounding. the natural binary scale saturates to its minimum positive value.5 0. e = (double *) calloc(L. In part (c). *fpRxx.h> void adc().0). replace the statement within adc: y = x + Q/2. corr(). x[n] = 0. N.double ran(). sizeof(double)). &iseed. Only the full-scale range is different. x = (double *) calloc(L.h> #include <stdlib. e. R. "w"). i<=M.1 to compute all the sample autocorrelations and cross-correlations. pi = 4 * atan(1.18 The following C program carries out all the required operations. } corr(L. adc(x[n]. The same program segment of that example applies here for generating the codes and quantized values. &R). fpRee = fopen("Ree". "w"). R). scanf("%d %ld %d". i. *fpRex. e. Ree = (double *) calloc(M+1.1 and 2. double v. x[n]). xq = dac(b. R = "). corr(L. Rex[i]/normex).0 −2. fpe fpx = fopen("e". "%lf\n". Problem 2. long iseed.0 2. N. "w"). by y = x. &L. Rxx). iseed=10. fprintf(fpx. *Rex.1). M. printf("enter N.4. sizeof(double)). n<L.25 * R * cos(2 * pi * n / sqrt(131. fpRex = fopen("Rex". "% lf\n".25 * R * (2 * ran(&iseed) .0 −2. *fpx. M. double dac(). normex. b. double *x. FILE *fpRee. normex = sqrt(Ree[0] * Rxx[0]). x.16 These versions are straight forward.

19 The mean of v is zero because E[u]= 0.5R(E[u]−0. and therefore. Indeed. we ﬁnd 0 cos(a + φ)cos(b + φ)p(φ) dφ 2π 0 − Q1 2 ≤ x2 ≤ Q1 2 These limits must serve as the full scale range of the second ADC. we have: Rxx (k)= 1 2 2 A cos(2πf0 k)+σv δ(k) 2 E[v]= 0. the normalized autocorrelation function becomes: ρxx (k)= Problem 2. printf("Ree(0) = %lf\n".5)= 0 The variance of v is related to the variance of u as follows: 2 2 σv = E[v2 ]= (0. Thus. We have: 2π a= SNR SNR + 1 ⇒ 1−a= 1 SNR + 1 Problem 2. we must choose: cos(a + φ)cos(b + φ) dφ 1 2π R2 = Q 1 = R1 2B1 .5R)2 E[(u − 0.0)). because v(n) is assumed to be zero-mean white noise. that is. the cross terms will vanish. it varies of the limits E[cos(a + φ)]= 0 1 cos(a + φ)p(φ) dφ = 2π 2π 0 cos(a + φ) dφ = 0 Similarly.20 Inserting x(n)= A cos(2πf0 n + φ)+v(n) into the deﬁnition of the autocorrelation function.printf("erms = Q/sqrt(12) = %lf\n". we ﬁnd: Deﬁning the parameter: 2 σv A 2 /2 Rxx (k) = 2 2 cos(2πf0 k)+ 2 2 δ(k) Rxx (0) A /2 + σ v A /2 + σ v Rxx (k) = E[x(n + k)x(n)] = A2 E[cos 2πf0 (n + k)+φ cos(2πf0 n + φ)] + AE[cos 2πf0 (n + k)+φ v(n)]+AE[v(n + k)cos(2πf0 n + φ)] + E[v(n + k)v(n)] assuming φ and v(n) are independent random variables. The residual signal formed at the output of the ﬁrst DAC. we will have: 22 23 .5R)2 Rxx (0)= R2 1 = 12 48 1 2 2 A + σv 2 Therefore. Q2 = R2 2B2 = R1 2B1 +B2 1 cos(a − b) 2 The following program segment illustrates the sequence of operations: E[cos 2πf0 (n + k)+φ cos(2πf0 n + φ)]= 1 1 cos(2πf0 (n + k)−2πf0 n)= cos(2πf0 k) 2 2 Finally. is the quantization error. Q/sqrt(12. } 2 E[v(n + k)v(n)]= σv δ(k) It follows that the autocorrelation of the noisy sinusoid will be: Problem 2.5: At lag k = 0. sqrt(normee)). by the independence assumption the expectation value of the product becomes the product of the expectation values: we ﬁnally have: a= A 2 /2 2 A2 /2 + σ v ⇒ 1−a= 2 σv 2 A2 /2 + σv ρxx (k)= a cos(2πf0 k)+(1 − a)δ(k) Deﬁning the signal to noise ratio as the relative strength of the sinusoid versus the noise in the autocorrelation function.21 The quantization width of the ﬁrst ADC will be Q1 = R1 /2B1 . x2 = x − x1 . SNR = we may express the parameter a as: A 2 /2 2 σv E[v(n + k)cos(2πf0 n + φ)]= E[v(n + k)]·E[cos(2πf0 n + φ)]= 0 where the last zero follows either from the zero-mean property of v(n) and/or from the zero mean property of E[cos(2πf0 n + φ)]= 0. we have the property: 2π E[cos(a + φ)cos(b + φ)] = = = Thus.5R)2 σu = (0. The latter follows from uniformity of φ whose probability density will be: p(φ)= 1/(2π).5)2 ]= (0.

0 . B2. − 3 ] h = [ 1 . adc(x. R3). R2). but the term nx(n − 3) breaks time-invariance. b2 = (int *) calloc(B2. } Chapter 3 Problems Problem 3. adc(x3. sizeof(int)). R2).b) These problems are of the general form: y(n)= ay(n − 1)+x(n) with a = −0. b2 = (int *) calloc(B2. for n ≥ 1 24 25 . B1.1. the output due to x1 (n)= 2x(n) will be y1 (n)= 3x1 (n)+5 = 6x(n)+5 = 2(3x(n)+5). (b) The quadratic term x2 (n − 1) breaks linearity because it quadruples whenever the input doubles.9 for (b). however. B1.x1. for (n=0.5. x2 = dac(b2. which is then quantized to B3 bits with a full scale range and quantization width: y(n − D)= x2 (n − D − 1)+x(2(n − D))= x2 (n − D − 1)+x(2n − 2D) Thus.R2 = R1 / (1 << B1). The system is. n++) { x = A * cos(2 * pi * f0 * n). b2. b3. b1 = (int *) calloc(B1. B3. 0. − 1 ] Problem 3. adc(x. this is not the same as the delayed (shifted) y(n) obtained by replacing n by n − D: B = B1 + B 2 + B 3 The B2 -bit output of the second ADC must be passed into a second DAC to get the corresponding analog value and subtracted from the input x − x1 to get the third error output. Indeed. (d) The system is linear. sizeof(int)). but not linear since the output does not double whenever the input doubles. 1. R1). x1 = dac(b1. x3 = x . the system is not linear. (c) System is time-invariant. sizeof(int)). B2.1 (a) If the input is doubled the output is not doubled. n<L. B1. b3 = (int *) calloc(B3. we obtain the causal solution: h(0)= ah(−1)+δ(0)= a · 0 + 1 = 1 h(1)= ah(0)+δ(1)= a · 1 + 0 = a h(2)= ah(1)+δ(2)= a · a + 0 = a2 h(3)= ah(2)+δ(3)= a · a2 + 0 = a3 ··· h(n)= ah(n − 1)+δ(n)= a · an−1 = an .9 for (a). (e) The time-dependent term n breaks both time invariance and linearity. and a = 0. R2).x1 . R1). R3 = R2 / (1 << B2). 0 . The corresponding output yD (n) can be computed from the given I/O equation: When there is a third B3 -bit stage.2 Picking out the coefﬁcients of the x-terms. R1). adc(x-x1.x2. −2 .22 The quantized triangularly-dithered signals were generated by the for-loop given in Example 2. sizeof(int)). The term x(2n) will break time-invariance. Thus. the total number of bits will be yD (n)= x2 (n − 1)+xD (2n)= x2 (n − 1 − D)+x(2n − D) D but. for (n=0. b2. we ﬁnd: (a) (b) (c) h = [ 3 . b1 = (int *) calloc(B1. R3 = Q2 = R2 2B2 . let xD (n)= x(n − D) be a delayed input. R1). 0 . b1. n<L. } Problem 3. h(n)= ah(n − 1)+δ(n) Iterating forward in time with zero initial condition h(−1)= 0. Setting x(n)= δ(n) we ﬁnd the difference equation for the impulse response: Problem 2. x1 = dac(b1. adc(x2. n++) { x = A * cos(2 * pi * f0 * n).3 (a. Indeed. B2. the system is neither linear nor time-invariant. B1. 4 ] h = [ 4 . Q3 = R3 2B3 = R1 2B1 +B2 +B3 The following loop shows these operations: R2 = R1 / (1 << B1). b1. x2 = x . time-invariant since it has constant-in-time coefﬁcients. sizeof(int)).

for (c) we have a = 0.53 xn−4 · · · Subtracting. ] (e) The impulse response satisﬁes: h(n)= 0.53 xn−4 + · · · h = [1.8)2 for (c).82 xn−3 + · · · Problem 3. Problem 3.9)2 for (d).Thus. and y(n)= ay(n − 2)+x(n) with a = 0.5)3 . a. .8yn−1 = 5xn + 2xn−1 y(n)= ay(n − 1)+x(n) In cases (a) and (b).8)n−1 u(n − 1)= [5.5). . . a. . .8).5h(1)= 3(0. h(n)= ah(n − 2)+δ(n) A few iterations (with zero initial conditions) give: Problem 3. .81 = −(0.81. 0. In cases (c) and (d).5) h(3)= 0. .9j.5 The impulse response sequence is explicitly: h = [4.52 xn−3 + 0. a2 . The impulse response will satisfy the difference equation: y(n)= −0. . h(n) will be the geometric series: h = [1.5xn−2 + 0. .82 xn−3 + · · · 0. and y(n)= 0. 3.5yn−1 = 4xn + 3xn−1 − 2xn−1 yn = 0.5h(n − 1)+4δ(n)+δ(n − 1) A few iterations give: yn − 0. we apply this result with a = 0.9. 6(0.8xn−2 + 0.8yn−1 = 4xn−1 + 6 0. .5xn−2 + 0. all the odd-indexed h(n) are zero: yn = h0 xn + h1 xn−1 + h2 xn−2 + h3 xn−3 + h4 xn−4 + · · · etc.8xn−2 + 0. .5yn−1 = 2xn−1 + 3 0. for (d) we have a = 0. we have: = 4xn + 3 xn−1 + 0.9.6 We may write the given impulse response in the form: etc.d) These problems are similar to Thus.81y(n − 2)+2x(n) And. we get: h(0)= 1 h(1)= 0 h(2)= ah(0)= a h(3)= ah(1)= 0 h(4)= ah(2)= a2 h(5)= ah(3)= 0.5h(2)= 3(0. It follows that: 0. we apply this result twice and verify that h(n)= an u(n)+(−a)n u(n) leads to the difference equation y(n)= a2 y(n − 2)+2x(n) 26 27 . 6.81. 0. ] (c. Thus. a2 = 0. then the I/O difference equation is which gives yn − 0. . 6(0.52 xn−3 + 0. 3(0. a3 . 3(0.5h(0)+1 = 3 h(2)= 0. a2 = −0. a3 . 0. and a = −0.5)2 . ] ⎧ ⎨4 ⎩3(0.5)n−1 Proceeding as in the previous problem we have: if n = 0 if n ≥ 1 h(n)= yn = 5xn + 6 xn−1 + 0. a2 . h(0)= 4 h(1)= 0. ] Replacing these values into the convolutional equation.5)2 . 0.81y(n − 2)+2x(n) A systematic and simpler way of solving this type of problem will be presented after we cover z-transforms. a4 . 3(0. 0. h(n)= 5δ(n)+6(0.64 = (0.9 and a = −0.4 We have seen that if h(n)= an u(n).5yn−1 = 4xn + xn−1 or. Thus.8)2 .

4. which is valid for all n: a m h(m − 1)x(n − m)= a k h(k)x(n − k − 1)= ay(n − 1) the last equation following from the convolution equation by replacing n by n − 1: y(n)= k h(k)x(n − k) ⇒ y(n − 1)= k h(k)x(n − 1 − k) h(n)= c0 δ(n)+c1 an−1 u(n − 1) where the shifted unit-step u(n − 1) vanishes for n = 0 and equals one for all n ≥ 1. Therefore. b1 x(n − 1). that is.5 = 3. whereas the presence of δ(m − 1) extracts only the m = 1 term. with a change of variables of summation from m to k = m − 1 or m = k + 1. the i δ(n) term will contain the delayed terms: h(n)−ah(n − 1)= c0 δ(n)−ac0 δ(n − 1)+c1 δ(n − 1)= c0 δ(n)+(c1 − ac0 )δ(n − 1) Or. Because h(n) satisﬁes h(n)= ah(n − 1) for n ≥ 2.4.7 had b0 = c0 = 2 and b1 = c1 − ac0 = 4 − 2 · 0. However. the second term of hn will be annihilated by (1 − p2 D). h(n) satisﬁes the recursions h(n)= ah(n − 1). Moreover. p2 : 1 + a1 z−1 + a2 z−2 = (1 − p1 z−1 )(1 − p2 z−1 ) so that y(n) = m h(m)x(n − m) ah(m − 1)+b0 δ(m)+b1 δ(m − 1) x(n − m) m = =a h(m − 1)x(n − m)+ m m b0 δ(m)+b1 δ(m − 1) x(n − m) Then.8 First.10 Deﬁne the polynomial with roots p1 . note that if fn = an u(n) then for n ≥ 1 ah(n − 1)= ac0 δ(n − 1)+c1 a Subtracting. terms in hn will be annihilated by the delay polynomial: hn + a1 hn−1 + a2 hn−2 = (1 + a1 D + a2 D2 )hn = (1 − p1 D)(1 − p2 D)hh 28 29 . pn i a 2 = p 1 p2 In the second sum. the presence of δ(m) extracts only the m = 0 term. we have (1 − p1 D)(1 − p2 D)· · · (1 − pM D)= 1 + a1 D + a2 D2 + · · · + aM DM h(n)−ah(n − 1)= c0 δ(n)−ac0 δ(n − 1)+c1 an−1 δ(n − 1) But note that an−1 δ(n − 1)= δ(n − 1) because it is nonzero only at n = 1 for which we have a1−1 δ(0)= a0 δ(0)= δ(0). Instead of manipulating the I/O convolutional equation into a difference equation as we did above. that is. Problem 3. To do this we start with the convolutional equation and replace h(m) by its difference equation expression. b0 x(n). the a-term is recognized to be ay(n − 1). Then. the a1 = −(p1 + p2 ). indeed. the difference equation satisﬁed by hn will be: h(n)= ah(n − 1)+b0 δ(n)+b1 δ(n − 1) Example 3. hn + a1 hn−1 + · · · + aM hn−M = 0. The given expression for h(n) can be rewritten in the more compact form.9 The Ci pn terms are annihilated by the same product as in the previous problem. Next. let us determine directly the difference equation satisﬁed by h(n) and from that determine the difference equation for y(n). all the terms in hn will be annihilated by the product h(n)−ah(n − 1)= c0 δ(n)−ac0 δ(n − 1)+c1 a n−1 u(n − 1)−u(n − 2) But the difference u(n− 1)−u(n− 2)= δ(n− 1) as follows from the standard result u(n)−u(n− 1)= δ(n). etc. we have n−1 u(n − 2) (1 − aD)fn = fn − afn−1 = an − aan−1 = 0 n where D is the delay operator deﬁned by (Df )n = fn−1 . if n ≥ M + 1. It follows that the ﬁrst term p1 u(n) of hn will be annihilated by (1 − p1 D). Thus.7 It is evident from the deﬁnition that for n ≥ 2. setting b0 = c0 and b1 = c1 − ac0 and solving for h(n) we ﬁnd aM δ(n − M)+aM−1 δ(n − M + 1)+ · · · But.4. we are led to consider the delayed function h(n − 1) and multiply it by a: We ﬁnally ﬁnd the I/O difference equation for y(n): y(n)= ay(n − 1)+b0 x(n)+b1 x(n − 1) which is exactly the same as that satisﬁed by h(n). which was essentially derived in Example 3. we map this difference equation for h(n) into a difference equation for y(n). h(n − 1)= c0 δ(n − 1)+c1 a and n−2 u(n − 2) Problem 3. Therefore. then these terms vanish too.Problem 3. n≥M+1 Problem 3. that is.

we have with n ≥ 2: ⇒ (1 − 0.5D)= 1 − 0.25hn−2 = 0 For (c). the a1 = −(p1 + p2 + p3 ). 2: (C1 + C2 )−(C1 p2 + C2 p1 )z−1 C1 C2 = H(z)= + 1 − p1 z−1 1 − p2 z−1 (1 − p1 z−1 )(1 − p2 z−1 ) which may be rewritten as or.4hn−2 = 0 For (b). 1.3hn−1 + 0. n≥3 yn + a1 yn−1 + a2 yn−2 = b0 xn + b1 xn−1 These results can be obtained quickly using z-transforms: The coefﬁcients b0 . for n = 0.5jD)= 1 + 0. pn i a 2 = p 1 p2 + p 2 p3 + p 3 p 1 .4D)(1 − 0. the coefﬁcient of C1 is p2 + a1 p1 + a2 . 1: Problem 3.13 For (a). The coefﬁcients b0 .4D − 0.5D)(1 + 0.for n ≥ 2.3D + 0. the coefﬁcient of C2 is zero. which is zero because p1 is a root of the polynomial 1 z2 + a1 z + a2 . we ﬁnd: b0 = C 1 + C 2 b1 = C1 p1 + C2 p2 − (p1 + p2 )(C1 + C2 )= −(C1 p2 + C2 p1 ) To summarize. 2: b0 = C1 + C2 + C3 b1 = − C1 (p2 + p3 )+C2 (p3 + p1 )+C3 (p1 + p2 ) b2 = C1 p2 p3 + C2 p3 p1 + C3 p1 p2 b0 = h 0 b1 = h 1 + a 1 h0 b2 = h 2 + a 1 h1 + a 2 h 0 which give: Problem 3. the results can be justiﬁed quickly using z-transforms: (1 − 0. we have with n ≥ 3: ⇒ C1 C2 + H(z) = C0 + 1 − p1 z−1 1 − p2 z−1 (C0 + C1 + C2 )− C1 p2 + C2 p1 + C0 (p1 + p2 ) z−1 + C0 p1 p2 z−2 = (1 − p1 z−1 )(1 − p2 z−1 ) (1 − 0.1D3 hn − 0. a3 = −p1 p2 p3 terms in hn will be annihilated by the delay polynomial: (1 + a1 D + a2 D2 + a3 D3 )hn = (1 − p1 D)(1 − p2 D)(1 − p3 D)hh = 0 (P3.5jD)(1 + 0. To determine the coefﬁcients b0 . hn will satisfy the difference equation: Then.5D)(1 − 0.4D2 hn − 1. b0 = h 0 b1 = h 1 + a 1 h 0 b2 = h 2 + a 1 h 1 + a 2 h0 H(z)= b0 + b1 z−1 1 + a1 z−1 + a2 z−2 b0 = C1 + C2 + C3 b1 = C1 p1 + C2 p2 + C3 p3 + a1 (C1 + C2 + C3 ) b2 = C1 p2 + C2 p2 + C3 p2 + a1 (C1 p1 + C2 p2 + C3 p3 )+a2 (C1 + C2 + C3 ) 1 2 3 which simplify into: and leads to the desired difference equations for hn and yn .12 Deﬁne the polynomial with roots p1 . b1 .25hn−2 + 0. (P3.11 Now the difference equation Eq. for n = 0. p2 . 1. b1 may be found by explicitly calculating the right-hand side of this difference equation using the expression for hn .25D2 hn + 0. Again.4hn−1 − 0. b2 may be found by explicitly calculating the right-hand side of this difference equation using the expression for hn . b1 .8D)= 1 − 1.1) for n ≥ 3. we have with n ≥ 2: b0 = C 0 + C 1 + C 2 b1 = C1 p1 + C2 p2 + a1 (C0 + C1 + C2 )= −(p1 + p2 )C0 − (C1 p2 + C2 p1 ) b2 = C1 p2 + C2 p2 + a1 (C1 p1 + C2 p2 )+a2 (C0 + C1 + C2 )= C0 p1 p2 1 2 In b2 . hn + a1 hn−1 + a2 hn−2 = b0 δ(n)+b1 δ(n − 1) Inserting this into the convolutional equation.25D2 + 0.1) will be satisﬁed for n ≥ 3. we evaluate the right hand side for n = 0. we obtain the I/O difference equation: hn + a1 hn−1 + a2 hn−2 + a3 hn−3 = 0.1hn−3 = 0 ⇒ 30 31 . or. Problem 3. p3 : 1 + a1 z−1 + a2 z−2 + a3 z−3 = (1 − p1 z−1 )(1 − p2 z−1 )(1 − p3 z−1 ) so that b0 = h0 + a1 h−1 + a2 h−2 = h0 = C1 + C2 b1 = h1 + a1 h0 + a2 h−1 = h1 + a1 h0 = C1 p1 + C2 p2 + a1 (C1 + C2 ) Using the expression for a1 . Similarly. b2 .

y(n) and.Problem 3. we have: yD (n) = m hD (m)x(n − m)= m h(m − D)x(n − m) = k h(k)x(n − D − k)= y(n − D) where we changed summation variables from m to k = m − D. that is. hence y(0). 32 33 .18 ˜ Because h(n) agrees with h(n) for n ≥ −D. Therefore. It follows: ˜ |y(n)−y(n)| = | m=−∞ h(m)x(n − m)| ≤ m=−∞ |h(m)||x(n − m)| ≤ m=−∞ |h(m)|A y(0)= m h(m)x(−m)= m h(m)sign h(m) This summation is ﬁnite because it is a subsum of the stability condition: −D−1 ∞ Recognizing that in general xsign(x)= |x|. we have: −D−1 −D−1 −D−1 But. and evaluated y(n) at n − D. the number of terms shrinks to zero giving: −D−1 D→∞ Because x(n) was bounded.16 Working with the convolutional I/O equation. we ﬁnd |h(m)| ≤ m=−∞ m=−∞ |h(m)| < ∞ y(0)= m |h(m)| In the limit of large D. x(m)= sign h(−m) .17 We have: hD (m)xA (n − m)= m m h(m − D)x(n − m + D)= k h(k)x(n − k) where we changed variables of summation from m to k = m − D. lim |h(m)| → 0 m=−∞ Problem 3. must be bounded. then this term would not contribute to the convolutional sum. x(−m)= sign h(m) . If at some m.15 Starting with ˜ y(n) = m=−D ˜ h(m)x(n − m)= m=−D h(m)x(n − m) y(n)= m h(m)x(n − m) Subtracting. y(n)= k h(k)x(n − k) ⇒ y(n − D)= k h(k)x(n − D − k) Problem 3. we have: ∞ |y(n)| = | m h(m)x(n − m)| ≤ m |h(m)||x(n − m)| ≤ m |h(m)|B = AB y(n) = m=−∞ ∞ h(m)x(n − m) ∞ Problem 3.14 From the convolutional I/O equation we get: Problem 3. h(m)= 0. the terms m ≥ −D cancel and we get: −D−1 we obtain at n = 0: ˜ y(n)−y(n)= m=−∞ h(m)x(n − m) y(0)= m h(m)x(−m) Assuming x(n) is bounded by A.

7.1 The convolution table is: h\x 1 1 2 1 Folding the table. − 2 . The LTI table is: 1 1 1 2 1 2 2 2 4 2 1 1 1 2 1 1 1 1 2 1 2 2 2 4 2 1 1 1 2 1 1 1 1 2 1 1 1 1 2 1 The three subblocks begin at the absolute times n = 0. 2. respectively. aligning the output blocks according to their absolute timings and adding them up gives the ﬁnal result: n y0 y1 y2 y 0 1 1 3 2 5 3 6 1 7 4 4 3 7 5 1 5 6 6 6 1 7 7 4 2 6 8 1 3 4 9 10 1 3 5 3 3 1 1 In practice this method is implemented efﬁciently by computing the individual block convolutions using the FFT instead of time-domain convolution. 4 . 3. 5. and the middle 5 samples are the steady-state outputs. 6 . 4. 2. 1. 0 . 5. 3 .2 The convolution table is: h\x 2 -2 -1 1 Folding the table. 0] These convolutions can be done by separately folding the three convolution subtables: block 2 2 2 4 2 0 1 1 1 2 1 1 1 1 2 1 block 2 2 2 4 2 1 1 1 1 2 1 1 1 1 2 1 block 1 1 1 2 1 2 0 0 0 0 0 Problem 4. 2] y1 = h ∗ x1 = [1. Convolving each block separately with h gives: y0 = h ∗ x0 = [1. 1. 7 . 1 ] The ﬁrst and last three samples are the input and output transients. The LTI table is: 2 4 -4 -2 2 2 4 -4 -2 2 0 0 0 0 0 1 2 -2 -1 1 -1 -2 2 1 -1 0 0 0 0 0 1 2 -2 -1 1 2 4 -4 -2 2 h\ x 1 1 2 1 1 1 1 2 1 34 35 . 6 . 3. 1 . and the middle 5 samples are the steady-state outputs. 7. 2 . we get y = [ 1 . 1. 1 . 3. 1] y2 = h ∗ x2 = [1. − 1 . 1. The computational gain of this “fast” convolution method versus the conventional time-domain “slow” method is approximately log2 N fast = slow M If the input is divided into length-5 subblocks. 1] Aligning them at multiples of n = 5. 5. 0 ] x0 x1 x2 n y0 y1 y 0 1 1 1 3 3 2 5 5 3 7 7 4 7 7 5 5 1 6 6 5 2 7 7 2 4 6 8 4 4 9 3 3 10 1 1 where we padded an extra zero at the end to get a length-3 block. 5 . 1. the input is divided into the following three contiguous blocks: x = [ 1. the last subblock will have length 3: x = [ 1. 7. 3 . 6. 1. 2. 2. 1. − 6 . 2. − 5. 4. 1. we get y = [ 4. 5. 2] The ﬁrst and last three samples are the input and output transients. 3. 1. 3.Chapter 4 Problems Problem 4. 1] y1 = h ∗ x1 = [1. 5. 3. the length of each x-block is chosen to be N1 = N − M. 4. For an FIR ﬁlter of order M and an FFT of length N (which is a power of two). 6. 4. It follows from timeinvariance that the corresponding output blocks will also begin at the same absolute times. 2. 1 ] x0 The convolutions of the subblocks with the ﬁlter are: y0 = h ∗ x0 = [1. we have: x1 n x\ h 1 2 1 1 2 1 1 1 0 1 1 1 1 1 2 2 2 2 2 1 3 1 1 4 1 1 4 5 6 7 8 9 10 partial output x(0)h(n − 0) x(1)h(n − 1) x(2)h(n − 2) x(3)h(n − 3) x(4)h(n − 4) x(5)h(n − 5) x(6)h(n − 6) x(7)h(n − 7) 2 2 1 2 1 2 2 1 1 4 1 1 7 2 2 1 1 6 1 2 1 4 1 2 3 1 1 y(n) 1 3 5 7 7 6 x(m)h(n − m) m For the overlap-add method. 7. 6. 1. 4. Thus. 3.

2. 0 ] x0 x1 x2 n y(n) 4 3 2 1 0 3 6 10 13 on where we padded an extra zero at the end to get a length-3 block. 2. 0.1 shows the ﬁlter.1) n y0 y1 y2 y 0 4 1 0 2 -6 3 0 2 2 4 2 -4 -2 5 1 1 1 6 7 8 9 10 ⇒ 13 ≤ n ≤ 26 4 0 -6 If the input is divided into length-5 subblocks. we get: 10 + m ≤ n ≤ 20 + m Using the ﬁrst of Eq. −1. −4. 1. input. 2.n x\h 2 2 0 1 -1 0 1 2 0 2 4 1 -2 -4 4 2 -1 -2 -4 0 3 1 2 -2 0 2 4 5 6 7 8 9 10 partial output x(0)h(n − 0) x(1)h(n − 1) x(2)h(n − 2) x(3)h(n − 3) x(4)h(n − 4) x(5)h(n − 5) x(6)h(n − 6) x(7)h(n − 7) n y0 y1 y 0 4 4 1 0 0 2 -6 -6 3 2 2 4 -2 -2 2 0 -2 -2 5 1 0 1 6 2 2 4 7 -1 2 1 8 -5 -5 9 -1 -1 10 2 2 0 -1 2 0 1 1 0 2 4 -1 0 -2 4 1 Problem 4. 2 ] x0 The convolutions of the subblocks with the ﬁlter are: y0 = h ∗ x0 = [4.1) are equivalent to 3≤m≤6 n − 20 ≤ m ≤ n − 10 ⇒ max (3. 2. 1. we extend the range to: 2 2 4 -1 2 1 0 -5 -5 -1 -1 2 2 10 + 3 ≤ 10 + m ≤ n ≤ 20 + m ≤ 20 + 6 (P4. 0. the input is divided into the following three contiguous blocks: x = [ 2. −1. −5. 0. −1. h\ x 2 -2 -1 1 block 0 2 2 0 4 4 0 -4 -4 0 -2 -2 0 2 2 0 block 1 1 -1 0 2 -2 0 -2 2 0 -1 1 0 1 -1 0 block 2 1 2 2 4 -2 -4 -1 -2 1 2 For the direct form. 2. 0. n − 10) The ﬁnal expression for the direct form will be: 36 37 . −1. x(n). −2.3. −2. 0. 1. −6.1) and solve for m: −20 ≤ m − n ≤ −10 ⇒ n − 20 ≤ m ≤ n − 10 Thus. (P4. 2. −1] y1 = h ∗ x1 = [0. we have: Aligning the output subblocks at multiples of n = 3. −5. 2. 0. 2] These convolutions can be done by separately folding the three convolution subtables: 16 20 steady 23 off 26 n Fig. 2] Aligning them at multiples of n = 5.1). 0] y2 = h ∗ x2 = [2. −1. 1. 0 -1 -4 -5 1 -2 -1 2 2 y(n) 4 0 -6 2 -2 1 x(m)h(n − m) m h(n) 1 0 3 6 10 13 x(n) 16 20 23 26 For the overlap-add method. we have: x1 This is the range of index n of the output yn .3 Figure P4. and computed output signals.1 h(n). 1. To ﬁnd the limits of summation over m. (P4. 2. P4. we change the sign of the second of Eq. the last subblock will have length 3: x = [ 2. n − 20)≤ m ≤ min(6. Convolving each block separately with h gives: y0 = h ∗ x0 = [4. −6. the indices of hm and xn−m are restricted to lie within their respective ranges: 3≤m≤6 10 ≤ n − m ≤ 20 Solving the second with respect to n. 2] y1 = h ∗ x1 = [2. and y(n) signals of Problem 4. the inequalities in Eq. 1. (P4. 0.

4 .n−3) yn = m=max(10. 3 . 4 .1. if the ﬁlter and input signals are unity over the ranges (P4. (P4. we have n 1 1−a for n − ∞ → n y(n)= m=0 am (−1)n−m = (−1)n m=0 (−a)m = (−1)n 1 − (−a)n+1 1+a Problem 4. n − 20)+1 (P4.n−6) 1 · 1 = min(10. 0≤n<∞ Note also that because the ﬁlter is delayed by 3 samples. for 13 ≤ n ≤ 26 The transition from the input-on transients to the steady state takes place at time 6 = n − 10 or n = 16 at which the upper limit switches from n − 10 to 6. In summary. input-on: 13 ≤ n ≤ 15 yn = m=3 6 hm xn−m Problem 4. 2 . 4 . Note that because the input is constant. Similarly. Eq.n−20) 1 · 1 = min(6. at n = 23. that is. The square pulse x(n)= u(n)−u(n − L) of duration L is applied as input. 4 . n − 10)− max (3. 4 . the input is cutoff at n = 20 but this is not felt by the ﬁlter until 3 instants later. the steady-state DC output can be predicted in advance from the DC gain: y(n)− → yn = n − 10 − 3 + 1 = n − 12 yn = 6 − 3 + 1 = 4 yn = 6 − (n − 20)+1 = 27 − n If x(n)= (−1)n u(n). we use the formula: n n steady-state: 16 ≤ n ≤ 23 yn = m=3 6 input-off: 24 ≤ n ≤ 26 yn = m=n−20 hm xn−m y(n)= m=0 h(m)x(n − m)= m=0 am u(m)u(n − m) or.n−L+1) h(m)x(n − m). Or. (P4. Also.3) Note that Eq. 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. more explicitly: input-on: 13 ≤ n ≤ 15 steady-state: 16 ≤ n ≤ 23 input-off: 24 ≤ n ≤ 26 With numerical values: y = { 1.16) becomes: n yDC = m hm = 1 + 1 + 1 + 1 = 4 y(n)= m=max(0.4 hm xn−m Because both the input and ﬁlter are causal and have inﬁnite duration. but to the summation limits: Inserting the given signals for h(n) and x(n). we have: yn = m=max(10. the output will not begin to come out until 3 time instants after the input begins. 3.n−L+1) am · 1 Using the geometric series identity M2 am = m=M1 aM1 − aM2 +1 1−a we ﬁnd: 38 39 . For the LTI form.5 Consider the IIR ﬁlter h(n)= an u(n). for 13 ≤ n ≤ 26.n−20) hm xn−m . that is. the three ranges are: n−10 min(20. n − 6)− max (20. Because the ﬁlter is inﬁnite (M = ∞). 4 .2). 1 } The ﬁrst and last M = 3 samples are the input on/off transients. we ﬁnd: n y(n)= m=max(0. 4 .2) The steady-state response is the large-n limit of this formula. 2 . that is at n = 13.n−6) xm hn−m . n − 3)+1 (P4. (P4.n−3) yn = m=max(3.n−10) min(20.n−10) n y(n)= m=0 am = 1 − an+1 1−a yn = m=max(3. Eq. 4 . In particular.min(6. (4. where 0 < a < 1. for 13 ≤ n ≤ 26 For part (b).1) is replaced by 10 ≤ m ≤ 20 3≤n−m≤6 This leads to the same range for the output index n. 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.3) is equivalent to Eq. The middle samples are the steady samples. the output can be expressed compactly as: min(6.1).

conv(Ma. for (n=0. ya). m++) y[n] += x[m] * h[n-m].h> #include <math.1. *yb. L = 200.7 For example. (4. 4.c . n − L + 1)= 0. -1. and y(n)= an−L+1 − an+1 1 − aL = an−L+1 = an−L+1 y(L − 1).h> void convlti(M. conv(Mb. double ha[Ma+1]. void main() { int K = 50.n−L+1) − an+1 1−a The following C program computes the output signals of the two ﬁlters (a) and (b) of Example 4. ya[n]). n − L + 1)= n − L + 1.8 */ #include <stdio.Problem 4. we have x(n)= 1 and 1 − an+1 1 − an 1 − an+1 − a + an+1 −a = = 1 = x(n) y(n)−ay(n − 1)= 1−a 1−a 1−a Finally. compute outputs printf("\n\n"). Problem 4. n++) printf("%lf\n". n<=Ma. n++) printf("%lf\n".h> #define Ma 14 #define Mb 5 void conv(). hb[Mb+1] = {0.c . for (n=0.h> #define MAX 64 memory allocation size 40 41 . sizeof(double)). n++) for (y[n] = 0. ya = (double *) calloc(L+Ma. *y. after the input is turned off.convolution example 4. L=input length for (n = 0. n<L. { int n. L. the LTI form is obtained by interchanging the roles played by x and h and their lengths L and M + 1. n < L+M. double *x. *ya. else x[n] = 0.75.c . n). n-M).8. for (n=0. yb = (double *) calloc(L+Mb. for 0 ≤ n ≤ L − 1.1.1. hb. for (n=0. 1−a 1−a (input-off) Thus. /* blkfilt. x.(b) deﬁne ﬁlter (a) deﬁne input y(n)−ay(n − 1)= an−L+1 yL−1 − aan−1−L+1 yL−1 = 0 = x(n) Problem 4. yb). The following routine is an implementation of Eq. we have max (0.8: /* convex.6 From the previous problem. n++) if (n%K < K/2) x[n] = 1. n. x. -2. x=input block. yb[n]). n<L+Ma.9 A complete such program is included below. 2. 1. for n ≥ L.19): /* convlti. 1 − a0+1 − a · 0 = 1 = x(0) 1−a y(0)−ay(−1)= Then. *x.8 (a) Ex. sizeof(double)).1. L-1). m <= min(n. L. L. y=output block M=ﬁlter order. we have at n = 0.8 y(n)= amax(0. the output decays exponentially to zero. L. for 1 ≤ n ≤ L − 1. and y(n)= 1−a 1−a n+1 (input-on transients and steady state) whereas for n ≥ L. h. we have x(n)= 0 and Ex. n++) ha[n] = 0. x. we have max (0. int M. sizeof(double)). } h=ﬁlter. 4.25 * pow(0. m. deﬁnes max( ) and min( ) In particular.2}. n<L+Mb.1.2. ha. -0. y) double *h. } Problem 4.FIR filtering by block convolution */ #include <stdio. m = max(0.h> #include <stdlib.convolution in LTI form */ #include <stdlib.h> #include <stdlib. x = (double *) calloc(L.

The ﬁltering portion of the program is identical to the program segment discussed at the end of Section 4. dmax = MAX. M++) { if (M == max) { if necessary. L. ﬁnal allocation x = (double *) calloc(L. states. N<L. (max + 1) * sizeof(double)). ytemp). M++) { read h if (M == max) { reallocate h. } block length The dimension of the ﬁlter array h is determined on the ﬂy by reading the ﬁle of ﬁlter coefﬁcients. (M + 1) * sizeof(double)). y[i]). read input block N=L except for last process block write output block process last block last block has N<=L for (M=0. /* firfilt. "r")) == NULL) { fprintf(stderr. h. "blocksize L must be at least %d\n". *y. ytemp). initial allocation size M--. } h = (double *) calloc(max + 1. y[i]). x. the next group of L input samples is entered and the program outputs the corresponding group of L outputs. int max = MAX. only after a group of L samples has been entered followed by a <CR> (carriage return). sizeof(double)). "%lf". i++) printf("%lf\n". sizeof(double)). } L = atoi(argv[2]).10 A complete such program is included below. Because the length of this ﬁle is not known in advance.. sizeof(double)). "%lf".10. one must enter a <CTRL-Z> (for MSDOS) in order for the program to process the input-off transients. M). int M. and so on. double *h. y. sizeof(double)). if necessary max += dmax. x+N) == EOF) goto last. exit(0). "usage: firfilt hfile <xfile >yfile\n"). i. } ﬁlter ﬁle M = ﬁlter order. output samples allocation for h and increment if (argc != 2) { fprintf(stderr. } if ((fph = fopen(argv[1]. y. "usage: blkfilt hfile L <xfile >yfile\n"). write entire y block if (argc != 3) { fprintf(stderr. i++) printf("%lf\n". allocate output block ytemp = (double *) calloc(M. i. argv[1]). void main(int argc. exit(0). N. blockcon(M. *x. h = (double *) calloc(max + 1. reallocate h max += dmax. Then. 42 43 . M is ﬁlter order if (L < M) { fprintf(stderr. will the program output the ﬁrst group of L outputs. N++) if (scanf("%lf". x. The program can receive its input from stdin with the user entering the input samples one at a time.c . h = (double *) realloc((char *) h.h> #include <stdio. However. "can’t open filter file: %s\n". N. } last: blockcon(M. initialized to zero start ﬁltering: ﬁlter ﬁle ﬁlter. (max + 1) * sizeof(double)). exit(0). h + M) == EOF) break. i<L. } h = (double *) realloc((char *) h. y.h> #define MAX 64 double fir(). h + M) == EOF) break. dmax = MAX. h.. exit(0). L = blocksize initial allocation & increment for (i=0. exit(0). } if (fscanf(fph..) { for (N=0. preliminary allocation for (. the program keeps reallocating the length of h in increments of MAX coefﬁcients until the ﬁnal length is determined and the ﬁnal reallocation is made. } if (fscanf(fph. *ytemp. for (i=0. int max = MAX.1. void main(int argc. Problem 4. read h for (M=0. *w. h = (double *) realloc((char *) h. "can’t open filter file: %s\n". allocate input block y = (double *) calloc(L + M. At the end. } if ((fph = fopen(argv[1]. double *h. argv[1]). input. int M. L. char **argv) { FILE *fph. char **argv) { FILE *fph.void blockcon(). x. sizeof(double)). i<N+M.FIR filtering by sample-by-sample processing */ #include <stdlib. "r")) == NULL) { fprintf(stderr.

} M--;

M is ﬁlter order ﬁnal allocation

if ((fph = fopen(argv[1], "r")) == NULL) { fprintf(stderr, "can’t open filter file: %s\n", argv[1]); exit(0); } h = (double *) calloc(max + 1, sizeof(double));

preliminary allocation

**h = (double *) realloc((char *) h, (M + 1) * sizeof(double)); w = (double *) calloc(M + 1, sizeof(double));
**

start ﬁltering:

while(scanf("%lf", &x) != EOF) { y = fir(M, h, w, x); printf("%lf\n", y); } for (i=0; i<M; i++) { y = fir(M, h, w, 0.0); printf("%lf\n", y); } }

keep reading input samples compute output sample write output sample

input-off transients

for (M=0;; M++) { read h if (M == max) { reallocate h, if necessary max += dmax; h = (double *) realloc((char *) h, (max + 1) * sizeof(double)); } if (fscanf(fph, "%lf", h + M) == EOF) break; } M--;

M is ﬁ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 coefﬁcients. The program keeps reallocating the length of h in increments of MAX coefﬁcients 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. The program can receive its input from stdin with the user entering the input one sample at a time. After each input is entered followed by a <CR>, the program computes and outputs the corresponding output sample. (One can also enter a few input samples at a time, followed by a <CR>, and the program will produce the corresponding outputs.) At the end, one must enter a <CTRL-Z> (for MSDOS) in order for the program to process the input-off transients.

}

**h = (double *) realloc((char *) h, (M + 1) * sizeof(double)); w = (double *) calloc(M + 1, sizeof(double)); initialize p p = w;
**

start ﬁltering:

while(scanf("%lf", &x) != EOF) { y = cfir(M, h, w, &p, x); printf("%lf\n", y); } for (i=0; i<M; i++) { y = cfir(M, h, w, &p, 0); printf("%lf\n", y); }

keep reading input samples compute output sample write output sample

input-off transients

Problem 4.11

A complete such program is included below.

/* cfirfilt.c - FIR filtering using circular delay-line buffer */ #include <stdlib.h> #include <stdio.h> #define MAX 64 double cfir(); void main(int argc, char **argv) { FILE *fph; double *h, *w, *p; double x, y; int M, i; int max = MAX, dmax = MAX;

initial allocation size

It is identical to firfilt.c, except it uses the circular version cfir instead of fir to do the ﬁltering. In addition, the circular pointer p is deﬁned and initialized by the program. This program must be compiled and linked with cfir.c and wrap.c. The version using the routine cfir1 is identical. The following version is based on the routine cfir2 and uses the circular pointer index q instead of the pointer p. It must be linked with the routines cfir2 and wrap2.

/* cfirfil2.c - FIR filtering using circular delay-line buffer */ #include <stdlib.h> #include <stdio.h>

ﬁlter ﬁle ﬁlter, states, circular pointer input and output samples allocation for h and increment

#define MAX 64 double cfir2(); void main(int argc, char **argv) { FILE *fph; double *h, *w; double x, y; int M, i, q; int max = MAX, dmax = MAX;

initial allocation size

if (argc != 2) { fprintf(stderr, "usage: cfirfilt hfile <xfile >yfile\n"); exit(0); }

ﬁlter ﬁle ﬁlter, states, circular pointer input and output samples circular pointer index allocation for h and increment

44

45

if (argc != 2) { fprintf(stderr, "usage: cfirfil2 hfile <xfile >yfile\n"); exit(0); } if ((fph = fopen(argv[1], "r")) == NULL) { fprintf(stderr, "can’t open filter file: %s\n", argv[1]); exit(0); } h = (double *) calloc(max + 1, sizeof(double));

preliminary allocation

if (argc != 3) { fprintf(stderr, "usage: cdelfilt i D <xfile >yfile\n"); exit(0); } i = atoi(argv[1]); D = atoi(argv[2]); if (i>D) { fprintf(stderr, "i must be in the range {0, 1, ..., D}\n"); exit(0); } w = (double *) calloc(D + 1, sizeof(double)); p = w; while(scanf("%lf", &x) != EOF) { *p = x; y = tap(D, w, p, i); cdelay(D, w, &p); printf("%lf\n", y); } for (j=0; j<i; j++) { *p = 0; y = tap(D, w, p, i); cdelay(D, w, &p); printf("%lf\n", y); } }

for (M=0;; M++) { read h if (M == max) { reallocate h, if necessary max += dmax; h = (double *) realloc((char *) h, (max + 1) * sizeof(double)); } if (fscanf(fph, "%lf", h + M) == EOF) break; } M--;

M is ﬁlter order

initialize p keep reading input samples store in circular buffer y(n) = x(n-i) = i-th delay update delay line write output sample

**h = (double *) realloc((char *) h, (M + 1) * sizeof(double)); w = (double *) calloc(M + 1, sizeof(double)); initialize q q = 0;
**

start ﬁltering:

input-off transients zero input

while(scanf("%lf", &x) != EOF) { y = cfir2(M, h, w, &q, x); printf("%lf\n", y); } for (i=0; i<M; i++) { y = cfir2(M, h, w, &q, 0); printf("%lf\n", y); } }

keep reading input samples compute output sample write output sample

Problem 4.13

input-off transients

Consider a 3d order ﬁ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

The following C program is an implementation:

/* cdelfilt.c - Implementation of delay using circular buffer */ #include <stdlib.h> #include <stdio.h> double cdelay(); double tap(); void main(int argc, char **argv) { double *w, *p; double x, y; int D, i, j;

w1 (n) = w0 (n − 1) w0 (n) = x(n)

Thus, the current states are obtained from the previous ones by shifting the previous contents of the delay line and reading x(n) into w0 (n). Once this shift is done, the ﬁlter’s output is computed by the dot product:

y(n)= h0 w0 (n)+h1 w1 (n)+h2 w2 (n)+h3 w3 (n)

The following routine firalt.c implements this alternative procedure:

/* firalt.c - Alternative version of FIR filter in direct form */

linear buffer & circular pointer input and output samples

double firalt(M, h, w, x) double *h, *w, x; int M; {

Usage: y=ﬁralt(M, h, w, x); h=ﬁlter, w=state, x=input M=ﬁlter order

46

47

int i; double y; for (i=M; i>=1; i--) w[i] = w[i-1]; w[0] = x; for (y=0, i=0; i<=M; i++) y += h[i] * w[i]; return y; }

n

y=output sample update states from previous call done in reverse order read current input sample x

x

1 2 1 1 2 1 1 1 0 0 0

w0

1 2 1 1 2 1 1 1 0 0 0

w1

0 1 2 1 1 2 1 1 1 0 0

w2

0 0 1 2 1 1 2 1 1 1 0

w3

0 0 0 1 2 1 1 2 1 1 1

y = w0 + w1 + 2w2 + w3

1 3 5 7 7 6 7 6 4 3 1

process current output sample

0 1 2 3 4 5 6 7 8 9 10

Note that the previous state vector is updated ﬁ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.

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:

#include <stdio.h> #include <malloc.h>

Problem 4.14

Introduce the internal states:

declares calloc()

w0 (n) = x(n) w1 (n) = x(n − 1)= w0 (n − 1) w2 (n) = x(n − 2)= w1 (n − 1) w3 (n) = x(n − 3)= w2 (n − 1)

Then, the I/O equation together with the state-updating equations will read:

double x[8] = {1,2,1,1,2,1,1,1}; double filter2(); void main() { int n; double y, *w; w = (double *) calloc(4, sizeof(double)); for (n=0; n<8; n++) { y = filter2(x[n], w); printf("%lf\n", y); } for (n=8; n<11; n++) { y = filter2(0.0, w); printf("%lf\n", y); } } double filter2(x, w) double x, *w; { double y; w[0] = x; y = w[0] + w[1] + 2 * w[2] + w[3]; w[3] = w[2]; w[2] = w[1]; w[1] = w[0];

usage: y = ﬁlter2(x, w); allocates & initializes w to zero

w0 (n)= x(n)

and

w3 (n + 1) = w2 (n) w2 (n + 1) = w1 (n) w1 (n + 1) = w0 (n)

input-on transients & steady-state

y(n)= w0 (n)+w1 (n)+2w2 (n)+w3 (n)

**This leads to the following sample processing algorithm and block diagram:
**

input-off transients

x

w0 w1

y z-1 z

-1

for each input sample x do:

w2 w3 z-1 2

w0 = x y = w0 + w1 + 2w2 + w3 w3 = w 2 w2 = w 1 w1 = w 0

read input sample compute output sample update internal states

The sample processing algorithm generates the following output samples:

48

49

25 4. } Then.8000 3.25 y for each input sample x do: y = 0.7520 7.16 We deﬁne the internal state: w1 (n)= y(n − 1) 0 1 2 3 4 50 51 .8y(n − 1)+x(n) and the state updating equation will read: y(n)= 0.7520 y = 0 . 2.8016 w0 (n)= x(n) and w3 (n + 1) = w2 (n) w2 (n + 1) = w1 (n) w1 (n + 1) = w0 (n) y(n)= w0 (n)−w3 (n) Note that the output y(n) at time n and the next internal states at time n + 1 are computable from the knowledge of the present input x(n) and the present states at time n.8000 3.5625 w1 0 1 1 2. The sample processing algorithm can be cranked on the given input samples to generate the output: n x 1 1 2 2 4 y = 0.0000 1.25w2 + x The sample processing algorithm can be applied to the given input samples to generate the output samples: n 0 1 2 3 4 x 1 1 2 2 4 w0 1 1 2 2 4 w1 0 1 1 2 2 w2 0 0 1 1 2 w3 0 0 0 1 1 y = w0 − w 3 1 1 2 1 3 w2 = w1 w1 = y General versions of such routines will be considered in Chapter 7. the difference equation y(n)= 0.25w2 (n)+x(n) w2 (n + 1) = w1 (n) and w1 (n + 1) = y(n) This leads to the following sample processing algorithm and block diagram realization: x y z-1 w1 z-1 w2 0.15 We deﬁne the state-variables wi (n).25 2.25w2 + x 1 1 2. 3 as follows: x y z-1 w1 0. the I/O equation y(n)= x(n)−x(n − 3) together with the state-updating equations will read: w1 = y The table of computations is: n 0 1 2 3 4 x 1 1 2 2 4 w1 0. 8w 1 + x w0 (n) = x(n) w1 (n) = x(n − 1)= w0 (n − 1) w2 (n) = x(n − 2)= w1 (n − 1) w3 (n) = x(n − 3)= w2 (n − 1) Then.0000 1.25y(n − 2)+x(n) and state updating equations become: y(n)= 0. i = 0.25 2.return y.8w1 (n)+x(n) and w1 (n + 1)= y(n) This leads to the following sample processing algorithm and block diagram realization: Problem 4. This leads to the following sample processing algorithm and block diagram realization: Problem 4. 8w 1 + x 1.4400 4.0000 1.8 y for each input sample x do: y = 0 .25 w2 0 0 1 1 2. 1.25 Problem 4.17 We deﬁne the internal states: w1 (n) = y(n − 1) w2 (n) = y(n − 2)= w1 (n − 1) x w0 z w1 w2 w3 z -1 -1 y for each input sample x do: ⇒ w1 (n + 1) = y(n) w2 (n + 1) = y(n − 1)= w1 (n) z-1 -1 w0 = x y = w0 − w3 w3 = w2 w2 = w1 w1 = w0 The difference equation y(n)= 0.4400 4.

Thus. w. After y is computed. w1 and w2 are simply the input signal delayed by i = 0. 1. only one w-register changes value at each time instant. 2. 2 units. that is. y(n)= x(n − 2). w1 ] at successive time instants. 2. so does pout . 2. 3. 2. 2. but tap-2 and tap-3 are. p. which receives the input sample x. 0. 2. w1 . In the circular case. 1. the down-arrow indicates the w-register receiving the current input. that is. The block diagram and sample processing algorithm are: Problem 4. 2) s3 = tap(3. 2 ] The LTI form is implemented by the following table: x w0 w1 w2 y z z -1 for each input sample x do: -1 -1 n x\h 1 1 2 2 2 2 1 1 0 1 1 1 0 0 1 2 -1 -1 0 2 3 2 2 -1 0 2 4 5 6 7 8 9 10 partial output x(0)h(n − 0) x(1)h(n − 1) x(2)h(n − 2) x(3)h(n − 3) x(4)h(n − 4) x(5)h(n − 5) x(6)h(n − 6) x(7)h(n − 7) w3 z-1 2 w0 = x y = w0 − w2 + 2w3 w3 = w2 w2 = w1 w1 = w0 The corresponding circular-buffer version will be: for each input sample x do: 2 -2 0 2 4 -2 0 2 4 -2 0 1 3 4 -2 0 1 3 4 -1 0 3 2 -1 1 2 2 s0 = ∗p = x s2 = tap(3. 4] y1 = h ∗ x1 = [2. 3. 2. 0.Notice how the computed y becomes the next w1 and w1 shifts into w2 . 2] These convolutions can be done by separately folding the two convolution subtables: block 0 1 2 2 2 0 0 -1 -2 2 4 block 1 2 1 2 1 0 0 -2 -1 4 2 x1 Problem 4. 1. whereas the pointer pout points to the w-register containing the current output. 0. that is. Therefore. − 1 . 3. 1. 2. 0. 0. In the linear case. If pin points to w[qin ] and pout to w[qout ]. w[qin ]. the call to cdelay circularly decrements the pointer p. 1. then h\x 1 0 -1 2 pin = w + qin 1 1 0 -1 2 1 1 0 -1 2 2 2 0 -2 4 2 2 0 -2 4 pout = w + qout where qout = (qin + 2)% 3 Thus. y(n) 1 1 1 3 2 4 x(m)h(n − m) m For the overlap-add method. 1. whereas the up-arrow indicates the corresponding output sample.19 Figure P4. 1. It follows from timeinvariance that the corresponding output blocks will also begin at the same absolute times. 0. 1. 1 The following table lists the contents of w for both the linear and circular buffer implementations. 2. respectively. the input and output circular indices take on the sequence of values: The two subblocks begin at the absolute times n = 0. 0 . ] x0 Convolving each block separately with h gives: y0 = h ∗ x0 = [1.18 The impulse response is read off from the coefﬁcients of the I/O equation: h = [ 1. 2. 4. Tap-0 s0 is the content of the current location pointed to by p. 2 qout = 2. −1. p. 1. 1.2 shows the contents of the registers w = [w0 . pout is shifted clockwise by 2 with respect to pin : pout = pin + 2 (modulo 3) As pin gets decremented circularly. aligning the output blocks according to their absolute timings and adding them up gives the ﬁnal result: qin = 0. 3) y = s0 − s2 + 2s3 cdelay(3. n y0 y1 y 0 1 1 1 1 1 2 1 1 3 3 3 4 0 2 2 5 2 2 4 6 4 -1 3 7 3 3 8 3 3 9 1 1 10 2 2 52 53 . 0. w. 2. & p) where tap-1 is not needed. the input is divided into the following length-4 contiguous blocks: x = [ 1. 1. 2. 1. Each time the circular pointer p = pin points to the w-register that receives the current input. 1. w0 . w[qout ]. w. In the circular case.

as in Fig. 3. 4. Replace all adders by nodes. Replace all nodes by adders. the output adder will be replaced by a node with the signals ﬂowing in reversed directions. (4. 4. 4.3 Transposed direct form realization. Indeed. and v3 (n+ 1) three times. the vi (n) are no longer the delayed versions of each other. that is.20 The transposed form is obtained by the following rules: 1. 54 55 . Problem 4. that is.7.2. P4. linear circular n 0 1 2 3 4 5 6 7 8 9 10 x 8 7 6 5 4 3 2 1 0 0 0 w0 8 7 6 5 4 3 2 1 0 0 0 w1 0 8 7 6 5 4 3 2 1 0 0 w2 0 0 8 7 6 5 4 3 2 1 0 w0 8↓ 8 8↑ 5↓ 5 5↑ 2↓ 2 2↑ 0↓ 0 w1 0 0↑ 6↓ 6 6↑ 3↓ 3 3↑ 0↓ 0 0↑ w2 0↑ 7↓ 7 7↑ 4↓ 4 4↑ 1↓ 1 1↑ 0↓ qin 0 2 1 0 2 1 0 2 1 0 2 qout 2 1 0 2 1 0 2 1 0 2 1 y 0 0 8 7 6 5 4 3 2 1 0 Let v1 (n). We can draw it reversed. P4. 2.2. and x(n) will be exchanged with y(n). each is a delayed version of its input.2. These inputs will become the contents of the delays at the next time instant. P4. and v3 (n) be the contents of the three delays at time n. in Fig. 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. y(n)= h0 x(n)+v1 (n)= h0 x(n)+ h1 x(n − 1)+v2 (n − 1) Similarly.3. Fig.w1 0 n=0 0 n=1 w0 8 7 n=2 6 8 n=3 6 y(n) 5 h0 v1 (n) z-1 h1 pin pout w2 0 n=4 6 pout pin pin pout 8 x(n) pin pout 7 7 n=5 3 5 n=6 3 3 n=7 pout 2 2 v2(n) z-1 h2 v3(n) z-1 h3 pout pin pin pout 5 pin pout 4 pin 1 4 4 n=8 0 n=9 0 0 n=10 pout 0 0 pin pout 2 pin pout 1 pin 0 1 Fig.6). v3 (n − 2)= h3 x(n − 3). They can be thought of as the internal states of the realization. Because of the intervening adders between the delays. Reverse all signal ﬂows. down-shifting v2 (n+ 1) twice. Exchange input with output. Rather. The resulting block diagram is shown in Fig. v2 (n). we have v1 (n)= v2 (n − 1)+h1 x(n − 1) Therefore. v2 (n− 1)= v3 (n− 2)+h2 x(n− 2).2 Circular delay-line buffer contents.3.6). we get y(n) = h0 x(n)+h1 x(n − 1)+v2 (n − 1) = h0 x(n)+h1 x(n − 1)+ h2 x(n − 2)+v3 (n − 2) = h0 x(n)+h1 x(n − 1)+h2 x(n − 2)+h3 x(n − 3) which is equivalent to Eq. Therefore. and the nodes at the inputs of the delays will be replaced by adders. The I/O system leads then to the following sample by sample processing algorithm: For example. down-shifting v1 (n + 1).1.

The v1 and v2 entries in each row are obtained by forming v2 + h1 x and v3 + h2 x of the previous row. x=input M=ﬁlter order for (M=0. sizeof(double)).2. Problem 4. return v[0]. M++) { read h if (M == max) { reallocate h. . while(scanf("%lf". The ﬁnal result is the same as in Example 4. Table P4. 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).c is an implementation: /* firtr. h. } if (fscanf(fph.21 The generalization of the transposed algorithm to order M is straightforward: for each input sample x do: for i = 0. i++) { keep reading input samples compute output sample write output sample input-off transients 56 57 . char **argv) { FILE *fph.1 shows the contents of the vi registers at each time instant.c .h> #define MAX 64 double firtr(). v = (double *) calloc((M + 1). The v3 column is the delayed (down-shifted) version of the h3 x column.1 Computations in Problem 4.h> #include <stdio. M is ﬁlter order ﬁnal allocation h = (double *) realloc((char *) h. h + M) == EOF) break. y).20.1. x.1. { int i. input.c instead of fir. Usage: y=ﬁrtr(M. v[M] = h[M] * x.c. *v. x).c is the corresponding version of firfilt. int max = MAX. v. The only difference is that it uses the routine firtr. double *h.c . output samples allocation for h and increment if (argc != 2) { fprintf(stderr. } for (i=0. output & update states last state for each input sample x do: y = v1 + h 0 x v1 = v 2 + h 1 x v2 = v3 + h2 x v3 = h3 x For Example 4. if necessary max += dmax. v=state. "usage: firfilt hfile <xfile >yfile\n"). i<=M-1. } y = v0 = v1 + h0 x The following stand-alone C program firfiltr. .FIR filter in transposed direct form */ double firtr(M. . &x) != EOF) { y = firtr(M. exit(0). *v.FIR filtering in transposed form */ #include <stdlib. The following C routine firtr. initial allocation size n 0 1 2 3 4 5 6 7 8 9 10 x 1 1 2 1 2 2 1 1 0 0 0 h0 x 1 1 2 1 2 2 1 1 0 0 0 h1 x 2 2 4 2 4 4 2 2 0 0 0 h2 x −1 −1 −2 −1 −2 −2 −1 −1 0 0 0 h3 x 1 1 2 1 2 2 1 1 0 0 0 v1 0 2 1 4 1 5 3 2 3 0 1 v2 0 v3 0 1 1 2 1 2 2 1 1 0 0 y = v1 + h0 x 1 3 3 5 3 7 4 3 3 0 1 −1 0 −1 1 −1 0 1 0 1 0 ﬁlter ﬁle ﬁlter array. h=ﬁlter. exit(0). (M + 1) * sizeof(double)). . dmax = MAX. argv[1]). h. sizeof(double)). } M--. y. int M. printf("%lf\n".for (i=0. "can’t open filter file: %s\n". The vi are initialized to zero. int M. } if ((fph = fopen(argv[1]. h = (double *) realloc((char *) h. x) double *h. "r")) == NULL) { fprintf(stderr. i++) v[i] = v[i+1] + h[i] * x.c: /* firfiltr. v. } h = (double *) calloc(max + 1. h. x). (max + 1) * sizeof(double)). v.2. 1. preliminary allocation Table P4. i. void main(int argc.. "%lf". i<M. x.

From the delay property of z-transforms. Y(z)= H(z)X(z) Problem 5. } } compute output sample Chapter 5 Problems Problem 5. We may work with the deﬁnition: ∞ 5 z−5 1 − z−1 X(z) = n=−∞ u(−n + 5)z−n = n=−∞ 1 · z−n = z−5 + z−4 + z−3 + z−2 + z−1 + 1 + z + z2 + z3 + · · · = z−5 1 + z + z2 + z3 + · · · = z−5 1−z = z−5 U(z−1 ) 58 59 .2 a. v. d. such as in the implementation of FIR decimators and interpolators in multirate applications. printf("%lf\n". Thus.0). but now the ROC must only exclude the point at inﬁnity z = ∞. Thus. Similarly. c. so that n = k + D. we get: ∞ ∞ Y(z)= m=−∞ h(m)Xm (z)= m=−∞ h(m)z−m X(z)= ∞ m=−∞ h(m)z−m X(z) or. 0. b. X(z)= z−5 . X(z)= z−5 Δ(z). The convolution property follows from the linearity and delay properties. Writing y(n) in terms of the delayed replicas of x(n). X(z)= z5 Δ(z)= z5 .y = firtr(M. MATLAB uses this form to implement its built-in ﬁltering routines. [a1 x1 (n)+a2 x2 (n)]z−n = a1 x1 (n)z−n + a2 x2 (n)z−n The delay property follows from: ∞ XD (z) = n=−∞ ∞ xD (n)z−n = ∞ n=−∞ x(n − D)z−n = ∞ k=−∞ = k=−∞ x(k)z−(k+D) = z−D x(k)z−k = z−D X(z) where we changed summation index from n to k = n − D. h. where Δ(z)= 1 is the ztransform of δ(n). we have: ∞ ∞ y(n)= m=−∞ h(m)x(n − m)= m=−∞ h(m)xm (n) Taking z-transforms of both sides and using the linearity and delay properties. The unit-step has z-transform: U(z)= 1/(1 − z−1 ). y). X(z)= z−5 U(z)= with ROC |z| > 1. The ROC is the entire z-plane with the exception of the point z = 0.1 The linearity property follows from: ∞ n=−∞ ∞ n=−∞ ∞ n=−∞ Transposed forms are convenient in some applications.

−a10 .5.5z−1 (1 − 0. −1. 0. ] X(z) = 1 − z−2 + z−4 − z−6 + z−8 − · · · = 1 + x + x2 + x3 + x4 + · · · = 1 1 + z−2 x=−z−2 = 1 1−x x=−z−2 = (0. an w(n)− W(z/a)= → 1 − (z/a)−10 1 − a10 z−10 = −1 1 − (z/a) 1 − az−1 Problem 5. Their z-transform is where convergence of the geometric series requires: 60 61 . that is.6 Method 1: List the values of x(n) and sum the geometric series: Problem 5.5. Using the linearity and delay properties. the signals in questions (a) and (b) are the same. both terms are causal. we rewrite 2(0.b. a. the ﬁrst term requires |z| > 0. ROC |z| > 1 − 0. 0. Using the general property that X(z)= 1 1 2 2 = + = 1 − 0. a . we have X(z)= (1 − (−0.25z−1 + = 1 − 0. 1.8. b. a . . 0. we have with x = −a2 z−2 . 2 cos θ = ejθ + e−jθ . 0.5z−1 ).The convergence of the series requires the ROC |z| < 1. c.5z−1 ). −a6 .5. In case (b).5)10 z−10 )/(1 + 0. ROC is |z| < 0. both terms are anticausal. The ﬁrst term in the z-transform expansion −1 X(z)= 1 + az−1 + a2 z−2 + · · · + a9 z−9 = where in the last step we used the ﬁnite geometric series: 1 + x + x + ··· + x 2 1 − a10 z−10 1 − az−1 X(z)= − n=−∞ (0. 0. .8jz−1 (1 − 0. we have X(z)= 2[1 − a2 z−2 + a4 z−4 − a6 z−6 + a8 z−8 − a10 z−10 + · · · ]= where we applied the inﬁnite geometric series 1 + x + x2 + x3 + · · · = 1 1−x 2 1 + a2 z−2 W(z)= U(z)−z −10 U(z)= (1 − z −10 1 − z−10 )U(z)= 1 − z−1 Using the modulation property of z-transforms.5z−1 1 + 0. 0. 0. 0. 0. 0.8)n cos(πn/2) = (0.25)n z−n + ∞ n=0 4n z−n m 1 − xm+1 . Convergence of the geometric series requires that |x| < 1 or | − a2 z−2 | < 1 or |z| > |a| or in our case |z| > 0.3 a.5| = 0. In case (c). ROC |z| > |a|. −a2 . ROC is the whole z-plane minus the point z = 0. = 1−x with x = az −1 and m = 9 would require ROC |z| < 0. The signal in (d) is unstable from both sides of the time axis. 0.8jz−1 ) 1 + 0.25 and |z| < 4.8. 0. Z g(−n)− G(z−1 ) → Z ROC is |z| > |0. a4 . with ROC |z| > | − 0. we ﬁnd ROC 0. Alternatively. Method 1: Let w(n)= u(n)−u(n − 10) with z-transform W(z).64z−2 g(n)− G(z) ⇒ → we ﬁnd X(z)= z−5 U(z−1 ). An alternative method is to list a few of the signal values and then use the inﬁnite geometric series to sum them up.8j)n +(−0.25z−1 1 − 4z−1 1 − 4.5z−1 ) 1 − 0. there is no set of z’s for which the z-transform would converge. · · · ] we obtain n −1 Problem 5. 1 1 2 − 4.8jz−1 )(1 + 0.25. X(z)= 0.25 and the second |z| > 4. a .8: x(n)= 2[1. that is. Using the general result: a u(n)− 1/(1 − az ).4 Using Euler. with a = 0. with θ = πn/2 and also the fact that ejπ/2 = j and e−jπ/2 = −j.c) all have the same z-transform. 1 1 2 2 = + = . a . we obtain: X(z)= → 1/(1 − (−0.25z−2 Problem 5.8j)n Thus.8)n [ejπn/2 + e−jπn/2 ] x(n) = [1. that is. Thus. thus.25 and |z| > 4. a . 0. 0.5z−1 )(1 + 0. a8 . we recognize that x(n) is the delayed version of u(−n). −1.8j| = 0. a . Thus.5 The three signals in parts (a. Combining. ROC is |z| > 4. · · · ] 2 3 4 5 6 7 8 9 and use the deﬁnition of z-transforms: They differ only in their region of convergence: In case (a). −1. |z| < 0. The intersection of the two ROC sets is empty. a .25 while the second |z| < 4. a .25 < |z| < 4.8jz−1 1 + 0. Method 2: We recognize that x(n) is the ﬁnite sequence X(z)= x(n)= [1.25z−1 + z−2 With a = −0.5)z−1 )= 1/(1 + 0.8)n [jn + (−j)n ]= (0. 0. x(n)= u(−n + 5)= u(−(n − 5)). . therefore |z| > 0. 1. namely.

g. 3. . . the answer is stable because the ROC contains the unit circle.5z−1 ) =A+ B 1 − 0. −1.5. 0.9|.9 B= 3(1 + 0.5)n u(n) For the second ROC.9| = | − 0.9z−1 ) 1 − 0. Ordinary partial fraction expansion is not valid in this case because the degree of the numerator is the same as the degree of the denominator. the last two terms will be inverted causally: x(n)= 5δ(n)+3δ(n + 3)+2δ(n − 2) x(n)= Aδ(n)+B(0. x(n)= −A(0.5z−1 X(z)= G(z) 1 − z−4 = 1 − z−2 1 − z−2 1 = = 1 − z−4 (1 − z−2 )(1 + z−2 ) 1 + z−2 where B and C are determined in the usual manner and A is determined by evaluating X(z) at z = 0: Problem 5. the signal is non-zero only at n = −3. z=0. b. 0.3z−1 ) A B = = + −2 1 − 0. the best method to invert is to just pick out the coefﬁcients of the polynomial.8 |x| < 1 ⇒ | − z−2 | < 1 ⇒ |z| > 1 a. The second ROC is |z| < |0.5)n u(−n − 1)−C(−0. we get: X(z) = 6 − 3z−1 − 2z−2 6 − 3z−1 − 2z−2 = −2 1 − 0.5.9)n u(n) As expected.9|. z=0.9| = | − 0.9)n u(−n − 1) The answer is unstable. 2: For the ﬁrst ROC. .9)n u(−n − 1)−B(−0. 0].9z−1 = 2. thus both terms will be inverted anticausally: for a = j and a = −j.5)n u(n)+C(−0.25 X(z) = (1 − 4z−2 )(1 + 3z−1 )= 1 + 3z−1 − 4z−2 − 12z−3 ⇒ x(n) = [1.9z−1 1 + 0. However. ] or. Taking z-transforms. the two terms will be inverted anticausally: x(n)= Aδ(n)−B(0. we have: A= 6 − 3z−1 − 2z−2 1 − 0.5)n u(−n − 1) As expected. Deﬁning the length-4 sequence g = [1.9 The ﬁrst ROC is |z| > |0.3z−1 ) 3(1 + 0.9)n u(n)+B(−0.9z−1 =1 z=−0.5z−1 + C 1 + 0.25z−2 = z=0 6z2 − 3z − 2 z2 − 0. |z| < 0.3z−1 ) 1 − 0.5z−1 = − 4. Carry out a partial fraction expansion: Method 2: Use Euler’s formula to split x(n) as the sum of two terms of the form an u(n): X(z)= where x(n)= cos(πn/2)u(n)= 1 1 πjn/2 + e−πjn/2 u(n)= [jn + (−j)n ]u(n) e 2 2 3(1 + 0.5z−1 =2 z=−0.9z−1 )(1 + 0. g. Method 3: Recognize that x(n) is periodic with period 4. 62 63 . we ﬁnd: X(z)= 1/2 1 − jz−1 + 1/2 1 + jz−1 = 1 (1 − jz−1 )(1 + jz−1 ) = 1 1 + z−2 A= 3(1 + 0. thus both terms will be inverted causally: where we applied the result an u(n)− → Z 1 1 − az−1 x(n)= A(0. only the ﬁrst inverse is stable because its ROC contains the unit circle.3z−1 ) 1 + 0.25z (1 − 0.9z−1 where we used eπj/2 = j.81z (1 − 0. −12] B= 6 − 3z−1 − 2z−2 1 + 0.25 = z=0 −2 =8 −0. we see that x(n) will be the periodic replication of g(n): x = [g.7 Whenever X(z) is a polynomial. we may still have an expansion of the form: x(n)= g(n)+g(n − 4)+g(n − 8)+g(n − 12)+ · · · Taking z-transforms of both sides gives X(z)= G(z)+z−4 G(z)+z8 G(z)+ · · · = 1 + z−4 + z−8 + z−12 + · · · G(z) Summing up the series and using G(z)= 1 − z−2 . because the ROC does not contain the unit circle.5 C= 6 − 3z−1 − 2z−2 1 − 0.5 For (b). |z| > 0. −4.5z−1 )(1 + 0.Problem 5. For (a).

5)n u(n) The answer is marginally stable because the pole z = 1 is on the unit circle. x(n) has a slightly causal part extending to the right up to n = 4.8z−1 B(0.8)n u(−n − 1)−6B(−0. we have the anticausal/unstable answer: x(n)= 4δ(n)+6(0.8. the two terms are inverted causally: w(n)= A(0. When the poles are complex. Note also that the last two terms are now active for −n + 4 ≥ 0 or n ≤ 4.8.5j)n u(n)]= 6(0.c. and ﬁnally restore the effect of the numerator.5j)n u(n)+B∗ (−0. they come in conjugate pairs.64z−2 (1 − 0.5j)n u(n)= 2Re[B(0. do a partial fraction on the denominator. write Again.5z−1 x(n) = −6A(0. get its inverse ztransform. To show these steps. The PF expansion gives: X(z) = −4 + = −4 + 1 1 = −4 + 1 + 4z−2 (1 − 2jz−1 )(1 + 2jz−1 ) 1/2 1/ 2 + 1 − 2jz−1 1 + 2jz−1 X(z) = 10 + z−2 10 + z−2 = 1 + 0.5.5j We only needed to calculate B.5)n cos(πn/2)u(n) For the anticausal case. where A = B = 0.8)n u(n)+6B(−0. we obtain the anticausal version of the second term.5)n u(n)+(−0.8)n u(−n − 1) − A(0.64z−2 10 + z−2 10.25z−2 ) 1 − z−1 1 − 0.8)n−5 u(n − 5) Note that the last two terms are active only for n ≥ 5.5j)n u(n) Now.5j)n u(n)+B∗ (−0. we have then 10 + z−2 1 + 0. For the ROC |z| > 0.5)n cos(πn/2)u(−n − 1) e. we ﬁnd x(n)= Aδ(n)+B(0. Thus.5jz−1 |z| > 2 and |z| < 2 64 65 . For the causal case.8)n u(−n − 1) which gives for x(n): X(z)= 6 − 2z−1 − z−2 4 1 1 + + = 1 + 0.8z−1 )(1 + 0.5)n Re[jn ]u(n) But.5j)n u(n)= 6(0. The degree of the numerator is strictly greater than the degree of the denominator. Re[jn ]= Re[ejπn/2 ]= cos(πn/2) Thus.25 1 1 − 0. the A-term is needed because the degrees of numerator and denominator polynomials are equal.5jz−1 )(1 + 0.5j)n u(n)+B∗ (−0. f.8)n u(n) Inserting in x(n)= 6w(n)+w(n − 5). because the last two terms are complex conjugates of each other.8)n−5 u(n − 5) + B(−0.5jz−1 =3 z=0.8)n u(n)+B(−0.8)n−5 u(−n + 4) The u(−n + 4) was obtained as u(−(n − 5)−1).5z−1 (1 − z−1 )(1 − 0.8z−1 1 + 0.25 = z=0 1 =4 0. We ﬁnd A= B= X(z) = 6 + z−5 = (6 + z−5 )· 1 − 0. This happened because the strictly anticausal signal w(n) was delayed (shifted to the right) by 5 time units by the term w(n − 5). only half of the residues need be computed: Because ROC is |z| > 1 > 0.8)n u(n)+A(0.8z−1 ) 1 − 0. In this case.5jz−1 ) The two regions of convergence are: B∗ B + =A+ 1 − 0. the corresponding residues are complex conjugates. x(n)= 4δ(n)−6(0. we may use the general identity 2Re(z)= z + z∗ to write W(z)= A B 1 1 = = + 1 − 0.25z−2 = z=0 10z2 + 1 z2 + 0.64z−2 ≡ (6 + z−5 )W(z)= 6W(z)+z−5 W(z) In the time-domain. and use B∗ for the conjugate pole. we ﬁnd B(0. namely. that is. The minor new feature of this problem is that the poles are complex-valued. For the ROC |z| < 0. that is. ignore the numerator completely. too.5)n cos(πn/2)u(n) and the ﬁnal result is x(n) = 6A(0.5.8)n u(−n − 1)−B(−0. The simplest approach in such cases is to use the “remove/restore” method. Doing a partial fraction expansion on W(z).5jz−1 1 + 0. we have x(n)= 6w(n)+w(n − 5) Thus. d.25z−2 (1 − 0. The partial fraction expansion is: w(n)= −A(0. the problem is reduced to the problem of ﬁnding w(n). all terms are inverted causally to give: x(n)= 4u(n)+(0.8)n−5 u(−n + 4)−B(−0.

4)n u(n) x3 (n) = Aδ(n)−B(0.4 D(an ) = a ∂ (an )= anan−1 = nan ∂a D2 (an ) = D(D(an ))= D(nan )= nD(an )= n(nan )= n2 an D3 (an ) = D(D2 (an ))= D(n2 an )= n2 D(an )= n2 (nan )= n3 an ··· D (a ) = nk an k n =2 z=0.They correspond to the causal and anticausal inverses: Problem 5.5 =3 z=−0.5(−2j)n u(−n − 1) Using Euler’s formula.2z−2 1 + 0. Noting that = 2n cos(πn/2) Thus.6z−1 + 0.5(2j)n u(n)+0. because in the second term n is effectively negative and causes it to decay exponentially for large negative n.2z−2 1 − 0. we can rewrite: we get ∂ xa (n)= nan−1 u(n) ∂a x1 (n) = −4δ(n)+2 cos(πn/2)u(n) x2 (n) = −4δ(n)−2 cos(πn/2)u(−n − 1) Thus.5)n u(−n − 1)+C(−0. The B-term in x2 (n) and both the B and C terms of x3 (n) diverge exponentially for large negative n. we have: 2n cos(πn/2)u(−n − 1)= 2−|n| cos(πn/2)u(−n − 1)→ 0 g.6z−1 + 0.4)n u(n) x2 (n) = Aδ(n)−B(0.5z−1 = z=0 0. derive the z-transform of the sequence x(n)= nan u(n). that is.4z−1 Problem 5.6z−1 + 0.4 Thus.5 (2j)n +(−2j)n ] = 2n [jn + (−j)n ]= 2n [ejπn/2 + e−jπn/2 ] 2 2 xa (n)= an u(n) Xa (z)= 1 1 − az−1 Applying the derivative operator ∂/∂a to the pair.4. The PF expansion is in this case: as n n ∂ ∂ Xa (z)= ∂a ∂a 1 1 − az−1 = z−1 (1 − az−1 )2 nan−1 u(n)− → Multiplying by a.2z−2 (1 − 0. ∂ ∂a 1 1 − az−1 = az−1 (1 − az−1 )2 nan u(n)− → Z az−1 (1 − az−1 )2 66 67 .5z−1 )(1 + 0.5)n u(n)+C(−0.4z−1 4 − 0. for k = 1.4z−1 ) 1 − 0. Its ROC contains the unit circle. in the z-domain: |z| > 0.9 Consider the z-transform pair: x1 (n) = −4δ(n)+0.5(2j)n u(−n − 1)+0. or.5)n u(−n − 1)−C(−0.5.2z−2 =A+ + (1 − 0.4)n u(−n − 1) Only x1 (n) is stable. 2 = −1 − 0 . we get: Z z−1 (1 − az−1 )2 n → −∞ nan u(n)− → Z az−1 (1 − az−1 )2 X(z)= where B C 4 − 0.5z−1 1 + 0. a Therefore.4z−1 ) 4 − 0. Only x2 (n) is stable because its ROC contains the unit circle.10 We note that each application of D brings down a factor of n: A= B= C= The three ROC’s are: 4 − 0. we have: Z ∂ ∂a k 1 1 − az−1 x1 (n) = Aδ(n)+B(0.5(−2j)n u(n) x2 (n) = −4δ(n)−0. writing n = −|n|. 5 · 0 .6z−1 + 0.5z−1 )(1 + 0.5 > |z| > 0.4 > |z| → a nk an u(n)− In particular. 0. we may write: 1 1 0. The corresponding inverses are: 0.

n + L − 1)− min(0.n) 1 L max (L − 1. we obtain the range of the summation in m: n2 an u(n)− → Z az−1 (1 + az−1 ) (1 − az−1 )3 0≤m≤L−1 0≤m−n≤L−1 which combine into the single inequality: max (0. that is. we obtain the restrictions on the convolution summation indices: 0≤m≤L−1 = az−1 = Therefore. n + L − 1) The convolution sum becomes then: ⇒ n≤m≤n+L−1 Adding the results of the k = 1 and k = 2 cases. n)≤ m ≤ min(L − 1. we also get: n(n + 1)an u(n)− → Z 2az−1 (1 − az−1 )3 For the cases k = 3. m=max(0.n+L−1) az−1 (1 + 4az−1 + a2 z−2 ) → n a u(n) − (1 − az−1 )4 3 n Z L g1 (m)g2 (n − m). n + L − 1)− min(0. the right-hand-side of the desired z-transform is the product: an u(n)− → and apply it for a = Rejω0 and a∗ = Re−jω0 : 1 1 − az−1 → Rn ejω0 n u(n) − Rn e−jω0 n u(n) − → Z Z 1 1 − Rejω0 z−1 1 1 − Re−jω0 z−1 X(z)= 1 L 1−z 1 − z−1 −L 2 zL−1 = 1 L G1 (z)G2 (z) The cosine and sine signals are obtained from the above as the following linear combinations: Thus. in the time domain we have the convolution: Rn cos(ω0 n)u(n) = Rn g1 (m)g2 (n − m) m 1 ejω0 n u(n)+e−jω0 n u(n) 2 1 ejω0 n u(n)−e−jω0 n u(n) 2j x(n)= 1 L g1 (n)∗g2 (n)= 1 L Rn sin(ω0 n)u(n) = Rn 68 69 . L −(L − 1)≤ n ≤ L − 1 At all other n. it is easily veriﬁed that the above expression is equivalent to: g1 (n) = u(n)−u(n − L) g2 (n) = g1 (n + L − 1)= u(n + L − 1)−u(n − 1) and using the z-transform x(n)= 1 L max (L − 1. u(n)− U(z)= → we ﬁnd the z-transforms: Z 1 1 − z−1 Problem 5. −1 (1 − az)2 −1 + 2az−1 (1 − az−1 )3 −(L − 1) ≤ n − m ≤ 0 By adding them. n)+1 Problem 5. we obtain the overall range of the index n of x(n). 4. both g1 (n) and g2 (n) are unity.n+L−1) L 1·1= m=max(0.n) −(L − 1)≤ n ≤ L − 1 Because over this range.12 Start with the result Z 1 − z−L G1 (z) = U(z)−z−L U(z)= 1 − z−1 1 − z−L L−1 G2 (z) = U(z)zL−1 − z−1 U(z)= z 1 − z−1 Therefore. x(n) is zero.which agrees with the previous problem. including the end-points n = ±L. az (1 + az ) (1 − az−1 )3 −(L − 1)≤ n ≤ L − 1 For any n in this range. we ﬁnd after some tedious algebra: x(n)= 1 min(L−1. we apply D again to get: a ∂ ∂a 2 1 1 − az−1 = a ∂ ∂a az−1 (1 − az−1 )2 1 Because g1 (n) is non-zero only over 0 ≤ n ≤ L − 1 and g2 (n) over −(L − 1)≤ n ≤ 0. n)+1 = 1 − |n| .11 Deﬁning the square pulses By checking separately the ranges −(L − 1)≤ n ≤ 0 and 0 ≤ n ≤ L − 1. For k = 2. we obtain: az−1 (1 + 11az−1 + 11a2 z−2 + a3 z−3 ) n a u(n) − → (1 − az−1 )5 4 n Z x(n)= 1 min(L−1.

14 Factoring the denominator 1 − z−4 . 3. 1.15 Summing the geometric series. we have: +z −8 A(z) + · · · )A(z)= 1 − z−4 X(z)= 1 − z−2 + z−4 − z−6 + z−8 − · · · = Alternatively. we can verify the ﬁrst four values {a0 .Therefore. we have: 1 1 + z−2 a0 + a1 z−1 + a2 z−2 + a3 z−3 1 − z−4 X(z)= 1 − z−2 + z−4 − z−6 + z−8 − · · · = 1 − z−2 (1 − z−2 + z−4 − z−6 + z−8 − · · · )= 1 − z−2 X(z) which gives where the convergence of the geometric series requires the ROC |z| > 1. 2. a3 }.13 Deﬁne the z-transform of one period: A(z)= a0 + a1 z−1 + a2 z−2 + a3 z−3 Then. a1 . we obtain for n ≥ 0: x(n) = A + B(−1)n +Cjn + C∗ (−j)n = A + B(−1)n +Cejπn/2 + C∗ e−jπn/2 = A + B(−1)n +2Re Cejπn/2 = A + B(−1)n +2Re (CR − jCI )ejπn/2 = A + B(−1)n +2CR cos(πn/2)+2CI sin(πn/2) So that ﬁnally: Problem 5. the corresponding linear combinations of z-transforms will be: → Rn cos(ω0 n)u(n) − n Z Z 1 2 1 1 + 1 − Rejω0 z−1 1 − Re−jω0 z−1 1 1 − Rejω0 z−1 A= B= C= a0 + a1 z−1 + a2 z−2 + a3 z−3 (1 + z)(1 − jz−1 )(1 + jz−1 ) −1 −2 −3 = z=1 a0 + a1 + a2 + a3 4 1 R sin(ω0 n)u(n) − → 2j which simplify into: − 1 1 − Re−jω0 z−1 a0 + a1 z + a2 z + a3 z (1 − z−1 )(1 − jz−1 )(1 + jz−1 ) a0 + a1 z + a2 z + a3 z (1 − z−1 )(1 + z)(1 + jz−1 ) −1 −2 −3 = z=−1 a0 − a1 + a2 − a3 4 1 − R cos ω0 z−1 R cos(ω0 n)u(n) − → 1 − 2R cos ω0 z−1 + R2 z−2 n Z = z=j (a0 − a2 )−j(a1 − a3 ) 4 ≡ CR − jCI Rn sin(ω0 n)u(n) − → Z R sin ω0 z−1 1 − 2R cos ω0 z−1 + R2 z−2 Taking (causal) inverse z-transforms of the PF expansion. Problem 5. Problem 5. we obtain the PF expansion: (1 + z−2 )X(z)= 1 ⇒ X(z)= 1 1 + z−2 The inverse z-transform is causal and can be obtained from the PFE: a0 + a1 z−1 + a2 z−2 + a3 z−3 a0 + a1 z−1 + a2 z−2 + a3 z−3 = X(z) = 1 − z−4 (1 − z−1 )(1 + z)(1 − jz−1 )(1 + jz−1 ) = A 1 − z−1 X(z)= which gives: 1 0. the z-transform of the periodic signal is recognized as the sum of the delayed replicas of A(z). x(n) = a0 + a1 + a2 + a3 4 + a0 − a1 + a2 − a3 4 (−1)n X(z) = a0 + a1 z−1 + a2 z−2 + a3 z−3 + a0 z−4 + a1 z−5 + a2 z−6 + a3 z−7 + a0 z−8 + a1 z−9 + a2 z−10 + a3 z−11 + · · · = (a0 + a1 z−1 + a2 z−2 + a3 z−3 )+z−4 (a0 + a1 z−1 + a2 z−2 + a3 z−3 ) + z−8 (a0 + a1 z−1 + a2 z−2 + a3 z−3 )+ · · · = A(z)+z−4 A(z)+z−8 A(z)+ · · · = (1 + z = −4 + a0 − a2 2 cos(πn/2)+ a1 − a3 2 sin(πn/2) Setting n = 0.5 = + 1 + z−2 1 − jz−1 1 + jz−1 + B 1 + z−1 + C 1 − jz−1 + C∗ 1 + jz−1 where the coefﬁcients C and C∗ are conjugates because they correspond to the conjugate poles ±j (this follows from the fact that the denominator has real coefﬁcients.5(−j)n u(n)= cos(πn/2)u(n) 70 71 .) The PFE coefﬁcients are determined as follows: x(n)= 0. that is. a2 .5 0.5jn + 0.

Problem 5. Thus. 1. . the roots of the denominator are the solutions of 1 + z−4 = 0 or. 1.19 for the denominator zeros. 0. z4 = −1. e 7jπ/4 1 − pi z−1 + 1 − p∗ z−1 i A∗ i which are the conjugate pairs: which can be assembled into the 2nd order section: z = e±jπ/4 . 0. R(z) degree M − 1. 0. Then. −1. 0.16 In all cases. e 3jπ/4 . 0. 0. 1. k = 0. 0. 1. 0. 0. 0. 1. . the four numbers ⇒ z = e(jπ+2jπk)/4 . 0. 0. 0. of the type: M z4 = −1 = ejπ = ejπ+2jπk that is. . 0. ] Problem 5. 0. Any truly complex poles will come in conjugate pairs. . The z-transform and its inverse are: A= B= 1 (1 − e−jπ/4 z−1 )(1 − e3jπ/4 z−1 )(1 − e−3jπ/4 z−1 ) 1 z=eπj/4 = = 1 4 1 4 (1 − ejπ/4 z−1 )(1 − e−jπ/4 z−1 )(1 − e−3jπ/4 z−1 ) z=e3πj/4 X(z) = 1 = 1 − z−4 + z−8 − z−12 + z−16 − · · · 1 + z−4 Thus. . 0. . X(z) = 1 = 1 − z−8 + z−16 − z−24 + · · · 1 + z−8 x(n) = [1. 0. the term R(z)/D(z) will admit a PF expansion of the form: R(z) Ai = D(z) i=1 1 − pi z−1 where pi are the M zeros of D(z) or the poles of H(z). 0. −1. 0. e±3jπ/4 A∗ (Ai + A∗ )−(Ai p∗ + A∗ pi )z−1 Ai i i i i + ∗ −1 = −1 1 − pi z 1 − pi z 1 − (pi + p∗ )z−1 + pi p∗ z−2 i i where the numerator and denominator coefﬁcients are all real. 0. 0. 1. . 0. 0. ] b. See the solution of Problem 5. . The z-transform and its inverse are: Cases (b. 0. 0. that is. −1. 0. . 1. Q(z) will have degree L − M. 0. 0. 0. 0. 0. 0. 0. we ﬁnd the causal inverse for n ≥ 0: x(n) = [1. 0. The z-transform and its inverse are: x(n) = = 1 jπn/4 1 1 1 e + e−jπn/4 + e3jπn/4 + e−jπn/4 4 4 4 4 1 1 cos(πn/4)+ cos(3πn/4) 2 2 X(z) = 1 = 1 + z−4 + z−8 + z−12 + z−16 + · · · 1 − z−4 x(n) = [1. 0. . 0. 0. 0. 0. 0. 2. 1. 0. 0. 0. 0. 0.18 Let Q(z) and R(z) be the quotient and remainder polynomials of the division of N(z) by D(z). 0. 0.c. 0. 0. 0. 0. 0. 1. 0. 0. the z-transform factors as follows and has the PF expansion: X(z) = = 1 1 + z−3 1 = (1 − ejπ/4 z−1 )(1 − e−jπ/4 z−1 )(1 − e3jπ/4 z−1 )(1 − e−3jπ/4 z−1 ) A 1− ejπ/4 z−1 + A∗ 1− e−jπ/4 z−1 + B 1− e3jπ/4 z−1 + B∗ 1− e−3jπ/4 z−1 where the coefﬁcients are: 72 73 . The z-transform and its inverse are: It follows that: N(z)= Q(z)D(z)+R(z) X(z) = 1 1 − z−8 =1+z −8 +z −16 +z −24 + ··· H(z)= Q(z)D(z)+R(z) R(z) N(z) = = Q(z)+ D(z) D(z) D(z) x(n) = [1. −1. 0. ] d. 0.d) are done in a similar fashion. 0. 0. Thus. 0. 1. ] c. e 5jπ/4 . 1. 0. .Problem 5. we expand in the appropriate geometric series and pick out the coefﬁcients of the expansion. 0. 3 Ai z=e jπ/4 . 0. 0. a.17 For case (a). They are obtained as follows: Because the degree of R(z) is strictly less than the degree of D(z). 0. 0. . 0.

Now. Its z-transform is: n X(ω) = n x(n)e−jωn x∗ (n)ejωn n Y(z)= n y(n)z−n = n an x(n)z−n = n x(n)(z/a)−n X∗ (ω) = 74 75 . To ﬁnd them. that is. m integers. where k is an integer. X(ω)ejωn dω = = 1 2π π −π m x(m)e−jωm ejωn dω 1 2π π −π x(m) m ejω(n−m) dω = m x(m)δ(n − m) Problem 5. . the scaled z will be They lie on the unit circle at the angles ωk = 2πk/D. P5.20 The roots of 1 − az−D are the solutions of the equation = x(n) k = 0 . replace 1 by e2πjk = 1.1 shows the two cases for D = 8. . the unit circle lies in the ROC or that the signal x(n) is strictly stable). D − 1 where we interchanged the series with the integral (this step is justiﬁed by assuming that the series is convergent.19 The roots of the polynomial 1 − z−D are the solutions of the equation zD = 1.1 Roots of 1 − z−8 and 1 + z−8 . k = 0 . . . Then. 1 . we have the solutions of 1 + z ejπ+j2πk with any integer k. D − 1 obtained by dividing the circle into D equal parts. . 1. D − 1 Y(z)= X(z/a) Since the spectrum X(ω) is obtained by replacing z = ejω . .Problem 5. k = 0. the roots of 1 + az−D . for n = m the left hand side is unity. . but they are shifted as a whole with respect to the standard D-th roots of unity by a rotation angle of π/D.23 We may assume in general that x(n) is complex-valued. . we replace −1 = e D πj = Y(ω)= n y(n)e−jωn = n ejω0 n x(n)e−jωn = n x(n)e−j(ω−ω0 )n = X(ω − ω0 ) zD = −1 = ejπ(2k+1) ⇒ zk = ejπ(2k+1)/D . D − 1 Problem 5. . 1. And. we get 1 2π π −π Fig. . Problem 5.22 We use the identity 1 2π π −π They also lie on the unit circle at D equal divisions. that is. 1. and take D-th roots of both sides: Comparing with X(z)= n x(n)z−n we see that zD = 1 = e2πjk ⇒ zk = ej2πk/D . Similarly. we have: Problem 5. but at the shifted D-th root of unity angles. ejω(n−m) dω = δ(n − m) for n. . Fig. P5. Indeed. we have: 1 2π π −π ejω(n−m) dω = cos π(n − m) − cos −π(n − m) 2πj(n − m) =0 z8 = 1 z 8 = -1 Inserting the deﬁnition of the DTFT into the inversion formula. . then they must be identically equal to each other. . for n = m. The product of the 1st order zero factors must make up the polynomial 1 − z−D : D−1 z/a = ejω /ejω0 = ej(ω−ω0 ) Thus. . lie on the same circle. we may work directly with the deﬁnition of the DTFT: = 0 or z = −1. zD = a = aej2πk ⇒ zk = a1/D ej2πk/D . and ﬁnd the roots −D Y(ω)= X(ω − ω0 ) Alternatively. k = 0. For the other case. They all lie on a circle of radius a1/D at the D-th root of unity angles. the relationship Y(ejω )= X(ej(ω−ω0 ) ) may be written as (1 − zk z−1 )= 1 − z−D k=0 This identity follows from a theorem of algebra that states that if two polynomials have the same set of roots and unity constant coefﬁcient. . the D-th roots of unity.21 Let y(n)= a x(n).

it follows that 1 2π π −π Chapter 6 Problems π −π ∗ X(ω)X∗ (ω) dω = = 1 2π X(ω) n π −π x∗ (n)ejωn jωn dω Problem 6..8 to 0.1 a. w1 = y |X(−ω)|e −j arg X(−ω) = |X(ω)|e j arg X(ω) b.g..8z−1 = −1. we have: The causal inverse z-transform of H(z) is h(n)= (−0.8 in the above problem. it will behave as a high pass ﬁlter: z-plane X(ω) = n x(n)e−jωn x(n)ejωn n = pole |H(ω)| 0. z=0 B = 1 + z−1 z=0. z = 0. where 1 + z−1 B =A+ 1 − 0.8z−1 ⇒ h(n)= Aδ(n)+B(0.8 is in the “low frequency” part of the unit circle and the ﬁlter is acting as a low pass ﬁlter.25 The ﬁlter enhances low frequencies for two reasons: ﬁrst.Using the inverse DTFT formula.55 0 5 X∗ (ω) = X∗ (−ω) = n -0.8)n u(n) A= 1 + z−1 1 − 0.8 1 x(n)e−jωn π ω where in the third equation. The I/O equation Y(z)= 0.8z−1 ⇒ H(ω)= 1 1 + 0. and it has a zero in the high frequency range. Its frequency response will be H(ω)= 1 + e−jω 1 − 0.e.8.25. arg X(−ω)= − arg X(ω) H(z)= that is. There is only one pole at z = −0.8e−jω 76 77 .8)n u(n).24 For a real-valued signal x(n). Thus. i.8 = 2. the ﬁlter will tend to enhance high frequencies.8z−1 Y(z)+X(z)+z−1 X(z) gives Equating magnitudes and phases. the magnitude spectrum is even in ω and the phase spectrum is odd. e. we replaced ω by −ω.8. c.8z−1 Y(z)+X(z) it follows: n 1 x (n) 2π X(ω)e dω H(z)= = n x∗ (n)x(n) 1 1 + 0.8 y for each input sample x do: y = − 0. Comparing the ﬁrst and third equations. we obtain: Block diagram realization and the sample-by-sample processing algorithm: X∗ (−ω)= X(ω) Writing X(ω) in its polar form. it has a pole in the low frequency range. 8 w 1 + x |X(−ω)|ej arg X(−ω) ∗ = |X(ω)|ej arg X(ω) or. that is. near the “high frequency” part of the unit circle. we get the conditions: |X(−ω)| = |X(ω)| . Now the pole at z = 0. From Y(z)= −0.8e−jω Problem 5. X(ω)= |X(ω)|ej arg X(ω) .8z−1 1 − 0. z = −1. Change −0. the hermitian property reads: x y z-1 w1 -0.

8z−1 Using the “remove/restore numerator” method of problem (2h).8 0 π w1 = w 0 The canonical form realization and its sample processing algorithm are: The direct form realization and its sample processing algorithm are: x z 0.833. The canonical form realization and its sample processing algorithm are: x w0 z-1 w1 z-1 w2 0.375 -0.5z−1 X(z) gives H(z)= where 1 − 0.8.5e±jπ/2 . the ﬁlter will tend to act as a lowpass ﬁlter.25w2 z-plane 0. Indeed.8)n−2 u(n − 2) The ﬁlter has two conjugate zeros at midrange. we ﬁnd H(z)= v1 = x w1 = y h(n)= (0.8)= 0.5.5 0. the ﬁlter will enhance low frequencies and suppress midrange frequencies: d. Thus. their effect will be to cancel each other.8)n u(n) z-plane 0.8 w 1 + x y = w0 − 0.625.25 y for each input sample x do: w 0 = 0 .8 = zeros = poles |H(ω)| 2.8 ⇒ -1 z -1 for each input sample x do: y = 0 .8 w 1 + x x y = w0 + w1 w1 = w0 y z v1 -0. 8 w 1 + x + v 1 1 + 0. Y(z)= 0.8z−1 = 0. 5 v 1 w1 w1 v1 = x w1 = y The direct form realization and its sample processing algorithm are: e.833 0.8z−1 Y(z)+X(z)+0. whereas its response at ω = π or z = −1 is (1 + 0. Here.5z−1 z=0. 1 − 0.5)/(1 − 0.8 w 1 + x y = w0 + 0. its response at ω = 0 or z = 1 is (1 − 0. z = ±0. Thus.8 0 π ω The ﬁlter has a zero at z = 0.5 0.z-plane = zeros = poles 10 |H(ω)| exact zero x ω 0.5j = zeros = poles |H(ω)| A= 1 − 0.8z−1 ⇒ h(n)= Aδ(n)+B(0.8 w0 -1 y for each input sample x do: w 0 = 0 .25(0.8 w2 = w 1 w1 = w 0 0 π ω The direct form realization and its sample processing algorithm are: The canonical form realization and its sample processing algorithm are: 78 79 .25z−2 .5z−1 B =A+ 1 − 0. Thus.8)= 2.8)n u(n)+0. and whichever is closest to the unit circle ultimately wins.8 w0 z-1 w1 -0. z=0 B = 1 − 0.5 0. The I/O equation Y(z)= 0.8 w 1 + x − 0 .8z−1 Y(z)+X(z)−0.8z−1 1 − 0. and a low frequency pole at z = 0.5j 0.5 y for each input sample x do: w 0 = 0 .5 and a pole at z = 0. the pole is nearer.5j = 0.5z−1 1 − 0.8 = 0.8 y z-1 w1 for each input sample x do: y = 0.25z−2 X(z) x z-1 v1 0.5w1 -1 0.5)/(1 + 0.8 — both in the low frequency range.

2 f.5 (1 + 3z−1 )(1 − 2z−1 ) 1 − 0.4. . Thus. The two poles at z = 0. we ﬁnd ) z=0. which implies The direct form realization and its sample processing algorithm are: H(z)= 1 + z−1 − 6z−2 1 − 0.2 0.4z−1 )(1 − 0.5 = zeros = poles 13. 2w 2 Factor numerator and denominator and expand in partial fractions: B (1 + 3z−1 )(1 − 2z−1 ) C =A+ H(z)= + (1 − 0. ] The ﬁrst 3 outputs are the initial transients.5z−1 −1 −1 = −30 z=0 Problem 6. 0.4| = 13. the output always settles to a constant value (for a stable ﬁlter). y(n)= [1. That constant value can be easily precalculated as H(1).9 w 1 − 0 .4 = 136 = −105 z=0.4| = 2. 6. H(1)= 1 + 6 + 11 + 6 = 24. Noting that the input z-transform is X(z)= 1/(1 − z−1 ).x z-1 v1 z-1 v2 0.4z−1 )(1 − 0.2z−2 Y(z)+X(z)+z−1 X(z)−6z−2 X(z).5z−1 ) (1 + 3z )(1 − 2z 1 − 0.9 y z-1 w1 z-1 w2 for each input sample x do: y = x + v 1 − 6v 2 + 0 . we have: z-plane 0.5 are both in the low frequency range. Thus. Setting x(n)= u(n) in the I/O difference equation. h(n)= Aδ(n)+B(0.86. evaluating at a few n’s we ﬁnd: Thus. 0.9 y for each input sample x do: w 0 = x + 0 . 18. In the present case. we get 80 81 . For the alternating step. 24. and the 2nd term only for n ≥ 2.25 0.5||1 − 0. 0.4) u(n)+C(0. 0. The two zeros at z = −3 and z = 2 are too far from the unit circle to have any signiﬁcant effect on the magnitude response. Y(z)= 0.2z−2 x z-1 v1 z-1 v2 -6 -0. .8 y z-1 w1 for each input sample x do: y = x + 0.8w1 x w0 z-1 w1 0.4 -3 0. the 3d term is active only n ≥ 2. Inverting. whereas its value at ω = π or z = −1 is |1 − 1 − 6|/|1 + 0. . 24.9z−1 Y(z)−0.2 w 2 y = w 0 + w 1 − 6w 2 v2 = v1 v1 = x w1 = y z-1 w2 -6 w2 = w 1 w1 = w 0 -0. 24.33.5||1 + 0.5z−1 where v2 = v1 v1 = x w2 = w1 w1 = y A= B= C= (1 + 3z−1 )(1 − 2z−1 ) (1 − 0. we ﬁnd The canonical form realization and its sample processing algorithm are: Y(z)= H(z)X(z)= 1 − z−4 = 1 + z−1 + z−2 + z−3 1 − z−1 where we used the ﬁnite geometric series. The value of the magnitude response at ω = 0 or z = 1 is |1 + 1 − 6|/|1 − 0.33 2 0 |H(ω)| 2. 7. · · · ] There is a pole zero cancellation: the ﬁlter has a zero at z = −1.4z−1 n n y(n)= u(n)+6u(n − 1)+11u(n − 2)+6u(n − 3) The 4th term is active only for n ≥ 3.2 a. the remaining constant values are the steady part.4z−1 1 − 0. the ﬁlter will be a low pass ﬁlter. b.5) u(n).5z−1 ) 1 − 0.25v2 + 0. Note that when you send in a unit step. 9w 1 − 0.86 Y(z) = 1 + 6z−1 + 11z−2 + 6z−3 = 1 + 5z−1 + 6z−2 1 + z−1 π ω y(n) = [1. 5. 24.9z−1 + 0. cutting off the highfrequency input.

where A = H(−1)= 4/5 and y(n)= [1.25z−2 ) (1 − z−1 )(1 − 0. · · · ] Y(z) = H(z)X(z)= 1 (1 + 0.5.8z−1 ) 1 − z−1 1 − 0.1. 0. 0. The B-term is the steady part.5jz−1 )(1 + 0.5jz−1 1 + 0. the ﬁlter has a high frequency zero at z = −1. 0. The pole of the input canceled the zero of the ﬁlter. For the alternating step.8)n u(n) with A = H(1)= 10.4)n u(n)+C(0.5z−1 ) (1 + z−1 )(1 − 0.8z−1 ) 1 − z−1 1 − 0.5jz−1 ) (1 − A z−1 )(1 + 1 + z−1 − 6z−2 − 0.25.5z−1 + y(n) = Au(n)+B(0. . we have: 1 1 Y(z) = H(z)X(z)= = (1 − z−1 )(1 − 0.5jz−1 Y(z) = 1 (1 + 0.4z−1 )(1 − 0.8)n u(n) with A = H(1)= 2. B = −1. 1. B = H(1)= 5. 1. B = 1/6.8.8z−1 )(1 + z−1 ) = A 1 + 0.5z−1 y(n) = Au(n)+B(0.25z−2 ) = 1 (1 + z−1 )(1 − 0. cutting off the high frequency input. For ﬁlter (c): + B 1 − 0.5jz−1 ) For the alternating step and ﬁlter (a) of Problem 6. C = −5.8)n u(n)+B(−1)n u(n) 82 83 . B = −9.1.5z−1 )(1 + 0.5) u(n) where A = H(−1)= 4/3. 2 j z=0.5.5jz−1 ) = 0 . 1.8z−1 y(n) = Au(n)+B(0. The B-term represents the steady part.8)n u(n) where A = Y(0)= 0.25z−2 B + =A+ (1 − z−1 )(1 − 0.3 For ﬁlter (a).8z−1 ) 1 − z−1 1 − 0. the ﬁlter cuts off the unit step from going through because the ﬁlter has a zero at z = 1. C = 1/6.8)n u(n)+Bu(n) where A = 1/2. For ﬁlter (b): Problem 6.4z−1 1 − z−1 + C 1 − 0. C = −0.5z−1 + n C 1 + 0. y(n) = A(−0.8)n u(n)+Bu(n) where A = −4. B = H(1)= 1/1.4 For a unit-step input and the ﬁlter (a) of Problem 6.5z−1 ) C 1 + 0.5jz 1 + 0.5)n u(n) where A = H(1)= 4/3. 0.5z−1 )(1 + 0.8z−1 + B 1 + z−1 y(n) = A(−1)n u(n)+B(0.5. For ﬁlter (f): Y(z) = 1 (1 − z−1 )(1 + 0. 0. 1. For (b).25. .8z−1 A B B∗ = + + −1 −1 1−z 1 − 0.5j)n u(n) y(n) = A(−0. The A-term is the steady part.5z−1 1 (1 − 0. The A-term is the steady part. we have: Y(z) = (1 − z−1 )(1 B A 1 + z−1 + = − 0. we have: Y(z)= 1−z = 1 − z−1 + z−2 − z−3 1 + z−1 −4 ⇒ y(n)= [1. For ﬁlter (d): Y(z) = = 1 1 = (1 + z−1 )(1 − 0.25z−2 ) A 1 − z−1 y(n) = A(0. −1.5jz−1 y(n) = Au(n)+B(0.25z−2 ) A 1 + z−1 n + B 1 − 0.5j)n u(n)+B∗ (−0.5)n u(n) 1 Y(z) = = (1 + z−1 )(1 + 0. we have: 1 1 = Y(z) = (1 − z−1 )(1 + 0.5j Problem 6. .5) u(n)+C(−0.8z−1 y(n) = Au(n)+B(0.5z−1 ) B= And.5j) u(n)+B (−0. we have: B B∗ A + + 1 + z−1 1 − 0.5jz−1 )(1 + 0. the remaining zeros are the steady state. 2 j z=0.8z−1 + B 1 − z−1 Again. −1. In the steady-state. For the alternating step: B= 1 (1 + z−1 )(1 + 0. 0.5j = B 1 − 0.8z−1 )(1 − z−1 ) = A 1 − 0.8z−1 )(1 − z−1 ) = A 1 + 0.5625. for the alternating step: = 0.5)n u(n)+C(−0.8z−1 + B 1 − z−1 Y(z) = = (1 − z−1 )(1 − 0. The B-term represents the steady part. 0. 1 − 0. For ﬁlter (e): y(n) = A(−1) u(n)+B(0.5z−1 n Y(z) = 1 − 0.5z−1 A B = + (1 − z−1 )(1 − 0.5jz−1 ) Y(z) = C 1 + 0. ] The ﬁrst four samples are the transients.5. B = H(1)= 6.1 + 0 . B = −0.3125.5j) u(n) where A = H(1)= 4/5 and n ∗ n y(n) = Aδ(n)+Bu(n)+C(0.

5z−1 ) 1 − 0.4z−1 1 − 0.8. The ﬁlter acts as a lowpass ﬁlter (it is actually an accumulator with delay).8z−1 Y(z)= H(z)X(z)= z−5 X(z) 1 − z−1 ⇒ (1 − z−1 )Y(z)= z−5 X(z) ⇒ Y(z)= z−1 Y(z)+z−5 X(z) ⇒ Its frequency response is y(n)= y(n − 1)+x(n − 5) y(n) = (0. The B-term represents the steady part. y(n) = (0.8)n u(n) For ﬁlter (e): B C 1 + 0. Thus. Block diagram realization and sample-by-sample processing algorithm: Y(z) = A 1 − 0. Therefore.4)n u(n)+C(0. For ﬁlter (b): Y(z) = 1 (1 − 0.5z−1 B = + (1 + z−1 )(1 − 0.4z−1 )(1 − 0.8)n u(n) The B-term is the steady part. The output is only transient — it decays to zero exponentially. For question (d). B = H(−1)= 5. the input has X(z)= 1/(1 − 2z−1 ).5z−1 ) A B 1 + 3z−1 = + (1 − 0. 84 85 . For question (e).8z−1 ) 1 − 0.5z−1 1 = Y(z) = (1 − 0.25z−2 )(1 − 0.8z−1 ) 1 + z−1 1 − 0.e.where A = −4.5z−1 y(n) = A(0. we have x(n)= (0.5z−1 y(n) = A(−1)n u(n)+B(0.5)n cos(πn/2)u(n)− X(z)= 1/(1 + 0.4)n u(n)+B(0.8z−1 y(n) = Aδ(n)+B(−1)n u(n)+C(0.5 Filter (a): H(z)= z−5 with I/O equation Y(z)= H(z)X(z)= z−5 X(z) and in the time domain y(n)= x(n − 5).8z−1 ) Z n H(ω)= e−5jω 1 − e−jω ⇒ |H(ω)| = 1 2| sin(ω/2)| The pole at z = 1 or ω = 0 dominates the frequency response.8z−1 x z-1 w1 z-1 z-1 w3 z-1 w4 z-1 w5 y Filter (b): H(z)= z−5 U(z)= z−5 /(1 − z−1 ) and the I/O equation gives for each input sample x do: y(n) = A(−1)n u(n)+B(0. ﬂat in ω.4z−1 )(1 − 0.8) u(n) The high frequency zero at z = −1 of the ﬁlter canceled the high frequency input signal.8)n u(n) Again.5z−1 ) −1 −2 y = w5 w5 = w4 w4 = w3 w3 = w2 w2 = w1 w1 = x A 1 + z−1 + B 1 − 0.8z−1 ) (1 + z 1 − 0..8z−1 ) 1 + z−1 1 − 0.8z−1 + B 1 + z−1 Y(z) = = (1 + 3z−1 )(1 − 2z−1 ) (1 − 2z−1 )(1 − 0. y(n) = (0. B = H(−1)= 1/1. For ﬁlter (f): w2 Y(z) = = 1 + z − 6z (1 + z−1 )(1 − 0.1(d) gives: 1 − 0.25. H(ω)= e−5jω and |H(ω)| = 1. Y(z) = 1 1 + 0. Thus.4z−1 + C 1 − 0. i. The B-term represents the steady part. the signal poles were canceled by the ﬁlter zeros.25z−2 = 1 − 0.4z−1 )(1 − 0.8z−1 )(1 + z−1 ) = A 1 − 0. For ﬁlter (c): 1 + z−1 1 = Y(z) = −1 )(1 − 0.8z−1 y(n) = A(0. the input z-transform is X(z)= 1/(1 − 0.8) u(n) → The ﬁlter zero canceled the signal pole.25z−2 =A+ Y(z) = + (1 + z−1 )(1 − 0. For ﬁlter (d): n Problem 6.8z−1 (1 + 0.25z−2 ). applied to Problem 6.5z−1 )(1 − 0.5z−1 ).5)n u(n) The unstable input was canceled by a ﬁlter zero to give a stable output.5)n u(n) For question (c).8)n u(n)+B(−1)n u(n) where A = 1/2.

z = ae2πjk/8 = −0. 0. Filter (e): With a = −0. Filter (d): H(z)= 1/(1 + 0.5 Y(z)= H(z)X(z)= X(z) 1 + 0. 7 z-plane = zeros y 1 The direct form realization and its sample processing algorithm are: z=a=-0. the impulse response is ﬁnite: h(n)= [1. 6. a2 . To ﬁnd them. 0.8y(n − 1)+x(n) The rest is as in problem (3d).8z−1 ) and the I/O equation becomes: z-plane = poles |H(ω)| 0.8y(n − 1)+x(n) 1 0 The canonical form realization and its sample processing algorithm are: π ω The rest is as in problem (3c).and in the time domain y(n)= 0. solve the equation z8 = a8 and exclude the solution z = a.8z−1 )Y(z)= X(z) ⇒ Y(z)= −0.8z−1 Y(z)+X(z) y = x + aw1 + a2 w2 + a3 w3 + a4 w4 + a5 w5 + a6 w6 + a7 w7 w7 = w6 w6 = w5 w5 = w4 w4 = w3 w3 = w2 w2 = w1 w1 = x 86 87 .8z−1 ⇒ (1 − 0. They are shown below k = 1 . a7 . a5 . a3 .8e2πjk/8 = 0. a6 .8. 2 . a4 . 5 . that is.8z−1 ⇒ (1 + 0.8z−1 ) and the I/O equation becomes: Y(z)= H(z)X(z)= X(z) 1 − 0.8z−1 )Y(z)= X(z) ⇒ Y(z)= 0.8z−1 Y(z)+X(z) ⇒ y(n)= −0.8ejπ e2πjk/8 . 3. a. 0. 4 .8 for each input sample x do: v2 -1 z v3 z-1 v4 z-1 v5 z w1 -1 y = w1 + v5 w1 = y v5 = v4 v4 = v 3 v3 = v 2 v2 = v 1 v1 = x The I/O equation in the time domain is y(n)= x(n)+ax(n − 1)+a2 x(n − 2)+ · · · + a7 x(n − 7) Sample-by-sample processing algorithm and block diagram realization: for each input sample x do: y Filter (c): H(z)= 1/(1 − 0. · · · ] Its z-transform is x z-1 w0 w1 z-1 z -1 H(z)= 1 + az−1 + a2 z−2 + a3 z−3 + a4 z−4 + a5 z−5 + a6 z−6 + a7 z−7 = 1 − a8 z−8 1 − az−1 for each input sample x do: w2 w3 z-1 w4 z-1 w5 x z-1 v1 z -1 w0 = x + w1 y = w5 w5 = w 4 w4 = w 3 w3 = w 2 w2 = w 1 w1 = w 0 The point z = a is not really a pole of H(z) because it is canceled by a numerator zero — H(z) has seven zeros.

64y(n − 2)+2x(n) There is a low frequency pole at z = 0.52 z−16 + 0.8jz−1 1 + 0. Thus.8e±π/2 . or.64z−2 Problem 6. the ﬁlter will emphasize both the low and high frequencies: y z-1 w1 z-1 w2 -0. we can deduce the transfer function from H(ω): H(z)= Y(z) = H(z)X(z)= 2X(z) 1 + 0.8j)n u(n) 1 1 2 + = H(z) = 1 − 0. |z| > (0.8z−1 1 + 0.64z−2 2X(z) 1 − 0.64 Filters (g.5z−8 x 2 y z -1 y for each input sample x do: y = 2x + 0.5.8 0.8j = 0. Thus.64z−2 0 π/2 π ω Y(z) = H(z)X(z)= ⇒ Y(z)= 0.64z−2 Y(z)+2X(z) −0.64z−2 ⇒ Y(z)= −0.52 z−16 + 0.8)n cos(πn/2)u(n)= (0. w8 ]. z = ±0. 5 w 8 delay(8. w1 .6 0 π/2 π ω Taking z-transforms.8z−1 1 − 0. w) w2 = w 1 w1 = y w2 where the call to delay updates the 9-dimensional state vector of the eightfold delay w = [w0 .8j Filter (f): H(z)= 1 1 2 + = 1 − 0.7 Because z = ejω .h): -1 w0 z -8 w8 0.5z−8 + 0.5)1/8 .8 and a high frequency pole at z = −0.8jz−1 1 + 0.5 + z−8 1 − 0.8)n 2Re[jn ]u(n) = (0.5 + 0.64w2 w2 = w1 w1 = y z-plane = poles |H(ω)| Problem 6. .53 z−24 + · · · = The direct form realization and its sample processing algorithm are: 1 1 − 0.64w2 where convergence requires |z|8 > 0.8j = poles |H(ω)| y -0.5 y for each input sample x do: y = w 0 = x + 0.64y(n − 2)+2x(n) H(z)= −0. h(n) = 2(0.x a0 w1 z -1 a1 z -1 w2 z -1 w3 z -1 a4 w4 z -1 w5 z -1 w6 z -1 w7 There is a conjugate pair of poles at midfrequency. .5z−8 88 89 . we ﬁnd: -0. .5 + 0. . the ﬁlter will emphasize mid frequencies: a2 a3 a5 a6 a7 z-plane 0.5z−8 + 0.75z−8 1 + 0.8j)n u(n)+(−0.5z−8 It can be written in a form that can be expanded in powers of z−8 : y(n) = −0. The block diagram and sample processing algorithm are: x w1 z 0.64z−2 Y(z)+2X(z) The direct form realization and its sample processing algorithm are: x 2 y(n) = 0.64 y for each input sample x do: y = 2x − 0.53 z−24 + · · · 1 − 0.8.75z−8 = −0.8 H(z)= 1 + 0.

0. Solving for H(z): H(z)= z−1 1 − z−1 − z−2 h(n) h(n + 1) h(n) = +1 · h(n − 1) h(n − 1) h(n) If we denote the ratio r(n)= h(n + 1)/h(n). 0. Thus.75(0. For large n.75/4 1 − φz−1 z=−φ−1 =− = −√ 1 5 . . The sequence y(n) satisﬁes the recursion y(n)= y(n − 1)+y(n − 2) for n ≥ 3. we have 1+ 5 .5). The poles of H(z) are the roots of 1 − z−1 − z−2 = 0 or r(n)r(n − 1)= r(n − 1)+1 1± 5 2 √ z2 − z − 1 = 0 ⇒ z= The limiting value r(n)→ r will satisfy the limiting equation: Denoting the ﬁrst one by φ. . the impulse response will be h = [−0.618). It is unstable because φ is greater than 1 (note. we obtain a closed-form solution for the nth Fibonacci number: 0 -0. using the property φ2 = φ + 1 and successively multiplying it by powers of φ. 2 √ − 1 √ φ which is the same as that satisﬁed by φ.75 0. Problem 6. 0. 0.. For n ≥ 1. r = φ because they are the positive solutions. 0. 0. we get: A z−1 B z−1 = = + H(z)= 1 − z−1 − z−2 (1 − φz−1 )(1 + φ−1 z−1 ) 1 − φz−1 1 + φ−1 z−1 90 91 .5)2 . 0. ] It is depicted below: where A= B= z−1 1 + φ−1 z−1 z −1 = z=φ φ−1 1 = √ 1 + φ−2 5 φ 1 + φ2 h(n) 0. 0. 0. 0. 0.75. we have: h(n + 1)= h(n)+h(n − 1) H(z)= z −1 H(z)+z −2 H(z)+z −1 h(n + 1) h(n) = +1 h(n − 1) h(n − 1) or.5. the other one will be: r2 = r + 1 = 1− 5 2 φ= Indeed. The sequence is properly initialized at n = 0. the exponentially increasing term φn dominates the expression. 0. 0. because the z-transform of δ(n − 1) is z−1 . Taking the causal inverse z-transform.1) to get H(z): Dividing by h(n − 1). 0. Indeed. 0. Therefore. 0. 0.1) h(n)= h(n − 1)+h(n − 2)+δ(n − 1) h(n + 1) Aφn+1 → =φ h(n) Aφn This can also be seen from the difference equation of h(n)..8 a. 0.Thus. for n ≥ 2 the δ(n − 1) term is absent and each h(n) is the sum of the previous two.5 n h(n)= Aφn + B(−φ)−n . we get − 1 φ =− 2 1+ √ 5 =− 2 ( 1 − 5) 2 ( 1 − 5) 1− 5 √ √ =− = 1−5 2 (1 + 5)(1 − 5) √ √ √ y(3) = φ2 = φ + 1 = y(2)+y(1) y(4) = φ3 = φ2 + φ = y(3)+y(2) y(5) = φ4 = φ3 + φ2 = y(4)+y(3) ··· Performing a partial fraction expansion on H(z).75/2 0. 1: h(0) = h(−1)+h(−2)+δ(−1)= 0 + 0 + 0 = 0 h(1) = h(0)+h(−1)+δ(0)= 0 + 0 + 1 = 1 Next. we take z-transforms of both sides of Eq. 0.75(0. (P6. The impulse response h(n) satisﬁes the difference equation: c. 0. 0. 0. φ n≥0 1. 0. . the ratio of two successive Fibonacci numbers will tend to: (P6. d. 0. we have Indeed. we may write this as: b.

the ratio of two successive numbers will converge to y2 (n)= 2bn u(n) 92 93 .5z−1 1 − 0. 5 Y2 (z) = H(z) 1 − 0. the transfer function is θ 1 A = −B = 2 = √ θ +1 2 2 Thus.5(0.10 The input and output z-transforms are: 1 . ] Problem 6.4z−1 (1 − 0.11 The input and output z-transforms are: 1 1 − az−1 1 1 2 − (a + b)z−1 ) 2(1 − cz−1 ) = + = 1 − az−1 1 − bz−1 (1 − az−1 )(1 − bz−1 ) (1 − az−1 )(1 − bz−1 ) 2(1 − cz−1 ) Y1 (z) = X1 (z) 1 − bz−1 z 2 = 2z + 1 The PF expansion is then ⇒ z=1± 2 = {θ.The z-transform of y(n) will be the once-delayed z-transform of the geometric series.5z−1 )(1 − 0. the two start-up values are: H(z)= Therefore. which may be solved for X(z): Y(z)= z−1 z−1 · (1 + θ−1 z−1 )= H(z)(1 + θ−1 z−1 ) = −1 −1 )(1 + θ−1 z−1 ) 1 − θz (1 − θz and therefore. That is. the second output. . it may be thought of as the output when the input is: z−1 Y(z) 1 − φz−1 = 1 + φ−1 z−1 X(z)= = z−1 H(z) (1 − φz−1 )(1 + φ−1 z−1 ) which gives the sequence: X(z)= 1 + θ−1 z−1 or. 0. Y(z)= z−1 1 − φz−1 h(n + 1) Aθn+1 =θ → h(n) Aθn The y(n) sequence has z-transform Thinking of Y(z) as the output of H(z) for a particular input X(z).4z−1 Problem 6. θ−1 . we ﬁnd H(z): Y2 (z)= 1 1 − 0. 0. the nth Pell number will be: H(z)= If the input x2 (n)= cn u(n) is applied it will have z-transform X2 (z)= 1/(1 − cz−1 ) and will cause the output: h(n)= Aθn + B(−θ)−n . . having z-transform h(0) = 2h(−1)+h(−2)+δ(−1)= 0 + 0 + 0 = 0 h(1) = 2h(0)+h(−1)+δ(0)= 0 + 0 + 1 = 1 will be produced by Taking z-transforms. . 0. that is.9 As in the previous problem. Therefore.4z−1 H(z)= 2z −1 H(z)+z −2 H(z)+z −1 ⇒ z−1 H(z)= 1 − 2z−1 − z−2 √ X2 (z)= 0. ] x(n)= δ(n)+φ−1 δ(n − 1) or x = [1. the impulse response satisﬁes the difference equation: X1 (z)= Y1 (z)= It follows that transfer function is: h(n)= 2h(n − 1)+h(n − 2)+δ(n − 1) with zero initial conditions.4z−1 ) 2(1 − 0. n≥0 Y2 (z)= H(z)X2 (z)= and in the time domain: 2(1 − cz−1 ) 1 2 · = 1 − bz−1 1 − cz−1 1 − bz−1 Because the exponentially diverging term θn dominates the sum.45z−1 ) Y1 (z) = X1 (z) 1 − 0. 0 .45)n u(n) The roots of the denominator polynomial are the solutions of Problem 6. 0.5z−1 1 1 2(1 − 0. .45z−1 ⇒ x2 (n)= 0. −θ−1 } X1 (z) = Y1 (z) = H(z)= where A z−1 B z−1 = = + 1 − 2z−1 − z−2 (1 − θz−1 )(1 + θ−1 z−1 ) 1 − θz−1 1 + θ−1 z−1 where c = (a + b)/2. we have Y(z)= H(z)X(z).45z−1 ) + = 1 − 0. 1 − 0. 0. 0. φ−1 . 0 . x(n)= δ(n)+θ−1 δ(n − 1) ⇒ x = [1.

001) 3 = = 1 .008π h(n)= 2.4 − 1 − 0.8781z−1 + 0.5z−1 Expanding in partial fractions.5z−1 (1 − 0. The approximate numerical value of neff = − 2 ln Δω =− 2 ln(0.7z−1 )(1 − 0. for the 60 versus 40 dB time constants.9874 2 2 Problem 6. we have: T=− ln τ = neff T = − which gives: 2 ln Δω T=− 2 ln 2πΔf T πΔf a1 = −(p + p∗ )= −2R cos ω0 = −2 · 0.008π We take the ﬁlter poles to be at locations: where T = 1/fs is the interval between samples.1 π ω0 = = 12.01) = 366.008π = 0.5 ln(0. In seconds.5z−1 1 − 0.2 Δf 94 95 .9874) Therefore the transfer function will be: 2(1 − 0.6z−1 ) Y(z) = H(z)= X(z) 1 − 0.01) 2 R=1− 1 1 Δω = 1 − 0. we have: The approximate expression is obtained by replacing R in terms of Δω: neff = ln ln = ln R ln(1 − Δω/2) ln −Δω/2 =− 2 ln Δω H(z)= which has the causal inverse: 2(1 − 0.5 Q= Δω 0.9750 τ=− ln πΔf − ln(0.12 The input and output z-transforms are: 1 1 − 0.13 and The denominator polynomial will be: 1 + a1 z−1 + a2 z−2 = (1 − pz−1 )(1 − p∗ z−1 )= 1 − (p + p∗ )z−1 + p∗ pz−2 which gives: = 0.4(0. the Q -factor of the ﬁlter will be: 0 .6z−1 ) 0.7z−1 1 − 0.4 = 2 .Problem 6.4δ(n)−0.1π [rads/sample] 5000 2π20 = 0.7z−1 1 1 2 ( 1 − 0.5)n u(n) which compares well with the exact value.14 The -level time constant of a ﬁlter is (in sampling instants): 2πf0 2π250 = 0. the designed ﬁlter will be: H(z)= 1 1 − 1.15 Using the approximate expression of Problem 6. p∗ = Re−jω0 The pole radius R may be determined from the approximate relationship τ1 = ln ln 1 2 τ2 Δω = 2(1 − R) which gives: In particular.18 ln R ln(0.001. It follows that the will be and 2 level time constants τ1 = And therefore. the scale factor is: ln ln 1 2 = ln(0.47 0.9874 · cos(0.01) = = 363.9750z−2 X(z) = Y(z) = The time constant of the resonator is given in terms of the maximum pole radius (there is only one radius here): neff = ln ln(0.001) πΔf = 2.008π [rads/sample] 5000 ln ln ρ ω0 = Δω = fs 2πΔf = neff = where ρ = max i |pi | is the maximum pole radius.8781 a2 = p∗ p = R2 = 0.13 The normalized peak and width frequencies are: Problem 6.1π)= −1. Problem 6. ln ρ τ2 = ln 2 T ln ρ p = Rejω0 . 6 z ) + = 1 − 0. the time constant is: fs = τ = neff T = ln T ln ρ 1 Therefore.5z−1 where we used the small-x approximation ln(1 − x) the time constant will be: −x. ln 1 T.5z−1 ) −1 Therefore.

2 Direct and canonical realizations of Problem 6. .2. 0] is the basic period of length 8. . Here.16. 0. 3]. w1 = w0 . The corresponding sample processing algorithm is: for each input x do: w0 = x + w 8 y = w 0 + 2w 1 + 3 w 2 + 4 w 3 delay(8.3. w) where the call to delay(8. In the z-domain. 4.1 Filter realizations of Problem 6. The cascade realization is obtained by factoring the numerator and denominator into (up to) 2nd order polynomials: Fig. 4 The sample processing algorithm for the canonical case is: for each input x do: w0 = x + w 4 y = w 1 + 2w 2 + 3w 3 delay(4. that is. . 1. 2. we may write: h(n)= g(n)+g(n − 4)+g(n − 8)+g(n − 12)+ · · · 96 97 . that is. .16. . w) implements the updating of the delay line.1. 0. P6. H(z)= z−1 + 2z−2 + 3z−3 = 1 − z−4 z−1 1 − z−2 1 + 2z−1 + 3z−2 1 + z−2 ≡ H0 (z)H1 (z) for each input x do: The block diagram is shown in Fig. w) where the call to delay(4. w7 = w6 .17 The solution is similar to that of Problem 6. 0.16 The periodic impulse response may be thought of as the sum of the delayed replicas of one period. where g(n)= [0. . 3. Problem 6. that is. x z -1 y z 2 3 -1 x w0 z w1 -1 y z-1 z-1 z-1 w2 z-1 z-1 w3 w4 z-1 z-1 z-1 2 3 x z-1 z-1 z-1 2 3 4 y z-1 x w0 z-1 w1 z-1 w2 w3 w4 w5 w6 z-1 z-1 z-1 z-1 w7 w8 z-1 z-1 2 3 y z-1 z-1 z-1 z-1 z-1 z-1 z-1 Fig. . w3 = w2 . 2. The sample processing algorithm for the canonical case is: The direct and canonical realizations are shown in Fig. but the last 5 are lumped together into a ﬁvefold delay z−5 . P6. Note that in the canonical realization the total number of delays is 8. Thus. Using the geometric series on the ﬁrst factor we obtain: 1 + 2z−1 + 3z−2 + 4z−3 G(z) H(z)= = 1 − z−8 1 − z−8 The direct and canonical realizations are shown in Fig. G(z) 1 − z−4 h(n)= g(n)+g(n − 8)+g(n − 16)+ · · · where g(n)= [1. P6. w8 = w7 . the repetition period is 4 and we have: w0 = x + w 2 x1 = w 1 w2 = w1 w1 = w0 v 0 = x1 − v 2 y = v 0 + 2v1 + 3v 3 v2 = v1 v1 = v0 Using partial fractions. P6. Taking z-transforms we obtain: H(z)= z−1 + 2z−2 + 3z−3 1 − z−4 H(z)= G(z)+z−8 G(z)+z−16 G(z)+ · · · = (1 + z−8 + z−16 + · · · )G(z) where G(z)= 1 + 2z−1 + 3z−2 + 4z−3 .17. w1 = w 0 . . w) implements the updating of the delay line. w4 = w3 . P6. we have: H(z)= G(z)+z−4 G(z)+z−8 G(z)+ · · · = (1 + z−4 + z−8 + · · · )G(z)= where G(z)= z−1 + 2z−2 + 3z−3 .Problem 6.

3 . . 0. . The output due to the input x = [3. 2. 3. 0 . Because the numerator has length 4. The sample processing algorithm is: for each input x do: A= B= C − jD = z−1 + 2z−2 + 3z−3 (1 + z−1 )(1 − jz−1 )(1 + jz−1 ) z−1 + 2z−2 + 3z−3 (1 − z−1 )(1 − jz−1 )(1 + jz−1 ) z−1 + 2z−2 + 3z−3 (1 − z−1 )(1 + z−1 )(1 + jz−1 ) = 1. The same conclusion can be reached working with z-transforms. 2. 1. w1 = w0 . 0. 1. ] Thus. 0. 1. its period-2 replicas will overlap with each other and must be added together: h(n)= [1.5 z=1 = − 0. . 0. 3. 1. 1. 6. 3 . 5 z=j Taking (causal) inverse z-transforms. . We have: H(z)= 1 + z−1 + z−2 + z−3 = (1 + z−1 + z−2 + z−3 )(1 + z−7 + z−14 + · · · ) 1 − z−7 The expansion of the denominator in powers of z−7 will cause the period-7 replication of the numerator.5(−1)n − cos(πn/2)− sin(πn/2) Evaluating at the ﬁrst couple of periods. scaled by the input samples: = − 0 . 0 . . . 2. P6. . 0. 1. We have for the output z-transform: h(n)= [0. .4. ] Y(z)= H(z)X(z) = = (1 + z−1 + z−2 + z−3 )(3 + 2z−1 + z−2 ) 1 − z−7 3 + 5z−1 + 6z−2 + 6z−3 + 3z−4 + z−5 1 − z−7 Problem 6. The numerical values are: The canonical realization is shown in Fig. 2. 2. will cause the period-2 replication of the numerator. . 2. 1. 1.5 − 0. 5. . 0. A B C − jD C + jD = + + + 1 − z−1 1 + z−1 1 − jz−1 1 + jz−1 where the PFE coefﬁcients C ± jD are conjugates. 1. 1. 0 . 0. 1. ] y n = [ 3 . 1. 0. 3 . we ﬁnd: n n n x0 hn−1 = [0. 1. 0.5 + j 0 . . 2. 1] may be obtained by using the LTI form of convolution. 0. 3 . 0 . 0. 3 . 3. 0. H(z) = z−1 + 2z−2 + 3z−3 z−1 + 2z−2 + 3z−3 = 1 − z−4 (1 − z−1 )(1 + z−1 )(1 − jz−1 )(1 + jz−1 ) Fig. 0 . 2. . 2. 2. 3. 0. 0 .4 Canonical realizations of Problem 6. . 0. . 3 . 1. w) where the call to delay implements the delay-line updates w7 = w6 . 5 . 0 . P6. . 0. .x w0 z-1 w1 z-1 w2 x1 v0 z-1 v1 z-1 v2 -1 3 2 y x w0 z-1 w1 z-1 w2 w3 w4 w5 w6 z-1 w7 z-1 z-1 z-1 z-1 y H0(z) H1(z) Fig. 2. 0. 3 . summing up the delayed replicas of the impulse response. 0.19 The expansion of the denominator. 1. 1 . 0. the output also has period 7. 2. 1 . P6. 3. 1. 3 . 0. 1. 0. 2. .17. . 0. 6.3 Cascade realization of Problem 6. 0 . ] 98 99 . . 3. 1. 0. 6 .18 Expand the denominator in powers of z−7 and pick out the coefﬁcients of the powers of z−1 . 0. 1. 1. 0. 1. 6 . 3 . 3. 0. 2. 0. The powers of z−7 cause the period-7 replication of the basic period G(z)= 1 + z−1 + z−2 + z−3 : Problem 6. 6. 0. 1. .5 z=−1 w0 = x + w7 y = w0 + w1 + w2 + w3 delay(7. . 1. ] x0 hn−2 = [0. 1. . ] n jπn/2 h(n) = A + B(−1) +(C − jD)j + (C + jD)(−j) = A + B(−1) +2Re (C − jD)e = A + B(−1)n +2C cos(πn/2)+2D sin(πn/2) = 1. 6 . 5. 2. w6 = w5 . 1. 0. 0. 1. 3 . 0. we ﬁnd for n ≥ 0: x 0 h n = [ 3 . that is. 3.18.

. . . 0. 0. 2. 0. the magnitude response will vanish at the harmonics ωk = kω1 = 2πk/16. 1. . Problem 6. 1. . 1. otherwise W0 (z)= X(z)+z−1 W0 (z) ⇒ W0 (z)= Thus. 0. ] +[0. 1. 0. P6. 2. in the time domain: h =[1. 0. 3 The numerator polynomial 1 − z−4 will have ejωk as roots. 0. 1. . 2. Putting the poles just behind the zeros. . . 1. 0. P6. 2. if n = 0 ⎪ ⎪ ⎨ h(n)= Ban/16 . ] The canonical realization and sample processing algorithm are: H(z)= 1 + z−1 + z−2 + z−3 (1 + z−2 )(1 + z−1 ) = (1 − z−1 )(1 + z−1 ) 1 − z−2 which is the same as that of Problem 6. 1. 0. 2. 1. 0. . 0.5. 2. that is. 1. 0. W2 (z)= z−1 W1 (z)= z−2 W0 (z) X(z) 1 − z−1 H(z)= B 1 − z−16 =A+ = A + B(1 + az−16 + a2 z−32 + · · · ) 1 − az−16 1 − az−16 ⎧ ⎪A + B = 1. 0. Problem 6. .20 H(z)= Writing the sample processing algorithm in terms of the time index n. 2. the harmonics will lie at the fourth roots of unity around the unit circle: ωk = kω1 = 2πk . 0. 2. Fig. in the z-domain where 0 < a < 1 must be chosen to be very near 1. we get: +[0. W2 (z) in favor of Y(z) and X(z). we obtain: pk = a1/16 ejωk = a1/16 e2πjk/16 . if n is a non-zero multiple of 16 ⎪ ⎪ ⎪ ⎩0. The impulse response is obtained by expanding H(z) into powers of z−16 . 2. 15 The zeros and poles are shown in Fig. .6 shows a sketch of |H(ω)|. . 2. k = 0. 4 k = 0. . 1. . 0. 0. 0. zk = ejωk = e2πjk/16 . 0.19. the causal impulse response will be h(n): Y(z)= W0 (z)+z−2 W0 (z)= (1 + z−2 )W0 (z)= (1 + z−2 ) X(z) 1 − z−1 100 101 . .21 The number of harmonics ﬁtting within the Nyquist interval are: x w0 z-1 w1 -1 w2 z y for each input x do: w3 z -1 w0 = x + w 2 y = w0 + w 1 + w 2 + w 3 w3 = w2 w2 = w1 w1 = w0 fs 240 = =4 60 f1 Therefore. 0. we have 1 − z−4 1 − az−4 w0 (n) = x(n)+w1 (n) y(n) = w0 (n)+w2 (n) w2 (n + 1) = w1 (n) w1 (n + 1) = w0 (n) or. 0. . 0. 1. 1. 1. ]+ · · · =[1. 0.22 The zeros are at the 16th roots of unity. 2. and be essentially ﬂat between zeros. We have with A = 1/a and B = 1 − A = 1 − 1/a: W1 (z)= z−1 W0 (z). 1. . If a is very near 1. . k = 0.which gives: H(z)= 1 + z−1 + z−2 + z−3 = (1 + z−1 + z−2 + z−3 )(1 + z−2 + z−4 + · · · ) 1 − z−2 H(z)= 1 + z−2 Y(z) = X(z) 1 − z−1 or. 15 The poles are just behind the zeros at the same angles: W0 (z) = X(z)+W1 (z) Y(z) = W0 (z)+W2 (z) zW2 (z) = W1 (z) zW1 (z) = W0 (z) Eliminating W0 (z). 1. . . we get the desired multinotch ﬁlter: Problem 6. W1 (z). ] Multiplying numerator and denominator by 1 + z−1 .

P6. −0.24 The gain factor 1 − a normalizes the magnitude response to unity at DC.5z−1 ) x w0 w16 a z-16 -1 y H(z)= w0 = x + w16 y = w0 − aw16 delay(16.5.. are shown in Fig.5)n u(n) h(n)= Aδ(n)−B2n u(−n − 1)−C(−0. 102 103 . 15ω1 16ω1=2π Fig. . Thus.24. 6.5.5)n u(n) h(n)= Aδ(n)−B2n u(−n − 1)+C(−0.5z−1 − z−2 3 − 3z−1 − z−2 1 + 0. It follows that h(n)= −0.5z−1 3 − 3z−1 − z−2 1 − 2z−1 =1 z=0 =1 z=2 Problem 6. The direct form I/O difference equation is obtained from: =1 z=−0.5z−1 where the call to delay updates the 17-dimensional delay line. Problem 6.5 H(z)= or. w) Expanding in partial fractions.5.22.25 The canonical realization and sample processing algorithm are: The ﬁlter poles are at z = 2.5z−1 − z−2 (1 − 2z−1 )(1 + 0.6 . |H(ω)| ω1 = 2π/16 x 1−a w0 z-1 w1 y x a − + y z-1 w1 ω 0 ω1 2ω1 3ω1 4ω1 a Fig.6(0. as well as the canonical realization. for each input x do: 3 − 3z−1 − z−2 3 − 3z−1 − z−2 = 1 − 1.7 Realizations of Problem 6.6 Magnitude response of Problem 6.3 + 1 − 0. Problem 6.24.5)n u(−n − 1) Only the second one is stable.. P6. H(z)= −0. we have: H(z)= where B 3 − 3z−1 − z−2 C =A+ + (1 − 2z−1 )(1 + 0.5z−1 A= B= C= 3 − 3z−1 − z−2 1 − 1.3δ(n)+0. 2 > |z| > 0. The corresponding sample processing algorithm will be: for each input x do: 1 y = x + a(w1 − x) w1 = y Fig.23 0 .22. Its ROC contains the unit circle.5)n u(n).z-plane = zeros = zeros y(n)= x(n)+a(y(n − 1)−x(n)) A realization based on this expression. h(n)= Aδ(n)+B2n u(n)+C(−0. P6. |z| < 0. 1−a Y(z) = X(z) 1 − az−1 The three possible ROCs and corresponding inverses are: ⇒ (1 − az−1 )Y(z)= (1 − a)X(z) Y(z)= az−1 Y(z)+(1 − a)X(z)= X(z)+a(z−1 Y(z)−X(z)) and in the time domain: |z| > 2 .5z−1 ) 1 − 2z−1 1 + 0.5 Pole/zero pattern of Problem 6.

for 0 ≤ |ω| ≤ ωc H(ω)= ⎩ 0.5.5z−1 + z−2 3(1 + z−2 ) 1 − 0. |z| < 0.5z−1 3( 1 + z ) 1 − 2z−1 −2 −2 y(n)= =3 z=0 1 2π ωc −ωc Ge−jDω X(ω)ejωn dω = G 1 2π ωc −ωc X(ω)ejω(n−D) dω Comparing this with the expression of x(n).28 The PF expansion of H(z) is of the form: Thus. (6. the ROCs and corresponding inverses are: |z| > 2 .5z−1 (1 − 2z−1 )(1 − 0.5z−1 ) 1 + z−2 h(n)= i=1 Ai pn u(n) i Problem 6. we recognize that =5 z=2 y(n)= Gx(n − D) = −5 z=0.5z−1 + z−2 Using d(ω)= D. Thus.5n u(n) h(n)= Aδ(n)−B2n u(−n − 1)−C0.5.5z−1 + z−2 (1 − 2z−1 )(1 − 0.5z−1 A= B= C= 3( 1 + z ) 1 − 2. giving: H(z)= where B 3(1 + z−2 ) 3(1 + z−2 ) C =A+ = 1 − 2. The output z-transform will be Y(z)= H(z)X(z). for ωc < |ω| ≤ π where G is its passband gain.5z−1 Y(z)−z−2 Y(z)+3X(z)+3z−2 X(z) ⇒ H(z)= Y(z) 3(1 + z−2 ) = X(z) 1 − 2.5) u(n) n The z-transforms of the causal and anticausal sinusoidal inputs are the same up to a negative sign: Problem 6. ωc ].5). respectively.5n u(−n − 1) H(z)= N(z) M M = i=1 Ai 1 − pi z−1 (1 − pi z−1 ) i=1 The z-transform of the signal g(n) is: g(n)= cos(πn/2)u(n)− G(z)= → Therefore. we ﬁnd: 1 − 2z−1 3 3(1 + z−2 ) · = 1 − 0.3.26 The transfer function is obtained from the I/O difference equation by taking z-transforms of both sides and solving for the ratio Y(z)/X(z): x(n)= 1 2π ωc −ωc X(ω)ejωn dω Y(z)= 2. Thus. the deﬁnition of H(ω) over one Nyquist interval will be: Factoring the denominator into its poles and expanding in partial fractions. 2 > |z| > 0.5z−1 ) 1 − 2z−1 1 − 0. we have: π −π ejω0 n u(n) − → Z Z 1 1 − ejω0 z−1 1 1 − ejω0 z−1 y(n)= 1 2π H(ω)X(ω)ejωn dω ejω0 n u(−n − 1) − − → Similarly.Problem 6.5 Problem 6. ⎡ ⎢ ⎢ Ai = ⎢ ⎣ j=i ⎤ N(z) (1 − p j z −1 x(n)= g(n)−2g(n − 1)− X(z)= G(z)−2z−1 G(z)= (1 − 2z−1 )G(z)= → Thus. we get: ⎧ ⎨Ge−jDω . the output z-transform will be: Z 1 − 2z−1 1 + z−2 ⎥ ⎥ ⎥ )⎦ z=pi = j=i N(pi ) (1 − pj p−1 ) i Taking causal inverse z-transforms. the z-transform of the input x(n) will be: Z 1 1 + z−2 where the i-th coefﬁcient is obtained by deleting the factor (1 − pi z−1 ) from the left-hand side and evaluating the remainder at z = pi . that is. the integration range for y(n) also collapses to [−ωc .27 Using the inverse DTFT formula of Eq. assuming its spectrum is restricted to be only over the range [−ωc . in the two cases: 104 105 . we ﬁnd for h(n): M Y(z)= H(z)X(z)= Inverting causally. for the input signal. ωc ]: with ROCs |z| > 1 and |z| < 1. h(n)= Aδ(n)+B2n u(n)+C0.29 y(n)= 3(0.5n u(n) h(n)= Aδ(n)−B2n u(−n − 1)+C0.

n ≤ −D − 1 ∞ −1 n=−D (1 − ejω0 p−1 ) i j=i − (1 − pj pi 1 ) The corresponding z-transform is by deﬁnition: H(z)= n=0 [δ(n)+0. we have: Bi = Ai 1 − ejω0 p−1 i The last term can be summed by changing summation variables from n to m = −n: −1 n=−D D To get the inverse z-transform y(n). which is recognized as the standard steady-state sinusoidal response of the ﬁlter. These choices for the ROCs.5-pole term will be inverted causally and the 2-pole anticausally: h(n)= δ(n)+0. It follows from the linearity of the ﬁlter that the corresponding output will be the sum of the two outputs obtained above.5 < |z| < 2. so that all the PFE terms will be inverted causally. we used the property u(n)+u(−n − 1)= 1 for all n. the ROC will be the annular region between the maximum pole and the unit circle: max |pi | < |z| < 1 i 2n z−n = m=1 2−m zm = 2−1 z(1 − 2−D zD ) 1 − 2−D zD =− 1 − 2−1 z 1 − 2z−1 where we used the ﬁnite geometric series: D xm = x + x2 + · · · xD = x(1 + x + x2 + · · · xD−1 )= m=1 x(1 − xD ) 1−x Thus. and Bi are obtained by deleting the factor (1 −pi z−1 ) and evaluating the rest at z = pi : ⎡ ⎤ ⎥ ⎢ N(z) ⎥ ⎢ ⎥ Bi = ⎢ ⎣ (1 − ejω0 z−1 ) (1 − p z−1 ) ⎦ j j=i z=pi = N(pi ) M ⎧ ⎪δ(n)+0. the factor 2−D can be made as small as desired.5n ]z−n − 2n z−n Comparing with the result of the previous problem. we take the ﬁlter part to be causal and the input anticausal.5n .5z−1 )(1 − 2z−1 ) 1 − 0. that is. For the causal case.Problem 6. the error transfer function: y(n) = H(ω0 )ejω0 n u(−n − 1)− i=1 Bi pn u(n) i H(z)−H(z)= The given input has z-transform: Adding up the right-sided and left-sided sinusoidal inputs gives rise to the double-sided input: ejω0 n u(n)+ejω0 n u(−n − 1)= ejω0 n u(n)+u(−n − 1) = ejω0 n . 2−D zD · (1 − 2z−1 )= 2−D zD 1 − 2z−1 y(n) = H(ω0 )ejω0 n u(n)+ i=1 Bi pn u(n)+H(ω0 )ejω0 n u(−n − 1)− i i=1 Bi pn u(n) i and in the time domain: E(z)= = H(ω0 )ejω0 n u(n)+H(ω0 )ejω0 n u(−n − 1) = H(ω0 )e jω0 n e(n)= 2−D δ(n + D) By choosing D large enough. Therefore. This gives: M M E(z)= Y(z)−Y(z)= H(z)X(z)−H(z)X(z)= H(z)−H(z) X(z) or.5z−1 1 − 2z−1 Y(z)= ± Bi C ± 1 − ejω0 z−1 1 − pi z−1 i=1 M The stable ROC containing the unit circle will be 0. 106 107 . we must assume a particular ROC. 5 z 1 − 2z−1 2−D zD 1 − 2z−1 2−D zD 1 − 2z−1 Z y(n) = H(ω0 )ejω0 n u(n)+ i=1 Bi pn u(n) i M H(z)= H(z)− or. (6. give: M H(z)= 1 + Comparing with the exact H(z) we have: 1 1 − 2−D zD + −1 1 − 0.5n u(n)−2n u(−n − 1) The truncated impulse response agrees with h(n) for n ≥ −D and is zero otherwise. −D ≤ n ≤ −1 ⎪ ⎪ ⎪ ⎩0. as we saw in Eq.30 Y(z)= ± (1 − e The partial fraction expansion leads to N(z) M jω0 −1 The PF expansion of H(z) gives: −1 z ) i=1 (1 − p i z ) H(z)= 3 − 5z−1 + z−2 1 1 =1+ + (1 − 0. that is: where C = H(ω0 ). n ≥ 0 ⎪ ⎪ ⎨ h(n)= −2n . the 0. we take the ROC to be |z| > 1.3. In this case the C term will be inverted anticausally and the Bi terms causally.10). For the anticausal case. −∞ < n < ∞ The error output will be x(n)= δ(n)−2δ(n − 1)− X(z)= 1 − 2z−1 → where.

for each input x do: v0 = x + v 1 x1 = v 1 delay(1.. Therefore. w3 . 1.2 shows the cascade of these two ﬁlters. −5 x v0 z v1 -1 x1 w0 -1 w z 1 -1 w2 z -1 w z 3 -1 -1 y 2 3 4 -1 -1 z-1 w4 x v0 z v1 z-1 v2 v3 v4 z-1 z-1 3 4 2 -1 w0 z w1 z-1 w2 w3 w4 w5 z-1 z-1 z-1 -1 y x w0 z w1 z-1 w2 w3 w4 w5 z-1 z-1 z-1 3 4 2 -1 y Fig. for each input x do: Problem 7. v2 . we get: 1 + H2 (z)+H1 (z)H2 (z) Y(z)= H1 (z)H2 (z)X(z)+E(z) and solving for Y(z): where v = [v0 . Fig. P7.1 Expanding the denominator in powers of z will replicate the numerator periodically with period 5. P7. w1 . 2. its output will be H1 (z) Y(z) −X(z) . w1 = w0 . ] The direct and canonical realizations are shown in Fig. e. Factoring the denominator as 1 − z transfer functions: −5 = (1 − z −1 )(1 + z −1 +z −2 +z −3 +z −4 ).Chapter 7 Problems Problem 7.2 Cascade realization of Problem 7. w) for each input x do: w0 = x + w 5 y = w 1 + 2w 2 + 3 w 3 + 4 w 4 delay(5. we get the cascaded Y(z)= H1 (z)H2 (z) 1 + H2 (z)+H1 (z)H2 (z) X(z)+ 1 E(z) 1 + H2 (z)+H1 (z)H2 (z) H(z)= 1 + 2z−1 + 3z−2 + 4z−3 z−1 + 2z−2 + 3z−3 + 4z−4 z−1 = · 1 − z−5 1 − z−1 1 + z−1 + z−2 + z−3 + z−4 Thus. the replicas will not overlap. . w) H1 (z) Y(z)−X(z) − Y(z)− H2 (z) H1 (z) Y(z)−X(z) − Y(z) → Adding the noise component E(z) to the output of H2 (z) will generate Y(z). The input and output of H2 (z) will be then : v0 = x w0 = w5 + v1 + 2v2 + 3v3 + 4v4 y = w0 delay(4. 4. P7. w = [w0 . w1 . w2 . The calls to the delay routines update the delay line. But because the numerator itself has length 5. which updates the ﬁlter’s internal state vectors.1. w) is equivalent to the shifts: w5 = w4 . v) delay(5. w4 ] are the internal state vectors for the two ﬁlter sections. and we will get the repetition of the numerator coefﬁcients: h = [0. 1. the input to H1 (z) is X(z)−Y(z).2 In the z-domain. v) w0 = x1 − w1 − w2 − w3 − w4 y = w 0 + 2 w 1 + 3 w 2 + 4w 3 delay(4. w3 = w2 . resulting in: Y(z)= H2 (z) H1 (z) Y(z)−X(z) − Y(z) + E(z) Moving the Y-dependent terms to the left. w4 . v1 . w4 = w3 . w2 .1. w3 . . w) where v = [v0 . 2.and 6-dimensional state vectors needed for the numerator and denominator polynomials. The corresponding sample processing algorithm is as follows: 108 109 . 4. v4 ]. w = [w0 . the call delay(5.1 Direct and canonical realizations of Problem 7. the desired transfer functions are identiﬁed to be: Hx (z) = He (z) = H1 (z)H2 (z) 1 + H2 (z)+H1 (z)H2 (z) 1 1 + H2 (z)+H1 (z)H2 (z) Figure P7. with each ﬁlter realized in its canonical form.w5 ] are the 5. . The sample processing algorithms are expressed with the help of the routine delay. 0. 2. 3. 3. 4. 1. 0. w2 = w1 . v1 ]. 3.1.g.

v5 ]. But because the numerator itself has length 6. 1. 0. the call delay(6. w5 . 1. v4 . w1 . w2 = w1 . e. P7. w) where u = [u0 . u) v0 = x1 − v1 − v2 x 2 = v 0 + 2v 2 delay(2. w = [w0 . u2 ].4 The z-domain versions of the time domain difference equations are: w0 = x + w 6 y = w 1 + 5 w 3 + 6w 5 delay(6. v2 . See also Problems 12. Factoring the denominator as 1 − z−6 = (1 − z−2 )(1 + z−2 + z−4 )= (1 − z−2 )(1 + z−1 + z−2 )(1 − z−1 + z−2 ) we get the cascade transfer function: 1 = (1 − z−1 )2 1 + H2 (z)+H1 (z)H2 (z) which can be solved for H1 (z) and H2 (z) giving: H1 (z) = H2 (z) = 1 1− z−1 H(z)= z−1 1 − z−2 · 1 + 2z−2 1 + 3z−2 · 1 + z−1 + z−2 1 − z−1 + z−2 z−1 1 − z−1 Figure P7. 3. 1. w5 = w4 ..24 and 12.4 shows the cascade of these three ﬁlters. 0. The presence of z−1 in the numerator of H2 (z) is necessary to make the overall closed loop computable. w) for each input x do: Problem 7. They are both integrators. w1 . 0. 0. 0. The calls to the delay routines update the delay line. ] Fig.4 Cascade realization of Problem 7. v) delay(6. for each input x do: v0 = x w0 = v1 + 5v3 + 6v5 + w6 y = w0 delay(5. v2 ]. which updates the ﬁlter’s internal state vectors.3 Direct and canonical realizations of Problem 7. v1 .3 Multiplying the numerator factors. 5. 5.3. v) w0 = x2 + w1 − w2 y = w 0 + 3w 2 delay(2. w2 ]. x u0 z-1 u1 z-1 u2 x1 v0 -1 v1 z -1 -1 x2 w0 -1 w1 z y Problem 7. w4 = w3 . 0. with each ﬁlter realized in its canonical form. To determine the impulse response. 0. 5. we get the transfer function: z-1 v2 2 -1 z-1 w2 3 H(z)= z−1 (1 + 2z−2 )(1 + 3z−2 ) z−1 + 5z−3 + 6z−5 = 1 − z−6 1 − z−6 Fig.and 7-dimensional state vectors needed for the numerator and denominator polynomials.g. 0. v1 . . w3 = w2 . 3.3. 0. the replicas will not overlap. 5. w) v(n) = x(n)+v(n − 1) y(n) = v(n)+v(n − 2)+v(n − 4) ⇒ V(z) = X(z)+z−1 V(z) Y(z) = V(z)+z−2 V(z)+z−4 V(z) 110 111 . P7. w1 = w0 .3. The corresponding sample processing algorithm is as follows: The direct and canonical realizations are shown in Fig. 6]. and we will get the repetition of the numerator coefﬁcients: h = [0. v = [v0 . . w = [w0 . w3 . x v0 z-1 v1 z-1 v2 v3 v4 v5 z-1 z-1 z-1 6 5 w0 z-1 w1 z-1 w2 w3 w4 w5 w6 z-1 z-1 z-1 z-1 y x w0 z-1 w1 z-1 w2 w3 w4 w5 w6 z-1 z-1 z-1 z-1 6 5 y for each input x do: u0 = x + u 2 x1 = u1 delay(2.25. P7. are the internal state vectors for the three ﬁlter sections.The conditions that Hx (z) be a plain delay and He (z) a double differentiator. we note that the numerator corresponds to the length-6 signal b = [0. w6 ] are the 6. The sample processing algorithms are expressed with the help of the routine delay. 3.w4 . 0. u1 . Expanding the denominator in powers of z−6 will replicate the numerator periodically with period 6. w2 . 1. . gives the two equations: H1 (z)H2 (z) 1 + H2 (z)+H1 (z)H2 (z) = z−1 where v = [v0 . w) is equivalent to the shifts: w6 = w5 .

the transfer function is: H(z)= 1 + z−2 + z−4 1 + z−1 + z−2 = · (1 − z−1 + z−2 ) 1 − z−1 1 − z−1 where we factored the numerator as 1 + z−2 + z−4 = (1 + z−1 + z−2 )(1 − z−1 + z−2 ) The direct. w) y = w0 + w2 delay(2. P7. P7. w) Problem 7.5 w 2 w0 = x + w 1 y = w0 + w 2 + w 4 delay(4.25 0. we may write the transfer function as: 2 − 3z−1 1 + z−2 2 − 3z−1 + 2z−2 − 3z−3 = · −2 −2 1 − 0. w) 112 113 .6.6 Direct and canonical realizations of Problem 7. v0 = x + v 1 x1 = v0 + v1 + v2 delay(2. P7.7. w) for each input x do: w0 = x + 0.5 v 2 x1 = 2 v 0 − 3 v 1 delay(2. v) w 0 = x 1 − 0 . canonical. 5z 1 + 0.25w4 y = w0 delay(3. and cascade realizations of Problem 7. Y(z)= (1 + z−2 + z−4 )V(z)= 1 + z−2 + z−4 X(z) 1 − z−1 for each input x do: Therefore. X(z). P7. gives: V(z)= X(z) 1 − z−1 . canonical. Its sample processing algorithm is: for each input x do: v 0 = x + 0 . v) delay(1.25z−4 1 − 0 . w) And for the cascade realization: for each input x do: Fig.25w4 y = 2w 0 − 3w 1 + 2w 2 − 3w 3 delay(4. v) delay(4.5. w) x x1 v0 z-1 v1 v2 z-1 w1 w2 w0 z-1 z-1 -1 y x 2 v0 z v1 z-1 v2 v3 z-1 -1 w0 -3 2 -3 y x 2 w0 z -1 y z -1 w1 z-1 w2 z-1 z -1 -3 2 -3 w1 w2 w3 z-1 z-1 z -1 Fig. v) w0 = x1 y = w0 − w1 + w2 delay(2.5. 5z x v0 z-1 v1 z-1 v2 v3 v4 z-1 z-1 w0 z-1 w1 y x w0 z-1 w1 w2 w3 w4 z-1 z-1 z-1 y H(z)= The direct and canonical realizations are shown in Fig.5 Factoring the denominator. The direct and canonical sample processing algorithms are: for each input x do: w3 w4 0. and cascade realizations are shown in Fig. Their sample processing algorithms are: for each input x do: v0 = x w0 = 2v0 − 3v1 + 2v2 − 3v3 + 0.4.25 w4 v0 = x w0 = v0 + v2 + v4 + w1 y = w0 delay(4. P7.Eliminating V(z) in favor of Y(z). The cascade realization is shown in Fig.5 Direct.

0625w4 y = w0 delay(2.5jz−1 1 + 0.4096z−4 1 − 0.5)n u(n)+2(−0.5 2 2 + + + 1 − 0.5. the impulse response will be: h(n)= 2. in the causal case.6. It corresponds the factorization: H(z)= 2 .x 2 x1 w0 z-1 w1 -0. P7. namely. Their sample processing algorithms are: for each input x do: The four poles z = ±0.25 y z-1 v2 z-1 w2 z-1 v2 z-1 w2 Fig.25w2 delay(4. v) delay(4. w) h(n)= 5(0. deﬁne only two ROCs. v) y = w0 = x1 + 0. The cascade realization is shown in Fig.5 -3 y x x1 v0 z-1 v1 -0. Problem 7. we have: z-1 z-1 z-1 w4 -2 Fig.5)n u(n) Writing jn + (−j)n = ejπn/2 + e−jπn/2 = 2 cos(πn/2).6.11. w) for each input x do: w0 = x + 0.25v2 + 0.25v2 x1 = v0 − 2.0625 x v0 z v1 z-1 v2 v3 v4 z-1 z-1 0. P7.25 w0 z-1 w1 -2.5)n cos(2πn/2)+2(0. P7. P7. Its sample processing algorithm is: for each input x do: v0 = x − 0.64z−2 1 + 0. P7.5)n u(n) Problem 7.8. The cascade realization is shown in Fig.5z−1 1 + 0.5. w) x v0 z-1 v1 z-1 v2 -2.25v2 delay(2.64z−2 114 115 .4096w4 delay(4.9 Cascade realization of Problem 7. P7. w) Expanding H(z) in partial fractions.25 w0 z-1 w1 z-1 w2 z-1 z-1 0.5)n u(n)+2(−0.9. v) delay(4.5j)n u(n)+2(0.5j.5j)n u(n)+2.7 The direct and canonical realizations are shown in Fig.5 v0 z-1 v1 0. Fig. we have: v0 = x w0 = v0 − 2.5 2.4096w4 y = w 0 − 2w 2 + w 4 delay(4.7 Cascade realization of Problem 7.5 and the anticausal one |z| < 0.5z−1 H(z)= 1 − 2z−2 + z−4 1 − z−2 1 − z−2 = · 1 − 0.5(−0. P7.10 Direct and canonical realizations of Problem 7.6 The direct and canonical realizations are shown in Fig.25 z-1 w4 y v0 = x y = w0 = v0 − 2v2 + v4 + 0.10. the causal case |z| > 0.5jz−1 1 − 0. For example.0625 y x w0 z-1 w1 w2 w3 z-1 z-1 -2. Their sample processing algorithms are: for each input x do: for each input x do: w0 = x + 0.7.25 0. P7.5(0.4096 w1 w2 w3 Fig.5.0625w4 y = w0 − 2.4096 -2 -1 w0 z -1 y x w0 z -1 y w1 z-1 w2 z-1 z-1 w3 w4 0. ±0.8 Direct and canonical realizations of Problem 7. w) w3 w4 0.25w2 delay(2.

64z 1 − 0. v) w0 = x1 − 0. w[11]. w) w10 The C version of the algorithm is as follows: double reverb(x. i>=1.8z−2 1 − 0.64 w0 z-1 w1 -1 -0. Its sample processing algorithm is: for each input x do: v 0 = x + 0 . P7.Note that the numerator could also have been factored as: 1 − 2z−2 + z−4 = (1 − z−2 )2 = (1 − z−1 )2 (1 + z−1 )2 = (1 − 2z−1 + z−2 )(1 + 2z−1 + z−2 ) But the chosen one has the simplest coefﬁcients.7.0.12 Cascade realization of Problem 7.75w10 y = −0. y = . return y. i--) w[i] = w[i-1]. double y. w) x1 = v0 + v1 delay(2.75 + e−10jω e e = = −10jω −10jω 1 − 0. From the transfer function. v) w0 = x1 − 0. we obtain the frequency response: x1 = v0 − v 2 delay(2.11 Cascade realization of Problem 7.75 * w[10]. { int i.75e (1 − 0.8w2 y = w0 − w1 + w2 delay(2.75w0 + w10 delay(10. 8 z Problem 7.75 y for each input sample x do: w0 = x + 0. Its sample processing algorithm is: for each input x do: v0 = x + 0. H(z)= 1 + z−3 1 + z−1 1 − z−1 + z−2 · = −4 −2 1 + 0.64v2 } for (i=10. P7. P7.75z−10 Its block diagram realization and sample processing algorithm are given below: x w0 z 0.64z−4 z-1 v2 z-1 w2 -1 1 + z−4 = (1 + z−1 )(1 − z−1 + z−2 ) we obtain the cascade factors: Fig. it follows that H(ω) will have unit magnitude. 116 117 . w[0] = x + 0.12. Problem 7.9 x x1 v0 z-1 v1 0.64w2 y = w0 − w 2 delay(2. w) H(ω)= (1 − 0.64 y The given sample processing algorithm corresponds to the canonical realization of the ﬁlter: H(z)= Factoring the numerator in the form: 1 + z−3 1 − 0.8 w0 z-1 w1 -0.75e−10jω ) Noting that the ratio of two conjugate complex numbers has unit magnitude.75e−10jω )∗ −10jω 1 − 0.75 + z 1 − 0. x x1 v0 z-1 v1 0. 8v 2 H(z)= −0.75e10jω −10jω −0. w) double x.75e 1 − 0.75 -10 -0.8 The given difference equations describe the canonical realization form of the ﬁlter: −10 The cascade realization is shown in Fig.9.8 -1 y z-1 v2 z-1 w2 Fig.75 * w[0] + w[10].

j = zeros = poles j 0. 3 that is. Its sample processing algorithm is: for each input x do: v0 = x − 0. 1] -0.Problem 7. P7. The poles are at z = ±0.9)n u(n)] π -0.14 Pole/zero plot of Problem 7. Fig.6561w4 delay(4. k = 0. and the third ﬁlter has zeros at the fourth roots of unity.15 Direct and canonical realizations of Problem 7. P7.15.. and a pole at z = 0. 0 .6561 y z-1 π ω π ω π ω v2 v3 w3 w4 Fig. each being a triple zero. z = ±1. that is. P7.9 1 for each input x do: v0 = x y = w0 = v0 + v4 + 0. that is. 3 . ±j.12 The zeros are at the roots of 1 + 16z−4 = 0.e.13 together with the corresponding sketches of the magnitude responses |H(ω)| over the right half of the Nyquist interval 0 ≤ ω ≤ π. Their sample processing algorithms are: Problem 7.6561 y x w0 z-1 w1 w2 w3 z-1 z-1 0.11.11.9j.14 shows the pole/zero locations and the corresponding magnitude response.11 Fig. v) delay(4.9j Fig.81z−2 ) H(z)= (1 − √ √ The cascade realization is shown in Fig. the 4th roots of unity rotated by 45o .9j 0.81w2 √ y = w 0 + 2w 1 + w 2 delay(2.6561w4 y = w0 + w 4 delay(4. z4 = − 1 ⇒ z = ejπ(2k+1)/4 .9j |H(ω)| 0.9m.81v2 √ x1 = v0 − 2v1 + v2 delay(2.10. The pole/zero plots of the three ﬁlters are shown in Fig. 0 . P7. Multiplying the transfer function factors. where w(n)= (0. 1 .9j.13 Pole/zero patterns of Problem 7. v4 w4 Problem 7. 2. i.10 The ﬁrst ﬁlter is an FIR ﬁlter with transfer function and impulse response: = zeros = poles 0.16. 0 . w) for each input x do: w0 = x + 0. P7. The direct and canonical realizations are shown in Fig. 118 119 . that is. h(n)= w(n)−w(n − 4).9. the zeros will be at the roots of 1 + z−4 = 0. we obtain: 2z−1 + z−2 )(1 + 2z−1 + z−2 ) 1 + z−4 = 1 − 0. ω The ﬁrst ﬁlter has zeros at z = ±j. P7.9 The causal impulse response of the third ﬁlter is obtained by the remove restore method. 3 .6561z−4 (1 + 0. v) w0 = x1 + 0.9j -1 -0. P7. ±0. The second ﬁlter has poles at z = ±0.9 H(z)= (1 + z−2 )3 = 1 + 3z−2 + 3z−4 + z−6 ⇒ h = [ 1 .81z−2 )(1 − 0. w) x -j |H(ω)| |H(ω)| |H(ω)| -j v0 z-1 v1 z-1 z-1 z-1 w0 w1 w2 z-1 z-1 z-1 z-1 0. w) Therefore.

x x1 v0 z-1 v1 -0. P7.5 2z−1 + 0. z-1 = zeros = poles unit circle v3 w3 w4 |H(ω)| 1 v4 w4 Fig. giving |H(ω)| = |e−4jω | · ) (1 + ce (1 + ce−4jω ) −4jω ∗ =1·1=1 H(z)= c + z−4 1 + cz−4 =c+ (1 − c2 )z−4 = c + (1 − c2 ) z−4 − cz−8 + c2 z−12 − c3 z−16 + · · · 1 + cz−4 To get the cascade form. 3 Fig. v0 = x y = w0 = 0.0625 · · 1 + 0. P7.2 w0 z-1 w1 0.0625x + 0.25w2 √ y = w 0 + 2 2w 1 + 4w 2 delay(2. 2 .0625 v0 z-1 v1 z-1 v2 z-1 z-1 w0 w1 w2 z-1 z-1 z-1 z-1 -0.5 2w1 − 0.0625w4 delay(4. P7.0625z−4 1 − 0.16 Cascade realization of Problem 7. k = 0. 5 e jπ(2k+1)/4 . P7.81 .0625 y ⇒ z = 0. 1 .0625. we ﬁnd: √ 2az−1 + a2 z−2 )(1 + √ 2az−1 + a2 z−2 ) √ √ 1 1 1 + z−4 = (1 + 24 z−4 )= (1 − 2 2z−1 + 4z−2 )(1 + 2 2z−1 + 4z−2 ) 16 16 16 ⎧ ⎪c ⎪ ⎪ ⎪ ⎪ ⎨−(1 − c2 )c(n−4)/4 h(n)= ⎪(1 − c2 )c(n−4)/4 ⎪ ⎪ ⎪ ⎪ ⎩ 0 if n = 0 if n is an even multiple of 4 if n is an odd multiple of 4 otherwise 120 121 . 3 that is. Its sample processing algorithm is: for each input x do: √ v0 = 0.0625 + z−4 1 − 2 2z−1 + 4z−2 1 + 2 2z−1 + 4z−2 √ √ = 0. k = 0.12. we may factor the numerator and denominator using the identity: 1 + a4 z−4 = (1 − Thus the numerator becomes: Extracting the coefﬁcients of z−1 .0625w0 + w4 delay(4. w) z4 = −16 ⇒ z = 2ejπ(2k+1)/4 .0625w4 y = 0.17 Pole/zero plot of Problem 7. the transfer function is then: H(z)= 0.5 2v1 − 0. w) Fig. 2. w) Finally.25z−2 1 + 0. P7. The magnitude response is constant in ω.25v2 √ x 1 = v 0 − 2 2v 1 + 4 v 2 delay(2.81 2 y Noting that 1/16 = 0.25z−2 √ √ z-1 v2 z-1 w2 The direct and canonical realizations are shown in Fig. P7.11. Their sample processing algorithms are: for each input x do: for each input x do: w0 = x − 0. 1 .5 2z−1 + 0. the impulse response may be obtained by writing: H(ω)= c + e−4jω 1 + ce−4jω = e−4jω (1 + ce4jω ) (1 + ce−4jω )∗ = e−4jω 1 + ce−4jω (1 + ce−4jω ) The ratio of the two conjugate factors will have unity magnitude.18. the 4th roots of unity rotated by 45o and scaled in magnitude by a factor of 2. v) √ w0 = x1 − 0.19.0625 w0 z-1 w1 w2 w3 z-1 z-1 -0. v) delay(4. Similarly.0625v0 + v4 − 0. setting c = 1/16. Indeed.0625 y x 0. the poles are at: 1 z =− 16 4 x 0.18 Direct and canonical realizations of Problem 7.17 shows the pole/zero locations. π Fig.12. we have: ω The cascade realization is shown in Fig.

(i=0. Problem 7.313 0. &x) != EOF) { a.i<=M. i). } /* input data */ printf("\n\n"). sections K = ").dat.147 0. M. say. j<3. % .206 0 0. b. A. while(fscanf(fpx. } The program must be linked with the routines cas2can. b). The number of sections K and the corresponding rows of the matrices A and B are entered interactively. A[i]+j).122 -0. j++) scanf("%lf". b = (double *) calloc(M+1. i++) { 122 123 . B. input. The program stops ﬁltering as soon as the end-of-ﬁle of x. ycas = cas(K. b[i]).6f } "%lf". wdir = (double *) calloc(M+1.dat is encountered. the user input for the given transfer functions will be (starting with K = 4): 4 1 1 1 1 0. double *vdir. wcan. *wcan.117 0. and also conv required by cas2can and sos required by cas. ycan. ycas).5 2 -0. cas(). sizeof(double)). *wdir.h> void cas2can(). B[i]+j). vdir.190 0 0. i<K. i++) { A[i] = (double *) calloc(3.25 z-1 v2 -2 2 4 -0. dir. (double **) calloc(K. b = \n"). (double **) calloc(K. P7.294 0. sizeof(double)). sizeof(double)). b. printf("\n a. sizeof(double *)). a = (double *) calloc(M+1.103 These inputs may also be saved in a ﬁle. sizeof(double)). ydir.5 2 -0.234 0. j. cas.147 0.25 z-1 w2 22 4 Fig.103 -0. for(j=0. } for(i=0. **W. wdir. &K). double **A.19 Cascade realization of Problem 7. x).0625 x1 v0 -1 v1 z w0 -1 w1 z y printf("enter A[%d] = ".117 0.780 0. for(j=0. **B. A = B = W = for (double **) calloc(K. wcan = (double *) calloc(M+1.360 0. sizeof(double *)). W[i] = (double *) calloc(3.712 0. j<3.IIR filtering experiments */ #include <stdio. 0. scanf("%d".dat. M. x). a[i]. can. B[i] = (double *) calloc(3. a. ycan = can(M.6f\n". /* direct form coefficients */ for (i=0. *b. M.6f % . FILE *fpx. j++) scanf("%lf". M=2*K. } cas2can(K. i++) { printf("enter B[%d] = ".891 -0. printf("% . For example. x. i). sizeof(double *)).c . ydir = dir(M. *a.i++) printf("% . "r").dat". sizeof(double)). ycas. can(). i<K. sizeof(double)). and piped into the program by iirfilt < input. x).6lf % . cas2can(K. a). K. A.373 -1. i<K. fpx = fopen("x. void main() { int i. vdir = (double *) calloc(M+1. printf("no.13 The following program implements this computer experiment: /* iirfilt.6f % .h> #include <stdlib.12. double x.313 0. ycan.x 0. W. The ﬁrst 10 of the input and output samples are shown below: for(i=0. ydir. B.dat The input signal xn to be ﬁltered is assumed to be in the ﬁle x. double dir(). sizeof(double)).6lf\n". sizeof(double)).

112201 0. The outputs computed by dir. } if ((fpa = fopen(argv[1].524036 0.c of Problem 4.283588 0. *fpb. *b. M++) { if (M == max) { 124 125 .026788 0.112201 0.005637 0. dmax = MAX.079222 0.000000 1.20.163405 0. int L.163405 0.248430 0.dat >y.000000 −3.248430 0.000554 0.032979 0.000000 1.000000 0.dat\n").005637 0. plotted together with the input.c . exit(0). and cas are of course the same.164600 1.807624 1.196860 −0.465987 2.283588 0.003881 0. *w.IIR filtering in canonical form */ #include <stdlib.000000 0.dat <x.026788 0. "r")) == NULL) { fprintf(stderr. "Usage: canfilt a.000000 1. } a = (double *) calloc(max + 1.163405 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. P7.019407 0. Calling cas2can on the matrices A and B gives the direct form denominator and numerator coefﬁcients: a 1. The program reads and allocates the ﬁlter coefﬁcient arrays. can.000554 0.164600 1.14 An example of such program is given below.019407 0.248430 0.043772 1.000554 0.275606 0. The impulse response h(n).007142 hcan (n) 0. "Can’t open filter file: %s\n".011644 0.000000 1.120828 −0.807624 1. exit(0). P7.157457 Fig.275606 0.000000 1. void main(int argc.157457 ycas (n) 0.011644 0.807624 1. char **argv) { FILE *fpa. sizeof(double)).120828 −0. initial allocation size x(n) 1.043772 1.166000 4.10.275606 0. output initial allocation and increment H(ω) ω=0 = H(z) z=1 =1 This can be observed in the output which rises up to 1 before it dies out to zero.236148 0.x(n) 1. M.000000 1.283588 0. i.120828 −0.dat containing 1 followed by 49 zeros.000000 0.000000 1.h> #include <stdio.000000 b 0.000000 if (argc != 3) { fprintf(stderr.000000 0. input.000000 ydir (n) 0.157457 ycan (n) 0.000000 0.006191 0. output. Fig.236148 0.873631 −4.112201 0.000554 0.000000 0.h> #define MAX 64 double can(). double *a. y.000554 0.524036 0.026788 0.018165 0. It is patterned after firfilt. for (M=0.000000 1. "r")) == NULL) { fprintf(stderr. argv[2]).003881 0.005637 0. "Can’t open filter file: %s\n".000554 0.20 Input. K..006191 0.164600 1.000000 hdir (n) 0. int max = MAX. The last while loop performs the actual ﬁltering: /* canfilt.20 shows the full output.13.236148 0.043772 1.079222 0.006191 0. P7. } if ((fpb = fopen(argv[2]. and impulse response of Problem 7.000554 0. It is shown also in Fig.524036 0.592519 −0. x.dat b.007142 hcas (n) 0.000000 0.032979 0.079222 0.941724 0.032979 0. 0 ≤ n < 50 can be computed by running this program on a ﬁle x. argv[1]). exit(0)..000000 0.000000 1. Therefore.000554 0.000000 0. the steady-state DC response will be coefﬁcient ﬁles coeffs. state. The ﬁrst 10 impulse response samples computed by the three realizations are shown below: Problem 7.

(L + 1) * sizeof(double)). "Usage: casfilt A. j<3. x. (M + 1) * sizeof(double)). L++) { if (L == max) { max += dmax. a + M) == EOF) break.dat in a concatenated form. W[i] = (double *) calloc(3. (max + 1) * sizeof(double)). &x) != EOF) { y = cas(K. argv[2]). "%lf". "r")) == NULL) { fprintf(stderr. exit(0).IIR filtering in cascade form % % y = casﬁlt(B. for (M=0. w. printf("%lf\n". "%lf". sizeof(double)). A = (double **) calloc(K. w = (double *) calloc((K + 1). while(scanf("%lf". int M. a = (double *) realloc((char *) a. B[i] + j). B[i] = (double *) calloc(3. double *a. i++) { A[i] = (double *) calloc(3. The last while loop performs the actual ﬁltering: /* casfilt. L. int max = MAX. a = (double *) realloc((char *) a. } else K = M / 3. A. j<3. b = (double *) realloc((char *) b.dat\n"). sizeof(double)). (max + 1) * sizeof(double)). y. To facilitate the initial allocation of A. b = (double *) realloc((char *) b. sizeof(double *)). a temporary array a is used to read the rows of A. "Can’t open filter file: %s\n". if (M%3 != 0) { fprintf(stderr. void main(int argc.h> #define MAX 64 double cas(). B = (double **) calloc(K. where N is the input length: % casfilt. for (L=0. and then it reshapes it into the K×3 matrix A. % if (argc != 3) { fprintf(stderr. exit(0). while(scanf("%lf".. i<K.m is given below. m. } if (fscanf(fpa. argv[1]). The program reads and allocates the ﬁlter coefﬁcient matrices A and B. K. sizeof(double)). } } process input samples Problem 7. sizeof(double)). i<K. A. b + L) == EOF) break.dat <x. } if (fscanf(fpb. (max + 1) * sizeof(double)). for (i=0. "all rows of A must be 3-dimensional").. printf("%lf\n". y). } a = (double *) calloc(max + 1. } for(i=0. B. i++) for(j=0. y). exit(0). } M--. exit(0). char **argv) { FILE *fpa. for(i=0. "%lf". } if ((fpb = fopen(argv[2]. } 126 127 .dat >y. x). b = (double *) calloc(max + 1.dat B. i<K.15 An example of such program is given below. M++) { if (M == max) { max += dmax. **W.m . j. W = (double **) calloc(K. (M + 1) * sizeof(double)). i++) for(j=0. initial allocation size coefﬁcient ﬁles temporary coefﬁcient array allocation and increment The MATLAB version casfilt. x). sizeof(double *)). j++) A[i][j] = a[3*i + j]. x).m N times.c . a + M) == EOF) break. } if (fscanf(fpa. sizeof(double *)).IIR filtering in cascade form */ #include <stdlib. &x) != EOF) { y = can(M. "Can’t open filter file: %s\n". sizeof(double)). double **A. It calls cas. sizeof(double)). a. "r")) == NULL) { fprintf(stderr. i. a = (double *) realloc((char *) a. j++) fscanf(fpb. dmax = MAX. W.max += dmax. } L--. } } process input samples if ((fpa = fopen(argv[1]. } a = (double *) realloc((char *) a. b. "%lf". **B. *fpb.h> #include <stdio. K = (L <= M) ? M : L.

0). A. scanf("%d". &N).70849 0. u = (double *) calloc(9. double double double Problem 7.50 0.dat".98z−8 Expanding in powers of z−8 and extracting coefﬁcients. w1. *v. 8. "w").94z−8 1 − 0.h> #include <math. P7. x1 = u[0] + u[8]. void main() { int n. noise-free.dat". u[0] = G2 * x .5 0. The ﬁrst ﬁlter has a short time constant. section 1 */ /* filter 2.0625z−8 1 + z−8 1 − 0. fprintf(fps. delay(8.4 remain the same.21 shows the desired. W. W] = cas(K. *fpy1. The second ﬁlter has a longer time constant.8lf\n". y2 = v[0] .3). v[0] = x1 + 0.16 The two ﬁlters are: 1 + z−8 .h> #include <stdlib. n<N. "w"). y2). x = s + A2 * cos(w2*n) + A3 * cos(w3*n). x). x. y1 = w[0] + w[8]. /* filter 1 */ |H1 (ω0 )| = |H2 (ω0 )| = 1 The following program implements this computer experiment.98z−8 H1 (z)= 0.8lf\n". y2. sizeof(double)). for (n=0. "%. fprintf(fpy2.0625z−8 FILE *fps. we ﬁnd the impulse responses. *fpx.5 0. fprintf(fpy1. delay(8.96 * v[8]. v). x1. delay(8.70849 · H2 (z)= 0. fpy1 = fopen("y1. "%.22. P7. for n = 1:N. sizeof(double)).96z−8 · −8 1 + 0. The corresponding output signals y1 (n) and y2 (n) from H1 (z) and H2 (z) are shown in Fig.0625 * w[8].% B = Kx3 numerator matrix (K = number of sections) % A = Kx3 denominator matrix % x = row vector input % y = row vector output fpx = fopen("x.02150 − 12. but does not remove the noise component well. end printf("enter input length N = "). except the input sample x gets multiplied by the corresponding normalization gains: /* combex. K1] = size(A). x(n)).98 * v[8].04433 1 − 0.94 * u[8]. /* filter 1 */ /* filter 2.c .0.comb filtering examples */ #include <stdio. fps = fopen("s. *w.00 * * * * pi pi pi pi / / / / 8.8lf\n". 8.dat". "w"). s).33584 + H2 (z) = 1. sizeof(double)). [y(n).00 3.94z 1 − 0. 8.0 0. were chosen such that the magnitude responses are unity at ω = ω0 = 0. w3. w0. fprintf(fpx. [N1. *fpy2.4. for 0 ≤ n ≤ 16: 128 129 . w2. H1 (z) = −11. y1).02063 + 1 + 0. w[0] = G1 * x + 0. w). 0. 1 − 0. x) [K.06191 0.98021 · The scale factors. n++) { s = A0 * cos(w0*n) + A1 * cos(w1*n). B. pi = 4*atan(1.75 1. } } "%.3 and 7.8lf\n". v = (double *) calloc(9.98021 /* filter 2 */ /* section 1 output */ /* section 2 output */ #define G1 #define G2 Fig. W = zeros(K. u). that is. we ﬁnd (where the PFE coefﬁcients are given with 5-digit accuracy): N. The sample processing algorithms of Examples 7. s. void delay(). N] = size(x). w0 w1 w2 w3 = = = = 0.h> #define #define #define #define A0 A1 A2 A3 1. which serves as the input to the comb ﬁlters. "w").17 Performing a partial fraction expansion on H1 (z) and H2 (z). Problem 7. but it removes the noise very well.5π/8. "%.4.0. w = (double *) calloc(9. section 2 */ function y = casfilt(B. fpy2 = fopen("y2.dat". *u. signal s(n) and the noisy signal x(n). y1.5 0. A.

scanf("%d".c of Problem 7. double *p.98021 0 0 0 0 0 0 0 0. ydir. double **A. double dir(). P7. /* circular pointers */ wdir = (double *) calloc(M+1. ccas(). dir. **P. /* initialize */ 130 131 . *wcan. FILE *fpx. Problem 7.circular buffer versions */ #include <stdio. P7. but with changing the input x(n) into an impulse δ(n). M. j.07841 0 0 0 0 0 0 0 −0. printf("no.22 Outputs of comb ﬁlters 1 and 2 of Problem 7. *a.18 The following program replaces iirfilt.13.h> void cas2can(). Fig. sizeof(double)).IIR filtering experiments .c is left in the program as before. For comparison. The computed impulse responses are shown in Fig.16.23 Impulse responses of comb ﬁlters 1 and 2 of Problem 7.75277 0 0 0 0 0 0 0 0. n 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 h1 (n) 0.c .70849 0 0 0 0 0 0 0 0.16.h> #include <stdlib. Fig. p = wcan. P7. wcan = (double *) calloc(M+1. &K). double x. **W.21 Desired and noisy inputs of Problem 7. sizeof(double)). sections K = "). ycas. vdir = (double *) calloc(M+1.dat". sizeof(double)).17.04705 h2 (n) 0. ccan(). P7. double *vdir.The impulse responses of the two ﬁlters can be computed by the same program as above. fpx = fopen("x. /* iirfilt.23 Fig. *b. *wdir. K.03489 void main() { int i. ycan. M=2*K. **B. "r").

a. b. P7. P = (double **) calloc(K. i<K. Therefore its usage is: ycan = ccan(M.5 One minor difference in ccan is that it assumes the same order M for both vectors a and b.5)2 z−6 + (0.i++) printf("% . A.i<=M. j<3. It has z-transform: W(z)= 1 D(z) X(z)= 1 X(z) 1 − 0.6lf % . } x 6 y w0 s0 z-3 w3 s3 /* allocate */ 0.6f\n".5 n 0 1 2 3 4 5 6 x 1 0 0 0 0 0 0 w0 1 1 1 1 0 0 0 w1 0 0 0 0. P7. ] s3 0 0 0 1 0 0 0.6f % . a).5)3 z−9 + · · · which gives the impulse response: h = 6. B. i). P. which is the intermediate signal obtained at the output of the input adder. for(j=0. sizeof(double *)). for(j=0. x). 0 . M. /* initialize */ for each input x do: w 0 = x + 0 . x). 5 2 s1 0 1 0 0 0 .5 0. wdir. 0 . . 2(0. & p) The impulse response can be obtained by dividing out the numerator and writing H(z)= Expanding in powers of z−3 . ycas = ccas(K. b. 0. sizeof(double *)). . they are the successively delayed versions of w(n). x). &p. sizeof(double)). b.5 w2 0 0 0 0 0 0 0. A. x). printf("\n\n"). i++) { printf("enter B[%d] = ". x). wcan. } for(i=0. 0 . W = (double **) calloc(K.5)3 .5 . sizeof(double *)). j++) scanf("%lf". for (i=0. i). a[i].19. 0.52 w3 0 0 0 0 0 0 0 s0 1 0 0 0.5 -2 Fig. i<K. w.5z−3 H(z)= 4 + 2 1 + (0. } cas2can(K. . ydir. A[i]+j). x. B. i<K.5). P[i] = W[i].5)2 . sizeof(double)). sizeof(double)).6f % . .24. 0 . 0. &x) != EOF) { ydir = dir(M. i++) { A[i] = (double *) calloc(3. B[i] = (double *) calloc(3. 0. W. p. = [ 6 . printf("% . . for (i=0. The linear and circular buffer versions of the sample processing algorithm are as follows: that is. ycas). vdir.5 0. 2(0. The states si represent the delay-line outputs: whereas the usage of can was: ycan = can(M.5 0. b. cas2can(K.5 0 0 s2 0 0 1 0 0 0 .5z−3 1 − 0. 0. ycan. w) for each input x do: s3 = tap(3. sizeof(double)). &p.6lf\n". b). 3) s0 = x + 0. s0 (n) ⎢ s (n) ⎢ 1 s(n)= ⎢ ⎣ s2 (n) s3 (n) ⎡ ⎤ ⎡ w(n) ⎥ ⎢ w(n − 1) ⎥ ⎢ ⎥=⎢ ⎦ ⎣ w(n − 2) w(n − 3) ⎤ ⎥ ⎥ ⎥ ⎦ Problem 7.a = (double *) calloc(M+1.5)z−3 + (0. b[i]). } for(i=0. M.6f % . wcan. "%lf". i++) { printf("enter A[%d] = ".5z−3 132 133 . A = (double **) calloc(K. 1 . j++) scanf("%lf". 2(0. sizeof(double)). b = \n"). wcan. 0. j<3. B = (double **) calloc(K. B[i]+j).5 0 y = 6s 0 − 2 s 3 6 0 0 1 0 0 0 . ycan = ccan(M. . 0 .24 Canonical realization of Problem 7. while(fscanf(fpx. a. } printf("a.5 0 0 0.19 The canonical realization is shown in Fig.5 w 3 y = 6w 0 − 2w 3 delay(3. 0. w. b = (double *) calloc(M+1. we have: 6 − 2z−3 2 =4+ 1 − 0. W[i] = (double *) calloc(3. a. a. sizeof(double *)).5s3 y = 6s0 − 2s3 ∗p = s0 cdelay(3. 0.

together with the exact magnitude response. a4 ]= [1. in the cascade case the rounding operation changed the magnitude response somewhat. Thus. the ﬁlter will remain stable. 0. (P7. a01 .1) The cascade realization. They are both inside the unit circle. the roots of the denominator polynomial.9) p0 = R0 ejω0 . are: ˆ ˆ ˆ p0 = R0 ejω0 . 1π ω 1 = 0. that is. a1 .26. . 0. If we round the direct form coefﬁcient vector a to 2-digit accuracy. carrying out the convolution of the two vectors in Eq. The latter is blowing up exponentially.4) ˆ ˆ The ﬁlters Hdir (z) and Hcas (z) are not equal. 0. 5 0. −3.7. 2π . the ﬁlter remains stable.4749. The corresponding cascade transfer function will be: (P7.25 s1 0 1 2 3 0 . ˆ ω1 = 0. we have X(z)= 1. in the sense that if we round its coefﬁcients also to 2-digit accuracy.5 s0 1 2 3 0. (P7. Thus. P7. a3 . therefore. 0.5 0. ˆ R1 = 0. its four poles. the p0 pole has moved outside the unit circle.5 1 s3 0 0 0 1 2 3 0. −3.6065. 0. 5. Rounding the cascade coefﬁcients to 2-digit accuracy is not equivalent to rounding the direct form coefﬁcients. 0. we obtain: ˆ ˆ ˆ ˆ ˆ = [1. 0. −1.5) are shown in Fig.7) gives the following direct form vector.9) are shown in Fig. rounding the SOS coefﬁcients (P7. over 0 ≤ ω ≤ 0.1045π ˆ ω1 = 0.9950 ω0 = 0. −3. giving: W(z)= 1 = 1 + (0.For a delta-function input. −3. a11 .99] a The roots of these sections are: ˆ ˆ ˆ p0 = R0 ejω0 . The zeros of a polynomial are indirect functions of the coefﬁcients 134 135 .1) and (P7. 0.979] The full precision cascade coefﬁcients are: a0 = [1. The seemingly benign replacement of a by the rounded ˆ has made the direct form a realization unusable. ˆ ˆ ˆ p1 = R1 ejω1 . p1 = R1 e jω1 R0 = 0.50. P7. 0.02. a12 ]= [1.9950.5π. rounding does not preserve convolution. P7. a12 ]= [1.25 Full and 2-digit precision ﬁlters. a02 ]= [1. 5 w2 0 0 3 3 3 3 0.464.9859] The poles are at: (P7. a02 ]= [1.5.5 1 1 .90.98] a and the corresponding direct form transfer function: ˆ Hdir (z)= 1 ˆ 1 + a1 (P7. (P7. Indeed.5 1 1.8955.0961π ˆ R1 = 0.52 . . which is the right half of the Nyquist interval. which is not quite the same as that given by Eq.1989π (P7.8) and their conjugates.46. −1. 0. a2 . The impulse responses of the two ﬁlters (7. on the other hand.9801] a a ˆ R0 = 1. 20 log10 |H(ω)|. −1.024. 0.25 w3 0 2 2 2 2 1.5)z−3 + (0.5100. and their conjugates. 5 0. rendering the ﬁlter unstable. 0. 5.7) ˆ ˆ R0 = 0.9929. a3 .502. ] For the input x = [1.5 1 . Indeed.25. −3.2) (P7.4): ˆ0 ∗ ˆ1 = [1. The impulse response and the magnitude response of the cascaded ﬁlter (P7.0045. 0. but has not affected the stability of the ﬁlter.6) ˆ ˆ p 1 = R1 e ˆ jω1 .61. that is. 0. Indeed. we have: n 0 1 2 3 4 5 6 x 1 2 3 0 0 0 0 w0 1 1 1 1 1 1 1 w1 0 0 0 0.9965.5 y = 6 s 0 − 2s 3 6 12 18 1 2 3 0 .20 The full precision direct form denominator is: a = [1. a1 . 2. R1 = 0. a11 .3) ˆ Hcas (z)= 1 1 · ˆ ˆ ˆ ˆ 1 + a01 z−1 + a02 z−2 1 + a11 z−1 + a12 z−2 (P7. 0. ˆ ω0 = 0. The magnitude responses are plotted in dB. a4 ]= [1.5 Fig.99] a ˆ ˆ ˆ1 = [1. Problem 7. 5 0.0390.5)2 z−6 + (0. The sensitivity of the direct form and the robustness of the cascade form can be understood analytically in the following way.5z−3 and in the time domain: w(n)= [1.9930] a1 = [1.2000π (P7. . Therefore. ˆ = a0 ∗ a1 ≠ ˆ0 ∗ ˆ1 a a a z−1 ˆ + a2 z−2 ˆ + a3 z−3 ˆ + a4 z−4 (P7.9860. 3]. a2 .5)3 z−9 + · · · 1 − 0.5 s2 0 0 1 2 3 0. is more robust. ω 0 = 0. −3. because rounding does not preserve products—the rounded product of two numbers is not equal to the product of the two rounded numbers.5) This ﬁlter is unstable.2) to 2-digits gives: ˆ ˆ ˆ0 = [1. a01 . −1. 5.

1046π ˆ p1 = p1 + dp1 = 0. (p0 − p∗ ) 0 dp1 = − p1 da11 + da12 ∗ (p1 − p1 ) (P7.001] Using the numerical values given in Eq. (P7.5770 = 0. setting z = p1 .10) and (P7.3. p0 is associated with the ﬁrst SOS and p1 with the second. the induced changes in the zeros can be large. we can calculate the pole shifts using (P7. the induced changes remain small.2π = 0. A similar calculation can be made based on Eq. it follows that if the poles are closely clustered. the new pole locations will be: (P7. consider the above fourth order denominator vector a. thus. a → a + da dp0 = − p0 da01 + da02 .4) in the form ˆ = a + da. we obtain 0 dp0 = 0. 0. 0. 0. the sensitivity of each pole is coupled to the other poles. that is. i = 0.1): a a a da = ˆ − a = [0.4) and (P7. The relationship of the zeros to the coefﬁcients is established via the polynomial identity: (1 − p0 z−1 )(1 − p∗ z−1 ) = 1 + a01 z−1 + a02 z−2 0 (1 − p1 z−1 )(1 − p∗ z−1 ) = 1 + a11 z−1 + a12 z−2 1 Using the above procedure of taking differentials of both sides and setting z = p0 in the ﬁrst and z = p1 in the second.9965ej0.3). For example. we ﬁnd for dp1 : dp1 = − p3 da1 1 + + p1 da3 + da4 (p1 − p∗ )(p1 − p0 )(p1 − p∗ ) 0 1 p2 da2 1 (P7. 1 To determine dp0 and dp1 in terms of da.13). P7. .3079 p1 = 0. giving the relationship: p0 = 0.26 Impulse and magnitude responses of 2-digit-precision cascade form. such factors cause large shifts in the pole locations. small changes in the latter will induce changes in the former.9863ej0.12) (pi − pj ) j=1 j≠i In the cascade realization.9501 + j0.1989π Similarly.3238 = 1. not on the other sections. the denominator involves the differences between poles. .11). . (P7. da1 . the induced changes in the poles dpi will be large even if the coefﬁcient changes dai are small. pM : dpi = ∂pi ∂pi ∂pi da1 + da2 + · · · + daM ∂a1 ∂a2 ∂aM where the partial derivatives are: ∂pi =− ∂am Fig.1π = 0. we obtain subtracting (P7.0033 − j0.11). the distances from all the other poles.6). In the cascade form. through the denominator factors of the form (p0 − p1 ). Therefore.0023 + j0. causing them to move outside the unit circle.004. −0. da4 ]= [0. p2 . Setting z = p0 will remove all but the ﬁrst term in the left-hand-side. that is.5836 With these values of the poles and dai . (P7.10) dp1 = −0. we may actually apply them to the above example and estimate the pole shifts for the 2-digit case. . . . a2 .002. The dependence of p0 on a0 and p1 on a1 is established through the identities of the polynomial. da3 .0066 dp0 = − p3 da1 + p2 da2 + p0 da3 + da4 0 0 (p0 − p∗ )(p0 − p1 )(p0 − p∗ ) 0 1 ˆ p0 = p0 + dp0 = 0. (P7.13) ⇒ pi → pi + dpi . a1 . .246] to the case of an order-M ﬁlter a = [1. For the direct form. we take differentials of both sides of the above polynomial identity to get: The sensitivity of each pole depends only on the SOS it belongs to. Writing the rounded ˆ of Eq.9477 + j0. pM−m i M (P7. da2 .0159.10) and (P7. We ﬁnd: −dp0 p−1 (1 − p∗ p−1 )(1 − p1 p−1 )(1 − p∗ p−1 )= da1 p−1 + da2 p−2 + da3 p−3 + da4 p−4 0 0 0 0 0 0 0 0 1 0 Multiplying by p4 and solving for dp0 . Even though the sensitivity formulas (P7. In Eqs. we obtain the induced changes in the poles due to small changes in the coefﬁcients of the sections: (1 − p0 z−1 )(1 − p∗ z−1 )(1 − p1 z−1 )(1 − p∗ z−1 )= 1 + a1 z−1 + a2 z−2 + a3 z−3 + a4 z−4 1 0 A small change in the coefﬁcients will induce a small change in the zeros p0 and p1 .9929ej0. if p0 is near p1 . . therefore.10) and (P7.11) involve differential changes.Because.8033 + j0. 136 137 . aM ] with M zeros p1 . we have − dp0 z−1 (1 − p∗ z−1 )(1 − p1 z−1 )(1 − p∗ z−1 ) 0 1 − (1 − p0 z − (1 − p0 z −1 −1 )dp0 z ∗ −1 (1 − p 1 z −1 )(1 − p1 z (1 − p1 z ∗ −1 ∗ −1 ) ) )(1 − p0 z ∗ −1 )dp1 z −1 − (1 − p0 z−1 )(1 − p∗ z−1 )(1 − p1 z−1 )dp∗ z−1 0 1 = da1 z−1 + da2 z−2 + da3 z−3 + da4 z−4 which is still an identity in z.0037ej0.11) which compare well with the actual values of Eq. (P7.004. The above sensitivity formulas generalize easily [2.7999 + j0.

21.58649943 0.923469 ± j0. The rounded ai are: ˆ0 = [1. Problem 7.284105 0. However. the roots of the denomia nator polynomials a.266869 0.12) which can cause large shifts in the poles even though da is small. Fig. as we see below. Figure P7. and in fact they are practically equal to the unquantized ones. it has a passband ripple of almost 2 dB instead of the required 1 dB. full precision 0.1 Exact.84961490 −4.967208 ± j0. that is.978849 0. The 4-digit cascade response.216576 0.49508213 11. 5.008071 0.74713000 3.1 shows the equivalent direct-form coefﬁcient vector ˆcas arising a from the cascade of the quantized second order section coefﬁcients.215739 0. Table P7.49540451 11. P7.05062000 −16.6487×10−6 ˆcas a 1.84993647 −4. 0.980971 0. (P7.and 4-digit direct forms fail.00000000 −5. Thus.1.Problem 7. and 4-digit cascade cases are shown in Fig.8671. the ﬁlter remains stable.079185 4-digit direct 0. the 4-digit cascade form gives an adequate approximation of the exact ﬁlter. and ˆ2 . P7. the error in the 5-digit case is less than that in the 4-digit case. whereas both the 5.05046030 −16.and 4-digit ˆ.078311 5-digit direct 0. 0.888774 ± j0.2580×10−7 a 4-digit ˆ 1. the error of the cascade case is larger.20.49540000 11.9623] a ˆ1 = [1.980962 0.078152 magnitude 0.923398 ± j0. Problem 7. 5-digit direct.300414 0. −1. da a = ˆ−a a a where a denotes the length of the vector a.929217 magnitude 0.56570000 13.05062482 −16.74710000 1. The fourth column of Table P7.58633537 0.927787 ± j0.00000000 −5. and of the rounded SOS polynomials ˆ0 .56573395 13. rounded to 4-digit accuracy.8992] a ˆ2 = [1. which is unstable. This behavior can be traced to the pole sensitivity formula Eq.923396 ± j0.948265 0.301259 0. the quantized coefﬁcients ˆ correspond a to an unstable ﬁlter.56570000 13.00000000 −5.20.74713457 relative error a 5-digit ˆ 1.853736 4-digit cascade 0. 5-digit.49540000 11.23 See the solution of Problem 7. rounded to 5. 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.8518. meets the speciﬁcations. −1. 0.8468.27 Impulse responses of full-precision and 4-digit-precision ﬁlters.58650000 0. Problem 7.925911 ± j0.58650000 0.931610 ± j0. But.21 The numerical values of a are shown in the ﬁrst column of Table P7.952730 0.56573000 13.999999 0. −1.84990000 −4.853736 magnitude 0.948258 0. ˆ1 .301303 0.28.00000000 −5. 138 139 . a a a For the 5-digit direct form. one almost on the unit circle.9240×10−5 Table P7.215719 0. By contrast. deﬁned as the ratio relative error = (P7. The second and third columns of this table show the quantized versions of a.999999 0.2 Filter poles. the roots of the 4-digit quantized cascaded form ˆcas remain a inside the unit circle. As expected.14) Table P7.926857 magnitude 1.74710016 1.27 shows the impulse responses of the exact ﬁlter based on a and the 4-digit-precision ﬁlter based on ˆ.22 See the solution of Problem 7.8634] a The table also shows the relative error in each case. for the 4-digit direct form. a The impulse responses of the 5-digit case and the 4-digit cascade case based on ˆcas are shown a in Fig.and 4-digit accuracy.05060000 −16. and 4-digit coefﬁcients.925902 ± j0.2 shows the poles of the exact and approximate ﬁlters. But.933557 ± j0. Note that the 5-digit direct no longer meets the passband specs.927976 0. on the other hand. P7.29.84994000 −4.933552 ± j0. The magnitude responses of the full precision.929194 a 1.

Problem 7. .24 The transfer function is: b0 + b1 z−1 + b2 z−2 + b3 z−3 H(z)= 1 + a1 z−1 + a2 z−2 + a3 z−3 (P7. by 140 141 .or. .a[M] * v[0]. will be: y(n)= v0 (n)= b0 x(n)+v1 (n) v1 (n + 1)= b1 x(n)−a1 y(n)+v2 (n) v2 (n + 1)= b2 x(n)−a2 y(n)+v3 (n) v3 (n + 1)= b3 x(n)−a3 y(n) which leads to the sample processing algorithm: Fig.25 In the case of a general transfer function of the type of Eq.c . Problem 7. M−1 do: vi = bi x − ai v0 + vi+1 v M = b M x − aM v0 The following C function transp. and 4-digit cascade.1.21. we also introduce the quantity v0 (n) which is the overall output obtained at the top adder. v = internal state vector a. . b. For indexing convenience. b. /* transp. (7. The (M+1)-dimensional array v = [v0 . .c is an implementation. v1 (n)= b1 x(n − 1)−a1 v0 (n − 1)+v2 (n − 1)= b1 x(n − 1)−a1 y(n − 1)+v2 (n − 1) Its usage is the same as that of can or dir. we have the sample processing algorithm. v[M] = b[M] * x . x) double *a. . i++) v[i] = b[i] * x . that is. v. vM ] must be declared and allocated in the main program. usage: y = transp(M. where we assumed L = M for simplicity: for each input sample x do: Fig. *v. v[0] = b[0] * x + v[1]. These rules can be applied to the canonical or direct realizations of IIR ﬁlters. and adders by nodes. reversing all ﬂows.17) Problem 7. v2 (n). *b. a. advancing it to the next time instant: v1 (n + 1)= b1 x(n)−a1 v0 (n)+v2 (n)= b1 x(n)−a1 y(n)+v2 (n) Therefore.28 Impulse responses of 5-digit direct and 4-digit cascade ﬁlters.4).a[i] * v[0] + v[i+1]. which includes the updating of the internal states. a.16) y = v 0 = b 0 x + v1 v1 = b1 x − a1 y + v2 v 2 = b 2 x − a 2 y + v3 v3 = b3 x − a 3 y Problem 7.21. int M.29 Magnitude responses of exact. x. . 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). v3 (n). the overall I/O system. for each input sample x do: (P7. v1 .15) Transposed realizations of FIR ﬁlters are obtained by the four transposition rules of exchanging input with output. 5-digit direct. . . y = v 0 = b0 x + v1 for i = 1. } v0 (n)= y(n)= b0 x(n)+v1 (n) The output of each delay is the delayed version of the output of the adder below it. P7. x). replacing nodes by adders. 2. { int i. return v[0]. i<=M-1.b have same order M output y(n)= v0 (n) state updating for (i=1. v. for example. for example. P7. double transp(M.IIR filtering in transposed of canonical form */ (P7.

we obtain the following nested form for the computation of the output. Transposed realizations are not intuitively obvious. the transfer function (P7.h> #include <stdio.30. (max + 1) * sizeof(double)). /* trspfilt. } L--. char **argv) { FILE *fpa. x. "Can’t open filter file: %s\n". and using Y(z)= H(z)X(z).h> #define MAX 64 double transp(). for (L=0. "Usage: trspfilt a.14. } v = (double *) calloc(M + 1. exit(0).84z The transpose of the canonical form is shown in Fig. this program aborts if the lengths are unequal. (P7. but their overall implementation in terms of Eq. } } process input samples H(z)= −(a1 z−1 + a2 z−2 + a3 z−3 )H(z)+b0 + b1 z−1 + b2 z−2 + b3 z−3 which can be written in the nested form: H = b0 + z−1 (b1 − a1 H)+z−1 (b2 − a2 H)+z−1 (b3 − a3 H) Multiplying both sides by the z-transform X(z) of the input x(n).dat <x. sizeof(double)). 4z 1 + 0. a + M) == EOF) break. void main(int argc. a. "%lf".5z−2 −2 + 0.dat >y. The sample processing algorithm of a 2nd order section is simply: for each input sample x do: y = v0 = b0 x + v 1 v1 = b 1 x − a 1 y + v 2 v2 = b 2 x − a 2 y which can replace Eq. } M--. } a = (double *) calloc(max + 1.25. sizeof(double)). Because transp assumes that a and b have the same length M. P7. L.double *v.15) can be written as: fprintf(stderr.. "Can’t open filter file: %s\n". } if (fscanf(fpa. sizeof(double)). int M. (L + 1) * sizeof(double)). y).17) has a certain simplicity and elegance.2). *b. (max + 1) * sizeof(double)). output initial allocation and increment The transfer function is: H(z)= 9 − 4z−2 + 4z−4 3 − 4z−1 + 2z−2 3 + 4z−1 + 2z−2 = · −1 + 0. } if ((fpb = fopen(argv[2]. } if ((fpa = fopen(argv[1]. sizeof(double)). *v. It corresponds to writing the transfer function of the ﬁlter in a nested form.5z−2 1 + 0. exit(0). printf("%lf\n". int max = MAX.b must have same length").25z−4 1 − 0 .b must have same length"). x). b + L) == EOF) break.c of Problem 7. i. } if (fscanf(fpb. a = (double *) realloc((char *) a. The I/O difference equations are: 142 143 . &x) != EOF) { y = transp(M.2. "coefficient vectors a. while(scanf("%lf". For o example. a = (double *) realloc((char *) a. input. exit(0). if (argc != 3) { initial allocation size Problem 7. b = (double *) realloc((char *) b.. fprintf(stderr. y. M++) { if (M == max) { max += dmax. "%lf". which is basically the transposed form: Y = b0 X + z−1 (b1 X − a1 Y)+z−1 (b2 X − a2 Y)+z−1 (b3 X − a3 Y) The transposed form can also be used in the cascade realization. double *a. L++) { if (L == max) { max += dmax. b = (double *) calloc(max + 1. Problem 7. where each second order section will be realized in its transposed form.c . It replaces canfilt. argv[1]).IIR filtering in transposed form */ #include <stdlib. calling the routine transp. dmax = MAX. b = (double *) realloc((char *) b. which is similar to H¨rner’s rule of evaluating a polynomial. v. b. (7..26 The following program implements ﬁltering in the transposed form. if (M != L) { fprintf(stderr. *fpb. (M + 1) * sizeof(double)). for (M=0. exit(0).dat b.27 coefﬁcient ﬁles coeffs. state.c of Problem 7. argv[2]). v = (double *) calloc(M+1. "r")) == NULL) { fprintf(stderr.dat\n"). "coefficient vectors a. "r")) == NULL) { fprintf(stderr.4z−1 + 0.

4y(n)+v12 (n) v12 (n + 1)= 2x1 (n)−0.31. The cascade form with both 2nd order sections realized in their transposed form is shown in Fig.5 Fig.5x1 (n) y(n)= 3x1 (n)+v11 (n) v11 (n + 1)= 4x1 (n)−0. x(n) e(n) z -1 g(n) H1(z) H2(z) y(n) f(n) Fig.4y + v12 v12 = 2x1 − 0.25y(n) and the corresponding sample processing algorithm: v0 (n) v1 (n) z-1 v2(n) z -1 y(n) -4 -0.84y(n)+v3 (n) v3 (n + 1)= v4 (n) v4 (n + 1)= 4x(n)−0. The I/O difference equations are in this case: x(n) 3 v00 (n) v01 (n) z-1 x1(n) 3 v10 (n) v11 (n) z-1 y(n) x1 (n)= 3x(n)+v01 (n) v01 (n + 1)= −4x(n)+0. 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.5y(n) The sample processing algorithm will be: for each input sample x do: x1 = 3x + v01 v01 = −4x + 0.9 x(n) y(n)= 9x(n)+v1 (n) v1 (n + 1)= v2 (n) v2 (n + 1)= −4x(n)−0.5y -4 0.4 4 -0. P7. the adder and ﬁltering equations are in the time and z domains: e(n) = x(n)+f (n) g(n) = e(n − 1) y(n) = h1 (n)∗g(n) f (n) = h2 (n)∗y(n) ⇒ E(z) = X(z)+F(z) G(z) = z−1 E(z) Y(z) = H1 (z)G(z) F(z) = H2 (z)Y(z) 144 145 .5 2 v12(n) z-1 -0.4x1 + v02 v02 = 2x − 0.25y -0. P7. transfer function of the feedback system can be worked out easily using z-transforms.28 Problem 7.32 Then.28 The overall. P7. P7. P7.5x1 y = 3x1 + v11 v11 = 4x1 − 0. The general approach to analyzing this. with signal names assigned as in Fig.25 Fig.4x1 (n)+v02 (n) v02 (n + 1)= 2x(n)−0.84 v3(n) z -1 for each input sample x do: y = 9x + v 1 v4(n) z 4 -1 v1 v2 v3 v4 = v2 = −4x − 0. and any other.31 Cascade form with transposed sections. closed-loop.4 v02(n) z-1 2 -0.32 Case A of Problem 7.30 Transposed of canonical form. Consider case A.84y + v3 = v4 = 4x − 0.

28 and the individual transfer functions: In case B.4v(n − 1)+y(n) f (n) = 0.4v1 + y1 f = 0. The difference equations and corresponding sample processing algorithm are now: for each input sample x do: v0 = 0. we ﬁnd: w(n) w0 z-1 w1 0.2z−2 + 0. 4 v 1 + y f0 = 0.4 v(n-1) 0. Fig. Cases C and D have: v0 z-1 v1 -0.4(v0 − v1 ) (update delays) f1 = f0 w1 = w 0 v1 = v 0 w(n) w0 -1 z w1 0.34 Case B of Problem 7.4v(n − 1) e(n) = x(n)+f (n) w(n) = 0. Problem 7.4(v0 − v1 ) H1 (z)= 1 + z−1 .4v(n − 1)+y(n − 1). P7.5 w 1 + e y = w0 + w1 y1 = y (update delays) w1 = w0 v1 = v0 x(n) e(n) e(n) = x(n)+f (n − 1) w(n) = 0. which is not possible because f (n) is not yet Fig.Eliminating F(z) and E(z) in favor of X(z) and Y(z) gives: x(n) e(n) Y(z)= z−1 H1 (z)E(z)= z−1 H1 (z) X(z)+F(z) = z−1 H1 (z) X(z)+H2 (z)Y(z) and 1 − z−1 H1 (z)H2 (z) Y(z)= z−1 H1 (z)X(z) Solving for the closed-loop transfer function H(z)= Y(z)/X(z).5z−1 0. are: for each input sample x do: e=x+f w 0 = 0 . the overall transfer function remains the same.5z−1 H2 (z)= z−1 0.4 v(n) y(n) f1 f(n-1) z-1 z−1 H1 (z) H(z)= 1 − z−1 H1 (z)H2 (z) Case B has the same transfer function H(z). we would have e(n)= x(n)+f (n). P7.5w(n − 1)+e(n) y(n) = w(n)+w(n − 1) v(n) = 0.4(1 − z−1 )z−1 1 + z−1 1− · −1 1 − 0. P7.4z−1 1 + 0.3z−1 + 0. If this delay were not there.4z−2 H(z)= 1 − 1. The change causes a re-ordering of the computational cycle. 1 − 0.4v(n − 1) e = x + f1 w 0 = 0 . Now.4z−1 v(n) = 0.5w(n − 1)+e(n) y(n) = w(n)+w(n − 1) H1 (z) = H(z)= 1 − H1 (z)H2 (z) which gives 1 + z−1 1 − 0.33 Case A of Problem 7. The difference equations and sample processing algorithm. P7. we assign internal state variables as shown in Fig.29 The overall transfer function of this system can be computed using the results of Problem 7.29.4(1 − z−1 ) 1 − 0.4v(n − 1)+y(n − 1) f (n) = 0.29.5 w(n-1) 0.4 Notice how the extra delay factor z−1 in H2 (z) delays the output f (n) and allows the start of the computational cycle with e(n)= x(n)+f (n − 1).4v(n)−0.6z−1 − 0. The output f (n) is computed last. the start of the computational cycle is v(n)= 0. shown in Fig. where both quantities 146 147 .4z−3 In case A.4v(n)−0.34.4 v(n) y(n) y(n-1) y1 z-1 f(n) v0 z-1 v1 -0. 5w 1 + e y = w0 + w1 v 0 = 0.4 H(z)= 1− z−1 H H1 (z) 1 (z)H2 (z) computed.4 v(n-1) 0.5z 1 − 0.33. written in the right computational order.5 w(n-1) f0 f(n) 0.

p. δ(n − 1). Note that y(n) is computed last and then put into the feedback delay to be used in the next time step. v) y = u 0 = x + v2 v 0 = 0 . δ(n − 2). giving rise to the following generation algorithm.35 Feedback systems of Problem 7.30 The ﬁlter G(z) can be implemented by the input/output sample processing algorithm of its canonical form: for each x do: y = 0. v2 are the input impulse and its delays: δ(n).8y(n − 1). then the ﬁrst three iterations will ﬁll the feedback delay buffer w with the desired waveform samples. w2 . 2 x + 0.1 Problem 7. At each iteration. w) x v0 z-1 v1 w0 z-1 w1 z-1 2 y x w0 z-1 w1 z-1 w2 w3 z-1 2 y (a) (b) (c) x z -4 y v0 u G(z) x v4 z -4 y x v2 z-2 G(z) u0 z-2 y z-1 w2 w3 z-1 v2 v4 v0 G(z) Fig. Fig.v(n − 1) and y(n − 1) are available from the previous time step. w. & p) w0 = w 3 delay(3.2 u 2 + 0 . Identifying the proper input and output to the ﬁlter G(z) and using the above sample processing algorithm. v1 . P7.and z-domains: h(n) = b(n)+b(n − 3)+b(n − 6)+ · · · H(z) = B(z)+z−3 B(z)+z−6 B(z)+ · · · = B(z) 1 − z−3 = w1 = y where w1 is its internal state. y(n − 1). v0 u2 Fig. y(n − 3): 148 149 . 8 w 1 w 1 = v0 delay(2. v) delay(3.1. 3) cdelay(3. u) v0 = x y = w0 = v 1 + 2 v 2 + w 3 delay(2. delay(2. 8w 1 for each x do: for each x do: z−1 + 2z−2 1 − z−3 The direct and canonical realizations are shown in Fig. that is. that is. the feed-forward part of the algorithm will be zero. y(n − 2). P7. The w-columns are the successively delayed output signals y(n). v). For the direct form realization. v) y = x + v4 v 0 = 0. 8 w 1 w 1 = v0 delay(4.35 shows the three cases with explicitly assigned signal labels. P8. Chapter 8 Problems Problem 8. 2v 4 + 0. Their sample processing algorithms are: for each input x do: for each input x do: w1 = u y = v0 = x + u delay(4.2x(n)+0.1. 2]. 8 w 1 The transfer function is obtained by the period-3 repetition of the sequence b(n)= [0. w1 (n)= y(n − 1) in the difference equation: y(n)= 0. w. w) The following table shows the initialization and steady part of the linear buffer case. P8. The columns v0 . 2 y + 0.30. 1. in the time. w0 is replaced by the value of w3 and only then is the row of w’s shifted to the right to give the values of w1 .1 Direct and canonical realizations of Problem 8. we obtain the implementation of the three cases: for each x do: u = 0 . expressed in its of the linear and circular buffer versions: repeat forever: repeat forever: ∗p = tap(3. if the input is a unit impulse so that x = 1 at the ﬁrst iteration of the algorithm and zero for all other iterations. From then on. w3 of the next row. w) w0 = x + w 3 y = w 1 + 2w 2 delay(3.

will cause the period-5 replication of the numerator sequence b = [1. n 0 1 2 3 q 0 3 2 1 w0 ↑0 0 0 0 w1 0 0 0 ↑0 w2 0 0 ↑2 2 w3 0 ↑1 1 1 y 0 1 2 0 n 4 5 6 7 q 0 3 2 1 w0 ↑1 1 1 1 w1 0 0 0 ↑1 w2 2 2 ↑0 0 w3 1 ↑2 2 2 y 1 2 0 1 The following table shows the initialization and steady parts of the linear buffer case: n 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 v0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 v1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 v2 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 v3 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 v4 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 w0 1 2 3 −4 −5 1 2 3 −4 −5 1 2 3 −4 −5 w1 0 1 2 3 −4 −5 1 2 3 −4 −5 1 2 3 −4 w2 0 0 1 2 3 −4 −5 1 2 3 −4 −5 1 2 3 w3 0 0 0 1 2 3 −4 −5 1 2 3 −4 −5 1 2 w4 0 0 0 0 1 2 3 −4 −5 1 2 3 −4 −5 1 w5 0 0 0 0 0 1 2 3 −4 −5 1 2 3 −4 −5 y 1 2 3 −4 −5 1 2 3 −4 −5 1 2 3 −4 −5 n 8 9 10 11 q 0 3 2 1 w0 ↑2 2 2 2 w1 1 1 1 ↑2 w2 0 0 ↑1 1 w3 2 ↑0 0 0 y 2 0 1 2 n 12 13 14 15 q 0 3 2 1 w0 ↑0 0 0 0 w1 2 2 2 ↑0 w2 1 1 ↑2 2 w3 0 ↑1 1 1 y 0 1 2 0 The table entries circulate every D(D + 1)= 12 iterations. 5) cdelay(5. & p) w0 = w5 delay(5.2. −5]. 3. P8. w. v) delay(5. w) 150 151 . Their sample processing algorithms are: for each input x do: The circular version is given in the following table. We used 15 iterations because they contain one complete cycle of the table entries after the ﬁrst 3 initializing iterations. w. −4.2 Expanding the denominator in powers of z−5 . P8. p.2 Direct and canonical realizations of Problem 8. The buffer entry that contains the current output sample is shown with an up-arrow symbol and it corresponds to the entry wq deﬁned by the circulating value of q: v0 = x w0 = v0 + 2v1 + 3v2 − 4v3 − 5v4 + w5 y = w0 delay(4.x n 0 1 2 3 4 5 6 7 8 v0 z-1 v1 z-1 v2 v3 v4 z-1 z-1 2 3 -4 -5 w0 z-1 w1 z-1 w2 w3 w4 w5 z-1 z-1 z -1 y x w0 z-1 w1 z-1 w2 w3 w4 w5 z-1 z-1 z -1 y 2 3 -4 -5 v0 1 0 0 0 0 0 0 0 0 v1 0 1 0 0 0 0 0 0 0 v2 0 0 1 0 0 0 0 0 0 w0 0 1 2 0 1 2 0 1 2 w1 0 0 1 2 0 1 2 0 1 w2 0 0 0 1 2 0 1 2 0 w3 0 0 0 0 1 2 0 1 2 y = w0 0 1 2 0 1 2 0 1 2 The circular version is given in the following table.2. Problem 8. entry n = 3 and n = 15 will be the same. Thus. w) for each input x do: n 0 1 2 3 4 5 q 0 5 4 3 2 1 w0 = x + w5 y = w 0 + 2w 1 + 3 w 2 − 4 w 3 − 5 w 4 delay(5. w) w0 1↑ 1 1 1 1 1 w1 0 0 0 0 0 1↑ w2 0 0 0 0 − 5↑ −5 w3 0 0 0 − 4↑ −4 −4 w4 0 0 3↑ 3 3 3 w5 0 2↑ 2 2 2 2 y 1 2 3 −4 −5 1 The steady parts of the linear and circular buffer generation algorithms are: repeat forever: repeat forever: ∗p = tap(5. The buffer entry that contains the current output sample is shown with an up-arrow symbol and it corresponds to the entry wq deﬁned by the circulating value of q: Fig. The direct and canonical realizations are shown in Fig. 2.

w[2] = [b0 . P8. q4 ]= [0. w[3]. b6 ] For the linear interpolation case. q2 . 7. 5.36): q0 = 0 q1 = q0 − c = − q2 = q1 − c = 2 8 8 32 ≡8− = =6 5 5 5 5 4 32 8 24 − = =4 5 5 5 5 1 24 8 16 − = =3 5 5 5 5 3 16 8 8 − = =1 5 5 5 5 n 12 13 14 15 16 17 q 0 5 4 3 2 1 w0 3↑ 3 3 3 3 3 w1 2 2 2 2 2 3↑ w2 1 1 1 1 2↑ 2 w4 −4 −4 − 5↑ −5 −5 −5 w4 −5 −5 1↑ 1 1 1 w5 3 − 4↑ −4 −4 −4 −4 y 3 −4 −5 1 2 3 q3 = q2 − c = q4 = q3 − c = Fig. b1 . The d = 5 possible values of the offset index q are obtained by iterating Eq. We used 35 iterations because they contain one complete cycle of the table entries after the ﬁrst 5 initializing iterations. w[5]. P8. b2 . w[3]. q1 . Down-truncation gives the following integer values for the q’s and corresponding buffer entries: [q0 . q3 .3 n 6 7 7 9 10 11 q 0 5 4 3 2 1 w0 2↑ 2 2 2 2 2 w1 1 1 1 1 1 2↑ w2 −5 −5 −5 −5 1↑ 1 w3 −4 −4 −4 − 5↑ −5 −5 w3 −5 −5 −5 1↑ 1 1 w4 3 3 − 4↑ −4 −4 −4 w5 2 3↑ 3 3 3 3 y 2 3 −4 −5 1 2 The shift is c = D/d = 8/5 = 1. w[6]. b4 . 2] w[0]. 3. q1 . b4 . q4 ]= [0. b3 .1. 6. 3. Thus. b3 .6. w[5]. (8. b6 ] Rounding to the nearest integer gives: The table entries circulate every D(D + 1)= 30 iterations. q4 n 18 19 20 21 22 23 q 0 5 4 3 2 1 w0 − 4↑ −4 −4 −4 −4 −4 w0 − 5↑ −5 −5 −5 −5 −5 w0 1↑ 1 1 1 1 1 w1 3 3 3 3 3 − 4↑ w2 2 2 2 2 3↑ 3 w3 1 1 1 2↑ 2 2 w5 −4 − 5↑ −5 −5 −5 −5 w5 −5 1↑ 1 1 1 1 y −4 −5 1 2 3 −4 q3 w 3 b5 w4 b 4 q 2 w5 b3 w2 b6 b7 w1 q0 b 0 w0 b2 w6 b1 w7 q1 n 24 25 26 27 28 29 q 0 5 4 3 2 1 w1 −4 −4 −4 −4 −4 − 5↑ w1 −5 −5 −5 −5 −5 1↑ w2 3 3 3 3 − 4↑ −4 w3 2 2 2 3↑ 3 3 w4 1 1 2↑ 2 2 2 y −5 1 2 3 −4 −5 Fig. w[4]. w[6]. q3 . 2] w[0]. q3 . 4. b7 ] Up-truncation gives: n 30 31 32 33 34 35 q 0 5 4 3 2 1 w2 −4 −4 −4 −4 − 5↑ −5 w3 3 3 3 − 4↑ −4 −4 w4 2 2 3↑ 3 3 3 w5 1 2↑ 2 2 2 2 y 1 2 3 −4 −5 1 [q0 . q2 . q1 .3 Successive positions of q when d = 5.Problem 8. 1] w[0]. 4. q2 . q4 ]= [0. w[2] = [b0 . 5. w[1] = [b0 . entry n = 5 and n = 35 will be the same. b5 . [q0 . 6. b2 .3 shows the relative locations of the q’s with respect to the circular buffer. The ﬁve q-arrows are now at relative angles ω = 2π/5. we have the outputs: 152 153 . w[7]. b5 . w[4].

4. . b1 . 4. . b5 . . b5 . y3 . w[4]. b5 . w[5]. . q4 . P8. y0 . b6 . w[6]. b4 . 2] w[0]. b2 . . b0 . b0 . 7.1. . ] where the y’s are given above. b0 . b4 . w[1] = [b0 . b7 . q4 . ]= [1. b1 . y5 . w[3]. b5 . Referring to Fig. ] (truncate down) (truncate up) (round) 154 155 . q1 .4 The shift is c = D/d = 8/6 = 4/3. ] [y0 . b5 . . b7 . . and rounding: [q0 . w[3]. b6 ] [b0 . 6. y2 .5 This problem is similar to Example 8. . . 4. b3 . 4. w[7]. b2 . y1 . Down-truncation gives the following integer values for the q’s and corresponding buffer entries: [b0 . 7. w[5]. . . . y5 . 3. ] [b0 . b5 . . b6 . b0 . b4 . . q5 ]= [0. y3 . b6 . ] [b0 . 1] w[0]. q1 . b6 . w[4]. b2 . y2 . q3 . b2 . w[4]. . 3. b2 .4 Successive positions of q when d = 6. b5 .14. b6 . y1 . 5. b7 . w[6]. . b3 . (8. b7 ] Up-truncation gives: Problem 8. b0 . b4 . 5.q4 q0 = 0 6 < q1 < 7 4 < q2 < 5 3 < q3 < 4 1 < q4 < 2 q5 b5 w2 b6 b7 w1 q0 ⇒ y0 = w[0]= b0 2 3 ⇒ y1 = w[6]+(q1 − 6)(w[7]−w[6])= b1 + b2 5 5 w3 q3 w4 b 4 w5 q2 b3 ⇒ y2 = w[4]+(q2 − 4)(w[5]−w[4])= 4 1 b3 + b4 5 5 b 0 w0 b2 w6 b1 w7 q1 1 4 ⇒ y3 = w[3]+(q3 − 3)(w[4]−w[3])= b4 + b5 5 5 ⇒ y4 = w[1]+(q4 − 1)(w[2]−w[1])= 3 2 b6 + b7 5 5 Thus. . ]= [1. . 1. . b0 . 8. b4 . . 6. b4 . b4 . q2 . ] where the y’s were given above. b6 . b1 . b1 . q5 ]= [0. w[7]. 7. 6. q4 . b5 . b3 . 1. up. b7 . b4 . y3 . q5 ]= [0. ] [b0 . b2 . the following period-5 subsequences will be produced: Fig. y4 . b2 . b0 . b4 . b1 . 6. y2 . b3 .1. we have the outputs: Problem 8. q3 . ] [y0 . b3 . b3 . P8. b3 . . b7 . depending on the output method. . b4 . y4 . q2 . b6 . y2 . 2. . . q3 . b6 . . The d = 6 possible values of the offset index q are obtained by iterating Eq. q2 . b5 . b2 . b5 . b3 . b2 . 3. . b4 . w[2] = [b0 . b6 . b4 . b3 . . 1. (truncate down) (truncate up) (round) (interpolate) [q0 . . 4. w[2]. b3 . ] [b0 . 6. b0 . The six q-arrows are now at relative angles ω = 2π/6. ] [b0 . . 1] w[0]. . q1 . w[1] = [b0 . b2 . (truncate down) (truncate up) (round) (interpolation) Rounding to the nearest integer gives: [q0 . b1 . b3 . b4 . ] [b0 . we have for the cases of truncating down. b7 . b5 . b5 . 4. b0 . y1 . . y3 . b2 . b6 . the following period-5 subsequences will be produced: Fig. . . b1 . . depending on the output method. b3 . y1 . . . b1 . . b2 . ]= [1. y4 . . b3 . b6 . .1. b5 . b7 ] For the linear interpolation case.2. 7. y0 . y4 . 3.4 shows the relative locations of the q’s with respect to the circular buffer. 6. 4. b3 . . b5 . [b0 .36): q0 = 0 6 < q1 < 7 5 < q2 < 6 2 20 4 4 ≡8− = =6 3 3 3 3 ⇒ y0 = w[0]= b0 ⇒ y1 = w[6]+(q1 − 6)(w[7]−w[6])= ⇒ y2 = w[5]+(q2 − 5)(w[6]−w[5])= ⇒ y3 = w[4]= b4 ⇒ y4 = w[2]+(q4 − 2)(w[3]−w[2])= ⇒ y5 = w[1]+(q5 − 1)(w[2]−w[1])= 2 1 b5 + b 6 3 3 1 2 b6 + b 7 3 3 2 1 b1 + b 2 3 3 1 2 b2 + b 3 3 3 q0 = 0 q1 = q 0 − c = − q2 = q 1 − c = q3 = q 2 − c = q4 = q 3 − c = q5 = q 4 − c = q3 = 4 2 < q4 < 3 1 < q5 < 2 1 20 4 16 − = =5 3 3 3 3 16 4 12 − = =4 3 3 3 2 12 4 8 − = =2 3 3 3 3 1 4 4 8 − = =1 3 3 3 3 Thus. .

b5 . . i). b6 .dat".dat". *fp3. c. 2. } /* load wavetables */ /* might need the cast w1[(int)q1] */ y0 = b 0 = 1 y1 = y2 = y3 = y4 = 2 3 2 3 b 1 + b 2 = 2 + 3 = 2 . n. b5 . D\n"). . 7. .6 5 5 5 5 4 1 4 1 b 3 + b 4 = 4 + 5 = 4 . b6 .667 3 3 3 3 3 void main(int argc. . b6 . ] where (truncate down) (truncate up) (round) (interpolation) fp1 = fopen("y1. square(). w2 = (double *) calloc(D. fprintf(fp2. 8] we ﬁnd for the period-5 sequences: [b0 .0. fprintf(stderr. q3. 1. 3. &q1)). F. . i++) { w1[q1] = sine(D. ]= [1. 2. 3*D/4. sizeof(double)). square wave. *w2. b2 . b3 . "D = wavetable size\n"). . 3. .c . i). fp2 = fopen("y2.circular wavetable example */ #include <stdio. . "c = no.4 5 5 5 5 The case d = 6 is similar to Problem 8. q2. double *w1. wavgen(D. q1 = 0. ] [y0 . b4 . b1 . gdelay2(D-1. .6 This problem is similar to Problem 8. It generates three wavetables: sinusoidal. 8.0. b2 . &q3)). ] [b0 . ] [b0 . .1. &q2). 7 . just before Figs. of periods in D samples. its zeros are the solutions of: 156 157 . . "%lf\n". w2. 4.667. ]= [1. "A = wavetable amplitude\n"). . 3. char **argv) { int i. F=c/D\n"). b3 . 8. gdelay2(D-1. ] "usage: wavgenex A. "%lf\n". . A. .0. y4 . w2[q2] = square(D/2. 2. 6. wavgen(D.If we interpolate linearly.667 3 3 3 3 3 1 2 1 2 20 b5 + b6 = 6 + 7 = = 6. 6. F. . "w"). fp3 = fopen("y3.6. Therefore. 7. gdelay2(D-1. b2 . } Problem 8. b7 . 6. fprintf(stderr. 4. for (i=0.667. n<D. .4. 4. D = atoi(argv[3]). *w3.h> #include <math. 3.8. ]= [1. 0. y1 .h> void gdelay2().9. *fp2. . fprintf(fp3. "%lf\n". double wavgen(). A. y3 . Problem 8. sizeof(double)).8 Partial C code for this problem was given in the text. fprintf(stderr. wavgen(D. } for (n=0. &q2)). F = c / D. .8 5 5 5 5 3 2 3 2 b 6 + b 7 = 7 + 8 = 7 . 3.4.667. q3 = 0. . w3 = (double *) calloc(D. 5. ]= [1. A. w3. i<D. trapez(). 3. c. 5. "w"). . b7 ]= [1. 7. } A = atof(argv[1]).2 5 5 5 5 1 4 1 1 b 4 + b 5 = 5 + 6 = 5 . D. w1. w3[q3] = trapez(D. . FILE *fp1. . 1. sizeof(double)). q1. F. b1 . A.h> #include <stdlib. n++) { fprintf(fp1. and trapezoidal. 1. 5. 6.667. &q1). b4 . 4. b4 . The ﬁrst ﬁlter has H(z)= 1 + z−8 . 1. F. so that the period-3 sequence is: [1.1. "w"). y2 . Problem 8. w1 = (double *) calloc(D. . i). q2 = 0. . &q3).2. c = atof(argv[2]). .dat". Problem 8.20 and 8.7 An example program that exercises the wavetable routines is listed below. double sine(). 7.9 The zero patterns and magnitude responses |H(ω)| of the four ﬁlters are shown in Fig. we get the sequence: y0 = b0 = 1 y1 = y2 = 1 2 1 2 11 b2 + b3 = 3 + 4 = = 3. b5 . exit(0). . if (argc != 4) { fprintf(stderr. /* wavgenex. Inserting the numerical values for the wavetable contents: b = [b0 .3. 5.21.

5o . n<Ntot. a1 = 1 + ranl(Dran.11 is given in the text. &q2.5 + ranl(Dran.2. fprintf(fpx.h> double plain(). xd2 = tapi(D. and lowpass reverb */ #include <stdio. y = (x + a1 * xd1 + a2 * xd2) / 3. &q3.c . 2*d1/D). Similarly. p. xd1 = tapi(D. d2 = D * (0. For the recursive ﬂanger. "%lf\n". double *w2. &q1. p. d1). w. d). fprintf(fpa. 1 . &p). } /* is not shown */ Typical output is shown in Fig. fprintf(fpy.z8 = −1 = ejπ e2πjk ⇒ zk = ejπ/8 ej2πk/8 .2.11 A typical program is as follows: /* reverb. *p = y. "%lf\n". allpass(). yd = tapi(D. y). *p1.h> #include <math. "%lf\n".5 . "%lf\n". . u4. &iseed1)).9. Problem 8. Problem 8. o k = 0. x = cos(2 * pi * F * n). &iseed3). . void main(int argc. fprintf(fpy. but among them the roots of the denominator 1 + z−8 must be excluded. the 8th roots of unity rotated by π/8 ≡= 22.6. fprintf(fpd.cos(2 * pi * Fd * n)). 8. d2). w. P8. cdelay(D. The second ﬁlter has H(z)= 1 − z−8 and thus. "%lf\n". &p). /* u1 is 2-dim */ /* mean = D/2 */ /* mean = 1 */ /* input x(n) */ /* delay x(n-d1) */ /* output */ /* update delay */ /* declaration of fpx */ 158 159 . lowpass().plain.5 + ranl(Dran. Fig. a1). allpass. This results in 16 zeros. w. n++) { d = 0. 7 That is. w. *p2. u3. x). The third and fourth ﬁlters can be written as follows.10 Typical C code for generating Fig. a2 = 1 + ranl(Dran. &iseed2)). &q4. we have the code segment: for (n=0. For the double chorus case. n<Ntot.50 * D * (1 . &iseed4). the last ﬁlter’s zeros are the 24th roots of unity with the 8th roots of unity excluded. fprintf(fpd.5 Comb ﬁlters of Problem 8. p. w. *p = x.9 and 8. u2. P8. d/D). . P8. its zeros are the 8th roots of unity. "%lf\n". n++) { d1 = D * (0. . "%lf\n". char **argv) { double *w1. y = a * yd + x. Typical output for D = 100 and D = 10 is shown in Fig.6 Double chorusing of sinusoidal signal. } /* yd is y(n-d) */ The third has roots the 24th roots of unity shifted by π/24 = 7. using the ﬁnite geometric series: H(z) = 1 − z−8 + z−16 = H(z) = 1 + z−8 + z−16 = 1 + z−24 1 + z−8 1 − z−24 1 − z−8 for (n=0. x).h> #include <stdlib. x = cos(2 * pi * F * n). u1. P8. cdelay(D. we have the code fragment: |H(ω)| 2 2 3 3 2π ω 2π ω 2π ω 2π ω Fig. fprintf(fpx.7. y).

Ntot. w1. "w").5}.12 A typical program is as follows: Fig. else x=0. y1. y3. x). exit(0). sizeof(double)). y2 = allpass(D.75 . /* reverb. fp1 = fopen("y1. } } Problem 8. sizeof(double)). int D. "%lf\n". double x. *p4. double *w3.c .3. for (n=0.dat". Ntot = atoi(argv[2]). 160 161 . #include <stdio. p1 = w1.15}.h> use D=20. -0. fprintf(fp2. v. double v[2] = {0. double *w6. b. "%lf\n". "%lf\n". P8. fprintf(fp3. a0. *p3. int Ntot=500. w3. (double *) calloc(D+1. n.75. *p5. FILE *fp1. y2. &p1.75 . double b[2] = {0. y3). sizeof(double)). if (argc != 3) { fprintf(stderr. a. w2. "w"). } D = atoi(argv[1]). *p2. double *w2. double y1. *fp3. *p1.7 Recursive ﬂanger. w3. n++) { triangular pulse if (n<=5) x=n.Schroeder’s plain/allpass reverb system */ #define #define #define #define #define #define #define #define #define #define #define #define D1 D2 D3 D4 D5 D6 a1 a2 a3 a4 a5 a6 29 37 44 50 27 31 . y2. x.75 . w1 = (double *) calloc(D1+1.}. x). fp3 = fopen("y3. a0. (double *) calloc(D+1. double *w5. void main() { double *w1.dat". y. y5. fprintf(fp1. double a[2] = {1. "usage: reverb D Ntot").75 . w2 = (double *) calloc(D2+1. y4. 0.75 .y1 = plain(D. x). sizeof(double)). *p6.75 double *w3. 0. Ntot=100 double plain(). y1). sizeof(double)). w1 p1 w2 p2 w3 p3 = = = = = = (double *) calloc(D+1. double a0 = 0. sD. *fp2. y3 = lowpass(D. M. "w"). *p3. w1. n<Ntot. w2.dat".. &p2. FILE *fpy. M=1. else if (n<=10) x = 10-n.h> #include <stdlib. &p3. allpass(). double *w4. y3. fpy = fopen("y. y2). fp2 = fopen("y2.dat".h> #include <math. n. "w").

p3 = w3.9*y2 + 0.13 The difference equations are: v(n) = y(n − D)−a1 v(n − 1) u(n) = b0 v(n)+b1 v(n − 1) y(n) = x(n)+u(n) The corresponding circular version of the sample processing algorithm is for each input x do: sD = tap(D. v0 = sD − a1 v1 u = b 0 v0 + b 1 v 1 v1 = v0 y =x+u ∗p = y cdelay(D. *p1. *p2.7*y4. p6 = w6. y1 y2 y3 y4 = = = = plain(D1. else x = 0. N=300. p. -0. x). a1. w6. w=0. sizeof(double)). L=150. &p1.5}. double double double int D. sD. y5 = allpass(D5. = 0. a6. M=1. w2. sizeof(double)). a4. pi L. 0. w5. D+1 y(n)= H(ω)ejωn u(n)−u(n − L) + i=1 Bi pn u(n)−ejωL p−L u(n − L) i i y = y1 + 0.plain and lowpass reverberation of sinusoid */ * * run with: * D=300. for (n=0. w4. w=pi * */ #include <stdio. double b[2] = {0. w3. &p4. &p2. x. &p3.3.75. y = allpass(D6. sizeof(double)). *fp2.14 The response to a causal sinusoid will be of the form: D+1 ejωn u(n)− H(ω)ejωn u(n)+ → i=1 Bi pn u(n) i where Bi = Ai pi /(pi − ejω ).2pi. y2. double a[2] = {1. as shown in Problem 6. It follows that the response to a delayed sinusoid will be: D+1 ejω(n−L) u(n − L)− H(ω)ejω(n−L) u(n − L)+ → i=1 Bi pn−L u(n − L) i Multiplying both sides by the factor ejωL and subtracting from the undelayed result. we ﬁnd that the response to the ﬁnite sinusoid: x(n)= ejωn u(n)−u(n − L) is x).c . impulse Problem 8.8*y3 + 0.15}. sizeof(double)). &p5. &p6. x). n. 162 163 . x). a0 w. w3 = (double *) calloc(D3+1. lowpass().h> #include <math. 0.h> #include <stdlib. "%lf\n". & p) FILE *fp1. N. } } Problem 8. a3. w1.. w. plain(D2. D) double plain(). plain(D4. y). n<Ntot. p5 = w5. y1. a5.}.h> Problem 8. n++) { if(n==0) x = 1. fprintf(fpy. w4 = (double *) calloc(D4+1. w5 = (double *) calloc(D5+1. void main(int argc. double v[2] = {0. y5). y). a2.15 A typical C program that utilizes the routines plain and lowpass is given below: /* reverbex. = 4*atan(1.0). char **argv) { double *w1. w. double *w2.p2 = w2. p4 = w4.29. w6 = (double *) calloc(D6+1. plain(D3.

v. y2). p. a. "%. double a[2] = {1. A] = lprvb(b.fp1 = fopen("ypl. a0. a. x). z = exp(j * w).h> double ran().z^L / p(i)^L). D). A] = lprvb(b. D) % returns poles and residues of lowpass reverberator (delay D) % [p. end for n=0:N-1. x). for j=1:D+1.16lf\n". iseed=1234567 D=50. A] = lprvb(b.0}. exit(0). b. n<N. for i=1:D+1. for i=1:D+1. "%. end end end for (n=0. Ntot=500. atoi(argv[2]). else x = 0. a(2)] /* * * * * * /* karplus. sizeof(double)). end #include <stdio. } D L N w = = = = atoi(argv[1]). a. n++) { if (n < L) x = cos(pi*w*n). atof(argv[4]). b.. A(i) = 1 + a(2) / p(i). w1. *p. void main(int argc.z). zeros(1. y2 = lowpass(D.D-2). [p. &p2. y1). in units of pi w1 p1 w2 p2 (double *) calloc(D+1. (double *) calloc(D+1. the following MATLAB function calculates the residues Bi and computes N samples of the output signal y(n): function [y. H = 1 / (1 . sizeof(double)). a.}. w1. M. y(n+1) = y(n+1) + B(i) * p(i)^n * (1 . w. "w"). 164 165 . if j ~= i.h> #include <math. fprintf(fp1.h> #include <stdlib. 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").c . p=roots(c). 0. "w").16 A typical C program is as follows: The analytical expression for y(n) can be obtained as follows. a. D) % calculate y(n) for a finite-duration sinusoidal input. char **argv) { double *w. = = = = end end Then. 0. A] = yon(N. y(n+1) = y(n+1) + B(i) * p(i)^n. y(n+1) = H * z^n.m given below. B(i) = A(i) * p(i) / (p(i) . w2. b(2)] % a=[1. D) % % b=[b(1). for i=1:D+1.p(j)).z^(-D) * (b(1) + z^(-1)*b(2)) / (1 + a(2)*z^(-1))). if (n<L). } } Problem 8. L.16lf\n". Ntot=500. lowpass(). iseed=1234567 c = [a. we determine the poles pi and residues Ai of the transfer function: function [p. fprintf(fp2. sinusoid on for L samples y1 = plain(D. &p1. for i=1:D+1. atoi(argv[3]). fp2 = fopen("ylp. A(i) = A(i) * p(i) / (p(i) .Karplus-Strong String Algorithm */ run with: D=25. end else y(n+1) = 0.dat". double v[2] = {0. w2. -b]. Using the MATLAB function lprevb.dat".

The difference equations are the system: double lpdel(D. y. } } initialize w(n) = aw(n − D)+x(n) y(n) = cx(n)+bw(n − D) c w0 wD b x z -D a y Fig. v. *b. 166 167 . p). } usage: y=plaindel(D.dat". P8. P8. n. n<Ntot.18 The block diagrams and sample processing algorithms are essentially given in Section 8.plain reverberating delay */ double tap(). D-th tap delay output delay input update delay line Fig. /* lpdel.&p. w. a. b.9 Prototypical delay effect. int D. w.0. **p = x + a * y. D). y). &p. The C routines are: /* plaindel. exit(0). "%. P8. w. v.2.c . "w"). y = tap(D.a. **p. "usage: karplus D Ntot iseed"). P8. cdelay(D.lowpass reverberating delay */ double tap(). a. D) for each input x do: y = cx + bwD w0 = awD + x delay(D. n++) { y = lowpass(D.0). fpy = fopen("y. void cdelay(). p = w. w. a. void cdelay().8.5.9. x) double *w. x. } D = atoi(argv[1]). p is passed by address The output signals corresponding to D = 25 and D = 50 are shown in Fig. 0. x. fprintf(fpy. b. sizeof(double)). x) double *w. *v.5. for (n=0. w) x=0 y = cx + bsD ∗p = asD + x cdelay(D. p. The sample processing algorithm is in its linear and circular buffer forms: for each input x do: sD = tap(D. p. if (argc != 4) { fprintf(stderr. for (n=0.x). int D. M. w = (double *) calloc(D+1. a. { double y. w. M. can(). w. w.w.17 A block diagram realization is given in Fig. *a. p. **p. Ntot. M=1. n<=D. *p.double b[2] = {0. FILE *fpy. 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. return y. iseed = atol(argv[2]). & p) Problem 8. Ntot = atoi(argv[2]).8 Karplus-Strong string algorithm outputs. Problem 8. long iseed.4. n++) w[n] = ran(&iseed) .5}. 0.16lf\n". double x.c . double plaindel(D.

*w. sizeof(double)). b. "%. x). x1). *p.10 Multi-delay effects processor outputs. y = b[0] * x + b[1] * s[1] + b[2] * s[2]. w. v. w.15}.20 The sample processing routine is as follows. } Typical output is shown in Fig. } /* plain */ Fig. P8. } D-th tap delay output delay input update delay line The routines differ from plain and lowpass in that the ﬁlter outputs are taken after the delay z−D . cdelay(D1+D2. D2. s[0] = x + a[1] * s[1] + a[2] * s[2]. { double s[3]. **p. w1. &p2. b. return y. y = mlttap(D1. x1 = plaindel(D1. w1. x1). instead of before. */ y = b0 * x + b1 * x1 + b2 * x2.c . &p2. x). x. p2 = w2. v2. w. x). 1. cdelay(D. /* p passed by reference */ Typical output is as in Fig. It can easily be generalized to more than two multitap delay segments: Problem 8. Problem 8. fprintf(fpy.11 and is obtained by the code segment: for (n=0. /* mlttap. b. s[1] = tap(D1+D2. we have: 168 169 . } /* use L=1 or L=200 */ w1 = (double *) calloc(D1+1. w2. else x = 0. 0. sizeof(double)). */ x2 = lpdel(D2. else x = 0. y). a. *p1. w2 = (double *) calloc(D2+1. y = tap(D. M.. *p2. y. b. void cdelay(). double mlttap(D1.16lf\n". "%. a[2] = {1.19 Typical C code for this problem is: for (n=0. b. x2 = plaindel(D2.3. w. y). x2. w. /* lowpass */ /* output */ where the initializations are: double x. n++) { if (n<L) /* use if (n<1) for impulse response */ x = 1. { double y. p). &p. P8. b[2] = {0. return y. a0.}. Problem 8. *w1.8lf\n".. b2=0.multi-tap delay line */ double tap(). a. P8. fprintf(fpx.10.5}. D1+D2). D). x). &p1. n<Ntot. p). -0. double b[3]. *p. y. *p. x1. a. D2.int D. **p = x + can(M. /* /* x1 = lpdel(D1. v2[2] = {0. a. w. 0. /* /* /* /* /* /* 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. x) int D1. 0. n++) { if (n < L) x = 1. y). v1. w2. a. b1=0. s[2] = tap(D1+D2. fprintf(fpy. &p1.21 From the pole equation. a0. n<Ntot. 1.8lf\n". *w2.8. **p = s[0].16lf\n". "%.6 a0 = 0. w. fprintf(fpx. p. "%. x). D1).}.75. D2. a[3]. b0=1. double double double double double double v1[2] = {0.

.22 Working in the z-domain and denoting by WL (z) and WR (z) the inputs to the delays z−L and z−R . responding independently to their respective inputs. then using the inequality |a1 | + |a2 | < 1. Then. the sample processing algorithm is straightforward. For the case GL (z)= aL . wL1 .1) D(z)= 1 − z−R GR (z) and therefore. we get: YL (z) = HLL (z)XL (z)+HLR (z)XR (z) YR (z) = HRL (z)XL (z)+HRR (z)XR (z) 170 171 . XR (z). If both cross-feedbacks are zero.where HLL (z) = cL + HLR (z) = HRL (z) = 1 1 D(z) 1 − z−R GR (z) bL z−L D(z) 1 dR bR z−L z−R dL bL z−R z−L 1 1 − z−L GL (z) bR z−R D(z) HRR (z) = cR + with Fig. we would have: HLL (z) = cL + HLR (z) = 0 HRL (z) = bL z−L 1 − z−L GL (z) |z|D1 +D2 ≥ |z|D2 > |a1 ||z|D2 + |a2 ||z|D2 ≥ |a1 ||z|D2 + |a2 | which contradicts Eq. the computational sample processing algorithm will be: WR (z) −L GL (z)WR (z)+bR XR (z)+dL z WL (z) Solving the ﬁrst and third for the Ws. then the left and right channels decouple completely. we get the system: 1 − z−L GL (z) 1 − z−R GR (z) YL (z)−cL XL (z) − dR z−L YR (z)−cR XR (z) = bL z−L XL (z) YR (z)−cR XR (z) − dL z−R YL (z)−cL XL (z) = bR z−R XR (z) Solving for YL (z). . GR (z)= aR . Denote the left and right delay-line buffers by wL = [wL0 . YR (z) in terms of XL (z). . Thus. . we get: WL (z)= zL YL (z)−cL XL (z) . . we have: zD1 +D2 = a1 zD2 + a2 ⇒ (P8. but the right channel responds to both the right input and the cross feedback from the left output. all poles must have |z| < 1. wR1 . and let the corresponding delay outputs be sL and sR .1).11 Multi-Tap Delay Line. P8. the I/O equations of the block diagram will be: 1 − z−R GR (z) dL bL z−L z−R 1 − z−L GL (z) HRR (z) = cR + The corresponding I/O system is then: bR z−R 1 − z−R GR (z) YL (z) = cL XL (z)+z−L WL (z) WL (z) = z−L GL (z)WL (z)+bL XL (z)+dR z−R WR (z) YR (z) = cR XR (z)+z WR (z) = z −R −R YL (z) = HLL (z)XL (z) YR (z) = HRL (z)XL (z)+HRR (z)XR (z) which means that the left channel responds only to the left input (it does not receive any crossfeedback from the right channel). (P8. Thus. the transfer functions simplify to: 1 − z−L GL (z) |z|D1 +D2 = |a1 zD2 + a2 | ≤ |a1 ||z|D2 + |a2 | If a pole had |z| ≥ 1. D(z) D(z)= 1 − z−R GR (z) 1 − z−L GL (z) − dL dR z−L z−R For the special case when the cross couplings are dL = 0 and dR = 0. wLL ]= (L+1)-dimensional wR = [wR0 . . . wRR ]= (R+1)-dimensional Let pL and pR be the circular pointers circulating over them. dL = dR = 0. the outputs of these delays will be z−L WL (z) and z−R WR (z). . WR (z)= zR YR (z)−cR XR (z) Inserting them into the second and fourth. Problem 8.

for each input pair {xL , xR } do: sL = tap(L, wL , pL , L) sR = tap(R, wR , pR , R)

yL = cL xL + sL y R = c R xR + s R ∗pL = bL xL + aL sL + dR sR ∗pR = bR xR + aR sR + dL sL cdelay(L, wL , & pL ) cdelay(R, wR , & pR )

Problem 8.23

The sample processing algorithm is implemented by the C code segment:

int L = 30, R = 70; double *wL, *wR, *pL, *pR; wL = (double *) calloc(L+1, sizeof(double)); wR = (double *) calloc(R+1, sizeof(double)); for (n=0; n<Ntot; n++) { if (n < P) xL = 1; else xL = 0; sL = tap(L, wL, pL, L); sR = tap(R, wR, pR, R); yL = cL * xL + sL; yR = cR * xR + sR; *pL = bL * xL + aL * sL + dR * sR; *pR = bR * xR + aR * sR + dL * sL; cdelay(L, wL, &pL); cdelay(R, wR, &pR); fprintf(fp1, "%.16lf\n", yL); fprintf(fp2, "%.16lf\n", yR); } pL = wL; pR = wR;

Fig. P8.12 Stereo delays, with dL = dR = 0.3.

/* use xR = 0 */

Fig. P8.13 Stereo delays, with dL = 0.3, dR = 0.

} for (n=0; n<N; n++) { if (n < N/3) x = A1 * cos(w0 * n); else if (n < 2*N/3) x = A2 * cos(w0 * n); else x = A3 * cos(w0 * n); c = a * c1 + (1-a) * fabs(x); c1 = c; g = f(rho, c/c0); if (L > 1) G = fir(L-1, h, v, g); else G = g; y = G * x; /* use N = 600 */ /* generate input */ /* use w0 = 0.15 * pi */

Figures P8.12 and P8.13 show typical outputs. The left output does not start until n = L, therefore, the ﬁ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.

/* control signal */ /* update delay */ /* gain function */

Problem 8.24

The sample processing algorithm is implemented by the C code segment:

if (L > 1) h = v = for { (double *) calloc(L, sizeof(double)); (double *) calloc(L, sizeof(double)); (n=0; n<L; n++) h[n] = 1.0 / L; /* L-point smoother */

/* gain smoothing */ /* no smoothing */ /* compressor output */

172

173

fprintf(fpx, fprintf(fpy, fprintf(fpc, fprintf(fpg, }

"%.16lf\n", "%.16lf\n", "%.16lf\n", "%.16lf\n",

x); y); c); G);

/* /* /* /*

save save save save

input */ output */ control */ gain */

**where the compressor function is deﬁned by f (x)= xρ−1 , for x ≥ 1:
**

/* compressor function with 1:rho compressor ratio */ #include <math.h> double f(rho, x) double rho, x; { if (x >= 1) return pow(x, rho-1); else return 1; }

Fig. P8.14 Expander output and gain with increased threshold.

The compressing action takes place only above the threshold. For an expander, the gain function is deﬁned as follows, where now ρ > 1, but it takes effect only below the threshold:

/* expander gain function with 1:rho expander ratio */ #include <math.h> double f(rho, x) double rho, x; { if (x <= 1) return pow(x, rho-1); else return 1; }

Fig. P8.15 Noise gate output and gain with increased threshold.

Problem 8.25

Increasing the threshold to c0 will cause both A1 and A3 to be attenuated. However, A3 because it is further from c0 than in the case of Fig. 8.2.38, it will be attenuated more. Fig. P8.14 shows the results. The noise gate with threshold c0 = 1.5, will suppress both A1 and A3 , but A3 by much more, for the same reasons explained above. Fig. P8.15 shows the results.

Problem 8.27

Assuming a partial fraction expansion of the form:

M

H(z)=

i=1

Ai

1 − pi z−1

**we have for the impulse response:
**

M

Problem 8.26

Assuming the causal sequence {x(0), x(1), . . . } is zero-mean white, then the terms in the convolutional sum will be mutually uncorrelated and zero-mean: It follows that we have the bound:

M

hn =

i=1

Ai pn u(n) i

y(n)= h0 x(n)+h1 x(n − 1)+ · · · + h(n)x(0)

Thus, the output will have zero mean and its variance will be the sum of the variances of the successive terms:

n

2 2 2 2 2 σy = E[y(n)2 ]= h2 σx + h2 σx + · · · h2 σx = σx 0 1 n

M

M

|hn | =

i=1 M

A i pn ≤ i

i=1

|Ai ||pi |n ≤

i=1

|Ai ||pmax |n = C|pmax |n

h2 m

n=0

where C = i=1 |Ai | and we used the inequality |pi | ≤ |pmax |. The NRR inequality follows now by squaring and summing the above inequality for |hn | and applying the geometric series on the right-hand side.

174

175

Problem 8.28

For ideal ﬁlter shapes, the NRR is computed most conveniently using its frequency response deﬁnition: NRR =

2 σyv 2 σv

then we have the recursion:

s2 1 = s 2 + n+ n

1

n+1

(xn − mx )2 −s2 n

π

=

−π

|H(ω)|2

dω 2π

**For a bandpass ﬁlter, H(ω) is non-zero only over the interval ωa ≤ |ω| ≤ ωb , where it is unity. Thus, NRR =
**

2 σyv 2 σv

initialized with s2 = 0. The following program will calculate the input and output signals and 0 the experimental mean-square values. Any discrepancies are due to the ﬁlter transients and they disappear with increasing L:

/* smoothex.c - filtering with 1st order smoother */ #include <stdio.h> #include <math.h> double gran(); void main(int argc, char **argv) { int n, L; long iseed; double s=5, x, y, w1, a, m=0, sigma=1; double sx2=0, sy2=0; FILE *fpx, *fpy; if (argc != 4) { puts("\nUsage: smoothex a iseed L"); exit(0); } a = atof(argv[1]); iseed = atol(argv[2]); L = atoi(argv[3]); fpx = fopen("ttx", "w"); fpy = fopen("tty", "w"); for (w1=0, n=0; n<L; n++) { x = s + gran(m, sigma, &iseed); y = (1 - a) * x + a * w1; w1 = y; fprintf(fpx, "%lf\n", x); fprintf(fpy, "%lf\n", y); sx2 += ((x-s)*(x-s) - sx2) / (n+1); sy2 += ((y-s)*(y-s) - sy2) / (n+1); } printf("theoretical 1/NRR = %lf\n", (1+a)/(1-a)); printf("experimental 1/NRR = %lf\n", sx2/sy2); }

=

−ωa −ωb

dω + 1· 2π

ωb ωa

ωb − ωa dω = 1· 2π π

Problem 8.29

The following program is an implementation:

/* smooth1.c - 1st-order exponential smoother */ #include <stdio.h> #include <math.h> void main(int argc, char **argv) { double a, x, y, w1 = 0; if (argc != 2) { fprintf(stderr, "usage: smooth1 a <x.dat >y.dat\n"); exit(0); } a = atof(argv[1]); fprintf(stderr, "%lf\n", a); while(scanf("%lf", &x) != EOF) { y = a * w1 + (1-a) * x; w1 = y; printf("%lf\n", y); } }

Problem 8.30

The mean of x(n) is mx = s = 5. The mean of y(n) is the same because it is preserved through the ﬁlter. Indeed, taking means of both sides of

y(n)= ay(n − 1)+(1 − a)x(n)

gives

Problem 8.31

my = amy + (1 − a)mx ⇒ m y = mx

The requirement that the high-frequency signal s(−1)n go through unchanged is that the ﬁlter have unity gain at ω = π or z = −1. This requires the value for the constant b:

The mean-square values may be determine recursively as follows: If we deﬁne

s2 = n

1

n−1

b (xk − mx )2

1 − az−1

z=−1

=

b

1+a

=1

⇒

b=1+a

n

k=0

176

177

. its values at DC and AC are: N Problem 8. 1. Thus. N − 1 1 0 π ω This gives hn = λ(−1)n . ∞ n≥0 H(π)= n=0 hn (−1)n = 1 which sums up to NRR = n=0 h2 = n n=0 A2 p2n + A∗2 p∗2n + 2AA∗ |p|2n where we used the fact ejπn = (−1)n . n = 0. . ∂hn n = 0. P8. and the AC constraint then ﬁxes λ to be: N−1 N−1 hn (−1)n = λ n=0 n=0 (−1)2n = λN = 1 ⇒ λ= 1 Fig. . Thus. N − 1 The Lagrange multiplier method is as follows. . n subject to n=0 hn (−1)n = 1 A∗2 2|A|2 A2 + + ∗2 2 1−p 1−p 1 − |p|2 This can be solved by Lagrange multipliers or more simply by deﬁning the quantities gn = hn (−1)n . This can be understood in the frequency domain by the Fig. 1 − az−1 h(n)= (1 + a)an u(n) N−1 N−1 NRR = n=0 g2 = min. hn = (−1)n gn = 1 N (−1)n .32 For an FIR ﬁlter of length N. The magnitude response is normalized to unity at high frequencies. |H(π)|2 = 1 where H(z)= A A∗ G = + 1 − p∗ z−1 (1 − pz−1 )(1 − p∗ z−1 ) 1 − pz−1 Problem 8. Introducing a Lagrange multiplier.4 to be gn = 1/N.a 2 J= output noise spectrum N−1 N−1 h 2 + 2λ 1 − n n=0 n=0 hn (−1)n The minimization condition with respect to the unknowns hn are: input noise spectrum ∂J = 2hn − 2λ(−1)n = 0.Thus the ﬁlter transfer function and impulse response will be: H(z)= The NRR is: 1+a . . n = 0. . . and replacing G2 by its normalized value G2 = (1 − R)2 1 − 2R cos(2ω0 )+R2 gives the desired expression for NRR after some tedious algebra. .33 Expand the transfer function into partial fractions: |H(0)|2 = 1+a 1−a 2 . and therefore it must be larger at low frequencies because it is a lowpass ﬁlter.16. that enforces the constraint. 1. . the problem reduces to the following minimization problem: n n Inserting p = Rejω0 . 1 . P8. the NRR must be minimized subject to this AC condition: N−1 N−1 NRR = NRR = n=0 h2 = min. . n subject to n=0 gn = 1 1+a h(n) = (1 + a) = NRR = 1 − a2 1−a n=0 2 2 ∞ 1 whose solution was found in Example 8. the solution of the highpass problem will be: Thus. its frequency response will be: N−1 A= G 1 − p∗ /p = Gp jGejω0 =− p − p∗ 2 sin ω0 H(ω)= n=0 hn e−jωn The corresponding impulse response and NRR will be then The condition that the gain is unity at AC is: N−1 ∞ hn = Apn + a∗ p∗n . 178 179 . say λ. the NRR is magniﬁed if 0 < a < 1. we modify the NRR to be minimized into the effective performance index: ( 1+a ( 1. Because g2 = h2 . Indeed. N− 1. . .16 Lowpass ﬁlter for extracting high-frequency signal.3. and A as given above.

18.9242.1.8541 = 0. hn = Bδn + Ap un + A p from which we can calculate the NRR: ∞ ∞ n ∗ ∗n un NRR = n=0 h2 = B 2 + n n=1 ∞ (Apn + A∗ p∗n )2 = B2 + n=1 A2 p2n + A∗2 p∗2n + 2|A|2 |p|2n + A∗2 p∗2 2|A|2 |p|2 + 1 − p∗2 1 − |p|2 G(1 − p2 ) p2 − |p|2 = B2 + The parameters B and A are: A 2 p2 1 − p2 B=− G .21 show the input signal.2.34 For the ﬁrst ﬁlter. we start with neff from which we may solve for R = (0.8833z−1 + 0.35 For Q = 6.36 The designed ﬁlter has the form: Its 1% time constant is neff = 146.93906z−2 Fig. H(z)= 0. P8.18 Filter outputs of Problem 8. (8. Figures P8.4. Then.96953 Problem 8.34. which gives the 5% time constant: neff = ln(0. ﬁlter responses.9901 where R is related to the 3-dB width by: R 2 = a 2 = 2b − 1 = 1 − tan(Δω/2) 1 + tan(Δω/2) which gives Δω = 0.0730(1 − z−2 ) 1 − 1.8541z−2 H(z)= Its pole radius is R = √ a2 = √ 0. and output signals. P8.2.17 Magnitude responses and noisy input of Problem 8.22) and (8. P8. 180 181 . the ﬁlter is identical to that of Example 8. the design equations give: H(z)= 0.80289z−1 + 0. the transfer function is designed using Eqs.85955z−1 + z−2 1 − 1. For Q = 60.7633z−1 + 0.05)1/neff = 0.19–P8.Problem 8.23): 1 − 1. For the second ﬁlter.17 and P8.8.35. we ﬁnd the transfer function: 0.0099(1 − z−2 ) 1 − 1.9802z−2 and NRR = 1/101.0064π. Problem 8.19 Noisy input and desired signal of Problem 8. |p|2 A=− Fig. The numerical value of NRR is NRR = 1/13.34. P8. The required graphs are shown in Figs.05) = 38 ln(R) Its NRR can be computed by carrying out a partial fraction expansion of the form: H(z)= B + which gives the impulse response: A 1 − pz−1 + A∗ 1 − p∗ z−1 Fig.3.

4 2931.984414 0.Fig.37 The following MATLAB m-ﬁle designs the 60 Hz notch ﬁlter.36. generates the noisy ECG and ﬁlters it.992207 0. and computes the ﬁlter’s magnitude response: 182 183 .36.36. Fig. P8.996088 0. for Q = 6 and Q = 60.980741 0.35. Problem 8.21 Filter outputs.8 Fig.961481 0.23 Filtered output y(n) when Q = 80.992177 0. Problem 8. P8. Problem 8. Fig. Problem 8. P8.01 for the 1% time constant. H(z)= b The time constant is computed as: 1 − z−D 1 − az−D neff = D where ln ln a = 0.998040 neff 1172.24 Filtered s(n) for Q = 80 and Q = 200.26.35. Problem 8.6 5863. The relevant graphs are shown in Figs. for Q = 6 and Q = 60.22–P8. P8. Fig.20 Magnitude responses.996081 b 0. P8.7 11727.22 Desired signal and noisy input. P8. The ﬁlter parameters are in the four cases: Q 80 200 400 800 a 0. Problem 8.

B = b * [1. A. P8. x0 = ecg(600). df = f0/Q. normalize it to 1. a = (1 . x = x/m. x = [x0. w = (0:499)*pi/500. 2*b-1]. yv = filter(B. h = abs((B(1) + B(2)*z + B(3)*z. dw = 2 * pi * df / fs. % add shifted square wave % and ﬁlter it yv=ﬁlter(B. w0 = 2 * pi * f0. w = (0:500)*pi/500. h = abs(b * (1 . x0]. xv). % noise baseline shift % noisy ECG 184 185 .25 Filtered s(n) for Q = 400 and Q = 800.n = 0:1499. B(2). 9. % replicate three beats x=[x0. x0. v0 = [1 1 1 1 1 -1 -1 -1 -1 -1]. x = sgfilt(0. x = x/m. f0 = 60. df = 0. % replicate three beats x=[x0.5 sec/beat => 500 samples/beat => 1000 samples/sec % f0=60. fs = 600. compute ﬁlter’s magnitude response. n = 0:1199.A. % numerator % denominator % ecgex1.x0. compute ﬁlter’s magnitude response. v0]. f0 = 60/1000.5 * v. v = v0.36. A = [1. x0]. xv = x + 0. generates the noisy ECG and ﬁlters it.5 * cos(w0 * n). x).xv) % ﬁnally. % % compute notch ﬁlter coefﬁcients % generate length-500 ecg by calling x0=ecg(500).x0] and smooth them with x=sgﬁlt(0. b = (1 + a) / 2. x).^10) . xv = x + 0. w0 = 2 * pi * f0 / fs. P8. x0 = ecg(500). m = max(x).26 Magnitude responses for Q = 80 and Q = 800.simulated ECG + 60Hz square-wave noise example % % assume 1 beats/sec => 1 sec/beat => 600 samples/beat => 600 samples/sec % % compute notch ﬁlter coefﬁcients % generate length-600 ecg by calling x0=ecg(600). A = [1 0 0 0 0 0 0 0 0 0 -a].^10)).^2) .m . z = exp(-i*w). m = max(x)./ (1 + A(2)*z + A(3)*z. and computes the ﬁlter’s magnitude response: Fig.38 The following MATLAB m-ﬁle designs the 60 Hz comb ﬁlter.A. 9. x). 5. yv = filter(B.z. 1].beta) / (1 + beta). x). end v = 2 + v./ (1 . x = sgfilt(0. xv).x0. x = [x0.simulated ECG + 60Hz noise example % % assume 2 beats/sec => 0. % ecgex2.xv) % ﬁnally. df=f0/Q. Problem 8. Problem 8.^2)).x0] and smooth them with x=sgﬁlt(0. dw = 2 * pi * df. v = [v. B = b * [1 0 0 0 0 0 0 0 0 0 -1]. b = 1 / (1+tan(dw/2)). for k=1:119.75. Q = 60. Problem 8. -2*cos(w0). normalize it to 1.m . Q=60. beta = tan(dw * 10 / 4). A. z = exp(-i*w).a * z.36. % one noise period % 120 noise periods % D=10 here Fig. % add 80 percent 60-Hz noise % and ﬁlter it yv=ﬁlter(B. 5.

sizeof(double)). a Thus. i++) s[i] = -1 + (i . "w"). A+B=b h = [b. y. for (i=D4. "%lf\n". . x). . } Problem 8. "%lf\n". the tangent has argument: ΔωD 4 = Δω 4 · π πΔω 2π = = ω1 2ω 1 2Q where we used ω1 = 2π/D. i<D4. cdelay(D.h> double gran(). i++) s[i] = i / D4. Ba3 . FILE *fpy.0. Ba. for (i=3*D4. .3*D4) / D4.39 Using partial fractions.triangular wave */ void triang(D. ] with the nonzero entries separated by D − 1 zeros. iseed = atol(argv[3]). { int i. constructs 40 periods of length-50 of the noisy triangular waveform. double *s. 0.Problem 8. dw = 0. i++) for (n=0. s) int D. fps = fopen("s. s[n]). 0. fprintf(fpy. . N = atoi(argv[2]). sizeof(double)). . one period of triangular wave triang(D. } D = atoi(argv[1]). 0. fpx = fopen("x. double D4 = D/4. . the impulse response is B=b 1+ 1 a . we expand puts("\nUsage: combex D N iseed"). *fpx. double *s. i<3*D4. a b period number of periods initial seed ﬁlter output noise-free input noisy input H(z)= b where B 1 + z−D =A+ = (A + B)+Baz−D + Bz2 z−2D + · · · 1 − az−D 1 − az−D b A=− . or D = 2π/ω1 ..tan(D*dw/4)) / (1 + tan(D*dw/4)). void cdelay(). double a. b. . .h> #include <math. . *fps. fpy = fopen("y. . } 186 187 .a) / 2. "%lf\n". &p). 1. n++) { x = s[n] + 0. The sum of the squares is ∞ ∞ = (1 . i<N. char **argv) { int n. y).40 The following program designs the comb ﬁlter. fprintf(fpx. D).0008 * pi. s). i++) s[i] = 1 + (D4 . sD = tap(D. i.*/ /* triang. tap(). *p. *w. s = (double *) calloc(D. D. .. i<D. w. . .IIR comb filter with noisy periodic input */ #include <stdio.h> #include <stdlib. exit(0). p. .dat". 0. void main(int argc. *p = b * x + a * sD. 0. for (i = 0. n<D.i) / D4. "w"). Ba2 . 0. double x. "w"). generate N periods for (i=0.dat". y = (*p) + sD.0). N.c . p = w. 0. } NRR = n=0 h2 = b 2 + B 2 n m=1 a 2m = b 2 + B 2 a 2 1 − a2 = = b2 (1 − a2 )+b2 a2 (1 + a−2 ) 2b2 (1 + a) 2(1 − a)2 (1 + a) = = 1 − a2 1 − a2 4(1 − a)(1 + a) 1−a 2 In the ﬁlter design parameter β = tan(ΔωD/4). 0. . pi=4*atan(1. sD. if (argc != 4) { /* -------------------------------------------------------. 0.5 * gran(0. w = (double *) calloc(D+1. &iseed).c . long iseed. = (1 . and ﬁlters them using the circular buffer implementation of the canonical realization of the ﬁlter: /* combex. fprintf(fps. triang(). w.dat".

c . the Nyquist frequency here is fs /2 = 2fsc = 7. we have half-order M = 8/2 = 4. cdelay(D. 188 189 .41. Fig.1. i++) if (scanf("%lf". *p. double tap().42 See Table P8.12lf\n". p. whereas the D-th tap output is the content of w[qD ]. so that the subcarrier frequency shown in the ﬁgure is only one-quarter of the Nyquist interval. N. D-i)). namely.43 The following is a complete C program for performing signal averaging. The frequency scale is in MHz and extends only up to about 4. k++) for (i=0. i<D. At each time instant. where the scaling by N is done afterwards. "x. "usage: sigav D N < x. 6 7 8 9 10 11 12 s0 s1 s2 − − − − Table P8. &x) != EOF) { /* keep reading input samples */ *p = tap(D. Fig.Problem 8. } D = atoi(argv[1]).signal averaging */ #include <stdio. This is efﬁcient in hardware implementations and for large values of D. we must verify: void main(int argc.dat must contain N periods of length D\n").27 Lowpass/bandpass and highpass/bandstop responses.1 Signal averager with circular delay for D = 3. N. i. w. D) + x / N.dat > y. w = (double *) calloc(D+1. exit(0). *w. The input data are taken from stdin and the averaged period is output to the stdout: /* sigav. The advantage of the circular implementation is that only one entry of w. Problem 8. N = 4. if (argc != 3) { fprintf(stderr. Problem 8. Note that the circular pointer p points to the buffer entry w[q].159 MHz. i<D.41 The complementarity properties may be veriﬁed for each pair. k. for ﬁlter 2.dat\n"). int D. For example. k<N. } else { fprintf(stderr. p. i++) printf("%.27 shows the frequency responses in the four cases. for (k=0. P8. n 0 1 2 3 4 5 x s0 s1 s2 s0 s1 s2 s0 s1 s2 s0 s1 s2 − qD 3 2 1 0 3 2 1 0 3 2 1 0 q 0 3 2 1 0 3 2 1 0 3 2 1 w0 s0 s0 s0 s0 2s1 2s1 2s1 2s1 3s2 3s2 3s2 3s2 w1 0 0 0 2s0 2s0 2s0 2s0 3s1 3s1 3s1 3s1 4s2 4s2 w2 0 0 w3 0 y = w q /4 s0 /4 s1 /4 s2 /4 2s0 /4 2s1 /4 2s2 /4 3s0 /4 3s1 /4 3s2 /4 s2 s2 s2 s2 3s 0 3s 0 3s 0 3s 0 4s 1 4s 1 4s 1 s1 s1 s1 s1 2s 2 2s 2 2s 2 2s 2 4s 0 4s 0 4s 0 4s 0 Problem 8. char **argv) { double x. w[q]. } for (i=0. w. } HLP (z)+HBP (z)= 1 1 (1 + z−2 )2 (−1 + 6z−2 − z−4 )+ (1 − z−2 )4 = z−4 16 16 which follows by expanding out the terms. For reference. tap(D. N = atoi(argv[2]).1 shows the results. p = w. The inputs to the program are the period D and the number N of periods to be averaged. Thus. the content of w[q] is updated by w[q]= w[qD ]+x. exit(0). w. Table P8. D).5 MHz.h> #include <stdlib. P8. "Input must have %d periods of length %d\n".h> void cdelay(). sizeof(double)). fprintf(stderr. is changed at each time instant. &p).

n++) { x = s[n] + gran(0.dat and s. i<N. "%lf\n". i++) for (n=0. it writes out the contents of the delay line in reverse order. &p). N=11. w. tap(D. long iseed. char **argv) { int n.signal averaging example */ #include <stdio. "%. n<D. w = (double *) calloc(D+1. "w"). void main(int argc. 1).dat will contain the averaged periods and the noise-free period: /* sigavex. n++) { accumulate N periods each of length D noisy input D-th tap of averager accumulate x update delay line save input sample period number of periods noise seed fprintf(fps. s[n]).. write averaged period 190 191 . tap().12lf\n". y2). x = sgfilt(0. After processing the ND input samples. } D = atoi(argv[1]). rand(’seed’. p.h> #include <stdlib. *fpy. 15. y1 = sgfilt(d.SG filtering of noisy ECG L=500. n<D. 10033). s = (double *) calloc(D. The following ﬁgures should be compared with the single-pass cases of Figs. for (i=0. fpy = fopen("y. exit(0). D). *p = sD + x. fprintf(fpy. x0 = ecg(L)’. N.Problem 8.12lf\n".c .3.28 Double SG ﬁltering.dat". D.34. N. x0). if (argc != 4) { puts("\nUsage: sigavex D N iseed"). 41 and d = 0. w. xv = x + v. x). cdelay(D. D-n)/N). &iseed). FILE *fpx. iseed = atol(argv[3]). y2 = sgfilt(d.dat". sizeof(double)). fpx = fopen("x. double sD. w. v = 0. 8. "w"). N = 11.33 and 8. double *s. so that the ﬁles y. i<D. } for (n=0. "%.m . x = x/mx. x. mx = max(x). p. p = w. *p. for (i=0.dat".. fprintf(fpx.h> double gran(). rand(’normal’).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: % sgecgex. and averages these periods using the circular buffer form of the averager. sizeof(double)).3. xv). *fps. } } Problem 8. N. N = atoi(argv[2]). "w"). P8.h> #include <math. void cdelay(). 1. sD = tap(D. Fig.3 * rand(L. i++) if (i < D/2) s[i] = 1. fps = fopen("s. *w. i. else s[i] = -1.44 The following program generates N periods of length D of the noisy signal. d=2. % generate ECG % unity max % generate noise % generate noisy ECG % ﬁrst pass through SG % second pass The ﬁltering twice through the SG ﬁlter improves the smoothing operation but introduces longer transients in the ﬁlters.

The frequency spacing is Δf = fs /N = 8000/256 = 31. And if the FFT is used. 41 and d = 4.2 Fig. we shift the negative index by one period N to get the positive index: −k → N − k = 64 − 8 = 56 Thus.1 Use the formula TR = LT = L/fs to solve for L = fs TR . where f = 10 kHz. N = 11. · · · . N log2 N/2 = 256 · 8/2 = 1024. the total signal length will be N = kD = k fs f which gives for k = 16. Problem 9. We will also get a peak at the negative index −k. N = 16 · 8 = 128 samples. or in words no. 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. Its spectrum will have peaks at ±f . If we perform an N-point DFT. then the number of multiplications would be N · N = 256 · 256 = 65536. we would require L · N = 1024 · 256 = 262144 multiplications. If the signal is reduced mod-256. where M = L/N = 1024/256 = 4 is the number of segments. that is. The cost of performing the mod-256 reduction is N(M − 1)= 256 · 3 = 768 additions. the k-th DFT frequency will coincide with f . of seconds) Thus. of samples = (no. This cost may be added to the costs of FFT or reduced DFT. Fig. The sinusoidal signal is something like x(t)= cos(2πf t). In summary. fk = k fs =f N Thus.29 Double SG ﬁltering. If the DFT is done directly. the second peak will be at k = 56. 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.25 Hz.3 The number of samples in one period is given by: D= 40 fs = = 8 samples f 5 Therefore. then because of the choice of N. if k periods are collected . which translates mod-N to N − k. N = 11. N − 1. P8.30 Double SG ﬁltering. 41 and d = 2. L = 8 kHz × 128 msec = 1024 samples. 1. we expect to see a peak at the kth DFT bin. we expect to see peaks at the DFT indices: k = 16 and N − k = 128 − 16 = 112 192 193 . we expect to see a peak at k = 8 and another one at k = −8. of samples per second) x (no.Chapter 9 Problems Problem 9. Problem 9. P8.

0.2 * pi / N. use L = 10.Problem 9. which replaces the C functions dtft. X = abs(fft(x.c . Problem 9. z = exp(-j*w).4 The expected DFT index will be at 18 f k = N = 16 · = 36 fs 8 Because k is greater than N − 1 = 15. N ≥ L = 400.8 The following C program generates the length-L time signal and computes its N-point DFT.h> #include <cmplx.N)). f3 = 0.46 * cos(2*pi*n/(L-1)). for n = L-1:-1:0.2. Problem 9. /ascii. N = 200. xrec = cos(w0 * n). one could use fft. the FFT length must be at least L. or.54 . /ascii. the width of the main lobe of the data window must be equal or smaller than the width of the peak. w0 = 0. save save save save xrec. Instead of the DFT routine dft. i. xham = w.dat xrec xham Xrec Xham /ascii. The 32-point DFT is extracted by keeping one out of every 256/32 = 8 points of the 256-point DFT. it may be reduced mod-N down to: where % dtft. 100 and N = 256.* xrec.6 The following MATLAB function generates the time data and computes the required DTFTs with the help of the function dtft. /* dtftex. /ascii. in our case.e. n = 0:(L-1).5 To be able to resolve a peak. w)). wh = 0.dat frec. N=256. % % x = row vector of time samples % w = row vector of frequencies in rads/sample % X = row vector of DTFT values % % based on and replaces both dtft.1*pi..c and dtftr. f1 = 0.dat fham. Xham = abs(dtft(xham. 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. X = x(n+1) + z . For the other cases. computational resolution example */ #include <stdio.m . indeed. n = 0:(L-1). with L = 10. xham = wh .rectangular/hamming windowed sinsuoids L = 200.7 The following MATLAB function generates the time data and computes the required DTFTs: % sinexp. % windowed data % DTFT of rectangular data % DTFT of Hamming data 194 195 . Xrec = abs(dtft(xrec. included below. This gives the condition X = 0. The next power of two is N = 512.25. end fs ≤ Δf L ⇒ L≥ fs Δf Problem 9.m.m . f2 = 0.3.c. w = (0:N-1) * 0. 20. [L1.DTFT of a signal at a frequency vector w % % X = dtft(x.h> void dtftr(). w).* X.physical vs.c and dtftr. w = 0.dat xham.c. w)). L] = size(x).c k = 36 − 2 × 16 = 4 It corresponds to the DFT frequency fk = kfs /N = 4 · 8/16 = 2 kHz. Xham = abs(fft(xham. 40. w) falias = f mod fs = 18 mod 8 = 18 − 2 × 8 = 2 kHz The −2 kHz or −18 kHz component will be represented by the DFT index N − k = 16 − 4 = 12. L ≥ 8000/20 = 400 samples.N)).c: % dtftexp.0. 100. We must pad 112 zeros to the end of the length-400 signal before the FFT is taken.54 .3 sinusoids of length L=10 L=10.*x.m . This is frequency within the Nyquist interval that is aliased with f = 18 kHz. we have function X = dtft(x.46 * cos(2*pi*n/(L-1)).h> #include <stdlib. % frequency range % Hamming window Problem 9. x = cos(2*pi*f1*n) + cos(2*pi*f2*n) + cos(2*pi*f3*n).

f2 = 0. 30 kB = 39. Its 4-point DFT is X(0) ⎢ X(1) ⎢ X=⎢ ⎣ X(2) X(3) ⎡ ⎤ ⎡ ⎥ ⎢ 1 ⎥ ⎢ ⎥=⎢ ⎦ ⎣ 1 1 1 1 −j −1 j 1 −1 1 −1 j ⎥⎢ 3 ⎥ ⎢ 0 ⎥ ⎥ ⎢ ⎥ ⎥⎢ ⎥=⎢ ⎥ ⎥⎢ −1 ⎦ ⎣ 3 ⎦ ⎣ 0 ⎦ −j 3 0 1 ⎤⎡ 3 ⎤ ⎡ 12 ⎤ For the IDFT we use the formula IDFT(X)= [DFT(X∗ )]∗ /N: 196 197 . 30.9 See Example 9. fpdtft= fopen("dtft. Problem 9.2. x = (double *) calloc(L.2. k. both for the rectangular and Hamming windows.10 Using the relationship k = Nf /f s.1 kB = 38. pi = 4 * atan(1. } N-point DFT Problem 9. sizeof(complex)). &L. f3 = 0.2 Spectra of DTMF sinusoids. for (k=0.30. N. 47 X(0) ⎢ X(1) ⎢ ⎢ X= ⎣ X(2) X(3) ⎡ ⎤ ⎡ ⎥ ⎢ 1 ⎥ ⎢ ⎥=⎢ ⎦ ⎣ 1 1 1 1 1 −1 1 −1 1 1 1 1 1 1 1 −1 1 −1 1 ⎡ ⎢ ⎢ ⎤⎢ ⎢ ⎢ ⎥⎢ ⎥⎢ ⎥⎢ ⎦⎢ ⎢ ⎢ ⎢ ⎢ ⎣ Because each keypress generates one tone from group A and one from group B. 27. X). n++) x[n] = cos(2*pi*f1*n) + cos(2*pi*f2*n) + cos(2*pi*f3*n). for (n=0.3 Problem 9.12 Acting on x by the 4×8 DFT matrix. X = (complex *) calloc(N. 43. P9. 3.7. 3]. printf("enter L. DTFT ﬁle Fig. 25. N − kA and N − kB . P9. double f1 = 0. 27.20.11 The time signal and its DTFT are shown in Figs. we calculate the group-A and group-B DFT indices: group A group B and their rounded versions: group A: group B: Fig. double *x. "w").) −j −1 j j −1 −j −j −1 j j −1 −j 1 2 2 1 2 1 1 2 ⎤ ⎥ ⎥ ⎥ ⎡ ⎥ ⎥ ⎥ ⎢ ⎥ ⎢ ⎥=⎢ ⎥ ⎣ ⎥ ⎥ ⎥ ⎥ ⎦ 12 0 0 0 ⎤ ⎥ ⎥ ⎥ ⎦ Problem 9.main() { int L. 24. n<L.1 and P9.3. "%lf\n". 42.1 Rectangularly and Hamming windowed DTMF sinusoids. &N). that is. kA = 22. 47.8.3. the DTFT will have peaks at the corresponding pair of DFT indices (and their negatives.25. cabs(X[k])). FILE *fpdtft.1.6.dat". n. N. N: "). P9. we obtain: kA = 22. scanf("%d %d". sizeof(double)). complex *X. 3. k<N.0). k++) fprintf(fpdtft. x. dft(L. ˜ The mod-4 wrapped version of x is x = [3.

in groups of N operations at a time so that they can be implemented by the DSP hardware. Then.Problem 9. The IFFT is obtained by conjugating X. The required FFT of X∗ is: The four N-dimensional vectors are then shipped over to the FFT processor. 198 199 . 7 . and their FFTs are returned into four N-dimensional DFT vectors. 4. . 8 4 2π 2 π ω2 = = . 3 . computing its FFT. . . 1. P9. 8 2 2π 3 3π ω3 = = 8 4 It is easily veriﬁed that the costs of the two methods are the same. 2N − 1.13 The 8-point FFT is: shuffling ⎡ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ x=⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎣ 5 −1 −3 −1 5 −1 −3 −1 DFT merging N-FFT ⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎦ ⎡ 8−FFT − → ⎢ 0 ⎥ ⎥ ⎢ ⎥ ⎢ ⎢ 16 ⎥ ⎥ ⎢ ⎢ 0 ⎥ ⎥ ⎢ ⎥ X=⎢ ⎢ 8 ⎥ ⎥ ⎢ ⎢ 0 ⎥ ⎥ ⎢ ⎥ ⎢ ⎣ 16 ⎦ 0 0 ⎤ N 2N N 4N N 2N N N-FFT N-FFT N-FFT N 2N N W2N 4N N k 2N W4N k N W2N k It follows that the FFT spectrum will show peaks at the frequencies: X(ω2 )= X(ω6 )∗ = X(−ω2 )∗ = 16. The butterﬂy operations can be done is small parts. respectively. one at a time. . 6 .14 Fig. We used the values of the DFT frequencies: 2π π ω1 = = . The ﬁrst merging stage require mulk tiplication by the twiddle factors W2N . Problem 9. The total cost is the cost of four N-point FFTs. . N − 1. The second stage uses the factors k W4N . 1. . X(ω4 )= 8 Problem 9. ω5 are the negatives (modulo-2π) of ω1 . and a (4N)-fold multiplication for the second stage: 1 cost = 4 N log2 N + 2N + 2N = 2N log2 N + 4N 2 If the (4N)-point FFT could be done in one pass. ω3 . 4. each of the (2N)-dimensional vectors is shufﬂed again into two N-dimensional subvectors. k = 0. 1. . . we express x(n) as a sum of sinusoids: x(n) = 1 8 7 X(k)ejωk n = k=0 1 4ejω1 n − 4jejω2 n + 4ejω3 n + 4ejω5 n + 4jejω6 n + 4ejω7 n 8 1 jω2 n 1 1 1 −jω2 n 1 1 = ejω1 n + e e + ejω3 n + e−jω3 n − + e−jω1 n 2j 2 2 2j 2 2 = cos(ω1 n)+ sin(ω2 n)+ cos(ω3 n)= cos(πn/4)+ sin(πn/2)+ cos(3πn/4) which agrees with the above IFFT values at n = 0. k = 0. .3 Performing large FFTs. ω6 . 6 . we would have cost: cost = 1 (4N)log2 (4N)= 2N log2 (4N) 2 ⎡ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ∗ X =⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎣ 0 4 4j 4 0 4 − 4j 4 ⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎦ ⎡ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎣ 8−FFT − → 16 8 0 −8 −16 8 0 −8 ⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎦ ⎡ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ x=⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎣ ⇒ 2 1 0 −1 −2 1 0 −1 ⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎦ Using the inverse DFT formula.16 The ordinary convolution is y = h ∗ x = [ 1 . . 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. The (4N)-dimensional time data vector is shufﬂed once into two (2N)-dimensional subvectors by putting every other one of its entries on top and the remaining entries on the bottom. . 7. .3 shows the procedure.15 x(0) ⎢ x(1) ⎢ x=⎢ ⎣ x(2) x(3) ⎡ ⎤ ⎡ ⎥ 1 ⎢ 1 ⎢ ⎥ ⎢ ⎥= ⎦ 4 ⎣ 1 1 1 1 1 −j −1 j −1 1 −1 j ⎥⎢ 0 ⎥ ⎢ 3 ⎥ ⎥ ⎢ ⎥ ⎥⎢ ⎥=⎢ ⎥ ⎥⎢ −1 ⎦ ⎣ 0 ⎦ ⎣ 3 ⎦ −j 0 3 1 ⎤⎡ 12 ⎤ ⎡ 3 ⎤ Figure P9. These are then merged ﬁrst into (2N)-point DFTs and then into the desired (4N)-point DFT. 3 . and dividing by 8. for example. the cost of two N-fold multiplications for the ﬁrst merging stage. ω2 . Problem 9. 1 ] The DFT frequencies ω7 .

we have: L−1 L−1 XpN (pk)= X(k)ejωk n 1 = 8ejω0 n − 16jejω2 n + 24ejω4 n + 16jejω6 n 8 n=0 x(n)WpN = n=0 pkn kn x(n)WN = XN (k) k=0 Problem 9. 200 201 . ﬁnally. 5. . ω0 = 0. 3. Problem 9. 2 − b. . b] It should be evident that. 1. a. ˜ x = [2. The alternative method is to reduce ﬁrst x and h mod-4: ˜ h = [2.20 For a general power p. 5. Problem 9. 7. 1].18 Consider the length-7 signal [1 − a. X8 (k)= X16 (2k).19 Using the ﬁnite geometric series and the deﬁnition WN = e−2πj/N . compute their ordinary convolution: ˜ ˜ h ∗ x = [4. ω4 = π. If k = 0. 6. · · · . we would get unity as an answer (and zero otherwise). reduce that modulo 4 to get y = [9. 1. 2. ˜ and. namely. . we have a ratio of 0/0. 1. Note. 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. gives 1 N−1 kn WN = n=0 Nk 1 1 − WN 1 1 − e−2πjk = k N 1 − WN N 1 − e−2πjk/N Problem 9. 6. that these arguments break down if k is allowed to go beyond the range 0 ≤ k ≤ N − 1. and unity if k = 0. Thus.17 Carrying out the 8-point FFT gives: ⎡ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ x=⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎣ 4 2 4 −6 4 2 4 −6 ⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎦ ⎡ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ X=⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎣ 8−FFT − → 8 0 −16j 0 24 0 16j 0 ⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎦ N If k = 0. but in this case. for n = 0. . 8. because whenever it is a multiple of N. taking every other entry of that gives the 2-point FFT: X= 8 24 X(ω)= n=0 x(n)e−jωn L−1 Can we get these results directly? Yes. 3. 3 . Problem 9.20 by setting N = 8 and p = 2. the numerator vanishes but not the denominator. 1. Taking every other entry of the result gives the 4-point FFT. In conclusion. 9]. To do the 4-point FFT. then. k = 0. for any values of the parameters a and b. and using Euler’s formula we obtain: πn x(n)= 1 + 4 sin( )+3 cos(πn) 2 which agrees with the given x. 2]. 9. in this case the answer is zero. 4. its mod-5 reduction is [ 1.˜ Reducing this mod-4 gives: y = [9. 9. 9. 4 . which implies: Noting that for an 8-point FFT. 8. ω2 = π/2. and ω6 = 3π/2 ≡ −π/2. 5 ] .21 This follows from the results of Problem 9. All of the N terms in the sum become unity. 9]. giving N/N = 1. ﬁrst reduce the signal modulo 4 to get ⎤ ⎡ ⎡ ⎤ 8 8 ⎥ ⎢ ⎢ −16j ⎥ 4 ⎥ 4−FFT ⎢ ⎢ ⎥ ⎥ ⎥ ˜ − → X=⎢ x=⎢ ⎣ ⎣ 24 ⎦ 8 ⎦ −12 16j Putting the above 8-point FFT into the 8-point inverse FFT formula gives 1 x(n)= 8 7 XN (k)= n=0 L−1 kn x(n)WN XpN (k)= n=0 kn x(n)WpN Replacing k by pk in the third and using part (a). 1. 2 . we can just go back to the series deﬁnition and set k = 0. the answer is zero if k = 0. 2]. we have: p ⎡ ⎢ ⎢ X=⎢ ⎣ 8 −16j 24 16j ⎤ ⎥ ⎥ ⎥ ⎦ WpN = e−2πj/(pN) p = e−2πj/N = WN The DTFT of a length-L signal and its N-point and (pN)-point DFTs are: L−1 And.

e. Their aliased versions that lie inside the Nyquist interval [−4. gives the 16-point DFT. replaced −πn/8 by 2πn − πn/8 = 15πn/8. It so happens that the zeros of the sidelobes of the W(ω − ωi ) coincide with 16-point DFT frequencies. X(4)= 8. X(30)= 32 Comparing with the 8-point IDFT. ω4 = 2π4/16 = π/2. π/8 = 2π/16 = ω1 . 8j. 1 . 0. . 0. 0.25 Arguing in a similar fashion. and 2 kHz.22 Using a trig identity to write the product of sines as a sum of sines. The spectral peaks at the signal frequencies are evident. 0. .5ejω8 n (P9. . we ﬁnd the (non-zero) values of the 32-point DFT: x(n)= ejπn − jejπn/2 + je−jπn/2 = 1 −8jejω2 n + 8ejω4 n + 8jejω6 n 8 X(2)= 32. Using Euler’s formula. P9. 0. 16. X(24)= 16. 1. 1 . we get: Problem 9. X(12)= 8. we shifted the negative frequency exponents by adding 2πn to them. X(8)= 16.. 4] kHz are. 0. 8. 202 203 . The DTFT of each complex sinusoid is given by the shifted spectrum of the rectangular window W(ω) of length-16: = 1 − jejπn/4 + je−jπn/4 + jejπn/2 − je−jπn/2 − jej3πn/4 + je−j3πn/4 + 3ejπn = 1 8ejω0 n − 8jejω1 n + 8jejω2 n − 8jejω3 n + 24ejω4 n + 8jejω5 n − 8jejω6 n + 8jejω7 n 8 where X(ω)= 0. setting ω4 = π. Now. 0. − → X = [0. 0. 10. we write: x(n)= 0. 16] The same DFT values can be determined without any computation by comparing x(n) with the inverse DFT. we get the time samples: x(n)= 1 16 15 X(k)ejωk n k=0 x(n)= cos(πn)+2 sin(πn/2) Evaluating it at n = 0. ω6 = −(π/2)mod(2π). −3 ] 8−FFT and noting that π/2 = 8π/16 = ω4 . −8j.24 Using Euler’s formula.23 Using Euler’s formula. 1 . X(15)= 16. Comparing with the IDFT formula. Thus.5eπjn/2 + 0. The peak values are correctly identiﬁed by the 16. 24. ω2 = π/2.Problem 9. comparing with the 16-point IDFT formula x(t)= cos(8πt)+ sin(4πt)+ sin(4πt)= cos(8πt)+2 sin(4πt) Setting t = nT = n/8. 0. Taking every other 16-DFT point gives the 8-point DFT. and multiplying and dividing by 8. −8j. and 15π/8 = 30π/16 = ω15 . respectively. 8j] W(ω)= sin(8ω) −15jω/2 1 − e−16jω e = 1 − e−jω sin(ω/2) The magnitude spectrum |X(ω)| is plotted versus 0 ≤ ω ≤ 2π in Fig. 8j. or. and 2 kHz. we write x(n) = 0. −8j. −3 . ω12 = −ω4 mod(2π). 7 gives the values. Dividing the Nyquist interval into 16 equal bins.26 Write x(n) in its complex sinusoidal form: Problem 9. 1 . we get: X = [8.g. 0. . 0] X = [0. 8.5W(ω − ω8 ) where we reordered the terms according to increasing DFT index. −8j. 3π/2 = 24π/16 = ω12 . 2. we may identify the (non-zero) values of X(k) as follows: X(1)= 16. gives the above DFT vector: x(n)= 1 8 7 X(k)ejωk n k=0 Problem 9. and their FFT: x = [ 1 .and 8-point DFTs because the peak frequencies coincide with DFT frequencies. ω8 = 2π8/16 = π are the signal frequencies expressed as 16-point DFT frequencies. 0. 8. we get the equivalent expression: Problem 9. 8j. 0.5ejω0 n − jejω4 n + jωjω12 n + 1.5W(ω)−jW(ω − ω4 )+jW(ω − ω12 )+1.1) x(n) = 1 + 2 sin( πn 4 )−2 sin( πn 2 )+2 sin( 3πn )+3(−1)n 4 where ω0 = 0. 4. 0.5e−πjn/2 + eπjn/8 + e−πjn/8 = 1 8eπjn/2 + 8e3πjn/2 + 16eπjn/8 + 16e15πjn/8 16 x(t)= cos(24πt)+2 sin(12πt)cos(8πt)= cos(24πt)+ sin(20πt)+ sin(4πt) The frequencies of the three terms are 12. 0. the aliased signal that would be reconstructed by an ideal reconstructor will be: where. 1 .4.

−2. −3] Problem 9. 1. − 1. − 2 . Problem 9. 0. 1. −2]. −1. 0. −16j. −16j. Thus. compute the FFTs of the two signals: First.27 We will show that the product AA is proportional to the identity matrix. 0.30 The 16-point DFT can be determined from the expression of x(n) by comparing it with 16-point IDFT formula. 8 . the desired equation reads x† x = 1 10 0 2 0 2 0 2 0 ⎤ ⎡ ⎥ ⎢ 0 ⎥ ⎢ 0 ⎥ ⎥ ⎢ ⎥ ⎢ ⎥ ⎥ ⎢ ⎥ ⎢ ⎥ ⎥ ⎢ −8j ⎥ ⎢ −16j ⎥ ⎥ ⎢ ⎥ ⎢ ⎥ ⎥ ⎢ ⎥ ⎢ 0 ⎥ ⎢ 0 ⎥ ⎥ ⎢ ⎥ ⎥×⎢ ⎥=⎢ ⎥ ⎥ ⎢ 12 ⎥ ⎢ 24 ⎥ ⎥ ⎢ ⎥ ⎢ ⎥ ⎥ ⎢ ⎥ ⎢ 0 ⎥ ⎢ 0 ⎥ ⎥ ⎢ ⎥ ⎥ ⎢ ⎥ ⎢ ⎥ ⎦ ⎣ 8j ⎦ ⎣ 16j ⎦ 0 0 4 40 ⎤ Divide by N = 8. − 2. we note that the above sum will be zero if i = j. we may extract the DFT coefﬁcients: X = [8. Multiplying and dividing Eq. the mod-6 reduction is y = [4. 0. 2. −2. conjugate every entry. 16j. 1. 1. 8. −1. 7. 0. 7. 24. − 2. 0] Every other entry is the 8-point DFT: X = [8. P9. 0.19. 2. 0. it will be equal to N if i = j. 1]∗[2. −2.28 Vectorially. strictly speaking y is y with one zero padded at the end.|X(ω)| = DTFT 24 16 8 = 16-point DFT = 8-point DFT Problem 9. 24. The mod-5 reduction is y = [1. 2. the length should be N = 8. 4. −1. −1. −2. Problem 9. 1. 0. Finally. 0. 0. 0. −1]. 1. The minimal N is N = Ly = Lx + Lh − 1 = 4 + 4 − 1 = 7. 1. −2. 2. that is. 8 . − 2 ] Then. And.29 First.4 DTFT. 0 π 2π ω Fig. The ij-th matrix element of the product is: N−1 N−1 ∗ ⎡ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎣ (AA∗ )ij = n=0 Ain A∗ = nj n=0 in WN WN −jn N−1 = n=0 WN (i−j)n ∗ − where we used the fact that WN = WN1 . 2 ] The mod-4 reduction of this is y = [0. (P9. −3. 0. 2. we can write compactly: N−1 2 1 1 1 2 1 1 1 ⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎦ ⎡ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎣ 8−FFT − → 10 0 2 0 2 0 2 0 ⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥.1) by 16. −1. 2. 16j. 0. −2. 1. 0] and wrap it mod-8 to get ˜ y = [ 8. Using the results of Problem 9. One minor detail is that in the mod-8 case. 2 . 16-point and 8-point DFTs. 2]. −3] = [4. 4. we obtain (IN = N × N identity matrix) ⎢ 0 ⎢ ⎢ ⎢ 2j ⎢ ⎢ 0 ⎢ ⎢ ⎢ 3 ⎢ ⎢ 0 ⎢ ⎢ ⎣ − 2j 0 5 ⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎦ ⎡ 8−FFT − → X† X = x† A† Ax = x† NIN x = Nx† x ⎢ 6 ⎥ ⎥ ⎢ ⎥ ⎢ ⎢ 8 ⎥ ⎥ ⎢ ⎢ −2 ⎥ ⎥ ⎢ ⎥ ⎢ ⎢ 8 ⎥ ⎥ ⎢ ⎢ 6 ⎥ ⎥ ⎢ ⎥ ⎢ ⎣ 8 ⎦ −2 8 ⎤ 204 205 . 2. 0]. − 1 . 2. 11. compute the ordinary linear convolution: y = h ∗ x = [ 2 . Using X = Ax and the property AA† = A† A = NIN . of the N × N DFT matrix. ⎥ ⎥ ⎥ ⎥ ⎥ ⎦ ⎡ ⎢ 1 ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ 2 ⎥ ⎢ ⎥ ⎢ −3 ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ 2 ⎥ ⎢ ⎥ ⎢ 1 ⎥ ⎢ ⎥ ⎢ ⎥ ⎣ 2 ⎦ −3 ⎤ ⎡ 2 ⎤ ⎡ 8−FFT − → ⎢ 0 ⎥ ⎥ ⎢ ⎥ ⎢ ⎢ − 8j ⎥ ⎥ ⎢ ⎢ 0 ⎥ ⎥ ⎢ ⎥ ⎢ ⎢ 12 ⎥ ⎥ ⎢ ⎢ 0 ⎥ ⎥ ⎢ ⎥ ⎢ ⎣ 8j ⎦ 0 4 ⎤ (AA∗ )ij = n=0 WN (i−j)n Multiply them point-wise: = Nδ(i − j) ⎡ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎢ ⎣ which is equivalent to the matrix relationship AA∗ = NI where I is the N × N identity matrix. 1. 0. the mod-7 and mod-8 reductions of y leave it unchanged. −1. 6 . −2. and take an 8-point FFT: ⎡ X† X N where † denotes conjugate transpose. 2. 6 . compute the linear convolution of the given signals: y = h ∗ x = [2. 0. y = [2. 0. thus. 8 .

Nhalf=N/2. 0 .h> void fft(). b] Problem 9. A(N − k)∗ = A(k) and B(N − k)∗ = B(k). (that is. 65% of the standard cost for N = 1024. 0] X(k)= A(k)+jB(k) ⇒ X(N − k)∗ = A(N − k)∗ −jB(N − k)∗ N X(k)ejωk n . 0. The ﬁnal expressions that construct X(k) are the standard Butterﬂy operations for merging G(k) and H(k). 6 . 12.33 Using linearity.h> #include <stdlib. 1. the divisions by 2 k and 2j. 8. 2. except that the dimension of the FFTs is N/2. x = [6 − a. 8. 12]. { int n.c . kn ∗ WN a(n) /* fftreal.5 2 2 2 1 2 log2 N N log2 N 2 If one takes into account the multiplications required for computing the Wk powers. 0 . then the total becomes ˜ d. 1 ] b.5 N log2 N 2 log2 N N N−1 A(N − k)= n=0 −kn WN a(n) Typically.31 a. The 8-FFT algorithm gives x = [ 6 . 1 . k=0 Using the results of Problem 9. Reduce x mod-4 to get x = [12.35 kn WN n=0 ∗ A(k)∗ = But. 1. Using x(n)= 1 N−1 Problem 9. 0. 0. x. a. because a(n) is real N−1 Problem 9. On the other hand. it can be written as WN (N−k)n a(n) N 2 log2 ( 4N )+ 2 2 = 1 + 1 . The additional multiplications to build X(k) from Y(k) are 3N/2. Thus the total number of multiplications using this method compared to a direct N-point FFT will be 3N N 1N log2 ( )+ 2 = 1 + 2. 1. 1. we obtain X(N − k)∗ = A(k)−jB(k). 1.32 Start with N−1 A(k)= n=0 kn WN a(n) and evaluate it at N − k N−1 A(N − k)= n=0 N Noting that WN = 1. 6. we have ⇒ X = [16. 1. complex *X. Its 4-FFT is easily found to be X = [16. 0. 0.34 The expressions for G(k) and H(k) follow from the results of Problem 9. 12. 2]. 6. 0. c.33. double pi=4*atan(1.FFT of a real-valued signal */ #include <math. double *x. Problem 9.Problem 9. time data FFT array 206 207 . 1. = −kn WN Thus. Thus.h> #include <cmplx. X) int N. a]. A(N − k)= A(k)∗ void fftreal(N. 0.32. With arbitrary values of a and b: x = [6 − a.0). It can also be obtained by picking every other entry of the 8-point DFT. k. 12. we have the system of equations: x(n)= πn 1 16 + 12ejπn/2 + 8ejπn + 12e−jπn/2 = 2 + 3 cos + (−1)n 8 2 X(k) = A(k)+jB(k) X(N − k)∗ = A(k)−jB(k) which can be solved for A(k) and B(k). 1 . 1 − b. 0. 1. and multiplications by WN ).

Y = (complex *) calloc(Nhalf. complex *Y. Wk. 0]+[0. x[2*n+1]). . 0. .36. -2*pi/N)). Y). temp)). .5). 2N − 1 The operation of delay on the reﬂected signal then gives: At k = N. Replacing Yk in terms of Ck gives for n = 0. x2 . using linear superposition.0). we used X(z−1 )= X(−ωk )= X(−k)= X(N − k) by the periodicity of the k N-point DFT. temp). x2 . else temp = conjg(Y[Nhalf-k]). . for (n=0. Hk). . we have: Y2N−k = 2ejπ(2N−k)/2N C2N−k = 2ejπ e−jπk/2N C2N−k = −2e−jπk/2N C2N−k XR (z)= z−3 [x3 z3 + x2 z2 + x1 z + x0 ]= z−3 X(z−1 ) ∗ Yk = 2e−jπk/2N Ck In the time domain. it gives C2N−N = −CN or CN = −CN which implies CN = 0. one = cmplx(1. the reversed signal xR is delayed by N samples. . temp). we ﬁnd: yn = 1 2N 2N−1 Yk ejωk n . we have x = [x. . . halfj. x1 . k<Nhalf. 0.0). W. 0. . we have: Z xR (n)= x(N − 1 − n)= x(−(n − N + 1))− z−(N−1) X(z−1 ) → −k The N-point DFT of the reversed signal is obtained by setting z = zk = e2πjk/N = WN . Using N the property WN = 1. we have in the z-domain: Y(z)= X(z)+z−N XR (z)= X(z)+z−2N+1 X(z−1 ) where the factor z−N represents the delay of xR by N samples. X[k+Nhalf] = csub(Gk.0. In terms of Ck . that is.5. W = cexp(cmplx(0. for (Wk=one. its real part is the cosine transform: N−1 Re e−jωk /2 X(ωk ) = n=0 xn cos ωk (n + 1/2) = Ck Problem 9.0. Replacing z by zk = ejωk . k=0. and the results of Problem 9. the operation of reﬂection leads to the z-transform pairs: Equating the right-hand sides and canceling the common factors gives the symmetry property x(n)− X(z) → Z ⇒ → x(−n)− X(z−1 ) Z C2N−k = −Ck . x0 ] It follows that −1 −2 −3 It follows that Yk = 2ejωk /2 Ck = 2ejπk/2N Ck + x2 z + x3 z −2 ⇒ ⇒ X(z)= x0 + x1 z XR (z)= x3 + x2 z −1 + x1 z + x0 z−3 Because Yk is the (2N)-point DFT of a real-valued signal. . and using the result z2N = 1. -0. sizeof(complex)). Wk). X[k] = cadd(Gk. . . temp)). considering the inverse DFT for Yk . xR ]= [x. csub(Y[k]. N − 1: where in the last step. } } Wk = Wk note: Y(0) = Y(N/2) Problem 9. 1. Gk = cmul(half.36 An example will demonstrate the result. we get k Yk = Y(ωk )= X(ωk )+ejωk X(−ωk )= ejωk /2 e−jωk /2 X(ωk )+ejωk /2 X(−ωk ) = 2ejωk /2 Re e−jωk /2 X(ωk ) where we used the hermitian property X(−ω)= X(ω)∗ . . x3 ] xR = [x3 . . Hk. temp. . xn = 1 2N 2N−1 2ejωk /2 Ck ejωk n = k=0 1 2N−1 N Ck ejωk (n+1/2) k=0 208 209 . xR ] N zeros N zeros Thus. k++) { if (k==0) temp = conjg(Y[0]). 0. half. half = cmplx(0. Hk = cmul(halfj. the delay property of z-transforms. . Next. we have: x = [x0 . . The quantity under the real part is now: N−1 N−1 G(k) H(k) Wk H(k) next Wk = Wk+1 G(k) + Wk H(k) e−jωk /2 X(ωk )= e−jωk /2 n=0 xn e−jωk n = n=0 xn e−jωk (n+1/2) G(k) − Wk H(k) Thus.complex one. 2N − 1 XR (k)= z−N+1 X(z−1 )= WN k k (N−1)k −k X(−k)= WN X(N − k) But the ﬁrst N samples of yn are precisely xn . Wk = cmul(W.0. x1 . . Gk. . cadd(Y[k]. it will satisfy the hermitian property ∗ Y2N−k = Yk .37 In the deﬁnition of y. 1. 0. For N = 4. 1. n<Nhalf. k = 0. halfj = cmplx(0. fft(Nhalf. 0. temp = cmul(Wk. k=0 n = 0. n++) Y[n] = cmplx(x[2*n]. .

1. k i = 1. 1]∗[1. 0. (1. 0. 2 . 1. 0. −1. 1. −1. x. 2. 3. 0.38 By deﬁnition. 0. perform the ordinary linear convolution of the given signal and ﬁlter to get y = h ∗ x = [ 1. 1. 3. x. for example. 0] Abutting the rest of the points. 4 where the second summation starts at k = N + 1 because CN = 0. 1. 0. z = zk = e2πjk/4 . 1. 1. 0. −1. 1. 1] ˜ y3 = [x. −2. 1. 0. 2. x. 2. If we change variables from k to m = 2N − k. 3. x. we obtain: ˜ y0 = [x. 3 . 3 xn = 1 N−1 N−1 N C0 + k=1 Ck ejωk (n+1/2) + k=1 Ck e−jωk (n+1/2) Problem 9. 1.Next. 3. 0] ˜ y2 = [x. − 1 . 1 . 2. 1. 1. x. 1. −1. Problem 9. 2 . 2.41 Using the convolution table. 0. − 1 . the inverse DFT becomes (changing the summation from m back to k): X3 (zk )−X1 (zk )= 0. x. 0. 1. 1. 0. 1. −1. 2 . −1. 4 N−1 Ck ejωk (n+1/2) = k=N+1 m=1 C2N−m ejω2N−m (n+1/2) Problem 9. 0. 1]∗[1. 1]∗[1. as shown below: x= 1. 0. = W5 . 0. (3. we obtain −k i = 1. −1. 0][−1.40 Consider. 0. −2. 3. 1. 0. 3. we obtain Thus. 3] y1 = [1. 0. 1 . −1. 1. x. 0. − 2 . 1. 0. 2. we can write 2N−1 ik Xi (zk )= z−i X0 (zk )= W5 X0 (zk ). 2. −1. −1. that is. −3. 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. 2. 2. −1. 3] = [1. −2. 1]∗[3. − 1 . −3. x. 0. 0 . 1][0. −1. 2. and the trig identity X1 (z) = x0 + x1 z−1 + x2 z−2 + x3 z−3 + x4 z−4 + x5 z−5 + x6 z−6 + x7 z−7 X3 (z) = x0 + x1 z−1 + (x2 + x6 )z−2 + (x3 + x7 )z−3 + x4 z−4 + x5 z−5 Subtracting. −2. 0. 0] ˜ y1 = [x. 1] y3 = [1. −2. 2. 1. 0 . 0) The two summations now combine with Euler’s formula to give: xn = 1 N−1 N C0 + 2 k=1 Ck cos ωk (n + 1/2) Problem 9. −1. we get y = [x. 2. k = 0. 1. 2. 2 . 0. 2] = [3. 0. the answer is correct. 0] With the exception of the ﬁrst M points. x. 0. −1. 2). − 2 .39 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 0 x4 x3 x2 x1 0 0 x4 x3 x2 0 0 0 x4 x3 0 0 0 0 x4 0 0 0 0 0 210 211 . 3 . 1. 3. the ﬁrst and the third. we have ejω2N−m (n+1/2) = ejπ(2N−m)(n+1/2)/N = e2jπ(n+1/2) e−jπm(n+1/2)/N = −e−jωm (n+1/2) we have (with the two minus signs canceling): N−1 N−1 X3 (z)−X1 (z)= x6 z−2 (1 − z−4 )+x7 z−3 (1 − z−4 )= (x6 z−2 + x7 z−3 )(1 − z−4 ) Cm e −jωm (n+1/2) C2N−m e m=1 jω2N−m (n+1/2) = m=1 Evaluating at the 4th roots of unity. 2nk W 2N ⇒ X2N (2k)= n=0 nk WN . 2nk x(n)W2N y0 = [1. −1. 0. 2. 0 . 1] = [1. 0. Their z-transforms are Using the symmetry property C2N−m = −Cm . 0. 0. X2N (2k)= n=0 nk x(n)WN = XN (k) n=0 Reducing these mod-8 and ignoring their ﬁrst M = 3 points (indicated by x). 0] = exp −2πj2nk/2N = exp −2πjnk/N = L−1 L−1 2nk x(n)W2N = Thus. 0. 1. 3 . we have L−1 L−1 nk x(n)W2N n=0 Convolving these segments with the ﬁlter gives: X2N (k)= But. 1. −1. 0. 1. 0. 2] y2 = [1. 0. −1. 0 . 0. 0. x. 0. 1. 0. −3. 0][−2. 2. we split the summation into three terms: Their z-transforms differ by a simple delay factor. 0. 0. 0] = [1. 2N−1 xn = 1 N−1 N C0 + k=1 Ck ejωk (n+1/2) + k=N+1 Ck ejωk (n+1/2) Setting z = zk = e jωk Xi (z)= z−i X0 (z). − 1. 1. 1. −1. −1. 0. 0 . −1. 0.

Problem 9. char **argv) { FILE *fph. } 212 213 .7.44 An example of such a program is given below: /* ovsave. namely. } if (fscanf(fph. int M. the input blocks have length N − M and are non-overlapping. in both cases.9. X= ⎢ ⎥ 0 4⎢ ⎢ ⎥ √ ⎢ −j(2 − 2) ⎥ ⎢ ⎥ ⎢ ⎥ ⎣ ⎦ 0 √ j(2 + 2) ⎡ 0 ⎤ ⎡ ⎢ ⎢ ⎢ ⎢ ⎢ 1⎢ ⎢ b= ⎢ 4⎢ ⎢ ⎢ ⎢ ⎢ ⎣ 0 √ (2 + 2)/8j 0 √ −(2 − 2)/8j 0 √ (2 − 2)/8j 0 √ −(2 + 2)/8j ⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎦ calloc(). preliminary allocation L = (N − M)K + M (N − M)K which is essentially the same as in Eq. complexify().5 .42 At fs = 8 Hz. whereas b3 and b5 correspond to ±f2 = ±3 Hz. *X. Thus. for (M=0.2) for large L.1. M = ﬁlter order N log2 N + N = N(1 + log2 N) per segment Thus. } N = atoi(argv[2]). h + M) == EOF) break. 0 . Thus. n. "r")) == NULL) { fprintf(stderr.FIR filtering by overlap-save method and FFT */ #include <stdio.5 −1 − 0. "can’t open filter file: %s\n".5 . 2*M). M++) { read h if (M == max) { reallocate h. (9.5 0 − 0. void main(int argc. we have cost: KN(1 + log2 N)= LN(1 + log2 N) N−M if (N <= 2*M) { fprintf(stderr. Thus. } M--.7. argv[1]). the input blocks overlap by M points. dmax = MAX. we treat these MACs as complex-valued. we have in the overlap-save method: if ((fph = fopen(argv[1]. Thus. We ﬁnd: This is to be compared with the cost of L(M + 1) of linear convolution of the entire input array with the ﬁlter (here. the total length will be (N − M)K plus an extra M points at the end. } > yfile\n"). the aliased coefﬁcients can be obtained by computing the 8-point DFT of one period and dividing by 8. L = (N − M)K (P9.5 1 0.h> #define MAX 64 void circonv().) Thus. we will have: if (argc != 3) { fprintf(stderr.2) In Fig. *x. if necessary max += dmax. Problem 9. These samples can be evaluated by setting t = nT = n/8 in the expression for x(t). "%lf". − 0 . "usage: fastconv hfile N < xfile exit(0). realloc() initial allocation size The coefﬁcients b1 and b7 correspond to frequencies ±f1 = ±1 Hz. 1 . 9.5 } 4 LN(1 + log2 N) N(1 + log2 N) N−M = L(M + 1) (N − M)(M + 1) According to Eq. if there are K blocks in the total length.c . exit(0). (9.5 ⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎦ DFT − → ⎢ −j(2 + √2) ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ 0 ⎢ ⎥ √ 1 ⎢ j(2 − 2) ⎥ ⎢ ⎥ ⎥.h> #include <cmplx.43 In the overlap-add method.h> #include <stdlib. − 1 . we ﬁnd from Eq. 0 . double *h.. ifft(). 5 . complex *H. "must have N > 2M = %d".4). *Y. ⎡ ⎢ ⎢ ⎢ ⎢ ⎢ 1⎢ ⎢ x= ⎢ 4⎢ ⎢ ⎢ ⎢ ⎢ ⎣ 0 0 . (P9. exit(0). the total number of segments can be estimated to be: K= L N−M Per segment. i. N. the relative cost of the fast versus slow convolution will be: fast = slow x(n)= 1 { 0 . int max = MAX. h = (double *) realloc((char *) h. (max + 1) * sizeof(double)). *xhead. we are doing two FFTs and N multiplications. fft(). for K segments. but again if there are K segments. sizeof(double)). there are 8 samples per period. This DFT can be done quickly by an 8-point FFT by hand.5) and after using Euler’s formula: xal (t)= 2jb1 sin(2πf1 t)+2jb3 sin(2πf2 t)= 2+ 2 2− 2 sin(2πt)− sin(6πt) 16 16 √ √ ﬁlter ﬁle x = length-N block N-point DFTs It can be veriﬁed easily that xal and x(t) agree at the sampling instants t = nT = n/8. − 0 . h = (double *) calloc(max + 1. 0 . which gives: Problem 9.

0). ifft(N. done once pad M zeros in front of ﬁrst block keep reading input in blocks x previous tail is head of present block x void complexify(N. for (i=M. n++) x[n] = xhead[n]. sizeof(complex)).0). for (i=M. x = (double *) calloc(N. X). Y). n<M. Y = (complex *) calloc(N. X) int N. x + n) == EOF) goto lastblocks. X. sizeof(complex)). H. else H[n] = cmplx(0. n++) xhead[n] = 0. for (n=0. i++) x[i] = 0. 0. n++) X[n] = cmplx(x[n]. 0. x. fft(N. (M+1) * sizeof(double)). H. sizeof(double)). must be done previously n = index where EOF occurred for (i=n. n++) if (n <= M) H[n] = cmplx(h[n]. X. for (i=0. X. X). n<N. for (n=0. n++) if (scanf("%lf". Y). for (n=M. circonv(N. i<N. complex *X. fft(N. head/tail of input block xhead = (double *) calloc(M. H. k<N. x. i++) xhead[i] = x[i + N . for (k=0.M]. H = (complex *) calloc(N. i<N. circonv(N. double *x. } lastblocks: tail of present block x will be head of next block X = cmplx(x. the tail of previous block will be non-zero head of very last block 214 215 . i<N. complex *H. pad rest of x with zeros if n <= N-M there is only one last block to consider otherwise. n<M.else h = (double *) realloc((char *) h. for (n=0. X). X = (complex *) calloc(N. there are two last blocks exit. real(Y[i])). } ——————————————————————– read rest of x from input stream for (n=M.M]. for (i=0. i++) printf("%lf\n". X[k]). n<N. x. n++) xhead[n] = x[n + N . 0) done by fft discard ﬁrst M points.0. Y). complexify(N. if only one last block otherwise. real(Y[n])). H). complexify(N. k++) Y[k] = cmul(H[k]. X). } circular convolution via FFT H = FFT(h). H. process very last block if n > N-M. 0. { int n. x. save the rest void circonv(N. n++) printf("%lf\n". *X. if (n <= N-M) exit(0). for (. sizeof(double)). for (n=0. i<N. real(Y[i])). complexify(N. i++) if (i < M) x[i] = xhead[i]. sizeof(complex)). rest of block is zero complexify/extend to length N } ——————————————————————– H = FFT(h). i++) printf("%lf\n". Y) int N. *Y.0). i<M. X. n<N. { int k..) { for (n=0. Y). n<N. n<M. allocate DFT arrays x[i] = 0. circonv(N.

2 For the bandpass example. 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. Setting d(−k)= −d(k) in the sum.) d(k)= ∂ ∂k ωc −ωc ejωk dω ∂ = 2π ∂k sin(ωc k) πk D(ω)= d(0)+ k=1 d(k)e−jωk + −1 k=−∞ d(k)e−jωk = d(0)+ ∞ k=1 d(k)e−jωk + ∞ d(−k)ejωk k=1 where the ω-integration gave the standard lowpass ﬁlter. The second term vanishes for nonzero integer ks. we may replace it by δ(k): Thus. 216 217 . we get the required expression for d(k): In the symmetric case. and its equal to unity for k = 0. it will have d(0)= 0.3 For the lowpass differentiator. and ωb = π the highpass one. and therefore ∞ ∗ For the differentiator and Hilbert transformer. we get −π D(ω)ejωk dω = 2π jωejωk dω 2π D(ω)= D(−ω)∗ = −D(−ω) which implies that D(ω) is pure imaginary and odd in ω. we obtain: ∞ Because d(k) belongs to the antisymmetric class.3. gives = = −ωa −ωb dω + 2π −jωb k ejωk dω = 2π jωa k ejωk 2πjk = + −ωb D(−ω)∗ = ∞ d(k)ejωk k=−∞ ∗ ∞ = k=−∞ d(k)e−jωk = D(ω) e −jωa k 2πjk + e jωb k −e sin(ωb k)− sin(ωa k) 2πjk πk This result uses only the reality of d(k) and is the usual hermitian property for transfer functions of real-valued impulse responses. we have d(−k)= −d(k). we have for k = 0: D(ω)= −2j k=1 d(k)sin(ωk) (antisymmetric case) d(k)= cos(πk) k = (−1)k k (differentiator) The Hilbert transformer case is similar. we can change the summation from k to −k to get: ∞ Setting ωa = 0. In the antisymmetric case. Problem 10. In the latter. Taking conjugates and replacing ω by −ω. Performing the differentiation. the reality and evenness conditions imply together: d(k)= δ(k)− sin(ωa k) πk D(ω)= D(−ω) = D(−ω) which states that D(ω) is both real and even in ω. Thus. Because d(k)= d(−k). we have π ωc −ωc D(ω)= k=−∞ d(k)e−jωk = ∞ k=−∞ d(−k)e−jω(−k) = − ∞ k=−∞ d(k)e−j(−ω)k = −D(−ω) d(k)= Together with the reality condition. gives the lowpass case. see the more general cases of Problem 10.1 Start with ∞ Problem 10.Chapter 10 Problems Problem 10. d(0)= 0 because it must satisfy d(−0)= −d(0).and positive-k terms. we use the fact that D(ω)= 1 over the passband ωa ≤ |ω| ≤ ωb to get: π d(k) = d(k)e −jωk D(ω)= k=−∞ −π D(ω)ejωk ejωk −e dω = 2π ωb ωa −ωa −ωb D(ω)ejωk dω + 2π −ωa ωb ωa D(ω)ejωk ejωk 2πjk ωb ωa dω = 2π and assume that d(k) is real and even in k. Thus. Separating the negative. we have: d(k)= sin(πk)− sin(ωb k) πk D(ω)= k=−∞ d(k)e−jωk = ∞ k=−∞ d(−k)e−jω(−k) = ∞ k=−∞ d(k)e−j(−ω)k = D(−ω) The ﬁrst term is zero for all non-zero k. we can rewrite D(ω) in the form: ∞ It can be evaluated either by parts. we set d(−k)= d(k) and combine the two sums with Euler’s formula to get: ∞ d(k)= ωc cos(ωc k) sin(ωc k) − πk πk2 Setting ωc = π gives the full-band differentiator: D(ω)= d(0)+2 k=1 d(k)cos(ωk) (symmetric case) d(k)= cos(πk) k − sin(πk) πk2 For the antisymmetric case.

The integrations give the bandpass ﬁlter case. and is in this case d(k)= 2/πk. transfer function. NRR = NRRmax For the full-band Hilbert transformer.3. the NRR can be computed as: NRR = ωc −ωc |D(ω)|2 dω = 2π ωc −ωc |jω|2 ω3 dω = c 2π 3π 2 k=1 1 k2 = π2 3 ∞ ⇒ k=1 1 k2 = π2 6 Thus. ∞ d2 (k)= k=−∞ k=0 1 ∞ k2 =2 k=1 1 k2 For the ideal lowpass differentiator case. To see how closely it resembles the ideal differentiator. and frequency response: h = [ 1 . Then.6 Let E(ω)= D(ω)−D(ω) be the error in the designed ﬁlter. we have d(k)= (−1)k /k. Using Parseval’s identity we have ∞ π ⇒ H(z)= 1 − z −1 ⇒ H(ω)= 1 − e −jω h2 0 + h2 1 =1+1=2 d2 (k)= k=−∞ −π |D(ω)|2 dω = 2π π −π ω2 dω π2 = 2π 3 Thus. we have ∞ M Thus. it increases rapidly with ωc . the noise power doubles at the output.5 For the ﬁrst-order differentiator. EM = π −π |D(ω)−D(ω)|2 ∂ d(k)= ∂k sin(ωb k)− sin(ωa k) dω = d2 (k) 2π |k|>M πk The right-hand side sum can be written with the help of Parseval’s identity applied to D(ω) itself: ∞ π which becomes the difference of two lowpass differentiators: ωb cos(ωb k) ωa cos(ωa k) sin(ωb k) sin(ωa k) − + d(k)= − πk πk2 πk πk2 d2 (k)= |k|>M k=−∞ d2 (k)− |k|≤M d2 (k)= −π |D(ω)|2 dω − d(k)2 2π k=−M M Problem 10. Parseval’s identity applied to this ﬁlter gives: ∞ π d2 (k)= k=−∞ −π |D(ω)|2 dω = 2π π −π |jsign(ω)|2 dω = 2π π −π 1 dω =1 2π E(ω)= D(ω)−D(ω)= k=−∞ d(k)e−jωk − k=−M d(k)e−jωk = |k|>M d(k)e−jωk The left-hand side on the other hand becomes: ∞ ∞ because the coefﬁcients d(k) cancel for |k| ≤ M.4 Using the differentiation argument. for the differentiator ﬁlter. we expand the frequency response at low frequencies: But the left-hand side is twice the required sum: ∞ H(ω)= 1 − e −jω 1 − (1 − jω)= jω for small ω Thus. we have in this case: Parseval’s identity applied to e(k) gives then π ωb ωa d(k)= ∂ ∂k −ωa −ωb ejωk dω + 2π ejωk dω 2π −π |E(ω)|2 dω = e2 (k)= d2 (k) 2π k=−∞ |k|>M ∞ or. the time-domain coefﬁcients of the error are: d2 (k)= 2 k=−∞ k=1 k=odd 4 π2 k2 e(k)= 0 d(k) if |k| ≤ M if |k| > M Thus. k = 0.7 From Problem 10. we have ωc π 3 d(k)= 1 − cos(πk) πk = 1 − (−1)k πk . Thus. Compared to the full-band maximum NRR obtained with ωc = π. − 1] Thus. we have NRRmax = π3 /3π = π2 /3 and therefore. k=0 Problem 10.Problem 10. the second term in the right-hand side tends to the Parseval limit. Thus. d(k) is nonzero only for odd k. the NRR will be NRR = In the limit as M → ∞. Problem 10. we obtain 218 219 . thus canceling the ﬁrst term and resulting in EM → 0. we have impulse response.

4. because sin(ωn)= [ejωn − e−jωn ]/2j.5 . and therefore. − 3 . 5 . the symmetry/antisymmetry properties of d(k) will be preserved and will imply similar results on the locations of the zeros. Thus. − 1 ] ∗ } are shown in Fig. Thus. Using the antisymmetry property and splitting the sum in two parts. − 3 . M D(z−1 )= ± k=−M d(k)z−k = ±D(z) H(z)= 1−(0. 1] In the antisymmetric case. The same conclusion follows from the frequency response. D(ω) vanishes. 1 H(z)= (1 − z−2 )(1 − 3z−1 + 4.1 Pattern of zeros of linear phase ﬁlters.∞ 2 k=1 k=odd 4 ∞ π 2 k2 =1 ⇒ k=1 k=odd 1 k2 = π2 8 * 1/z0 z0 If the sum for all integers k is π2 /6 and for odd ones π2 /8. jωn M e jωn − D(ω)e → D jωn = −jsign(ω)e Replacing ω by −ω. 0 0 1 ∗ If z0 lies on the unit circle then because 1/z0 = z0 .5z−2 − 3z−3 + z−4 )= 1 − 3z−1 + 3. we have for the outputs: 1 −jsign(ω)ejωn − jsign(ω)e−jωn = −sign(ω)cos(ωn) → sin(ωn)− 2j D Setting ω = 0. we have in addition two zeros at z = ±1 contributing a factor (1 −z−2 ) to the transfer function. 0 . 0 1 z0 = 1 − j. Problem 10. then D(z−1 )= ±D(z0 )= 0 0 Thus. d (k)= w(k)w(k).5z−4 + 3z−5 − z−6 and in the time domain: h = [ 1 . if z0 is a complex zero. From the reality of d(k). and using the odd symmetry property of D(ω).5j. we get the length-5 symmetric (about its middle) impulse response: h = [ 1 . Therefore.8 The sinusoidal response of D(ω) in its steady-state form is: In the antisymmetric case. we have: cos(ωn)− → D D This follows because d(k) is odd and summed over symmetric limits and because the factor (±1)k is even in k. 3 . Thus.5 + 0. − 3 .5j)z−1 1−(0. then z∗ is also a zero. it follows that if z0 is a zero. In the symmetric/antisymmetric cases. forming the same linear combination of outputs. z 0 z0 . we note that if d(k) is windowed by a window w(k). P10.5−0. the following must necessarily be zeros: D(z)= k=−M d(k)z−k ⇒ D(z−1 )= k=−M d(k)zk = k=−M d(−k)z−k z0 = 0.9 From the deﬁnition of D(z). the only other distinct zero is the complex conjugate. we get: M M M 1 −jsign(ω)ejωn + jsign(ω)e−jωn = sign(ω)sin(ωn) 2 D(ω)= k=−M d(k)e−jωk = k=1 d(k) e−jωk − ejωk = −2j k=1 d(k)sin(ωk) Similarly.5z−2 − 3. 1/z0 and 1/z∗ are both zeros. corresponding to z = ±1. that is. 5 . Problem 10. it follows by subtraction that the sum over even integers will be: ∞ k=2 k=even * z0 1 k2 = π2 6 − π2 8 = π2 24 1/z0 Fig. The four zeros {z0 . Finally. it follows that the zeros will come in conjugate pairs if they are complex. we have: D(±1)= k=−M d(k)(±1)k = 0 e−jωn − D(−ω)e−jωn = jsign(ω)e−jωn → But cos(ωn)= [ejωn + e−jωn ]/2. − 3 . z∗ .5+0. Thus. 1 z∗ 0 =1+j where in the last step we changed summation from k to −k.5 − 0. then because the window w(k) is symmetric with respect to the origin. we have: M M M Problem 10.1.5j. the transfer function will be z∗ = 0.10 For the symmetric case. 3 . we have sin(ωk)= 0.5z−2 −3z−3 +z−4 In the time domain. 220 221 . From the symmetry or antisymmetry 0 properties. π. we have d(k)= ±d(k).5j)z−1 1−(1−j)z−1 1−(1+j)z−1 = 1−3z−1 +4. P10. we have in particular for z = ±1.

000472 dB In the 4-times oversampling case. that is. we have: ⇒ Δf = Dfs N−1 As in the previous problem.2. we calculate δpass and δstop from Eq.13 First.55 − 19.017 as in the previous problem.The frequency response in the symmetric case is obtained by factoring out a factor of z−2 and using Euler’s formula: Problem 10. the maximum ﬁlter length will correspond to the maximum number of instructions that ﬁt within the sampling interval T. we have: log10 (1 ± x)= It follows that ln(1 ± x) = ±0.4343 δpass = 17.7)= 0. therefore.5jz−1 )(1+0. 0.4343 x ln(10) δ = 10−A/20 = 10−91.6281 14. D= A − 7. 100.1/20 − 1 = 0.017 14. 0.0058. 5 Δf Dfs Dfs = N finstr 2 ⇒ N = 103 222 223 . 3.55 = 5 kHz This gives the width factor and attenuation: Apass = 20 log10 1 + δpass 1 − δpass = 20 log10 (1 + δpass )−20 log10 (1 − δpass ) D= 20 · 0.000027 which gives the passband attenuation: ±x Apass = 17.31 dB ⇒ h = [1.5(z − z−1 ) H(ω)= −2je−3jω sin(3ω)−3 sin(2ω)+3. we ﬁnd D = 5. we ﬁnd the minimum width (where we used N instead of N − 1 in the denominator): The transition width is Δf = fstop − fpass = 2 − 1.372 δ = 0. Thus.25z −4 −z −6 A − 7. 0.805 14.25z −2 +z −4 −3.5 kHz.25.15 The window’s width factor is D = 5.5 H(ω)= 2e−2jω cos(2ω)−3 cos(ω)+4.36 Inserting this into the Kaiser design formula. 0. the transition width is required to be: Δf = 24.0001 Therefore.017 · 10 Dfs = 101.36 4f s ⇒ A = 14.857.5 = 0.2007 kHz = N−1 251 − 1 Problem 10. then we may solve for the D-factor and attenuation A: D= )= 1+3. δstop )= δstop = 0.017 · 44.017 · 10 Dfs = 0.1102(80 − 8.372 δpass A − 7.1/20 + 1 Assuming that an N-tap ﬁlter requires approximately N instructions for processing each input sample. 4.5jz−1 )(1−2jz−1 )(1+2jz−1 )= 1+4.25z−2 +z−4 and for the antisymmetric case: ⇒ h = [1.1 = = 1.95 Δf = (N − 1) = 3. The D and α parameters are computed by: Nmax = T finstr = Tinstr fs α = 0.1102(A − 8.95 = 91.95 = 60. −1] The corresponding ripple will be Problem 10.4343 δpass + 20 · 0.25z −2 H(z)= (1−z −2 )(1+4. which in dB is A = −20 log10 δ = Astop = 80.16 Problem 10. δ = min(δpass .95 Δf = (N − 1) = 5. −3.36D + 7.25.5 For the antisymmetric case. we ﬁnd the transfer function of the symmetric case: Δf = Dfs 5. 1] Conversely.05 dB Problem 10.36 fs ⇒ A = 14.017.5): 100. Thus.0001.36D + 7. Problem 10.11 Proceeding as in the previous problem. δpass = δstop = 10−80/20 = 0. (10.729 kHz N−1 129 − 1 H(z)= (1−0. if Δf = 2 kHz.25. H(z)= z−3 (z3 − z−3 )−3(z2 − z−2 )+3.14 The transition width is inversely related to the ﬁlter length N: H(z)= z−2 z2 + z−2 − 3(z + z−1 )+4.31/20 = 0. 0.95 = 5.12 We use the ﬁrst-order Taylor series approximation: ln(1 ± x) Changing to base-10. the ﬁlter length will be: Δf = N =1+ 5.34 =1+ 0.5 sin(ω) ⇒ Δf = 5.7)= 7.

Apass = 0. with fs = 2 so that ω = 2πf /2 = πf .4π. fpb = 6. wc. P10. 0.m: wc = 0. fpass. omega).05π.10 0. The magnitude responses are shown in Figs. that is. h = kbp(fs. H = dtft(h. fstop = 4. in kHz in dB % s = −1 for alternative design Similarly. P10.0.05.95 Δf 0.3. fsb = 8. 60). π] with the help of the function dtft. omega). hham = w .2 Lowpass differentiator with ωc = 0. π] % frequency response For example.4π. in kHz in dB % s = −1 for highpass Fig. the following MATLAB program segment computes the bandpass ﬁlter of Example 10. in the case ωc = 0. fpa. NF = 200. NF = 200. they are: D= A − 7. w = 0. Hham = dtft(hham. % cutoff frequency % ﬁlter length % Hamming window % ideal lowpass ﬁlter % windowed ﬁlter % 200 frequencies in rads/sample % over the interval [0.2. omega). omega = (0:NF-1) * pi / NF.18 The following MATLAB program segment computes the rectangularly and Hamming windowed impulse responses with the help of the MATLAB function dlh. omega = (0:NF-1) * pi / NF.2 and P10. Problem 10. h = klh(-1. Δω = 0. H = dtft(h.05 0. omega = (0:NF-1) * pi / NF. we obtain the maximum width parameter D and attenuation A: Problem 10. omega). A = 60 dB.m. fsb. Apass = 0. Astop.Problem 10.1. The ﬁlter lengths depend only on the values of Δf and A.* hrec. N = 81.95 Δf finstr Δf =N = = Finstr ΔF 2 14. 0. Apass. Apass.36 fs fs ⇒ A = 14.54 . Astop = 80.17 Using N = finstr /fs for the maximum ﬁlter length. fsa. fstop. hrec = dlh(1.20 Use the design MATLAB routine kdiff.19 As an example. fpa = 4.46 * cos(2 * pi * (0:N-1) / (N-1)).10 0. fs. N).3 * pi. -1). fpb. omega = (0:NF-1) * pi / NF. Astop = 80. the f ’s are the ω’s in units of π.05 A 30 60 30 60 N 33 75 63 147 Problem 10.36Finstr ΔF + 7. omega). fpass = 5. NF = 200. 224 225 .4. and then it computes the corresponding frequency responses over NF equally spaced frequencies over the right half of the Nyquist interval [0. fsa = 3. the highpass ﬁlter can be designed by: fs = 20. NF = 200.1. H = dtft(h. we have the MATLAB code: h = kdiff(2. Hrec = dtft(hrec.2 (alternative design): fs = 20. Astop).

omega = (0:NF-1) * pi / NF. A1 = 1. Xh = abs(dtft(xh. the Hilbert transformer with ωc = 0. the f ’s are the ω’s in units of π. [B. 60). Xkmax = max(Xk). S’ * S. P10.8π. xh = (0. 0. omega). 0.0. DF = (F2-F1)/3. The magnitude responses are shown in Figs.22 Use the design MATLAB routine khilb.6.20. A = 60 dB. 60). P10. L) .30. in the case ωc = 0.05. same as in Problem 10. Δω = 0. omega). Xk = abs(dtft(xk.20.2)’. omega = (0:NF-1) * pi / NF.54 . n = (0:L-1). omega)). F2 = 0. they are the 226 227 .23 The following MATLAB segment computes the Kaiser and Hamming spectra in dB.* x. % Kaiser differentiator % Savitzky-Golay smoothing ﬁlters % polynomial basis matrix % Savitzky-Golay differentiator ﬁlters % ﬁrst-order derivative ﬁlter Problem 10. Xk = 20 * log10(Xk / Xkmax). with fs = 2 so that ω = 2πf /2 = πf . omega)). can be designed by the MATLAB segment: h = khilb(2. P10. omega = (0:NF-1) * pi / NF.Fig.05π. F3 = 0.m: F1 = 0.05. x = A1 * cos(2*pi*F1*n) + A2 * cos(2*pi*F2*n) + A3 * cos(2*pi*F3*n). % DTFT spectrum % normalized and in dB Problem 10. A3 = 1. A2 = 10^(-50/20).21 For example.8π. Problem 10. F = G = g = S] = sg(3. [alpha.* x. NF = 256. H = dtft(h. we have the MATLAB segment that computes the Kaiser differentiator and the Savitzky-Golay differentiators of polynomial order d = 3: h = kdiff(2. 0. R = 70.4.3 Lowpass differentiator with ωc = 0.25. and A = 60 dB. % Kaiser windowed signal % Hamming windowed signal The magnitude responses are shown in Fig. R). The ﬁlter lengths depend only on the values of Δf and A. For example. 0.4 Comparison of Kaiser and SG differentiators. % frequency responses xk = kwind(alpha. Δω = 0. % frequency responses Fig.05π. H = dtft(h. G = dtft(g.4π. G(:. that is. S * F^(-1).5 and P10. P10. NF = 200. omega). N). L] = kparm2(DF.8. The Kaiser window parameters are determined by the function kparm2. % units of fs % amplitudes % sidelobe level in dB % Kaiser parameters NF = 500.46 * cos(2*pi*n/(L-1))) .4.

Xhmax = max(Xh). Fig. P10. 228 229 .6 Full-band Hilbert transformer. Xh = 20 * log10(Xh / Xhmax).Fig. P10.5 Lowpass Hilbert transformer with ωc = 0.8π.

the bandwidth levels g2 may be deﬁned arbitrarily in the two B cases. This is guaranteed if the bandwidth is 0 ≤ Δω ≤ π/2 in rads/sample. we assume that the parameter β = tan(Δω/2) remains positive and less than one. we may express the magnitude squared response in the following form that explicitly shows the gains: β = tan Δω 2 Δω 2 |H(Ω)|2 = G2 0 (Ω2 − Ω2 )2 +N(g. g2 − g2 B D(g. D(g. gB )= g . the parameter b is the same for both ﬁlters.Chapter 11 Problems Problem 11. under the substitutions {g. we have: where the numerator and denominator gain functions are deﬁned by R= 1−β 1+β (1 − 1 1 β)(1 − β) 2 2 1−β 1− Δω 2 1 − x. which does not depend on the gains. gB )γ2 Ω2 0 . g 1 . if we take them also to be related by the substitution gB → g−1 . the boost and cut magnitude responses are: B |Hboost (Ω)|2 = G2 0 (Ω2 − Ω2 )2 +N(g.3 For the 3-dB case. gB )= 1 . and vice versa. we obtain the approximate expression Δω = 2(1 − R). This condition implies that the poles are complex conjugate and have radius Problem 11. (Ω2 − Ω2 )2 +α2 Ω2 0 α=γ g2 − 1 B . gB ) . the functions N and D interchange roles. we recognize that the two numerators add up to become the denominator: g2 = B 2 1 + g2 . then the boost and cut gains will be g = 10±A/20 .2 For small values of Δω. Adding the two transfer functions. Indeed. g−1 )= D(g. However. D(g. gB ) B 230 231 . g2 Hnotch (z)+Hpeak (z) = b = 1 − z−2 1 − 2 cos ω0 z−1 + z−2 + (1 − b) 1 − 2b cos ω0 z−1 + (2b − 1)z−2 1 − 2b cos ω0 z−1 + (2b − 1)z−2 1 − 2b cos ω0 z−1 + (2b − 1)z−2 b(1 − 2 cos ω0 z−1 + z−2 )+(1 − b)(1 − z−2 ) = 1 − 2b cos ω0 z−1 + (2b − 1)z−2 1 − 2b cos ω0 z−1 + (2b − 1)z−2 For the magnitude responses squared we may use the equivalent analog expressions to get: |Hnotch (ω)|2 +|Hpeak (ω)|2 = |Hnotch (Ω)|2 +|Hpeak (Ω)|2 = (Ω2 − Ω2 )2 α 2 Ω2 0 + =1 (Ω2 − Ω2 )2 +α2 Ω2 (Ω2 − Ω2 )2 +α2 Ω2 0 0 Now. g−1 )γ2 Ω2 0 B (Ω2 − Ω2 )2 +D(g−1 . g2 − g 2 B where g= G . gB )= g2 − 1 B g2 − g 2 B where we used the Taylor expansions (1 ∓ x)±1/2 1 − x/2 and (1 − x/2)2 Δω. then we can B show that the boost and cut ﬁlters are inverses to each other. gB )= 1 (arithmetic) gB = g . g−1 )= N(g. (Ω2 − Ω2 )2 +D(g. This range covers most practical applications. Thus. Normalizing everything to the reference gain G0 . then there are two real poles.4 The analog transfer function and magnitude response squared are in the general boost or cut case: H(s)= where G0 (s2 + Ω2 )+Gαs 0 s2 + αs + Ω2 0 ⇒ |H(Ω)|2 = G2 (Ω2 − Ω2 )2 +G2 α2 Ω2 0 0 (Ω2 − Ω2 )2 +α2 Ω2 0 R2 = 1−β 1+β ⇒ R= 1−β 1+β α = (1 + Ω2 )β = (1 + Ω2 )tan 0 0 Δω 2 G2 − G 2 0 B ≡γ G2 − G2 B G2 − G2 0 B G2 − G 2 B (If β > 1. gB } → {g−1 . g2 = B . or. 0 ≤ Δf ≤ fs /4 in Hz. gB )γ2 Ω2 0 |Hcut (Ω)|2 = G2 0 (Ω2 − Ω2 )2 +N(g−1 . Even though the boost and =1 cut gains are equal and opposite. . For the arithmetic. 2 2g 2 1 + g2 N(g. gB )γ2 Ω2 0 Then.) It follows that the -level time constant will be where the last step deﬁnes the parameter γ. g−1 )γ2 Ω2 0 B Under this substitution. Solving for N(g. 0 ≤ β ≤ 1. we may use the ﬁrst-order Taylor expansion tan(x) imately: (Ω2 − Ω2 )2 +g2 α2 Ω2 0 . the substitution g → g−1 changes a boost into an equal and opposite cut. gB )= g2 g2 − 1 B . and harmonic mean choices for g2 the functions N and D simplify B as follows: Problem 11. g−1 }. geometric. one can show easily that N(g−1 . if we consider an equal and opposite boost and cut by. gB )= 1 . G0 gB = GB G0 x to write approx- Then. gB )γ2 Ω2 0 (Ω2 − Ω2 )2 +D(g. B D(g−1 . gB )= g2 . we have neff = ln ln R |H(Ω)|2 = G2 0 Problem 11. expanding R to ﬁrst-order in β and thus to ﬁrst-order in Δω. (geometric) (harmonic) N(g.1 Here. gB )= D(g. which happens when π/2 < Δω ≤ π. N(g. say by A dB (with respect to the reference). that is.

and their magnitude responses: w0 = 0. boost/cut. w)). a. x = [1. -s*(G0 . zeros(1.1 and computes their impulse response. 10^(3/20). G. w).35*pi. parmeq(1. P11. H1 = dtft(b1. gB ) s2 + Ω2 + γs N(g−1 . w)). the following MATLAB code designs the ﬁrst four ﬁlters of Example 11.5 The following MATLAB code segment designs the three ﬁlters (two peaking and one complementary notch). But. -s*(1-beta)/(1+beta)]. 10^(-9/20). x). parmeq(1. a4. pi. a. [b3. w) . parmeq(1. w0. function [b./ H2 = dtft(b2. H2 = abs(dtft(b2. a4.G*beta)] / (1+beta). g−1 ) 0 B which implies for the analog and the bilinearly transformed digital transfer functions: Hcut (s)= G2 0 Hboost (s) ⇒ Hcut (z)= G2 0 Hboost (z) Problem 11. 0. beta2] = parmeq(0. w) . gB )γ2 Ω2 0 |Hcut (Ω)|2 = G2 0 (Ω2 − Ω2 )2 +D(g. 0./ H3 = dtft(b3. w) . G0. s2 + Ω2 + γs D(g. beta3] = parmeq(1. a1. 10^(9/20). Gc.2. h2 = filter(b2. impulse responses Hence.60*pi.6. G0. b = [(G0 + G*beta).Therefore. [b2. gB )γ2 Ω2 0 (Ω2 − Ω2 )2 +N(g.35*pi. gB ) 0 = G0 2 Hcut (s)= G0 2 −1 s + Ω2 + γs N(g.4. w0. g−1 . −1 = lowpass. highpass The 5-percent time constants can be calculated as in Problem 11. with = 0.1 shows the phase responses. 0.1. 10^(-6/20). also that the transfer functions themselves are inverses to each other. x).1). b1 ] = numerator coefﬁcients % a = [1.^2. 1/sqrt(2). w). Indeed. not just their magnitudes. w) .60*pi. [b1. Dw). H1 = abs(dtft(b1.2. Gc = reference. h3 = filter(b3. computes their impulse responses. we can write them in the form: w = (0:199)*pi/200. Dw = 0./ dtft(a3. a = [1. and phase responses (in degrees): [b1. (Ω2 − Ω2 )2 +D(g. 0. zeros(1. Problem 11. gB ) 0 s2 + Ω0 + γs D(g−1 .2*pi).1*pi. G. x).lowpass/highpass first-order shelving EQ filter design % % [b. [b2. a2. a1 ] = denominator coefﬁcients % G0 . beta] = lheq(s. equal and opposite bandwidth gains in B dB.2*pi). h1 = filter(b1. frequency. Dw). any other choice of gB will do. 49)]. w). 1.1 and 11. x). 10^(9/20).7 impulse responses The following MATLAB function lheq. a2. w) . Note.05. beta1] = parmeq(0.6 For example. a2. % b = [b0 . x = [1. w). pi. dtft(a3. x).m implements the design of both the lowpass and highpass shelving ﬁlters (the parameter s = ±1 selects the two cases): 200 frequencies over [0. 10^(-9/20). 10^(-3/20). sqrt(0. Dw). B B satisfy the desired property. wc) beta = (tan(wc/2))^s * sqrt(abs(Gc^2 . gB ) 0 . w)). π] magnitude responses % lheq. Hboost (s)= G0 2 s + Ω2 + γs D(g. length-50 unit impulse The ﬁlters of Examples 11. 0. 99)]./ dtft(a2. pi.G0^2)) / sqrt(abs(G^2 .35*pi. 0. argH1 argH2 argH3 argH4 = = = = angle(H1) angle(H2) angle(H3) angle(H4) * * * * 180 180 180 180 / / / / pi./ dtft(a1. gB )γ2 Ω2 0 .Gc^2)). wc) % % s = 1. 10^(6/20). filter(b4. a1. a1. their product will be identically equal to G4 . a3. and therefore.^2.^2. H3 = abs(dtft(b3. w0. a3. filter(b2. in rads/sample peaking 3-dB width peaking 10-dB width notching 3-dB width unit impulse Fig. Figure P11. 1. x)./ H4 = dtft(b4.1 Phase responses of Problem 11. w) . w) . dtft(a4. G. dtft(a2.1*pi). [b4. a3. x).1*pi). filter(b3. 1/sqrt(2). g−1 }. which also shows how to compute the magnitude responses of the two complementary cases: 232 233 ./ dtft(a1. 0. [b3. Gc. w = (0:199)*pi/200.2 may be designed by the following MATLAB code. and cutoff gains % wc = cutoff frequency in [rads/sample] % beta = design parameter β Problem 11. as long as one deﬁnes the boost bandwidth to be gB and the cut bandwidth. a2. 0. a3. beta1] beta2] beta3] beta4] = = = = parmeq(1. The geometric-mean and weighted geometric0 mean choices for g2 are special cases of the substitution {g.m . that is. gB } → {g−1 . beta] = lheq(s. Note the rapid variations in the vicinities of the center s2 + Ω2 + γs N(g. gB )γ2 Ω2 0 h1 h2 h3 h4 = = = = filter(b1. gB ) 0 frequencies. the boost and cut ﬁlters will be: |Hboost (Ω)|2 = G2 0 (Ω2 − Ω2 )2 +N(g. 0. a1.

0. 1/sqrt(2).9).m that uses a circular buffer: D = 10. 0. x(n+1)). 0. 0. [a1.c . 1./dtft(a1. lowpass cases highpass cases 200 frequencies in [0. 1. omega).comb filtering with circular buffer % % [y. w.c x = [1. 10^(-3/20). w. D. 1/sqrt(2). a5. D-1). [1. beta4] = lheq(1. & p) The following C function combfilt. H5 = abs(dtft(b5. 0. [b6. D.^2. dtft(num1. wc. [b3. w. omega = (0:399)*2*pi/ 400. b1. b. omega).2.2 Phase responses and impulse response of Problem 11. D). [y1(n+1). angle(H1) * 180 / pi. % % The ﬁlter parameters [a. beta1] = lheq(1. den1. P11. -c1].7*pi). 0. omega). zeros(1. p. p. w.2*pi). *p. a1.2*pi). -c2]. -a2]. return y. y = b * s0 .2*pi). q] = combﬁlt(a. h1 = filter(num1. 1. 2π] Fig. D-1).c * sD.025 * pi. [1. b2.comb filtering with circular buffer */ void cdelay(). 20 * log10(abs(H2)). beta3] = lheq(1. a4. s0 = x + a * sD. p). sqrt(0. and computes the corresponding magnitude and phase responses. π] magnitude response squared Problem 11. c1.1.[b1. 20 * log10(abs(H1)). sqrt(0. 0. D-1). double combfilt(a. 10^(3/20). beta2] = lheq(1./ dtft(den2. *w. beta1] = combeq(1. w. D. num1 den1 H1 magH1 angH1 num2 den2 H2 magH2 angH2 = = = = = = = = = = [b1. a2. D) x s0 z-D sD a b y s0 = x + asD y = bs0 − csD ∗p = s0 cdelay(D. w. D+1). c] can be obtained from combeq. **p = s0. that is.8. 0.m given below: The phase responses of the comb and notch ﬁlters and the impulse response of the comb are shown in Fig. The canonical realization and the corresponding circular buffer version of the sample processing % combfilt. zeros(1. H1 = abs(dtft(b1.^2. **p. Dth tap output input to D-fold delay output sample update circular delay line (D+1)-dimensional state vector circular pointer index for n=0:199. with unshifted peaks. omega). 1. x). omega)). sD = tap(D. sD. q = 0./ dtft(den1. w = zeros(1. [a2. w. c.m b − cz−D algorithm of the transfer function H(z)= are given below: 1 − az−D 234 235 . beta6] = lheq(-1. 0. length-200 unit impulse impulse response 400 frequencies in [0. cdelay(D. 1). b. q] = combfilt(a1. omega)). 1. angle(H2) * 180 / pi./dtft(a5.5. x) double a. omega) . [b4. 199)].9).7*pi). c. x). q. w. p passed by address as in cfir. 0. D-1). 0. 10^(-12/20). D.m . zeros(1. a6.9). zeros(1. 1). q. c. [b5. dtft(num2. D. a3. end note: h1=y1 } The MATLAB version is the function combfilt. double tap(). it also computes the impulse response of the ﬁrst ﬁlter in two ways: (a) using MATLAB’s function filter and (b) the customized function combfilt. b1.8 The following MATLAB code generates the ﬁrst pair of comb and notch ﬁlters of Example 11. 0. { double s0. -a1]. omega = (0:199)*pi/200. 1. 1/sqrt(2). 10^(9/20). beta2] = combeq(1. x.2*pi). P11. [b2. b. y. wc = 0. sqrt(0.c is an implementation: -c numerator coefﬁcients denominator coefﬁcients frequency response magnitude response phase response in degrees /* combfilt. [b2. c2. for each input sample x do: sD = tap(D. omega) . int D. c1. beta5] = lheq(-1. wc. b. w. zeros(1.

% % It uses cdelay2.m, wrap2.m, tap2.m % based on combfilt.c

⎡ A(Ωpass )= 10 log10 ⎣1 + ε2 stop Ωpass Ωstop

2N

⎤ ⎦ < 10 log (1 + ε2 )= Apass 10 pass

function [y, w, q] = combfilt(a, b, c, D, w, q, x) sD = tap2(D, w, q, D); s0 = x + a * sD; y = b * s0 - c * sD; w(q+1) = s0; q = cdelay2(D, q);

Thus, in either case, the speciﬁcations are more than satisﬁed.

Problem 11.11

The call to the MATLAB function lhbutt.m:

[A, B, P] = lhbutt(1, 40, 10, 15, 3, 35);

It uses the following routine tap2.m that helps extract the components of the circular internal state vector:

% tap2.m - read ith tap of circular delay-line buffer

% % si = tap2(D, w, q, i) % % w = (D + 1)-dimensional % q = circular index into w % delay amount i = 0, 1, . . . , D % based on tap2.c

produces the following cascade matrices 0.5001 ⎢ B = ⎣ 0.3821 0.2765

⎡

0.5001 2 × 0.3821 2 × 0.2765

0 ⎥ 0.3821 ⎦ , 0.2765

⎤

⎡

⎢ A=⎣ 1

1

1

0.0002 0.0007 0.0005

0 ⎥ 0.5279 ⎦ 0.1056

⎤

Thus, the designed transfer function will be:

H(z)=

function si = tap2(D, w, q, i) si = w(rem(q+i, D+1)+1);

% si is delayed output s(n − i)

0.5001(1 + z−1 ) 0.3821(1 + z−1 )2 0.2765(1 + z−1 )2 · · 1 + 0.0002z−1 1 + 0.0007z−1 + 0.5279z−2 1 + 0.0005z−1 + 0.1056z−2

The parameter vector P is:

**P = [Ωpass , Ωstop , εpass , εstop , Nexact , N, Astop , Ω0 , f0 ] = [1, 2.4142, 0.9976, 56.2252, 4.57, 5, 38.26, 1.0005, 10.0030]
**

where Astop is the actual stopband attenuation realized by the designed ﬁlter, and f0 is the 3dB cutoff frequency. The apparent discrepancy between the computed 3-dB frequency and the given 3-dB passband speciﬁcation is accounted for from the fact that the 3-dB frequency Ω0 or f0 is deﬁned to be the frequency where the magnitude squared response drops to one-half its DC value; this is almost a 3-dB drop, but not exactly. By hand, the design is as follows. First, we prewarp the physical frequencies:

Problem 11.9

In the FIR case of designing a lowpass ﬁlter, the limits 1 ± δpass and ±δstop represent the ripples of the (real-valued) frequency response D(ω). These translate to the limits for the magnitude response 1 ± δpass in the passband and [0, δstop ] in the stopband. In the IIR case, the deﬁnitions are motivated by the closed-form expressions of the magnitude response squared in the Butterworth and Chebyshev cases.

Problem 11.10

Because Ωstop > Ωpass , and N ≥ Nexact , we have the inequality

Ωpass = tan Ωstop = tan >1+ ε2 stop

ωpass

2

= tan = tan

πfpass fs πfstop fs

= tan = tan

π10

40

= tan(0.25π)= 1 = tan(0.375π)= 2.4142

ωstop

2

π15

40

Ωstop Ωpass

2N

>

Ωstop Ωpass

2Nexact

=

ε2 stop ε2 pass

⇒

1+

ε2 pass

Ωstop Ωpass

2N

Then, we compute the -parameters:

Thus, using Eq. (11.6.14) we have:

⎡ A(Ωstop )= 10 log10 ⎣1 + ε2 pass Ωstop Ωpass

2N

⎤ ⎦ > 10 log (1 + ε2 )= Astop 10 stop

**εpass = 10Apass /10 − 1 = 103/10 − 1 = 0.9976,
**

and the exact and up-rounded value of N:

εstop = 10Astop /10 − 1 = 1035/10 − 1 = 56.2252

Similarly, if we ﬁx Ω0 by the stopband speciﬁcation, then we have:

**Nexact = Ωpass Ωstop
**

2N

ln(εstop /εpass ) ln(Ωstop /Ωpass )

=

ln(56.2252/0.9976) = 4.57 , ln(2.4142/1.0000)

N=5

Ωpass Ωstop

2N

<

Ωpass Ωstop

2Nexact

=

ε2 pass ε2 stop

⇒

1 + ε2 stop

< 1 + ε2 pass

Then, we calculate the 3-dB Butterworth parameter Ω0 and invert it to get the 3-dB frequency f0 :

Then, using Eq. (11.6.15), we have:

Ω0 =

Ωpass ε1/N pass

=

1

(0.9976)1/5

= 1.0005 ,

f0 =

fs arctan(Ω0 )= 1.0030 kHz π

236

237

The coefﬁcients 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 coefﬁcients of all the sections will not be exactly zero. The Butterworth angles are computed by

Problem 11.14

Using a trig identity, we obtain:

θi =

which gives

π

2N

(N − 1 + 2i)=

π

10

(4 + 2i),

i = 1, 2

**| sin(ω1 + ω2 )| = | sin ω1 cos ω2 + sin ω2 cos ω1 | ≤ | sin ω1 || cos ω2 | + | sin ω2 || cos ω1 | ≤ | sin ω1 | + | sin ω2 | = sin ω1 + sin ω2
**

where we used the inequalities | cos ω1 | ≤ 1 and | cos ω2 | ≤ 1 and the fact that sin ω1 and sin ω2 are non-negative for values of their arguments in the range [0, π]. Thus, the above inequality implies |c| ≤ 1.

θ1 = 0.6π,

θ 2 = 0 . 8π

Problem 11.12

The call to lhbutt.m:

[A, B, P] = lhbutt(-1, 10, 3, 2, 0.5, 35);

Problem 11.15

Here, the Butterworth ﬁlter order is given to be N = 3. Thus, there remains only the parameter Ω0 to be ﬁxed. The normalized passband frequencies are

produces the following cascade matrices

ωpa =

0.3414 0.2454

2πfpa

B=

0.3414 0.2454

−2 × 0.3414 −2 × 0.2454

,

A=

1 1

0.0817 0.0587

0.4471 0.0404

fs

=

2π 2 = 0.2π, 20

ωpb =

2πfpb

fs

=

2π 8 = 0 .8 π 20

Because they add up to π, the bilinear transformation parameter c will be zero, as follows from the equation

Thus, the designed transfer function will be: 0.3414(1 − z−1 )2 0.2454(1 − z−1 )2 H(z)= · 1 + 0.0817z−1 + 0.4471z−2 1 + 0.0587z−1 + 0.0404z−2 The parameter vector P is:

c=

sin(ωpa + ωpb ) sin ωpa + sin ωpb 1 + z−2 1 − z−2

=0

Thus, the bilinear transformation will be here:

**P = [Ωpass , Ωstop , εpass , εstop , Nexact , N, Astop , Ω0 , f0 ] = [0.7265, 1.3764, 0.3493, 3.0000, 3.37, 4, 13.27, 0.9451, 2.5899]
**

where Astop is the actual stopband attenuation realized by the designed ﬁlter, and f0 is the 3-dB cutoff frequency in kHz. The required closed-form expression for part (c) is:

s=

The analog passband frequency will be: c − cos ωpb

Ωpass =

sin ωpb

= − cot ωpb = 1.3764

The εpass parameter is calculated to be:

|H(ω)|2 =

1+

1 cot(ω/2)

2N

**εpass = 10Apass /10 − 1 = 100.5/10 − 1 = 0.3493
**

which implies for Ω0 :

Ω0

Problem 11.13

The real part of s can be expressed as follows: Re s =

Ω0 =

Ωpass ε1/N pass

=

1.3764 = 1.9543 0.34931/3

z∗2 − 2cz∗ + 1 (z2 − 2cz + 1)(z∗2 − 1)+(z∗2 − 2cz∗ + 1)(z2 − 1) z2 − 2cz + 1 1 + = (s + s∗ )= 2(z2 − 1) 2(z∗2 − 1) 2(z2 − 1)(z2 − 1)∗ 2

The coefﬁcients 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,

θ1 =

π

2N

(N − 1 + 2)=

2π 3

⇒

cos θ1 = −0.5

|z|4 − 1 − c(z + z∗ )(|z|2 − 1) (|z|2 − 1)(|z|2 − c(z + z∗ )+1) = = |z2 − 1|2 |z2 − 1|2

where in the last step we factored |z|4 − 1 = (|z|2 − 1)(|z|2 + 1). Because |c| ≤ 1, the second factor of the numerator is non-negative. Indeed, noting that (z + z∗ ) is real-valued, we have:

We ﬁnd for the second-order section:

G0 = 0.6615,

and the fourth-order section:

a01 = 0,

a02 = −0.3230

|c(z + z∗ )| ≤ |z + z∗ | ≤ |z| + |z∗ | = 2|z|

Adding |z|2 + 1 to both sides we get the inequality:

⇒

−2|z| ≤ c(z + z∗ )≤ 2|z|

G1 = 0.5639,

a11 = 0,

a12 = −0.8325,

a13 = 0,

a14 = 0.4230

**resulting in the transfer function:
**

∗

2

|z| −2|z|+1 ≤ |z| −c(z+z )+1 ≤ |z| +2|z|+1

2 2 2

∗

⇒

0 ≤ (|z|−1) ≤ |z| −c(z+z )+1 ≤ (|z|+1)

2 2

H(z)=

0.5639(1 − z−2 )2 0.6615(1 − z−2 ) · −2 1 − 0.8325z−2 + 0.4230z−4 1 − 0.3230z

Therefore, the sign of Re s is the same as the sign of the factor (|z|2 − 1), and the desired result follows.

The 3-dB frequencies are calculated from Eq. (11.6.44) with c = 0. We ﬁnd:

f0a = 1.5054 kHz,

f0b = 8.4946 kHz

238

239

Problem 11.16

We have: 1

Problem 11.18

Ω2 0 Ω2 − 2sΩ0 cos θi + s2 0 Ω2 0 Ω2 − 2 0

1 − z−1 1 + z−1 Matching the stopband speciﬁcations exactly means that the stopband frequencies ωsa , ωsb map onto ±Ωstop and that at Ωstop the attenuation is exactly Astop . The ﬁrst requirement implies 1 − z−1 1 + z−1

2

s2 s 1−2 cos θi + 2 Ω0 Ω0 =

=

=

Ω0 cos θi +

−Ωstop = Ωstop =

which can be solve for c and Ωstop :

c − cos ωsa sin ωsa c − cos ωsb sin ωsb

Ω2 (1 + z−1 )2 0 2 −1 )2 −2(1 − z−1 )(1 + z−1 )Ω cos θ + (1 − z−1 )2 Ω 0 (1 + z 0 i

Ω2 (1 + z−1 )2 0 = 2 Ω0 (1 + 2z−1 + z−2 )−2(1 − z−2 )Ω0 cos θi + (1 − 2z−1 + z−2 ) = Ω2 (1 + z−1 )2 Gi (1 + z−1 )2 0 = 1 + ai1 z−1 + ai2 z−2 (1 − 2Ω0 cos θi + Ω2 )+2(Ω2 − 1)z−1 + (1 + 2Ω0 cos θi + Ω2 )z−2 0 0 0

c=

sin(ωsa + ωsb ) , sin ωsa + sin ωsb

Ωstop =

c − cos ωsb sin ωsb

Given the value of c, we compute next the two candidates for Ωpass :

where the ﬁnal result was obtained by dividing numerator and denominator by the factor (1 − 2Ω0 cos θi + Ω2 ) in order to make the constant coefﬁcient of the denominator unity. 0 The highpass case is obtained by replacing z−1 by −z−1 , which effectively changes the sign of the ai1 coefﬁcient. The bandpass case can be done in a similar, but more tedious, fashion.

Ωpa =

c − cos ωpa , sin ωpa

Ωpb =

c − cos ωpb sin ωpb

Ideally, we would like have Ωpb = Ωpass and Ωpa = −Ωpass . But this is impossible because c has already been ﬁxed. Because the Butterworth magnitude response is a monotonically decreasing function of Ω, it is enough to choose the widest of the two passbands deﬁned above. Thus, we deﬁne:

Problem 11.17

The right 3-dB frequency is obtained by solving the equation

**Ωpass = max |Ωpa |, |Ωpb | c − cos ω0b = Ω0 sin ω0b
**

Once we have computed Ωpass and Ωstop , we design our Butterworth analog ﬁlter; that is, compute N and Ω0 from

Using the trig identities cos ω0b = 1 − tan2 (ω0b /2) , 1 + tan2 (ω0b /2) sin ω0b = 2 tan(ω0b /2) 1 + tan2 (ω0b /2)

Nexact =

ln(εstop /εpass ) ln(Ωstop /Ωpass )

,

N = Nexact ,

Ω0 =

Ωstop ε1/N stop

The above equation reduces to the quadratic equation in the variable t = tan(ω0b /2):

where the equation for Ω0 matches the stopband speciﬁcation exactly. The digital ﬁlter coefﬁcients are then computed in terms of N and Ω0 as usual. The following MATLAB function bpbutt2.m implements the above procedure and is an alternative to bpsbutt.m:

% bpbutt2.m - bandpass Butterworth digital filter design

%

c−

1 − t2 1 + t2 = Ω 0 2t

⇒

(1 + c)t2 − 2Ω0 t − (1 − c)= 0

% [A, B, P] = bpbutt2(fs, fpa, fpb, fsa, fsb, Apass, Astop) % % alternative to bpsbutt.m % it matches stopbands and uses worst passband. % % design parameters: % P = [Wpass, Wstop, Wpa, Wpb, c, fc, epass, estop, Nex, N, Apass, W0, f0a, f0b]; % A,B are Kx5 matrices of cascade of 4th/2nd order sections

1+

t2

which has positive solution:

t=

implying for the 3-dB frequency

Ω0 +

Ω2 0

+ (1 − c)(1 + c)

1+c

**function [A, B, P] = bpbutt2(fs, fpa, fpb, fsa, fsb, Apass, Astop)
**

2 2 fs ⎜ Ω0 + 1 − c + Ω 0 ⎟ arctan ⎝ ⎠ π 1+c

tan

ω 0b

2

= tan

πf0b fs

=

Ω2 + 1 − c 2 + Ω 0 0

1+c

⎛

⎞

c = sin(2*pi*(fsa + fsb) / fs) / (sin(2*pi*fsa / fs) + sin(2*pi*fsb / fs)); fc = 0.5 * (fs/pi) * acos(c); Wstop = abs((c - cos(2*pi*fsb / fs)) / sin(2*pi*fsb / fs)); Wpa = (c - cos(2*pi*fpa / fs)) / sin(2*pi*fpa / fs); Wpb = (c - cos(2*pi*fpb / fs)) / sin(2*pi*fpb / fs);

⇒

f 0b =

The left 3-dB frequency is obtained by replacing Ω0 by −Ω0 in the above solution.

240

241

0.Wi^2) / D. B are Kx5 matrices of cascade 4th/2nd order sections function [A. Nex.W0^2 . A(i+1. a1.m is an alternative to the bandpass Chebyshev type-2 design function bpcheb2. 0.c^2 + 1) + W0)/(c+1)). fsa.c^2 + 1) . W0 = sinh(a) / Wstop. f3b. epass. a1. end for i=1:K. f3b. 0. Astop) 242 243 . 0].1) / (1 + Wi^2). P] = bpcheb2a(fs. b1. fpb.1 + 2 * i) / (2 * N). else B(1. N.0^(Apass/10) . Wpa = (c . fsa. ceil(Nex). estop. estop = sqrt(10. Apass. D = 1 . 1].:) = [1.r) / 2. epass. b2. fpa. f0a. a1 = 4 * c * (W0 * cos(th) . 0. th = pi * (N . ceil(Nex).:) = [1. a2.r) / 2. Wpa. f3a = (fs/pi) * atan((sqrt(W3^2 . Nex. 1]. c. B. end for i=1:K. Apass = 10 * log10(1 + (Wpass/W0)^(2*N)). 0]. a1. G = W0 / (1 + W0).1). fpb. a2 = (1 . if r==1. a4]. W3 = Wstop / cosh(acosh(estop)/N). 0. rem(N. a1.W0) / (1 + W0). Wpb. c. 0. P] = bpcheb2a(fs. A(1. the function bpcheb2a. fsb. 0.W0)/(c+1)). c = sin(2*pi*(fsa + fsb) / fs) / (sin(2*pi*fsa / fs) + sin(2*pi*fsb / fs)).W3)/(c+1)). a2 = 2 * ((2*c*c + 1)*(W0^2 + Wi^2) . A(1. a4 = (1 + 2 * W0 * cos(th) + W0^2 + Wi^2) / D. 0. B.m: % bpcheb2a. estop = sqrt(10. Wpb. a1 = -2 * c * W0 / (1 + W0).:) = G * [1. c. a3.cos(2*pi*fpb / fs)) / sin(2*pi*fpb / fs). 0. b1. f0b]. 0. Wpb. a]. A(i+1. estop.m % matches stopbands instead of passbands % % design parameters: % P = [Wpass.4 * c * (W0 * cos(th) + 1) / D. Wi = sin(th) / Wstop. f3a. a4]. B(i+1. B(i+1. 0]. else B(1. (N . f3a. 0.4 * c * Wi^2 / (1 + Wi^2). a2. P = [Wpass.0^(Apass/10) . 0. Wpb = (c . N.Wpass = max(abs(Wpa). a1 = 4 * c * (W0 * cos(th) . B(1.0^(Astop/10) .alternative bandpass Chebyshev type 2 digital filter design % % [A. N. 0]. if r==1. rem(N. Nex N = r = K = = log(estop/epass) / log(Wstop/Wpass). W0. b1 = . 0.:) = [1. 0. Wpass = max(abs(Wpa). abs(Wpb)).4 * c * (W0 * cos(th) + W0^2 + Wi^2) / D. -2. a2. a2 = -(1 . P = [Wpass.2).1 + 2 * i) / (2 * N). end a = asinh(estop) / N. th = pi * (N . D = 1 . fpa. G = 1 / (1 + W0). fsb. (N .:) = [1.:) = G * [1.cos(2*pi*fpa / fs)) / sin(2*pi*fpa / fs). Astop) % % alternative to bpcheb2. f0a = (fs/pi) * atan((sqrt(W0^2 . Wstop. epass = sqrt(10. 0. Wstop. abs(Wpb)). epass.W0^2) / D.1) / D. -1. f0b = (fs/pi) * atan((sqrt(W0^2 . B(1. epass = sqrt(10. 0.1). fc. a1 = -2 * c / (1 + W0). Wpa. Apass. W0 = Wstop * (estop^(-1/N)). 0. Wpa. 0. f3b = (fs/pi) * atan((sqrt(W3^2 .cos(2*pi*fsb / fs)) / sin(2*pi*fsb / fs)). Wstop. a]. Nex N = r = K = = acosh(estop/epass) / acosh(Wstop/Wpass). a2. A(1.1) / D. 0].1).2 * W0 * cos(th) + W0^2. end % reciprocal of text Similarly. Nex. a2 = 2 * (2*c^2 + 1 . a3 = .:) = [1. % A. 0]. b2 = 2 * (Wi^2 * (2*c*c+1) . a3. A(1.0^(Astop/10) . Wstop = abs((c . 0]. G = W0^2 / D.1).:) = [1. 0. estop.c^2 + 1) + W3)/(c+1)).:) = [1. a3 = .:) = G * [1. G = (1 + Wi^2) / D.2 * W0 * cos(th) + W0^2 + Wi^2.:) = [1.W0) / (1 + W0). a4 = (1 + 2 * W0 * cos(th) + W0^2) / D. 0].c^2 + 1) . Apass.:) = G * [1.m . -1.2). 0.

"r")) == NULL) { fprintf(stderr.c .c . { int i. double y. } single 4th-order section = (1 + z−1 )2 +Ωi −2 (1 − z−1 )2 −1 )2 −2Ω−1 cos θ (1 − z−1 )(1 + z−1 )+(Ω−2 + Ω −2 )(1 − z−1 )2 (1 + z i i 0 0 A.IIR filtering in cascade of fourth-order sections */ double sos4().c implement the sample-by-sample processing algorithm of the cascade of fourth-order sections: /* sos4.dat >y. "Can’t open filter file: %s\n".a[1]*w[1] . w). } and 244 245 . could replace these updates by the single call to delay(4. 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. i++) y = sos4(A[i].a[2]*w[2] . double **A. i. argv[2]).m.m. i<K. coefﬁcient ﬁles temporary coefﬁcient array allocation and increment if (argc != 3) { fprintf(stderr. m. b. double cas4(K. A. for (i=0. j. w[2]. y. **B.dat <x.m. w[4] w[3] w[2] w[1] = = = = w[3]. The transformation of the analog second-order sections is as follows: 1 + Ωi −2 s2 − 1 − 2Ω−1 cos θi s + (Ω0 2 + Ωi −2 )s2 0 /* cas4. y = x. w[0] = x . x) int K. exit(0). { double y. W are K×5 matrices = = (1 + Ωi −2 )+2(1 − Ωi −2 )z−1 + (1 + Ωi −2 )z−2 − − (1 − 2Ω−2 cos θi + Ω−2 + Ωi −2 )+2(1 − Ω−2 − Ωi −2 )z−1 + (1 + 2Ω0 2 cos θi + Ω0 2 + Ωi −2 )z−2 0 0 0 Gi (1 + bi1 z−1 + z−2 ) 1 + ai1 z−1 + ai2 z−2 initial input to ﬁrst SOS4 where the ﬁnal step follows by dividing the numerator by the factor (1 + Ωi −2 ) and the denomi− nator by (1 − 2Ω0 2 cos θi + Ω−2 + Ωi −2 ). y). *w.c which is analogous to casfilt. } if ((fpa = fopen(argv[1]. Problem 11.15 and which reads A and B dynamically from the command line: /* casfilt4. "r")) == NULL) { fprintf(stderr. x. argv[1]). and can be passed as inputs to the above C functions.h> #include <stdio.20 The s-domain poles are si = Ωpass sinh a cos θi + jΩpass cosh a sin θi = Ω0 cos θi + jΩi cosh a It follows that The K × 5 matrices A and B are generated by the ﬁlter design MATLAB functions. B. or bscheb2.c .a[3]*w[3] .c and cas4.dat B. double *a.a[4]*w[4]. w are 5-dimensional a[0]= 1 always void main(int argc. "Usage: casfilt4 A. **W. x) double *a. **B.21 The following C functions sos4. x.Problem 11.h> #define MAX 64 initial allocation size |si |2 = Ω2 cos2 θi + Ωi 2 cosh2 a = Ω2 (1 − sin2 θi )+Ωi 2 (1 + sinh2 a) 0 0 = Ω2 + Ωi 2 + (Ω2 sin2 θi − Ωi 2 sinh2 a)= Ω2 + Ωi 2 0 0 0 where the last two terms canceled because Ω0 sin θi = Ωpass sinh a sin θi = Ωi sinh a double cas4(). int max = MAX. "Can’t open filter file: %s\n". W. exit(0). } a = (double *) calloc(max + 1. B. exit(0). w[1]. *b. dmax = MAX. return y. sizeof(double)). char **argv) { FILE *fpa. bpcheb2.dat\n"). w.19 We work with the type-2 design since it has more complicated numerator. w[0]. B[i]. **W.IIR filtering in cascade of fourth-order sections */ #include <stdlib. K. *fpb. 0 output of ith section ﬁnal output from last SOS4 Problem 11.IIR filtering by single (canonical) fourth-order section */ double sos4(a.c of Problem 7. a. return y. b. } if ((fpb = fopen(argv[2]. W[i]. double **A. such as bpsbutt. int M. x. y = b[0]*w[0] + b[1]*w[1] + b[2]*w[2] + b[3]*w[3] + b[4]*w[4].

[A5. 1. 10).m of Problem 7. 2. B. W. 4. w. P6] = bpsbutt(1. while(scanf("%lf". A. 4. [y(n). w. w). 20. y). i++) { A[i] = (double *) calloc(5. B2. a + M) == EOF) break. w] = sos4(b. b3. B = (double **) calloc(K. Apass. x) [K. Astop). x).22 The following MATLAB code designs the pairs of lowpass. B. y). b1. W] = cas4(K. x) % % b = [b0. i++) for(j=0. x) w(1) = x . P3] = lhbutt(-1. W] = cas4(K. A. W. W = zeros(K. } else number of SOS4 K = M / 5. exit(0).cascade of fourth order sections % % [y. Astop). 2.fourth order section % % [y. i<K. sizeof(double)). B. sizeof(double *)). for(i=0. x(n)).cascade of fourth-order sections % % y = casﬁlt4(B. W] = cas4(K. j<5. 0. j<5. a. A. W[i] = (double *) calloc(5. W(i. stringent case lowpass lowpass highpass highpass bandpass bandpass function [y.15: % casfilt4. A(i. and bandstop Butterworth ﬁlters. i<K. a2. B5. } for(i=0. and shows how to compute the phase response and impulse response of one of the ﬁlters (the ﬁrst bandpass ﬁlter): Apass = -10*log10(0. 20. N] = size(x). for n = 1:N. P5] = bpsbutt(1. &x) != EOF) { y = cas4(K.5). for i = 1:K. 10). 1. [N1.for (M=0. [y. } if (fscanf(fpa. 0.02). 5. Astop). B[i] = (double *) calloc(5. sizeof(double *)).:).5. 0. P1] = lhbutt(1. x) y = x.5. } a = (double *) realloc((char *) a. 4.5. } } allocate K rows states of each SOS4 each row is 5-dim % cas4. Apass. 4.m .5. 4. w = delay(4. j++) fscanf(fpb. B4. "%lf".a(2:5) * w(2:5)’. w1.5. P2] = lhbutt(1. 4. W. w2. i++) for(j=0. B1. a4] = 5-dim denominator (row vector) % w = [w0. b4] = 5-dim numerator (row vector) % a = [1.m . B6. P4] = lhbutt(-1. x) % % B = Kx5 numerator matrix % A = Kx5 denominator matrix % W = Kx5 state matrix % x = scalar input % y = scalar output function [y. x) % % B = Kx5 numerator matrix % A = Kx5 denominator matrix % x = row vector input % y = row vector output form A matrix read B matrix function y = casfilt4(B. 20. [A2. a. 4.:)] = sos4(B(i. A. (M + 1) * sizeof(double)). y = b * w’. w4] = 5-dim ﬁlter state (row vector) % x = scalar input % y = scalar output Problem 11. K1] = size(A). a = (double *) realloc((char *) a. "%lf".:).98). for (i=0. w3. A.m . 20. 5. W. printf("%lf\n". M++) { if (M == max) { max += dmax. a1. j++) A[i][j] = a[5*i + j]. sizeof(double)). i<K. A = (double **) calloc(K. It is analogous to casfilt. 5. [A6. 4. 20. B. The MATLAB version of cas4: 246 247 . W(i. b2. B3. end The MATLAB version of casfilt4 for ﬁltering of a long input vector is as follows. bandpass. if (M%5 != 0) { fprintf(stderr. (max + 1) * sizeof(double)). w] = sos4(b.:). 10). end process input samples The MATLAB version of sos4 is as follows: % sos4. a3. sizeof(double)).5. A.5. W = (double **) calloc(K.. [A1. Astop = -10*log10(0. [A3. 20. "all rows of A must be 5-dimensional"). Apass. [A4. 5. highpass. B[i] + j). sizeof(double *)).

0. P1] = lhcheb1(1. P2] = lhcheb1(1. P7] = bpsbutt(-1. Problem 11. h5 = casfilt4(B5.5. 10)./ dtft(a7. 4. P11.5./dtft(a5. 2. 20. 4. 20. zeros(1. H5 = dtft(b5. 200 frequencies in [0. Astop). 5. 4. 20. 99)]. Astop). 0. Note that the Chebyshev phase response is not as linear within its passband. 200 frequencies in [0. 10). highpass. [A8. 4. P11. B8. [A8. 0.5. B7. b7 = cas2can(B7). P8] = bpsbutt(-1. 4. om).3 Phase and impulse responses of (the less stringent) bandpass ﬁlter of Problem 11. x). B5.23 The following MATLAB code designs the pairs of lowpass. stringent case LP type 1 LP type 1 HP type 1 HP type 1 LP type 2 LP type 2 BP type 2 BP type 2 248 249 . 10). om).5. 4. [A6. Note. 10). x = [1.5. om).5. P6] = lhcheb2(1. [A5. Astop). argH7 = angle(H7) * 180 / pi.5. Notice how the phase response is almost linear within its passband. 20. 20. [A7. B10. Apass. Apass.02). Apass. [A10. B3. 2. [A1. 20. h7 = casfilt4(B7. 0. B4. Apass. 4. 4. 4. 10). 2. Apass. om) . P11.5. P9] = bscheb2(20. and shows how to compute the phase response and impulse response of one of the ﬁlters (the ﬁrst bandpass ﬁlter): Apass = -10*log10(0.5. 5. P10] = bscheb2(20. π] bandpass case frequency response phase response (in degrees) length-100 unit impulse impulse response bandstop bandstop [A9. 10). 1.5. 5.4 Phase and impulse responses of (the less stringent) bandpass ﬁlter of Problem 11. 1. x = [1. 2. x). B8. P7] = bpcheb2(20. Fig. B7. B6. 1. x). 4. 1. B1. 20. B2. P8] = bpcheb2(20. 4.5. H7 = dtft(b7.22. 4. [A2. P3] = lhcheb1(-1.23.5. A5. Fig. 5. π] bandpass case frequency response phase response (in degrees) length-100 unit impulse impulse response BS type 2 BS type 2 conventional method. y7 = filter(b7. a7. [A4.98). 0. 4. Astop = -10*log10(0. Note. Astop). Apass.5. 2. a5. A7.5.5. om = (0:199) * pi / 200. a7 = cas2can(A7). 1. bandpass. x).5. 5. y5 = filter(b5. P5] = lhcheb2(1. a5 = cas2can(A5). Astop). y5=h5 conventional method. 5. 0. b5 = cas2can(B5). zeros(1. 2. argH5 = angle(H5) * 180 / pi. 4. B9. and bandstop Chebyshev ﬁlters.5. P4] = lhcheb1(-1.[A7. 4. 20. 4. om = (0:199) * pi / 200. Astop). 1. 4. [A3.3. 99)]. The computed phase and impulse responses are shown in Fig. y7=h7 The computed phase and impulse responses are shown in Fig. 4.4. P11.5.

90 − 0. The two polyphase subﬁlters are deﬁned by Eq.64.64 − 0.21.13z2 + 0. πk /2 −4 ≤ k ≤ 4 n′ 2n-2 2n 2n+2 2n+4 h = d = [0. x(n).64 0 −0. 0. xup (2n).55.64z −2 −2 − 0. 0] h1 = d1 = [−0.21. that is.21 0 1 2 3 -0. which is recognized as the double-sided ζ -transform of the sequence d given in Eq.64z −1 −1 + 0.21z + 0. −0. M=2.21 0 0.90ζ 4 + 0. 0.21 4 k′ −1 −1 Fig. 0.21] 250 251 . 0.21(ζ 6 + ζ −6 )−0.18) can be cast in a compact matrix form: H3 (z) = −0. 0. P12.15).90 − 0. P12. 1. 0. −0. 1. 1. xup (2n). −0. 0. The two subﬁlters act on the time-advanced (by M = 2) low-rate input samples {x(n + 2). L = 2 and we choose M = 2.18ζ 8 + 0.1 Length-9 symmetric impulse response of 2-fold FIR interpolator. as shown in Fig.21. P12.1 on each of the contributing low-rate samples −2 (−0.13 + 0.13ζ + 0. −0. we obtain the transfer function D(ζ). The Hamming windowed version of the ﬁlter is obtained by multiplying the full length-9 ﬁlter response h by a length-9 Hamming window.1): ⎡ yup (2n) yup (2n + 1) = 0 −0. so that N = 2LM + 1 = 9.05] di (k)= d(2k + i).21 + 0. Di (z) and Hi (z)= z−2 Di (z).55. xup (2n + 2).2.05.18z + 0. 1. 0.30z H2 (z) = −0.18z−1 D2 (z) = −0. The ideal impulse response is: d(k )= or.64 D0 (z) = 1 D1 (z) = −0. + ζ −3 (−0.2 In this case. 0.10). −2 ≤ k ≤ 1 They can be extracted from h by taking every second entry. N=9 0. −0.21ζ + 0. (12.05.2) will be: d(k′) 1 L=2.Chapter 12 Problems Problem 12. −0.18ζ 8 4 8 4 −4 ) These ﬁltering equations can also be obtained by superimposing the symmetric impulse response of Fig. P12.4. for i = 0. (12.2.18z −3 − 0.30z + 0. (12. The resulting impulse response will be: h = [0.64 1 0.30ζ + 0. i = 0.55. 0.18 + 0.55.2. x(n − 1)}.90(ζ + ζ −1 )+0.21z 2 2 -4 -3 -2 -1 -0. 0 ] The corresponding polyphase subﬁlters are obtained by extracting every second entry: h0 = [0.64. {xup (2n + 4). xup (2n − 2)}.64(ζ 2 + ζ −2 )+0.90z−1 + 0.21 xup (2n + 4) ⎢ x (2n + 2) ⎢ up ⎢ ⎣ xup (2n) xup (2n − 2) ⎤ ⎥ ⎥ ⎥ ⎦ D(ζ)=D0 (ζ 4 )+ζ −1 D1 (ζ 4 )+ζ −2 D2 (ζ 4 )+ζ −3 D3 (ζ 4 ) =1 + ζ +ζ −1 (−0.30z−2 − 0.64z + 0.05.90z + 0. xup (2n − 2)} and adding up their contributions at each of the intermediate sampling instants 2n + i. 0 ] It is depicted in Fig.13(ζ 7 + ζ −7 ) xup(2n-2) xup(2n) yup(2n+1) xup(2n+2) xup(2n+4) Problem 12.90z + 0. 0.18(ζ 5 + ζ −5 )−0. x(n + 1).30(ζ 3 + ζ −3 ) − 0.2. corresponding to Eq.64. Equations (12.64.1. numerically.2. 0.4. 0. 1.1 The low-rate transfer functions.64 0.2 Superposition of impulse responses.64 − 0. xup (2n + 2).13ζ −4 ) =1 + 0. sin(πk /2) . starting with the ith entry: h0 = d0 = [0.64ζ + 0.30 − 0. 0. P12. Fig.21z−3 The interpolated samples between x(n)= xup (2n) and x(n+ 1)= xup (2n+ 2) are calculated from Eqs.13z H0 (z) = z−2 H1 (z) = −0. (12.13z−3 Setting z = ζ 4 and using Eq. or. (12.18).21ζ −4 ) {xup (2n + 4). D3 (z) = −0.30 − 0. 1. 0] h1 = [−0.

02 xup (3n − 3) ⎡ ⎤ ⎥ ⎥ ⎥ ⎦ -0.32. 0. 1. 0] h1 = d1 = [−0.2. 0. −2 ≤ k ≤ 1 They can be extracted from h by taking every third entry.32 0. The ideal impulse response is: sin(πk /3) d(k )= . −0.83.4 For interpolation factor L = 4 and ﬁlter length N = 25. 2.4. 0. 0.55 0 −0. 0. 0] h1 = [−0. −0. 0. as shown in Fig.17.02 −0.21. numerically. we have L = 3 and choose again M = 2.The interpolation equations will be in this case: ⎡ yup (2n) yup (2n + 1) = 0 −0.17 −0.18) can be cast in a compact matrix form: N = 2LM + 1 ⇒ M = (N − 1)/2L = (25 − 1)/8 = 3 ⎤ ⎡ yup (3n) 0 ⎥ ⎢ ⎢ ⎣ yup (3n + 1) ⎦ = ⎣ −0.83. −0.32 k′ ⎤ xup (3n + 6) 0 ⎢ ⎥ ⎢ xup (3n + 3) −0.32. x(n − 1)}. N=13 ⎡ ⎤ ⎡ yup (3n) 0 ⎢ ⎥ ⎢ ⎣ yup (3n + 1) ⎦ = ⎣ −0. and d is the symmetric one. 0. P12. 0. 2. P12. P12. −0.17. xup (3n). that is. 0] where h is the causal version. 0. 0. P12.32.4 Superposition of impulse responses. with time origin at the middle of the vector. we ﬁnd: Fig.41. 0] The corresponding polyphase subﬁlters are obtained by extracting every third entry: h0 = [0.78. i = 0. h = d = [0.17 -3 -2 -1 -0. −0. 0.21 0 1 2 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.17 xup (3n − 3) ⎡ ⎤ ⎥ ⎥ ⎥ ⎦ Thus.2. {xup (3n + 6). x(n+1). xup(3n-3) xup(3n) yup(3n+1) xup(3n+3) xup(3n+6) −6 ≤ k ≤ 6 n′ 3n-3 3n 3n+3 3n+6 Fig. The length-25 ideal interpolation impulse response is calculated from: d(k )= sin(πk /4) .2.32. (12.06] h2 = [−0. 0. 0. (12.3 Length-13 symmetric impulse response of 3-fold FIR interpolator.21 5 6 L=3.06 ⎦ ⎢ ⎣ xup (3n) −0. 0.21 yup (3n + 2) ⎡ 0 0. −0. 0. πk /3 or. The resulting impulse response will be: h = [0. 1. −0. 1.3 on each of the contributing low-rate samples {xup (3n + 6). or. xup (3n + 3). 0. 0.21] h2 = d2 = [−0.83 1 0.78.41 -6 -5 -4 -0. xup (3n − 3)}.83 0.21.17] The interpolated samples between x(n)= xup (3n) and x(n + 1)= xup (3n + 3) are calculated from Eqs.06. 0.83 0.83 0. M=2.41.06.17 Problem 12. xup (3n). 0. P12. All three subﬁlters act on the time-advanced (by M = 2) low-rate input samples {x(n+2).83. xup (3n − 3)} and adding up their contributions at each of the intermediate sampling instants 3n + i.02] The interpolation equations will be in this case: di (k)= d(3k + i). 0.18).3 For the case of a 3-fold interpolator. x(n). with time origin at the left of the vector.41 4 3 -0. d(k′) 1 0. xup (3n + 3).78 0. The three polyphase subﬁlters are deﬁned by Eq.06 yup (3n + 2) 0 0.06. 1.83. corresponding to ﬁlter length N = 2LM + 1 = 13. −0. −0.41 ⎤ xup (3n + 6) 0 ⎢ ⎥ ⎢ xup (3n + 3) −0.78 1 0. −0.41 0.21.02.02.78. 0. This impulse response is shown in Fig. 1. −0. 1.21 ⎦ ⎢ ⎣ xup (3n) −0. πk /4 for − 12 ≤ k ≤ 12 This generates the numerical values: 252 253 .10). Problem 12. 0.05 0 0. for i = 0.78. starting with the ith entry: h0 = d0 = [0.3. Equations (12. 0. The Hamming windowed version of the ﬁlter is obtained by multiplying the full length-13 ﬁlter response h by a length-13 Hamming window.17.41.02.55 1 0.41. we use 3 low-rate samples above and three below every interpolated value to be computed.

13 This impulse response is shown in Fig. if (argc != 4) { x(n + 1) x(n) ideal interpolation ﬁlter Problem 12. 1. 0.5 (where the values have been rounded to 2-digit accuracy for convenience. 0. double d(). (12. *y.30 0. ⎡ ⎡ X 0.21 0. (12.000. 0.100 ⎥⎢ 0. P12.300 0. 0.64 0.000. M=3.21 -0.000.h> #include <math. Z} interpolated between C and D are calculated by convolving d with the upsampled low-rate samples.13 0. C.08 -0.900. 0.212 −0.129 ⎤⎢ ⎢ ⎢ 0.100.64 0.c . 0. double dot(). pi = 4 * atan(1.dat = file containing low-rate input samples yhigh.1.13 0.18 F -0.11.08 0.129 −0. *w. and add up the results.100. −0.13 0.000. 0.10 0.3. P12.2.) d(k′) 1 0. This procedure is shown in Fig.082.5 The ideal 3-fold interpolation case with M = 2.212.dat > yhigh.900 0. N=25 0.180 −0. using Eq. 0.127.90 0.3.6 The following complete C program interp. void main(int argc. 12.4. 0. 0. 0.L-fold FIR interpolator (rectangular and Hamming window design) Usage: hamm L M interp hamm L M < xlow.D CX d= [ 0. P.900 0.18 -0.18 k′ Z D Fig.212. **h. Given 2M = 6 low-rate samples {A.127 ⎦ ⎢ ⎢ ⎢ 0. order = P = 2M- xlow. −0.082 ⎢ ⎥ ⎢ ⎣ Y ⎦ = ⎣ 0.0).19): 254 255 .10 -0.h> #include <stdlib. The corresponding linear combinations of low-rate samples are precisely those of Eq.637 0. we position the impulse response d at the three successive positions.6 Interpolated values are calculated by the ﬂip-and-slide form of convolution. was discussed in Problem 12.180.30 L=4.13 n′ -0.180 0.900.90 E F 0. −0.3.10 -12 0.000.08 n′ -0. hamm. E.129.300 −0. 0. Using the ﬂip-and-slide form of convolution as in Fig. B A 0.13 -0.000 ] 0. 0. 12.64 0. double x. P12.300.21 C B E 0.127. read off the values of d(k ) where it intersects with the low-rate samples.18 D C B A 0. L.c implements the polyphase sample-by-sample processing algorithm of Eq.dat = file containing high-rate interpolated output samples ⎤ ⎡ yup (3n) 0 ⎥ ⎢ ⎢ ⎣ yup (3n + 1) ⎦ = ⎣ 0 0 yup (3n + 2) ⎡ 0 1/ 3 2/3 1 2/3 1/3 ⎤ x(n + 2) 0 ⎢ ⎥ ⎢ x(n + 1) 0 ⎦⎢ ⎣ x(n) 0 x(n − 1) ⎡ ⎤ ⎥ ⎥ ⎥= ⎦ 1/3 2/3 2/3 1/3 #include <stdio. −0.20) and the initialization procedure of (12. P12.6.082 ⎢ ⎣ F E D C B A ⎤ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎥ ⎦ Problem 12. 0. For the linear interpolator. M. B.2.000. D. char ** argv) { int i.64 Y E F 0.7).212 −0.h> void delay().637.30 0.21 -0.30 0. F} as shown in Fig.1. the three values {X. They may be rewritten in the polyphase matrix form (with the low-rate samples listed from the latest down to the earliest): 0.dat = 0/1 for rectangular/Hamming window = interpolation factor = half-length of polyphase subfilters (length = 2M.10 n′ Fig. (12.127 Z 0.637.100 ⎤ ⎡ −0.300. Y.13 -0. −0.08 12 -4 -3 -2 -1 0 1 2 3 4 -0.13 -0.129.90 A 0.180.082.90 0. 0. we have: /* * * * * * * 1) * * */ interp. n. −0.3).637 0.5 Length-25 symmetric impulse response of 4-fold FIR interpolator. so that N = 2LM + 1 = 2 · 3 · 2 + 1 = 13. 0.

(12. The following program cinterp. k) . k) int L. L. L is the interpolation factor. double x. computes the high-rate interpolated samples. initialize state w by reading ﬁrst M low-rate input samples while(scanf("%lf".c ideal interpolation ﬁlter ith interpolated output sample and write it into stdout update low-rate delay line hamm L M < xlow. y[i]).c is the circular-buffer version of inkeep reading low-rate samples till EOF terp. w = (double *) calloc(2*M. n++) rectangular window if (hamm == 0) h[i][n] = d(L."where: hamm = 0/1 for rectangular/hamm window\n"). } delay(P. initialize by Eq. *p. L*n+i-L*M) * (0." xlow.dat input-off transients zero input circular version of dot. { double t. P.c */ #include <stdio. 256 257 . y[i]). y = (double *) calloc(L. w).46*cos((L*n+i)*pi/(L*M))). The program designs the windowed length-N interpolation ﬁlter and then reads the low-rate input samples sequentially from a ﬁle xlow.2. i++) { y[i] = dot(P. L = atoi(argv[2]).dat\n\n"). (12. sizeof(double)).1." L fprintf(stderr.20) ith interpolated output sample and write it into stdout update low-rate delay line /* cinterp. double d().54 . char ** argv) { int i.dat for (i=0. sizeof(double)). return (sin(t)/t). double cdot(). void main(int argc. n<2*M.ideal L-fold interpolation coefficients */ The program interp.fprintf(stderr.dat = file for high-rate interpolated output samples\n"). fprintf(stderr.c: process by Eq. the rectangular and Hamming window design of the impulse response may be replaced easily by a Kaiser design.0).h> #include <stdlib. i++) h[i] = (double *) calloc(2*M. i<L. M = atoi(argv[3]).c uses a linear-buffer version of the low-rate delay line used by all the polyphase subﬁlters. printf("%. else { t = pi * k / L." M fprintf(stderr. pi = 4 * atan(1. h[i]. *y. i++) { y[i] = dot(P.0). } for (n=0.19) where the parameter hamm speciﬁes a Hamming or rectangular window. } delay(P. pi = 4 * atan(1.12lf\n"."\nUsage: cinterp fprintf(stderr.h> void cdelay(). for (i=0."\nUsage: interp hamm L M < xlow. = 0/1 for rectangular/hamm window\n").dat > yhigh. allocate low-rate internal state double d(L. n++) { w[0] = 0. if (k == 0) return (1.dat or stdin. and writes them to the ﬁle yhigh.*/ /* d(L. polyphase ﬁlter order allocate L subﬁlters each of length 2M allocate L polyphase outfprintf(stderr. *w. if (argc != 4) { fprintf(stderr. else { if (k%L == 0) return (0. fprintf(stderr. so that the total ﬁlter length is N = 2LM + 1. Each low-rate input generates L high-rate outputs." xlow. hamm. = file for low-rate input samples\n"). i++) construct polyphase subﬁlters for (n=0. for (i=0. n<M."where: hamm fprintf(stderr. Inside the program. wrap(). w + i). i<L. i<L. for (i=0. L*n+i-L*M)." yhigh.dat\n\n").2.c .dat or to the stdout." M = half-length of polyphase subfilters\n"). h = (double **) calloc(L. w). } hamm = atoi(argv[1]). Hamming window else h[i][n] = d(L. n. h[i]. for (i=M.dat > yhigh. M. } } } d(0) = 1 d(k) vanishes at non-zero multiples of L typical sin x/x impulse response The program has usage: interp hamm L M < xlow. w).0. = half-length of polyphase subfilters\n"). i--) scanf("%lf"." L = interpolation factor\n"). i<L. i>=1.h> #include <math.0). **h. fprintf(stderr. } } /* -------------------------------------------------------. w).dat = file for low-rate input samples\n"). = interpolation factor\n"). fprintf(stderr.12lf\n". sizeof(double)). exit(0). k. &x) != EOF) { w[0] = x. sizeof(double *)). printf("%.0).circular-buffer version of interp. and M is the half-length of the polyphase subﬁlters.dat > yhigh.0. fprintf(stderr. P = 2*M .

for (i=0. k) . 1. { int i. p. Hamming window else h[i][n] = d(L. int P.19) and (12.dat = file for high-rate interpolated output samples\n"). { double t.2. (P12. m) for i = 0. typical sin x/x impulse response /* -------------------------------------------------------. y[i]). w. . P = 2*M ." exit(0). double cdot(P.46*cos((L*n+i)*pi/(L*M))). k.0. w. p).circular version of dot.12lf\n". . initialize by Eq. i=0. } } /* -------------------------------------------------------.*/ /* d(L. . i++) { y[i] = cdot(P. The upsampled versions of these inputs. yhigh. xup (n ). . h. P12. w. p). *w. L − 1 compute output of ith ﬁlter: yi = dot(P. for (y=0. else { t = pi * k / L. } hamm = atoi(argv[1]). else { if (k%L == 0) return (0. computes dot product of h with current internal state vector pointed to by pointer p for (i=0.7 together with the corresponding interpolated output signals yup (n ). i++) y += h[i] * tap(P. &p).2) } while(scanf("%lf". k) int L. The circular-buffer version of Eqs.12lf\n". i>=1. 258 259 . } cdelay(P.c */ double tap(). p).0). (P12. h. P determine internal states: sm = tap(P. i). *p. sizeof(double)). & p) and for each low-rate input sample x do: (P12. 1.ideal L-fold interpolation coefficients */ double d(L. computed by the length-17 Hamming windowed version of the interpolation ﬁlter. w. printf("%. L*n+i-L*M). sizeof(double *)). return y. h = (double **) calloc(L. can be stated as follows: for m = M down to m = 1 do: read low-rate input sample x ∗p = x cdelay(P. p. w. return (sin(t)/t). w.54 . w. pi = 4 * atan(1. hi . sizeof(double)). L = atoi(argv[2]). i<L.2) The length-17 rectangular and Hamming windowed ﬁlters for this problem were derived in Section 12.1) input-off transients zero input circular version of dot() and write it into stdout update low-rate delay line ∗p = x for m = 0. &p). y = (double *) calloc(L. double y.1.0). } for (n=0. (12. printf("%. & p) (P12. . h[i]. } } } d(0) = 1 d(k) vanishes at non-zero multiples of L polyphase ﬁlter order allocate L subﬁlters each of length 2M allocate L polyphase outfprintf(stderr.c. implemented by cinterp. are shown in Fig. &p). w. } cdelay(P. . h[i]. p) . n++) rectangular window if (hamm == 0) h[i][n] = d(L. i++) h[i] = (double *) calloc(2*M.1. keep reading low-rate samples till EOF beginning of state vector circular version of dot() and write it into stdout update low-rate delay line It uses a circular pointer p that circulates over the low-rate buffer w.4. y[i]).c. p = w.20). n++) { *p = 0. for (i=0. n<M. w.fprintf(stderr. i<=P. M = atoi(argv[3]).0.*/ allocate low-rate internal state initialize circular pointer /* cdot(P. n<2*M.2. i<L. s) cdelay(P. w. The given inputs were processed by interp. w = (double *) calloc(2*M.1) for (i=M. for (i=0. } initialize state w by reading ﬁrst M low-rate input samples process by Eq. i++) { y[i] = cdot(P. i--) { scanf("%lf". . w. i<L. i<L. cdelay(P. &x) != EOF) { *p = x. if (k == 0) return (1. L*n+i-L*M) * (0.0). sizeof(double)). i++) construct polyphase subﬁlters for (n=0. . p) double *h.

P12. we designed the ﬁlters with stopband attenuations A0 = A1 = 80 dB.54 = N Rsingle 260 261 . H1 (f ) are shown in Fig. H1 (f ) are shown in Fig.50 Rsingle L1 L0 − 1 Thus. have Kaiser lengths: N0 − 1 = and are rounded up to: L0 D = 80.27.9 Combined ﬁlter H0 (f )H1 (f ). which compares well with the approximation: L0 Rmulti 1 = + ΔF = 0.8. Δf = 5 kHz.11.10 4x2=8-fold oversampling ﬁlter. Similarly. shown in Fig. P12. and A = 80 for all the stages.08 ΔF Fig. N = 337 = 2LM + 1 = 16M + 1 ⇒ M = 21 fs 4 H0 4fs 2 8fs H1 The 2×4 multistage ﬁlters. The relative computational rate is in this case: N0 = 85 = 2L0 M0 + 1 = 4M0 + 1 N1 = 49 = 2L1 M1 + 1 = 8M1 + 1 The relative computational rate will be ⇒ ⇒ M0 = 21 M1 = 6 N0 + N1 F0 Rmulti = 0.14 F0 − 1 2−1 Fig. the multistage realization requires only 54 percent the cost of the single-stage one.7 We start with fs = 40 kHz.fs 2 H0 2fs 4 8fs H1 Fig. and individual ﬁlters H0 (f ). Problem 12. H1 (f ). P12.70 = Rsingle N The combined ﬁlter Htot (f )= H0 (f )H1 (f ) and the superimposed plots of the ﬁlters H0 (f ). we found that in order to keep the overall stopband attenuation Rmulti N0 + N 1 F0 = 0. shown in Fig. P12.10. The effective single stage ﬁlter will have Kaiser length: N−1= which is rounded up to: DL = 321. ΔF N1 − 1 = 8D DF1 = = 40. we ﬁnd the ﬁlter lengths: N0 = 169. P12. P12.8 2x4=8-fold oversampling ﬁlter.7 Interpolation of triangular and sinusoidal signals. The combined ﬁlter Htot (f )= H0 (f )H1 (f ) and the superimposed plots of the ﬁlters H0 (f ). P12. P12. for the 4×2 case. However. Initially. N1 = 17 Fig.9.

14 Single-stage 8-fold oversampling ﬁlter. Stage H0 operating at 2fs will have the narrow transition width Δf = 4. For reference. resulting in the relative computational rate N1 = 25. N2 = 17 N 0 + N 1 F0 + N 2 F 1 Rmulti = 0.0930 ⇒ N = 217.1 − 20 Δf = 0. in the 2×2×2 case.2. or ΔF1 = 1. DL 5. N−1= Fig. This did not change the ﬁlter lengths.11 Combined ﬁlter H0 (f )H1 (f ). Again.12.8 In units of fs = 44. M = (N − 1)/(2L)= 27 The corresponding computational rate of the polyphase realization is Rsingle = Nfs = 217 · 44. N0 = 85.1 kHz.1 kHz.0930 ⇒ N0 = 109. This gives the Kaiser length: Problem 12. whereas the ﬁrst two were A0 = A1 = 80 dB.0174 · 2 = 107. P12. H1 (f ).95)/14.36 = 5. we ﬁnd the ﬁlter lengths Fig. the attenuation of the second ﬁlter had to be increased to A1 = 84 dB.2.1 N0 − 1 = DL0 5. H2 (f ) are shown in Fig. Thus. or ΔF = 0. P12. Thus. H1 (f ). the ﬁlter length will be: 262 263 .36 = (80 − 7.0930. and individual ﬁlters H0 (f ). we ﬁnd the Kaiser length: The second stage H1 will have a wider transition width Δf1 = fs . P12. for a single-stage design with oversampling ratio L = 4.0174.95)/14. H1 (f ). The combined ﬁlter Htot (f )= H0 (f )H1 (f )H2 (f ) and individual ﬁlters H0 (f ). For the two-stage case.13 Combined ﬁlter H0 (f )H1 (f )H2 (f ). P12. M0 = (N0 − 1)/(2L0 )= 27 The Kaiser window width parameter is D = (A − 7.below 80 dB. Fig. shown in Fig. a 20-MIPS DSP chip can easily handle it. the design speciﬁcations are depicted in Fig. and individual ﬁlters H0 (f ). we also show in Fig.9 of Section 12. 12. P12. P12.5.60 = N Rsingle fs 2 H0 2fs 2 H1 4fs 2 H2 8fs Fig.14 the magnitude response of the single stage 8-fold oversampling ﬁlter.7 MAC/msec = 9. H2 (f ).803 = ΔF 0.0930 = fs 44.13. the nominal attenuation of the last factor H2 had to be increased to A2 = 84 dB.9 = ΔF 0.) Thus. but it changed slightly the Kaiser parameters D1 and α1 for that factor. Finally.5697 MIPS (assuming that each MAC is done with one instruction.1 = 9569. P12.0174 · 4 = 215. the transition width from the edge of the passband to the edge of the stopband will be: ΔF = 24.12 2x2x2=8-fold oversampling ﬁlter.

hold.15 and P12. |H1 (f )| = |H2 (f )| = |Hdac (f )| = sin(πf /L0 fs ) L1 sin(πf /L0 L1 fs ) 2 = = sin(πf /4fs ) 2 sin(πf /8fs ) 2 sin(πf /L0 L1 fs ) L2 sin(πf /L0 L1 L2 fs ) sin(πf /L0 L1 L2 fs ) sin(πf /8fs ) 2 sin(πf /16fs ) πf /L0 L1 L2 fs = sin(πf /16fs ) πf /16f