Go Down

### Topic: Number complex (Read 2035 times)previous topic - next topic

#### taurian

##### Mar 07, 2012, 06:01 pmLast 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

#1
##### Mar 07, 2012, 06:07 pm
Quote
I'm new to working with arduino I wanted to add two complex numbers:

Just like you would on any other computer.

#### el_supremo

#2
##### Mar 07, 2012, 06:19 pm
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)=civoid 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+bvoid 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

#3
##### Mar 07, 2012, 06:26 pm
I want to do the DFT definition through the arduino so I use complex numbers.

thank you Gil

#### PaulS

#4
##### Mar 07, 2012, 06:33 pm
Quote
I want to do the DFT definition through the arduino

The what?

#### el_supremo

#5
##### Mar 07, 2012, 06:39 pm
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

#6
##### Mar 07, 2012, 06:44 pm
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.

#### robtillaart

#7
##### Mar 07, 2012, 08:11 pm

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 pmLast 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

#9
##### Mar 08, 2012, 01:51 pm
Perhaps you should try writing the function in C, instead of Basic.

#### taurian

#10
##### Mar 08, 2012, 03:18 pm
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

#11
##### Mar 08, 2012, 03:52 pm
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

#12
##### Mar 08, 2012, 03:58 pm
You should consider merging the threads you have on this subject into one.

#### taurian

#13
##### Mar 08, 2012, 03:59 pm
yeah. I making the code in C or C + + how can I convert to the arduino?

thank Gil

#### taurian

#14
##### Mar 08, 2012, 04:04 pm
"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