WinFlt 4up

download WinFlt 4up

of 19

Transcript of WinFlt 4up

  • 8/15/2019 WinFlt 4up

    1/19

    MUS421/EE367B Lecture 6FIR Digital Filter Design

    Julius O. Smith III ([email protected] )Center for Computer Research in Music and Acoustics (CCRMA)

    Department of Music , Stanford UniversityStanford, California 94305

    March 28, 2005

    Outline

    Ideal Lowpass Filter

    Optimal Least Squares in Time Domain

    Window Method

    Optimal Methods

    Case Study: FIR Hilbert-Transform Design

    1

    FIR Digital Filter Design

    In a previous lecture, we looked at many windows, anexamined their properties. Today, we are going to seehow these windows can be used to design Finite ImpuResponse (FIR) digital lters.

    FFT processors implement long FIR lters moreefficiently than any other method (using Overlap-Add

    We need exible ways to design all kinds of FIR lteruse in FFT processors.

    2

    Ideal Lowpass Filter

    Amplitude Response:

    Frequency0 f s/ 20

    1

    G a

    i n

    f c

    Gain = 1 forf < f c Gain = 0 forf > f c

    3

    Impulse Response of Ideal LPF

    hideal(n)= DTFT 1n H ideal=

    12

    c

    ce jnd

    =sin(cn)

    n= 2f csinc(2f cn), n Z

    Problems:

    Innitely long

    Non-causal

    Cannot be shifted to make it causal

    Cannot be implemented in practice

    Conclusion:

    We must accept some compromise(s) in the designany practical lowpass lter.

    Managing such trade-offs is the topic of digital lter design.

    4

    http://www-ccrma.stanford.edu/~%7B%7Djosmailto:[email protected]://www-ccrma.stanford.edu/http://www.stanford.edu/group/Music/http://www.stanford.edu/http://www.stanford.edu/http://www.stanford.edu/group/Music/http://www-ccrma.stanford.edu/mailto:[email protected]://www-ccrma.stanford.edu/~%7B%7Djos
  • 8/15/2019 WinFlt 4up

    2/19

    Optimal (but Poor) Least-SquaresImpulse Response Design

    Let

    h(n) = ideal lter impulse response.

    h(n) = length L causal FIR lter (to be designed).

    Sum of squared errors :

    J 2(h) =

    n= h(n) h(n)

    2=

    L 1

    n=0h(n) h(n)

    2+ c2

    wherec2= 0n= |h(n)|

    2 + n= L |h(n)|2 does not

    depend onh. Note that J 2(h) c2.Result: The error is minimized (in the least-squares sense) by simply matching the rst L terms in the desired impulse response.Optimal least-squares FIR lter:

    h(n) =h(n), 0 n L 10, otherwise

    Also optimal under anyL p norm with any error weighting:

    J p(h) =L 1

    n=0

    w(n) h(n) h(n) p

    + c p c p

    5

    Length L = 30 Least-Squares LPF Design

    0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.50

    0.5

    1

    1.5

    Normalized Frequency (cycles/sample)

    M a g n

    i t u

    d e

    ( L i n e a r )

    Length 30 FIR Amplitude Response

    0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45

    50

    40

    30

    20

    10

    0

    Normalized Frequency (cycles/sample)

    M a g n

    i t u

    d e

    ( d B )

    Desired cut-off frequency isf c = 1/ 4

    Stopband attenuation only around 10 dB

    Passband gain has a resonance near cut-off

    Filter isquite poor for audio use

    H = H asincL

    6

    Length L = 71 Least-Squares LPF Design

    0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.50

    0.5

    1

    1.5

    Normalized Frequency (cycles/sample)

    M a g n

    i t u

    d e

    ( L i n e a r )

    Length 71 FIR Amplitude Response

    0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45

    70

    60

    50

    40

    30

    20

    10

    0

    Normalized Frequency (cycles/sample)

    M a g n

    i t u

    d e

    ( d B )

    Stopband attenuation still only around 10 dB Corner-frequency resonance ishigher , though narrower Gibbs phenomenon in the frequency domain

    What were doing wrong:

    Desired lter specication asks for too much(e.g, an innite roll-off rate).

    Time-domain-least-squares is a poor choice of errorcriterion for audio work.

    7

    Length L = 71 Optimal Chebyshev LPF Design

    remez(70,[0 0.5 0.6 1],[1 1 0 0]);

    0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45 0.50

    0.5

    1

    1.5

    Normalized Frequency (cycles/sample)

    M a g n

    i t u

    d e

    ( L i n e a r )

    Length 71 FIR Amplitude Response

    0 0.05 0.1 0.15 0.2 0.25 0.3 0.35 0.4 0.45

    70

    60

    50

    40

    30

    20

    10

    0

    Normalized Frequency (cycles/sample)

    M a g n

    i t u d e

    ( d B )

    Stopband attenuation better than 60 dB

    No corner-frequency resonance

    Transition regionfrom passband to stopband iscritical

    Error is equiripple in both stopband (visible) andpassband (not visible)

    8

  • 8/15/2019 WinFlt 4up

    3/19

    Impulse response is slightly impulsive at theendpoints (not shown).

    9

    Lowpass Filter Specications

    s

    p

    TW

    Ideal lowpassfilter response1

    0

    1 +p

    1 p

    0 p sFrequency

    Amplitude

    Lowpass Filter Specifications

    Pass-band Stop-band

    Transitionband

    s : stopband ripple ( 0.001 = 60 dB typical)

    p : passband ripple ( 0.1 dB typical)

    s: stopband edge frequency

    p: passband edge frequency

    TW: transition width= s p SBA: stop-band attenuation= 20log(s)

    10

    Example Ripple Calculations in Matlab

    Lets rst consider the passband ripple spec, 0.1 dB.Converting that to linear ripple amplitude gives, inMatlab,

    format long;dp=10^(0.1/20)-1dp =

    0.01157945425990

    Lets check it:

    >> 20*log10(1+dp)ans =

    0.10000000000000>> 20*log10(1-dp)ans =

    -0.10116471483635

    Ok, close enough. Now lets set the stopband ripple to1/10 times the passband ripple and see where we are:

    >> ds=dp/10;>> 20*log10(ds)ans =

    -58.7262381688205211

    So, thats about 60 dB stop-band rejection, which is ntoo bad. Now lets set the stopband ripple to 1/100times the passband ripple:

    >> ds=dp/100;>> 20*log10(ds)ans =

    -78.72623816882052

    So now were close to 80dB SBA, which is getting inthe high delity zone.

    Ideal Lowpass Filter

    The ideal lowpass lter is dened by the followingspecications:

    s = p = c= 2f c TW = 0

    p = s = 0 SBA=

    12

  • 8/15/2019 WinFlt 4up

    4/19

    The Window Method for FIR FilterDesign

    In practical FFT processors, we are limited to anite duration impulse response.

    An obvious method for FIR lter design is to simplywindow the ideal impulse response, just like wewindow ideal sinusoids in spectrum analysis:

    hw(n) = w(n) hideal(n)

    wherew is a zero phase window of lengthM (odd).

    We saw that the rectangular window is optimal in thetime-domain least-squares sense, but a poor choicefor typical audio lter design. What about otherwindows?

    Windowing ismultiplication in the time domainconvolution in the frequency domain.

    Thus, in the window method, theideal frequency response is convolved with the window transform:

    H w() = (W H ideal)()The convolution smears the response, introducingdeviations in both the pass-band and stop-band.

    13

    Example

    A typical windowed ideal lowpass lter response isdepicted in the following diagram:

    -60 -40 -20 0 20 40 60-0.6

    -0.4

    -0.2

    0

    0.2

    0.4

    0.6

    0.8

    1Length 101 Lowpass FIR Filter - Hamming Window

    time (samples)

    A m p

    l i t u

    d e

    14

    At this point in the design, we have a non-causal(zero phase) lter.

    In order to implement this in a real time situation, weneed to shift the lter by an amount equal to half itslength.

    hcausal(n) = h n M 1

    2

    This shift in the time domain results in alinear phase term in the frequency domain:

    H causal() = e j M 12 H ()

    15

    Examples

    length 25 FIR lter

    c = / 4

    hideal(n) =sin(cn)

    n n Z

    We will examine several windows:

    0 10 20-0.1

    0

    0.1

    0.2

    0.3Rectangular

    time (samples)

    A m p

    l i t u

    d e

    0 10 20-0.1

    0

    0.1

    0.2

    0.3Hanning

    time (samples)

    A m p

    l i t u

    d e

    0 10 20-0.1

    0

    0.1

    0.2

    0.3Hamming

    time (samples)

    A m p

    l i t u

    d e

    0 10 20-0.1

    0

    0.1

    0.2

    0.3Kaiser

    time (samples)

    A m p

    l i t u

    d e

    16

  • 8/15/2019 WinFlt 4up

    5/19

    Amplitude Response of Examples

    -2 0 2

    -60

    -40

    -20

    0

    Rectangular

    Frequency (radians/sample)

    A m p

    l i t u

    d e -

    d B

    -2 0 2

    -60

    -40

    -20

    0

    Hanning

    Frequency (radians/sample)

    A m p

    l i t u

    d e -

    d B

    -2 0 2

    -60

    -40

    -20

    0Hamming

    Frequency (radians/sample)

    A m p

    l i t u

    d e -

    d B

    -2 0 2

    -60

    -40

    -20

    0Kaiser

    Frequency (radians/sample)

    A m p

    l i t u

    d e -

    d B

    17

    Effect of Changing Filter Length, M = 11, 15, 41

    3 2 1 0 1 2 370

    60

    50

    40

    30

    20

    10

    0

    Hamming Window

    Frequency (radians/sample)

    A m p

    l i t u

    d e

    d B

    18

    Other Types of Filters

    Ideal highpass, bandpass, and bandstop lters can all beconsidered as modications of an ideal lowpass lter.

    A highpass lter can be constructed by shifting a lowpasslter by an amount equal to half the sampling rate.

    0

    0|H |

    |H |

    2

    2

    2

    2

    This is equivalent to a modulation bye jn in the timedomain. Hence,

    hhp(n) = hlp(n)e jn

    = hlp(n)( 1)n

    19

    Summarizing:

    To design a high-pass lter, rst design a nitelength, causal lowpass lter

    Use a lowpass cutoff frequency equal to (highpass cutoff)

    Design the lowpass lter as in the previous sect

    Modulate the impulse reponse by( 1)n to exchangeDC andf s/ 2

    Alternatively, if the passband of the prototype lowpasslter H () is very at about unity gain, a highpass ltcan be designed by simply subtracting from1:

    H hp() = 1 H lp() (n) h lp(n)

    A bandpass can be derived by designing the approprialowpass lter (with cutoff frequency equal to half thewidth of the bandpass), and thenmodulating it to thedesired center frequencyc. In the frequency domain,this means shifting two copies of the lowpass prototypone to the left by c, and the other to the right byc.The two shifted copies are added together to give abandpass lter having a real impulse response.

    20

  • 8/15/2019 WinFlt 4up

    6/19

    0

    0|H |

    |H |

    c

    0 ul

    c

    0

    To design a bandpass lter:

    Design a lowpass prototype lter of the desired width(cutoff c = u 0)

    Shift to the left and right by0 and sum:hbp(n) = 2 cos(n0)hlp(n)

    A bandstop lter can be constructed by rst designing abandpass with similar specications.

    In the frequency domain, we desire a lter with a transferfunction equal toH bs = 1 H bp. Hence, in the timedomain we have:

    hbs(n) =1 hbp(0) n = 0 hbp(n) n = 1, 2, . . . ,

    M 12

    21

    Summary of the Window Method

    Basic Idea:

    Start with Ideal Lowpass-Filter Impulse Response

    Sinc functionsin(t/T )/ (t/T ) Innite duration Non-causal

    Window the innite duration sinc to get a niteduration lter

    Windowlength determines transition width Windowtype determines the sidelobe level (SLL Rectangular window yields the optimal lter in

    unweighted least squares sense

    Shift the noncausal (zero phase) lter to get a caus(linear phase) lter

    The linear phase slope equals half the lter leng

    Other types of lters (highpass, bandpass, bandstopare designed by rst designing a low pass, andapplying transformations

    22

    Important Points (Window Method)

    Easy to design (seefir1 and fir2 in Octave andMatlab SPTB)

    Can design extremely long FIR lters withoutnumerical problems

    Not usually optimum in any sense

    General Remarks (Window-Method)

    Transition width TW determined by window lengthM

    As window gets longer, its main lobe narrows Narrower main lobe narrower transition band Tighter specs demand longer lters Length M 1/ TW in general

    Pass-band and stop-band ripple are determined bywindow side lobes

    We do not have individual control over passbandand stopband ripple(This is a limitation of the window method)

    Ripple determined by window used Ripple normally largest around transition band

    23

    Optimal FIR Digital Filter Design

    Optimal Chebyshev FIR Design

    L p Norm Minimization

    Least squares problems Min-Max problems

    Least Squares Optimization

    PseudoInverse

    FIR Filter Design

    Linear Phase

    Complex Filter Design Other Applications

    Books including digital lter design:

    Boyd and Vandenberghe

    Parks and Burrus

    Rabiner and Gold

    Oppenheim and Schafer

    Steiglitz24

  • 8/15/2019 WinFlt 4up

    7/19

    Strum and Kirk

    See Music 421 References1

    1 http://ccrma.stanford.edu/jos/refs421/

    25

    Optimal Chebyshev Filters

    Minimize themaximumof the error

    Stopband and passband errors areequiripple

    Remez Multiple Exchange (Parks-McClellanalgorithm)

    Available in Octave and the Matlab SP Tool Box:remez(), cremez()

    Problems with Remez Exchange

    Convergenceunlikely for FIR lters longer than a fehundred taps or so

    Fundamentallyreal polynomial approximation on thunit circle

    Applies only tolinear phase lters Cannot design individual (non-minimum phase)

    sub-lters in polyphase lter bank form

    Really need optimal weightedcomplex approximatione.g., minimum phase FIR lter design

    26

    Example: Chebyshev window and its transform:

    -100 -50 50 100

    0.1

    0.2

    0.3

    0.4

    0.5

    0.6

    0.7

    0.8

    0.9

    1

    Time (samples)

    A m p

    l i t u

    d e

    Chebyshev Window: M = 101, Ripple = -40 dB

    0 0

    27

    -3 -2 -1 1 2 3

    -70

    -60

    -50

    -40

    -30

    -20

    -10

    freq

    d B M a g n

    i t u

    d e

    DFT of Chebyshev Window: M = 11, Ripple = -40 dB0

    0

    28

    http://ccrma.stanford.edu/~%7B%7Djos/refs421/http://ccrma.stanford.edu/~%7B%7Djos/refs421/
  • 8/15/2019 WinFlt 4up

    8/19

    Lp norms

    The L p norm of anN -dimensional vectorx is dened as

    x p=

    N 1

    i=0

    |xi | p1 p

    Special cases

    L1 norm

    x 1=

    N 1

    i=0

    |xi |

    Sum of the absolute values of the elements City block distance

    L2 norm

    x 2= N 1

    i=0

    |xi |2

    Euclidean distance Minimized by Least Squares techniques

    29

    L -norm

    x = lim

    p

    N 1

    i=0

    |x i| p1 p

    In the limit asp , the L p norm of x isdominated by the maximum element of x.

    30

    Filter Design using Lp Norms

    In terms of L p norm minimization, the FIR lter designproblem becomes:

    minh

    W (k) [H (k) D(k)] p

    Where

    k = suitable discrete set of frequencies

    H (k) = frequency response of our FIR lter

    D(k) = desired (complex) frequency response

    W (k) = (optional) weighting functionLets look at some specic cases:

    31

    Least-Squares Linear-Phase FIR Filter Design

    Let the FIR lter length beL + 1 samples, withL even,and suppose well initially design it to be centered abthe time origin (zero-phase). Then the frequencyresponse is given on our frequency gridk by

    H (k) =L/ 2

    n= L/ 2

    hne jkn

    Enforcingeven symmetry in the impulse response, i.e.,hn = h n, gives azero phase FIR lter which we canlater right-shiftL/ 2 samples to make a causal,linear phase lter. In this case, the frequency response reducto a sum of cosines :

    H (k) = h0 + 2L/ 2

    n=1

    hn cos(kn), k = 0, 1, 2, . . . , N

    or in matrix form:H (0 )H (1 )...

    H (N 1 )

    =

    1 2cos(0 ) . . . 2cos[0 (L 1)]1 2cos(1 ) . . . 2cos[1 (L 1)]...1 2cos(N 1 ) . . . 2cos[N 1 (L 1)]

    A

    h0h1...

    hL/

    x(Note that Remez exchange algorithms are also based this formulation internally.)

    32

  • 8/15/2019 WinFlt 4up

    9/19

    Matrix Formulation: Optimal L2 Design, Contd

    In matrix notation, our lter design problem can be stated

    minx

    Ax b 22

    where, for zero-phase lters,

    A =

    1 2cos(0) . . . 2cos[0(L 1)]1 2cos(1) . . . 2cos[1(L 1)]

    ...1 2cos(N 1) . . . 2cos[N 1(L 1)]

    x = h

    and b = [D(k)] is the desired frequency response at thespecied frequencies.

    The functionfirls in the Matlab Signal Processing ToolBox implements frequency-domain weighted-least-squaresFIR lter design (not available in Octave as of 2/2003).

    33

    Least Squares Optimization

    x = argminx

    Ax b 2 = arg minx Ax b22

    Hence we can minimizeAx b 22 = (Ax b)

    T (Ax b)

    Expanding this, we have:

    (Ax b)T (Ax b) = (bT xT AT )(Ax b)

    This is quadratic inx, hence it has aglobal minimumwhich we can nd by taking the derivative, setting it tzero, and solving forx. Doing this yields:

    AT Ax AT b = 0

    These are the famousnormal equations whose solution given by:

    x = (AT A) 1AT b

    The matrixA = (AT A) 1AT

    is known as thepseudo-inverse of the matrixA.34

    Geometrical Interpretation of Least Squares

    Typically, the number of frequency constraints is muchgreater than the number of design variables (lter taps).In these cases, we have anoverdetermined system of equations (more equations than unknowns). Therefore,we cannot generally satisfy all the equations, and we areleft with minimizing some error criterion to nd theoptimal compromise solution.

    In the case of least-squares approximation, we areminimizing theEuclidean distance , which suggests thefollowing geometrical interpretation:

    Ax

    column-space of A

    Ax = b + eMinimizex e 2 = b Ax 2

    35

    Ax

    column-space of A

    This diagram suggests that the error vectorb Ax isorthogonal to the column space of the matrixA, hence imust be orthogonal to each column inA.

    AT (b Ax) = 0 AT Ax = AT b

    This is how theorthogonality principle can be used toderive the fact that the best least squares solution isgiven by

    x = (AT A) 1AT b = Ab

    Note that the pseudo-inverseA projects the vector bonto the column space of A.

    In Matlab:

    x = A \ b

    x = pinv(A) * b

    36

  • 8/15/2019 WinFlt 4up

    10/19

    Chebyshev Optimal Linear Phase lter Design

    Consider theL -norm minimization problem:

    minx

    Ax b

    We said earlier that the norm of a vector is themaximum element of that vector, hence minimizing the norm is minimizing the maximum element of a vector:

    minx

    maxk

    |aT k x bk|

    whereaT k denotes the kth row of the matrixA.

    We can then write this as:

    min ts.t. |aT k x bk| < t

    If we introduce a new variablex = xt , then

    t = f T x = [ 0 . . . 0 1 ]x, and our optimization problembecomes:

    minx

    f T x

    s.t. [ aT k 0 ] x bk < xf T x

    37

    Hence we are minimizing alinear objective , subject to aset of linear constraints . This is known as alinear programming problem (linprog in Matlab).

    Linear

    Linear

    Objective

    Constraints

    38

    More General Real FIR Filters

    So far we have looked at the design of linear phase FIRlters. In this case,A, x and b are all real.

    Sometimes we may want to design lters and specify boththe magnitude and the phase of the frequency response.

    Examples:

    Minimum phase lters

    Inverse lters

    Fractional delay lters

    Interpolation polyphase sublters

    39

    Complex FIR Filter Design

    In linear-phase lter design, we assumed symmetry oflter coefficients [h(n) = h( n)]

    The lter frequency response became asum of cosines (zero phase)

    The matrix A was real

    The desired magnitude responseb was real

    The nal zero-phase lterx could be right-shiftedL/ 2 samples to get a corresponding causallinear-phase FIR lter

    Now we would like to specify acomplex frequencyresponse. This means that:

    b is complex

    A is complex

    We still wantx (our lter coefficients) to be real

    If we try to use \ orpinv in Matlab, we will generallyget a complex result forx

    40

  • 8/15/2019 WinFlt 4up

    11/19

    Summarizing our problem:

    minx

    Ax b 2

    where, A C NxM , bC Nx 1, and x R Mx1

    Hence we have,

    minx

    [R (A) + j I (A)]x [R (b) + j I (b)] 22which can be written as:

    minx

    R(A)x R (b) + j [ I (A)x + I (b)] 22or

    minx

    R (A) I (A) x

    R (b) I (b)

    2

    2

    which is written in terms of onlyreal variables.

    Hence, we can use the standard least squares solvers inMatlab and end up with areal solution.

    Related paper

    Design of Fractional Delay Filters Using ConvexOptimization (Mohonk-97, Music 421 handout):

    http://ccrma.stanford.edu/~jos/eps/mohonk97.ps.gz

    41

    Optimal FIR Filters Arbitrary Magnitude andPhase Speciciations

    cremez (Matlab Signal Processing Toolbox) performscomplex L FIR lter design:

    Documentedonlineat The Mathworks(search forcremez )

    Convergence theoretically guaranteed forarbitrary magnitude and phase specications versus frequenc

    Reduces to Parks-McClellan algorithm (Remez secalgorithm) as a special case.

    Written by Karam and McClellan. See Design of Optimal Digital FIR Filters with Arbitrary Magnituand Phase Responses, by Lina J. Karam and JameH. McClellan, ISCAS-96. The paper may bedownloaded at

    http://www.eas.asu.edu/~karam/papers/iscas96 km.html

    42

    Second-Order Cone Problems (SOCP)

    A linear function is minimized over the intersection of an affine set and the product of second-order(quadratic) cones

    Nonlinear, convex problem including linear and(convex) quadratic programs as special cases

    Solved by efficient primal-dual interior-point methods

    Number of iterations required to solve a problemgrows at most as thesquare root of the problem size

    Typical number of iterations ranges between 5 and50, almost independent of the problem size

    See Applications of second-order cone programming, byM. Lobo, L. Vandenberghe, S. Boyd, and H. Lebret,Linear Algebra and its Applications , 284:193-228,November 1998, Special Issue on Linear Algebra inControl, Signals and Image Processing. Available online:

    http://www.stanford.edu/~boyd/socp.html

    For more on this topic, see also Prof. Boyds course onconvex optimization: EE 364 2 and text book (Boyd andVandenberghe, Cambridge U. Press, 2004).

    2 http://www.stanford.edu/class/ee364/

    43

    Hilbert Transform Filter Design Example:A Case Study in FIR Filter Design

    Design Example:

    Ideal Single-Sideband Filter (Hilbert transformer)

    Window Method using Kaiser Window

    Optimal Chebyshev using Remez Exchange

    44

    http://ccrma.stanford.edu/~%7B%7Djos/gz/mohonk97.ps.gzhttp://www.mathworks.com/access/helpdesk/help/toolbox/signal/filter11.shtmlhttp://www.eas.asu.edu/~%7B%7Dkaram/papers/iscas96_km.htmlhttp://www.stanford.edu/~%7B%7Dboyd/socp.htmlhttp://www.stanford.edu/class/ee364/http://www.stanford.edu/class/ee364/http://www.stanford.edu/~%7B%7Dboyd/socp.htmlhttp://www.eas.asu.edu/~%7B%7Dkaram/papers/iscas96_km.htmlhttp://www.mathworks.com/access/helpdesk/help/toolbox/signal/filter11.shtmlhttp://ccrma.stanford.edu/~%7B%7Djos/gz/mohonk97.ps.gz
  • 8/15/2019 WinFlt 4up

    12/19

    Problem Statement

    Design a negative-frequency lter which converts areal signal into its complex analytic signalcounterpart by ltering out negative frequencies.

    Equivalently, design a single sideband (SSB) lterwhich outputs a single-sideband signal in response toa complex-conjugate pair of sidebands (a Hermitianspectrum).

    We could also call it a positive-frequency-pass lter.

    The imaginary part of such a lter is called aHilbert transform lter .

    The ideal Hilbert transform is anallpass lter thatdelays positive-frequency components by 90 degrees,and advances negative-frequency components by 90degrees.

    45

    Hilbert Transform

    y(t) = (h i x)(t) (Hilbert transform of x)

    h i(t)= 1t (Hilbert transform kern

    H i()=

    j, > 0 j, < 0

    1, = 0

    (Hilbert frequency respo

    xa(t)= x(t) + jy (t) (Analytic signal fromx)

    = 1

    0X ()e jtd (Note: Lower limit usua

    Proof:

    X a() = X () + jY () (By linearity of Fourier

    = X + + X (Apply frequency respon+ j [ jX + + jX ]

    = 2X + ()

    46

    Kaiser Window

    Kaiser window in causal, linear-phase form:

    w = kaiser(M,beta); % M=length=257, beta=8

    Zero-pad by a factor of 8 and convert to zero-phase form(N = FFT size = 2048):

    wzp = [w((M+1)/2:M),zeros(1,N-M),w(1:(M-1)/2)];

    Kaiser window transform:

    W = fft(wzp);

    47

    0.5 0.4 0.3 0.2 0.1 0.1 0.2 0.3 0.4 0.5160

    140

    120

    100

    80

    60

    40

    20

    Kaiser Window Transform, FFT size = 2048, Window length = 257

    Normalized Frequency (cycles/sample)

    G a

    i n ( d B )

    0

    0

    48

  • 8/15/2019 WinFlt 4up

    13/19

    Kaiser window transform, close-up on main lobe

    0.05 0.04 0.03 0.02 0.01 0.01 0.02 0.03 0.04 0.05120

    100

    80

    60

    40

    20

    Close Up on Kaiser LF Response, FFT size = 2048, Window length = 257

    Normalized Frequency (cycles/sample)

    G a

    i n ( d B )

    0

    0

    49

    Oversimplied Window Method

    Sample the ideal Hilbert-transform kernelh(t) = 1/t

    to get

    h i(n)=

    1nT

    (Sampled Hilbert transform ke

    hw(n)= w(n)h i(n) (Windowed ideal impulse resp

    H w() = (W H )(n) (Smoothed ideal frequency re

    Design Parameters:

    fs = 22050; % sampling rate (Hz)T = 1/fs; % sampling period (sec)M = 257; % FIR filter length = window lengthN = 8*(M-1); % for interpolated spectral displaysbeta = 8; % beta for Kaiser window

    Filter Design:

    n = [-N/2+0.5:N/2-0.5]; % Time axis (avoid t=0)hi = T ./ (pi*n*T); % Sampled Hilbert kernel

    hr = sin(pi*n) ./ (pi*n); % 1/2 sample delay filterh = (hr + j*hi)/2; % Sampled ideal final filterplot(f,fftshift(max(-100,20*log10(abs(fft(h)))))); grid;...

    50

    FFT of Truncated(2048) Ideal Impulse Response

    -0.6 -0.4 -0.2 0.2 0.4 0.6-100

    -80

    -60

    -40

    -20

    20FFT of Truncated Analytically Specified "Ideal" Impulse Response

    Normalized Frequency (cycles/sample)

    G a

    i n ( d B )

    0

    0

    h = [h(N/2+1:N),h(1:N/2)]; % zero-phase form (almost)hw = wzp .* h; % Apply window to ideal impulse responseHw = fft(hw); % Frequency response we really get

    % Compute total stopband attenuation:ierr = norm(Hw(N/2+2:N))/norm(Hw)

    = 0.0378 = 3.8 percent

    For spectral displays, rotate buffer so negative frequenciesare on the left and DC is atk = N/ 2:

    51

    Hwp = [Hw(N/2+2:N), Hw(1:N/2+1)]; % Neg. freqs on leftHwpn = abs(Hwp); Hwpn = Hwpn/max(Hwpn);

    plot(f,20*log10(Hwpn)); grid;...

    FIR Frequency Response by the Window Method

    0.5 0.4 0.3 0.2 0.1 0.1 0.2 0.3 0.4 0.5140

    120

    100

    80

    60

    40

    20

    Length 257 AnalyticDerived FIR Frequency Response, FFT size = 2048

    Normalized Frequency (cycles/sample)

    G a i n ( d B )

    0

    0

    52

  • 8/15/2019 WinFlt 4up

    14/19

    Zoom in on low-frequency transition band

    0.05 0.04 0.03 0.02 0.01 0.01 0.02 0.03 0.04 0.05140

    120

    100

    80

    60

    40

    20

    20AnalyticDerived LowFrequency Transition Band, f1/fs=0.023926 (marked by "+")

    Normalized Frequency (cycles/sample)

    G a

    i n ( d B )

    0

    0

    Poorly positioned transition region from positive tonegative frequencies.

    Need to rstbandpass-lter the ideal impulse

    response. High-frequency transition identical, by symmetry

    53

    Ideal Bandlimited Impulse Response

    Since we are working with sampled data, the idealsingle-side-band lter impulse response is

    h(n) = IDTFT n(u)=

    12

    u()e jnd

    whereu() is the unit step function in the frequencydomain:

    u() = 1, 00, < 0

    We can evaluate the IDTFT directly as follows:

    h(n) =1

    2

    0e jnd =

    12jn

    e jn

    0=

    e jn 12jn

    =( 1)n 1

    2jn=

    0, n even, n = 0 j 1n , n odd

    For n = 0, going back to the original integral gives

    h(0) =1

    2

    0

    e j 0d =1

    2

    .

    Thus, the real part of h(n) is (n)/ 2, and the imaginarypart is 1/ (n ) for odd n and zero otherwise (as a resultof bandlimiting). There is no aliasing. However, we a

    54

    need a transition band . We can work this out analytically,or we can simply draw it in the frequency domain, takea (large) inverse DFT, and window that. Since the latterapproach is more general, well do that.

    Window Method applied to Bandlimited IdealImpulse Response

    Further Design Parameters:

    f1 = 530; % lower passband limit (Hz)N = 2^(nextpow2(8*fs/f1)) % FFT size from xition widthif N

  • 8/15/2019 WinFlt 4up

    15/19

    Desired Impulse Response

    h = ifft(H); % zero-phase form

    % measure of round-off error:ierr = norm(imag(h(1:2:N)))/norm(h) % zero?

    ierr =

    4.1958e-15

    % rough estimate of time-aliasing error:aerr = norm(h(N/2-N/32:N/2+N/32))/norm(h)

    aerr =

    4.8300e-04

    % for plots, prefer negative times on the left:hp = [h(N/2+2:N), h(1:N/2+1)];

    57

    Real Part of Desired Impulse Response

    150 100 50 50 100 1500.1

    0.1

    0.2

    0.3

    0.4

    0.5

    0.6Ideal SSB Filter Impulse Response, Real Part, FFT size = 2048

    Time (samples)

    A m p l i t u

    d e

    0

    0

    58

    Imaginary Part of Desired Impulse Response

    150 100 50 50 100 1500.4

    0.3

    0.2

    0.1

    0.1

    0.2

    0.3

    0.4Ideal SSB Filter Impulse Response, Imaginary Part, FFT size = 2048

    Time (samples)

    A m p l i t u d e

    0

    0

    Apply window to ideal impulse response:

    hw = wzp .* h; % Final FIR coefficientsHw = fft(hw); % Frequency response well see

    Total stopband energy:

    ierr = norm(Hw(N/2+2:N))/norm(Hw)disp(sprintf([Stop-band energy is %g percent of,...

    total spectral energy], 100*ierr));

    59

    Final FIR Filter Frequency Response

    0.5 0.4 0.3 0.2 0.1 0.1 0.2 0.3 0.4 0.5180

    160

    140

    120

    100

    80

    60

    40

    20

    Length 257 FIR filter Frequency Response, FFT size = 2048

    Normalized Frequency (cycles/sample)

    G a

    i n ( d B )

    0

    0

    60

  • 8/15/2019 WinFlt 4up

    16/19

    Zoom-in on Transition Region of Final FrequencyResponse

    0.05 0.04 0.03 0.02 0.01 0.01 0.02 0.03 0.04 0.05140

    120

    100

    80

    60

    40

    20

    20LowFrequency Transition Band, f1/fs=0.023926 (marked by "+")

    Normalized Frequency (cycles/sample)

    G a

    i n ( d B )

    0

    0

    Transition band better positioned

    100 dB stob-band attenuation

    61

    Remez Multiple Exchange Method

    Remez exchange algorithm for optimal Chebyshev(equiripple) FIR lter design.

    Original reference: J. H. McClellan, T. W. Parks, aL. R. Rabiner, A Computer Program for DesigninOptimum FIR Linear Phase Digital Filters,IEEE Trans. Audio Electro., vol AU-21, Dec. 1973,

    pp. 506-526. Text reference: L. R. Rabiner and B. Gold,Theory

    and Application of Digital Signal Processing,Prentice-Hall, 1975.

    Pertinent recent reference: A. Reilly, G. Frazer, andB. Boashash, Analytic Signal GenerationTips anTraps, IEEE Tr. Signal Processing , vol. 42, no. 11,Nov. 1994.

    Design an optimal lowpass lter of the desired width(takes quite a while):

    hrm = remez(M-1, [0,(f2-fs/4)/fn,0.5,1], ...[1,1,0,0], [1,10]);

    The weighting [1,P] says make the passband ripple Ptimes that of stopband. For steady-state audio spectra,

    62

    passband ripple can be 0.1 dB or more. However,consider an FM signal in which a sinusoid is sweepingback and forth in the passband. In that case, thepassband ripple generates AM sidebands, so a spec morelike that in the stopband may be called for. Here, weallow the passband ripple to be 10 times the stopbandripple, as a compromise.Modulate it up to where its a single-sideband lter. I.e.,right-shift by/ 2 in the frequency domain. I.e., rotatethe frequency response counterclockwise along the unitcircle by 90 degrees:

    hr = hrm .* j .^ [0:M-1];

    63

    Optimal Chebyshev FIR(257) FrequencyResponse

    0.5 0.4 0.3 0.2 0.1 0.1 0.2 0.3 0.4 0.5200

    150

    100

    50

    50Length 257 Optimal Chebyshev FIR SingleSidebandFilter Freq. Response

    Normalized Frequency (cycles/sample)

    G a

    i n ( d B )

    0

    0

    64

  • 8/15/2019 WinFlt 4up

    17/19

    Zoom-In on Transition Band

    0.05 0.04 0.03 0.02 0.01 0.01 0.02 0.03 0.04 0.05200

    150

    100

    50

    50LowFrequency Transition Band, f1/fs=0.023926 (marked by "+")

    Normalized Frequency (cycles/sample)

    G a

    i n ( d B )

    0

    0

    65

    Passband Ripple

    0.18 0.2 0.22 0.24 0.26 0.28 0.3 0.324

    3

    2

    1

    1

    2

    3

    4x 10

    4 Passband Ripple

    Normalized Frequency (cycles/sample)

    G a

    i n ( d B )

    0

    66

    Initial Impulse Response

    5 10 15 20 25 30 35 40 45 508

    6

    4

    2

    2

    4

    6

    8x 10

    4 First 50 impulseresponse coefficients

    Index

    A m p l i t u d e

    0

    0

    67

    Summary of Trade-Offs

    Window-method lter:

    Stopband droops which wastes lter taps if theworst-case stopband attenuation is the only stopbanspec. However, such roll-off is natural in thefrequency domain and corresponds to a smootherpulse in the time domain.

    Passband is degraded by early roll-off. Edge is off

    Filter length can be thousands of taps as needed fofull audio band.

    Optimal Remez-Exchange lter:

    Stopband is ideal, equiripple.

    Transition region close tohalf that of the windowmethod.

    Pass-band is ideal, equiripple.

    Time-domain impulses frompassband ripple are smal

    Design time orders of magnitude larger than that fwindow method.

    68

  • 8/15/2019 WinFlt 4up

    18/19

    Fails to converge for lters much longer than 256taps. (Need to increase working precision to getlonger lters.)

    69

    Matlab hilbert() function

    The Matlab Hilbert function returns an analytic signalgiven its real part.

    Nh = M-2; % This looks bestdelta = [1,zeros(1,Nh)]; % zero-phase impulsehh = hilbert(delta); % zeros negative-freq FFT binsHh = fft(hh); % FIR frequency response

    0.5 0.4 0.3 0.2 0.1 0.1 0.2 0.3 0.4 0.5350

    300

    250

    200

    150

    100

    50

    Frequency Response of Length 256 hilbert() using Matlab

    Normalized Frequency (cycles/sample)

    G a

    i n ( d B )

    0

    0

    Looks pretty good, but lets zero-pad the impulseresponse to interpolate the frequency response:

    70

    hhzp = [hh(Lh/2+1:Lh), zeros(1,N-Lh), hh(1:Lh/2)];Hhzp = fft(hhzp); % Frequency response

    0.5 0.4 0.3 0.2 0.1 0.1 0.2 0.3 0.4 0.5350

    300

    250

    200

    150

    100

    50

    Interpolated Frequency Response of Length 256 hilbert() using Matlab

    Normalized Frequency (cycles/sample)

    G a

    i n ( d B )

    0

    0

    71

    0.05 0.04 0.03 0.02 0.01 0.01 0.02 0.03 0.04 0.05350

    300

    250

    200

    150

    100

    50

    50LowFrequency Transition Band, f1/fs=0.023926 (marked by "+")

    Normalized Frequency (cycles/sample)

    G a

    i n ( d B )

    0

    0

    Problems:

    Transition bandwidth only 2 bins wide.

    Massive time aliasing.

    Only justiable for periodic signals with period exequal to lter length Nh. In this case only, timealiasing is equivalent to overlap-add from adjacentperiods.

    72

  • 8/15/2019 WinFlt 4up

    19/19

    More generally, any real signal given to hilbert() must beinterpreted as precisely one period of a periodic signal.

    73