1.谁能帮我写个FIR程序 急急急!
谁能帮我写个FIR程序 急急急!娱乐 app 源码
先用窗函数法算出滤波器系数,hrtf算法源码然后求输入信号序列和滤波器的商城源码侵权卷积,求出的dubbo 源码结构就是输出序列了。窗函数法源代码#include"math.h"
void firwin(n,macd 指标源码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 if kaiser window(2<beta<)\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)
{ case 1:
{ for(i=0;i<=n2;i++)
{ s=i-delay;
h[i]=(sin(wc1*s)/(pi*s))*window(wn,n+1,beta);
h[n-i]=h[i];
}
if(mid==1)h[n/2]=wc1/pi;
break;
}
case 2:
{ 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;
}
case 3:
{ for(i=0;i<=2;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;
}
case 4:
{ 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)
{ case 1:
{ w=1.0;
break;
}
case 2:
{ k=(n-2)/;
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;
}
case 3:
{ w=1.0-fabs(1.0-2*i/(n-1.0));
break;
}
case 4:
{ w=0.5*(1.0-cos(2*i*pi/(n-1)));
break;
}
case 5:
{ w=0.-0.*cos(2*i*pi/(n-1));
break;
}
case 6:
{ w=0.-0.5*cos(2*i*pi/(n-1))+0.*cos(4*i*pi/(n-1));
break;
}
case 7:
{ w=kaiser(i,n,beta);
break;
}
}
return(w);
}
static double kaiser(i,n,beta)
int i,n;
double beta;
{ double a,w,a2,b1,b2,beta1;
double bessel0();
b1=bessel0(beta);
a=2.0*i/(double)(n-1)-1.0;
a2=a*a;
beta1=beta*sqrt(1.0-a2);
b2=bessel0(beta1);
w=b2/b1;
return(w);
}
static double bessel0(x)
double x;
{ int i;
double d,y,d2,sum;
y=x/2.0;
d=1.0;
sum=1.0;
for(i=1;i<=;i++)
{ d=d*y/i;
d2=d*d;
sum=sum+d2;
if(d2<sum*(1.0e-8))break;
}
return(sum);
}
滤波:length为有效数据格数
for(g=0;g<length;g++)
{ int k;
int min=g-;
int max=g;
if(min>0)
{ for(k=min;k<=max;k++)
{ j[g]+=f[k]*h[g-k];
}
}
else
{ for(k=0;k<=max;k++)
{ j[g]+=f[k]*h[g-k];
}
}
}//求卷积
for(g=0;g<length;g++)
{ l[g]=j[length-g];}
//时间反转
for(g=0;g<length;g++)
{ int k2;
int min2=g-;
int max2=g;
if(min2>0)
{ for(k2=min2;k2<=max2;k2++)
{ p[g]+=l[k2]*h[g-k2];
}
}
else
{ for(k2=0;k2<=max2;k2++)
{ p[g]+=l[k2]*h[g-k2];
}
}
}//再一次求卷积
for(g=0;g<length;g++)
{ q[g]=p[length-g];}
//再一次时间反转