Digital Signal Processing Reference
In-Depth Information
/*====================================================
Unnorm_LP_Coefs() - converts normal lowpass coefs to
unnormal LP coefs at a specific freq.
Prototype: int Unnorm_LP_Coefs(Filt_Params *FP,
double freq);
Return: error value
Arguments: FP - ptr to struct holding filter params
freq - unnormalization frequency
====================================================*/
int Unnorm_LP_Coefs(Filt_Params *FP,double freq)
{ int qd,cf, /* quad and coef number */
qd_start; /* starting quad for loop */
/* Handle first-order, if odd; set qd_start */
if(FP->order % 2)
{ FP->acoefs[2] *= freq;
FP->bcoefs[2] *= freq;
qd_start = 1;
}
else
{ qd_start = 0;}
/* Handle quadratic factors, qd indexes through
quadratic factors, cf converts to coef number */
for(qd = qd_start; qd < (FP->order + 1)/2; qd++)
{ cf = qd * 3;
FP->acoefs[cf+1] *= freq;
FP->acoefs[cf+2] *= (freq * freq);
FP->bcoefs[cf+1] *= freq;
FP->bcoefs[cf+2] *= (freq * freq);
}
return ERR_NONE;
}
Listing E.2 Unnorm_LP_Coefs function.
Listing E.3 shown below gives the Unnorm_BP_Coefs function. This
function and the Unnorm_BS_Coefs function are more complicated than the
lowpass and highpass functions. One of the ways that these functions are more
complicated is that the coefficient arrays must be resized to hold the larger number
of coefficients for a bandpass function. (Remember that for bandpass and
bandstop filters, the final order will be twice the original lowpass normalized
order.) Thus, early in this function, variables from the original lowpass function
are stored as well as the new order of the bandpass function. Then new pointers to
the larger arrays of bandpass coefficients are assigned while leaving the original
pointers unchanged. Throughout this function new_num , new_den , org_num
and org_den are used to identify the new and original numerator and
denominator coefficients, respectively. As in previous functions, we handle the
first-order factors before the second-order factors. The values assigned to the new
coefficients are the same as we determined in Section 3.3.
Search WWH ::




Custom Search