7
Lab Handout 09: FIR Filter Design Using MATLAB Course Code: EEE 420 Course Name: Digital Signal Processing Electrical & Electronic Engineering , Eastern Mediterranean University Instructor: Asst. Prof. Dr. Erhan A. İnce E-mail: [email protected] Ext: 2778 Lab Assistant: Mr. Burçin Özmen E-mail: [email protected] Ext: 2771 LINEAR-PHASE FIR FILTER Shapes of impulse and frequency responses and locations of system function zeros of linear-phase FIR filters will be discussed. Let , be the impulse response of length (or duration) M. Then the system function is which has poles at the origin z = 0 (trivial poles) and zeros located anywhere in the z-plane. The frequency response function is Type-1 Linear-Phase FIR Filters Symmetrical impulse response and M odd. In this case , is an integer, and , . Then we can show that

uncublackman

Embed Size (px)

DESCRIPTION

ok

Citation preview

Lab Handout 09: FIR Filter Design Using MATLAB

Lab Handout 09: FIR Filter Design Using MATLABCourse Code: EEE 420

Course Name: Digital Signal Processing

Electrical & Electronic Engineering , Eastern Mediterranean University

Instructor: Asst. Prof. Dr. Erhan A. nce

E-mail: [email protected]: 2778Lab Assistant: Mr. Burin zmen

E-mail: [email protected]: 2771

LINEAR-PHASE FIR FILTERShapes of impulse and frequency responses and locations of system function zeros of linear-phase FIR filters will be discussed.

Let , be the impulse response of length (or duration) M. Then the system function is

which has poles at the origin z = 0 (trivial poles) and zeros located anywhere in the z-plane. The frequency response function is

Type-1 Linear-Phase FIR FiltersSymmetrical impulse response and M odd. In this case , is an integer, and , . Then we can show that

where sequence is obtained from as

Since then, we have

where is an amplitude response function and not a magnitude response function.

function [Hr,w,a,L]=Hr_Type1(h);

% Computes Amplitude response Hr(w)of a Type-1 LP FIR filter

% -----------------------------------------------------------

% [Hr,w,a,L]=Hr_Type1(h)

% Hr = Amplitude Response

% w = 500 frequencies between [0,pi] over which Hr is computed

% a = Type-1 LP filter coefficients

% L = Order of Hr

% h = Type-1 LP filter impulse response

%

M = length(h);

L= (M-1)/2;

a = [h(L+1) 2*h(L:-1:1)]; % 1x(L+1) row vector

n = [0:1:L] % (L+1)x1 column vector

w = [0:1:500]'*pi/500;

Hr = cos(w*n)*a';Type-2 Linear-Phase FIR FiltersSymmetrical impulse response and M even. In this case , is not an integer, and , . Then we can show that

where

Hence,

where is an amplitude response function. Note that we get

regardless of or . Hence we cannot use this type (i.e. symmetrical and M even.) for highpass or bandstop filters.

Type-3 Linear-Phase FIR FiltersAntisymmetric impulse response and M odd. In this case , is an integer, and , , and . Then we can show that

where

Hence,

Note that at and we have , regardless of or . Furthermore, , which means that is purely imaginary. Hence this type of filter is not suitable for designing a lowpass or a highpass filter. However, this behavior is suitable for approximating ideal Hilbert transformers and differentiators.

function [Hr,w,c,L]=Hr_Type3(h);

% Computes Amplitude response Hr(w) of a Type-3 LP FIR filter

% -----------------------------------------------------------

% [Hr,w,c,L]=Hr_Type3(h)

% Hr = Amplitude Response

% w = frequencies between [0,pi] over which Hr is computed

% b = Type-3 LP filter coefficients

% L = Order of Hr

% h = Type-3 LP filter impulse response

%

M = length(h);

L = (M-1)/2;

c = [2*h(L+1:-1:1)];

n = [0:1:L];

w = [0:1:500]'*pi/500;

Hr = sin(w*n)*c';Type-4 Linear-Phase FIR FiltersAntisymmetric impulse response and M even. This case is similar to Type-2. We have

where

and

Note that at and we have and . Hence, this type is also suitable for designing digital Hilbert transformers and differentiators.

Assignments

1. MATLAB functions for Type-1 and Type-3 is given. Write a MATLAB function to compute the amplitude response and the location of the zeros of for Type-2 and Type-4.

2. Let

Determine the Type of the Linear-Phase FIR filters. Find the amplitude response and locations of the zeros of . Also plot the impulse response, amplitude response, coefficients, and the zero locations.

WINDOW DESIGN TECHNIQUESSummary of commonly used window function characteristics.

Window

NameTransition ApproximateWidth Exact ValuesMin. Stopband Attenuation

Rectangular

21 dB

Bartlett

25 dB

Hanning

44 dB

Hamming

53 dB

Blackman

74 dB

MATLAB provides several routines to implement window functions discussed above table.

w = boxcar(n) returns the n-point rectangular window in array w. w = triang(n) returns the n-point Bartlett (Triangular) window in array w. w = hanning(n) returns the n-point symmetric Hanning window in a column vector in array w .

w = hamming(n) returns the n-point symmetric Hamming window in a column vector in array w. w = blackman(n) returns the n-point symmetric Blackman window in a column vector in array w.

w = kaiser(n,beta) returns the beta-valued n-point Kaiser window in array w.Using these routines, we can use MATLAB to design FIR filters based on the window technique, which also requires an ideal lowpass impulse response as shown below.

function hd=ideal_lp(wc,M);

% Ideal LowPass filter computation

% --------------------------------

% [hd] = ideal_lp(wc,M);

% hd = ideal impulse response between 0 to M-1

% wc = cutoff frequency in radians

% M = length of the ideal filter

%

alpha = (M-1)/2;

n = [0:1:(M-1)];

m = n - alpha +eps; % add smallest number to avoi divided by zero

hd = sin(wc*m)./(pi*m);

To display the frequency domain plots of digital filters, MATLAB provides the freqz routine. Using this routing, we can developed a modified version, called freqz_m, which returns the magnitude response in absolute as well as dB scale, the phase response, and the group delay response as shown below.

function [db,mag,pha,grd,w] = freqz_m(b,a)

% Modified version of freqz subroutine

% ------------------------------------

% [db,mag,pha,grd,w] = freqz_m(b,a)

% db = relative magnitude in dB computed over 0 to pi radians

% mag = absolute magnitude computed over 0 to pi radians

% pha = Phase response in radians over 0 to pi radians

% grd = Group delay over 0 to pi radians

% w = 501 frequency samples between 0 to pi radians

% b = numerator polynomial of H(z) (for FIR: b=h)

% a = denominator polynomial of H(z) (for FIR: a=[1])

%

[H,w] = freqz(b,a,1000,'whole') ;

H = (H(1:1:501))'; w = (w(1:1:501))';

mag = abs(H);

db = 20*log10((mag+eps)/max(mag));

pha = angle(H);

grd = grpdelay(b,a,w);

Assignment 33. Design a digital FIR lowpass filter with the following specifications:

_1109607927.unknown

_1109608367.unknown

_1109609048.unknown

_1109610896.unknown

_1109611032.unknown

_1109611064.unknown

_1109611086.unknown

_1109613431.unknown

_1109666937.unknown

_1109612058.unknown

_1109611074.unknown

_1109611045.unknown

_1109610994.unknown

_1109611005.unknown

_1109611019.unknown

_1109610962.unknown

_1109609127.unknown

_1109610145.unknown

_1109609583.unknown

_1109609664.unknown

_1109609182.unknown

_1109609107.unknown

_1109608537.unknown

_1109608621.unknown

_1109608549.unknown

_1109608568.unknown

_1109608498.unknown

_1109608395.unknown

_1109608477.unknown

_1109608162.unknown

_1109608235.unknown

_1109608288.unknown

_1109608209.unknown

_1109607961.unknown

_1109607988.unknown

_1109607934.unknown

_1109606970.unknown

_1109607413.unknown

_1109607702.unknown

_1109607890.unknown

_1109607856.unknown

_1109607481.unknown

_1109607039.unknown

_1109607339.unknown

_1109606982.unknown

_1109606146.unknown

_1109606657.unknown

_1109606756.unknown

_1109606719.unknown

_1109606248.unknown

_1109606189.unknown

_1109606029.unknown

_1109605837.unknown

_1109605873.unknown