Digital Signal Processing Reference
In-Depth Information
This memory allocation can be done prior to calling the individual functions and
thereby eliminate the requirement of memory allocation in each of the individual
functions.
The component calculation functions are very similar to one another although
the equations for component values are somewhat different. For that reason, only
the Calc_LP_Comps function shown in Listing F.1 will be discussed here. The
work within the function begins by initializing the variable K_Total , which will
store the product of all stage K s. Then, if a first-order stage is required, the R and
C values for it are calculated and start is set to 1. Then, the component values
for the stages implementing the quadratic factors are calculated within the for
loop, which has a starting index of start . The coefficients from the
Filt_Params structure are retrieved, and the common values of C and R A are
placed in the RC_Comps structure. Then a determination has to be made within a
switch statement as to whether a filter with complex conjugate zeros will be
required. If the zeros are not required, the calculations are made and the process
continues. However, if complex conjugate zeros are required, it must be decided
whether a resistor, capacitor, or no additional value is necessary.
The loop will continue its iterations until all stage components have been
determined. Once the loop finishes, the gain adjustment factor can be determined
and the voltage divider components can be calculated. If the gain adjustment is
exactly 1, no values are calculated since a division by zero would result.
/*====================================================
Calc_LP_Comps() - calculates the component values
for lowpass analog active filter.
Prototype: int Calc_LP_Comps(Filt_Params *FP,
RC_Comps *RC,double C,double Ra);
Return: error value
Arguments: FP - ptr to struct holding filter params
RC - ptr to struct holding RC components
C - capacitor value for all stages
Ra - feedback resistor for all stages
====================================================*/
int Calc_LP_Comps(Filt_Params *FP,RC_Comps *RC,
double C,double Ra)
{ int i,start; /* Loop counter and start pt*/
double K,K_Total, /* K value and total */
Gain_Adj, /* Gain adjustment factor */
a2,a2r, /* Numerator constants */
b1,b2,b2r; /* Denominator constants */
/* Initialize K total */
K_Total = 1;
/* If order is odd, determine R & C values for
first-order stage and set start to 1 */
start = 0;
if(FP->order % 2)
{ RC->C[0] = C;
RC->R[0] = 1 / (C * FP->bcoefs[2]);
RC->Ra[0] = Ra;
start = 1;
}
/* Determine values for second-order stages */
Search WWH ::




Custom Search