DSPRelated.com
Forums

DSP, IIR filter C/C++ Code, Need Help

Started by Deepak October 24, 2004
Hi,

I am running into a problem, and that is developing a C code for
TMS320C6713 DSP processor. The application requires coding of a
complex valued IIR filter.
The filter equation is:

H(z) = 1/(1+ SUM(i=1:8) (Ai Z^-i))

Hoopefully you can understand the above equation, the SUM is actually
summation sign (SIGMA) and (i= 1:8) is lower and upper limit of the
sigma.
I have precalculated coefficients of the filter (Ai's) and they are
all complex.

Now the design requirement is:

A complex valued signal of gaussian distribution is passes through
this filter. No as C doesn't support gaussian random variates, I have
a standard algorithm to convert the output of Rand() function which
are uniformly distributed, into Gaussian distribution. How do I really
write a C code for this application. I have tried and it doesn't work.
I created a structure of complex type for handling complex math, such
as assigning a complex value, complex add, subtraction and
multiplication.

If anybody is eager to help me out, please respond to this message or
email me at kumar.dk@gmail.com    I would even provide better
documentation to make you better understand the problem.

Thank you in advance,
Deepak
Deepak wrote:
> Hi, > > I am running into a problem, and that is developing a C code for > TMS320C6713 DSP processor. The application requires coding of a > complex valued IIR filter. > The filter equation is: > > H(z) = 1/(1+ SUM(i=1:8) (Ai Z^-i)) > > Hoopefully you can understand the above equation, the SUM is actually > summation sign (SIGMA) and (i= 1:8) is lower and upper limit of the > sigma. > I have precalculated coefficients of the filter (Ai's) and they are > all complex. > > Now the design requirement is: > > A complex valued signal of gaussian distribution is passes through > this filter. No as C doesn't support gaussian random variates, I have > a standard algorithm to convert the output of Rand() function which > are uniformly distributed, into Gaussian distribution. How do I really > write a C code for this application. I have tried and it doesn't work. > I created a structure of complex type for handling complex math, such > as assigning a complex value, complex add, subtraction and > multiplication. > > If anybody is eager to help me out, please respond to this message or > email me at kumar.dk@gmail.com I would even provide better > documentation to make you better understand the problem. > > Thank you in advance, > Deepak
See section 3 of http://www.wescottdesign.com/articles/zTransform/z-transforms.html -- it shows how to make a filter from a transfer function. Translating this to complex coefficients should be trivial. Two notes: One: You _do not_ want to use a direct-form filter! You'll want to factor your polynomial and make a cascade of eight first-order filters -- the article explains why. Two: The C++ standard math library includes a complex type. Assuming that you can use C++ and that TI has followed the standard for your processor you should use it. Otherwise a set of C code will do OK, at the cost of less readable code. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com
Tim Wescott wrote:

> ... You'll want to > factor your polynomial and make a cascade of eight first-order filters
How does one get complex ans zeros poles with first-order sections? Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Jerry Avins wrote:

> Tim Wescott wrote: > > >>... You'll want to >>factor your polynomial and make a cascade of eight first-order filters > > > How does one get complex ans zeros poles with first-order sections? > > Jerry
I wrote that?!!! How does one get complex poles and zeros with first-order sections? -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Jerry Avins wrote:

>>>... You'll want to >>>factor your polynomial and make a cascade of eight first-order filters >> >>How does one get complex ans zeros poles with first-order sections? >> >>Jerry > > I wrote that?!!!
Well, I didn't want to go rub it on your face, but since you brought it up...... ;-) Carlos --
Jerry Avins wrote:

> Tim Wescott wrote: > > >>... You'll want to >>factor your polynomial and make a cascade of eight first-order filters > > > How does one get complex ans zeros poles with first-order sections? > > Jerry
Jerry: Y'know, I was assuming that since he has a complex input signal that his poles were not matched up into nice tidy conjugate pairs -- which may or may not be the case. At any rate, if you allow complex arithmetic you get a complex pole in a 1st-order section by having a transfer function 1/(z-d) with d complex. It requires nearly as much computation as a 2nd-order transfer function with a conjugate pair and it requires a complex math type but it does allow you to do computations with non-conjugate poles. Ahh, assumptions, assumptions. Deepak: Is your transfer function strictly real valued, with only complex data to process, or are the A_i complex as well? If all of the A_i are real-valued then you'll want to process the real and imaginary parts of your input separately (but with the same transfer function), and make your filter as a cascade of 1st- and 2nd-order fully-real valued transfer functions. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com