Digital Signal Processing Reference
In-Depth Information
ω
1
a
ω
=
2
f
tan
d
s
2
f
s
(G.2)
/*====================================================
Calc_DigIIR_Coefs() - calcs digital IIR coefs
Prototype: int Calc_DigIIR_Coefs(Filt_Params *FP);
Return: error value
Arguments: FP - ptr to struct holding filter params
====================================================*/
int Calc_DigIIR_Coefs(Filt_Params *FP)
{ int Error; /* error value */
/* Pre-warp frequencies before making calcs */
Error = Warp_Freqs(FP);
if(Error) { return 10*Error+1;}
/* Calc order and coefs, then unnormalized coefs */
Error = Calc_Filter_Order(FP);
if(Error) { return 10*Error+2;}
Error = Calc_Normal_Coefs(FP);
if(Error) { return 10*Error+3;}
Error = Unnormalize_Coefs(FP);
if(Error) { return 10*Error+4;}
/* Transform from s-domain to z-domain */
Error = Bilinear_Transform(FP);
if(Error) { return 10*Error+5;}
/* Put the critical freqs back to orig value */
Error = UnWarp_Freqs(FP);
if(Error) { return 10*Error+6;}
return ERR_NONE;
}
Listing G.1 Calc_DigIIR_Coefs function.
The objective of the Bilinear_Transform function shown in Listing G.2
is to implement the transformation from an analog transfer function to a digital
transfer function. A check that the acoefs and bcoefs arrays actually exist is
made first in the function. Then, constants that will be used often are calculated
and stored in f2 and f4 . And, finally, the number of quadratics is calculated as
well as a starting point for the quadratic loop. If the order of the filter is odd, then
a first-order term is handled, and start is set to 1. Notice that start controls
which quadratic factor will start the process. If a first-order factor (which is stored
as a quadratic) has already been processed, the for loop will start with the second
quadratic (if one is present). The actual transformation calculations are handled in
exactly the same manner as derived in (6.20) to (6.25). Also notice that the total
gain of the filter is adjusted in the first-order case as well as in the quadratic loop.
By the end of the function, all gain adjustments have been included and the analog
coefficients have been replaced by digital IIR coefficients.
Search WWH ::




Custom Search