Digital Signal Processing Reference
In-Depth Information
After calculating the constant rad2deg for converting radians to degrees,
the primary work of the function is performed within two nested for loops. The
outer loop controls the frequency at which the response is being calculated, while
the inner loop steps through the number of quadratics in the approximation
function. As we start the calculation for a new frequency, the magnitude value
( RP->magna[f] ) is initialized to the overall gain value of the filter, while the
phase value ( RP->angle[f] ) is set to 0. We then convert to radian frequencies
and make the calculation of the radian frequency squared outside the quadratic
loop. That saves time by not repeatedly making those calculations inside the loop
where there is no change in their value.
Once we reach the inner quadratic loop, which is controlled by the variable q ,
we define a value c that is based on q to help access the individual coefficients of
each quadratic. We first handle the numerator portion of the quadratic by
determining the real and imaginary parts of the complex number. Then the total
magnitude is multiplied by the magnitude of the complex number, and the total
angle is incremented by the angle of the complex number.
A similar process is performed for the denominator portion of the quadratic
except that the total magnitude is divided by the denominator's magnitude, and the
denominator's phase is subtracted from the total phase. This inner loop process is
repeated for all of the quadratic terms, and then the phase value is converted to
degrees outside the quadratic loop.
If the magnitude of the response was specified to be in decibels, each of the
magnitude values is converted to decibels before leaving the function. Since the
logarithm of zero is undefined, an artificial value ZERO is defined in
F_RESPON.H so that no math error will be produced by the compiler if values
become too small. Since we are using type double to describe the magnitude
values, a value of 1E-30 was chosen for ZERO that is still within the limits of
expression for doubles. This value will produce a gain value of −600 dB, which is
well beyond the normal levels of gain we expect in filter design, so our definition
of ZERO should have no effect on the normal operation of the program.
3.6 SAVING THE FILTER PARAMETERS
Once a filter has been designed, WFilter can save it. The saved file can then be
used by other software programs to identify the values of the filter gain,
coefficients, and other characteristics of the filter, or the filter can be reloaded into
WFilter for continued work. The structure of this WFilter binary data file is
therefore included below.
A binary file has a number of advantages over a text file in this situation.
First, the binary file will be easier to read if the data is needed by another program.
There is a very good chance that the filter designer will want to transfer the filter
coefficients that have been determined by WFilter to another program for testing
Search WWH ::




Custom Search