Escolar Documentos
Profissional Documentos
Cultura Documentos
Dec 2014
1. Introduction
Fir filters are designed by choosing filter coefficients to approximate in a " best manner " an ideal desired
specification in the stop and pass band using many methods. One of the methods that allows optimization of deviation energy
is the eigen filter .(ref On The Eigenfilter Design Method and Its Applications: A Tutorial
Andre Tkacenko, Student Member, IEEE, P. P. Vaidyanathan, Fellow, IEEE, andTruong Q. Nguyen, Senior Member, IEEE)
The basis of the eigen filter is the z transform for FIR viz
H(z) = h0 +h1*z^-1 +h2*z^-2 +.... hn*z^-N
z^-2
z^-N ]transpose
where h is the coefficient vector and e(jw) is the column vector of the delay chain z
mx= max(xm)
xml = 20*log10( abs(xm/mx));
oma=omg/2/%pi ;
figure(1);
plot(oma, xml);
// figure(1)
0. 0.5 ;
0.5 0. ;
0.
0. ;
0.5 0. ;
0. 0.5 ; ]
so htr = C *b
hz =c*hseqa' //gives
hz =
0.0830144
0.4080832
0.5534498
0.4080832
0.0830144
2 Theory
The spec function of scilab 5.3.3 is verified as it gives nearly same value as the power method . N=odd length filter
The bands are specified in
sig3 =.5 *%pi // stop band
sig4 = 1*%pi // stop band
sig1 = 0*%pi // passband
sig2 =.3*%pi // pass band
The integrated p matrix is computed using special case for row =0 col =0 etc to avoid division by zero.
//P matrix stop band use sig4=pi sig3 less
if ( (rn==0)&(cn==0) ) then
p(r,c) =sig4 -sig3 ;
end ;
if ( (rn==0)&(cn>0) ) then
p(r,c) = sin(sig4 *cn)/cn
- sin(sig3 *cn)/cn ;
end ;
if ( (rn> 0)&(cn==0) ) then
p(r,c) = sin(sig4 *rn)/rn
- sin(sig3 *rn)/rn ;
end ;
if ( (rn*cn> 0) & ( rn==cn) ) then
p(r,c) = 1/2* ( sig4 -sig3 + sin(sig4 *(rn +cn ) )/ (rn+cn) - sin(sig3 *(rn +cn ) )/ (rn+cn)
end ;
if ( (rn*cn> 0) & ( abs(rn-cn) >0 ) ) then
p(r,c) = 1/2* ( sin(sig4 *(rn +cn ) )/ (rn+cn) - sin(sig3 *(rn +cn ) )/ (rn+cn) ) ;
p(r,c) = p(r,c) + 1/2* ( sin(sig4 *(rn -cn ) )/ (rn-cn) - sin(sig3 *(rn -cn ) )/ (rn-cn) ) ;
);
)/2 ;
Next the htot matrix is used to obtain the inverse hin and the max eigenvector of hin is the min eigenvector of htot .
5. Scilab 5.3.3 code for Eigen Type 1 FIR filter
// Eigenfilter ver 5 N-1 =even and m=( N-1)/2
N= 31 // N=odd only is considered
p=[] //the stop band matrix
q=[] // the pass band matrix
n1=(N-1)/2 +1 // modified M
// set sigma values passband sig1 sig2 in radians
// stop band sig3 sig4
sig3 =.5 *%pi // stop band
sig4 = 1*%pi // stop band
sig1 = 0*%pi // passband
sig2 =.3*%pi // pass band
p=zeros(n1,n1); // building the integrated p matrix
for r=1:n1
rn =r-1 ;
for c=1:n1
cn = c-1 ;
//P matrix stop band use sig4=pi sig3 less
if ( (rn==0)&(cn==0) ) then
p(r,c) =sig4 -sig3 ;
end ;
if ( (rn==0)&(cn>0) ) then
p(r,c) = sin(sig4 *cn)/cn
- sin(sig3 *cn)/cn ;
end ;
if ( (rn> 0)&(cn==0) ) then
p(r,c) = sin(sig4 *rn)/rn
- sin(sig3 *rn)/rn ;
end ;
if ( (rn*cn> 0) & ( rn==cn) ) then
p(r,c) = 1/2* ( sig4 -sig3 + sin(sig4 *(rn +cn ) )/ (rn+cn) - sin(sig3 *(rn +cn ) )/ (rn+cn)
end ;
if ( (rn*cn> 0) & ( abs(rn-cn) >0 ) ) then
p(r,c) = 1/2* ( sin(sig4 *(rn +cn ) )/ (rn+cn) - sin(sig3 *(rn +cn ) )/ (rn+cn) ) ;
p(r,c) = p(r,c) + 1/2* ( sin(sig4 *(rn -cn ) )/ (rn-cn) - sin(sig3 *(rn -cn ) )/ (rn-cn) ) ;
end ;
p(r,c) =p(r,c)/%pi ;
end;
end ;
//Q matrix passband use sig2=.3 >sig1=0
for r=1:n1
rn =r-1 ;
for c=1:n1
cn = c-1 ;
if ( ( rn ==0)& (cn ==0 ) ) then
q(r,c)=0 ;
end ;
if ( ( rn ==0)& (cn >0 ) ) then
q(r,c)=0 ;
end;
if ( ( cn ==0)& (rn >0 ) ) then
q(r,c)=0 ;
end;
if ( ( (rn *cn) > 0) & (rn==cn) ) then
q(r,c) = sig2 - sin(rn*sig2)/rn - sin(cn*sig2)/cn ...
+ ( sin( (rn+cn)*sig2) /(rn+cn) + sig2
)/2;
q(r,c)=q(r,c) - ( sig1 - sin(rn*sig1)/rn - sin(cn*sig1)/cn ...
+ ( sin( (rn+cn)*sig1) /(rn+cn) + sig1
)/2 ) ;
end ;
if (
(rn*cn)>0 & ( abs(rn -cn) >0)
) then
q(r,c)= sig2 - sin(rn*sig2)/rn -sin(cn*sig2 )/cn ;
q(r,c)=q(r,c)+ ( sin( (rn+cn)*sig2) /(rn+cn) + sin( (rn-cn)*sig2) /(rn-cn)
)/2 ;
q(r,c)=q(r,c) - (sig1 - sin(rn*sig1)/rn - sin(cn*sig1)/cn ) ;
q(r,c)=q(r,c) - ( sin( (rn+cn)*sig1) /(rn+cn) + sin( (rn-cn)*sig1) /(rn-cn)
end
q(r,c)= q(r,c)/%pi ;
end;
end ;
alp=.5
htot = alp*p+(1-alp)*q;
// finding the min eigen value vector
hin = htot^-1 ; // invert htot and we seek max of hin
nit=100 // max iterations
v2= ones(1, n1) ;
v2=v2';
smx = sqrt( v2'*v2) ;
v2=v2/smx;
lamo=0 ;
for i=1:nit
v3= hin*v2 ;
lamn= sqrt ( ( v3'*v3 ) / (v2'*v2 ) ) ;
rer= abs(lamo- lamn ) ;
if ( rer< .001) then break end;
)/2 ;
);
lamo=lamn ;
v2= v3/sqrt( v3'*v3 ) ;
end
h s eq a = v2 ; // thi s i s the fiter w e s e e k
npt =100 // number of plot points
dw= %pi/npt ;
omg= zeros(1:npt);
for k=1:npt
xm(k)= 0;
omg(k)=omg(k)+(k-1)* dw;
for i=1:n1
xm(k) = hseqa(i)*cos(omg(k)*(i-1) ) +xm(k) ;
end
end
xm =real(xm) ;
plot(omg, xm); // the magn vs w response
figure(1);
mx= max(xm)
xml = 20*log10( abs(xm/mx)); // in db
oma=omg/2/%pi ;
plot(oma, xml); // db magn vs per unit freq
// lamn =1836256.4
//1/lamn =0.0000005
//hseqa =
0.5197220
0.7810746
0.2383787
- 0.1455732
- 0.1698201
- 0.0035968
0.0906716
0.0448063
- 0.0291368
- 0.0377701
- 0.0018667
0.0180220
0.0086882
- 0.0038613
- 0.0045153
- 0.0004323
//figure 0
figure1
// using
[evseqr ,diagevalsr]=spec(htot) ;
diag(diagevalsr ) ; // print all eigen values
// ans =
2.308924
0.3732253
0.0508677
0.0082529
0.0000005
0.0001573
0.1889106
0.2370807
0.2496339
0.2499695
0.2499997
0.2500000
0.25
0.25
0.25
0.25
h s eq a = r e al ( ev s eqr(:, 5) ) // printout min eig en value ve ctor ie 5 th ve ctor in our e x a mpl e
hseqa =
- 0.5197220
- 0.7810746
- 0.2383787
0.1455732
0.1698201
0.0035968
- 0.0906716
- 0.0448063
0.0291368
0.0377701
0.0018667
- 0.0180220
- 0.0086882
0.0038613
0.0045153
0.0004323
// notice hseqa is negative of previous result
// so set hseqa= -hseqa
hseqa= -(hseqa) ; // change to real type
//plot using rsult of spec function
npt =100
dw= %pi/npt ;
omg= zeros(1:npt);
for k=1:npt
xm(k)= 0;
omg(k)=omg(k)+(k-1)* dw;
for i=1:n1
xm(k) = hseqa(i)*cos(omg(k)*(i-1) ) +xm(k) ;
end
end
xm =real(xm) ;
figure(2);
plot(omg, xm); // plot the magn vs freq
figure(3);
mx= max(xm)
xml = 20*log10( abs(xm/mx));
oma=omg/2/%pi ;
plot(oma, xml);
figure(3)
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx