1、FNCCH(x)log(x+sqrt(x*x-1)FNSH1(x)(exp(x)-exp(-x)/2FNCH1(x)(exp(x)+exp(-x)/2/*/double *bcg(double ap,double as,double wp,double ws,int *n,double *h,int *type);struct rptr *bsf(double *c,int ni,double *f1,double *f2,int nf,struct rptr *ptr,int *no);double *pnpe(double *a,int m,int n,double *b,int *mn)
2、;double *ypmp(double *a,int m,double *b,int n,double *c,int *mn);void lowpass_input(double *wp,double *ws,double *ap,double *ar,double *f1,double *f2,int *nf);void highpass_input(double *wp,double *ws,double *ap,double *ar,double *f1,double *f2,int *nf);void bandpass_input(double *wp,double *ws,doub
3、le *ap,double *ar,double *f1,double *f2,int *nf);void draw_image(double *x,int m,char *title1,char *title2,char *xdis1,char *xdis2,int dis_type);void main(void)double *f1,*f2,*hwdb;double *h=NULL;int N,nf,ns,nz,i,j,k,ftype,type;COMPLEX hwdb1,hwdb2;double wp,ws,ap,as,jw,amp1,amp2;char title80,tmp20;s
4、truct rptr *ptr=NULL;/* printf(%lf,PI);getch();N=500;f1=(double *)calloc(4,sizeof(double);f2=(double *)calloc(4,sizeof(double);hwdb=(double *)calloc(N+2,sizeof(double);if (hwdb=NULL)printf(n Not enough memory to allocate!);exit(0);n1.Lowpass 2.Highpass 3.bandpassnPlease select the filter type:scanf(
5、%d,&ftype);switch(ftype)case 1:lowpass_input(&wp,&ws,&ap,&as,f1,f2,&nf);break;case 2:highpass_input(&case 3:bandpass_input(&default:h=bcg(ap,as,wp,ws,&ns,h,&type);nThe analog filter denominator coefficients of Ha(s):for(i=0;iai,i,ptr-bi);nnPress any key to calculate the filter response of H(z).nWait
6、ting for calculating./* Calculate the magnitude-frequency response*/for(k=0;kai*cos(i*jw);hwdb2.real+=ptr-bi*cos(i*jw);hwdb1.image+=ptr-ai*sin(i*jw);hwdb2.image+=ptr-bi*sin(i*jw);amp1=(pow(hwdb1.real,2)+pow(hwdb1.image,2);amp2=(pow(hwdb2.real,2)+pow(hwdb2.image,2);if(amp1=0) amp1=1e-90;if(amp2=0) am
7、p2=1e-90;hwdbk=10*log10(amp1/amp2);if(hwdbkb);a);free(h);free(hwdb);free(f2);free(f1);/*/void lowpass_input(double *wp,double *ws,double *ap,double *ar,double *f1,double *f2,int *nf)double fp,fr,fs;nPlease input the Fp,Ap,Fr,Ar,Fs valuenFp,Ap:Passband frequency(Hz) and MAXAttenuation(dB)nFr,Ar:Stopb
8、and frequency(Hz) and MINAttenuation(dB)nFs is the sample frequency(Hz) Lowpass filternInput parameters Fp,Ap,Fr,Ar,Fs:%lf,%lf,%lf,%lf,%lffp,ap,&fr,ar,&fs);if(fpfr)|(*ap*ar)|(fs2*fr);*wp=tan(PI*fp/fs);*ws=tan(PI*fr/fs);*f1=-1.0;*(f1+1)=1.0;*f2=1.0;*(f2+1)=1.0;*nf=1;/*/void highpass_input(double *wp,
9、double *ws,double *ap,double *ar,double *f1,double *f2,int *nf)nFs is the sample frequency(Hz) highpass filterif(fp*ar)|(fs2*fp)while(fp*ar)|(fsfp2)|(fp1fr2)|(*ap2*fr2)while(fp12*fr2);wp1=2*PI*fp1/fs;wr1=2*PI*fr1/fs;wp2=2*PI*fp2/fs;wr2=2*PI*fr2/fs;cw0=sin(wp1+wp2)/(sin(wp1)+sin(wp2);pwp1=fabs(cw0-co
10、s(wp1)/sin(wp1);pws1=fabs(cw0-cos(wr1)/sin(wr1);pwp2=fabs(cw0-cos(wp2)/sin(wp2);pws2=fabs(cw0-cos(wr2)/sin(wr2);if(fabs(pws1-pwp1)real=-wc*FNSH1(x)*sin(y);image=-wc*FNCH1(x)*cos(y);c=(pow(10.0,(0.1*ap)-1.0)/(pow(10.0,(0.1*as)-1.0);*n=(int)(fabs(log(c)/log(wp/ws)/2.0)+0.99999);b=(COMPLEX *)calloc(*n+
11、2,sizeof(COMPLEX);wc=wp/pow(pow(10.0,0.1*ap)-1.0,1.0/(2.0*(*n);a=pow(wc,(double)(*n);p=PI*(0.5+(2.0*i+1.0)/2.0/(*n);real=wc*cos(p);image=wc*sin(p);nThe order of prototype filter is:,*n);/* b1=(COMPLEX*)calloc(*n+2,sizeof(COMPLEX);b2=(COMPLEX*)calloc(*n+2,sizeof(COMPLEX);h=(double *)calloc(*n+2),size
12、of(double);if(h=NULL)b1-real=-(b-real);image=-(b-image);(b1+1)-real=1.0;image=0.0;if(*n!=1)for(i=1;I;K+)cs1=(b1+k)-real-(b1+k+1)-real*(b+i)-real;cs2=(b1+k)-image-(b1+k+1)-image;(b2+k+1)-real=cs1+(b1+k+1)-image*(b+i)-image=cs2-(b1+k+1)-b2-real=-(b1-real-b1-image=-(b1-image+b1-(b2+i+1)-real=(b1+i)-image=(b1+i)-=i+1;(b1+k)-real=(b2+k)-image=(b2+k)-(b2+k)-real=0.0;=*n;hi=(b1+i)-nz%2d=%16fnz0=%16f,nz1=%16f,nz2=%16f,nz3=%16f,nz4=%16f,1.0,2.6131/wc,3.4142/pow(wc,2),2.6131/pow(wc,3),1/a);=*n-1;ppi=xs*n-1i;hi=ppi/pow(wc,i);free(b);/* free(b1);free(b2);return h;/*/*
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1