# Reading voltage from sin wave

Hy,

i am doing a project "Clip indicator" for car audio. I already done the hardware but now i have problem with programming...(i am begginer, but i know the basics of java, c itd). I bought Arduino Duemilanove and try all the tutorials but i need your help. I want to read 2 sinus(40Hz) values/voltage from my indicator and devide them with each other. Let's say v1 and v2. And if it goes to 1 LED is ON and if it goes to infinity LED is OFF or print to LCD some message.

v1/v2 --> 1 LED on v1/v2 --> ? LED OFF

Both of values are in range of mV so it's not problem to read with arduino because it has range 0-5V. Please any help how to begin.

Thank you

Could be describe more details, what signals comming from, and what math formula? Why it goes to infinity, v2 stay close to "0"?

It's like this:

from radio come 40Hz sinus wave, and while i put volume up i measure if there is any clipping/distortion on subwoofer. I did some electronic circiut with filters and some thing(don't know word in english :) ) that convert signal into DC. And from this point i want to continue with arduino. So on arduino analog 1. pin want to measure signal 40Hz from radio and on another 2. pin signal from filter that i made.

v1= signal from radio v2=signal from filter

Than math formula just simple v1 / v2 = x , if x goes to ? there is no distortion so LED is off and if x goes to 1 there is distortion so LED is on.

And yes v2 stay close to 0 and v1 is rising. But both signals are in range of mV.

O'K, I guess, I've got the picture. You are measuring IMD+Noise distortion by driving PA with 40 Hz sine wave, than measure at the output magnitude without main F (notch filter). There is a topic with a code taken from the book (I believe, one of the best book for programming arduino): http://arduino.cc/forum/index.php/topic,80070.msg605236.html#msg605236 You can start to adapt it for your needs, be aware to supply DC offset to analog pins with two resistors and supply sine signal via cap. Other suggestion would be to make your measurements with FFT code: http://fftarduino.blogspot.com/2011/02/color-organ-spectrum-analyzer-on.html

Change size of array 64 to 256, increasing resolution to 65/4 = 16 Hz, so if you supply 32 Hz as test tone, main F would be bin #2, second harmonic bin #4 etc.

Careful, The arduino, at it's most sensitive, can only see the difference of 3.22 mV. If your looking to have something more sensitive than that, you will have to use an amplifier.

Assuming you can offset/scale the input signal voltage to stay within a 0-5vdc window (no negative voltage allowed), your software just needs to have two 'peak detector' variables that hold the highest reading from the continous reading of the analog input pins. Read a value, if it higher then the prior reading then update the peak detector value and compare it you your software constant 'clipping' value and set the output led if it exceeds that clipping value. There will also need to be a part implement the 'decay' time where you 'reset' the peak detector as the value drops below the 'clipping' value.

Lefty

Hy,

i gave up for a while. But i'm again working with this project.

New idea:

Sine wave (40Hz) put on arduino on some analog pin. Then is there a way to make some notch filter of this 40hz with arduino? Or is it to hard to do it for me who is noob with C :) I think i need to sample that 40 hz sine wave don't i? And is there any way to write the code for any sine Hz? So if i put 40hz or 100 hz or 1kHz or X Hz the program will recognize it and sample it, filtered it and calculate distortion.

Then when signal is filtered i just need a simple mathematic for THD = (Urms - Urms(f0)) / Urms And i will get value my distortion.

comment, help?