dsp_iir

22
1 Infinite Impulse Response Filter (IIF) = = = = = N 0 k M 0 k k k 0 k ) k n ( y a ) k n ( x b ) k n ( x ) k ( h ) n ( y Realizable IIR is characterized by the following recursive equqtion: = = + = = M 0 k k k N 0 k k k z a 1 z b ) z ( X ) z ( Y ) z ( H X(n) y(n) Direct 1 form b N -a 1 -a 2 -a M . . . . . . b 0 b 1 b 2 z -1 z -1 z -1 z -1 z -1 z -1 y(n) X(n) Direct 2 form z -1 z -1 z -1 b 0 -a 1 -a 2 -a M . . . . . . b 1 b 2 b N

Transcript of dsp_iir

  • 11

    Infinite Impulse Response Filter (IIF)

    = =

    ===

    N

    0k

    M

    0kkk

    0k)kn(ya)kn(xb)kn(x)k(h)n(y

    Realizable IIR is characterized by the following recursive equqtion:

    =

    =

    +== M

    0k

    kk

    N

    0k

    kk

    za1

    zb

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

    X(n) y(n)Direct 1 form

    bN

    -a1

    -a2

    -aM

    .

    .

    .

    .

    .

    .

    b0

    b1

    b2

    z-1

    z-1

    z-1

    z-1

    z-1

    z-1

    y(n)X(n)Direct 2 form

    z-1

    z-1

    z-1

    b0

    -a1

    -a2

    -aM

    .

    .

    .

    .

    .

    .

    b1

    b2

    bN

  • 22

    Design Steps

    1. Filter Specification

    2. Coefficient Calculations

    3. Realisation

    4. Implementation

    Pole-Zero PlacementImpulse InvariantBilinear Z-Transform (BZT)

    Coefficient Calculations Methods

  • 33

    Pole-Zero PlacementBasic Concept:

    H(f)=0Zero in the z- plane

    H(f)=maxPole in the z- plane

    x

    xFs/4 3Fs/4

    f

    H(f)

    Fs/4

    Fs/4

    3Fs/4

    Fs/2 0

    0

    Fs/2

  • 44

    Pole-Zero Placement

    Example: Design Bandpass Digital Filter to meet the following Specifications:

    1. Comlete signal rejection: f=0 (dc) and f=250 Hz;2. Narrow passband centred: 125 Hz;3. At 3 dB bandwidth: Bw=10 Hz;4. Sampling frequency: Ft=500 Hz.

    Solution:

    Fs=0; 3Fs/4=250 Hz;

    250Hz

    x

    xf

    H(f)

    00

    125Hz

    125Hz

    125Hz0 250Hz

    r

    r=1-(Bw/Ft)*=0.937

  • 55

    Pole-Zero Placement

    The difference equation:

    y(n) = - 0.877969 y(n-2)+x(n)- x(n-2)1

    z-1 z-1

    z-1

    z-1

    x(n) y(n)-1

    - 0.877969

    2

    2

    2/j2/j

    z877969.01z1

    )rez)(rez()1z)(1z()z(H

    +=

    =+=

  • 66

    Impulse invariant Method

    [ ] pt1 Ce)s(HL)t(h;ps

    C)s(H ===

    Basic Concept:

    H(s) h(t)LT Sampling

    h(nt)ZT

    H(z)

    Ilustration:

    1ze1C)z(H

    zCez)nT(h)z(H

    pT

    0n

    npnT

    0n

    n

    =

    == =

    =

  • 77

    Impulse invariant Method

    0 50 100 150 200 250 300 350 400 450 500-25

    -20

    -15

    -10

    -5

    0

    M

    a

    g

    n

    i

    t

    u

    d

    e

    (

    d

    B

    )

    Frequency (Hz)

    FN=1000/2; % Nyquist frequency

    fc=300; % cut offf frequency

    N=5; % filter order

    [z, p, k]=buttap(N);% create an analog filter

    w=linspace(0, FN/fc, 1000); % plot the response of filter

    h=freqs(k*poly(z), poly(p), w);

    f=fc*w;

    plot(f, 20*log10(abs(h))), grid;

    ylabel('Magnitude (dB)')

    xlabel('Frequency (Hz)')

    Matlab-files for design analog filter

    Example:Design a IIF filter with Butterworth characteristic to meetthe followingSpecifications:

  • 88

    Impulse invariant Method

    0 50 100 150 200 250 300 350 400 450 500-18

    -16

    -14

    -12

    -10

    -8

    -6

    -4

    -2

    0

    2

    Frequency (Hz)

    M

    a

    g

    n

    i

    t

    u

    d

    e

    (

    d

    B

    )

    Fs=1000; % sampling frequency

    fc=300; % cutoff frequency

    WC=2*pi*fc; % cutoff frequency in radian

    N=5; % filter order

    [b,a]=butter(N,WC,'s'); % create an analog filter

    [z, p, k]=butter(N, WC, 's');

    [bz, az]=impinvar(b,a,Fs);% determine coeff. of filter

    [h, f]=freqz(bz, az, 512,Fs);

    plot(f, 20*log10(abs(h))), grid

    xlabel('Frequency (Hz)')

    ylabel('Magnitude (dB)')

    Matlab-files for design digital Impulse invariant filter

  • 99

    IIF design using Impulse invariant Method

    wp=0.25*pi; ws=0.55*piRp=0.5; Rs=15; s=0.1*Rs; e2=(10^s)-1;

    v=0.1*Rp; e3=10^v-1; k=ws/wp; N=log10(e2/e3)/(2*log10(k)); N=ceil(N)

    [z p k]=buttap(N) % Buttap - Butterworth analog lowpass filter

    [num,den]=zp2tf(z,p,k); %[num,den]- numerator and denominator coefficients of analog filter

    [bz,az]=impinvar(num,den) % [bz,az] numerator BZ and AZ denominator coefficients of digital filter

    [h omega]=freqz(bz,az,512);%[h omega]-frequency response of digital filter

    g=20*log10(abs(h));

    plot(omega/pi,g);'grid'

    xlabel('Normalized frequeny')

    ylabel('Gain,dB')

    [bz,az]=impinvar(num,den)

    )wp/wslog(2110)110log(

    N10/Rp

    10/Rs

    =

    Design IIF with following specifications:

    Passband edge frequency: wp=0.25*pi;Stopband edge frequency: ws=0.55*pi;Sampling frequency: T=1Passband ripple: Rp=-0.5;Stopband ripple: Rs=-15;Matlab Program:

  • 10

    10

    bz =-0.0000 0.0828 0.1657 0.0226 0

    az =1.0000 -1.5587 1.2283 -0.4722 0.0733

    Transfer function:

    4321

    321

    z07.0z4.0z2.1z5.11z02.0z16.0z08.0)z(H

    ++++=

    0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1-40

    -35

    -30

    -25

    -20

    -15

    -10

    -5

    0

    5

    Normalized frequeny

    G

    a

    i

    n

    ,

    d

    B

  • 11

    11

    Bilinear Z-Transform (BZT)

    Basic Concept:

    H(s) H(z)

    S-plane

    x

    x

    x

    x

    Im

    Rex

    x

    Im

    Re

    z-plane

    x

    xx

    x xx

    x

    x

    x

    T2or1k;

    1z1zks =+

    =

  • 12

    12

    Warping Effect

    2T

    tank p'p=

    - analog frequency- digital frequency

    T-sampling period

    2Ttank' =

    (analog)

    (digital)

    2Ttank;

    1e1ekj 'Tj

    Tj' =+

    =

    Relationship between and is nonlinear (tangensoidal) leading to a distortyion or warping of

    digital frequency.Passband for the analog filter are with

    regular intervals, whereas the passband for the digital

    filterare somewhat squashed up. This effect is

    Compensated for by prewarping the analog filter

    before applying the BZT.

    p- specified cutoff frequency p- prewarped frequency

    'js;ez Tj == T2or1k;

    1z1zks =+

    =

  • 13

    13

    Summary of the BZT

    'p2

    'p1

    'p2

    'p1

    20

    20

    2s

    s

    20

    2

    'p

    'p

    W;

    BSF);to(LPFs

    WsBPF);to(LPFWss

    HPF);to(LPFs

    sLPF);to(LPFss

    ==+=

    +=

    ==

    1. Use the DF specifications to find a suitable analog LPF, H(s)2. Determine and prewrap bandedge frequencies

    ;2T

    ktan;2T

    ktan

    2T

    ktan

    p2'P2

    p1'P1

    p'P

    ==

    = For LPF and HPF

    For Band pass and stopband filters

    p- desired cutoff frequency ; p- prewarped critical frequency3. Denormalized analog filter or H(s) by replac s one of the following transformations

    4. Apply BZT

    1z1zks +

    =

  • 14

    14

    0 50 100 150 200 250 300 350 400 450 500-250

    -200

    -150

    -100

    -50

    0

    50

    M

    a

    g

    n

    i

    t

    u

    d

    e

    (

    d

    B

    )

    Frequency (Hz)

    0 50 100 150 200 250 300 350 400 450 500-18

    -16

    -14

    -12

    -10

    -8

    -6

    -4

    -2

    0

    2

    Frequency (Hz)

    M

    a

    g

    n

    i

    t

    u

    d

    e

    (

    d

    B

    )

    Matlab-files using BZTFs=1000; % Sampling frequency

    FN=Fs/2; % Nyquist frequency

    fc=300; % cut offf frequency

    N=5; % filter order

    [z, p, k]=butter(N, fc/FN);

    [h, f]=freqz(k*poly(z), poly(p), 512, Fs);

    plot(f, 20*log10(abs(h))), grid

    ylabel('Magnitude (dB)')

    xlabel('Frequency (Hz)')

    Impulse invariant Method

    BZT

    Fs=1000; % sampling frequency

    fc=300; % cutoff frequency

    WC=2*pi*fc; % cutoff frequency in radian

    N=5; % filter order

    [b,a]=butter(N,WC,'s'); % create an analog filter

    [z, p, k]=butter(N, WC, 's');

    [bz, az]=impinvar(b,a,Fs);% determine coeffs of IIR filter

    [h, f]=freqz(bz, az, 512,Fs);

    plot(f, 20*log10(abs(h))), grid

    xlabel('Frequency (Hz)')

    ylabel('Magnitude (dB)')

  • 15

    15

    Matlab-files using BZT

    Fs=2000; % Sampling frequency

    FN=Fs/2; fc1=200/FN;

    fc2=300/FN;

    [b,a]=butter(4,[fc1, fc2]); % Create and digit. analogue filter.

    [z,p,k]=butter(4, [fc1, fc2]);

    subplot(2,1,1) % Plot magnitude freq. response

    [H, f]=freqz(b, a, 512, Fs);

    plot(f, abs(H))

    xlabel('Frequency (Hz)')

    ylabel('Magnitude Response ')

    subplot(2,1,2) % Plot pole-zero diagram

    zplane(b, a)

    0 100 200 300 400 500 600 700 800 900 10000

    0.2

    0.4

    0.6

    0.8

    1

    Frequency (Hz)

    M

    a

    g

    n

    i

    t

    u

    d

    e

    R

    e

    s

    p

    o

    n

    s

    e

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

    -0.5

    0

    0.5

    1

    4 4

    Real Part

    I

    m

    a

    g

    i

    n

    a

    r

    y

    P

    a

    r

    t

    Problem: Design Bandpass filter with Butterworth characteristics rhat meets the following specifications:

    Passband 200-300 HzSampling frequency 2000 HzFilter order 8

  • 16

    16

    Matlab-files using BZTProblem: Design Bandpass filter with Butterworth characteristics rhat meets the following specifications:

    Lower passband edge frequency 200 HzUppere passband edge frequency 300 HzLower stopband edge frequency 50 HzUppere stopband edge frequency 450 HzPassband ripple 3 dBStopband attenuation 20 dBSampling frequency 1 kHz

    Determine the order N of filter; b) poles, zeros, gain, coefficients and transfer functon of DF

    Fs=1000; % Sampling frequencyAp=3;As=20;Wp=[200/500, 300/500]; % Band edge frequenciesWs=[50/500, 450/500];[N, Wc]=buttord(Wp, Ws, Ap, As); % Determine filter order[zz, pz, kz]=butter(N,Wp); % Digitise filter[b, a]=butter(N, Wp);subplot(2,1,1) % Plot magnitude freq. response[H, f]=freqz(b, a, 512, Fs);plot(f, abs(H))xlabel('Frequency (Hz)')ylabel('Magnitude Response ')subplot(2,1,2) % Plot pole-zero diagramzplane(b, a)

    0 50 100 150 200 250 300 350 400 450 5000

    0.2

    0.4

    0.6

    0.8

    1

    Frequency (Hz)

    M

    a

    g

    n

    i

    t

    u

    d

    e

    R

    e

    s

    p

    o

    n

    s

    e

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

    -0.5

    0

    0.5

    1

    22

    Real PartI

    m

    a

    g

    i

    n

    a

    r

    y

    P

    a

    r

    t

  • 17

    17

    N=2

    pz= [-0.1884 0.7791j ; 0.1884 0.7791j]zz= [1 1 -1 -1]

    kz=0.0675

    b= [0.0675 0 -0.1349 0 0.0675]

    a= [1.0000 -0.0000 1.1430 -0.0000 0.4128]

    42

    42

    z4128.0z1430.11z0675.0z1349.00675.0)z(H

    +++=

    y(n)= 0.0675x(n)- 0.1349x(n-2) +0.0675x(n-4) -1.1430y(n-2)- 0.4128y(n-4)

    x(n)

    0.0675

    z-1 z-1

    z-1

    z-1

    y(n)0.0675

    - 0.4128

    z-1z-1

    -0.1349 z-1

    z-1

    - 1.1430

  • 18

    18

    Realization of IIR

    NM)kn(ya)kn(xb)n(yN

    0k

    M

    1kkk =

    = =

    z-1

    z-1

    X(n) y(n)b0

    b1

    b2

    -a1

    -a2

    w(n)

    Direct 2 2nd order

    z-1

    z-1

    z-1

    z-1

    -a1

    -a2

    b1

    b2

    b0X(n) y(n)

    Direct 12nd order

    = =

    =2

    0k

    2

    1kkk )kn(ya)kn(xb)n(y

    =

    =

    =

    =2

    0kk

    2

    1kk

    )kn(wb)n(y

    )kn(wa)n(x)n(w

    22

    11

    22

    110

    zaza1zbzbb)z(H

    ++++=

  • 19

    19

    Cascade Realization of IIR

    ==

    =

    ++++=

    2/N

    1k k

    k2/N

    1k2

    21

    1

    22

    110

    )z(D)z(N

    zaza1zbzbb)z(H 2

    21

    1k

    22

    110k

    zaza1)z(D

    zbzbb)z(N

    ++=++=

    )z(D)z(N

    )z(D)z(N)z(H;

    )z(D)z(N

    )z(D)z(N)z(H

    )z(D)z(N

    )z(D)z(N)z(H;

    )z(D)z(N

    )z(D)z(N)z(H

    1

    1

    2

    2

    2

    1

    1

    2

    1

    2

    2

    1

    2

    2

    1

    1

    ==

    ==

    X(n)

    z-1

    z-1

    b01

    b11

    b21

    -a11

    -a21

    z-1

    z-1

    y(n)b0n

    b1n

    b2n

    -a1n

    -a2n

    X(n)

    z-1

    b01

    b11-a11

    z-1

    z-1

    y(n)b0n

    b1n

    b2n

    -a1n

    -a2nCascade realization of a 3rd order IIR

  • 20

    20

    Parallel Realization of IIR

    =

    +=2/N

    1kk )z(HC)z(H

    z-1

    z-1

    b01

    b11-a11

    -a21

    z-1

    z-1

    b0n

    b1n-a1n

    -a2n

    X(n)

    y(n)

    .

    .

    .

    C

    1k1

    1k1

    1k1k0

    N

    N

    zaza1zbb)z(H,

    abC

    +++==

    =

    ++++=

    n

    1k1

    k11

    k1

    1k1k0

    zaza1zbbC)z(H

  • 21

    21

    Develop Cascade and Parallel Realization

    )z0165.0z3419.0z1801.01)zz3z31(1432.0)z(H 321

    321

    ++++=

    1. For casacade realization H(z) is expressed in factored form:

    1

    1

    21

    21

    z0490.01z1

    z3355.0z1307.01zz211432.0)z(H

    +

    +++=

    z-1z-1

    z-1

    y(n)

    0.1307

    -0.33557 1

    2

    10.1432

    0.0490 1

    1x(n)

    1. For parallel realization H(z) is expressed usingpartial fraction expansion as the sum second- and first order sections:

    7107.8z049.01

    1764.10z3355.0z131.01

    z08407.02916.1)z(H 1211

    ++=

    z-1

    z-1X(n) y(n)

    z-1

    -0.3355

    0.1310 -0.0841

    1.2916

    -8.7107

    0.0490

    10.1764

  • 22

    22

    Finite Wordlength Effects

    The main errors in IIR:

    1. ADC quantizing noise, with resulths from representing the samplesof x(n) by small number of bits

    2. Coefficients ak and bk quantizing errors, caused by representing ak and bk by a finite number of bits

    3. Overflow errors, which result from arithmetic operations and storage the results in a limited register length

    One of reserves to reduce errors in IIF is broken H(z) into smaller first and second order bloks which are then

    cconnected up in cascade or in parallel

    Application of IIR1. Telecommunication- in Transmitter as antialiasing filter and in Receiver anti imaging filter

    2. Digital Telephony-digital dual tone multifrequency touch-tone receiver

    3. Clock recover in Data communications etc