#include <math.h>
void firwin(n,band,fln,fhn,wn,h)
int n,band,wn;
double fln,fhn,h[];
{int i,n2,mid;
double s,pi,wc1,wc2,beta,delay;
double window();
beta=0.0;
if(wn==7)
{printf(“input beta parameter of Kaiser window (3<beta<10)\n”);
scanf(“%lf”,&beta);}
pi=4.0*atan(1.0);
if((n%2)==0)
{n2=n/2-1;
mid=1;}
else
{n2=n/2;
mid=0;}
delay=n/2.0;
wc1=2.0*pi*fln;
if(band>=3) wc2=2.0*pi*fhn;
switch(band)
{case1:
{for(i=0;i<=n2;i++)
{s=i-delay;
h[i]=(sin(wc1*s)/(pi*s))*window(wn,n+1,i,beta);
h[n-i]=h[i];}
if(mid==1) h[n/2]=wc1/pi;
break;}
case2:
{for(i=0;i<=n2;i++)
{s=i-delay;
h[i]=(sin(pi*s)-sin(wc1*s))/(pi*s);
h[i]=h[i]*window(wn,n+1,i,beta);
h[n-i]=h[i];}
if(mid==1) h[n/2]=1.0-wc1/pi;
break;}
case3:
{for(i=0;i<=n2;i++)
{s=i-delay;
h[i]=(sin(wc2*s)-sin(wc1*s))/(pi*s);
h[i]=h[i]*window(wn,n+1,i,beta);
h[n-i]=h[i];}
if(mid==1) h[n/2]=(wc2-wc1)/pi;
break;}
case4:
{for(i=0;i<=n2;i++)
{s=i-delay;
h[i]=(sin(wc1*s)+sin(pi*s)-sin(wc2*s))/(pi*s);
h[i]=h[i]*window(wn,n+1,i,beta);
h[n-i]=h[i];}
if(mid==1) h[n/2]=(wc1+pi-wc2)/pi;
break;}
}
}
static double window(type,n,i,beta)
int i,n,type;
double beta;
{int k;
double pi,w;
double Kaiser();
pi=4.0*atan(1.0);
w=1.0;
switch(type)
{case1:
{w=1.0;
break;}
case2:
{k=(n-2)/10;
if(i<=k)
w=0.5*(1.0-cos(i*pi/(k+1)));
if(i>n-k-2)
w=0.5*(1.0-cos((n-i-1)*pi/(k+1)));
break;}
case3:
{w=1.0-fabs(1.0-2*i/(n-1.0));
break;}
case4:
{w=0.5*(1.0-cos(2*i*pi/(n-1)));
break;}
case5:
{w=0.54-0.46*cos(2*i*pi/(n-1));
break;}
case6:
{w=0.42-0.5*cos(2*i*pi/(n-1))+0.08*cos(4*i*pi/(n-1));
break;}
case7:
{w=Kaiser(i,n,beta);
break;}
}
<< 上一页 [21] [22] [23] [24] [25] [26] [27] [28] 下一页