Professional Documents
Culture Documents
Linear Phase Finite Impulse Response
Linear Phase Finite Impulse Response
OBJECTIVES
Design the Linear Phase Finite Impulse Response (FIR) Filter and a lowpass filter and
bandpass filter through Window Design Technique of FIR.
2.
3.
COMPONENTS
Dekstop PC
THEORIES
3.1. LINEAR PHASE FIR FILTER
Among all the obvious advantages that digital filters offer, the FIR filter can guarantee
linear phase characteristics. There are many commercially available software packages
for filter design. However, without basic theoretical knowledge of the FIR filter, it will be
difficult to use them.
Filter coefficients:
Filter structure
A causal FIR filter whose impulse response is symmetrical is guaranteed to have a
linear phase response. (Even symmetry & Odd symmetry)
To fully
design
Filter specification.
(2)
Coefficient calculation.
(3)
Structure selection.
(4)
Simulation (optional).
(5)
Implementation.
There are several different methods available, the most popular are:
Window method.
Frequency sampling.
Parks-McClellan.
We will just consider the window method.
Linear phase is a one type of a filter. Filter need to modify a signal's magnitudespectrum
linear
There are four possible situation: filter length even or odd, and impulse response is
either
symmetric or antisymmetric :
FIGURE 2.0
3.2. FIR I AND FIR II TYPE
The symmetric coefficients shown that the frequency responses are of the
following form:
FIR I (M is even, sequence is symmetric and of odd length)
However, this system has linear phase (the quantity inside the parenthesis is a real
quantity) and the phase delay is M/2 samples.
Note
that this of
the
form
FIR
IV (M is
odd, the
sequence is antisymmetric and of even length)
In
both
cases, the phase response is of the form ()=-(M/2) + /2, hence generalized
linear phase. Again, in all of theses cases, the filter output is delayed by M/2 samples.
Also, for all cases, if G()<0, an additional term is added to the phase, which causes
the samples to be flipped.
The symmetric coefficients shown that the frequency responses are of the
following form:
FIR I (M is even, sequence is symmetric and of odd length)
However, this system has linear phase (the quantity inside the parenthesis is a real
quantity) and the phase delay is M/2 samples.
FIR II (M is odd, the sequence is symmetric and of even length)
Note
that this of
the
form
However, this system has linear phase (the quantity inside the parenthesis is a real
quantity) and the phase delay is M/2 samples.
FIR II (M is odd, the sequence is symmetric and of even length)
Note
that this of
the
form
However, this system has linear phase (the quantity inside the parenthesis is a real
quantity) and the phase delay is M/2 samples.
FIR II (M is odd, the sequence is symmetric and of even length)
Note
that this of
the
form
4.
PROCEDURES
5.
RESULTS
Part A
Properties of Linear-Phase Finite Impulse Response (FIR) Filters.
Type-1 FIR Filters
MATLAB script:
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';
1 -1
-2
5 -2
-1
1 -4
-2
-8
>>[Hr,w,a,L] = Hr_Type1(h);
>>a,L
a =
6
10
-4
L =
5
>>amax = max(a)+1; amin = min(a)-1;
>>subplot(2,2,1); stem(n,h); axis([-1 2*L+1 amin amax])
>>xlabel('n'); ylabel('h(n)'); title('Impulse Response')
7
>>subplot(2,2,3); stem(0:L,a); axis([-1 2*L+1 amin amax])
>>xlabel('n'); ylabel('a(n)'); title('a(n) coefficients')
>>subplot(2,2,2); plot(w/pi,Hr);grid
10
Output Simulation:
Impulse Response
10
h(n)
-5
10
10
a(n) coefficients
10
a(n)
-5
1 -1
-2
5 -2
-1
-4
>>[Hr,w,b,L] = Hr_Type2(h);
>> b,L
b =
12
10
-4
-2
-8
L =
6
>> bmax = max(b)+1; bmin = min(b)-1;
>> subplot(2,2,1); stem(n,h); axis([-1 2*L+1 bmin bmax])
>> xlabel('n'); ylabel('h(n)'); title('Impulse Response')
>> subplot(2,2,3); stem(1:L,b); axis([-1 2*L+1 bmin bmax])
>> xlabel('n'); ylabel('b(n)'); title('b(n) coefficients')
>> subplot(2,2,2); plot(w/pi,Hr);grid
>> xlabel('frequency in pi units'); ylabel('Hr')
>> title('Type-1 Amplitude Response')
>> subplot(2,2,4);
>> [Z,P,K]=tf2zp(1,b);
>> zplane(Z,P)
10
10
11
Output Simulation:
Impulse Response
10
h(n)
-5
6
n
10
12
10
12
b(n) coefficients
10
b(n)
-5
11
6
n
>> h = [-4 1 -1 -2 5 0 -5 2 1 -1 4]
h=
-4
1 -1
-2
-5
-1
-2
-8
>>[Hr,w,c,L] = Hr_Type3(h);
>> c,L
c =
0
10
-4
L =
5
10
Output Simulation:
Impulse Response
25
10
20
15
10
Hr
h(n)
5
0
-5
-5
0
-10
10
0.1
0.2
0.3
0.4
0.5
0.6
frequency in pi units
0.7
0.8
0.5
Imaginary Part
c(n)
c(n) coefficients
10
-0.5
-5
-1
0
10
-1
13
-0.5
0
Real Part
0.5
0.9
>> h = [-4 1 -1 -2 5 6 -6 -5 2 1 -1 4]
h=
-4
-1 -2
6 -6
-5
-1
>>[Hr,w,d,L] = Hr_Type4(h);
>> d,L
d =
12
10
-4
-2
-8
L =
6
>> dmax = max(d)+1; dmin = min(d)-1;
>> subplot(2,2,1); stem(n,h); axis([-1 2*L+1 dmin dmax])
>> xlabel('n'); ylabel('h(n)'); title('Impulse Response')
>> subplot(2,2,3); stem(1:L,d); axis([-1 2*L+1 dmin dmax])
>> xlabel('n'); ylabel('d(n)'); title('d(n) coefficients')
>> subplot(2,2,2); plot(w/pi,Hr);grid
>> xlabel('frequency in pi units'); ylabel('Hr')
>> title('Type-1 Amplitude Response')
>> subplot(2,2,4);
>> [Z,P,K]=tf2zp(1,d);
14
>> zplane(Z,P)
10
11
Impulse Response
10
h(n)
-5
6
n
10
12
10
12
Output Simulation:
d(n) coefficients
10
d(n)
-5
4
15
6
n
Part B
Designing the Finite Impulse Filter (FIR) using Window Techniques.
MATLAB script:
1.
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 avoid divided by zero
hd = sin(wc*m)./(pi*m);
2.
16
3.
17
hd(n)
0.2
0.1
0
-0.1
-0.2
-0.3
-0.4
10
20
30
40
50
60
70
60
70
0.4
0.3
h(n)
0.2
0.1
0
-0.1
-0.2
-0.3
-0.4
10
20
30
18
40
50
12
13
14
15
10
11
Columns 17 through 21
16
17
18
19
20
hd(n)
0.5
0
-0.5
-1
0
10
n
12
14
16
18
20
16
18
20
h(n)
Output Simulation:
0
-0.5
-1
0
6
20
10
n
12
14
6.
DISCUSSIONS
6.1. PART 1 (TYPE 1 - TYPE 4 LINEAR FIR FILTER)
6.1.1.
MATLAB COMMANDS
In order to get the wanted output, some Matlab command which corresponding the FIR equation
are entered into Matlab to be processed. There are including some constants and variables.
Below are constants which been used in Part 1 demonstrations:
L is order of Hr. L is written as, L = (M-1)/2.
w is frequencies between [0, pi] over which Hr is computed. w is w = [0:1:500] *pi/500.
n written as n = [0:1:L]
21
6.1.2
OUTPUT GRAPHS
From graph generated by Matlab, there are no restrictions on Hr(w) either w=0 or w=pi. System
poles
shows that there are three (3) poles on the right of real part, one x plane while the other
two symmetrically near y plane. On the negative side of real part, there are two more
on the x-plane.
Since poles present on the positive side of real part, system is not stable.
poles
We
Type-3.
6.2. PART 2
For the second part of the lab, we were asked to construct a digital bandpass FIR filter using the
22
following specifications;
lowerstopband
edge:
1s 0.2
As 60dB
lowerpassband
edge:
1p 0.35
Rp 1dB
upperpassband
edge:
2p 0.65
Rp 1dB
upperstopband
edge:
2s 0.8
As 60dB
Below is the image of the digital bandpass filter that must be produced. Notice that the highlighted
ones are the selected bandpass filter based on the requirements given above.
must be the same in the window design (there is no independent control over and . For
1 2
Blackman window design uses the same function of Hann window and Hamming window, except it
contains a second harmonic term given as follows;
23
2n
4n
0.42 0.5cos
0.08cos
n
M 1
M 1
24
;0 n M 1
;otherwise
We also need the ideal bandpass filter hd n impulse response function, . Therefore, the
MATLAB
bandpass filter.
magnitude response in absolute as well as in relative dB scale, the phase response and
response.
Based on the requirements given, using the command window of MATLAB, the following string of
code are entered so that it declare the position or the exact bandwidth of the bandpass filter:
Window
Name
Rectangular
Bartlett
Hanning
Hamming
Blackman
Transition
Approximate
4
M
8
M
8
M
8
M
12
M
Width,
Exact Values
1.8
M
6.1
M
6.2
M
6.6
M
11
M
Min. Stopband
Attenuation
21 dB
25 dB
44 dB
53 dB
74 dB
Next, find the value of filter length, M for the transitional width, (this is decided from the
summary table given above using the exact values),
M = ceil(11*pi/tr_width) +1
25
which returns the following results from the MATLAB output command;
M =
75
Next, entered the center frequency of the bandpass filter given as follows;
n = [0:1:M-1];
wc1 = (ws1+wp1)/2; wc2 = (wp2+ws2)/2;
Then, we entered the ideal bandpass filter function. Since there are two different center frequency, the
value of hd is calculated as follows;
hd = ideal_lp(wc2,M) - ideal_lp(wc1,M);
The values of hd will stored the attached value of number of pulses, n given above.
Next, run the Blackman window as blackman(M) and multiplied with the given hd, and stored in
h.
w_bla = (blackman(M))';
h = hd.*w_bla;
The function of freqz_m is used in this time with the stored value of the previous h.
[db,mag,pha,grd,w] = freqz_m(h,[1]);
is given by the default formula as ;
2
1000
delta_w =2*pi/1000;
26
Then, finally we obtained the actual bandpass ripple, Rp and minimum stopband attenuation, As. These
are given by the formula as follows;
Rp 20log10
1 1
0
1 1
As 20log10
2
0
1 1
Rp = -min(db(wp1/delta_w+1:1:wp2/delta_w))
As = -round(max(db(ws2/delta_w+1:1:501)))
As =
75
Then, to construct the following output simulation, the following string code of MATLAB command
is inputted as follows;
27
HAMMING WINDOW
Hr is amplitude response, equation used is, Hr = sin (w*n)*c. Where,
L is order of Hr. L is written as, L = (M-1)/2 and M = length (h).
w is frequencies between [0, pi] over which Hr is computed. w is w = [0:1:500]
*pi/500.
n written as n = [0:1:L]
c is type-3 low pass filter coefficients. c = [2*h(L+1:-1:1]
Frequency response of Hamming Window is sinusoidal in shape. This because it defines by w(n) =
0.54 - 0.46 cos (2pin/N). For n = 1, 2, ..., N - 1. In time domain, the Hamming window does not get as
close to zero near the edges.
7.
CONCLUSIONS
FIR filters is useful filter used in digital application due to some of its advantages. To
analyze this filter, we can use Matlab to analyze it.
To design FIR filter, user need to know the filter specification to be simulated. Then to
know the coefficient calculation followed by structure selection. Simulation that have
28
been done in this laboratory can be considered as important step. In this laboratory, the
signal have been designed by using Matlab. Finally is the implementation of the signal.
There are four type of FIR as been discussed in result part and discussion. Type 1,
symmetric sequence of odd length, Type 2, symmetric sequence of even length, Type 3,
anti-symmetric sequence of odd length and Type 4,anti-symmetric sequence of even
length.
With Matlab also we can construct bandpass filter, in this lab two windows model have
been used, Blackman and Hammings. There are other windows model can be used
although not demonstrated and discussed in this lab. There are Rectangular, Bartlett
and
Hanning windows. All with their special characteristics can be used in certain
8.
REFERRENCES
Vinay K. I. and John J. P., Digital Signal Processing Using Matlab (3 rd ed.), Cengage
Learning, US
J. W. Cooley and J. W. Tukey. An algorithm for the machine computation of
complex
29
30