14
FIR Filter Design & Implementation • To fully design and implement a filter five steps are required: (1) Filter specification (2) Coefficient calculation (3) Structure selection (4) Simulation (optional) (5) Implementation

FIR Filter Design & Implementation To fully design and implement a filter five steps are required: (1)Filter specification (2)Coefficient calculation (3)Structure

Embed Size (px)

Citation preview

Page 1: FIR Filter Design & Implementation To fully design and implement a filter five steps are required: (1)Filter specification (2)Coefficient calculation (3)Structure

FIR Filter Design & Implementation

• To fully design and implement a filter five steps are required:(1) Filter specification(2) Coefficient calculation(3) Structure selection(4) Simulation (optional)(5) Implementation

Page 2: FIR Filter Design & Implementation To fully design and implement a filter five steps are required: (1)Filter specification (2)Coefficient calculation (3)Structure

Software Tools for Designing Filter• MATLAB provides some advanced tools for filters design– Signal Processing Tool (SPTool)– Filter Design (FDATool)

• There are also some free software packages to design filters

• Our main problem is how to implement the filter given the coefficients

• So we will design FIR filters using the relatively simple method of Windowing -- write Matlab scripts

Page 3: FIR Filter Design & Implementation To fully design and implement a filter five steps are required: (1)Filter specification (2)Coefficient calculation (3)Structure

Lowpass Filter Specification

Page 4: FIR Filter Design & Implementation To fully design and implement a filter five steps are required: (1)Filter specification (2)Coefficient calculation (3)Structure

Window Method : Step 1• First stage of this method is to calculate the

coefficients of the ideal filter.• This is calculated as follows:

1

21

2sin

c

c

j nd

j n

c

h n H e d

e d

n

n

2

2

c c

s pc

f

f ff

Page 5: FIR Filter Design & Implementation To fully design and implement a filter five steps are required: (1)Filter specification (2)Coefficient calculation (3)Structure

Window Method : Step 2• Second stage of this method is to select a window function

based on the passband or attenuation specifications, then determine the filter length based on the required width of the transition band

Window

Type

Normalized Transition

Width

Passband

Ripple (dB)

Stopband

Attenuation (dB)

Rectangular 0.9/N 0.7416 21

Hanning 3.1/N 0.0546 44

Hamming 3.3/N 0.0194 53

Blackman 5.5/N 0.0017 74

Page 6: FIR Filter Design & Implementation To fully design and implement a filter five steps are required: (1)Filter specification (2)Coefficient calculation (3)Structure

Window Method : Step 2• The normalized transition bandwidth as listed in the

table is defined as

• Example: If we choose the Hamming window, and specify a transition band from 6kHz to 7kHz, with sampling frequency at 40kHz, then the filter order is calculated as

3.3 3.340000 132

( ) 1000samplings p

N ff f

( ) /s p samplingf f f f

Page 7: FIR Filter Design & Implementation To fully design and implement a filter five steps are required: (1)Filter specification (2)Coefficient calculation (3)Structure

Window Method : Step 3

• The third stage is to calculate the set of truncated or windowed impulse response coefficients, h[n]:

for

nWnhnh d

even : 2 2

N NN n

1 1 odd :

2 2

N NN n

Page 8: FIR Filter Design & Implementation To fully design and implement a filter five steps are required: (1)Filter specification (2)Coefficient calculation (3)Structure

Using Matlab's fir1()• Instead of doing the design start from the ideal reponse, we shall use Matlab's fir1() function

• We will design a FIR filter with the following specification– sampling frequency = 8000– passband edge frequency = 1200– stopband edge frequency = 1800– minimum stopband attenuation = 40 dB

• By using the Hamming window, the stopband attenuation specification is met

• By default, fir1() uses the Hamming window• For more information, please refer to the Matlab on-line

help

Page 9: FIR Filter Design & Implementation To fully design and implement a filter five steps are required: (1)Filter specification (2)Coefficient calculation (3)Structure

Using Matlab's fir1()

fsamp = 8000;fp = 1200; % passbandfs = 1800; % stopbandfc = (fp+fs)/2; % cutoff

% default using Hamming window, compute orderN = round(3.3*fsamp/(fs-fp));str=sprintf('Filter order = %d', N);disp(str);

wc = 2*fc/fsamp; % normalize to pi radianb=fir1(N,wc);

freqz(b,1,512,fsamp);filtdesign.m

Page 10: FIR Filter Design & Implementation To fully design and implement a filter five steps are required: (1)Filter specification (2)Coefficient calculation (3)Structure

FIR Filter Structure - Direct Form

0 1 1( ) ( ) ( 1) ( 1)Ly n b x n b x n b x n L

1

0

( )L

kk

k

H z b z

1z 1z 1z

( )x n( 1)x n ( 2)x n

0b 1b 2b 1Lb

( 1)x n L

( )y n

Page 11: FIR Filter Design & Implementation To fully design and implement a filter five steps are required: (1)Filter specification (2)Coefficient calculation (3)Structure

Linear Phase FIR• For linear phase FIR, such as those designed with the window method, the coefficients have to be symmetrical

• We can then make use of the symmetry to reduce the multiplications

Page 12: FIR Filter Design & Implementation To fully design and implement a filter five steps are required: (1)Filter specification (2)Coefficient calculation (3)Structure

Example of Symmetrical FIR - Even Length

1z 1z 1z

( )x n

0b 1b 2b

( )y n

1z 1z

Page 13: FIR Filter Design & Implementation To fully design and implement a filter five steps are required: (1)Filter specification (2)Coefficient calculation (3)Structure

Example of Symmetrical FIR - Odd Length

1z 1z 1z

( )x n

0b 1b 2b

( )y n

1z 1z

1z

3b

Page 14: FIR Filter Design & Implementation To fully design and implement a filter five steps are required: (1)Filter specification (2)Coefficient calculation (3)Structure

FIR Filters Design with FDATool• The Filter Design and Analysis Tool (FDATool) is a graphical user

interface (GUI) for designing, quantizing, and analyzing digital filters.

• It includes a number of advanced filter design techniques and supports all the filter design methods in the Signal Processing Toolbox.– designing filters by setting filter specifications;– analyzing designed filters;– converting filters to different structures; and– quantizing and analyzing quantized filters.

• Open the FDATool by typing "fdatool" at theMATLAB command window.