Вы находитесь на странице: 1из 16

FILTER DESIGN

Design of a Bandpass FIR Filter

Jayaweera A.A.L. 140270M

This is submitted as a partial fulfillment for the module


EN2570: Digital Signal Processing
Department of Electronic and Telecommunication Engineering
University of Moratuwa

28th of December 2016


Design of a Bandpass Finite Impulse Response (FIR) Filter

Ashira Jayaweera
Undergraduate, Department of Electronics and Telecommunication Engineering
University of Moratuwa
Katubedda, Sri Lanka

Abstract

Noise and interferences are major issues in digital signal processing (DSP)
applications because they affect the accuracy and reliability of the information carried
by a signal. Therefore filtering noise and interferences is a major operation in DSP. As a
result designing a digital filter having good performance is a demanding one. The design
procedure of a finite extent impulse response (FIR) filter satisfying all the required
conditions using the windowing method in conjunction with the Kaiser window is
discussed in this application report. Matlab is used as the software tool implementing
the filter.

Keywords – FIR Filter; bandpass filter; Matlab; Kaiser Window; passband; stopband

Introduction

A fundamental aspect of DSP is filtering which means allowing a particular set of


signals to pass through the filter according to the frequency and blocking other signals.
However practical filters suppress certain frequencies up to a desirable limit relative to
other frequencies. A digital filter performs mathematical operations on a discrete-time
signal to boost or suppress certain frequencies of that signal. Causality, stability and less
amplitude and delay distortion are features of a desirable filter. There are two types of
digital filters
1. Infinite extent Impulse Response (IIR) filters
2. Finite extent Impulse Response (FIR) filters.

Here digital filters are categorized according to the length of their impulse
responses. The output of an IIR filter depends not only on present and past inputs but
also past outputs. FIR filter generates output only from present and past inputs. FIR
filter has more advantages over an IIR filter such as,
 FIR digital filters have an exactly linear phase
 FIR filter is always stable
 Can be realized using a non-recursive structure
 Can achieve arbitrary prescribed amplitude and frequency responses
 Design and simulation can be achieved easily and efficiently using a software tool
like Matlab
 Since it can be designed using closed form method less computations involved
When designing an FIR filter using the closed form method, transfer function of
the filter in z domain should be obtained. Window method and weighted-Chebyshev
method are two methods to find out the transfer function of a nonrecursive FIR filter. In
this report window method is considered. A good window function should have lesser
Gibb’s oscillations and a narrow main lobe width in its spectrum in order to achieve
given specifications of the filter using less resources. Such window functions are listed
below.
 Rectangular window
 Von-Hann window
 Hamming window
 Blackman window
 Dolph-Chebyshev window
 Kaiser window
Among these windows Kaiser Window is more specific because it can be
adjusted in order to meet the given specifications. The design procedure of an FIR
bandpass filter for the following specifications is described in this report.
Specifications
Specifications are defined according to the index number 140270M
 Maximum pass band ripple, Ã𝑝 = 0.12 dB
 Minimum stop band attenuation, Ã𝑎 = 57 dB
 Lower pass band edge, 𝜔𝑝1 = 300 rad/s
 Upper pass band edge, 𝜔𝑝2 = 600 rad/s
 Lower stop band edge, 𝜔𝑎1 = 200 rad/s
 Upper stop band edge, 𝜔𝑎1 = 750 rad/s
 Sampling frequency, 𝜔𝑠 = 2000 rad/s

Figure 01- Parameters of a bandpass filter

Basic Theory [1]

The design procedure of a non-recursive bandpass FIR filter for prescribed


specifications is described below.

Step 01
Determine the impulse response ℎ(𝑛𝑇) using the Fourier series assuming an idealized
frequency response
1 𝑓𝑜𝑟 − 𝜔𝑐2 ≤ 𝜔 ≤ −𝜔𝑐1
𝑗𝜔𝑡
𝐻(𝑒 ) = {1 𝑓𝑜𝑟 𝜔𝑐2 ≤ 𝜔 ≤ 𝜔𝑐1
0 𝑂𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
This is given by,
2
(𝜔 − 𝜔𝑐2 ) 𝑓𝑜𝑟 𝑛 = 0
𝜔𝑠 𝑐1
ℎ(𝑛𝑇) = 1
(sin 𝜔𝑐2 𝑛𝑇 − sin 𝜔𝑐1 𝑛𝑇) 𝑂𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
𝑛𝜋
{

Where the more critical transition width,

𝐵𝑡 = min[(𝜔𝑝1 − 𝜔𝑎1 ), (𝜔𝑎2 − 𝜔𝑝2 )]

and the cut off frequencies,


𝐵𝑡 𝐵𝑡
𝜔𝑐1 = 𝜔𝑝1 – , 𝜔𝑐2 = 𝜔𝑝2 +
2 2

Step 02
Choose δ such that the actual passband ripple,𝐴𝑝 is equal to or less than specified
passband ripple Ã𝑝 , and the actual minimum stopband attenuation,𝐴𝑎 is equal or
greater than the specified minimum stopband attenuation, Ã𝑎
A suitable value is
𝛿 = min(𝛿𝑝 , 𝛿𝑎 )

10𝑜.𝑜5Ã𝑝 − 1
Where 𝛿𝑝 = and 𝛿𝑎 = 10−𝑜.𝑜5Ã𝑎
10𝑜.𝑜5Ã𝑝 + 1

Step 03
With the required δ defined, the actual stopband attenuation 𝐴𝑎 can be calculated as
𝐴𝑎 = −20 log(𝛿)

Step 04
Choose parameter α as
0 𝑓𝑜𝑟 𝐴𝑎 ≤ 21
0.4
𝛼 = { 0.5842(𝐴𝑎 − 21) + 0.07886(𝐴𝑎 − 21) 𝑓𝑜𝑟 21 < 𝐴𝑎 ≤ 50
0.07886(𝐴𝑎 − 8.7) 𝑓𝑜𝑟 𝐴𝑎 > 50
Step 05
Choose parameter D as
0.9222 𝑓𝑜𝑟 𝐴𝑎 ≤ 21
𝐷 = { 𝐴𝑎 − 7.95 𝑓𝑜𝑟𝐴𝑎 > 21
14.36

Then select the lowest odd value of N that would satisfy the inequality
ωs D
N≥ + 1 where 𝐵𝑡 = 𝜔𝑎 − 𝜔𝑝
Bt

Step 06
Form 𝑤𝑘 (𝑛𝑇) using the following equations:

𝐼0 (𝛽)
𝑓𝑜𝑟 |𝑛| ≤ (𝑁 − 1)/2
𝑤𝑘 (𝑛𝑇) = { 𝐼0 (𝛼)
0 𝑂𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑒
Where
2 2
2𝑛 1 𝑥 𝑘
𝛽 = 𝛼 √1 − (𝑁−1) , 𝐼0 (𝑥) = 1 + ∑∞
𝑘=1 [𝑘! (2) ]

Step 07
Form the transfer function of the FIR filter by,

𝐻 ′ 𝑤 (𝑧) = 𝑧 −(𝑁−1)/2 𝐻𝑤 (𝑧) 𝑤ℎ𝑒𝑟𝑒 𝐻𝑤 (𝑧) = Ƶ[𝑤𝑘 (𝑛𝑇)h(nT)]

Step 08
Finally the operation of the filter can be checked by finding the output of the below
signal in the frequency domain when sent through the filter by multiplying frequency
response of input signal and the filter.
3

𝑥(𝑛𝑇) = ∑ sin(𝜔𝑖 𝑛𝑇)


𝑖=1

Where ω1 is the middle frequency of the lower stopband, ω2is middle frequency of the
passband and ω3 is middle frequency of the upper stopband.
Results

Obtained important parameters of the FIR filter are as follows,


 Lower cutoff frequency, ωc1 = 250 rads-1
 Upper cutoff frequency, ωc2 = 650 rads-1
 Alpha α = 5.32266
 Length of the impulse response N = 73
 Passband ripple Ap = 0.0245dB
 Stopband attenuation Aa = 57dB

The generated Kaiser Window function after completing step 06, which is displayed in
Figure 02.

Figure 02- Kaiser Window function


Multiplying the impulse response of the ideal bandpass filter with the Kaiser Window
function Impulse Response of the FIR filter is generated, which is shown in Figure 03.

Figure 03 – Impulse response of the FIR filter

Magnitude response of the FIR filter within the whole analog frequency band and
passband is shown in Figure 04 and Figure 05 respectively.

Figure 04 – Magnitude response of the filter


Figure 05 – Magnitude response in the passband

Results from the step 08 are shown below. Figure 06 shows the time domain
representations of input signal to the filter, output from the filter and expected output
for the input signal from the ideal filter. The corresponding frequency responses are
shown in Figure 07.

Figure 06 – Time domain representations of signals


Figure 07 – Frequency domain representations of signals

Discussion

According to the specifications the lower transition band is from 200 to 300
rad/s and the upper transition band is from 600 to 750 rad/s. The critical transition is
at lower edge. Filter has been designed to satisfy both the conditions and hence
specifications are over satisfied at the upper edge. Therefore the cutoff frequencies have
been obtained accordingly.
Figure 01 shows the impulse response of the filter with a length (N) of 73
samples. However the initially calculated value for N is 71 in which case the designed
filter does not satisfy the prescribed specifications for attenuation in the lower
stopband. Therefore N is incremented by 2 in order to meet the specifications. Thus the
stopband characteristics have become more critical and eventually filter has over
satisfied the limitations for passband ripple.
Figure 05 is the time domain comparison of the input excitation and the
output signal which is given by the filter. There is also the output, if an ideal band pass
filter was used. The output of the filter is generated by taking the Discrete Fourier
Transform (DFT) of input signals using the fft() tool in Matlab. In this case lengths of
input signals and number of points in DFT are chosen according to following condition
in order to ensure that there is no time aliasing happens.
𝑁+𝑃−1≤𝐿
Where,
N = Length of the impulse response
P = Length of input signal
L = No. of points in DFT
A careful observation of the outputs of designed FIR filter and ideal filter
concludes that the two outputs are identical except the following two factors.
1. Output of the designed filter has initially appeared after few samples
This is because transient response of the filter. It will take little number of
samples to generate steady state response.

2. There is a delay between designed and ideal filter outputs


By observing the outputs it can be noticed that the output from the
designed filter has delayed the ideal output by 36 samples. This is the group
delay of the FIR filter which should have been expected and can be obtained
by (𝑁 − 1)/2 .

Figure 06 shows the frequency domain representations of the input signal,


output from designed and the ideal filters. It can be clearly noticed that the signals
which have frequencies in the stopbands have suppressed by the filter and only one
signal which have frequency of 450 rad/s which is in the passband has passed through
the filter.

Conclusions

From the analysis of results it can be concluded that the obtained bandpass
FIR filter has achieved the prescribed specifications and key desired feature of linear
phase response. In addition Kaiser Window can be used to design an FIR filter with
arbitrary prescribed specifications.

References

[1] Andreas Antoniou. (2010, October 28). Chapter 9 Design of Nonrecursive (FIR)
Filters [Online]. Available: http://www.d-filter.ece.uvic.ca/SupMaterials/Slides/DSP-
Ch09-S3,4.pdf
Appendix

1. Matlab code for the FIR bandpass filter

% FIR filter design


% A.A.L.Jayaweera
% 140270M

close all;
clear;
clc;

% FIR filter design specifications


Ap_ = 0.12; % mamimum passband ripple
Aa_ = 57; % minimum stopband attenuation
wp1 = 300; % lower passband edge
wp2 = 600; % upper passband edge
wa1 = 200; % lower stopband edge
wa2 = 750; % upper stopband edge
ws = 2000; % sampling frequency

% calculating cutoff frequencies


Bt = min((wa2 - wp2), (wp1 - wa1)); % transition band
wc1 = wp1 - Bt/2 ; % lower cutoff frequency
wc2 = wp2 + Bt/2 ; % upper cutoff frequency

% Calculating delta
deltaP = ( 10^(0.05*Ap_) - 1 ) / ( 10^(0.05*Ap_) + 1 );
deltaA = 10 ^ (-0.05*Aa_);
delta = min (deltaP , deltaA);

% Actual values for Aa and Ap


newAp = 20*log10((delta+1)/(1-delta));
newAa = -20*log10(delta);

% Calculating alpha and D


if newAa <= 21
alpha = 0;
D = 0.9222;
elseif 21 < newAa && newAa <= 50
alpha = 0.5842 * (newAa - 21)^0.4 + 0.07886 * (newAa - 21);
D = (Aa_ - 7.95)/14.36;
else
alpha = 0.1102 * (newAa - 8.7);
D = (Aa_ - 7.95)/14.36;
end

% calculating N
N = ceil(ws*D/Bt + 1);
if (mod(N,2) == 0)
N = N+1;
end

% Sampling period
T = 2*pi/ws;
% Gerating the impulse response and frequency response of the filter
% Iteratively check whether the frequency response meets the specifications
while 1
% Impulse response of idealized filter
hnT = zeros(1,N);
for i = -(N-1)/2 : (N-1)/2
if i==0
hnT(1,i+(N+1)/2) = 2*(wc2-wc1)/ws ;
else
hnT(1,i+(N+1)/2) = ( sin(wc2*T*i) - sin(wc1*T*i) )/( i*pi);
end
end

% Window function
n=0:(N-1)/2;
beta = alpha * sqrt(1-(2*n/(N-1)).^2);
bessel_0Alpha = bessel_0(alpha);
bessel_0Beta = bessel_0(beta);
wnT = bessel_0Beta / bessel_0Alpha;
leftHalf = fliplr(wnT);
wnT = [leftHalf(1:(N-1)/2) wnT];

% Impulse response and frequency response of the filter


hnT = wnT.*hnT;
[hejw,frequency] = freqz(hnT);
frequency = frequency/T;
gain = 20*log10(abs(hejw));

% Diffrent ranges in the frequency spectrum of the filter


range1 = size(find(frequency<=200));
range2 = size(find(frequency<300)) ;
range3 = size(find(frequency<=600)) ;
range4 = size(find(frequency<750)) ;

% Checking whether the specifications are satisfied


if (max(gain(1:range1(1)))>-57) || (max(gain(range2(1)+1:range3(1)))-
min(gain(range2(1)+1:range3(1))) > 0.12) || (max(gain(range4(1)+1:512))>-57)
N = N+2;
else
break
end

end

fprintf('\nValue for N is ');


fprintf('%i\n',N);

% Filter plots
% magnitude response of the filter
figure;
plot(frequency,gain);
grid on;
title('Magnitude response');
xlabel('Frequency (rad/s)');
ylabel('Gain (dB)');
axis([0 ws/2 -100 10])
% magnitude response of the filter in passband
figure;
plot(frequency,gain);
grid on;
title('Magnitude response in passband');
xlabel('Frequency (rad/s)');
ylabel('Gain (dB)');
axis([wp1 wp2 -0.03 0.03])

% magnitude response of the filter in lower stopband


figure;
plot(frequency,gain);
grid on;
title('Magnitude response in lower stopband');
xlabel('Frequency (rad/s)');
ylabel('Gain (dB)');
axis([0 wa1 -100 -Aa_])

% magnitude response of the filter in upper stopband


figure;
plot(frequency,gain);
grid on;
title('Magnitude response in upper stopband');
xlabel('Frequency (rad/s)');
ylabel('Gain (dB)');
axis([wa2 ws/2 -100 -Aa_])

i = 0 : N-1 ;

% Impulse response of the filter


figure;
stem(i,hnT)
title('windowed Impulse response')
grid on
xlabel('n');
ylabel('h(nT)');
axis([0 N-1 -0.3 0.4])

% Window function
figure;
stem(i,wnT)
title('Window function')
grid on
xlabel('n');
ylabel('w(nT)');
axis([0 N-1 0 1])

% Checking the operation of the filter


xn = @(n)(sin(wa1*T*n/2)+sin((wp1+wp2)*T*n/2)+sin((wa2+ws/2)*T*n/2));
n = 1:1025-N;
xnT = xn(n);
Xk = fft(xnT,1024);
Hk = fft(hnT,1024);
Yk = Xk.*Hk;
ynT = ifft(Yk);
k=1:1024;
y0nT = sin((wp1+wp2)*T*k/2);

% Frequency domain representation


figure;
k_ = k/1024*ws - ws/2;

% Input signal
Xk = fftshift(Xk);
subplot(3,1,1)
plot(k_,abs(Xk));
title('Input signal - X[k]')
xlabel('Frequency (rad/s)');
ylabel('Magnitude');
axis([-ws/2 ws/2 0 500])

% Output signal
Yk = fftshift(Yk);
subplot(3,1,2)
plot(k_,abs(Yk));
title('Output signal - Y[k]')
xlabel('Frequency (rad/s)');
ylabel('Magnitude');
axis([-ws/2 ws/2 0 500])

% Expected output signal


Y0k = fft(y0nT,1024);
Y0k = fftshift(Y0k);
subplot(3,1,3)
plot(k_,abs(Y0k));
title('Expected output signal - Y0[k]')
xlabel('Frequency (rad/s)');
ylabel('Magnitude');
axis([-ws/2 ws/2 0 500])

% Time domain representation


% Input signal
figure;
subplot(3,1,1)
stem(n,xnT);
axis([1 200 -3 3]);
title('Input signal - x(nT)');
xlabel('n');
ylabel('Amplitude');

% Output signal
subplot(3,1,2)
stem(k,ynT);
axis([1 200 -1.5 1.5]);
title('Output signal - y(nT)');
xlabel('n');
ylabel('Amplitude');

% Expected output signal


subplot(3,1,3)
stem(k,y0nT);
axis([1 200 -1.5 1.5]);
title('Expected output signal - y0(nT)');
xlabel('n');
ylabel('Amplitude');

fvtool(hnT);

2. Code for the 0th order Bessel function used in Kaiser Window calculations

function [ value ] = bessel_0( x )


k=1;
value = 1;
temp = (((x/2).^k)/factorial(k)).^2;
value = value + temp;
while max(temp) >= 10e-6
k = k+1;
temp = (((x/2).^k)/factorial(k)).^2;
value = value + temp;
end
end