EE 461 - Section 9a Filter Design Using Windows Method

EE 461 - Section 9a
Filter Design Using Windows
EE 461
Section 9a - Filter Design Using Windows
1
Method
1. Decide on a filter type
2. Specify for the chosen filter type
3. Find the impulse response for least mean squared error in
magnitude response for a filter of length 4. Multiply the impulse response with a window that is
symmetric:
•
EE 461
= −1−
Section 9a - Filter Design Using Windows
2
1
Window Selection
• The purpose of windowing is to reduce the ripple in the pass
band and stop band
• This reduction in ripple comes at the expense of a wider
transition band
• There are several well known windows to choose from
• The correct choice depends on the application
EE 461
Section 9a - Filter Design Using Windows
3
Windowing Explanation
• Windowing can be explained using the multiplication property
of the DTFT:
ଵ ଵ 1
஽்ி் 2
ଵ ௝ఠ ⊛ ଶ ௝ఠ
circular convolution
• Let ℎ be the impulse response for the ideal frequency
response
• Let be the length of this response, is very large but finite
• is either even or odd
• ℎ is either symmetric or anti-symmetric depending on the
choice of EE 461
Section 9a - Filter Design Using Windows
4
2
Windowing Explanation (cont.)
• Next shift ℎ by
←left
or shift ℎ by
−
shift
ூ ௝ఠ = ି௝ఠ
EE 461
−
for , odd
right→
ெିே
ଶ
ேିெ
ଶ
=
for , even
• In either case, we shift
• Thus ℎ = ℎ −
−
to left for , even or , odd
for ܰ and ‫ ܯ‬odd or even
to left
ି௝ఠ
ெିଵ
ଶ
ூ = ି௝ఠ
ேିଵ
ଶ
‫ܪ‬ூ ݁ ௝ఠ
ூ Section 9a - Filter Design Using Windows
5
Windowing Explanation (cont.)
• For Even:
• For Odd:
ℎூ ݊
ℎூ ݊
‫ܯ‬−1
2
point of symmetry
ℎ෡ூ ݊
ܰ−1
2
point of symmetry
‫ܯ‬−1
2
point of symmetry
ℎ෡ூ ݊
ܰ−1
2
point of symmetry
non-causal
EE 461
Section 9a - Filter Design Using Windows
6
3
Windowing Explanation (cont.)
• Let ℎ = ℎ • Then
௝ఠ
Window is always symmetric and length ܰ
• ܰ is even if ‫ ܯ‬is even
• ܰ is odd if ‫ ܯ‬is odd
1
ூ ௝ఏ ௝
=
2
గ
ିగ
గ
1
ି௝ఏ
=
2
ேିଵ
ଶ
ିగ
௝ఠ
ఠିఏ
=
ூ ି௝ ఠିఏ
ேିଵ
ଶ
௪ − గ
ି௝ఠ
ேିଵ
ଶ
1
ூ ௪ − 2
ିగ
Valid for ܰ odd
and for ܰ even
circular convolution
EE 461
Section 9a - Filter Design Using Windows
7
Properties of Window Functions
= 0 for < 0 and ≥ = − 1 − ; symmetric
= − ; even about = 0
+ = − for odd; even about = • Periodic with period 2
• + = − − for even; odd about = • Periodic with period 4
•
•
•
•
1
−1
௪ = ℎ
= 1 forNodd
2
2
గ
ିగ
windows are chosen so that
this integral is 1 or very nearly 1
EE 461
Section 9a - Filter Design Using Windows
8
4
Properties of Window Functions (cont.)
ℎூ non-causal
means it cannot be built
• However, it can be analyzed
and does have a frequency
response:
ூ ௝ఠ = ି௝ఠ
1
0
ℎ
EE 461
• ℎ is non-causal which
−1
ேିଵ
ଶ
ூ ௝ఠ
• ℎ is causal and can be
built
causal
Section 9a - Filter Design Using Windows
9
Properties of Window Functions (cont.)
• For most windows, has the form:
main lobe
• Area under main lobe is usually between 1 × 2 and 1.2 × 2
• Note:
• Width of lobes are proportional to
ଵ
ே
• Height of lobes are proportional to • Area under lobes does not depend on EE 461
Section 9a - Filter Design Using Windows
10
5
Properties of Window Functions (cont.)
• For odd, is even about = :
−2
−
0
2
• For even, is odd about = :
−2
−
EE 461
0
2
Section 9a - Filter Design Using Windows
11
Properties of Window Functions (cont.)
• Window has a symmetric impulse response:
௝ఠ = ି௝ఠ
• ௪ 0 = ௝଴
ேିଵ
ଶ
௪ • If ௪ ஻ = 0 then ௝ఠ = 0
EE 461
Section 9a - Filter Design Using Windows
12
6
Rectangular Window of Length ܰ
௝ఠ = 1 ି௝ఠ௡
ேିଵ
௡ୀ଴
• For = 0, = • For ≠ 0:
௝ఠ
1 − ି௝ఠே =
=
1 − ି௝ఠ
=
ି௝ఠ
∴ ௝ఠ = 0 if =
EE 461
ఠே
ଶ
ି௝
2
sin
2
sin
ேିଵ
ଶ
ି௝
ఠ
ଶ
, ,⋯
௝
௝
ఠே
ଶ
ఠ
ଶ
−
−
ఠே
ଶ
ି௝
ି௝
ఠ
ଶ
; First null is at =
Section 9a - Filter Design Using Windows
13
Rectangular Window of Length ܰ (cont.)
2
=
sin
2
• Consider the area under the main lobe:
௝ఠ = ି௝ఠ
ேିଵ
ଶ
௪ ∴ ௪
ଶగ
ே sin 2
2
≅ sin
ଶగ
ଶగ
2
2
ି
ି
ଶగ
ே sin
ே
−
2
ே
2
Let =
EE 461
sin
ఠே
, ଶ
=
ଶ
ே
గ
= 2
ିగ
For reasonable ܰ,
sin
ఠ
ଶ
≅
2ߨ
߱ <
ܰ
ఠ
ଶ
for
sin ≅ 1.18 × 2
Section 9a - Filter Design Using Windows
Independent of 14
7
Example 9.1
a) Plot for a rectangular window of length 21
b) Determine the difference in dB between the absolute
magnitudes of the main lobe and the second lobe
c) Plot the cumulative area under and determine the
area under main lobe
EE 461
Section 9a - Filter Design Using Windows
15
Example 9.1a Solution
a) Use MATLAB to plot:
௪
EE 461
× 21
sin
2
2
=
=
sin
sin
2
2
sin
Section 9a - Filter Design Using Windows
16
8
Example 9.1a Solution (cont.)
%*** Define parameters
N = 21;
dw = pi/1000;
w = [-2*pi:dw:2*pi];
%*** A(w)
Aw = sin( w * ( N / 2 ) ) ./ sin ( w / 2 );
%*** Plot
figure( 1 );
plot( w, Aw );
grid;
title( [ 'Example 9.1: A_w(\omega) of Rectangular Window, N = ', num2str( N ) ] );
xlabel( '\omega (radians per sample)' );
ylabel( 'A_w(\omega)' );
axis( [ -2*pi, 2*pi, -5, 25 ] );
set( gca, 'XTick', linspace( -2*pi, 2*pi, 9 ) );
set( gca, 'XTickLabel', { '-2p', '-1.5p', '-p', '-0.5p', '0', '0.5p', 'p', '1.5p', '2p' } );
set( gca, 'fontname', 'symbol' );
EE 461
Section 9a - Filter Design Using Windows
17
Example 9.1a Solution (cont.)
Main lobe has
height = ܰ = 21
EE 461
Section 9a - Filter Design Using Windows
18
9
Example 9.1b Solution
b) The magnitude of the main lobe = = 21
, , ⋯,
The nulls occur at =
must be at =
=
therefore the second lobe
Main lobe: 20log 21 = 26.44dB
Second lobe: 20log యഏ
మ
యഏ
మభ×మ
= 13.05dB
Difference = 26.44dB − 13.05dB = 13.39dB
EE 461
Section 9a - Filter Design Using Windows
19
Example 9.1b Solution (cont.)
%*** Define parameters
w = [-pi:dw:pi];
%***
Aw =
y1 =
y2 =
A(w)
20 * log10( abs( sin( w * ( N / 2 ) ) ./ sin ( w / 2 ) ) );
20 * log10( N );
20 * log10( abs( 1 / sin( 3*pi/N/2 ) ) );
%***
figure( 2 );
plot( w, Aw, [ -0.25*pi 0 ], [ y1 y1 ], '-r', [ -0.25*pi 0 ], [ y2 y2 ], '-r' );
h = text( -.3*pi, (y2+y1)/2, sprintf( '%.1f dB', y1-y2 ) );
set( h, 'BackgroundColor', [1 1 1] );
grid;
title( [ 'Example 9.1: A_w(\omega) of Rectangular Window, N = ', num2str( N ) ] );
xlabel( '\omega (radians per sample)' );
ylabel( '20xlog_1_0(|A_w(\omega)|)' );
axis( [ -pi, pi, -10, y1+2 ] );
set( gca, 'XTick', linspace( -pi, pi, 9 ) );
set( gca, 'XTickLabel', { '-p', '-0.75p', '-0.5p', '-0.25p', '0', '0.25p', '0.5p', '0.75p', 'p'
} );
set( gca, 'fontname', 'symbol' );
EE 461
Section 9a - Filter Design Using Windows
20
10
Example 9.1b Solution (cont.)
Second lobe is
13.4 dB down
from main lobe
EE 461
Section 9a - Filter Design Using Windows
21
Example 9.1c Solution
c) Plot the cumulative area under and determine area
under main lobe
Cumulative area is given by:
ఠ
1
௪ 2
ିగ
The area under the main lobe can be found by taking the
difference in the cumulative area from the start of the main
lobe = − to the end of the main lobe = Plot using MATLAB
EE 461
Section 9a - Filter Design Using Windows
22
11
Example 9.1c Solution (cont.)
for i = 1:length( w )
if( w(i) == 0 ) delta = N * dw / 2 /pi;
else delta = sin( w(i) * N / 2 ) / sin( w(i) / 2 ) * dw / 2 / pi;
end
if ( i > 1 ) sum_Aw(i) = sum_Aw(i-1) + delta;
else sum_Aw(i) = delta;
end
end
figure( 3 );
plot( w, sum_Aw, [ -2*pi/N -2*pi/N ], [ -0.2 1.2 ], '-r', ...
[ 2*pi/N 2*pi/N ], [ -0.2 1.2 ], '-r', ...
[ -4*pi/N 4*pi/N ], [ min( sum_Aw ) min( sum_Aw ) ], '-r', ...
[ -4*pi/N 4*pi/N ], [ max( sum_Aw ) max( sum_Aw ) ], '-r'
);
str1(1) = {' Area under main '};
str1(2) = {sprintf( ' lobe = %.2f ', max( sum_Aw ) - min( sum_Aw ) )};
h = text( 0.2*pi, 0.5, str1 );
set( h, 'BackgroundColor', [1 1 1], 'EdgeColor', [0 0 0] );
grid;
title( [ 'Example 9.1: A_w(\omega) of Rectangular Window, N = ', num2str( N ) ] );
xlabel( '\omega (radians per sample)' );
ylabel( 'Integral of A_w(\omega)' );
axis( [ -pi, pi, -0.2, 1.2 ] );
EE 461
Section 9a - Filter Design Using Windows
23
Example 9.1c Solution (cont.)
ఠ
1
න ‫ܣ‬௪ ߠ ݀ߠ
2ߨ
ିగ
EE 461
Section 9a - Filter Design Using Windows
24
12
Example 9.2
• Repeat Example 9.1 but with = 51
EE 461
Section 9a - Filter Design Using Windows
25
Example 9.2a Solution
Main lobe has
height = ܰ = 51
EE 461
Section 9a - Filter Design Using Windows
26
13
Example 9.2b Solution
Second lobe is
13.5 dB down
from main lobe
EE 461
Section 9a - Filter Design Using Windows
27
Example 9.2c Solution
ఠ
1
න ‫ܣ‬௪ ߠ ݀ߠ
2ߨ
ିగ
EE 461
Section 9a - Filter Design Using Windows
28
14
Hamming Window
• One well known window is the “Hamming Window”:
=
2
; 0 ≤ ≤ − 1
−1
0; otherwise
0.54 − 0.46 cos
• Proposed by Richard W. Hamming (1977)
• Window is optimized to minimize the largest side lobe
(nearest to main)
଼గ
• Width of main lobe is approximately ேିଵ (larger than for a
rectangular window which was
EE 461
ସగ
)
ே
Section 9a - Filter Design Using Windows
29
Example 9.3
• Consider a Hamming Window with length ܰ = 21:
a) Plot the impulse response
b) Plot c) Determine the difference in dB between the absolute
magnitudes of the main lobe and the second lobe
d) Plot the cumulative area under ௪ and determine the area
under main lobe
e)
EE 461
Determine the area under the second lobe
Section 9a - Filter Design Using Windows
30
15
Example 9.3a Solution
%*** Define parameters
N = 21;
dperpi = 1000;
dw = pi/dperpi;
w = [-pi:dw:pi];
titlestr = sprintf( 'Example 9.3:
Hamming Window, N = %d', N );
%*** Calculate w[n]
for n = 0:N-1
h( n + 1 ) = 0.54 - 0.46 * cos( 2 * pi * n / ( N - 1 ) );
end
%*** Stem plot of w[n]
figure( 1 );
stem( 0:N-1, h );
grid;
title( [ titlestr ] );
xlabel( 'n' );
ylabel( 'h_h_a_m_m_i_n_g[n]' );
EE 461
Section 9a - Filter Design Using Windows
31
Example 9.3a Solution (cont.)
EE 461
Section 9a - Filter Design Using Windows
32
16
Example 9.3b Solution
%*** Calculate A(w)
Aw = h((N-1)/2+1) + 2 * h(1:(N-1)/2)*cos([(0:((N-1)/2-1))-(N-1)/2].'*w);
%*** Plot A(w)
figure( 2 );
lf = 4 * pi / (N - 1);
plot( w, Aw, [ -lf -lf ], [ min( Aw ) - 2, max( Aw ) ], '-r', ...
[ lf lf ], [ min( Aw ) - 2, max( Aw ) ], '-r' );
str1(1) = {' Main lobe width '};
str1(2) = {' approximately 8\pi/(N-1)'};
h = text( 0.3*pi, max( Aw ) / 2, str1 );
set( h, 'BackgroundColor', [1 1 1], 'EdgeColor', [0 0 0] );
grid;
title( [ titlestr ] );
xlabel( '\omega' );
ylabel( 'A(\omega)' );
axis( [ -pi, pi, min( Aw ) - 2, max( Aw ) + 2 ] );
set( gca, 'XTick', linspace( -pi, pi, 9 ) );
set( gca, 'XTickLabel', { '-p', '-0.75p', '-0.5p', '-0.25p', '0', '0.25p', '0.5p', '0.75p', 'p'
} );
set( gca, 'fontname', 'symbol' );
EE 461
Section 9a - Filter Design Using Windows
33
Example 9.3b Solution (cont.)
EE 461
Section 9a - Filter Design Using Windows
34
17
Example 9.3c Solution
%***
Awdb
y1 =
y2 =
Calculate A(w) in dB
= 20 * log10( abs( Aw ) );
max( Awdb );
max( Awdb((1-2*4/(N-1))*dperpi:(1-4/(N-1))*dperpi) );
%***
figure( 3 );
plot( w, Awdb, [-0.5*pi 0], [y1 y1], '-r', [-0.5*pi 0], [y2 y2], '-r' );
str1(1) = {' Main lobe to second '};
str1(2) = {sprintf( ' lobe = %.1f dB ', y1-y2 )};
h1 = text( -.9*pi, (y2+y1)/2, str1 );
set( h1, 'BackgroundColor', [1 1 1], 'EdgeColor', [0 0 0] );
grid;
title( [ titlestr ] );
xlabel( '\omega (radians per sample)' );
ylabel( '20xlog_1_0(|A_w(\omega)|)' );
axis( [ -pi, pi, -35, max( Awdb ) + 2 ] );
set( gca, 'XTick', linspace( -pi, pi, 9 ) );
set( gca, 'XTickLabel', { '-p', '-0.75p', '-0.5p', '-0.25p', '0', '0.25p', '0.5p', '0.75p', 'p'
} );
EE 461
Section 9a - Filter Design Using Windows
35
Example 9.3c Solution (cont.)
EE 461
Section 9a - Filter Design Using Windows
36
18
Example 9.3d Solution
%*** Calculate and plot cumulative A(w)
for i = 1:length( w )
delta = 1 / 2 / pi * Aw(i)*dw;
if ( i > 1 ) sum_Aw(i) = sum_Aw(i-1) + delta;
else sum_Aw(i) = delta;
end
end
figure( 4 );
plot( w, sum_Aw, ...
[ -4*pi/N 4*pi/N ], [ min( sum_Aw ) min( sum_Aw ) ], '-r', ...
[ -4*pi/N 4*pi/N ], [ max( sum_Aw ) max( sum_Aw ) ], '-r'
);
str1(1) = {' Area under main '};
str1(2) = {sprintf( ' lobe = %.3f ', max( sum_Aw ) - min( sum_Aw ) )};
h = text( 0.2*pi, 0.5, str1 );
set( h, 'BackgroundColor', [1 1 1], 'EdgeColor', [0 0 0] );
grid; title( [ titlestr ] );
xlabel( '\omega (radians per sample)' );
ylabel( 'Integral of A_w(\omega)' );
axis( [ -pi, pi, -0.2, 1.2 ] );
set( gca, 'XTick', linspace( -pi, pi, 9 ) );
set( gca, 'XTickLabel', { '-p', '-0.75p', '-0.5p', '-0.25p', '0', ...
'0.25p', '0.5p', '0.75p', 'p' } );
set( gca, 'fontname', 'symbol' );
EE 461
Section 9a - Filter Design Using Windows
37
Example 9.3d Solution (cont.)
ఠ
1
න ‫ܣ‬௪ ߠ ݀ߠ
2ߨ
ିగ
EE 461
Section 9a - Filter Design Using Windows
38
19
Example 9.3e Solution
%*** Look at the height of the second lobe
y1 = min( sum_Aw );
y2 = max( sum_Aw((1-2*4/(N-1))*dperpi:(1-4/(N-1))*dperpi) );
figure( 5 );
plot( w, sum_Aw, [-0.5*pi 0], [y1 y1], '-r', [-0.5*pi 0], [y2 y2], '-r');
str1(1) = {' Area under second '};
str1(2) = {sprintf( ' lobe = %f ', y2 - y1 )};
h = text( -0.9*pi, 1.5*y2, str1 );
set( h, 'BackgroundColor', [1 1 1], 'EdgeColor', [0 0 0] );
grid; title( [ titlestr ] );
xlabel( '\omega (radians per sample)' );
ylabel( 'Integral of A_w(\omega)' );
axis( [ -pi, 0, (y1*2), -(y1*2) ] );
set( gca, 'XTick', linspace( -pi, 0, 5 ) );
set( gca, 'XTickLabel', { '-p', '-0.75p', '-0.5p', '-0.25p', '0' } );
set( gca, 'fontname', 'symbol' );
EE 461
Section 9a - Filter Design Using Windows
39
Example 9.3e Solution (cont.)
ఠ
1
න ‫ܣ‬௪ ߠ ݀ߠ
2ߨ
ିగ
EE 461
Section 9a - Filter Design Using Windows
40
20