NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » complex library

January 18, 2014
by scootergarrett
scootergarrett's Avatar

Is there a complex library for the Nerdkits? I'm doing some IIR filter stuff and I need complex math. I know I can make my own which I started, but someone else could probably do a better job.

here is my complex.h file so far

    struct Comp
    {
        double Re;
        double Im;
    };

    struct Comp AddComplex(struct Comp A, struct Comp B)
    {
        struct Comp D;

        D.Re = A.Re + B.Re;
        D.Im = A.Im + B.Im;

        return D;
    }

    struct Comp MulComplex(struct Comp A, struct Comp B)
    {
        struct Comp D;

        D.Re = A.Re*B.Re - A.Im*B.Im;
        D.Im = A.Re*B.Im + A.Im*B.Re;

        return D;
    }

Post a Reply

Please log in to post a reply.

Did you know that spinning a permanent magnet motor makes a voltage? Learn more...