Arduino Forum

Using Arduino => Audio => Topic started by: apollodriver on Dec 10, 2020, 12:20 am

Title: i want to create a guitar tuner - steps to take - parts to use
Post by: apollodriver on Dec 10, 2020, 12:20 am
hello dear  all good day.

i want to create a guitar tuner:

This project might not be as easy as you think, once we have got the signal in. We can get the note easy enough but not the octave.  Most of those projects are for a simple waveform frequency measurement and a guitar produces a complex evolving waveform that messes up the measurement.

to begin with the beginning: i am pretty new to the Arduino. And i think i just have to give it a test, and really will learn a lot. okay - you say - we buy a guitar tuner for less than 30 Dollars, but thats not that reason i want to do a guitar tuner myrself

i guess that it is pretty important to understand the principle behind the build.  There are 7 major musical notes denoted by the alphabets; A, B, C, D, E, F, G  - see more below:

The range allowed by the Arduino Audio frequency library spans from 60 to 1500 Hz.
so we have a Guitar string frequencies are  (standard tuning) :


Quote
329.63 Hz (E),
246.94 Hz (B),
196.00 Hz (G),
146.83 Hz (D),
110.00 Hz (A)
82.41 Hz  (E)
The project; what needs to be done: we convert the sound signal generated by the guitar to a frequency then compare with the exact frequency value of the string being tuned.

The frequency detection/conversion involves 3 main stages;

- Amplifying: here we use a o-amp
- Offsetting: here we take care for the ofset
- Analog to Digital conversion(sampling): here we take care for the conversion of the signal

In detail - we have the following steps in the chart:

* Signal input
* Analysis
* Comparison
* Presentation
(* Operation / ON-OFF / change of mood etc.)


first of all: we need to get the sound signal: The sound signal being produced will be much much too weak for the Arduino's ADC. We have (for sure ) to amplify this - this is very important.
After amplification, to keep the signal within the range recognizable by the Arduino's ADC - this is the Analog Digital converter. Another OpAmp between guitar and Arduino (maybe also a low pass) -- the signal is tooo weak - for the ADC.

well we need to prevent clipping of the signal; doing so we need to offset the voltage of the signal.
After offsetting, the signal is then passed to the Arduino ADC; Thats just fine: Now we can go ahead  where it is sampled and the frequency of that sound is obtained.

How we then turn the read-in values into "too high / too low"; There should be enough examples on the internet but in the end it will probably be not to difficult i guess here

Frequency analysis, plus filtering the strongest signal or the desired main tone. well - are there any Libs out there : this would be great Otherwise I could imagine that we first have a fixed table of frequency values, I'm going to start with the normal mood on E.

So, frequency table as assignment of tone constants to frequency. Then the tolerance-range from which the analysis recognizes the approximate tone,

Well the recogition is pretty important: If the system will recognice:
the user would definitely like to tune the E string, so I'll show him the range"
You would then have to define whether you would then assume 10% down or up, or whether you would enter that or whatever. In the end it is a pure comparison of numbers.

( we could also have the reference tone output to check whether you are totally wrong ...)

So let's separate the partial programs:

* Signal input
* Analysis
* Comparison
* Presentation
(* Operation / ON-OFF / change of mood etc.)

If we encapsulate it in this way, we can certainly make the representation as LED patterns, pointers, LCD display, the main thing is that the basic data is correct. To the signal input: Is it enough to simply fish the electrical signal at the jack socket, or do you place a piezo? Or both? Then connect high and low pass in hardware before going into the ANALOG-IN, or let the ARDi do it?

analysis: There are definitely ready-made libs out there:

Comparison: as I said, I would do it using a table, first prototype only for E-tuning.

A further development would then be to have a global table for the usual tones and then refer to them via whatever

this leads to the final stage - to the Presentation


Well - what do you say - which Arduino to take for this project?
Title: Re: i want to create a guitar tuner - steps to take - parts to use
Post by: DVDdoug on Dec 11, 2020, 04:49 pm
Quote
This project might not be as easy as you think,
I haven't tried it.  From what I've seen here on the forum, most people fail.  :(

Quote
We can get the note easy enough but not the octave.
If you say so...   I think it's pretty hard to tune a guitar an octave high or low so getting the note should be good enough.

Quote
There are 7 major musical notes denoted by the alphabets; A, B, C, D, E, F, G
Of course you only need to tune 6 strings/notes.   

There are 12 notes in an octave, spaced about 6% apart in frequency (one semitone) and that includes the sharps & flats...   The sharps & flats are NOT "half notes".  It's just a screwy note-naming system. 

C is about 6% higher than a B.
There is no B#.
C# (same as a Db) is ~6% higher than a C.
D is ~6% higher than a C#.

Quote
- Amplifying: here we use a o-amp
Maybe...   An electric guitar can put-out about 1V, but you might need gain during the sustain when you're actually tuning.

You can use the optional 1.1V ADC reference (equivalent to a gain of 5).   Of course you have to adjust the bias (offset) accordingly.    You can actually use 2 analog inputs (biased differently) and automatically switch between the two inputs and the two references.   I have an application where I automatically change the reference but I'm measuring DC so I'm only using one un-biased input.)

Quote
well we need to prevent clipping of the signal; doing so we need to offset the voltage of the signal.
Clipping is related to the signal level (after any gain).  Assuming you are biased properly at half the reference, the positive & negative peaks will be clipped equally.

Some clipping might be OK.   Clipping doesn't change the "note" (fundamental frequency), and clipping on the attack is probably not an issue in any case.

Quote
Is it enough to simply fish the electrical signal at the jack socket, or do you place a piezo? Or both?
If it's an electric guitar or an acoustic with a pick-up just plug it in.  If it's acoustic use a regular microphone.  (You can buy "Arduino microphone boards" with a built-in mic, preamp, and biased output.)

Quote
Then connect high and low pass in hardware before going into the ANALOG-IN, or let the ARDi do it?
If you don't low-pass before  digitizing you can get aliasing (false frequencies).     That happens when the signal is above the Nyquist limit (half the sample rate).    Every audio ADC has an anti-aliasing filter and it's important for high-quality audio.   That might  not be a problem with a tuner since the higher frequency harmonics are relatively weak and the aliases will be weak.     But, a simple R-C filter wouldn't hurt (and you may need an active filter).



Title: Re: i want to create a guitar tuner - steps to take - parts to use
Post by: MrMark on Dec 11, 2020, 05:17 pm
For audio input I've used MAX9814-based microphone boards (https://www.adafruit.com/product/1713) which has amplification including automatic gain control and outputs a DC biased signal, albeit centered to a 3.3V range.

This thread (https://forum.arduino.cc/index.php?topic=540969.30) discusses the development of a frequency analysis algorithm that should be suitable for a guitar tuner using code as in post #42 of that thread.

For what it's worth, in practice I use the Android phone app "GuitarTuna" (https://play.google.com/store/apps/details?id=com.ovelin.guitartuna&hl=en&gl=US) for tuning.