# Thread: How to implement Complex exponential functions in C ???

1. ## How to implement Complex exponential functions in C ???

Hi everyone

I am trying to write a code for an IIR filter. And for that purpose i need to implement the below funtion in C :-

out[n] = in[n] - ((b1 * e^jw * out[n-1]) + (b2 * e^2jw * out[n-2]))
Now, am facing problem ... wel rather i have no idea , as to how to implement the e^jw function. The value of w is known to me and n = the sample number.

It would be great if anyone could help me out.
Thanks a lot !!

2. What is j ? And further, you might want to have a look at :

math.h

3. Remember that e^jw = cos(w) + j*sin(w). You don't actually take the complex exponential.

EDIT: Or rather, you ARE taking it, but you are taking it via Euler's formula.

4. Originally Posted by brewbuck
Remember that e^jw = cos(w) + j*sin(w). You don't actually take the complex exponential.

EDIT: Or rather, you ARE taking it, but you are taking it via Euler's formula.
Hey ,
unfortunately i need to consider the complex part too , as its a digital IIR filter that i need to implement , and for that i can't ignore the imaginary part ...

5. Originally Posted by Clueless@work
Hey ,
unfortunately i need to consider the complex part too , as its a digital IIR filter that i need to implement , and for that i can't ignore the imaginary part ...
What makes you think that formula "ignores" the imaginary part?

The value e^jw is a complex number. The real part of this number is cos(w). The imaginary part is j*sin(w).

If you don't know this stuff you're going to get stuck.

6. > The value e^jw is a complex number. The real part of this number is cos(w). The imaginary part is j*sin(w).
The formula is true for any w, but if w isn't real, then he needs to know how to compute cos(w) and sin(w) for complex w, so it doesn't help. The formula

e^(x+jy) = (e^x)*(cos(y) + j*sin(y))

for real x and y should be more useful. It's just a matter of separating out the real and imaginary parts of jw.

Edit: I'm not sure I understood the OP's comment - is w real or complex? If it's real then the point is moot.

7. Originally Posted by robatino
The formula is true for any w, but if w isn't real, then he needs to know how to compute cos(w) and sin(w) for complex w, so it doesn't help.
I'm assuming the guy at least understands the distributive property for exponentials. If he doesn't, I'm afraid nothing we can say is going to help. You just can't do this stuff without understanding what you're doing.

8. Yes, I do understand the Euler's theorem and all about the exponential functions... But i wanna know the C command line for implementing the complex exponential function.

9. Just use exp(), cos() and sin().

10. There is no standard function for computing the complex exponential. I'm afraid that in order to accomplish what you want to do, you'll have to create a structure, and then store you complex results in those structures.

11. Is C99 available to you and implemented?
http://web.archive.org/web/200502070...aft.html#7.3.7