Arduino Forum

Using Arduino => Audio => Topic started by: satercito on Apr 30, 2014, 07:43 pm

Title: Creating a tuner..... Begginer!
Post by: satercito on Apr 30, 2014, 07:43 pm

Hi everyone!

I've already started doing a tuner for the guitar.
First step was get an arduino duemilanove from the university and a designed preamp for electric guitars.

Im a begginer so.. I've conected the preamp to the power, plugged the jack of my guitar to the preamp and the output to of the preamp to arduino. The thing is... just correct me if im wrong. The max ouput of the preamp its 2V  and arduino in the analog will show values from 0 to 1023.. so 512 should be like 2.5V in arduino.. the output max of the preamp its 2v max(like 400aprox from 1023) , that means I shouldnt see values highers than 400 or 500... and im watching more than 600 on the screen.. can you help me or correct me!  thanks!!
Title: Re: Creating a tuner..... Begginer!
Post by: tmd3 on Apr 30, 2014, 08:41 pm
First things first:
The preamp output is probably centered at ground, meaning that it's negative with respect to ground some of the time.  A negative voltage on an analog pin can damage your Arduino.  You'll need an input circuit to offset the input signal so that it doesn't go below ground.   We'd need to know the output impedance of your preamp to describe an appropriate input circuit; maybe that's listed in the specs somewhere.
Title: Re: Creating a tuner..... Begginer!
Post by: janost on Apr 30, 2014, 08:46 pm
Exactly how did you connect it?
Title: Re: Creating a tuner..... Begginer!
Post by: satercito on Apr 30, 2014, 09:57 pm
The preamp output impedance is 1K... 


this way!

(http://imagizer.imageshack.us/v2/640x480q90/838/ipsy.jpg) (https://imageshack.com/i/naipsyj)

All the conections are in their places..
Title: Re: Creating a tuner..... Begginer!
Post by: janost on Apr 30, 2014, 10:36 pm

Exactly how did you connect it?



:) :) :)
Title: Re: Creating a tuner..... Begginer!
Post by: satercito on Apr 30, 2014, 10:47 pm
Is it ok in that way? Do you need more information? So for sure I need another circuit?
Title: Re: Creating a tuner..... Begginer!
Post by: DVDdoug on May 01, 2014, 12:06 am
Quote
The max ouput of the preamp its 2V
Is that peak or RMS?  In any case, it's probably an approximation or a "worst case" spec (meaning that the preamp will clip at 2V or more), and it will depend on the power supply voltage to the preamp.  Ideally, you could get 5V peak-to-peak (1.77V RMS) with a 5V power supply, but there will be a voltage drop across the output transistors and a real-world circuit will put-out less.

It's the same with a power amp specs..   If the spec says 100 Watts maximum, that means if you drive it to it's maximum, you should at least get 100W.    You'd feel cheated if you could only get 90W, but you'd be happy if you get 110W.

Plus, it's an analog signal...  Very unpredictable!  ;)   The actual voltage will depend on how hard you pluck the string, the sensitivity of the guitar pickup, guitar's volume control setting, and the gain setting of the preamp.

You can get almost one volt out of a guitar pick-up, so the main purpose of the preamp is to present a high-impedance load that doesn't affect the guitar's output level or tone.    The Arduino already has a very-high impedance input, but only for the positive half of the waveform, and you are not supposed to feed-in negative voltages.

If you don't care about the tone or sound quality while tuning, you might be able to skip the preamp.   If you have a multimeter or access to an oscilloscope, you can check the guitar's output voltage.  (A multimeter will be too slow to measure the peak, but you should get a good idea of the signal level.)

There are a couple of ways to deal with AC input.    If you are analyzing the waveform with FFT to find the frequency, you need the whole waveform.   The simple solution is to add a pair of equal-value resistors to bias the input at 2.5V (and a capacitor to block the DC bias from your preamp..   (That means that silence will read about 512 on the ADC, but that's easy to subtract-out in your sketch.)   

If you only need to read the amplitude (maybe finding the zero-crossings to determine frequency) you can throw-away the negative half of the waveform.   The easiest way to do that is with a series "current limiting" resistor (to prevent damage to the preamp) and a pair of "protection diodes" to prevent the signal into the Arduino going negative or going above 5V.

I'll leave it to you to research those solutions in detail.
Title: Re: Creating a tuner..... Begginer!
Post by: tmd3 on May 01, 2014, 12:58 am
With an output impedance of 1K for the preamp, a simple voltage divider should work as an offset circuit.  Here's a way to do it:
http://interface.khm.de/index.php/lab/experiments/arduino-realtime-audio-processing/ (http://interface.khm.de/index.php/lab/experiments/arduino-realtime-audio-processing/).
Some things to think about with regard to that circuit:

So for sure I need another circuit?
Not absolutely for sure.  That preamp could be anything; there's no way to guess its output characteristics.  It might have a nicely-biased audio + DC output, centered at 2.5V, just waiting to be hooked to an Arduino, but I doubt it - it'd be an odd preamp.  I'll go out on a limb and say, yes, for sure you need another circuit.  Doing otherwise risks damaging an analog input to your Arduino, or damaging the the IC generally. 
Title: Re: Creating a tuner..... Begginer!
Post by: satercito on May 01, 2014, 11:22 am
Thanks to all!! I really apreciate so much your answers.
The thing is a got this preamp just to not do any circuit by myself, cause my knowledgment in electronic is really bad.
In this proyect the guay allows to use the op Amp of my preAmp (TL071).

which one could be the easiest way ,(no matter if tha final quality is not really good) to get the guitar frecuencys through this preamp I have and something else if needed...

I live in the countryside and maybe I wont recieve any piece I need till next week, and the only thing i have here is the preamp and arduino(Ok maybe I can find any resistor from any old electronic device).. My project should in one moth and Im really am in a hurry!

no worries if you cant help me!

Thank you very much.
Title: Re: Creating a tuner..... Begginer!
Post by: tmd3 on May 01, 2014, 08:10 pm
These statements -

  • ... my [knowledge] in electronic is really bad.

  • In this [project] the [guy] allows to use the op Amp of my preAmp (TL071).

  • My project should in one [month] and I'm really ... in a hurry!

- make me wonder if this a school project.  Is it?
Title: Re: Creating a tuner..... Begginer!
Post by: satercito on May 02, 2014, 12:08 pm
FInal project of my degree! Computer science.. the think is that I love music.. thats why I choosen this project.. but I really know about mobile programming
Title: Re: Creating a tuner..... Begginer!
Post by: satercito on May 02, 2014, 12:30 pm
I think I will talk to my  master and coment about your solution tmd3, since I have not knowledgment about electronic, i need to be sure about the circuit you propose.
Title: Re: Creating a tuner..... Begginer!
Post by: tmd3 on May 02, 2014, 01:16 pm

I think I will talk to my  master and coment about your solution ...
Please do. 

Once you capture the signal, how do you intend to process it?  After you process the signal, how do you intend to show the user whether he's in tune, and which way to tune?
Title: Re: Creating a tuner..... Begginer!
Post by: satercito on May 04, 2014, 07:28 pm


I think I will talk to my  master and coment about your solution ...
Please do. 

Once you capture the signal, how do you intend to process it?  After you process the signal, how do you intend to show the user whether he's in tune, and which way to tune?



With the Fast fourier transform.. and show in a LCD Screen the note with arrows in each side to say if he has to tune to the left or right
Title: Re: Creating a tuner..... Begginer!
Post by: tmd3 on May 05, 2014, 03:41 am
OK.  If you don't have the FFT and display program working yet, you probably want to start on them.  Eventually, you'll process an array of analog data with your FFT code.  You can start now, using test data.

I'd like to know if anyone has built a working tuner on the Arduino based on the FFT.
Title: Re: Creating a tuner..... Begginer!
Post by: satercito on May 05, 2014, 09:04 am
Good idea! I'll start with FFT test data now! Im not sure if I have bookmarked a page of someone who did the tuner with the FFT, if I find it , I¡ll post it
Title: Re: Creating a tuner..... Begginer!
Post by: satercito on May 05, 2014, 03:49 pm
I did some things this morning in the university laboratory with an oscilloscope, I tried using a offset of 2v, and now I see that im getting 300mv on the input (just noise, unplugged cable)  and in the output 3,50V.. so now its centered at 2V nut its losing a little bit. I used a 100k resistor between the ground and the hot leg of arduino as you said. Today I havent had time to try som stuffs and measure from guitar and so..but I will have the whole morning tomorrow to test inputs and outputs...

thanks so!
Title: Re: Creating a tuner..... Begginer!
Post by: zallesov on May 11, 2014, 09:22 pm
Just want to add my +1 to the topic.
I'm also a new to hardware but with software development background. I need an input circuit for audio. Then I will do som FFT and beat detection and blink led and lasers until seizure.
Here are link a found so far. You've probably also had.

http://www.instructables.com/id/Arduino-Audio-Input/ - an comprehansive tutorial on how to make a audio input board. It should convert signal to be 5v amplitude with a 2.5V center. But that did not work for me due to probably my curved hands. What I got were only 0 , 1023 and 510-515 values on arduino inputs.

http://macetech.com/store/index.php?main_page=product_info&products_id=11 Arduino input shield. Have not tried yet. Shipment to Germany is more expensive than board itself. But I might buy it in the end.

http://www.andregoncalves.info/ag_blog/?page_id=61 Seems to be the same as previous. I wrote to the man but he just does not reply.

There are few other audio boards out there but they do not provide raw audio data to the board or it is not clear from the description.
Can one suggest a ready to use solution if there is one?

Title: Re: Creating a tuner..... Begginer!
Post by: tmd3 on May 12, 2014, 12:13 am
I did some things ...

I don't see a description of what you did.  A schematic would help.


Can one suggest a ready to use solution if there is one?
Here's what I use: a cheap homemade circuit to connect the audio output of the PC to the Arduino.  A schematic is attached.  The Thevenin equivalent of the voltage divider is a 10K resistor and a 2.5V DC supply.  10K is suitable for an analog input, as described in the datasheet.  Note that there's nothing in series with the analog input.  I've verified that my PC won't output a 5V peak-to-peak signal, so I don't worry about overdriving the analog input.  You may prefer to use two 10K resistors, and a 5K in series, for an equivalent impedance of 10K, with the 5K providing a measure of protection for the analog input.  This scheme isn't really suitable unless the input is stiff enough to drive the equivalent impedance of the voltage divider; otherwise, the signal level will drop.

I added a 100K resistor to ground from the signal input.  That's because I suspect that the audio output is capacitively coupled, just like my input.   Without the resistor, the DC voltage between the two capacitors is essentially undefined.  Because I'm using an electrolytic capacitor, and I presume that the audio output does, too, I add the resistor to keep the DC level between them at ground, and make sure that the capacitor polarities are proper.  I can't say that it's necessary; I just like having it in the circuit.

Advantages are that it's cheap, easy to build, and I can define the analog input quite precisely by generating my own audio content.  The primary disadvantage is that it doesn't lend itself to real-world inputs:  The input impedance is so low it would pull down most guitar inputs, and it has no protection from analog overvoltage, as you might get from an amplifier output intended for a speaker. 

Criticism is welcome.
Title: Re: Creating a tuner..... Begginer!
Post by: zallesov on May 12, 2014, 11:29 am
BTW, what is amplitude of a signal from an average cell-phone player? Dow we need to amplify it?
Title: Re: Creating a tuner..... Begginer!
Post by: tmd3 on May 13, 2014, 04:56 pm
... what is amplitude of a signal from an average cell-phone player? ...
I don't know of any standards.  Here's a guy testing the audio output of an iPhone 5:  http://www.kenrockwell.com/apple/iphone-5/audio-quality.htm (http://www.kenrockwell.com/apple/iphone-5/audio-quality.htm).  According to him, full output is about 1.4V peak-to-ground, with an output impedance of 4.5 ohms.  With a 2.5V offset, that'll give ADC read ranging between roughly 225 and 800, at full output.
Title: Re: Creating a tuner..... Begginer!
Post by: satercito on May 13, 2014, 06:42 pm
Now , with my teacher I did a circuit after the previous preamp and I have in the input of arduino a signal between 1v and 4v more or less because with the picking up of the guitar sometimes if I play hard the string I can have 5v so from 1v to 4v would be enough. Now the second problem is to use a librarie that says me what frecuency is  on arduino input. I tried with ArduinoFFT and saw one FIx_FFT..

any help!? thanks!
Title: Re: Creating a tuner..... Begginer!
Post by: tmd3 on May 15, 2014, 02:40 pm

I tried with ArduinoFFT ...
What did you try?  What did you expect it to do, and what did it do? 

If you answer those questions, and post code and a schematic, it can only help.

Title: Re: Creating a tuner..... Begginer!
Post by: satercito on May 16, 2014, 12:41 pm
I think I understand the way fft works.. I need to  read frecuencys from my guitar that are going to be between 1hz and 1kHz so I should use 2khz sample rate. Then I will get 2 arrays one from real number and another with the imaginary , I should do the module from both and get another array, and in this final array I need to look for the maximux(that is the amplitude)) and that maximun I have to divid by the sample number and multiply sample rate, and I have the frecuency of the sine that im looking for..

Am i Right? Or Am I completely lost ? haha

thanks!