#include <math.h>
void iirbcf(ifilt,band,ns,n,f1,f2,f3,f4,db,b,a)
double b[],a[],f1,f2,f3,f4,db;
int ifilt,band,ns,n;
{
int k;
double omega,lamda,epslon,f1,fh;
double d[5],c[5];
void chebyi(),chebyii(),bwtf();
double coshl(),warp(),bpsub(),omin();
void fblt();
if((band==1)||(band==4)) fl=f1;
if((band==2)||(band==3)) fl=f2;
if(band<=3) fh=f3;
if(band==4) fh=f4;
if(ifilt<3)
{
switch(band)
{
case1:
case2:
{
omega=warp(f2)/warp(f1);
break;
}
case3:
{
omega=omin(bpsub(warp(f1),fh,fl),bpsub(warp(f4),fh,fl));
break;
}
case4:
{omega=omin(1.0/bpsub(warp(f2),fh,fl),1.0/bpsub(warp(f3),fh,fl));}
}
lamda=pow(10.0,(db/20.0));
epslon=lamda/cosh(2*ns*coshl(omega));
}
for(k=0;k<ns;k++)
{
switch(ifilt)
{ case1:
{
chebyi(2*ns,k,4,epslon,d,c);
break;
}
case2:
{
chebyii(2*ns,k,4,omega,lamda,d,c);
break;
}
case3:
{
bwtf(2*ns,k,4,d,c);
break;
}
}
fblt(d,c,n,band,fl,fh,&b[k*(n+1)+0],&a[(n+1)+0]);
}
}
static double coshl(x)
double x;
{
double z;
z=log(x+sqrt(x*x-1.0));
return(z);
}
static double warp(f)
double f;
{
double pi,z;
pi=4.0*atan(1.0);
z=tan(pi*f);
return(z);
}
static double bpsub(om,fh,fl)
double om,fh,fl;
{
double z;
z=(om*om-warp(fh)*warp(fl))/((warp(fh)-warp(fl))*om);
return(z);
}
static double omin(om1,om2)
double om1,om2;
{
double z,z1,z2;
z1=fabs(om1);
z2=fabs(om2);
z=(z1<z2)?z1:z2;
return(z);
}
static void bwtf(ln,k,n,d,c)
int ln,k,n;
double d[],c[];
{
int i;
double pi,tmp;
pi=4.0*atan(1.0);
d[0]=1.0;
c[0]=1.0;
for(i=1;i<=n;i++)
{
d[i]=0.0;
c[i]=0.0;
}
tmp=(k+1)-(ln+1.0)/2.0;
if(tmp==0,0)
{c[1]=1.0;}
else
{
c[1]=-2.0*cos((2*(k+1)+ln-1)*pi/(2*ln));
c[2]=1.0;
}
}
static void chebyi(ln,k,n,ep,d,c)
double d[],c[],ep;
int ln,k,n;
{
<< 上一页 [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] ... 下一页 >>