📄 iirbcf example.c
字号:
#include"stdio.h"
#include"iirbcf.c"
#include"gainc.c"
void main()
{ int i,k,n,ns,itilt,band;
double a[50],b[50],x[300],y[300];
double f1,f2,f3,f4,fc,fr,fs,flc,fls,fhc,fhs,freq,db;
char fname[40];
FILE *fp;
printf("enter 1 for Chebyshev I, 2 for Chebyshev II,3 for Butterworth\n");
scanf("%d",&ifilt);
printf("enter 1 for lowpass, 2 for highpass, 3 for bandpass, 4 for bandstop\n");
scanf("%d",&band);
n=(band<=2)?2:4;
printf("enter the number of filter section\n");
scanf("%d",&ns);
printf("enter sample frequence fs\n");
scanf("%lf", &fs);
if(ifilt<=2)
{ switch(band)
{ case 1:
case 2:
{ printf("enter passband edge frequency fc\n");
scanf("%lf",&fc);
printf("enter stopband edge frequency fr\n");
scanf("%lf",&fr);
if(band==1)
{ f1=fc;
f2=fr;
}
else
{ f1=fr;
f2=fc;
}
f3=f4=0.0;
case 3:
case 4:
{ printf("enter the lower passband edge frequency flc\n");
scanf("%lf",&flc);
printf("enter the higher passband edge frequency fhc\n");
scanf("%lf",&fhc);
printf("enter the lower stopband edge frequency fls\n");
scanf("%lf",&fls);
printf("enter the higher stopband edge frequency fhs\n");
scanf("%lf",&fhs);
if(band==3)
{ f1=fls;
f2=flc;
f3=fhc;
f4=fhs;
}
else
{ f1=flc;
f2=fls;
f3=fhs;
f4=fhc;
}
}
}
printf("enter stopband attenuation(dB)\n");
scanf("%lf",&db);
}
else
{ switch(band)
{ case 1:
case 2:
{ printf("enter passband edge frequency fc\n");
scanf("%lf",&fc);
f1=f2=f3=f4=0.0;
if(band==1)
{ f1=fc;}
else
{ f2=fc;}
break;
}
case 3:
case 4:
{ printf("enter the lower passband edge frequency flc\n");
scanf("%lf",&flc);
printf("enter the higher passband edge frequency fhc\n");
scanf("%lf",&fhc);
f1=f2=f3=f4=0.0;
if(band==3)
{ f2=flc;
f3=fhc;
}
else
{ f1=flc;
f4=fhc;
}
}
}
}
f1=f1/fs;
f2=f2/fs;
f3=f3/fs;
f4=f4/fs;
iirbcf(ifilt,band,ns,n,f1,f2,f3,f4,db,b,a);
for(k=0;k<ns;k++)
{ printf("\nsection %d\n\n",k+1);
for(i=0;i<=n;i++)
{ printf(" b[%d][%d]=%10.7lf ",k,i,b[k*(n+1)+i]);
if(((i%2)==0)&&(i!=0)) printf("\n");
}
printf("\n");
for(i=0;i<=n;i++)
{ printf(" a[%d][%d]=%10.7lf ",k,i,a[k*(n+1)+i]);
if(((i%2)==0)&&(i!=0)) printf("\n");
}
printf("\n");
}
printf("\nenter file name of magnitude response\n");
scanf("%s",fname);
if((fp=fopen(fname,"w"))==NULL)
{ printf("cannot open file %s\n",fname);
exit(0);
}
gainc(b,a,n,ns,x,y,300,2);
for(i=0;i<300;i++)
{ freq=i*0.5/300.0;
fprintf(fp,"%lf %lf\n",freq,x[i]);
}
fclose(fp);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -