Go Down

Topic: Number complex (Read 1 time) previous topic - next topic

taurian

Mar 07, 2012, 06:01 pm Last Edit: Mar 07, 2012, 06:19 pm by taurian Reason: 1
hello
I'm new to working with arduino I wanted to add two complex numbers:
(a + bi) + (a + bi)
how can I do this.

Thanks Gil

PaulS

Quote
I'm new to working with arduino I wanted to add two complex numbers:

Just like you would on any other computer.
The art of getting good answers lies in asking good questions.

el_supremo

Here's a simple piece of code which uses complex numbers.
Code: [Select]

struct complex {
  double r;
  double i;
} a,b,c;

// Set a complex number. Real(p)=cr, Imag(p)=ci
void set_complex(struct complex *p,double cr,double ci)
{
  p->r = cr;
  p->i = ci;
}

// Add two complex numbers and place the result in a third
// c = a+b
void add_complex(struct complex *c,struct complex *a,struct complex *b)
{
  c->r = a->r + b->r;
  c->i = a->i + b->i;
}
void setup(void)
{
  Serial.begin(9600);
 
  // Set a to (1,2)
  set_complex(&a,1,2);
  // set b to (3.2,-4.1)
  set_complex(&b,3.2,-4.1);
  // add a and b and put the result in c
  add_complex(&c,&a,&b);
  // Now print c
  Serial.print("c = ");
  Serial.print(c.r,1);
  if(c.i >= 0)Serial.print("+");
  Serial.print(c.i,1);
  Serial.println("i");
}

void loop(void)
{
}


But assuming you can add the two complex numbers, what are you going to do with the result?

Pete
Don't send me technical questions via Private Message.

taurian

I want to do the DFT definition through the arduino so I use complex numbers.

thank you Gil

PaulS

Quote
I want to do the DFT definition through the arduino

The what?
The art of getting good answers lies in asking good questions.

el_supremo

Good luck with that.
Have a look at this thread, which has code to do a fixed-point DFT.
http://arduino.cc/forum/index.php/topic,72729.0.html

Pete
Don't send me technical questions via Private Message.

PaulS

I looked up DFT - Detroit Fine Theater. I can't imagine how you can do that on the Arduino, or what complex numbers have to do with it.
The art of getting good answers lies in asking good questions.

robtillaart


A nice complex number class, here is a starter - http://www.dreamincode.net/code/snippet75.htm -
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

taurian

#8
Mar 07, 2012, 11:27 pm Last Edit: Mar 08, 2012, 01:17 pm by taurian Reason: 1
hello

I made this function to calculate the DFT (discrete Fourier transform) but I do not run the arduino has errors the compiler does not interpret the (I> complex number)

X=zeros(1,N);
for k=0:N-1
    a=zeros(1,N);
    for n=0:N-1
        a(n+1)=x(n+1)*exp(-(1i*2*pi*n*k)/N);
    end
     X(k+1)=sum(a);


thank you Gil

PaulS

Perhaps you should try writing the function in C, instead of Basic.
The art of getting good answers lies in asking good questions.

taurian

Hello,

In language C i dont know what the libraries that i have to use. Arduino doesn´t uses C language its a bit diferent, then i have a C function maybe i can develope one for Arduino.

Can you help me?

Thanks Gil

pYro_65

Quote
Arduino doesn´t uses C language its a bit diferent

Nope, its C and C++. There is no 'Arduino specific' language, it is just a C style API for use with Arduino boards.
Forum Mod anyone?
https://arduino.land/Moduino/

dxw00d

You should consider merging the threads you have on this subject into one.

taurian

yeah. I making the code in C or C + + how can I convert to the arduino?
 

thank Gil

taurian

"You should consider merging the threads you have on this subject into one"

I was wrong and I put 2 Posts
sorry I'll join the two

thank Gil

Go Up