Sunteți pe pagina 1din 23

Practical Signal Processing Concepts and Algorithms using MATLAB

FIR Filter Design

2010 Trity Technologies Sdn Bhd. All Rights Reserved

6-1

FIR Filter Design

Section Outline

I

FIR design methods Windowing Standard band filters Arbitrary response filters Multiband filters Raised cosine filters Frequency domain filtering
II III IV

2010 Trity Technologies Sdn Bhd. All Rights Reserved

6-2

FIR Filter Design

FIR Filter Design


FIR filters have the following advantages:

Exactly linear phase is possible


Always stable, even when quantized Design methods are generally linear Efficient hardware realizations Startup transients have finite duration FIR filters have the following disadvantages:

Higher filter order than IIR filters


Corresponding greater delays

2010 Trity Technologies Sdn Bhd. All Rights Reserved

6-3

FIR Filter Design

FIR Methods

Filter Method Windowing

Description Apply window to truncated inverse Fourier transform of desired filter

Filter Functions

fir1, fir2, kaiserord firls, firpm, firpmord fircls, fircls1 cfirpm firrcos
6-4

Multiband with Equiripple or least squares approach Transition Bands over frequency sub-bands Constrained Least Squares Arbitrary Response Raised Cosine Minimize squared integral error over entire frequency range subject to maximum error constraints Arbitrary responses, including nonlinear phase and complex filters Lowpass response with smooth, sinusoidal transition

2010 Trity Technologies Sdn Bhd. All Rights Reserved

FIR Filter Design

Method

Description

Functions

Windowing Multiband with Transition Bands Constrained Least Squares

Apply window to truncated inverse Fourier transform of desired "brick wall" filter Equiripple or least squares approach over sub-bands of the frequency range Minimize squared integral error over entire frequency range subject to maximum error constraints

fir1, fir2, kaiserord


firls, remez, remezord

fircls, fircls1

Arbitrary Response
Raised Cosine
2010 Trity Technologies Sdn Bhd. All Rights Reserved

Arbitrary responses, including nonlinear phase and complex filters


Lowpass response with smooth, sinusoidal transition

cremez

firrcos
6-5

FIR Filter Design

Impulse Response Revisited


FIR filter: y (n) bm x(n m)
m 0 M

>> b = [b0 b1 bM]; a = 1; stem(b)

no need to specify

impz(b,1)

FIR filter coefficients give the impulse response


2010 Trity Technologies Sdn Bhd. All Rights Reserved

6-6

FIR Filter Design

Linear Phase Filters


Impulse response is symmetric about its midpoint:

()/

d()/d

constant phase delay constant group delay no phase distortion Except for cfirpm, all of the FIR filter design functions in the Signal Processing Toolbox design linear phase filters only.
2010 Trity Technologies Sdn Bhd. All Rights Reserved

6-7

FIR Filter Design

FIR Filter Types


I II

odd length, odd symmetry

even length, odd symmetry

III

IV

odd length, even symmetry

even length, even symmetry

length of impulse response - 1


Filter Type Type I Type II Type III Type IV Filter Order Even Odd Even Odd Symmetry Response H(0) No restriction No restriction

No highpass or bandstop filters


Response H(1) (Nyquist) No restriction H(1) = 0 H(1) = 0 No restriction

b(k ) b(n 2 k ), k 1,..., n 1 b(k ) b(n 2 k ), k 1,..., n 1

b(k ) b(n 2 k ), k 1,..., n 1 H(0) = 0 b(k ) b(n 2 k ), k 1,..., n 1 H(0) = 0

fir1,fir2,firls,firpm,fircls,fircls1,firrcos
2010 Trity Technologies Sdn Bhd. All Rights Reserved

6-8

FIR Filter Design

Digital filters with finite-duration impulse response (all-zero, or FIR filters) have both advantages and disadvantages compared to infinite-duration impulse response (IIR) filters. FIR filters have the following primary advantages: They can have exactly linear phase. They are always stable. The design methods are generally linear. They can be realized efficiently in hardware. The filter startup transients have finite duration. The primary disadvantage of FIR filters is that they often require a much higher filter order than IIR filters to achieve a given level of performance. Correspondingly, the delay of these filters is often much greater than for an equal performance IIR filter.

2010 Trity Technologies Sdn Bhd. All Rights Reserved

6-9

FIR Filter Design

Example 1
Design a 48th-order FIR bandpass filter with passband 0.35 0.65:

Solution
>>b = fir1(48,[0.35 0.65]); >>freqz(b,1,512)

Example 2:
Design a lowpass filter with the following specifications using the optimal design method : >>rp = 0.01; >>rs = 0.1; >>fs = 8000; >>a = [1 0]; % Passband ripple % Stopband ripple % Sampling frequency % Desired amplitudes

>>f = [1500 2000]; % Cutoff frequencies

2010 Trity Technologies Sdn Bhd. All Rights Reserved

6-10

FIR Filter Design

Solution >>[n,fo,ao,w] = remezord(f,a,dev,fs);

>> dev=[0.01 0.1] >>[n,fo,ao,w]=remezord([1500 2000],[1 0],dev,8000); % approximate order, normalized frequency band edges, frequency band amplitudes, and weights that meet input specifications f, a, and dev.% >>b=remez(n,fo,ao,w); %use n, fo, ao and w to design the filter b which approximately meets the specifications given by remezord input parameters f, a, and dev.%
>>freqz(b,1,1024,8000); >>title('Lowpass Filter Designed to Specifications');

2010 Trity Technologies Sdn Bhd. All Rights Reserved

6-11

FIR Filter Design

Window-Based Design
H(f)
ifft

h(n)

h.*w HW(f) hw(n)

fft

2010 Trity Technologies Sdn Bhd. All Rights Reserved

6-12

FIR Filter Design

Windowing Functions
bartlett, barthannwin, blackman, blackmanharris, bohmanwin, chebwin, flattopwin, gausswin, hamming, hann, kaiser, parsenwin, rectwin, triang, tukeywin

.*

y = sin(n);

W = gausswin(2*length(y),3); w = W(length(y)+1:end);

wy = w'.*y;

2010 Trity Technologies Sdn Bhd. All Rights Reserved

6-13

FIR Filter Design

Windowing and Spectra


Truncated Signal and DFT: Truncated, Windowed Signal and DFT

>> windft
2010 Trity Technologies Sdn Bhd. All Rights Reserved

wider main lobe lower side lobes


6-14

FIR Filter Design

Window Visualization Tool


>> wvtool(kaiser(32,1),kaiser(32,5),kaiser(32,10))

2010 Trity Technologies Sdn Bhd. All Rights Reserved

6-15

FIR Filter Design

Window Design and Analysis Tool


>> wintool

2010 Trity Technologies Sdn Bhd. All Rights Reserved

6-16

FIR Filter Design

Example: Lowpass Filter


1 h( n ) 2

H ( )e

jn

1 d 2

0
0

e jn d

0 sinc( 0 n)

>> b = ... 0.4*sinc(... 0.4*(-25:25)); >> fvtool(b,1) >> bw = ... b.*hamming(51)'; >> fvtool(bw,1) Right click on the y-axis label in FVTool and choose Magnitude squared
2010 Trity Technologies Sdn Bhd. All Rights Reserved

6-17

FIR Filter Design

Standard Band FIR Design


>> b = fir1(n,Wn,'stop',kaiser(n+1,beta));

2010 Trity Technologies Sdn Bhd. All Rights Reserved

6-18

FIR Filter Design

Arbitrary Response FIR Filters


>> b = fir2(n,f,m,window);

2010 Trity Technologies Sdn Bhd. All Rights Reserved

6-19

FIR Filter Design

Multiband Filters
>> b = firls(n,f,a)

2010 Trity Technologies Sdn Bhd. All Rights Reserved

6-20

FIR Filter Design

Raised Cosine Filters


>> b = firrcos(n,F0,df,fs);

2010 Trity Technologies Sdn Bhd. All Rights Reserved

6-21

FIR Filter Design

Frequency Domain Filtering


finite buffer
b Overlap-add method (fftfilt): Partion x(n) into data blocks FFT to the frequency domain Convolve blocks efficiently with b using multiplication IFFT back to the time domain Assemble shifted partial convolutions using superposition
2010 Trity Technologies Sdn Bhd. All Rights Reserved

long x(n)

y(n)

6-22

FIR Filter Design

Section Summary

I

FIR design methods Windowing Standard band filters Arbitrary response filters Multiband filters Raised cosine filters Frequency domain filtering
II III IV

2010 Trity Technologies Sdn Bhd. All Rights Reserved

6-23