/* File name: FilterWrapper.c 29Feb2004 .. created from Fall 2003 code .. K.Metzger */ #include #define DATA short int #define ushort unsigned short // Support for various filter functions void delay(unsigned); short (*pFunction)(DATA*, DATA*, DATA*, DATA*, ushort, ushort); short fir(DATA*, DATA*, DATA*, DATA*, ushort, ushort); short iircas5(DATA*, DATA*, DATA*, DATA*, ushort, ushort); short myDF2IIR(DATA*, DATA*, DATA*, DATA*, ushort, ushort); short myTDF2IIR(DATA*, DATA*, DATA*, DATA*, ushort, ushort); // need to uncomment this short none(DATA*, DATA*, DATA*, DATA*, ushort, ushort); /* Filter coefficients */ // Equiripple FIR design #define int16_T int #include "FIR145.h" #define FIR_coeffs B #define NH (sizeof(FIR_coeffs)/sizeof(int)) #pragma DATA_ALIGN(db,2048); // overkill short int db[NH+2]; // will also use for IIR filter buffer unsigned nFIR_coeffs=NH; // IIR filter SOS coefficients are ordered: b0 b1 b2 a1 a2 // // b values are to be normalized tf2sos values integerized // after multiplying by 2^15. // // a values are to be tf2sos values integerized after // multiplying by 2^15. Except does not include the a0 values. // // Sections are ordered from input to output. // define names for the IIR SOS coefficient column positions #define b0 0 #define b1 1 #define b2 2 #define a1 3 #define a2 4 // Chebyshev 1 IIR design .. your values go here! long C1_coeffs[] ={ }; unsigned nC1_coeffs = (sizeof(C1_coeffs)/sizeof(long)); // Chebyshev 2 IIR design .. your values go here! long C2_coeffs[] = { }; unsigned nC2_coeffs = (sizeof(C2_coeffs)/sizeof(long)); // Elliptic IIR design .. your values go here! long El_coeffs[] = { // 1481, 2581, 1481, -45021, 17796, // test values using the // 8147, 5622, 8147, -33995, 23142, // FDAtool default design // 17616, 1500, 17616, -24248, 28212, // parameters and elliptic // 23728, -3146, 23728, -19933, 31474 // your elliptic goes here }; unsigned nEl_coeffs = (sizeof(El_coeffs)/sizeof(long)); short int *ptr_coeffs; short int coeffs[5*24]; // to hold IIR coeffs...make sure correct size or larger !!!! short int FilterType; ushort nSections; void FilterSetup(void) { int IIRtype, TFtype, idx; long* sections; // First ask if no filter, FIR filter or IIR filter. while (1) { printf("Enter (0=none, 1=FIR, 2=IIR): "); scanf("%d", &FilterType); if (FilterType<0) continue; // If IIR ask which function to use. if (FilterType > 1) { printf("Enter (0=IIRCAS5, 1=myDF2IIR, 2=myTDF2IIR): "); scanf("%d",&IIRtype); if (IIRtype<0) continue; // Finally, ask which TF type to use. printf("Enter TF type: (0=Cheby 1, 1=Cheby 2, 2=Elliptic): "); scanf("%d",&TFtype); if (TFtype<0) continue; } fflush(stdin); ptr_coeffs = coeffs; // set up default pointer to IIR coeffs if (FilterType==0) { pFunction = &none; } else if (FilterType==1) { IIRtype = -1; pFunction = &fir; nSections = nFIR_coeffs; ptr_coeffs = (short int*)FIR_coeffs; // change to point to fir coeffs printf("FIR with %d coefficients\n", nSections); } else if (TFtype==0) { // Chebyshev 1 nSections = nC1_coeffs/5; sections = C1_coeffs; printf("Chebyshev type 1 of order %d\n", 2*nSections); } else if (TFtype==1) { // Chebyshev 2 nSections = nC2_coeffs/5; sections = C2_coeffs; printf("Chebyshev type 2 of order %d\n", 2*nSections); } else { // Elliptic nSections = nEl_coeffs/5; sections = El_coeffs; printf("Elliptic of order %d\n", 2*nSections); } // The iircas5 function and the iircast5 function are // optimized to have the b and a coefficient values in // a particular order. The long values defined at the // start of this code are to reordered and a1 divided // by 2 and then converted to 16-bit form. if (FilterType == 0) { printf("straight through\n"); } else if (FilterType == 1) { printf("FIR\n"); } else if (IIRtype == 0) { // iircas5 DF2 filter printf("IIRCAS5 DF2\n"); pFunction = &iircas5; // don't forget to divide the a1 values by 2 for (idx=0; idx