/* this is an elliptic filter design program converted from basic to c-- in a klunky way. No attempt has been made to get rid of GOTOs, etc. from Cuthbert's adaption of Amstutz's Algorithm I received the basic version in response to a posting on usenet. The original basic is included as a comment at the end of the c-program. Converted: November 3, 1994 by Steven D. Swift, P.E. Seattle, Washington */ #include #include main() { double B[16],C[16],D[16],E[16],F[16]; double DN; double PI=3.14159265359; double sqrt(); double log(); double exp(); double pow(); double sin(); double cos(); double fabs(); double FS, FP; /* stopband edge and passband edge */ int N; /* number of attenuation peaks */ double R, P, Q, S, Y, W, Z, X ; double FC; /* geometric mean of FS and FP */ int K, J, M, L; printf("\nSymmetrical Elliptical Filter Synthesis\n"); DN = log(10.0)/10.0; G2010: printf("Passband edge (MHz): "); scanf("%lf", &FP); FP = FP*1000.0; /* convert to kHz */ printf( "Stopband edge (MHz): "); scanf("%lf", &FS); FS = FS*1000.0; /* convert to kHz */ if ( fabs(FS-FP) <= 0.0 ) goto G2010; G5555: printf("\nNumber of peaks (1-15)= "); scanf("%d", &N); if (N<=0) goto G2010; M = 2*N+1; FC = sqrt(FS*FP); R=FC+FC; for ( K=1;K<=2;K++) { S=FS+FP; for( J= 1; J<=6; J++) { P=sqrt(S*R); S=(S+R)/2.0; if (1.0e+08*(S-P) =2) goto G2200; Q=( (double) M)/S; R=fabs(FS-FP); } G2200: Q=Q*S; S=exp(-PI/Q); Y=S; printf("Critical Q= %lf\n", Q/(4.0*(1.0-S)*pow(S,(double) N)) ); printf("Stopband rejection (dB) = "); scanf("%lf", &S); if (S<=0.0) goto G2010; S=exp(S*DN/2.0); R=exp(PI*Q); P=(log(1.0+(S*S-1.0)/( pow((R/4.0+1.0/R),2.0) )) )/DN; printf( "Passband Ripple(dB)= %lf\n",P); R=R/(2.0*(S+sqrt(S*S-1.0))); R=log(R+sqrt(R*R+1.0))/(2.0*Q); R=sin(R)/cos(R); W=R; printf( "3 dB (kHz) about= %lf\n", FP+(FS-FP)/(1+FC/(FP*R*R)) ); printf( "Nominal ohms resistance="); scanf("%lf", &R); if (R<=0.0) goto G5555; Z=Y; E[N]=W; W=W*W; for (J=1; J<= M-1; J++) { F[J]=1; } K=1; for (J=1; J <= 1024; J++) { F[K]=F[K]*(1-Z)/(1+Z); if (K