ece 569 with matlab

Upload: xiao-yang

Post on 03-Jun-2018

231 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/12/2019 ECE 569 With Matlab

    1/17

    ECE 569

    Project 1 Report

    Xiao Yang

    Feb. 26 2015

  • 8/12/2019 ECE 569 With Matlab

    2/17

    1. Design objectives

    A band pass filter with specification shown as Fig.1 Desired Filter Performance Plot

    need to be designed by different method. Its has the following request to meet and

    these requirements apply to all different designing method in this project.

    1. Requirement on pass band: ripple 05.01 , presented in dB is

    dB4455.01

    1log20

    1

    , at the mean time, 3287.0,)1()1( 2112

    2. Requirement on stop band: ripple 01.02 , presented in dB is

    dB40)log(20 1 , because 2

    1

    )1(

    , so

    3. Pass band is ]5.0,25.0[ p , lower bound 25.0L , upper bound is

    5.0U

    , for prewarping 828.0)2

    tan(2

    L

    L

    T

    4. Stop band is ,55.0[]2.0,0s , the first part of stop band ends at

    55.02.0 21 ss , for prewarping, 65.0)2

    tan(2 1

    1 ssT

    5. Transition band is 55.0,5.0[]25.0,2.0tr

    6. Filter length should be as small as possible and linear phase property should be

    met when designing FIR filter

    2. FIR filter design

    Window method using Hamming window

    Design objective

    The objective of this designing method has been indicated in the first part.

  • 8/12/2019 ECE 569 With Matlab

    3/17

    Design Procedure

    While we design filters based upon ideal frequency response h() we desired, we

    have to perform Inverse Discrete Time Fourier Transformation (IDTFT) to transfer

    h() from frequency domain to time domain h(n). For a finite length in frequency

    domain, it will be transformed to h(n) of infinite length. So for a practical applied

    filter, a finite number of corresponding response are selected to build the filter and the

    tool used to select the response is called window. Hamming window is one of them.

    The filter length, or the order of filter is represented by N. N is even or not does not

    affect the designing the filter in the case of FIR filter designing, either does not the

    symmetry of N. To minimize the order of filter N, the bandwidth used for calculation

    is not the lower and upper bound of pass band but one expands it to be the middle of

    transitional band. Also in the calculation, a relaxation factor was applied. Then the

    frequency response will be

    ]2/)(2/)[(,1

    ,0d21{)(H

    UsLs

    otherwise

    When designing the filter, I designed M to be odd and the delaying2

    1Munits for

    linear phase property. Under such condition, by performing IDTFT which is

    deHdnh njd )(2

    1)( , we have )(nhd as

    2

    1]},2/)12()225.0sin[(]2/)12()525.0{sin[(

    2

    1)(

    MnMnMnnhd

    or 2/)1(,/)23.0()( Mnhd With knowing Hamming window as

    )1

    2cos(46.054.0)(

    M

    nnhm , the real unit sample response at each point of n when

  • 8/12/2019 ECE 569 With Matlab

    4/17

    we design using Hamming window will be )(*)()( nhnhnh md . In the following

    process of designing, Matlab and Matlab function freqz was applied, from the

    introduction, freqz is:

    [h,w] = freqz(b,a,n) returns the frequency response vector h and the

    corresponding angular frequency vector w for the digital filter whose transfer

    function is determined by the (real or complex) numerator and denominator

    polynomials represented in the vectors b and a, respectively. The vectors h and

    ware both of length n.n must be a positive integer greater than or equal to two.

    The angular frequency vector w has values ranging from 0 to radians per

    sample.1

    In this case, the denominator is considering as 1 and 8192 points are applied, so the

    range form 0 to is divided to be 8192 equal spaced and the relaxation factor is

    designed to be 0.0029 which gives band edges 0.2279 and 0.5221 to achieve the

    required performance. The minimum order I achieve in designing is 109. Its

    frequency response is plotted and attached in Fig.2 Hamming window design plot.

    The Frequency-sampling method

    Design objective

    The objective of this designing method has been indicated in the first part remains the

    same.

  • 8/12/2019 ECE 569 With Matlab

    5/17

    Design Procedure

    The first step in the designing is to choose the length of the filter. From previous designing

    experience, choose M=120 is a good option and divide 2 by 120, we can get 0.016 between two

    continued sampling points. Although the passing band could be simply decided as 1 but some

    ripple added will help it to reduce order of filter. So the Hd() could be presented in the following

    way after parameter of magnitude response of particular frequency in the transitional band has

    been decided by trials

    Hd()=

    ]44,25[,0

    ]24[],2.0[]23,22[,]8.0,1[

    ]21,12[],1.01,11.01,0.97,1.01,0.97,1.02,0.97,1.02,0.97,[

    ]11,10[,]8.0,15.0[

    ]9,0[,0

    1

    1

    k

    kke

    k

    ke

    k

    kM

    Mj

    kM

    Mj

    The whole serial is 90 numbers and using IDTFT and freqz, the corresponding filter will be

    achieved and the plot is in Fig.3 Frequency Response of Frequency Sampling Method

    The Remez method

    Design objective

    The objective of this designing method has been indicated in the first part remains the

    same.

    Design Procedure

    Another designing is performed by using Remez method. The algorithm was improved by Parks

    MmClellan. The designing procedure was done by Matlab with function firpm which works as

    described below:

    B=FIRPM(N,F,A) returns a length N+1 linear phase (real, symmetric coefficients) FIR filter

    which has the best approximation to the desired frequency response described by F and A in the

    minimax sense. F is a vector of frequency band edges in pairs, in ascending order between 0 and 1.

    1 corresponds to the Nyquist frequency or half the sampling frequency. At least one frequency

    band must have a non-zero width. A is a real vector the same size as F which specifies the

    desired amplitude of the frequency response of the resultant filter B.2

  • 8/12/2019 ECE 569 With Matlab

    6/17

    The function actually used is B=firpm(N,F,A,W) where the extra parameter W is weighting

    function which affecting the magnitude relationship between pass band ripples and stop band

    ripples.

    So in this designing, following parameters was applied:

    F=[0 0.2 0.25 0.5 0.55 1]

    A=[0 0 1 1 0 0]

    W=[1 5 1]

    The smallest M that success in the designing is M=65, the function talked above firpm is used to

    get h(n). After getting h(n), use function freqz in Matlab to calculate filters frequency response,

    the frequency response is plotted in Fig.4 Frequency Response of Remez designed filter.

    3. IIR filter design

    The primary task in designing IIR filter is to decide the order of filters of different

    designing method. By evaluating the order for a low pass filter, we can double the

    order of low pass filter and take it to design the band pass filter to fit requirement of

    design objectives, under assumption of 65.0and,8248.0 1 spLs ,

    99.995 and 0.3287. Hereby are the evaluation of pass band filters order of

    different designing methods:

    Butterworth filter: 48)log(

    )log(

    2

    p

    sM

    Chebyshev filter: 18

    )(cosh

    )(cosh

    21

    1

    p

    s

    M

    Elliptic filter: 10

    )(1)(

    )(1)(

    2

    2

    2

    s

    p

    s

    p

    KK

    KK

    M

    Considering a filter H(z), it could be actually write as the following format

    1

    1

    1

    0

    1

    )(M

    m

    m

    m

    M

    n

    n

    n

    za

    zb

    zH

    For FIR filter, the denominator is 1 with all coefficient of z at denominator equals to 0,

    so we only need calculate the coefficient of numerator. For IIR filter, we need to

  • 8/12/2019 ECE 569 With Matlab

    7/17

    calculate the coefficient of z at both numerator and denominator. After the calculation,

    use Matlab function freqz to achieve frequency response.

    Butterworth filter

    Design Objectives

    The objective of this designing is to design a Butterworth filter which achieves the

    performance indicated in the first part.

    Design Procedure

    Using Matlab and the function butter, which calculate the coefficient of numerator

    and denominator of a digital filter by giving the performance we desired for the filter,

    we can design the filter in Butterworth method. The function of butter works in the

    following way:

    BUTTER Butterworth digital and analog filter design.

    [B,A] = BUTTER(N,Wn) designs an Nth order lowpass digital Butterworth filter

    and returns the filter coefficients in length N+1 vectors B (numerator) and A

    (denominator). The coefficients are listed in descending powers of z. If Wn is a

    two-element vector, Wn = [W1 W2], BUTTER returns an order 2N bandpass filterwith passband W1 < W < W2.3

    Beginning from the order of 48/2=24, the performance requirement could be successfully met at

    this order. Then adjust band edge and decrease the order of the filter. By taking trials step by step,

    the design could be succeed at minimum order of M=18. At this time, the band edge applied to

    designing is 0.241 and 0.508. Frequency plot is available in Fig.5 Frequency Response of

    Butterworth Filter Design.

    Chebyshev filter

    Design Objectives

    The objective of this designing is to design a Chebyshev filter which achieves the

    performance indicated in the first part.

  • 8/12/2019 ECE 569 With Matlab

    8/17

    Design Procedure

    By using Matlab and the function of cheby1, nomerator and denominator coefficient

    of Chebyshev filter could be calculated. The function cheby1 works as described

    below:CHEBY1 Chebyshev Type I digital and analog filter design. [B,A] =

    CHEBY1(N,R,Wp) designs an Nth order lowpass digital Chebyshev filter with R

    decibels of peak-to-peak ripple in the passband. CHEBY1 returns the filter

    coefficients in length N+1 vectors B (numerator) and A (denominator). The

    passband-edge frequency Wp must be 0.0 < Wp < 1.0, with 1.0 corresponding to half

    the sample rate. Use R=0.5 as a starting point, if you are unsure about choosing R.

    If Wp is a two-element vector, Wp = [W1 W2], CHEBY1 returns an order 2N

    bandpass filter with passband W1 < W < W2.4

    As calculated previously, R=0.4455dB. The filter design start at M=18/2=9. From thesucceed designing of 9, the smallest order achieved is 8 which means the the pass

    band filter length is 16. Band edge applied to the design of order of 8 is 0.25 and

    0.5. The frequency response is attached as Fig.6 Frequency Response of Chebyshev

    Filter Design

    Elliptic filter

    Design Objectives

    The objective of this designing is to design a Elliptic filter which achieves the

    performance indicated in the first part.

    Design Procedure

    By using Matlab and the function of ellip, numerator and denominator coefficient of

    Chebyshev filter could be calculated. The function ellip works as described below:

    ELLIP Elliptic or Cauer digital and analog filter design.

    [B,A] = ELLIP(N,Rp,Rs,Wp) designs an Nth order lowpass digital elliptic filter with

    Rp decibels of peak-to-peak ripple and a minimum stopband attenuation of Rs

    decibels. ELLIP returns the filter coefficients in length N+1 vectors B (numerator)

    and A (denominator). The passband-edge frequency Wp must be 0.0 < Wp < 1.0, with

    1.0 corresponding to half the sample rate. Use Rp = 0.5 and Rs = 20 as starting

    points, if you are unsure about choosing them. If Wp is a two-element vector, Wp =

    [W1 W2], ELLIP returns an order 2N bandpass filter with passband W1 < W < W2.5

    Based on Matlab function introduced previously, Rp=0.4455 and Rs is 40 dB. Thedesigning was using M=10/2=5 and the band edge applied to the designing is 0.25

  • 8/12/2019 ECE 569 With Matlab

    9/17

    and 0.5. The result of minimum M is still 5 after several trials to reduce the number.

    The plot is available on Fig.7 Frequency Response of Elliptic Filter Design

    4. Conclusion

    The designing process of this project walked through FIR to IIR design, from mathematical aspect,

    as mentioned previously, the filter could be represented as a numerator polynomial over another

    denominator polynomial. The difference between FIR and IIR is that FIR has a denominator

    polynomial equals to 1 and IIR is not. In FIR, both the Hamming window and frequency sampling

    method could be summarized as knowing h(n), reversing it to h(), but frequency sampling allow

    designer to pic certain frequency to as desired magnitude and reflect it on the final designing. On

    the aspect of minimize the order, because Remez fully used the ripple allowed in the pass

    band/stop band, so it has the minimum filter order. On the aspect of saving resource including costand expense, Remez has the advantage. But Hamming still has the smoothest pass band. The

    advantage and disadvantage is decided relatively on the demand of using. Same idea was applied

    to IIR design. Chebyshev has better reaction speed which means transitional band is stiffer but the

    lager ripple of pass band than Butterworth. Elliptical has even stiffer transitional band than

    Chebyshev but the ripple exist on both pass band and stop band. The Chebyshev we designed here

    is Chebyshev type 1 which has ripple in pass band only and there is another type 2 which has

    ripple in stop band only. As same mentioned, these three type has advantage and disadvantage

    relatively on pass band ripple, stop band ripple and transitional band width. In practical

    application, we need to focus on real requirement and choose the most appropriate one.

  • 8/12/2019 ECE 569 With Matlab

    10/17

    1 http://www.mathworks.com/help/signal/ref/freqz.html2 Matlab help function text on function firpm

    3 Matlab help function text on function butter4 Matlab help function text on function cheby15 Matlab help function text on function ellip

    Fig.1Desired Filter Performance Plot

    http://www.mathworks.com/help/signal/ref/freqz.htmlhttp://www.mathworks.com/help/signal/ref/freqz.html
  • 8/12/2019 ECE 569 With Matlab

    11/17

    Fig.2Hamming window design

    plot

    Fig.3 Frequency Response of Frequency SamplingMethod

  • 8/12/2019 ECE 569 With Matlab

    12/17

    Fig.4 Frequency Response of Remez designed

    filter

    Fig.5 Frequency Response of Butterworth Filter Design.

    Fig.6Frequency Response of Chebyshev Filter Design

  • 8/12/2019 ECE 569 With Matlab

    13/17

    Fig.7Frequency Response of Elliptic Filter Design

    APPDIX

    1.wc1 =(1/4)*pi;

    wc2 =(1/2)*pi;

    wc3 =(0.2)*pi;

    wc4 =(0.55)*pi;

    delta1=0.05;

    delta2=0.01;

    nps = 8192;

    M=109;

    n = 0:(M-1);

    h =

    ( sin((wc4+wc2-0.0029*pi)/2*(n-(M-1)/2))-sin((wc3+wc1+0.0029*pi)/2

    *(n-(M-1)/2)) )./ (pi*(n-(M-1)/2));

    if (M/2)~=ceil(M/2),h((M+1)/2)=0.288 ; end

    hamming = 0.54 - 0.46*cos(2*pi*n/(M-1));

    [Hhm,w]=freqz(hamming.*h,1,nps);

    Hhmphase=angle(Hhm);

    figure(1),subplot(211),plot(w/pi,abs(Hhm),'-');

    axis([xlim 0 1.1]);

    xlabel('normalized frequency')

    ylabel('magnitude')

    title(['filter response, H(\omega), M=',num2str(M)]);

    grid;

    set(gca,'Xtick',[0 wc3/pi wc1/pi wc2/pi wc4/pi 1]);

    set(gca,'Ytick',[0 delta2 1-delta1 1+delta1]);

    subplot(212),plot(w/pi,Hhmphase,'-')

    axis([xlim -pi pi])

    xlabel('normalized frequency')

    ylabel('phase')

    title(['filter response, H(\omega), M=',num2str(M)])

    2M=90;BW=10;TBW=2;alpha = [0.15; 0.8];alpha1 = [1 ; 0.8];

  • 8/12/2019 ECE 569 With Matlab

    14/17

    w_k1 = ((2*pi)/M)*[0:M/2-1]';

    Hd_1 = [0.*ones(10,1);

    alpha.*ones(TBW,1) ;1.02;0.97;1.02;0.97;1.01;0.97;1.01;0.97;1.01;1;

    alpha1.*ones(TBW,1);0.2;0.*ones(20,1)] .* exp(-j*((M-1)/2)*w_k1);

    Hd_2 = conj(flipud(Hd_1));

    Hd_2 = conj(flipud(Hd_1));

    Hd = [Hd_1 ; zeros(M-2*length(Hd_1)-1,1) ; Hd_2 ] ;

    h = ifft(Hd);

    nps = 4096;

    [H,w]=freqz(h,1,nps);

    Hphase=angle(H);

    figure(1);subplot(211);

    plot(w/pi,abs(H),2*[0:floor((M+1)/2)-1]'/M,abs(Hd(1:floor((M+1)/2))),'o');

    set(gca,'XTick',[0.2 0.25 0.5 0.55 1]);

    set(gca,'YTick',[0.01 0.95 1 1.05]);

    xlabel('normalized frequency (\pi rad/sample)'),

    ylabel('|H(\omega)|')

    title(['Freq. samp. filt. resp.: M = ',num2str(M),', BW =

    ',num2str(BW)])

    grid

    3.

    subplot(212);plot(w/pi,Hphase);

    axis([xlim -pi pi]);

    grid

    xlabel('normalized frequency (\times\pi rad./sample)')

    ylabel('phase')

    title(['filter response, H(\omega), M=',num2str(M)])

    3.M=65;

    delta_1=0.05;%PB tolerance

    delta_2=0.01;%SB tolerance

    F=[0 0.2 0.25 0.5 0.55 1];%freq in Hz

    A = [ 0 0 1 1 0 0 ] ;

    W=[1 delta_2/delta_1 1];

    h=firpm(M-1,F,A,W);

    omega=[0:12000]*pi/12000;

  • 8/12/2019 ECE 569 With Matlab

    15/17

    H=freqz(h,1,omega);

    subplot(211),plot(omega/pi,abs(H));

    grid;

    set(gca,'Xtick',[0 0.2 0.25 0.5 0.55 1]);

    set(gca,'Ytick',[0 delta_2 1-delta_1 1+delta_1]);

    xlabel('Nomarlized Frequency');

    ylabel('Magnitude Response');

    title(['Filter Length N=',num2str(M)]);

    Hrphase=angle(H);

    subplot(212),plot(omega/pi,Hrphase,'-','linewidth',2);

    grid;

    set(gca,'Xtick',[0 0.45 0.6 1]);set(gca,'Ytick',[-3 -2 -1 0 1 2 3]);

    xlabel('Nomarlized Frequency');

    ylabel('Phase Response');

    4.[a,b]=butter(18,[0.241 0.508]);

    [z,p,k]=butter(18,[0.241 0.508]);

    Hz=tf(a,b,1);

    num=Hz.num;

    den=Hz.den;

    num=num{:};

    den=den{:};

    figure(1);

    nps = 10000;

    [H,w]=freqz(a,b,nps);

    Hphase=angle(H);

    figure(1);subplot(211);

    plot(w/pi,abs(H));

    set(gca,'XTick',[0.2 0.25 0.5 0.55 1]);

    set(gca,'YTick',[0.01 0.95 1 1.05]);xlabel('normalized frequency (\pi rad/sample)'),

    ylabel('|H(\omega)|')

    grid

    subplot(212);plot(w/pi,Hphase);

    axis([xlim -pi pi]);

    grid

    xlabel('normalized frequency (\times\pi rad./sample)')

    ylabel('phase')

  • 8/12/2019 ECE 569 With Matlab

    16/17

    5.[a,b]=cheby1(8,0.4455,[0.25 0.5]);

    [z,p,k]=cheby1(8,0.4455,[0.25 0.5]);

    Hz=tf(a,b,1);

    num=Hz.num;

    den=Hz.den;

    num=num{:};

    den=den{:};

    figure(1);

    nps = 10000;

    [H,w]=freqz(a,b,nps);

    Hphase=angle(H);figure(1);subplot(211);

    plot(w/pi,abs(H));

    set(gca,'XTick',[0.2 0.25 0.5 0.55 1]);

    set(gca,'YTick',[0.01 0.95 1 1.05]);

    xlabel('normalized frequency (\pi rad/sample)'),

    ylabel('|H(\omega)|')

    grid

    subplot(212);plot(w/pi,Hphase);

    axis([xlim -pi pi]);

    grid

    xlabel('normalized frequency (\times\pi rad./sample)')

    ylabel('phase')

    6.[a,b]=ellip(5,0.4455,40,[0.25 0.5]);

    [z,p,k]=ellip(5,0.4455,40,[0.25 0.5]);

    Hz=tf(a,b,1);

    num=Hz.num;

    den=Hz.den;

    num=num{:};

    den=den{:};

    figure(1);

    nps = 10000;

    [H,w]=freqz(a,b,nps);

    Hphase=angle(H);

  • 8/12/2019 ECE 569 With Matlab

    17/17

    figure(1);subplot(211);

    plot(w/pi,abs(H));

    set(gca,'XTick',[0.2 0.25 0.5 0.55 1]);

    set(gca,'YTick',[0.01 0.95 1 1.05]);

    xlabel('normalized frequency (\pi rad/sample)'),

    ylabel('|H(\omega)|')

    grid

    subplot(212);plot(w/pi,Hphase);

    axis([xlim -pi pi]);

    grid

    xlabel('normalized frequency (\times\pi rad./sample)')ylabel('phase')