Digital Signal Processing Reference
In-Depth Information
The primary function for the calculation of the analog frequency response is
Calc_Analog_Resp, which is shown in Listing 3.1. (The set of frequencies
used to evaluate the filter have already been calculated and stored in RP->freq .)
/*====================================================
Calc_Analog_Resp() - calcs response for analog filts
Prototype: int Calc_Analog_Resp(Filt_Params *FP,
Resp_Params *RP);
Return: error value
Arguments: FP - ptr to struct holding filter params
RP - ptr to struct holding respon params
====================================================*/
int Calc_Analog_Resp(Filt_Params *FP,Resp_Params *RP)
{ int c,f,q; /* loop counters */
double rad2deg, /* rad to deg conversion */
omega,omega2, /* radian freq and square */
rea,img; /* real and imag part */
rad2deg = 180.0 / PI; /* set rad2deg */
/* Loop through each of the frequencies */
for(f = 0 ;f < RP->tot_pts; f++)
{ /* Initialize magna and angle */
RP->magna[f] = FP->gain;
RP->angle[f] = 0.0;
/* Pre calc omega and omega squared */
omega = PI2 * RP->freq[f];
omega2 = omega * omega;
/* Loop through coefs for each quadratic */
for(q = 0 ;q < (FP->order+1)/2; q++)
{ /* c is coef index = 3 * quad index */
c = q * 3;
/* Numerator values */
rea = FP->acoefs[c+2] - FP->acoefs[c] * omega2;
img = FP->acoefs[c+1] * omega;
RP->magna[f] *= sqrt(rea*rea + img*img);
RP->angle[f] += atan2(img,rea);
/* Denominator values */
rea = FP->bcoefs[c+2] - FP->bcoefs[c] * omega2;
img = FP->bcoefs[c+1] * omega;
RP->magna[f] /= sqrt(rea*rea + img*img);
RP->angle[f] -= atan2(img,rea);
}
/* Convert to degrees */
RP->angle[f] *= rad2deg;
}
/* Convert magnitude response to dB if indicated */
if(RP->mag_axis == LOG)
{ for(f = 0 ;f < RP->tot_pts; f++)
{ /* Handle very small numbers */
if(RP->magna[f] < ZERO)
{ RP->magna[f] = ZERO;}
RP->magna[f] = 20 * log10(RP->magna[f]);
}
}
return ERR_NONE;
}
Listing 3.1 Calc_Analog_Resp function .
Search WWH ::




Custom Search