Академический Документы
Профессиональный Документы
Культура Документы
Activity No. 7
FIR Filter Design
I. OBJECTIVES
A finite impulse response (FIR) filter is a digital filter with impulse response h[n] that is a
finite sequence of numbers. FIR filters are always stable and generally designed to have a linear
phase response. The design of FIR filters is typically based on selecting a symmetric impulse
response h[n] whose length is determined to meet filter specifications. The most common design is
the windowed-sinc design. This design starts by determining the impulse response h[n] of an ideal
digital filter and then truncating the impulse response by an appropriate window.
Consider an ideal digital lowpass filter with cut-off frequency fc, in Hz, to be used at a
sampling frequency Fs. The frequency response H(Ω) is shown for one period as
where Ωc=2πfc/Fs. The impulse response h[n] that corresponds to this ideal lowpass frequency
response can be obtained by getting the Inverse Discrete Time Fourier Transform (IDTFT) of
H(Ω).
π Ωc
-π -Ωc
SLU ECE 1
ECE 515 FL
Digital Signal Processing Laboratory Activity 7: FIR Filter Design
The impulse response h[n] of the ideal lowpass filter is a sinc function.The sinc function is
a sequence that is real-valued, even symmetric, and infinite in duration. The symmetry of the sinc
function ensures that the phase response is linear. To realize a practical digital filter, the impulse
response h[n] of the ideal lowpass filter is truncated symmetrically about n=0 to maintain its linear
phase response. The filter is then made causal by shifting the truncated h[n] such that the first
element of h[n] is at n=0. The choice for the truncated length N of h[n] depends on the filter
specifications to be satisfied. It is generally selected that N is odd to allow easy transformation of
the lowpass filter to the other basic filter types such as highpass, bandpass, and bandstop filters.
SLU ECE 2
ECE 515 FL
Digital Signal Processing Laboratory Activity 7: FIR Filter Design
The magnitude response specifications are measured on a normalized magnitude response with the
peak passband gain made equal to 1. To normalize the magnitude response, the impulse response
h[n] is divided by the peak passband gain of the filter.
//Evaluate the normalized H(Ω) and plot themagnitude response and phase response
HW=zeros(W);
for n=1:length(hn)
HW=HW + hn(n)*exp(-%i*W*(n-1));
end;
clf;subplot(2,1,1); plot2d(f,abs(HW)); xgrid();
subplot(2,1,2); plot2d(f,atan(imag(HW),real(HW))*180/%pi); xgrid();
SLU ECE 3
ECE 515 FL
Digital Signal Processing Laboratory Activity 7: FIR Filter Design
The truncation of h[n] results to an approximation of the frequency response of the ideal
filter. Truncation causes overshoots and ripples in the passband and in the stopband, creates a
transition band between the passband and the stopband, and a non-zero gain in the stopband. The
gain specifications may also be specified in decibel (dB) values using the conversion
AdB=20log10A. The peak passband gain is thus normalized as 0dB. For the 31-point FIR filter in
example 1, the filter specifications are Ap=0.851(-1.4dB), As=0.0736 (-22.7dB), fp=875Hz, and
fs=1118Hz. It should be noted that the cut-off frequency used in the design is approximately at
the middle of fp and fs such that fc=0.5(fp+fs).
To reduce or eliminate the overshoots and ripples in the magnitude response, the impulse
response of the ideal filter is truncated using a tapered symmetric window w[n]. The window
w[n] is multiplied point-wise with windowed-sinc impulse response. The most common windows
are the boxcar or rectangular window, Bartlett or triangular window, Hanning or raised cosine
window, Hamming window, and Blackman window.
Boxcar: w[n] = 1, for -(N-1)/2 to (N-1)/2
Bartlett: w[n] = 1- (2|n| / (N-1)), for -(N-1)/2 to (N-1)/2
Hanning: w[n] = 0.5 + 0.5cos(2πn/(N-1)), for -(N-1)/2 to (N-1)/2
Hamming: w[n] = 0.54 + 0.46cos(2πn/(N-1)), for -(N-1)/2 to (N-1)/2
Blackman: w[n] = 0.42 + 0.5cos(2πn/(N-1)) + 0.08cos(4πn/(N-1)), for -(N-1)/2 to (N-1)/2
SLU ECE 4
ECE 515 FL
Digital Signal Processing Laboratory Activity 7: FIR Filter Design
Most windows have been developed with an optimality consideration which could be
decreasing the ripples in the passband, decreasing the stopband gain, or reducing the transition
width. Ultimately, the choice of window is based on which will result to the shortest filter length
to satisfy filter requirements.
Example 2:
A lowpass FIR filter is designed using windowed-sinc with a Hanning window. The filter
has a cut-off frequency fc=1000Hz at a sampling frequency of Fs=8000Hz. The filter length is
N=31. Use the program in example1 but the command line for the computation of the impulse
response is replaced by hn=(Wc/%pi)*sinc(Wc*n).* (0.5 + 0.5*cos(2*%pi*n/(N-1)));
The passband gain is approximately uniform and the stopband gain approaches zero. It is
noted that the primary consideration for the Hanning window are improvements in gain
characteristics but these improvements are realized at the expense of a wider transition band.
Example 3:
A lowpass FIR filter is to be designed using windowed-sinc with a Bartlett window. The
design requirements are Ap=0.95, As=0.05, fp=1000Hz, and fs=1200Hz. The sampling frequency
is Fs=8000Hz. Determine the minimum filter length N that satisfies the given specifications.
The given filter requirements require that the gain for frequencies 1000Hz and below
should not be less than 0.95 and the gain for frequencies 1200Hz and above should not be more
than 0.05. The design starts with computing the cut-off frequency to be used for the windowed-
sinc. The cutoff frequency to be used is middle frequency between fp and fs such that
fc=0.5(fp+fs)=1100Hz. The equivalent digital frequency Ωc is then computed. An initial filter
length N is chosen, say N=11, and the impulse response h[n] is computed using the SCILAB
command line hn=(Wc/%pi)*sinc(Wc*n).* (1-2*abs(n)/(N-1));
The magnitude response is plotted and the actual filter specifications are determined. The
length N is adjusted until the minimum N that satisfies the design specifications is determined.
With N=11, the actual filter specifications are Ap=0.68 which is very much lower than the
minimum passband gain of 0.95 and As=0.46 which is very much higher than the maximum
stopband gain of 0.05.
SLU ECE 5
ECE 515 FL
Digital Signal Processing Laboratory Activity 7: FIR Filter Design
With N=127, Ap=0.955 satisfies the passband gain requirement but As=0.051 which does
not satisfy the stopband gain requirement. By trying different values for N, it is determined that
the minimum filter length is N=131 with actual As=0.04995 and Ap=0.955.
Spectral Transformation
The other basic filter types such as the highpass, bandpass, and bandstop can be designed
by spectral transformation of the frequency response of a lowpass filter. These transformations use
the unit impulse δ[n] whose DTFT is 1, denoted as
DTFT
δ[n] 1
The transformation from lowpass to highpass may be done by (1) inverting the frequency response
of the lowpass filter or (2) by shifting the frequency response of the lowpass filter. Inverting the
frequency response of the lowpass filter is done by a combination of amplitude reversal and
amplitude shifting, illustrated as
Let HLP(Ω) be the frequency response of an ideal digital lowpass filter with cutoff frequency ΩcLP.
Its impulse response is hLP[n]=(ΩcLP/π)sinc(ΩcLP n). The impulse response of the highpass filter is
obtained from the transformation as
HLP(Ω) hLP[n]
-HLP(Ω) -hLP[n]
SLU ECE 6
ECE 515 FL
Digital Signal Processing Laboratory Activity 7: FIR Filter Design
Example 4:
A highpass FIR filter is to be designed using windowed-sinc with a Hamming window.
The lowpass-to-highpass transformation that uses amplitude inversion and shifting is used. The
SLU ECE 7
ECE 515 FL
Digital Signal Processing Laboratory Activity 7: FIR Filter Design
design requirements are Ap=0.95, As=0.05, fs=1000Hz, and fp=1500Hz. The sampling frequency
is Fs=8000Hz. Determine the minimum filter length N that satisfies the given specifications.
SLU ECE 8
ECE 515 FL
Digital Signal Processing Laboratory Activity 7: FIR Filter Design
The filter length N should be adjusted until the minimum length that satisfies the design
requirements is determined.
Example 5:
A highpass FIR filter is to be designed using windowed-sinc with a Hamming window.
The sign flipping lowpass-to-highpass transformation is used. Design requirements are Ap=0.95,
As=0.05, fs=1000Hz, and fp=1500Hz. The sampling frequency is Fs=8000Hz. Determine the
minimum filter length N that satisfies the given specifications.
The design of the highpass filter uses the same SCILAB routine as Example 4 with the
following revisions:
Hence, the impulse response of the ideal bandpass filter is described by the function
SLU ECE 9
ECE 515 FL
Digital Signal Processing Laboratory Activity 7: FIR Filter Design
Example 6:
A bandpass FIR filter is to be designed using windowed-sinc with a Hamming window.
The design requirements are Ap=0.95, As=0.05, fs1=1000Hz, fs2=2500Hz, fp1=1250Hz, and
fp2=2750Hz. The sampling frequency is Fs=8000Hz. Determine the minimum filter length N that
satisfies the given specifications.
The design of the bandpass filter uses the same SCILAB routine as Example 4 except the
computation for the impulse response as
SLU ECE 10
ECE 515 FL
Digital Signal Processing Laboratory Activity 7: FIR Filter Design
Example 6:
A bandstop FIR filter is to be designed using windowed-sinc with a Hamming window.
The design requirements are Ap=0.95, As=0.05, fp1=1000Hz, fp2=2750Hz, fs1=1250Hz, and
fs2=2500Hz. The sampling frequency is Fs=8000Hz. Determine the minimum filter length N that
satisfies the given specifications.
The design of the bandstop filter uses the same SCILAB routine as Example 4 except the
computation for the impulse response as
SLU ECE 11
ECE 515 FL
Digital Signal Processing Laboratory Activity 7: FIR Filter Design
(c) Use the low-pass filter to extract the bass part of sonatina.wav. Save the filtered signal as
sonatina_bass.wav. Normalize the filtered signal before saving.
(d) Design a high-pass filter using a Hamming window with the following filter specifications:
Ap=0.95, As=0.05, fp=250Hz, and fs=200Hz. Use a sampling rate Fs for the filter design that
is the same as the sampling rate of the signal to be filtered.
Determine the filter length N and the actual Ap and As. Ap=_________ As=__________
Plot the magnitude response for 150Hz f 300Hz.
Insert the plot of the magnitude response here
(d) Use the high-pass filter to extract the treble part of sonatina.wav. Save the filtered signal as
sonatina_treble.wav. Normalize the filtered signal before saving.
(e) Save a stereo version of sonatina with the bass part in the left channel and the treble part in
the right channel. Save the stereo version as sonatina_stereo.wav
SLU ECE 12
ECE 515 FL
Digital Signal Processing Laboratory Activity 7: FIR Filter Design
2. Design a band-pass FIR filter with Ap=0.95, As=0.05, fs1=300Hz, fp1=500Hz, fp2=3000Hz,
fs2=3200Hz. Use Hanning window and Fs=44100.
(a) Which window should be used to obtain the lowest filter length? ____________________
What is the minimum filter length? _____
What are the actual Ap and As? Ap = __________ As=__________
Plot the magnitude response for 0Hz f 4KHz.
Insert the plot of the magnitude response here
(b) Load the audio file dinar_16bit_44100Hz_stereo.wav and filter the audio signal. Use the filter
with the minimum length. Filter each channel separately and then save the result as a stereo
signal. Normalize the filtered audio signal and save it as dinar_bp_500Hz_3KHz.wav. Listen
to the original and filtered audio files. Does the filtered audio sound different to the original
audio file? _____
If yes, describe the difference. ___________________________________________________
____________________________________________________________________________
3. Design a 5-band equalizer with filter length of 63 and Hamming window. Let Fs=44100Hz.
Frequency Range Gain
200 Hz and below 0 dB
200-800 Hz -3 dB Note:
800-3200 Hz -6 dB Gain(dB) =20log(Gain)
3200 - 6400 Hz -3 dB Gain= 10^[Gain(dB)/20]
6400 Hz and above 0 dB 6 dB Gain approximately equal to gain of 10
(b) Filter the audio signal in dinar_16bit_44100Hz_stereo.wav and save the filtered signal as
dinar_16bit_44100Hz_stereo_bass_treble_boost.wav.
(c) Listen to the original signal and the filtered signal. Does the filtered signal have a relatively
louder bass and treble sound compared to the original? ______
SLU ECE 13