dsp & digital filters

Upload: yalcinayguel

Post on 10-Jan-2016

109 views

Category:

Documents


1 download

DESCRIPTION

signal is a numerical quantity that is a function of one or moreindependent variables such as time or position.

TRANSCRIPT

  • DSP and Digital Filters (2015-6724) Introduction: 1 1 / 16

    DSP & Digital Filters

    Mike Brookes

  • 1: Introduction

    1: IntroductionOrganization

    Signals

    Processing

    Syllabus

    Sequences

    Time Scaling

    z-TransformRegion ofConvergence

    z-Transform examples

    Rational z-Transforms

    Rational example

    Inverse z-Transform

    MATLAB routines

    Summary

    DSP and Digital Filters (2015-6724) Introduction: 1 2 / 16

  • Organization

    1: Introduction

    OrganizationSignals

    Processing

    Syllabus

    Sequences

    Time Scaling

    z-TransformRegion ofConvergence

    z-Transform examples

    Rational z-Transforms

    Rational example

    Inverse z-Transform

    MATLAB routines

    Summary

    DSP and Digital Filters (2015-6724) Introduction: 1 3 / 16

    18 lectures: feel free to ask questions

    Textbooks: (a) Mitra Digital Signal Processing ISBN:0071289461 41 covers

    most of the course except for some of the multirate stuff (b) Harris Multirate Signal Processing ISBN:0137009054 49

    covers multirate material in more detail but less rigour thanMitra

    Lecture slides available via Blackboard or on my website:http://www.ee.ic.ac.uk/hp/staff/dmb/courses/dspdf/dspdf.htm quite dense - ensure you understand each line email me if you dont understand or dont agree with anything

    Prerequisites: 3rd year DSP - attend lectures if dubious

    Exam + Formula Sheet (past exam papers + solutions on website)

    Problems: Mitra textbook contains many problems at the end of eachchapter and also MATLAB exercises

  • Signals

    1: Introduction

    Organization

    SignalsProcessing

    Syllabus

    Sequences

    Time Scaling

    z-TransformRegion ofConvergence

    z-Transform examples

    Rational z-Transforms

    Rational example

    Inverse z-Transform

    MATLAB routines

    Summary

    DSP and Digital Filters (2015-6724) Introduction: 1 4 / 16

    A signal is a numerical quantity that is a function of one or moreindependent variables such as time or position.

    Real-world signals are analog and vary continuously and takecontinuous values.

    Digital signals are sampled at discrete times and are quantized to afinite number of discrete values

    We will mostly consider one-dimensionsal real-valued signals withregular sample instants; except in a few places, we will ignore thequantization. Extension to multiple dimensions and complex-valued signals

    is straighforward in many cases.

    Examples:

  • Processing

    1: Introduction

    Organization

    Signals

    ProcessingSyllabus

    Sequences

    Time Scaling

    z-TransformRegion ofConvergence

    z-Transform examples

    Rational z-Transforms

    Rational example

    Inverse z-Transform

    MATLAB routines

    Summary

    DSP and Digital Filters (2015-6724) Introduction: 1 5 / 16

    Aims to improve a signal in some way or extract some informationfrom it

    Examples:

    Modulation/demodulation

    Coding and decoding

    Interference rejection and noise suppression

    Signal detection, feature extraction

    We are concerned with linear, time-invariant processing

  • Syllabus

    1: Introduction

    Organization

    Signals

    Processing

    SyllabusSequences

    Time Scaling

    z-TransformRegion ofConvergence

    z-Transform examples

    Rational z-Transforms

    Rational example

    Inverse z-Transform

    MATLAB routines

    Summary

    DSP and Digital Filters (2015-6724) Introduction: 1 6 / 16

    Main topics:

    Introduction/Revision

    Transforms

    Discrete Time Systems

    Filter Design

    FIR Filter Design

    IIR Filter Design

    Multirate systems

    Multirate Fundamentals

    Multirate Filters

    Subband processing

  • Sequences

    1: Introduction

    Organization

    Signals

    Processing

    Syllabus

    SequencesTime Scaling

    z-TransformRegion ofConvergence

    z-Transform examples

    Rational z-Transforms

    Rational example

    Inverse z-Transform

    MATLAB routines

    Summary

    DSP and Digital Filters (2015-6724) Introduction: 1 7 / 16

    We denote the nth sample of a signal as x[n] where < n < + andthe entire sequence as {x[n]} although we will often omit the braces.

    Special sequences:

    Unit step: u[n] =

    {1 n 0

    0 otherwise

    Unit impulse: [n] =

    {1 n = 0

    0 otherwise

    Condition: condition[n] =

    {1 condition is true

    0 otherwise(e.g. u[n] = n0)

    Right-sided: x[n] = 0 for n < Nmin Left-sided: x[n] = 0 for n > Nmax Finite length: x[n] = 0 for n / [Nmin, Nmax] Causal: x[n] = 0 for n < 0, Anticausal: x[n] = 0 for n > 0

    Finite Energy:

    n= |x[n]|2

  • Time Scaling

    1: Introduction

    Organization

    Signals

    Processing

    Syllabus

    Sequences

    Time Scalingz-TransformRegion ofConvergence

    z-Transform examples

    Rational z-Transforms

    Rational example

    Inverse z-Transform

    MATLAB routines

    Summary

    DSP and Digital Filters (2015-6724) Introduction: 1 8 / 16

    For sampled signals, the nth sample is at time t = nT = nfs

    where fs =1T

    is the sample frequency.

    Often easiest to scale time so that fs = 1Hz. E.g. to design a 1 kHzlow-pass filter for fs = 44.1 kHz we can design a 0.0227Hz filter forfs = 1Hz.

    To scale back to real-world values: Every quantity of dimension (Time)n ismultiplied by Tn (or equivalently by fns ). Thus all times are multiplied byT and all frequencies and angular frequencies by T1.

    We use for real angular frequencies and for normalized angularfrequency. The units of are radians per sample.

    Power is measured in units of energy per sample: to convert back toenergy per second you must multiply by T1 = fs.

    Warning: Several MATLAB routines scale time so that fs = 2 Hz. Weird,non-standard and irritating.

  • z-Transform

    1: Introduction

    Organization

    Signals

    Processing

    Syllabus

    Sequences

    Time Scaling

    z-TransformRegion ofConvergence

    z-Transform examples

    Rational z-Transforms

    Rational example

    Inverse z-Transform

    MATLAB routines

    Summary

    DSP and Digital Filters (2015-6724) Introduction: 1 9 / 16

    The z-transform converts a sequence, {x[n]}, into a function, X(z), of anarbitrary complex-valued variable z.

    Why do it?

    Complex functions are easier to manipulate than sequences

    Useful operations on sequences correspond to simple operations onthe z-transform:

    addition, multiplication, scalar multiplication, time-shift,convolution

    Definition: X(z) =+

    n= x[n]zn

  • Region of Convergence

    1: Introduction

    Organization

    Signals

    Processing

    Syllabus

    Sequences

    Time Scaling

    z-Transform

    Region ofConvergence

    z-Transform examples

    Rational z-Transforms

    Rational example

    Inverse z-Transform

    MATLAB routines

    Summary

    DSP and Digital Filters (2015-6724) Introduction: 1 10 / 16

    The set of z for which X(z) converges is its Region of Convergence (ROC).

    Complex analysis : the ROC of a power series (if it exists at all) is alwaysan annular region of the form 0 Rmin < |z| < Rmax .

    X(z) will always converge absolutely inside the ROC and may converge onsome, all, or none of the boundary.

    converge absolutely +

    n= |x[n]zn|

  • z-Transform examples

    DSP and Digital Filters (2015-6724) Introduction: 1 11 / 16

    The sample at n = 0 is indicated by an open circle.

    u[n] 11z1 1 < |z|

    x[n] 2z2 + 2 + z1 0 < |z|

  • Rational z-Transforms

    1: Introduction

    Organization

    Signals

    Processing

    Syllabus

    Sequences

    Time Scaling

    z-TransformRegion ofConvergence

    z-Transform examples

    Rationalz-Transforms

    Rational example

    Inverse z-Transform

    MATLAB routines

    Summary

    DSP and Digital Filters (2015-6724) Introduction: 1 12 / 16

    Most z-transforms that we will meet are rational polynomials with realcoefficients, usually one polynomial in z1 divided by another.

    G(z) = g

    Mm=1(1zmz

    1)

    Kk=1(1pkz

    1)= gzKM

    Mm=1(zzm)Kk1(zpk)

    Completely defined by the poles, zeros and gain.

    The absolute values of the poles define the ROCs:R + 1 different ROCs

    where R is the number of distinct pole magnitudes.

    Note: There are K M zeros or M K poles at z = 0 (easy to overlook)

  • Rational example

    1: Introduction

    Organization

    Signals

    Processing

    Syllabus

    Sequences

    Time Scaling

    z-TransformRegion ofConvergence

    z-Transform examples

    Rational z-Transforms

    Rational exampleInverse z-Transform

    MATLAB routines

    Summary

    DSP and Digital Filters (2015-6724) Introduction: 1 13 / 16

    G(z) = 82z1

    44z13z2

    Poles/Zeros: G(z) = 2z(z0.25))(z+0.5)(z1.5) Poles at z = {0.5,+1.5)},

    Zeros at z = {0,+0.25}

    Partial Fractions: G(z) = 0.751+0.5z1 +1.25

    11.5z1

    ROC ROC 0.751+0.5z11.25

    11.5z1 G(z)

    a 0 |z| < 0.5

    b 0.5 < |z| < 1.5

    c 1.5 < |z|

  • Inverse z-Transform

    1: Introduction

    Organization

    Signals

    Processing

    Syllabus

    Sequences

    Time Scaling

    z-TransformRegion ofConvergence

    z-Transform examples

    Rational z-Transforms

    Rational example

    Inversez-Transform

    MATLAB routines

    Summary

    DSP and Digital Filters (2015-6724) Introduction: 1 14 / 16

    g[n] = 12pijG(z)zn1dz where the integral is anti-clockwise around a

    circle within the ROC, z = Rej.

    Proof:1

    2pij

    G(z)zn1dz= 12pij

    (m= g[m]z

    m)zn1dz

    (i)=

    m= g[m]1

    2pij

    znm1dz

    (ii)=

    m= g[m][nm]= g[n]

    (i) depends on the circle with radius R lying within the ROC

    (ii) Cauchys theorem: 12pijzk1dz = [k] for z = Rej anti-clockwise.

    dzd

    = jRej 12pijzk1dz = 12pij

    2pi=0

    Rk1ej(k1) jRejd

    = Rk

    2pi

    2pi=0

    ejkd

    = Rk(k)= (k) [R0 = 1]

    In practice use a combination of partial fractions and table of z-transforms.

  • MATLAB routines

    1: Introduction

    Organization

    Signals

    Processing

    Syllabus

    Sequences

    Time Scaling

    z-TransformRegion ofConvergence

    z-Transform examples

    Rational z-Transforms

    Rational example

    Inverse z-Transform

    MATLAB routinesSummary

    DSP and Digital Filters (2015-6724) Introduction: 1 15 / 16

    tf2zp,zp2tf b(z1)

    a(z1) {zm, pk, g}

    residuez b(z1)

    a(z1)

    krk

    1pkz1

    tf2sos,sos2tf b(z1)

    a(z1)

    l

    b0,l+b1,lz1+b2,lz

    2

    1+a1,lz1+a2,lz2

    zp2sos,sos2zp {zm, pk, g}

    l

    b0,l+b1,lz1+b2,lz

    2

    1+a1,lz1+a2,lz2

    zp2ss,ss2zp {zm, pk, g}

    {x = Ax+Bu

    y = Cx+Du

    tf2ss,ss2tf b(z1)

    a(z1)

    {x = Ax+Bu

    y = Cx+Du

  • Summary

    1: Introduction

    Organization

    Signals

    Processing

    Syllabus

    Sequences

    Time Scaling

    z-TransformRegion ofConvergence

    z-Transform examples

    Rational z-Transforms

    Rational example

    Inverse z-Transform

    MATLAB routines

    Summary

    DSP and Digital Filters (2015-6724) Introduction: 1 16 / 16

    Time scaling: assume fs = 1 Hz so <

    z-transform: X(z) =+

    n= x[n]n

    ROC: 0 Rmin < |z| < Rmax Causal: ROC Absolutely summable: |z| = 1 ROC

    Inverse z-transform: g[n] = 12pijG(z)zn1dz

    Not unique unless ROC is specified Use partial fractions and/or a table

    For further details see Mitra:1 & 6.

  • 2: Three Different Fourier Transforms

    2: Three DifferentFourier Transforms

    Fourier TransformsConvergence ofDTFT

    DTFT Properties

    DFT Properties

    Symmetries

    Parsevals Theorem

    Convolution

    Sampling Process

    Zero-Padding

    Phase Unwrapping

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6724) Fourier Transforms: 2 1 / 13

  • Fourier Transforms

    2: Three DifferentFourier Transforms

    Fourier TransformsConvergence ofDTFT

    DTFT Properties

    DFT Properties

    Symmetries

    Parsevals Theorem

    Convolution

    Sampling Process

    Zero-Padding

    Phase Unwrapping

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6724) Fourier Transforms: 2 2 / 13

    Three different Fourier Transforms:

    Continuous-Time Fourier Transform (CTFT): x(t) X(j) Discrete-Time Fourier Transform (DTFT): x[n] X(ej) Discrete Fourier Transform (DFT): x[n] X[k]

    Forward Transform Inverse Transform

    CTFT X(j) = x(t)e

    jtdt x(t) = 12piX(j)e

    jtd

    DTFT X(ej) = x[n]e

    jn x[n] = 12pi pipiX(e

    j)ejnd

    DFT X[k] =N1

    0 x[n]ej2pi kn

    N x[n] = 1N

    N10 X[k]e

    j2pi knN

    We use for real and = T for normalized angular frequency.Nyquist frequency is = 2 fs2 =

    piTand = .

    For power signals (energy time interval), CTFT & DTFT areunbounded.Fix this by normalizing:

    X(j) = limA12A

    AA x(t)e

    jtdt

    X(ej) = limA12A

    AA x[n]e

    jn

  • Convergence of DTFT

    2: Three DifferentFourier Transforms

    Fourier Transforms

    Convergence ofDTFT

    DTFT Properties

    DFT Properties

    Symmetries

    Parsevals Theorem

    Convolution

    Sampling Process

    Zero-Padding

    Phase Unwrapping

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6724) Fourier Transforms: 2 3 / 13

    DTFT: X(ej) = x[n]e

    jn does not converge for all x[n].

    Consider the finite sum: XK(ej) =

    KK x[n]e

    jn

    Strong Convergence:x[n] absolutely summable X(ej) converges uniformly

    |x[n]|

  • [DTFT Convergence Proofs]

    DSP and Digital Filters (2015-6724) Fourier Transforms: 2 note 1 of slide 3

    (1) Strong Convergence: [these proofs are not examinable]

    We are given that |x[n]| 0, N such that

    |n|>N |x[n]| <

    For K N , supX(ej)XK(ej)= sup |n|>K x[n]ejn

    sup

    (|n|>K

    x[n]ejn)=|n|>K |x[n]| < (2) Weak Convergence:

    We are given that |x[n]|

    2 0, N such that|n|>N |x[n]|

    2 <

    Define y[K][n] =

    {0 |n| K

    x[n] |n| > Kso that its DTFT is, Y [K](ej) =

    y

    [K][n]ejn

    We see that X(ej)XK(ej) =

    x[n]e

    jn KK x[n]e

    jn

    =|n|>K x[n]e

    jn = y

    [K][n]ejn = Y [K](ej)

    From Parsevals theorem,

    y[K][n]2 = 12pi

    pipi

    Y [K](ej)2 d= 1

    2pi

    pipi

    X(ej)XK(ej)2 dHence for K N , 1

    2pi

    pipi

    X(ej)XK(ej)2 d = y[K][n]2 =|n|>N |x[n]|2 <

  • DTFT Properties

    2: Three DifferentFourier Transforms

    Fourier TransformsConvergence ofDTFT

    DTFT PropertiesDFT Properties

    Symmetries

    Parsevals Theorem

    Convolution

    Sampling Process

    Zero-Padding

    Phase Unwrapping

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6724) Fourier Transforms: 2 4 / 13

    DTFT: X(ej) = x[n]e

    jn

    DTFT is periodic in : X(ej(+2mpi) = X(ej) for integer m.

    DTFT is the z-Transform evaluated at the point ej:X(z) =

    x[n]z

    n

    DTFT converges iff the ROC includes |z| = 1.

    DTFT is the same as the CTFT of a signal comprising impulses atthe sample times (Dirac functions) of appropriate heights:

    x(t) =

    x[n](t nT )= x(t) (t nT )

    Equivalent to multiplying a continuous x(t) by an impulse train.

    Proof: X(ej) = x[n]e

    jn

    n= x[n] (t nT )e

    j tT dt

    (i)=

    n= x[n](t nT )e

    j tT dt

    (ii)=

    x(t)e

    jtdt

    (i) OK if |x[n]|

  • DFT Properties

    2: Three DifferentFourier Transforms

    Fourier TransformsConvergence ofDTFT

    DTFT Properties

    DFT PropertiesSymmetries

    Parsevals Theorem

    Convolution

    Sampling Process

    Zero-Padding

    Phase Unwrapping

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6724) Fourier Transforms: 2 5 / 13

    DFT: X[k] =N1

    0 x[n]ej2pi kn

    N

    DTFT: X(ej) = x[n]e

    jn

    Case 1: x[n] = 0 for n / [0, N 1]

    DFT is the same as DTFT at k =2piNk.

    The {k} are uniformly spaced from = 0 to = 2N1N

    .DFT is the z-Transform evaluated at N equally spaced pointsaround the unit circle beginning at z = 1.

    Case 2: x[n] is periodic with period N

    DFT equals the normalized DTFT

    X[k] = limKN

    2K+1 XK(ejk)

    where XK(ej) =

    KK x[n]e

    jn

  • Symmetries

    2: Three DifferentFourier Transforms

    Fourier TransformsConvergence ofDTFT

    DTFT Properties

    DFT Properties

    SymmetriesParsevals Theorem

    Convolution

    Sampling Process

    Zero-Padding

    Phase Unwrapping

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6724) Fourier Transforms: 2 6 / 13

    If x[n] has a special property then X(ej)and X[k] will have correspondingproperties as shown in the table (and vice versa):

    One domain Other domain

    Discrete PeriodicSymmetric Symmetric

    Antisymmetric AntisymmetricReal Conjugate Symmetric

    Imaginary Conjugate AntisymmetricReal + Symmetric Real + Symmetric

    Real + Antisymmetric Imaginary + Antisymmetric

    Symmetric: x[n] = x[n]X(ej) = X(ej)X[k] = X[(k)mod N ] = X[N k] for k > 0

    Conjugate Symmetric: x[n] = x[n]Conjugate Antisymmetric: x[n] = x[n]

  • Parsevals Theorem

    2: Three DifferentFourier Transforms

    Fourier TransformsConvergence ofDTFT

    DTFT Properties

    DFT Properties

    Symmetries

    ParsevalsTheorem

    Convolution

    Sampling Process

    Zero-Padding

    Phase Unwrapping

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6724) Fourier Transforms: 2 7 / 13

    Fourier transforms preserve energy

    CTFT|x(t)|2 dt = 12pi

    |X(j)|2 d

    DTFT |x[n]|

    2 = 12pi pipi

    X(ej)

    2 d

    DFTN1

    0 |x[n]|2 = 1

    N

    N10 |X[k]|

    2

    More generally, they actually preserve complex inner products:

    N10 x[n]y

    [n] = 1N

    N10 X[k]Y

    [k]

    Unitary matrix viewpoint for DFT:

    If we regard x and X as vectors, then X = Fx where F isa symmetric matrix defined by fk+1,n+1 = e

    j2pi knN .

    The inverse DFT matrix is F1 = 1NFH

    equivalently, G = 1NF is a unitary matrix with GHG = I.

  • Convolution

    2: Three DifferentFourier Transforms

    Fourier TransformsConvergence ofDTFT

    DTFT Properties

    DFT Properties

    Symmetries

    Parsevals Theorem

    ConvolutionSampling Process

    Zero-Padding

    Phase Unwrapping

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6724) Fourier Transforms: 2 8 / 13

    DTFT: Convolution Productx[n] = g[n] h[n]=

    k= g[k]h[n k]

    X(ej) = G(ej)H(ej)

    DFT: Circular convolution Productx[n] = g[n]N h[n]=

    N1k=0 g[k]h[(n k)modN ]

    X[k] = G[k]H[k]

    DTFT: Product Circular Convolution 2y[n] = g[n]h[n] Y (ej) = 12piG(e

    j)H(ej) = 12pi pipi G(e

    j)H(ej())d

    DFT: Product Circular Convolution Ny[n] = g[n]h[n]

    X[k] = 1NG[k]N H[k]

    g[n] : h[n] : g[n] h[n] : g[n]3 h[n]

  • Sampling Process

    DSP and Digital Filters (2015-6724) Fourier Transforms: 2 9 / 13

    Time Time Frequency

    AnalogCTFT

    Low PassFilter

    * CTFT

    Sample DTFT

    Window DTFT

    DFTDFT

  • Zero-Padding

    2: Three DifferentFourier Transforms

    Fourier TransformsConvergence ofDTFT

    DTFT Properties

    DFT Properties

    Symmetries

    Parsevals Theorem

    Convolution

    Sampling Process

    Zero-PaddingPhase Unwrapping

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6724) Fourier Transforms: 2 10 / 13

    Zero padding means added extra zeros onto the end of x[n] beforeperforming the DFT.

    Time x[n] Frequency |X[k]|

    WindowedSignal

    With zero-padding

    Zero-padding causes the DFT to evaluate the DTFT at more valuesof k. Denser frequency samples.

    Width of the peaks remains constant: determined by the length andshape of the window.

    Smoother graph but increased frequency resolution is an illusion.

  • Phase Unwrapping

    2: Three DifferentFourier Transforms

    Fourier TransformsConvergence ofDTFT

    DTFT Properties

    DFT Properties

    Symmetries

    Parsevals Theorem

    Convolution

    Sampling Process

    Zero-Padding

    Phase UnwrappingSummary

    MATLAB routines

    DSP and Digital Filters (2015-6724) Fourier Transforms: 2 11 / 13

    Phase of a DTFT is only defined to within an integer multiple of 2.

    -2 0 20

    2

    4

    6

    (rad/sample)

    x[n] |X[k]|

    -2 0 2

    -2

    0

    2

    (rad/sample)

    -2 0 2-40

    -20

    0

    (rad/sample)

    X[k] X[k] unwrapped

    Phase unwrapping adds multiples of 2 onto each X[k] to make thephase as continuous as possible.

  • Summary

    2: Three DifferentFourier Transforms

    Fourier TransformsConvergence ofDTFT

    DTFT Properties

    DFT Properties

    Symmetries

    Parsevals Theorem

    Convolution

    Sampling Process

    Zero-Padding

    Phase Unwrapping

    SummaryMATLAB routines

    DSP and Digital Filters (2015-6724) Fourier Transforms: 2 12 / 13

    Three types: CTFT, DTFT, DFT

    DTFT = CTFT of continuous signal impulse train

    DFT = DTFT of periodic or finite support signal

    DFT is a scaled unitary transform

    DTFT: Convolution Product; Product Circular Convolution

    DFT: Product Circular Convolution

    DFT: Zero Padding Denser freq sampling but same resolution

    Phase is only defined to within a multiple of 2.

    Whenever you integrate frequency components you get a scale factor

    12pi for CTFT and DTFT or

    1N

    for DFT

    Inverse transform, Parseval, frequency domain convolution

    For further details see Mitra: 3 & 5.

  • MATLAB routines

    2: Three DifferentFourier Transforms

    Fourier TransformsConvergence ofDTFT

    DTFT Properties

    DFT Properties

    Symmetries

    Parsevals Theorem

    Convolution

    Sampling Process

    Zero-Padding

    Phase Unwrapping

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6724) Fourier Transforms: 2 13 / 13

    fft, ifft DFT with optional zero-paddingfftshift swap the two halves of a vectorconv convolution or polynomial multiplication (not

    circular)x[n]y[n] real(ifft(fft(x).*fft(y)))unwrap remove 2 jumps from phase spectrum

  • 3: Discrete Cosine Transform

    3: Discrete CosineTransform

    DFT Problems

    DCT

    DCT of sine waveDCT/DFTEquivalence

    DCT Properties

    IDCT

    Energy Conservation

    Energy Compaction

    Frame-based coding

    Lapped Transform

    MDCT (ModifiedDCT)

    IMDCT & TDAC

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6724) Transforms: 3 1 / 15

  • DFT Problems

    3: Discrete CosineTransform

    DFT ProblemsDCT

    DCT of sine waveDCT/DFTEquivalence

    DCT Properties

    IDCT

    Energy Conservation

    Energy Compaction

    Frame-based coding

    Lapped Transform

    MDCT (ModifiedDCT)

    IMDCT & TDAC

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6724) Transforms: 3 2 / 15

    For processing 1-D or 2-D signals (especially coding), a common method isto divide the signal into frames and then apply an invertible transform toeach frame that compresses the information into few coefficients.

    The DFT has some problems when used for this purpose:

    N real x[n] N complex X[k] : 2 real, N2 1 conjugate pairs

    DFT the DTFT of a periodic signal formed by replicating x[n] . Spurious frequency components from boundary discontinuity.

    N=20f=0.08

    The Discrete Cosine Transform (DCT) overcomes these problems.

  • DCT

    3: Discrete CosineTransform

    DFT Problems

    DCTDCT of sine waveDCT/DFTEquivalence

    DCT Properties

    IDCT

    Energy Conservation

    Energy Compaction

    Frame-based coding

    Lapped Transform

    MDCT (ModifiedDCT)

    IMDCT & TDAC

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6724) Transforms: 3 3 / 15

    To form the Discrete Cosine Transform (DCT), replicate x[0 : N 1] but inreverse order and insert a zero between each pair of samples:

    0 12 23

    y[r]

    Take the DFT of length 4N real symmetric sequenceResult is real, symmetric and anti-periodic: only need first N values

    012

    23

    Y[k]

    Forward DCT: XC [k] =N1

    n=0 x[n] cos2pi(2n+1)k

    4N for k = 0 : N 1

    Compare DFT: XF [k] =N1

    n=0 x[n] expj2pi(4n+0)k

    4N

  • DCT of sine wave

    3: Discrete CosineTransform

    DFT Problems

    DCT

    DCT of sine waveDCT/DFTEquivalence

    DCT Properties

    IDCT

    Energy Conservation

    Energy Compaction

    Frame-based coding

    Lapped Transform

    MDCT (ModifiedDCT)

    IMDCT & TDAC

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6724) Transforms: 3 4 / 15

    DCT: XC [k] =N1

    n=0 x[n] cos2pi(2n+1)k

    4N

    f = mN

    f 6= mN

    x[n]N=20f=0.10

    N=20f=0.08

    |XF [k]|

    |XC [k]|

    DFT: RealComplex; Freq range [0, 1]; Poorly localizedunless f = m

    N; |XF [k]| k

    1 for Nf < k N2DCT: RealReal; Freq range [0, 0.5]; Well localized f ;

    |XC [k]| k2 for 2Nf < k < N

  • DCT/DFT Equivalence

    3: Discrete CosineTransform

    DFT Problems

    DCT

    DCT of sine wave

    DCT/DFTEquivalence

    DCT Properties

    IDCT

    Energy Conservation

    Energy Compaction

    Frame-based coding

    Lapped Transform

    MDCT (ModifiedDCT)

    IMDCT & TDAC

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6724) Transforms: 3 5 / 15

    XC [k] =N1

    n=0 x[n] cos2pi(2n+1)k

    4N0 12 23

    y[r]

    Define y[r] =

    0 r even

    x[r12

    ]r odd, 1 r 2N 1

    x[4N1r

    2

    ]r odd, 2N + 1 r 4N 1

    YF [k] =4N1

    r=0 y[r]Wkr4N where WM = e

    j2piM

    (i)=2N1

    n=0 y[2n+ 1]W(2n+1)k4N

    (ii)=N1

    n=0 y[2n+ 1]W(2n+1)k4N

    +N1

    m=0 y[4N 2m 1]W(4N2m1)k4N

    (iii)=N1

    n=0 x[n]W(2n+1)k4N +

    N1m=0 x[m]W

    (2m+1)k4N

    = 2N1

    n=0 x[n] cos2pi(2n+1)k

    4N = 2XC [k]

    (i) odd r only: r = 2n+ 1, (ii) reverse order for n N : m = 2N 1 n

    (iii) substitute y definition & W 4Nk4N = ej2pi 4Nk

    4N 1

  • DCT Properties

    3: Discrete CosineTransform

    DFT Problems

    DCT

    DCT of sine waveDCT/DFTEquivalence

    DCT PropertiesIDCT

    Energy Conservation

    Energy Compaction

    Frame-based coding

    Lapped Transform

    MDCT (ModifiedDCT)

    IMDCT & TDAC

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6724) Transforms: 3 6 / 15

    Definition: X[k] =N1

    n=0 x[n] cos2pi(2n+1)k

    4N Linear: x[n] + y[n] X[k] + Y [k] DFT ConvolutionMultiplication property does not hold / Symmetric: X[k] = X[k] since cosk = cos+k Anti-periodic: X[k + 2N ] = X[k] because:

    cos ( + ) = cos 2(2n+ 1)(k + 2N) = 2(2n+ 1)k + 8Nn+ 4NX[N ] = 0 since X[N ] = X[N ] = X[N + 2N ]

    Periodic: X[k + 4N ] = X[k + 2N ] = X[k]DCT basis functions:

    0:3:

    1: 4:

    2: 5:

  • IDCT

    3: Discrete CosineTransform

    DFT Problems

    DCT

    DCT of sine waveDCT/DFTEquivalence

    DCT Properties

    IDCTEnergy Conservation

    Energy Compaction

    Frame-based coding

    Lapped Transform

    MDCT (ModifiedDCT)

    IMDCT & TDAC

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6724) Transforms: 3 7 / 15

    y[r] = 14N4N1

    k=0 Y [k]Wrk4N =

    12N

    4N1k=0 X[k]W

    rk4N

    x[n] = y[2n+ 1] = 12N4N1

    k=0 X[k]W(2n+1)k4N [Y [k] = 2X[k]]

    (i)= 12N

    2N1k=0 X[k]W

    (2n+1)k4N

    12N2N1

    l=0 X[l]W(2n+1)(l+2N)4N

    012

    23

    Y[k]

    (ii)= 1

    N

    2N1k=0 X[k]W

    (2n+1)k4N W

    ba = e

    j 2piba

    (iii)= 1

    NX[0] + 1

    N

    N1k=1 X[k]W

    (2n+1)k4N +

    1NX[N ]W

    (2n+1)N4N

    + 1N

    N1r=1 X[2N r]W

    (2n+1)(2Nr)4N

    (iv)= 1

    NX[0] + 1

    N

    N1k=1 X[k]W

    (2n+1)k4N

    + 1N

    N1r=1 X[r]W

    (2n+1)r+2N4N

    x[n] = 1NX[0] + 2

    N

    N1k=1 X[k] cos

    2pi(2n+1)k4N = Inverse DCT

    (i) k = l + 2N for k 2N and X[k + 2N ] = X[k]

    (ii) (2n+1)(l+2N)4N =(2n+1)l

    4N + n+12

    (iii) k = 2N r for k > N (iv) X[N ] = 0 and X[2N r] = X[r]

  • Energy Conservation

    3: Discrete CosineTransform

    DFT Problems

    DCT

    DCT of sine waveDCT/DFTEquivalence

    DCT Properties

    IDCT

    EnergyConservation

    Energy Compaction

    Frame-based coding

    Lapped Transform

    MDCT (ModifiedDCT)

    IMDCT & TDAC

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6724) Transforms: 3 8 / 15

    DCT: X[k] =N1

    n=0 x[n] cos2pi(2n+1)k

    4N

    IDCT: x[n] = 1NX[0] + 2

    N

    N1k=1 X[k] cos

    2pi(2n+1)k4N

    rep

    0 12 23

    y[r]

    DFT 0

    1223

    Y[k]

    2

    Energy: E =N1

    n=0 |x[n]|2: E 2E 8NE 0.5NE

    E = 1N|X|2 [0] + 2

    N

    N1n=1 |X|

    2 [n]

    Orthogonal DCT (preserves energy)

    Define: c[k] =

    2kN

    c[0] =

    1N, c[k 6= 0] =

    2N

    ODCT: X[k] = c[k]N1

    n=0 x[n] cos2pi(2n+1)k

    4N

    IODCT: x[n] =N1

    k=0 c[k]X[k] cos2pi(2n+1)k

    4N

    Note: MATLAB dct() calculates the ODCT

  • Energy Compaction

    3: Discrete CosineTransform

    DFT Problems

    DCT

    DCT of sine waveDCT/DFTEquivalence

    DCT Properties

    IDCT

    Energy Conservation

    EnergyCompaction

    Frame-based coding

    Lapped Transform

    MDCT (ModifiedDCT)

    IMDCT & TDAC

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6724) Transforms: 3 9 / 15

    If consecutive x[n] are positively correlated, DCT concentrates energy in afew X[k] and decorrelates them.

    Example: Markov Process: x[n] = x[n 1] +1 2u[n]

    where u[n] is i.i.d. unit Gaussian.Then

    x2[n]

    = 1 and x[n]x[n 1] = .

    Covariance of vector x is Si,j =xxH

    i,j

    = |ij|.

    Suppose ODCT of x is Cx and DFT is Fx.

    Covariance of Cx isCxxHCH

    = CSCH (similarly FSFH)

    Diagonal elements give mean coefficient energy.

    5 10 15 20 25 30

    50

    60

    70

    80

    90

    100DCT

    DFT

    =0.9N=32

    No of coefficients

    C

    u

    m

    u

    l

    a

    t

    i

    v

    e

    e

    n

    e

    r

    g

    y

    (

    %

    )

    Used in MPEG and JPEG (superseded byJPEG2000 using wavelets)

    Used in speech recognition to decorrelatespectral coeficients: DCT of log spectrum

    Energy compaction good for coding (low-valued coefficients can be set to 0)Decorrelation good for coding and for probability modelling

  • Frame-based coding

    3: Discrete CosineTransform

    DFT Problems

    DCT

    DCT of sine waveDCT/DFTEquivalence

    DCT Properties

    IDCT

    Energy Conservation

    Energy Compaction

    Frame-basedcoding

    Lapped Transform

    MDCT (ModifiedDCT)

    IMDCT & TDAC

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6724) Transforms: 3 10 / 15

    Divide continuous signalinto frames

    Apply DCT to each frame

    Encode DCT

    e.g. keep only 30 X[k]

    Apply IDCT y[n]

    x[n]

    X[k] k=30/220

    y[n]y[n]-x[n]

    Problem: Coding may create discontinuities at frame boundariese.g. JPEG, MPEG use 8 8 pixel blocks

    8.3 kB (PNG) 1.6 kB (JPEG) 0.5 kB (JPEG)

  • Lapped Transform

    3: Discrete CosineTransform

    DFT Problems

    DCT

    DCT of sine waveDCT/DFTEquivalence

    DCT Properties

    IDCT

    Energy Conservation

    Energy Compaction

    Frame-based coding

    Lapped TransformMDCT (ModifiedDCT)

    IMDCT & TDAC

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6724) Transforms: 3 11 / 15

    Modified Discrete Cosine Transform (MDCT): overlapping frames 2N long

    x[0 : 2N 1]MDCT X0[0 : N 1]IMDCT y0[0 : 2N 1]

    x[N : 3N 1]MDCT X1[N : 2N 1]IMDCT y1[N : 3N 1]

    x[2N : 4N 1]MDCT X2[2N : 3N 1]IMDCT y2[2N : 3N 1]

    y[n] = y0[n] + y1[n] + y2[n]

    X0[k]

    y0[n]X1[k]

    y1[n]

    X2[k]

    y2[n] y[n]

    y[n]-x[n] = error

    x[n]

    0 N

    N

    2N

    2N

    3N

    3N

    4N

    4N

    MDCT: 2N N coefficients, IMDCT: N 2N samplesAdd yi[n] together to get y[n]. Only two non-zero terms far any n.Errors cancel exactly: Time-domain alias cancellation (TDAC)

  • MDCT (Modified DCT)

    3: Discrete CosineTransform

    DFT Problems

    DCT

    DCT of sine waveDCT/DFTEquivalence

    DCT Properties

    IDCT

    Energy Conservation

    Energy Compaction

    Frame-based coding

    Lapped Transform

    MDCT (ModifiedDCT)

    IMDCT & TDAC

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6724) Transforms: 3 12 / 15

    MDCT: XM [k] =2N1

    n=0 x[n] cos2pi(2n+1+N)(2k+1)

    8N

    IMDCT: yA,B [n] =1N

    N1k=0 XM [k] cos

    2pi(2n+1+N)(2k+1)8N

    MDCT from a DCT of length 2N :

    Split x[n] into four N2 -vectors:x =

    [a b c d

    ]

    Form the N -vectoru =

    [dc a

    b

    ]

    where c is in reverse order

    Form v =[u u

    ]

    Take 2N DCT: v VC

    Symmetry VC [2k] = 0

    Set XM [k] = VC [2k + 1]

    a b c da

    -b 1peaks sharpened.Pole at z = p gives peak bandwidth 2 |log |p|| 2 (1 |p|)For pole near unit circle, decrease bandwidth by 2 log

  • IIR Impulse response examples

    5: Filters

    Difference Equations

    FIR Filters

    FIR Symmetries

    IIR FrequencyResponse

    Negating z

    Cubing z

    Scaling z

    IIR Impulseresponse examples

    IIR Impulse response

    Other BIBOresponses

    Stability Triangle

    Low-pass filter

    Allpass filters

    Group Delay

    Minimum Phase

    Linear Phase Filters

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6724) Filters: 5 9 / 19

    To find the impulse response of B(z)A(z) , use partial fractions:

    Example 1: M < N

    B(z)A(z) =

    13.4z1

    10.3z10.4z2 =3

    1+0.5z1 +2

    10.8z1

    h[n] = (3 (0.5)n 2 (0.8)n) u[n]Example 2: M N

    B(z)A(z) =

    25.7z1+0.2z2+0.8z3

    10.3z10.4z2

    = 1 2z1 + 13.4z110.3z10.4z2= 1 2z1 + 31+0.5z1 + 210.8z1

    h[n] = [n] 2[n 1] + (3 (0.5)n 2 (0.8)n) u[n]Example 3: repeated pole at z = 0.5

    B(z)A(z) =

    35z11.3z2

    1+0.3z10.55z20.2z3

    = 21+0.5z1 +3

    (1+0.5z1)2+ 210.8z1

    h[n] = (2 (0.5)n + 3(n+ 1) (0.5)n 2 (0.8)n)u[n]

  • IIR Impulse response

    5: Filters

    Difference Equations

    FIR Filters

    FIR Symmetries

    IIR FrequencyResponse

    Negating z

    Cubing z

    Scaling z

    IIR Impulse responseexamples

    IIR Impulseresponse

    Other BIBOresponses

    Stability Triangle

    Low-pass filter

    Allpass filters

    Group Delay

    Minimum Phase

    Linear Phase Filters

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6724) Filters: 5 10 / 19

    H(z) = B(z)A(z) we want h[n], the inverse z-Transform of H(z).

    (1) Assume M < N else, do a long division: H(z) = D(z) + B(z)A(z)

    (2) Factorize A(z) =Np

    i=1

    (1 piz1

    )Ki (Np= # of distinct poles)(3) Then B(z)

    A(z) =Np

    i=1

    Kik=1

    ri,k

    (1piz1)k (Ki= multiplicity of pi)

    where ri,k =(pi)

    kKi

    (Kik)!dKik

    d(z1)Kik

    (B(z)A(z) (1 piz1)Ki

    )z=pi

    For the common case Ki = 1 i (e.g. all poles distinct):B(z)A(z) =

    Npi=1

    ri1piz1

    where ri =B(z)A(z) (1 piz1)

    z=pi

    (4) The impulse response is given by

    h[n] =Np

    i=1

    Kik=1C

    n+k1k1 ri,kp

    ni for n 0

    where C =!

    !()! is a binomial coefficient Cn+k1k1 nk1

    For the common case Ki = 1 i: h[n] =Np

    i=1 ripni for n 0

  • [Impulse Response: Proof of (3)]

    DSP and Digital Filters (2015-6724) Filters: 5 note 1 of slide 10

    [You do not need to memorise this proof]

    We assume thatB(z)A(z)

    =Np

    j=1

    Kjl=1

    rj,l

    (1pjz1)l and we want to determine ri,k

    (1) Multiply both sides by(1 piz

    1)Ki :

    B(z)A(z)

    (1 piz

    1)Ki =Npj=1Kjl=1 rj,l(1piz1)Ki(1pjz1)l

    now separate out the term with j = i:

    B(z)A(z)

    (1 piz

    1)Ki =Ki

    l=1 ri,l(1 piz

    1)Kil +j 6=iKjl=1 rj,l(1piz1)Ki(1pjz1)l

    (2) DifferentiateKi k times with respect to z1 : d

    Kik

    d(z1)Kikand evaluate at z = pi

    1 k Ki Ki k < Ki so we are differentiating < Ki times.

    Hence all terms in

    j 6=i

    Kjl=1

    rj,l(1piz1)Ki

    (1pjz1)l will still include a factor

    (1 piz

    1)in the

    numerator and will equal zero at z = pi.

    Similarly, terms inKi

    l=1 ri,l(1 piz

    1)Kil with l < k will also vanish.

    Also, terms inKi

    l=1 ri,l(1 piz

    1)Kil with l > k will also differentiate to zero.

    The only term remaining is: (p)Kik (Ki k)!ri,k from which the result follows.

    [Similarly(dn

    dxn(xm)

    )x=0

    is zero unless m = n in which case it equals m!]

  • [Impulse Response: Proof of (4)]

    DSP and Digital Filters (2015-6724) Filters: 5 note 2 of slide 10

    [You do not need to memorise this proof]

    We use induction on k to show that(1 pz1

    )k=

    n=0 Cn+k1k1 p

    nzn

    (1) Suppose the formula is true for k and differentiate both sides with respect to z1:

    dd(z1)

    {(1 pz1

    )k=

    n=0 Cn+k1k1 p

    nzn}

    This gives:

    pk(1 pz1

    )(k+1)=

    n=0 nCn+k1k1 p

    nz(n1) =

    n=1 nCn+k1k1 p

    nz(n1)

    where we have omitted the term with n = 0 because it equals zero.

    Now substitute, m = n 1:

    pk(1 pz1

    )(k+1)=

    m=0(m+ 1)Cm+kk1 p

    m+1zm

    (1 pz1

    )(k+1)=

    m=0m+1k

    Cm+kk1 p

    mzm =

    m=0 Cm+kk

    pmzm

    which proves the result for k + 1.

    (2) To start the induction at k = 1:(1 pz1

    )1=

    n=0 Cn0 p

    nzn =

    n=0 pnzn

    This is true from the standard geometric progression formula. (Note that Cn0 = 1n).

  • Other BIBO responses

    5: Filters

    Difference Equations

    FIR Filters

    FIR Symmetries

    IIR FrequencyResponse

    Negating z

    Cubing z

    Scaling z

    IIR Impulse responseexamples

    IIR Impulse response

    Other BIBOresponses

    Stability Triangle

    Low-pass filter

    Allpass filters

    Group Delay

    Minimum Phase

    Linear Phase Filters

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6724) Filters: 5 11 / 19

    All LTI systems described by difference equations have h[n] decayingexponentially or exponentially times a power of n.

    It is perfectly possible to have BIBO stable LTI systems whose impulseresponses decay more slowly than this.

    Example: h[n] = 11+n2 for n 0BIBO stable since

    |h[n]| = 2.077...

  • Stability Triangle

    5: Filters

    Difference Equations

    FIR Filters

    FIR Symmetries

    IIR FrequencyResponse

    Negating z

    Cubing z

    Scaling z

    IIR Impulse responseexamples

    IIR Impulse response

    Other BIBOresponses

    Stability TriangleLow-pass filter

    Allpass filters

    Group Delay

    Minimum Phase

    Linear Phase Filters

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6724) Filters: 5 12 / 19

    Not normally easy to tell if poles lie within|z| = 1, but easy test for a 2nd order filter:Suppose A(z) = 1 + a[1]z1 + a[2]z2

    The roots are p1,2 =a[1]

    a[1]24a[2]

    2

    Want the conditions that |p1,2| < K-2K 0 2K

    0

    PQ

    RSK

    2

    -K2

    a[1]

    Case 1: Real roots:(P) a[1]2 4a[2](Q) 2K < a[1]

    a[1]2 4a[2] < 2K

    a[1]2 4a[2] < 2K a[1]

    a[1]2 4a[2] < 4K2 4a[1]K + a[1]2 a[2] > K2 a[1]K

    Case 2: Complex roots:(R) a[1]2 < 4a[2]

    (S) |p1,2|2 = a[2] < K2

    Hence coefficients must lie within a stability triangle.

  • Low-pass filter

    5: Filters

    Difference Equations

    FIR Filters

    FIR Symmetries

    IIR FrequencyResponse

    Negating z

    Cubing z

    Scaling z

    IIR Impulse responseexamples

    IIR Impulse response

    Other BIBOresponses

    Stability Triangle

    Low-pass filterAllpass filters

    Group Delay

    Minimum Phase

    Linear Phase Filters

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6724) Filters: 5 13 / 19

    1st order low pass filter: extremely commony[n] = (1 p)x[n] + py[n 1] H(z) = 1p1pz1

    Impulse response:h[n] = (1 p)pn = (1 p)en

    where = 1 ln p is the time constant in samples.

    Magnitude response:H(ej) = 1p

    12p cos+p2

    Low-pass filter with DC gain of unity.

    3 dB frequency is 3dB = cos1(1 (1p)22p

    ) 2 1p1+p 1

    Compare continuous time: HC(j) =1

    1+j

    Indistinguishable for low but H(ej) is periodic, HC(j) is not

    -1 0 1-1

    -0.5

    0

    0.5

    1

    (z)

    p=0.80

    0.01 0.1

    -30

    -20

    -10

    0

    H(j)

    HC(j)

    1/ 2pi

    (rad/sample)

  • Allpass filters

    5: Filters

    Difference Equations

    FIR Filters

    FIR Symmetries

    IIR FrequencyResponse

    Negating z

    Cubing z

    Scaling z

    IIR Impulse responseexamples

    IIR Impulse response

    Other BIBOresponses

    Stability Triangle

    Low-pass filter

    Allpass filtersGroup Delay

    Minimum Phase

    Linear Phase Filters

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6724) Filters: 5 14 / 19

    If a[n] is real and a[n] = b[M n] then we have an allpass filterH(ej) =

    Mr=0 b[r]e

    jr

    Mr=0 b[r]e

    j(Mr) = ejM

    Mr=0 b[r]e

    jr

    Mr=0 b[r]e

    jr

    The two sums are complex conjugates they have the same magnitudeHence

    H(ej) = 1 allpassHowever phase is not constant: H(ej) = M + 2B(ej)

    1st order allpass: H(z) = p+z1

    1pz1 = p 1p1z1

    1pz1

    Pole at p and zero at p1: reflected in unit circle

    Constant distance ratio:ej p = |p|

    ej 1p

    0 1 2 300.20.40.60.8

    1

    0 1 2 3

    -3

    -2

    -1

    0

    -1 0 1-1

    -0.5

    0

    0.5

    1

    (z)

    In an allpass filter, the zeros are the poles reflected in the unit circle.

  • Group Delay

    5: Filters

    Difference Equations

    FIR Filters

    FIR Symmetries

    IIR FrequencyResponse

    Negating z

    Cubing z

    Scaling z

    IIR Impulse responseexamples

    IIR Impulse response

    Other BIBOresponses

    Stability Triangle

    Low-pass filter

    Allpass filters

    Group DelayMinimum Phase

    Linear Phase Filters

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6724) Filters: 5 15 / 19

    Group delay: H(ej) = dH(ej)

    d= delay of the modulation envelope.

    Trick to get at phase: lnH(ej) = lnH(ej)+ jH(ej)

    H =d((lnH(ej)))

    d=

    (1

    H(ej)dH(ej)

    d

    )=

    (zH(z)

    dHdz

    )z=ej

    H(ej) =

    n=0 h[n]ejn= F (h[n]) [F = DTFT]

    dH(ej)d

    =

    n=0jnh[n]ejn= jF (nh[n])

    H = (

    1H(ej)

    dH(ej)d

    )=

    (jF(nh[n])F(h[n])

    )=

    (F(nh[n])F(h[n])

    )

    Example: H(z) = 11pz1 H = [1 p]= (pej

    1pej

    )

    -1 0 1-1

    -0.5

    0

    0.5

    1

    (z)

    0 1 2 3

    -0.8

    -0.6

    -0.4

    -0.2

    0p=0.80

    0 1 2 3

    0

    1

    2

    3 p=0.80

    H

    Average group delay (over ) = (# poles # zeros) within the unit circleZeros on the unit circle count

  • [Group Delay Properties]

    DSP and Digital Filters (2015-6724) Filters: 5 note 1 of slide 15

    The group delay of a filter H(z) at a frequency , measured in seconds or samples, gives the time delay

    of the envelope of a modulated sine wave at a frequency . It is defined as H(ej) =

    dH(ej)d

    .

    For example, H(z) = zk defines a filter that delays its input by k samples and we can calculate thegroup delay by evaluating

    H(ej) =

    dH(ej)

    d=

    d

    d

    (ejk

    )=

    d

    d(k) = k

    which tells us that this filter has a constant group delay of k samples that is independent of .

    The average value of H equals the total change in H(ej) as goes from pi to +pi divided by

    2pi. If you imagine an elastic string connecting a pole or zero to the point z = ej, you can see that as goes from pi to +pi the string will wind once around the pole or zero if it is inside the unit circle butnot if it is outside. Thus, the total change in H(ej) is equal to 2pi times the number of poles insidethe unit circle minus the number of zeros inside the unit circle. A zero that is exactly on the unit circlecounts 1

    2since there is a sudden discontinuity of pi in H(ej) as passes through the zero position.

    When you multiply or divide complex numbers, their phases add or subtract, so it follows that whenyou multiply or divide transfer functions their group delays will add or subtract. Thus, for example,

    the group delay of an IIR filter, H(z) =B(z)A(z)

    , is given by H = B A. This means too that we

    can determine the group delay of a factorized transfer function by summing the group delays of theindividual factors.

  • [Group Delay from h[n] or H(z)]

    DSP and Digital Filters (2015-6724) Filters: 5 note 2 of slide 15

    The slide shows how to determine the group delay, H , from either the impulse response, h[n], orthe transfer function, H(z). We start by using a trick that is very common: if you want to get atthe magnitude and phase of a complex number separately, you can do so by taking its natural log:ln(rej

    )= ln |r| + j or, in general, lnH = ln |H| + jH. By rearranging this equation, we get

    H = (lnH) where ( ) denotes taking the imaginary part of a complex number. Using this, we canwrite

    H =d((lnH(ej)

    ))d

    =

    (d(lnH(ej)

    )d

    )=

    (1

    H(ej)

    dH(ej)

    d

    ). (1)

    By going back to the definition of the DTFT, we find that H(ej) = F (h[n]) anddH(ej)

    d=

    jF (nh[n]) where F ( ) denotes the DTFT. Substituting these expressions into the above equationgives us a formula for H in terms of the impulse response h[n].

    H =

    (F (nh[n])

    F (h[n])

    )(2)

    In order to express H in terms of z, we first note that if z = ej then dz

    d= jz. By substituting

    z = ej into equation (1), we get

    H =

    (1

    H(z)

    dH(z)

    d

    )=

    (1

    H(z)

    dH(z)

    dz

    dz

    d

    )=

    (jz

    H(z)

    dH(z)

    dz

    )=

    (z

    H(z)

    dH(z)

    dz

    )z=ej

    .

  • [Group Delay Example]

    DSP and Digital Filters (2015-6724) Filters: 5 note 3 of slide 15

    As an example, suppose we want to determine the group delay of : H(z) = 11pz1

    . As noted above,

    if H(z) =B(z)A(z)

    , then H = B A. In this case B = 0 so H = [1 p].

    Using equation (2) gives H = (

    F([0 p])F([1 p])

    )since nh[n] = [0 1] [1 p].

    Applying the definition of the DTFT, we get

    H =

    (pej

    1 pej

    )=

    (p

    ej p

    )=

    (p(ej p

    ))(ej p) (ej p)

    =p cos p2

    1 2p cos + p2

    As demonstrated above, the average value of H is zero for this filter because there is one pole and onezero inside the unit circle.

  • Minimum Phase

    5: Filters

    Difference Equations

    FIR Filters

    FIR Symmetries

    IIR FrequencyResponse

    Negating z

    Cubing z

    Scaling z

    IIR Impulse responseexamples

    IIR Impulse response

    Other BIBOresponses

    Stability Triangle

    Low-pass filter

    Allpass filters

    Group Delay

    Minimum PhaseLinear Phase Filters

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6724) Filters: 5 16 / 19

    Average group delay (over ) = (# poles # zeros) within the unit circle

    zeros on the unit circle count Reflecting an interior zero to the exteriormultiplies

    H(ej) by a constant butincreases average group delay by 1 sample. 0 1 2 3

    0

    1

    2

    3

    4

    -1 0 1

    -1-0.5

    00.5

    1

    (z)

    0 1 2 3

    -10

    -5

    0

    -1 0 1

    -1-0.5

    00.5

    1

    (z)

    0 1 2 3-10

    0

    10

    20

    30

    H

    A filter with all zeros inside the unit circle is a minimum phase filter: Lowest possible group delay for a given magnitude response Energy in h[n] is concentrated towards n = 0

  • Linear Phase Filters

    5: Filters

    Difference Equations

    FIR Filters

    FIR Symmetries

    IIR FrequencyResponse

    Negating z

    Cubing z

    Scaling z

    IIR Impulse responseexamples

    IIR Impulse response

    Other BIBOresponses

    Stability Triangle

    Low-pass filter

    Allpass filters

    Group Delay

    Minimum Phase

    Linear PhaseFilters

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6724) Filters: 5 17 / 19

    The phase of a linear phase filter is: H(ej) = 0 Equivalently constant group delay: H = dH(e

    j)d

    =

    A filter has linear phase iff h[n] is symmetric or antisymmetric:h[n] = h[M n] n or else h[n] = h[M n] n

    M can be even ( mid point) or odd ( mid point)Proof :2H(ej) =

    M0 h[n]e

    jn +M

    0 h[M n]ej(Mn)= ej

    M2

    M0 h[n]e

    j(nM2 ) + h[M n]ej(nM2 )

    h[n] symmetric:

    2H(ej) = 2ejM2

    M0 h[n] cos

    (n M2

    )

    h[n] anti-symmetric:

    2H(ej) = 2jejM2 M0 h[n] sin(n M2

    )

    = 2ej(pi2 +

    M2 )M

    0 h[n] sin(n M2

    )

  • Summary

    5: Filters

    Difference Equations

    FIR Filters

    FIR Symmetries

    IIR FrequencyResponse

    Negating z

    Cubing z

    Scaling z

    IIR Impulse responseexamples

    IIR Impulse response

    Other BIBOresponses

    Stability Triangle

    Low-pass filter

    Allpass filters

    Group Delay

    Minimum Phase

    Linear Phase Filters

    SummaryMATLAB routines

    DSP and Digital Filters (2015-6724) Filters: 5 18 / 19

    Useful filters have difference equations: Freq response determined by pole/zero positions N M zeros at origin (or M N poles) Geometric construction of |H(ej)|

    Pole bandwidth 2 |log |p|| 2 (1 |p|) Stable if poles have |p| < 1

    Allpass filter: a[n] = b[M n] Reflecting a zero in unit circle leaves |H(ej)| unchanged

    Group delay: H(ej

    )= dH(ej)

    dsamples

    Symmetrical h[n] H(ej

    )= M2

    Average H over = (# poles # zeros) within the unit circle Minimum phase if zeros have |q| 1

    Lowest possible group delay for given |H(ej)| Linear phase = Constant group Delay = symmetric/antisymmetric h[n]

    For further details see Mitra: 6, 7.

  • MATLAB routines

    5: Filters

    Difference Equations

    FIR Filters

    FIR Symmetries

    IIR FrequencyResponse

    Negating z

    Cubing z

    Scaling z

    IIR Impulse responseexamples

    IIR Impulse response

    Other BIBOresponses

    Stability Triangle

    Low-pass filter

    Allpass filters

    Group Delay

    Minimum Phase

    Linear Phase Filters

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6724) Filters: 5 19 / 19

    filter filter a signalimpz Impulse response

    residuez partial fraction expansiongrpdelay Group Delayfreqz Calculate filter frequency response

  • 6: Window Filter Design

    6: Window FilterDesign

    Inverse DTFT

    Rectangular window

    Dirichlet Kernel

    Window relationships

    Common Windows

    Uncertainty principle

    Order Estimation

    Example Design

    Frequency sampling

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6729) Windows: 6 1 / 12

  • Inverse DTFT

    6: Window FilterDesign

    Inverse DTFTRectangular window

    Dirichlet Kernel

    Window relationships

    Common Windows

    Uncertainty principle

    Order Estimation

    Example Design

    Frequency sampling

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6729) Windows: 6 2 / 12

    For any BIBO stable filter, H(ej) is the DTFT of h[n]

    H(ej) = h[n]e

    jn h[n] = 12

    H(ej)ejnd

    If we know H(ej) exactly, the IDTFT gives the ideal h[n]

    Example: Ideal Lowpass filter

    H(ej) =

    {1 || 0

    0 || > 0 h[n] = sin0n

    n

    -2 0 20

    0.5

    1

    20

    0

    2pi/0

    Note: Width in is 20, width in n is20: product is 4 always

    Sadly h[n] is infinite and non-causal. Solution: multiply h[n] by a window

  • Rectangular window

    6: Window FilterDesign

    Inverse DTFT

    Rectangularwindow

    Dirichlet Kernel

    Window relationships

    Common Windows

    Uncertainty principle

    Order Estimation

    Example Design

    Frequency sampling

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6729) Windows: 6 3 / 12

    Truncate to M2 to make finite; h1[n] is now of length M + 1

    MSE Optimality:Define mean square error (MSE) in frequency domain

    E = 12

    H(ej)H1(ej)2 d= 12

    H(ej)M2M

    2

    h1[n]ejn

    2 dMinimum E is when h1[n] = (h[n])Proof: Differentiate w.r.t. h1[r] and set to zero

    However: 9% overshoot at a discontinuity even for large n.

    0

    h1[n]M=14

    0 1 2 30

    0.5

    1

    M=14M=28

    Normal to delay by M2 to make causal. Multiplies H(ej) by ej

    M

    2.

  • Dirichlet Kernel

    6: Window FilterDesign

    Inverse DTFT

    Rectangular window

    Dirichlet KernelWindow relationships

    Common Windows

    Uncertainty principle

    Order Estimation

    Example Design

    Frequency sampling

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6729) Windows: 6 4 / 12

    Truncation Multiply h[n] by a rectangular window, w[n] = M2nM

    2

    Circular Convolution HM+1(ej) = 12H(e

    j)W (ej)

    W (ej) =M

    2

    M2

    ejn(i)= 1 + 2

    0.5M1 cos (n)

    (ii)= sin 0.5(M+1)sin 0.5

    Proof: (i) ej(n) + ej(+n) = 2 cos (n) (ii) Sum geom. progression

    Effect: convolve ideal freq response with Dirichlet kernel (aliassed sinc)

    -2 0 2

    0

    0.5

    1

    -2 0 2

    0

    0.5

    1

    4pi/(M+1)

    -2 0 2

    0

    0.5

    1

    -2 0 2

    0

    0.5

    1 M=14

    Provided that 4M+1 < 20 M + 1 >

    20:

    Passband ripple: 4M+1 , stopband

    2M+1

    Transition pk-to-pk: 4M+1

    Transition Gradient: d|H|d

    =0

    M+12

  • [Dirichlet Kernel]

    DSP and Digital Filters (2015-6729) Windows: 6 note 1 of slide 4

    Other properties of W (ej):

    The DTFT of a symmetric rectangular window of length M + 1 is W (ej) =sin 0.5(M+1)

    sin 0.5. For

    small x we can approximate sinx x; the error is < 1% for x < 0.25. So, for < 0.5,we haveW (ej) 21 sin 0.5(M + 1).

    The peak value is at = 0 and equals M + 1;this means that the peak gradient of HM+1(ej) will

    be M+12pi

    .

    The minimum value of W (ej) is approximately equal to the minimuum of 21 sin 0.5(M + 1)which is when sin 0.5(M + 1) = 1 i.e. = 1.5pi

    0.5(M+1)= 3pi

    M+1. Hence minW (ej)

    min 21 sin 0.5(M + 1) = M+11.5pi

    .

    Passband and Stopband ripple:

    The ripple in W (ej) =sin 0.5(+1)sin 0.5

    has a period of = 2pi0.5(+1)

    = 4piM+1

    and this gives rise to

    ripple with this period in both the passband and stopband of HM+1(ej).

    However the stopband ripple takes the value of HM+1(ej) alternately positive and negative. If you

    plot the magnitude response,HM+1(ej) then this ripple will be full-wave rectified and will double in

    frequency so its period will now be 2piM+1

    .

  • Window relationships

    6: Window FilterDesign

    Inverse DTFT

    Rectangular window

    Dirichlet Kernel

    Windowrelationships

    Common Windows

    Uncertainty principle

    Order Estimation

    Example Design

    Frequency sampling

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6729) Windows: 6 5 / 12

    When you multiply an impulse response by a window M + 1 longHM+1(e

    j) = 12H(ej)W (ej)

    -2 0 20

    0.5

    1

    -2 0 2

    0

    10

    20

    M=20

    -2 0 20

    0.5

    1

    1

    (a) passband gain w[0]; peak w[0]2 +0.52

    mainlobe

    W (ej)drectangular window: passband gain = 1; peak gain = 1.09

    (b) transition bandwidth, = width of the main lobetransition amplitude, H = integral of main lobe2rectangular window: = 4

    M+1 , H 1.18

    (c) stopband gain is an integral over oscillating sidelobes of W (ej)rect window:

    minH(ej) = 0.09 minW (ej) = M+11.5(d) features narrower than the main lobe will be broadened and

    attenuated

  • Common Windows

    6: Window FilterDesign

    Inverse DTFT

    Rectangular window

    Dirichlet Kernel

    Window relationships

    Common WindowsUncertainty principle

    Order Estimation

    Example Design

    Frequency sampling

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6729) Windows: 6 6 / 12

    Rectangular: w[n] 1dont use

    Hanning: 0.5 + 0.5c1ck = cos

    2knM+1

    rapid sidelobe decay

    Hamming: 0.54 + 0.46c1best peak sidelobe

    Blackman-Harris 3-term:0.42 + 0.5c1 + 0.08c2

    best peak sidelobe

    Kaiser:I0

    (

    1( 2nM )

    2

    )

    I0()

    controls width v sidelobesGood compromise:Width v sidelobe v decay

    0 1 2 3

    -50

    0-13 dB6.27/(M+1)

    0 1 2 3

    -50

    0-31 dB

    12.56/(M+1)

    0 1 2 3

    -50

    0

    -40 dB12.56/(M+1)

    0 1 2 3

    -50

    0

    -70 dB

    18.87/(M+1)

    0 1 2 3

    -50

    0

    -40 dB13.25/(M+1)

    = 5.3

    0 1 2 3

    -50

    0

    -70 dB

    21.27/(M+1) = 9.5

  • Uncertainty principle

    6: Window FilterDesign

    Inverse DTFT

    Rectangular window

    Dirichlet Kernel

    Window relationships

    Common Windows

    Uncertaintyprinciple

    Order Estimation

    Example Design

    Frequency sampling

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6729) Windows: 6 7 / 12

    CTFT uncertainty principle:(

    t2|x(t)|2dt|x(t)|2dt

    ) 12

    ( 2|X(j)|2d|X(j)|2d

    ) 12

    12

    The first term measures the width of x(t) around t = 0.

    It is like if |x(t)|2was a zero-mean probability distribution.

    The second term is similarly the width of X(j) in frequency.A signal cannot be concentrated in both time and frequency.

    So a short window cannot have a narrow main lobe.

    Proof:Assume

    |x(t)|

    2dt = 1

    |X(j)|

    2d = 2 [Parseval]

    Set v(t) = dxdt V (j) = jX(j) [by parts]

    Nowtxdx

    dtdt= 12 tx

    2t=

    12x

    2dt = 12 [by parts]

    So 14 = txdx

    dtdt2 ( t2x2dt) ( dx

    dt

    2 dt) [Schwartz]=(

    t2x2dt) (

    |v(t)|2 dt)=(

    t2x2dt) (

    12

    |V (j)|2 d

    )=(

    t2x2dt) (

    12

    2 |X(j)|

    2d)

    No exact equivalent for DTFT/DFT but a similar effect is true

  • [Uncertainty Principle Proof Steps]

    DSP and Digital Filters (2015-6729) Windows: 6 note 1 of slide 7

    (1) Suppose v(t) = dxdt

    . Then integrating the CTFT definition by parts w.r.t. t gives

    X(j) =

    x(t)ejtdt =

    [1j

    x(t)ejt]

    + 1j

    dx(t)dt

    ejtdt = 0 + 1j

    V (j)

    (2) Since ddt

    (12x2

    )= x dx

    dt, we can apply integration by parts to get

    tx dx

    dtdt =

    [t 1

    2x2

    ]

    t=

    dtdt 1

    2x2dt = 1

    2

    x2dt = 1

    2 1 = 1

    2

    It follows that

    tx dxdt

    dt

    2 = ( 12 )2 = 14 which we will use below.(3) The Cauchy-Schwarz inequality is that in a complex inner product space

    |u v|2 (u u) (v v). For the inner-product space of real-valued square-integrable functions,

    this becomes

    u(t)v(t)dt2

    u2(t)dt

    v2(t)dt. We apply this with u(t) = tx(t)

    and v(t) =dx(t)dt

    to get

    14=

    tx dxdt

    dt

    2 ( t2x2dt)( (

    dxdt

    )2dt

    )=

    (t2x2dt

    ) (v2(t)dt

    )

    (4) From Parsevals theorem for the CTFT,v2(t)dt = 1

    2pi

    |V (j|2 d. From step (1), we can

    substitute V (j) = jX(j) to obtainv2(t)dt = 1

    2pi

    2 |X(j|2 d. Making this substitution

    in (3) gives14

    (t2x2dt

    ) (v2(t)dt

    )=

    (t2x2dt

    ) (12pi

    2 |X(j|2 d

    )

  • Order Estimation

    6: Window FilterDesign

    Inverse DTFT

    Rectangular window

    Dirichlet Kernel

    Window relationships

    Common Windows

    Uncertainty principle

    Order EstimationExample Design

    Frequency sampling

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6729) Windows: 6 8 / 12

    Several formulae estimate the required order of a filter, M .

    E.g. for lowpass filter

    Estimated order is

    M 5.64.3 log10()21

    820 log10 2.2

    Required M increases as either thetransition width, 2 1, or the gaintolerances and get smaller.Only approximate.

    Example:Transition band: f1 = 1.8 kHz, f2 = 2.0 kHz, fs = 12 kHz,.

    1 =2f1fs

    = 0.943, 2 =2f2fs

    = 1.047

    Ripple: 20 log10 (1 + ) = 0.1 dB, 20 log10 = 35 dB

    = 100.1

    20 1 = 0.0116, = 1035

    20 = 0.0178

    M 5.64.3 log

    10(2104)1.0470.943 =

    10.250.105 = 98 or

    3582.2 = 117

  • Example Design

    6: Window FilterDesign

    Inverse DTFT

    Rectangular window

    Dirichlet Kernel

    Window relationships

    Common Windows

    Uncertainty principle

    Order Estimation

    Example DesignFrequency sampling

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6729) Windows: 6 9 / 12

    Specifications:Bandpass: 1 = 0.5, 2 = 1Transition bandwidth: = 0.1Ripple: = = 0.02

    20 log10 = 34 dB20 log10 (1 + ) = 0.17 dB

    Order:M 5.64.3 log10()

    21= 92

    Ideal Impulse Response:Difference of two lowpass filtersh[n] = sin2n

    n sin1n

    n

    Kaiser Window: = 2.5

    0

    M=92

    0 1 2 30

    0.5

    1

    0 1 2 30

    0.5

    1 M=92 = 2.5

    0 1 2 3-60

    -40

    -20

    0 M=92 = 2.5

  • Frequency sampling

    6: Window FilterDesign

    Inverse DTFT

    Rectangular window

    Dirichlet Kernel

    Window relationships

    Common Windows

    Uncertainty principle

    Order Estimation

    Example Design

    Frequencysampling

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6729) Windows: 6 10 / 12

    Take M + 1 uniform samples of H(ej); take IDFT to obtain h[n]

    Advantage:exact match at sample points

    Disadvantage:poor intermediate approximation if spectrum is varying rapidly

    Solutions:(1) make the filter transitions smooth over width(2) oversample and do least squares fit (cant use IDFT)(3) use non-uniform points with more near transition (cant use IDFT)

    -2 0 20

    0.5

    1 M+1=93

    0 1 2 3

    0

    0.5

    1 M+1=93

  • Summary

    6: Window FilterDesign

    Inverse DTFT

    Rectangular window

    Dirichlet Kernel

    Window relationships

    Common Windows

    Uncertainty principle

    Order Estimation

    Example Design

    Frequency sampling

    SummaryMATLAB routines

    DSP and Digital Filters (2015-6729) Windows: 6 11 / 12

    Make an FIR filter by windowing the IDTFT of the ideal response

    Ideal lowpass has h[n] = sin0nn

    Add/subtract lowpass filters to make any piecewise constantresponse

    Ideal filter response is with the DTFT of the window Rectangular window (W (z) =Dirichlet kernel) has 13 dB

    sidelobes and is always a bad idea Hamming, Blackman-Harris are good Kaiser good with trading off main lobe width v. sidelobes

    Uncertainty principle: cannot be concentrated in both time andfrequency

    Frequency sampling: IDFT of uniform frequency samples: not so great

    For further details see Mitra: 7, 10.

  • MATLAB routines

    6: Window FilterDesign

    Inverse DTFT

    Rectangular window

    Dirichlet Kernel

    Window relationships

    Common Windows

    Uncertainty principle

    Order Estimation

    Example Design

    Frequency sampling

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6729) Windows: 6 12 / 12

    diric(x,n) Dirichlet kernel: sin 0.5nxsin 0.5xhanninghammingkaiser

    Window functions(Note periodic option)

    kaiserord Estimate required filter order and

  • 7: Optimal FIR filters

    7: Optimal FIRfilters

    Optimal Filters

    Alternation TheoremChebyshevPolynomials

    Maximal ErrorLocationsRemez ExchangeAlgorithm

    Determine Polynomial

    Example Design

    FIR Pros and Cons

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6729) Optimal FIR: 7 1 / 11

  • Optimal Filters

    7: Optimal FIR filters

    Optimal FiltersAlternation TheoremChebyshevPolynomials

    Maximal ErrorLocationsRemez ExchangeAlgorithm

    Determine Polynomial

    Example Design

    FIR Pros and Cons

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6729) Optimal FIR: 7 2 / 11

    We restrict ourselves to zero-phase filters of odd length M + 1, symmetricaround h[0], i.e. h[n] = h[n].

    H() = H(ej) =M

    2

    M2

    h[n]ejn= h[0] + 2M

    2

    1 h[n] cosn

    H() is real but not necessarily positive (unlikeH(ej)).

    Weighted error: e() = s()(H() d()

    )where d() is the target.

    Choose s() to control the error variation with .

    Example: lowpass filter

    d() =

    {1 0 1

    0 2

    s() =

    {1 0 1

    1 2

    e() = 1 when H() lies at the edge of the specification.

    Minimax criterion: h[n] = argminh[n]max |e()|: minimize max error

  • Alternation Theorem

    7: Optimal FIR filters

    Optimal Filters

    AlternationTheorem

    ChebyshevPolynomials

    Maximal ErrorLocationsRemez ExchangeAlgorithm

    Determine Polynomial

    Example Design

    FIR Pros and Cons

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6729) Optimal FIR: 7 3 / 11

    Want to find the best fit line: with the smallest maximal error.

    Best fit line always attains themaximal error three times withalternate signs

    2 4 6 82

    4

    6

    8

    Proof:Assume the first maximal deviation from the line is negative as shown.There must be an equally large positive deviation; or else just move the linedownwards to reduce the maximal deviation.This must be followed by another maximal negative deviation; or else youcan rotate the line and reduce the deviations.

    Alternation Theorem:A polynomial fit of degree n to a bounded set of points is minimax if andonly if it attains its maximal error at n+ 2 points with alternating signs.There may be additional maximal error points.Fitting to a continuous function is the same as to an infinite number ofpoints.

  • Chebyshev Polynomials

    7: Optimal FIR filters

    Optimal Filters

    Alternation Theorem

    ChebyshevPolynomials

    Maximal ErrorLocationsRemez ExchangeAlgorithm

    Determine Polynomial

    Example Design

    FIR Pros and Cons

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6729) Optimal FIR: 7 4 / 11

    H() = H(ej) = h[0] + 2M

    2

    1 h[n] cosn

    But cosn = Tn(cos): Chebyshev polynomial of 1st kind

    cos 2 = 2 cos2 1 = T2(cos) T2(x) = 2x2 1

    cos 3 = 4 cos3 3 cos = T3(cos) T3(x) = 4x3 3x

    Recurrence Relation:Tn+1(x) = 2xTn(x) Tn1(x) with T0(x) = 1, T1(x) = x

    Proof: cos (n + ) + cos (n ) = 2 cos cosn

    So H() is an M2 order polynomial in cos: alternation theorem applies.

    Example: Symmetric lowpass filter of orderM = 4H(z) = 0.1766z2 + 0.4015z + 0.2124 + 0.4015z1 + 0.1766z2

  • Maximal Error Locations

    7: Optimal FIR filters

    Optimal Filters

    Alternation TheoremChebyshevPolynomials

    Maximal ErrorLocations

    Remez ExchangeAlgorithm

    Determine Polynomial

    Example Design

    FIR Pros and Cons

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6729) Optimal FIR: 7 5 / 11

    Maximal error locations occur either at bandedges or when dH

    d= 0

    H() = h[0] + 2M

    2

    1 h[n] cosn= P (cos)

    where P (x) is a polynomial of order M2 . 0 0.5 1 1.5 2 2.5 30

    0.2

    0.4

    0.6

    0.8

    1

    1.2

    |

    H

    |

    M=18

    dHd

    = P (cos) sin

    = 0 at = 0, and at most M2 1 zeros of polynomial P(x).

    With two bands, we have at most M2 + 3 maximal error frequencies.

    We require M2 + 2 of alternating signs for the optimal fit.

    Only three possibilities exist (try them all):

    (a) = 0 + two band edges + all(M2 1

    )zeros of P (x).

    (b) = + two band edges + all(M2 1

    )zeros of P (x).

    (c) = {0 and } + two band edges +(M2 2

    )zeros of P (x).

  • Remez Exchange Algorithm

    7: Optimal FIR filters

    Optimal Filters

    Alternation TheoremChebyshevPolynomials

    Maximal ErrorLocations

    Remez ExchangeAlgorithm

    Determine Polynomial

    Example Design

    FIR Pros and Cons

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6729) Optimal FIR: 7 6 / 11

    1. Guess the positions of the M2 + 2 maximal error frequencies and givealternating signs to the errors (e.g. choose evenly spaced ).

    2. Determine the error magnitude, , and the M2 + 1 coefficients ofthe polynomial that passes through the maximal error locations.

    3. Find the local maxima of the error function by evaluatinge() = s()

    (H() d()

    )on a dense set of .

    4. Update the maximal error frequencies to be an alternating subset ofthe local maxima + band edges + {0 and/or }.If maximum error is > , go back to step 2. (typically 15 iterations)

    5. Evaluate H() on M + 1 evenly spaced and do an IDFT to get h[n].

  • Remex Step 2: Determine Polynomial

    7: Optimal FIR filters

    Optimal Filters

    Alternation TheoremChebyshevPolynomials

    Maximal ErrorLocationsRemez ExchangeAlgorithm

    DeterminePolynomial

    Example Design

    FIR Pros and Cons

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6729) Optimal FIR: 7 7 / 11

    For each extremal frequency, i for 1 i M2 + 2

    d(i) = H(i) +(1)is(i)

    = h[0] + 2M

    2

    n=1 h[n] cosni +(1)is(i)

    Method 1: (Computation time M3)Solve M2 + 2 equations in

    M2 + 2 unknowns for h[n] + .

    In step 3, evaluate H() = h[0] + 2M

    2

    n=1 h[n] cosni

    Method 2: Dont calculate h[n] explicitly (Computation time M2)Multiply equations by ci =

    j 6=i

    1cosicosj

    and add:M2+2

    i=1 ci

    (h[0] + 2

    M2

    n=1 h[n] cosn +(1)is(i)

    )=M

    2+2

    i=1 cid(i)

    All terms involving h[n] sum to zero leavingM2+2

    i=1(1)icis(i)

    =M

    2+2

    i=1 cid(i)

    Solve for then calculate the H(i) then use Lagrange interpolation:

    H() = P (cos) =M

    2+2

    i=1 H(i)

    j 6=icoscosjcosicosj(

    M2 + 1

    )-polynomial going through all the H(i) [actually order

    M2 ]

  • Example Design

    7: Optimal FIR filters

    Optimal Filters

    Alternation TheoremChebyshevPolynomials

    Maximal ErrorLocationsRemez ExchangeAlgorithm

    Determine Polynomial

    Example DesignFIR Pros and Cons

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6729) Optimal FIR: 7 8 / 11

    Filter Specifications:Bandpass = [0.5, 1], Transition widths: = 0.2Stopband Attenuation: 25 dB and 15 dBPassband Ripple: 0.3 dB

    Determine gain tolerances for each band:25 dB = 0.056, 0.3 dB = 1 0.034, 15 dB = 0.178

    Predicted order: M = 36M2 + 2 extremal frequencies are distributed between the bandsFilter meets specs ,; clearer on a decibel scale

    Most zeros are on the unit circle + three reciprocal pairsReciprocal pairs give a linear phase shift

    0 0.5 1 1.5 2 2.5 30

    0.2

    0.4

    0.6

    0.8

    1

    |

    H

    |

    M=36

    0 0.5 1 1.5 2 2.5 3-30

    -25

    -20

    -15

    -10

    -5

    0

    |

    H

    |

    (

    d

    B

    )

    M=36

    -1 0 1 2

    -1

    -0.5

    0

    0.5

    1

  • FIR Pros and Cons

    7: Optimal FIR filters

    Optimal Filters

    Alternation TheoremChebyshevPolynomials

    Maximal ErrorLocationsRemez ExchangeAlgorithm

    Determine Polynomial

    Example Design

    FIR Pros and ConsSummary

    MATLAB routines

    DSP and Digital Filters (2015-6729) Optimal FIR: 7 9 / 11

    Can have linear phase no envelope distortion, all frequencies have the same delay , symmetric or antisymmetric: h[n] = h[n]n or h[n]n antisymmetric filters have H(ej0) = H(ej) = 0 symmetry means you only need M2 + 1 multiplications

    to implement the filter.

    Always stable ,

    Low coefficient sensitivity ,

    Optimal design method fast and robust ,

    Normally needs higher order than an IIR filter / Filter order M dBatten3.5 where is the most rapid transition

    Filtering complexity M fs dBatten3.5 fs =

    dBatten3.5 f

    2s

    f2s for a given specification in unscaled units.

  • Summary

    7: Optimal FIR filters

    Optimal Filters

    Alternation TheoremChebyshevPolynomials

    Maximal ErrorLocationsRemez ExchangeAlgorithm

    Determine Polynomial

    Example Design

    FIR Pros and Cons

    SummaryMATLAB routines

    DSP and Digital Filters (2015-6729) Optimal FIR: 7 10 / 11

    Optimal Filters: minimax error criterion

    use weight function, s(), to allow different errorsin different frequency bands

    symmetric filter has zeros on unit circle or in reciprocal pairs Response of symmetric filter is a polynomial in cos Alternation Theorem: M2 + 2 maximal errors with alternating signs

    Remez Exchange Algorithm (also known as Parks-McLellan Algorithm)

    multiple constant-gain bands separated by transition regions very robust, works for filters with M > 1000 Efficient: computation M2

    can go mad in the transition regions

    Modified version works on arbitrary gain function

    Does not always converge

    For further details see Mitra: 10.

  • MATLAB routines

    7: Optimal FIR filters

    Optimal Filters

    Alternation TheoremChebyshevPolynomials

    Maximal ErrorLocationsRemez ExchangeAlgorithm

    Determine Polynomial

    Example Design

    FIR Pros and Cons

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6729) Optimal FIR: 7 11 / 11

    firpm optimal FIR filter designfirpmord estimate require order for firpmcfirpm arbitrary-response filter designremez [obsolete] optimal FIR filter design

  • 8: IIR Filter Transformations

    8: IIR FilterTransformations

    Continuous TimeFilters

    Bilinear Mapping

    Continuous TimeFiltersMapping Poles andZerosSpectralTransformationsConstantinidesTransformations

    Impulse Invariance

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6707) IIR Transformations: 8 1 / 10

  • Continuous Time Filters

    8: IIR FilterTransformations

    Continuous TimeFilters

    Bilinear Mapping

    Continuous TimeFiltersMapping Poles andZerosSpectralTransformationsConstantinidesTransformations

    Impulse Invariance

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6707) IIR Transformations: 8 2 / 10

    Classical continuous-time filters optimize tradeoff:passband ripple v stopband ripple v transition widthThere are explicit formulae for pole/zero positions.

    Butterworth: G2() =H(j)2 = 11+2N

    Monotonic G() = 1 12

    2N + 384N +

    Maximally flat: 2N 1 derivatives are zero

    Chebyshev: G2() = 11+2T 2

    N()

    where polynomial TN (cosx) = cosNx passband equiripple + very flat at

    Inverse Chebyshev: G2() = 11+(2T 2N (1))

    1

    stopband equiripple + very flat at 0

    Elliptic: [no nice formula] Very steep + equiripple in pass and stop bands

    0.1 0.2 0.5 1 2 5 100

    0.2

    0.4

    0.6

    0.8

    1 N=5

    Frequency (rad/s)

    |

    H

    |

    0.1 0.2 0.5 1 2 5 100

    0.2

    0.4

    0.6

    0.8

    1

    Frequency (rad/s)

    |

    H

    |

    0.1 0.2 0.5 1 2 5 100

    0.2

    0.4

    0.6

    0.8

    1

    Frequency (rad/s)

    |

    H

    |

    0.1 0.2 0.5 1 2 5 100

    0.2

    0.4

    0.6

    0.8

    1

    Frequency (rad/s)

    |

    H

    |

  • Bilinear Mapping

    8: IIR FilterTransformationsContinuous TimeFilters

    Bilinear MappingContinuous TimeFiltersMapping Poles andZerosSpectralTransformationsConstantinidesTransformations

    Impulse Invariance

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6707) IIR Transformations: 8 3 / 10

    Change variable: z = +ss s =

    z1z+1 : a one-to-one invertible mapping

    axis (s) axis (z)

    axis (s) Unit circle (z)

    Proof: z = ejs = ej1ej+1 =

    ej 2 ej

    2

    ej 2 +ej

    2= j tan 2= j

    Left half plane(s) inside of unit circle (z)

    Proof: s = x+ jy |z|2 = |(+x)+jy|2

    |(x)jy|2

    = 2+2x+x2+y2

    22x+x2+y2 = 1 +4x

    (x)2+y2

    x < 0 |z| < 1

    Unit circle (s) axis (z)

    -4 -2 0 2 4-4

    -3

    -2

    -1

    0

    1

    2

    3

    4s-plane

    = 1

    -2 -1 0 1 2-2.5

    -2

    -1.5

    -1

    -0.5

    0

    0.5

    1

    1.5

    2

    2.5z-plane

    = 1

    0 2 4 6 8 100

    0.5

    1

    1.5

    2

    2.5

    3

    /

  • Continuous Time Filters

    8: IIR FilterTransformationsContinuous TimeFilters

    Bilinear Mapping

    Continuous TimeFilters

    Mapping Poles andZerosSpectralTransformationsConstantinidesTransformations

    Impulse Invariance

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6707) IIR Transformations: 8 4 / 10

    Take H(s) = 1s2+0.2s+4 and choose = 1

    Substitute: s = z1z+1 [extra zeros at z = 1]

    H(z) = 1( z1z+1 )

    2+0.2 z1

    z+1+4

    = (z+1)2

    (z1)2+0.2(z1)(z+1)+4(z+1)2

    = z2+2z+1

    5.2z2+6z+4.8 = 0.191+2z1+z2

    1+1.15z1+0.92z2

    Frequency response is identical (both magnitude andphase) but with a distorted frequency axis:

    Frequency mapping: = 2 tan1

    =[ 2 3 4 5

    ] =

    [1.6 2.2 2.5 2.65 2.75

    ]

    1 2 3 4 5 60

    0.5

    1

    1.5

    2

    2.5

    Frequency (rad/s)

    |

    H

    |

    0 0.5 1 1.5 2 2.5 30

    0.5

    1

    1.5

    2

    2.5

    (rad/sample)

    |

    H

    |

    =1

    0 2 4 6 8 100

    0.5

    1

    1.5

    2

    2.5

    3

    /

    Choosing : Set = 0tan 1

    20

    to map 0 0

    Set = 2fs =2T

    to map low frequencies to themselves

  • Mapping Poles and Zeros

    8: IIR FilterTransformationsContinuous TimeFilters

    Bilinear Mapping

    Continuous TimeFilters

    Mapping Poles andZeros

    SpectralTransformationsConstantinidesTransformations

    Impulse Invariance

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6707) IIR Transformations: 8 5 / 10

    Alternative method: H(s) = 1s2+0.2s+4

    Find the poles and zeros: ps = 0.1 2jMap using z = 1+s1s pz = 0.58 0.77j

    After the transformation we will always end up withthe same number of poles as zeros:Add extra poles or zeros at z = 1

    H(z) = g (1+z1)2

    (1+(0.580.77j)z1)(1+(0.58+0.77j)z1)

    = g 1+2z1+z2

    1+1.15z1+0.92z2

    Choose overall scale factor, g, to give the same gainat any convenient pair of mapped frequencies:

    At 0 = 0 s0 = 0H(s0)

    = 0.25 0 = 2 tan

    1 0

    = 0 z0 = ej0 = 1

    |H(z0)| = g 4

    3.08 = 0.25 g = 0.19

    H(z) = 0.19 1+2z1+z2

    1+1.15z1+0.92z2

    1 2 3 4 5 60

    0.5

    1

    1.5

    2

    2.5

    Frequency (rad/s)

    |

    H

    |

    -3 -2 -1 0 1 2

    -2

    -1

    0

    1

    2

    s

    -1 0 1

    -1

    -0.5

    0

    0.5

    1

    z

    =1

    0 0.5 1 1.5 2 2.5 30

    0.5

    1

    1.5

    2

    2.5

    (rad/sample)

    |

    H

    |

    =1

  • Spectral Transformations

    8: IIR FilterTransformationsContinuous TimeFilters

    Bilinear Mapping

    Continuous TimeFiltersMapping Poles andZeros

    SpectralTransformations

    ConstantinidesTransformations

    Impulse Invariance

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6707) IIR Transformations: 8 6 / 10

    We can transform the z-plane to change the cutofffrequency by substituting

    z = z1z z =z+1+z

    Frequency Mapping:

    If z = ej, then z = z 1+z1

    1+z has modulus 1since the numerator and denominator arecomplex conjugates.Hence the unit circle is preserved.

    ej = ej+

    1+ej

    Some algebra gives: tan 2 =(1+1

    )tan 2

    Equivalent to:z s = z1

    z+1 s =11+s z =

    1+s1s

    Lowpass Filter example:Inverse Chebyshev

    0 =2 = 1.57

    =0.6 0 = 0.49

    -2 -1 0 1 2-2

    -1

    0

    1

    2z

    -2 -1 0 1 2-2

    -1

    0

    1

    2z^

    = 0.6

    0 0.5 1 1.5 2 2.5 30

    0.2

    0.4

    0.6

    0.8

    1

    (rad/s)

    |

    H

    |

    0 0.5 1 1.5 2 2.5 30

    0.2

    0.4

    0.6

    0.8

    1

    ^ (rad/s)

    |

    H

    ^

    |

    = 0.6

    ^ = 0.49

  • Constantinides Transformations

    DSP and Digital Filters (2015-6707) IIR Transformations: 8 7 / 10

    Transform any lowpass filter with cutoff frequency 0 to:

    Target Substitute Parameters

    Lowpass < 1

    z1 = z1

    1z1 =sin(012 )sin(0+12 )

    Highpass > 1

    z1 = z1+

    1+z1 =cos(0+12 )cos(012 )

    Bandpass1 < < 2

    z1 = (1)2z1+(+1)z2

    (+1)2z1+(1)z2 =cos( 2+12 )cos( 212 )

    = cot(21

    2

    )tan

    (02

    )Bandstop

    1 2

    z1 = (1)2z1+(+1)z2

    (+1)2z1+(1)z2 =cos( 2+12 )cos( 212 )

    = tan(21

    2

    )tan

    (02

    )Bandpass and bandstop transformations are quadratic and so will double the order:

    -3 -2 -1 0 1 2 30

    0.5

    1

    (rad/s)

    |

    H

    |

    Lowpass

    -3 -2 -1 0 1 2 30

    0.5

    1

    ^ (rad/s)

    |

    H

    ^

    |

    Bandpass

  • Impulse Invariance

    8: IIR FilterTransformationsContinuous TimeFilters

    Bilinear Mapping

    Continuous TimeFiltersMapping Poles andZerosSpectralTransformationsConstantinidesTransformations

    Impulse InvarianceSummary

    MATLAB routines

    DSP and Digital Filters (2015-6707) IIR Transformations: 8 8 / 10

    Bilinear transform works well for a lowpass filter but the non-linearcompression of the frequency distorts any other response.

    Alternative method: H(s)L

    1

    h(t)sample h[n] = T h(nT )

    Z H(z)

    Express H(s) as a sum of partial fractions H(s) =N

    i=1gi

    spi

    Impulse response is h(t) = u(t)N

    i=1 giepit

    Digital filter H(z)T

    =N

    i=1gi

    1epiT z1has identical impulse response

    Poles of H(z) are pi = epiT (where T = 1

    fsis sampling period)

    Zeros do not map in a simple way

    Properties:, Impulse response correct. , No distortion of frequency axis./ Frequency response is aliased.

    Example: Standard telephone filter - 300 to 3400 Hz bandpass

    0 5 10 15 20 250

    0.5

    1

    Frequency (krad/s)

    |

    H

    |

    Analog Filter

    0 0.5 1 1.5 2 2.5 30

    0.5

    1

    (rad/sample)

    |

    H

    |

    Bilinear (fs = 8 kHz)

    Matched at 3.4 kHz

    0 0.5 1 1.5 2 2.5 3

    0.2

    0.4

    0.6

    0.8

    1

    (rad/sample)

    |

    H

    |

    Impulse Invariance (fs = 8 kHz)

  • Summary

    8: IIR FilterTransformationsContinuous TimeFilters

    Bilinear Mapping

    Continuous TimeFiltersMapping Poles andZerosSpectralTransformationsConstantinidesTransformations

    Impulse Invariance

    SummaryMATLAB routines

    DSP and Digital Filters (2015-6707) IIR Transformations: 8 9 / 10

    Classical filters have optimal tradeoffs in continuous time domain Order transition width pass ripple stop ripple Monotonic passband and/or stopband

    Bilinear mapping Exact preservation of frequency response (mag + phase) non-linear frequency axis distortion can choose to map 0 0 for one specific frequency

    Spectral transformations lowpass lowpass, highpass, bandpass or bandstop bandpass and bandstop double the filter order

    Impulse Invariance Aliassing distortion of frequency response preserves frequency axis and impulse response

    For further details see Mitra: 9.

  • MATLAB routines

    8: IIR FilterTransformationsContinuous TimeFilters

    Bilinear Mapping

    Continuous TimeFiltersMapping Poles andZerosSpectralTransformationsConstantinidesTransformations

    Impulse Invariance

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6707) IIR Transformations: 8 10 / 10

    bilinear Bilinear mappingimpinvar Impulse invariancebutter

    butterordAnalog or digitalButterworth filter

    cheby1cheby1ord

    Analog or digitalChebyshev filter

    cheby2cheby2ord

    Analog or digitalInverse Chebyshev filter

    ellipellipord

    Analog or digitalElliptic filter

  • 9: Optimal IIR Design

    9: Optimal IIRDesign

    Error choices

    Linear Least Squares

    Frequency Sampling

    Iterative Solution

    Newton-Raphson

    Magnitude-onlySpecification

    Hilbert RelationsMagnitude PhaseRelation

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6729) Optimal IIR: 9 1 / 11

  • Error choices

    9: Optimal IIRDesign

    Error choicesLinear Least Squares

    Frequency Sampling

    Iterative Solution

    Newton-Raphson

    Magnitude-onlySpecification

    Hilbert RelationsMagnitude PhaseRelation

    Summary

    MATLAB routines

    DSP and Digital Filters (2015-6729) Optimal IIR: 9 2 / 11

    We want to find a filter H(ej) = B(ej)

    A(ej) that approximates a target

    response D(). Assume A is order N and B is order M .

    Two possible error measures:

    Solution Error: ES() = WS()(B(ej)A(ej) D()

    )

    Equation E