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(2<beta<10)\n")
scanf("%1f",&beta)
}
pi=4.0*atan(1.0)
if((n%2)==0)/*如果n是偶数*/
{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/*先判断用户输入的数据,如果band参数大于3*/
switch(band)
{case 1:
{for(i=0i<=n2i++)
{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
}
case 2:
{for(i=0i<=n2i++)
{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=0i<n2i++)
{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=0i<=n2i++)
{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)/10
if(i<=k)
w=0.5*(1.0-cos(i*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.54-0.46*cos(2*i*pi/(n-1))
break
}
case 6:
{w=0.42-0.5*cos(2*i*pi/(n-1))+0.08*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=1i<=25i++)
{d=d*y/i
d2=d*d
sum=sum+d2
if(d2<sum*(1.0e-8)) break
}
return(sum)
}
这是窗函数法的,当然还有其他的比如切比雪夫,零相位滤波什么的,我也在研究,不是很懂哈
#include<stdio.h>void main()
{
char ch
int num1,num2,num3,num4,m
num1=0
num2=0
num3=0
num4=0
puts("Type in a sentence,then press <ENTER>\n")
while ((ch=getchar())!='\n')
{
if(ch>=48&&ch<=57) num1++
else if(ch>=65&&ch<=90) num2++
else if(ch>=97&&ch<=122) num3++
else num4++
}
printf("%4d%4d%4d%4d",num1,num2,num3,num4)
}
帮你改了一下 你的太复杂了 可以运行
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)