complex signal, in C/C++

Thread Starter

sddfds

Joined Jan 9, 2022
2
hello i would like to ask how to generate the complex signal f(t)=exp^(j*omega*t), j=sqrt(-1), in C/C++. thanks very much.
 

Papabravo

Joined Feb 24, 2006
18,456
You define the complex data type, and use Euler's identity to compute the values in a for loop.

\( e^{j\omega t}\;=\;cos(\omega t)\;+\;jsin(\omega t) \)

If you plot this function it will be a circle centered on the origin in the complex plane. It will repeat for

\( \omega t \;=\;2n\pi,\;\text {where n is an integer} \)
 
Last edited:

click_here

Joined Sep 22, 2020
544
Just the real and imaginary numbers being printed to the screen? Or being streamed to something else?

Are you familiar with the <complex.h> and <math.h> headers in C?
 

Thread Starter

sddfds

Joined Jan 9, 2022
2
Just the real and imaginary numbers being printed to the screen? Or being streamed to something else?

Are you familiar with the <complex.h> and <math.h> headers in C?
the values are being sent to the arduino. i will have a look at <complex.h> and <math.h>. thanks a lot.
 

click_here

Joined Sep 22, 2020
544
Here is a basic example
complex example:
#include <stdio.h>
#include <math.h>
#include <complex.h>

int main(void)
{
    const double pi = acos(-1.0);

    for(double t = 0.0; t <= 2*pi; t += 0.01)
    {
        double complex z = t * I;
        double complex f = cexp(z);

        printf("%.2f%+.2fi\n", creal(f), cimag(f));
    }

    return 0;
}
If you really want to use 'j' instead of 'I' for the imaginary numbers, you can do this...
Code:
#undef I
#define j _Complex_I
... But be warned that i/j/k are very commonly used as iterations in for loops, so I'd advise not to do it
 
Top