Digital Signal Processing Reference
In-Depth Information
to use them in the solution of the unnormalization of bandpass and bandstop
coefficients, we will have to define our own complex number definition. A
complex number can easily be defined with a structure using a real and imaginary
member as shown below.
typedef struct
{ double re, /* Real part of complex number */
im; /* Imag part of complex number */
} complex;
Using this complex struct will allow us to define any variables we like as
type complex . For example, in the variable declaration section of the function
we are studying now, the variables A , B , C , D , and E are defined as complex as
shown below.
complex A,B,C,D,E; /* temp cmplx vars */
Within the \C_CODE\FILTER\COMPLEX.C module there are a number of
complex functions defined to implement standard mathematical functions for
complex numbers. A list of the functions is shown below. We do not have space
to study them here, but the full module is contained on the software disc included
with this text.
cadd() — adds complex numbers and returns result.
cang() — returns angle (radians) of a complex number.
cconj() — returns complex conjugate of a complex number.
cdiv() — divides complex numbers and returns result.
cimag() — returns imaginary part of a complex number.
cmag() — returns the magnitude of a complex number.
cmplx() — returns complex number made from two doubles.
cmul() — multiplies complex numbers and returns result.
cneg() — returns the negative of a complex number.
cprt() — prints the value of a complex number.
cQuadratic() — factors quadratic eqn. with complex coefficients.
creal() — returns real part of a complex number.
csqr() — returns the square root of a complex number.
csub() — subtracts complex numbers and returns result.
As an example of one of these complex functions, cadd is shown in Listing
E.4. As indicated in the listing, cadd takes two complex numbers as arguments
and adds their respective real and imaginary parts. The new complex number x is
then returned to the calling function.
Another complex function is shown in Listing E.5 below. cQuadratic
takes five arguments, all of which are complex or point to complex numbers. The
first three arguments, a , b , and c , are the coefficients of a quadratic equation,
while d and e are the addresses where the factors of the quadratic equation are to
be stored. Each line of the function makes a partial calculation of the quadratic
formula, but using complex functions. The final results are then stored where the
Search WWH ::




Custom Search