CE105E12_AS5-Sol

Embed Size (px)

DESCRIPTION

sđ sdsdsd sd sd sdsssssssssssssssssssssssssssssssssssssssss ddddddddd sđ sdsdsd sd sd sdsssssss sssssssssssssssssssssssssssssssss ddddd ssssssssssssssssssssssssssssssssssssssss dddddddddddd ddddddddsđ sdsdsd sd sd sdsssssssssss sssssssssss sssssssssssssssssss dddddddddddd ddddddddddddddddddđfsdfs;kfjsfsdfjsdjfksjdfsl;dfj;alsjfàsjfsdkfjsldkfjlsdjfasdfskfj

Citation preview

  • 1

    CE105 DIGITAL SIGNAL PROCESSING

    ASSIGNMENT 5: FIR Filter Design

    Guide: Students are expected to submit MATLAB code and report the results in form of

    either MS Word or PDF format. All is zipped in a single file as [StudentID].zip.

    Send email to instructors with title [CE105.E12-AS1] [StudentID].

    For example, the student with ID 12345 should send the file named 12345.zip and the

    email title should be [CE105.E12-AS1] 12345

    1.1 Solution:

    Transition band:

    2 / 2 .1850 / 8000 0.4625p p sF F

    2 / 2 .2150 / 8000 0.5375s stop sF F

    | | 0.075p s

    Base on Table in Slide 32 Lecture 7, selecting the rectangular window will result in a

    passband ripple of 0.75dB and a stopband attenuation 21dB. Thus, this window selection

    would satisfy the design requirement for the passband ripple of 1dB and stopband

    attenuation of 20dB.

    Next, we determine the length of the filter as

    1.824L

    L

    The cutoff frequency is determined by:

    0.52

    p s

    c

    1.2 Solution:

    Based on the specifications, the Hann window will do the job, since it has a passband

    ripple of 0.055dB and a stopband attenuation of 44dB. Then

  • 2

    2

    | | 2500 1500 0.258000

    p s

    6.225L

    Hence, we choose 25 filter coefficients using the Hann window method. The cutoff

    frequency is 0.5 .

    Matlab Program:

    function B=firwd(N, Ftype, WnL, WnH, Wtype)

    %B=firwd(N,Ftype,WnL,WnH,Wtype)

    % FIR filter design using the window function method.

    % Input parameters:

    % N: the number of the FIR filter taps.

    % Note: It must be an odd number.

    % Ftype: the filter type

    %1. Lowpass filter;

    %2. Highpass filter;

    %3. Bandpass filter;

    %4. Band reject filter;

    % WnL: lower cutoff frequency in radians. Set WnL=0 for the

    highpass filter.

    % WnH: upper cutoff frequency in radians. Set WnH=0 for the

    lowpass filter.

    % Wtypw: window function type

    %1. Rectangular window;

    %2. Triangular window;

    %3. Hanning window;

    %4. Hamming window;

    %5. Blackman window;

    % Output:

    % B: FIR filter coefficients.

    M=(N-1)/2;

    hH = sin(WnH*[-M:1:-1])./([-M:1:-1]*pi);

    hH(M+1)=WnH/pi;

    hH(M+2:1:N)=hH(M:-1:1);

    hL=sin (WnL*[-M:1:-1])./([-M:1:-1]*pi);

    hL(M+1)=WnL/pi;

    hL(M+2:1:N)=hL(M:-1:1);

    if Ftype==1

    h(1:N)=hL(1:N);

    end

    if Ftype==2

    h(1:N)=-hH(1:N);

    h(M+1)=1+h(M+1);

  • 3

    end

    if Ftype==3

    h(1:N)=hH(1:N)-hL(1:N);

    end

    if Ftype==4

    h(1:N)=hL(1:N)-hH(1:N);

    h(M+1)=1+h(M+1);

    end

    % window functions;

    if Wtype==1

    w(1:N)=ones(1,N);

    end

    if Wtype==2

    w=1-abs([-M:1:M])/M;

    end

    if Wtype==3

    w = 0.5 + 0.5*cos([-M:1:M]*pi/M);

    end

    if Wtype==4

    w = 0.54 + 0.46*cos([-M:1:M]*pi/M);

    end

    if Wtype==5

    w = 0.42 + 0.5*cos([-M:1:M]*pi/M) + 0.08*cos(2*[-

    M:1:M]*pi/M);

    end

    B = h.*w

    Program P1.2

    % MATLAB program to create Figure in P1.2

    %

    N=25; Ftype=2; WnL=0; WnH=0.5*pi; Wtype=3;fs=8000;

    Bhan=firwd(N,Ftype,WnL,WnH,Wtype);

    freqz(Bhan,1,512,fs);

    axis([0 fs/2 -120 10]);

  • 4

    1.3 Solution:

    1 1 12

    | | 1600 500 0.2758000

    p s

    2 2 22

    | | 3500 2300 0.38000

    p s

    Based on the specifications, the Hamming window will do the job.

    1

    2

    246.6

    22

    L

    LL

    Choosing 25L filter coefficients using the Hamming window method:

    1 11

    1600 5002. 0.2625

    2 8000 2

    p s

    c

    2 22

    3500 23002. 0.725

    2 8000 2

    p s

    c

    0 500 1000 1500 2000 2500 3000 3500 4000-1500

    -1000

    -500

    0

    500

    Frequency (Hz)

    Phase (

    degre

    es)

    0 500 1000 1500 2000 2500 3000 3500 4000

    -100

    -50

    0

    Frequency (Hz)

    Magnitude (

    dB

    )

  • 5

    Program

    % MATLAB program to create Figure in P1.3

    %

    N=25;Ftype=3;WnL=0.2625*pi;WnH=0.725*pi;Wtype=4;fs=8000;

    Bham=firwd(N,Ftype,WnL,WnH,Wtype);

    freqz(Bham,1,512,fs);

    axis([0 fs/2 -130 10]);

    1.4 Solution:

    The normalized transition widths:

    1

    15002 0.375

    8000 , and 2

    13002 0.325

    8000

    The filter lengths are determined using the Blackman window as:

    1

    2

    29.3311

    33.8

    L

    LL

    0 500 1000 1500 2000 2500 3000 3500 4000-2000

    -1000

    0

    1000

    Frequency (Hz)

    Phase (

    degre

    es)

    0 500 1000 1500 2000 2500 3000 3500 4000

    -100

    -50

    0

    Frequency (Hz)

    Magnitude (

    dB

    )

  • 6

    We choose an odd number 35L . The normalized lower and upper cutoff frequencies are

    calculated as:

    2 .12500.3125

    8000cL

    2 .28500.7125

    8000cH

    Program P1.4

    % MATLAB program to create Figure in P1.4

    %

    N=35;Ftype=4;WnL=0.3125*pi;WnH=0.7125*pi;Wtype=5;fs=8000;

    Bblack=firwd(N,Ftype,WnL,WnH,Wtype);

    freqz(Bblack,1,512,fs);

    axis([0 fs/2 -120 10]);

    0 500 1000 1500 2000 2500 3000 3500 4000-3000

    -2000

    -1000

    0

    Frequency (Hz)

    Phase (

    degre

    es)

    0 500 1000 1500 2000 2500 3000 3500 4000

    -100

    -50

    0

    Frequency (Hz)

    Magnitude (

    dB

    )

  • 7

    Example:

    a) Design a 3-tap (L=3) FIR lowpass with cutoff frequency of 800Hz and

    sampling rate of 8000Hz using Hamming window function.

    b) Determine the transfer function and difference equation of the designed FIR

    system.

    c) Compute and plot the magnitude frequency response for 0, / 4, / 2,3 / 4

    and radians.