Projeto de Filtros FIR

download Projeto de Filtros FIR

of 37

Transcript of Projeto de Filtros FIR

  • 8/2/2019 Projeto de Filtros FIR

    1/37

  • 8/2/2019 Projeto de Filtros FIR

    2/37

    Copyright 1984 - 2001 by The MathWorks, Inc.

    2MATLAB for Signal Processing

    The filter Function

    The filter function implements adifference equation

    y=filter(b,a,x)

    Example: Averaging filter

    b=[0.5 0.5], a=1

    ylow=filter(b,a,x) Frequency[H,ang]=freqz(ylow,1)

    )1(1.1)(1.1)( += nxnxny

  • 8/2/2019 Projeto de Filtros FIR

    3/37

    Copyright 1984 - 2001 by The MathWorks, Inc.

    3MATLAB for Signal Processing

    Exercise: High and Low Pass Filter

    High pass and low pass filter test signal xwith filter and plot result

    Note: Test signal was:

    N=200; fs=10;t=(0:N-1)/fs;

    a=[1.00 0.25];f=[0.05; 5.0];

    x=a*cos(2*pi*f*t);

    )1(1.1)(1.1)( = nxnxny

  • 8/2/2019 Projeto de Filtros FIR

    4/37

    Copyright 1984 - 2001 by The MathWorks, Inc.

    4MATLAB for Signal Processing

    Solution: High and Low Pass Filter

    filter_soln

    1 1 1 1 1 11 11 11 11 11 11-1

    - .11

    - .11

    - .11

    - .11

    1

    .11

    .11

    .11

    .11

    1

    y=filter([0.5 0.5],1,x);plot(t,y)

    y=filter([0.5 -0.5],1,x);plot(t,y)

  • 8/2/2019 Projeto de Filtros FIR

    5/37

    Copyright 1984 - 2001 by The MathWorks, Inc.

    5MATLAB for Signal Processing

    Filter Design

    Frequency selective system

    Analog

    Digital

    Infinite impulse response (IIR)

    Finite impulse response (FIR) a=1

    ==

    =N

    k

    k

    M

    m

    m knyamnxbny11

    )()()(

    =

    =M

    m

    m mnxbny1

    )()(

  • 8/2/2019 Projeto de Filtros FIR

    6/37

    Copyright 1984 - 2001 by The MathWorks, Inc.

    6MATLAB for Signal Processing

    Filters

    DiscreteContinuous

    IIR FIR

    Chebyshev I

    Chebyshev II

    Eliptic

    Yulewalk

    Butterworth

    Arbitrary Response

    Equiripple

    Least Squares

    Raised Cosine

    Windowing

    Besse

    l

    Analog

    prototypedfilters

    Bilinear

    Transformation

    Filter Design Methods

  • 8/2/2019 Projeto de Filtros FIR

    7/37

    Copyright 1984 - 2001 by The MathWorks, Inc.

    7MATLAB for Signal Processing

    Filter Types

    Lowpass

    Highpass

    Bandpass

    Bandstop

  • 8/2/2019 Projeto de Filtros FIR

    8/37

    Copyright 1984 - 2001 by The MathWorks, Inc.

    8MATLAB for Signal Processing

    Transition Band

    Stopband

    Attenuation

    Passband Ripple

    Passband Stopband

    Fs/2

    Filter Specification

    Wp, Ws, Rp, Rs

  • 8/2/2019 Projeto de Filtros FIR

    9/37

    Copyright 1984 - 2001 by The MathWorks, Inc.

    9MATLAB for Signal Processing

    FIR Filter Design

    FIR

    FeaturesWindowing

    Inverse FFT to get h(n)

    Arbitrary response

    Other methods Example

    b=fir1(20,0.5,hanning(21));

    freqz(b,1)

  • 8/2/2019 Projeto de Filtros FIR

    10/37

    Copyright 1984 - 2001 by The MathWorks, Inc.

    10MATLAB for Signal Processing

    Windowing

    Finite data length Functions

    bartlett, blackman, boxcar, chebwin,

    hamming, hanning, kaiser, triang

    Example

    x=hanning(N);plot(hamming(32)

    stem(kaiser(16,30)

    1 1 11 11 11 11 11 111

    .11

    .11

    .11

    .00

    .11

    .00

    .00

    .00

    .00

    1

    1 1 1 1 1 11 11 11 111

    .11

    .11

    .00

    .11

    .00

    .11

    .00

    .11

    .00

    1

  • 8/2/2019 Projeto de Filtros FIR

    11/37

    Copyright 1984 - 2001 by The MathWorks, Inc.

    11MATLAB for Signal Processing

    Exercise: Remove a Note

    With Fs=8192, create a 3 second signal containing thesum of three unity amplitude tones (sinusoids) 220Hz,300Hz, 440Hz in the following time periods:

    220Hz 0

  • 8/2/2019 Projeto de Filtros FIR

    12/37

    Copyright 1984 - 2001 by The MathWorks, Inc.

    12MATLAB for Signal Processing

    Solution on Next Page

  • 8/2/2019 Projeto de Filtros FIR

    13/37

    Copyright 1984 - 2001 by The MathWorks, Inc.

    13MATLAB for Signal Processing

    Solution: Remove a Note

    Create signalFs=8192;

    t=0:1/Fs:3;

    a=[1 1 1];

    f=[220;300;440];

    mask(1,:)=ones(1,length(t));

    mask(2,:)=t>1;

    mask(3,:)=t>2;

    x=a*(mask.*sin(2*pi*f*t));

    plot(t,x)

    sound(x,Fs);

    remove_note

  • 8/2/2019 Projeto de Filtros FIR

    14/37

    Copyright 1984 - 2001 by The MathWorks, Inc.

    14MATLAB for Signal Processing

    Solution

    Design and apply filter using FDATool and SPTool

  • 8/2/2019 Projeto de Filtros FIR

    15/37

    Copyright 1984 - 2001 by The MathWorks, Inc.

    15MATLAB for Signal Processing

    Arbitrary Response FIR

    Specify arbitrary magnitude response

    Calculate FIR coefficients

    Function

    b = fir2(order,freq_vec,mag_vec);

    Example

    f = [0 0.6 0.6 1]; m = [1 1 0 0];

    b = fir2(30,f,m);

    freqz(b,1,128);

  • 8/2/2019 Projeto de Filtros FIR

    16/37

    Copyright 1984 - 2001 by The MathWorks, Inc.

    16MATLAB for Signal Processing

    Filter Design Tradeoffs

    Reduced width of

    transition band

    FIR

    Higher Order

    Always Stable

    Passband Phase

    Linear

    IIR

    Lower Order

    Can be Unstable

    Non-linear Phase

    Increased complexity

    (higher order)

    Lower Rp, Higher Rs Increased complexity

    (higher order)

  • 8/2/2019 Projeto de Filtros FIR

    17/37

    Copyright 1984 - 2001 by The MathWorks, Inc.

    17MATLAB for Signal Processing

    Impulse Response

    Given a set of a and b coefficients

    Calculate

    h=filter(b,a,[1 zeros(1,9)]);

    Calculate and plotimpz(b,a,10);

  • 8/2/2019 Projeto de Filtros FIR

    18/37

    Copyright 1984 - 2001 by The MathWorks, Inc.

    18MATLAB for Signal Processing

    Frequency Domain Filtering

    Filtering in time domain

    conv,filter Filtering in frequency domain

    fftfilt Efficient for long signals

  • 8/2/2019 Projeto de Filtros FIR

    19/37

    Copyright 1984 - 2001 by The MathWorks, Inc.

    19MATLAB for Signal Processing

    Summary

    Implement real world filter using filter

    Create LTI systems with specific magnitude response

    Filter passband types

    Filter specification IIR Filter Design

    Filter Design and Analysis Tool (FDATool)

    Filter Analysis with SPTool FIR Filter Design

    Filter in time domain

  • 8/2/2019 Projeto de Filtros FIR

    20/37

    Copyright 1984 - 2001 by The MathWorks, Inc.

    20MATLAB for Signal Processing

    Filter Design Functions

    IIR

    Features

    Design principleAnalog to discrete

    Methods

    Butterworth, Chebyshev I and II, Elliptic Functions

    butter, cheby1, cheby2, ellip

  • 8/2/2019 Projeto de Filtros FIR

    21/37

    Copyright 1984 - 2001 by The MathWorks, Inc.

    21MATLAB for Signal Processing

    IIR Filter Design

    Functions

    [b,a]=butter(order,specs,type) Example: Order 10 Butterworth. Fs=10 KHz

    (Nyquist=5kHz), bandpass 1.5KHz and 2KHz [b,a]=butter(10,[0.3 0.4],'bandpass'); Frequency response

    freqz(b,a,512,10000)

  • 8/2/2019 Projeto de Filtros FIR

    22/37

    Copyright 1984 - 2001 by The MathWorks, Inc.

    22MATLAB for Signal Processing

    Example: filtdem

    filtdem

  • 8/2/2019 Projeto de Filtros FIR

    23/37

    Copyright 1984 - 2001 by The MathWorks, Inc.

    23MATLAB for Signal Processing

    Arbitrary Response IIR

    Specify arbitrary magnitude response and frequencypoints

    Calculates IIR coefficients

    Function[b,a] = yulewalk(order,freq_vec,mag_vec);

    Examplef = [0 0.6 0.6 1]; m = [1 1 0 0];

    [b,a] = yulewalk(8,f,m);freqz(b,a,128,Fs);

  • 8/2/2019 Projeto de Filtros FIR

    24/37

    Copyright 1984 - 2001 by The MathWorks, Inc.

    24MATLAB for Signal Processing

    Exercise: Arbitrary Response IIR

    Using yulewalk, design an order 5 filter with thismagnitude response and a Sampling Frequency of 10Hz. Plot desired and actual response together.

  • 8/2/2019 Projeto de Filtros FIR

    25/37

    Copyright 1984 - 2001 by The MathWorks, Inc.

    25MATLAB for Signal Processing

    Solution: Arbitrary Response IIR

    yulewalk_soln

    f = [0 0.2 0.4 0.6 0.8 1];m = [0 1 .4 .3 .5 .9];Fs=10;[b,a] = yulewalk(5,f,m);[h,w] = freqz(b,a,128,Fs);

    plot(f*Fs/2,m,w,abs(h));grid;

  • 8/2/2019 Projeto de Filtros FIR

    26/37

    Copyright 1984 - 2001 by The MathWorks, Inc.

    26MATLAB for Signal Processing

    Example: filtdem2

    filtdem2

  • 8/2/2019 Projeto de Filtros FIR

    27/37

    Copyright 1984 - 2001 by The MathWorks, Inc.

    27MATLAB for Signal Processing

    Filter Design with FDAToolImport filter

    coefficients or

    design filter

    Set quantization

    parameters for

    Filter Design

    Toolbox

    Analysis method foranalyzing filter design

    Quantize

    current filter

    using Filter

    Design Toolbox

    Filter

    specifications

    Type of filter

    to design and

    method to use

    fdatool

  • 8/2/2019 Projeto de Filtros FIR

    28/37

    Copyright 1984 - 2001 by The MathWorks, Inc.

    28MATLAB for Signal Processing

    Importing Existing Designs

  • 8/2/2019 Projeto de Filtros FIR

    29/37

    Copyright 1984 - 2001 by The MathWorks, Inc.

    29MATLAB for Signal Processing

    Analyze Filters with FDATool

  • 8/2/2019 Projeto de Filtros FIR

    30/37

    Copyright 1984 - 2001 by The MathWorks, Inc.

    30MATLAB for Signal Processing

    Filter Quantization with FDATool

    Ability toquantize

    filters

  • 8/2/2019 Projeto de Filtros FIR

    31/37

    Copyright 1984 - 2001 by The MathWorks, Inc.

    31MATLAB for Signal Processing

    Print Preview and Annotation

  • 8/2/2019 Projeto de Filtros FIR

    32/37

    Copyright 1984 - 2001 by The MathWorks, Inc.

    32MATLAB for Signal Processing

    Convenient Exporting from FDATool

  • 8/2/2019 Projeto de Filtros FIR

    33/37

    Copyright 1984 - 2001 by The MathWorks, Inc.

    33MATLAB for Signal Processing

    Filter Design in SPTool

    Zoom controls

    Design Criteria

    numeric display

    Design method

    Filter type (lowpass,

    bandpass, etc.)Frequency

    response

    display and

    controls

  • 8/2/2019 Projeto de Filtros FIR

    34/37

    Copyright 1984 - 2001 by The MathWorks, Inc.

    34MATLAB for Signal Processing

    Filter Analysis with SPTool

    Magnitude, phase, pole zero,impulse, step, group

  • 8/2/2019 Projeto de Filtros FIR

    35/37

    Copyright 1984 - 2001 by The MathWorks, Inc.

    35MATLAB for Signal Processing

    Destination

    List of signals,

    filters, and

    spectra you want

    to export

    Items to list

    }

    Exporting Data from SPTool

    Exports objects to MATLAB workspace or file

    Stored as structure Export filters asobjects that can be

    used with the

    Control System

    Toolbox

  • 8/2/2019 Projeto de Filtros FIR

    36/37

    Copyright 1984 - 2001 by The MathWorks, Inc.

    36MATLAB for Signal Processing

    Overlay Spectra using SPTool

    Overlay spectrum

  • 8/2/2019 Projeto de Filtros FIR

    37/37

    37MATLAB for Signal Processing