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;
}
January 18, 2014
by scootergarrett
scootergarrett's Avatar

sorry for the double post I got an error the first time, so I re did it only to find out the first one worked. Nerdkits web site is little wacky. Any ways lets use this one thread

January 19, 2014
by esoderberg
esoderberg's Avatar

Scooter,

Probably more than you need, but complex number functions included here: science library

Eric

Post a Reply

Please log in to post a reply.

Did you know that the microcontroller's crystal oscillator can be used to keep accurate time? Learn more...