43
Infinite Impulse Response (IIR) Filters Uses both the input signal and previous filtered values y[n] = b 0 x[n] + b 1 x[n-1] + b 2 x[n-2] + … + a 1 y[n-1] + a 2 y[n-2] + a 3 y[n-3] + … The b k coefficients comprise the FIR part; filtering the input signal The a k coefficients comprise the IIR part; additional filtering using previously filtered values This concept has overlap with neural networks, a popular algorithm that statistically “learns” Sometimes called recursive filters

Infinite Impulse Response (IIR) Filters Uses both the input signal and previous filtered values y[n] = b 0 x[n] + b 1 x[n-1] + b 2 x[n-2] + … + a 1 y[n-1]

Embed Size (px)

Citation preview

Infinite Impulse Response (IIR) Filters

• Uses both the input signal and previous filtered values

y[n] = b0x[n] + b1x[n-1] + b2x[n-2] + … + a1y[n-1] + a2y[n-2] + a3y[n-3] + …

• The bk coefficients comprise the FIR part; filtering the input signal

• The ak coefficients comprise the IIR part; additional filtering using previously filtered values

• This concept has overlap with neural networks, a popular algorithm that statistically “learns”

Sometimes called recursive filters

IIR Filter Codepublic static double[] convolution(double[] signal, double[] b, double[] a)

{ double[] y = new double[signal.length + b.length - 1];

for (int i = 0; i < signal.length; i ++)

{ for (int j = 0; j < b.length; j++)

{ if (i-j>=0) y[i] += b[j]*signal[i - j]; }

if (a!=null)

{ for (int j = 1; j < a.length; j ++)

{ if (i-j>=0) y[i] -= a[j] * y[i - j]; }

}

}

return y;

}

Characteristics of Recursive Filters

• Advantages– Powerful filtering with very few parameters– Execute very fast

• Example 1: b0 = .15 and a1 = .85

• Example 1: b0 = 0.93 b1 = -0.93 a1 = 0.86

Input Signal Example 1output

Example 2 output

0.0

1.0

Low and High Pass Recursive Filter

• Low Pass: b0 = 1-x, a1 = x• High Pass: b0 = (1+x)/2, b1 = -(1+x)/x, a1 = x• 0≤x≤1, which controls the low and high pass boundaries

Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.

Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.

IIR Disadvantages

float x = 1

for (int i=0; i<N; i++)

{ float a=Math.random();

float b=Math.random();x = x + a; x = x + b; x = x - a; x = x - b;

}Loops

Err

or

Do you see the flaws inthe above program?

• Can be unstable: yn = xn + yn-1 //running sum• Additive errors propagate (round off drift)• Possible non-linear group delay

IIR Moving Average Filter

• Illustration (Sum of seven previous samples)y[50] = x[47]+x[48]+x[49]+x[50]+x[51]+x[52]+x[53]y[51] = x[48]+x[49]+x[50]+x[51]+x[52]+x[53]+x[54] = y[50] + x[54] – x[47]

• Example: {1,2,3,4,5,4,3,2,1,2,3,4,5}; M = 4

– Starting filtered values: {¼ , ¾, 1 ½, 2 ½, … }

– Next value: y4 = 2 ½ + (5 – 1)/4 = 3 ½

• Filter of degree (length) M– Centered Version: yn = yn-1 + xn+(M-1)/2 - xn-(M-1)/2 – 1

– Non Centered Version: yn = yn-1 + xn/M –xn-M/M

Two additions per point no matter the filter length

Note: Integers work best with this approach to avoid round off drift

Transforms

• Procedure– Transform the problem into a different domain– Execute a simpler algorithm in the transformed space– Transform back to get the solution

• DSP Example: We need a well-defined way to determine IIR filter coefficients that result in a filter that performs properly

• Image Processing: Mapping a three dimensional image into two dimension

Some problems are difficult (or impossible) to solve directly

Laplace Transform

• The Fourier domain is a one dimensional space; each point represents a sinusoid of a particular frequency

• The Laplace domain (S-Domain) is a two dimensional space of complex numbers; each point represents sinusoids of a particular frequency that either amplifies with higher y-axis values or degrades with lower y-axis values

Works with continuous functions

.

Positive frequency sinusoid

Negative frequency sinusoid

Fourier Domain

Laplace Domain

Positive frequency sinusoid that amplifies at a positive rate

Positive frequency sinusoid that exponentially decay (attenuates)

Imaginary axis

Real axis

The S-Domain1. Each S-Domain point models a basis function2. The top half is a mirror image of the bottom

Real axisImag axis

Note: The waveforms are counterintuitive since filters convolute from the current time backward. Attenuating waves, actually produces unstable filters

Laplace Transform Example

The Fourier transform is the Laplace Transform when σ=0

Laplace Transform

• Consider a process whose characteristics change over time

• Some function governs the changing behavior of the process

• We observe the process as a signal measured at points of time

• We want to predict the outputs, when the input system interacts with a filtering system process.

• We can model this problem with a differential equation, where time is the independent variable:a1 y’’’(t) + a2y’’(t) + a3y’(t) = b1 x’(t) +b2 x2 x(t)

A technique for solving differential equations

Laplace Transform Definition

• s is a complex number (σ+jω) where σ controls the degree of exponential decay and ω controls the frequency of the basis function

• e-st = e-(σ+jω)t = e-jωt / eσt

• The denominator controls the decay rate

• The numerator controls the frequency

• The integral starts if we are not interested in negative time (time past)

dt

Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.

Impact of σ, ω values on the resulting basis function

Assuming σ is negative

Poles and Zeroes

• The integrations causes S-plane some points to:– Evaluate to 0 (these are zeroes)– Evaluate to ∞ (these are poles)

• Pole and zero points determine IIR filter coefficients

• Note: Designing a filter comes down to picking the pole and zero points on the S-plane

dt

An S-domain PlotNoteThe poles are the peaksThe zeroes are the valleys

Note: The third dimension is the

magnitude of ∫f(t)e-stdt at s = (σ+jω)

Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.

Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.

Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.

Time domain impulse response

Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.

Attenuating impulse response

Amplifying impulse response

The Low Pass Filter IllustrationTransform the rectangular time domain pulse into the frequency domain andInto the s-domain

S-domain for a notch filter

Fourier frequencies are the points where the real value is zero

Notationx = pole○ = zero

The z-transform

• Z-transform is the discrete cousin to the Laplace Transform• Laplace Transform (s = σ+jω)

– Extends the Fourier Transform, uses integrals and continuous functions– s = e-(σ+jω)t becomes the Fourier transform when ω = 0– Fourier points fall along the imaginary axis– S-domain stable region is on the negative half of the domain

• Z-Transform (z = re-2πk/ts)– Extends the Discrete Fourier Transform, uses sums and discrete samples– z = e-j2πk/ts becomes the Discrete Fourier Transform (ts=sample size)

– Four transform points fall along the unit circle– Z-domain stable domain are those within the unit circle

Z{x[n]} =

Compare S-plane to Z-plane (cont.)• Filter design S: analog filters; Z: IIR filters• Equations S: differential equations, Z: difference equations• Filter Points S: rectangular along i axis, Z: polar around unit circle• Frequencies S: -∞ to ∞ (frequency line). Z: 0 to 2 π (frequency circle)• Plots S and Z: Upper and lower half are mirror images

Looking down vertically from the top of the domain

Note: the Lines to left of s-plane correspond to circles within the unit circle in the z-plane

Negative frequencies

Positive frequencies

Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.

Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.

Analog Filter Example

σ=(A-3)/2RC; ω=±(A2+6A-5)½/2RC

Sallen-Key Filters ona circle of 1/RC radius

A = amplificationR= resistanceC = capacitance

ButterWorth Filters

ButterWorth poles are equally spaced around the left side of a circle

Example Low Pass Filters• Butterworth poles

are equally spaced on a circle

• Chebshev poles are equally spaced on an ellipse

• Elliptic poles are on an ellipse; zeroes added to the stopband north and south of the poles

Examples

r φ Poles a1 a2

0.8 0.75 0.58±0.54j 1.17 -1.64

0.8 1.0 0.43±0.67j 0.86 -0.64

0.8 1.25 0.25±0.76j 0.50 -0.64

0.8 1.5 0.056±0.78j 0.11 -0.64

x xx

xxx

x

x

Freq Bandwth r φ Poles

F1 300 250 0.95 0.12 0.963±0.116j

F2 2200 250 0.95 0.86 0.619±0.719j

F3 3000 250 0.95 1.17 0.370±0.874j

xx

xx

xx

There are tables of pole/zero points and their effects

Pole Placement

• Poles characterized by:– Amplitude: height of the resonance– Frequency: placement in the spectrum– Bandwidth: Sharpness of the pole

• Place pole at reiφ

– Amplitude and bandwidth shrink as r approaches the origin3-db down (half power) estimate = -2 ln(r) or 2(1-r)/r½

– ω controls the resonant frequency When ω ≠0, IIR coefficients will be complex numbers IIR coefficients real if there are conjugate pairs (reiφ,re-iφ) If r < 0.5, the relationship between φ and frequency breaks

down because the pole “skirts” cause results to be less precise

Transfer Function

1. IIR Definition: yn = b0xn + b1xn-1 +…+ bMxn-M + a1yn-1 +…+ aNyn-N

2. Z transform both sides: Yz=Z{b0xn+b1xn-1+…+bMxn-M+a1yn-1+…+aNyn-N}

3. Linearity Property: Yz = Z{b0xn}+Z{b1xn-1}+…+Z{bMxn-M}+Z{a1yn-1}+…+Z{aNyn-N}

4. Time delay property (Z{xn-k} = xzz-k)Yz = b0Xz + b1Xzz-1 +…+bn-MXzz-M + a1Yzz-1+…+aNYzz-N

5. Gather TermsYz - a1Yzz-1-…- aNYzz-N = b0Xz + b1Xzz-1 +…+ bn-MXz

-M

Yz(1- a1z-1-…- aNz-N ) = Xz(b0 + b1z-1 +…+ bn-Mz-M)6. Divide to get transfer function

Yz/Xz= Hz= (b0 + b1z-1 +…+ bn-Mz-M)/(1- a1z-1-…- aNz-N ) Yz = Xz (Yz/Xz) = Xz (Hz) // Hz is the transform function for the filter

7. Perform Inverse Z transform: y[n] = x[n] * filter[n] // where * is convolutionBecause Z domain multiplication is time domain convolution

A polynomial equation that defines filter coefficients for particular Z,S domain setting

Starting with the IIR definition, derive Z-Transform Transfer Function

Z{x[n]} =

Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.

Transfer Function Example• Suppose

– b0=0.389, b1=-1.558, b2=2.338, b3=-1.558, b4=0.389– a1=2.161, a2=-2.033, a3=0.878, a4=-0.161

• Transfer FunctionH[z] = 0.389 - 1.558z-1+2.338z-2-1.558z-3+0.389z-4 /

(1-2.161z-1 + 2.033z-2 -0.878z-3+0.161z-4)= 0.389z4 - 1.558z3+2.338z2-1.558z1+0.389 / (z4-2.161z3 + 2.033z2 -0.878z1+0.161)

• Find the roots = (z-z1)(z-z2)(z-z3)(z-z4) / (z-p1)(z-p2)(z-p3)(z-p4)

Note: The bottom form tells us where the zeroes and poles are

Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.

Notch FilterZ1 = 1.00 ei(π/4), Z2 = 1.00 ei(-π/4)

P1=0.9ei(π/4), P2=0.9ei(-π/4)

Z1=0.7071+0.7071iZ2=0.7071-0.7071iP1=0.6364+0.6364iP2=0.6364-0.6364i

1. Convert to rectangular form2. Multiply the complex polynomials3. Collect terms4. Use the coefficients for the filter Note: Compare to the s-plane example

Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.

Second-order low pass IIR filter examples

Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.

Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.

Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.

Linear filters can be combined into parallel or serial systems

Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.

Note: It’s easier to design multiple two tap systems than a larger multiple tap system

Understanding Digital Signal Processing, Third Edition, Richard Lyons(0-13-261480-4) © Pearson Education, 2011.

Original Gain: (b0+b1)/(1 - a1) = 0.22 + 0.25 / (1-0.87) = 3.614Do normalize gain, divide coefficients by 3.64