Digital Signal Processing Reference
In-Depth Information
/*====================================================
Calc_DigFIR_Coefs() - calcs the digital FIR coefs
Prototype: int Calc_DigFIR_Coefs(Filt_Params *FP);
Return: error value
Arguments: FP - ptr to struct holding filter params
====================================================*/
int Calc_DigFIR_Coefs(Filt_Params *FP)
{ char ans;
int Error; /* error value */
double beta; /* parameter for Kaiser window */
/* Estimate the length (order) of filter.
Get beta for Kaiser window, if needed. */
beta = Estm_Filter_Len(FP);
/* See if user wants to adjust estimated length */
printf("\n Filter length is estimated as %d.", FP->order);
ans = Get_YN("\n Do you wish to change it? (Y/N):");
if(ans == 'Y')
{ FP->order = Get_Int("\n Please enter new length: ",0,500);}
/* Allocate memory for coefficients. */
FP->acoefs =
(double *) malloc(FP->order * sizeof(double));
if(!FP->acoefs) { return ERR_ALLOC;}
FP->bcoefs = (double *) malloc(FP->order * sizeof(double));
if(!FP->bcoefs) { return ERR_ALLOC;}
/* Set overall gain to 1.0 */
FP->gain = 1.0;
/* Calculate the ideal FIR coefficients
but not for Parks-McClellan. */
if(FP->approx != '6')
{ Error = Calc_Ideal_FIR_Coefs(FP);
if(Error) { return 10*Error+1;}
}
/* Determine the approximation method to use. */
switch(FP->approx)
{ case '0': Error = Calc_Rect_Win_Coefs(FP);
if(Error) { return 10*Error+2;} break;
case '1': Error = Calc_Bart_Win_Coefs(FP);
if(Error) { return 10*Error+3;} break;
case '2': Error = Calc_Blck_Win_Coefs(FP);
if(Error) { return 10*Error+4;} break;
case '3': Error = Calc_Hamm_Win_Coefs(FP);
if(Error) { return 10*Error+5;} break;
case '4': Error = Calc_Hann_Win_Coefs(FP);
if(Error) { return 10*Error+6;} break;
case '5': Error = Calc_Kais_Win_Coefs(FP,beta);
if(Error) { return 10*Error+7;} break;
case '6': Error = Calc_ParkMccl_Coefs(FP);
if(Error) { return 10*Error+8;} break;
default: return ERR_FILTER;
}
/* Multiply window and ideal coefs only for
but not for Parks-McClellan coefficients */
if(FP->approx != '6')
{ Error = Mult_Win_Ideal_Coefs(FP);
if(Error) { return 10*Error+9;}
}
return ERR_NONE;
}
Listing H.1 Calc_DigFIR_Coefs function.
Search WWH ::




Custom Search