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

  1. #1
    Registered User
    Join Date
    Apr 2007
    Posts
    7

    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 !!
    Last edited by Clueless@work; 04-25-2007 at 10:10 AM. Reason: missed a plus sign

  2. #2
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    What is j ? And further, you might want to have a look at :

    math.h
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  3. #3
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,398
    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.
    Last edited by brewbuck; 04-25-2007 at 10:41 AM.

  4. #4
    Registered User
    Join Date
    Apr 2007
    Posts
    7
    Quote Originally Posted by brewbuck View Post
    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. #5
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,398
    Quote Originally Posted by Clueless@work View Post
    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. #6
    Registered User
    Join Date
    Sep 2006
    Posts
    835
    > 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.
    Last edited by robatino; 04-25-2007 at 11:16 AM.

  7. #7
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,398
    Quote Originally Posted by robatino View Post
    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. #8
    Registered User
    Join Date
    Apr 2007
    Posts
    7
    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. #9
    Registered User
    Join Date
    Sep 2006
    Posts
    835
    Just use exp(), cos() and sin().

  10. #10
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    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.
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  11. #11
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,005
    Is C99 available to you and implemented?
    http://web.archive.org/web/200502070...aft.html#7.3.7
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. An array of macro functions?
    By someprogr in forum C Programming
    Replies: 6
    Last Post: 01-28-2009, 07:05 PM
  2. Replies: 7
    Last Post: 11-17-2008, 01:00 PM
  3. im extreamly new help
    By rigo305 in forum C++ Programming
    Replies: 27
    Last Post: 04-23-2004, 11:22 PM
  4. Passing pointers between functions
    By heygirls_uk in forum C Programming
    Replies: 5
    Last Post: 01-09-2004, 06:58 PM
  5. Passing data/pointers between functions #2
    By TankCDR in forum C Programming
    Replies: 1
    Last Post: 11-02-2001, 09:49 PM