Print This Post Print This Post

The MIDI Guitar – 1: Analog scanning of the Guitar Fretboard

For some time now, I have experimented with producing MIDI signals from a Guitar. Yes, I know there exist a choice of existing systems, but they all have both limitations and drawbacks, the worst of which are:

  • Cost
  • Limited to certain Guitar Models
  • Irreversible changes required to fit
  • Unsatisfactory string-bending capability

My documented antics with guitars have created much interest – both now, and in the past, and I stand accused amongst other things, of creating monsters out of perfectly decent Guitars!

However, I welcome all criticism – good and bad, it drives interest to the site, and there are one or two wiser Guitar pundits around who have remarked that everyone doubled up with laughter when Les Paul demonstrated his monstrous 1st attempt at electrifying the instrument.

‘They all laughed at Christopher Columbus, when he said the World was round,
They all laughed when Edison discovered Sound.’

Now, I wouldn’t rank myself as a Les Paul – but I believe I’m in good company in thoroughly enjoying making an idea actually work.

In a series of articles I hope to walk through the process I have used to create a MIDI guitar that dosn’t cost the earth and is at least as good, if not better, than any offerings on the market currently. The result, in keeping with my past record, is not beautiful to look at – that is a detail others may concern themselves with, but it will work.

I hope to present the design process, electronics and the necessary software in a way that most will understand, and hence be able to modify to their own purpose, and the electronics hardware is cheap and readily available, supported by printed-circuit designs of my own. Since at least some surgery will be performed on the Guitar, if you are to follow these articles, I suggest the purchase of an acoustic guitar which is cheap, but in reasonable condition. My ‘lab rat’ is a Fender Squier SD-3NAT, bought second-hand for £35.00.

I have presented my introduction on this post, as it is the 1st I will publish, but the introduction will be separated at some point when it is expanded, and augmented with a menu, as individual articles are added.
As is usual, feel free to comment, and please correct me if anything I give here is factually/arithmetically/electronically incorrect. I look at all comments, and I’m happy to publish those which are pertinent – even if these are critical.

The Guitar String as a Resistor

I start this section with a short introduction to Ohms law, for those who haven’t an electronics background. Be assured, this is the only formula I will ask the beginner to understand.
For those who understand all of this stuff already – a simple statement of what I will be doing will probably suffice, and they can ignore the basics:

A constant current is fed to the guitar string at the bridge. Each fret is grounded, so that the voltage between the bridge and a given fretted string is directly proportional to the resistance of the string between bridge and fret.

Please note in the following that the values I have used for current, voltage and resistance are for demonstrating Ohms law to beginners. They do not represent the actual values used in the final design. Also, assume that the Guitar strings are metal. This system will not work with nylon strings!

Starter: Ohms Law, and the guitar string as a resistor.

Starter: Ohms Law, and the guitar string as a resistor.

You will see in the above that we can derive a voltage unique for each fretted position for a given string. I will attempt to show you in the following how this can be utilised to give a MIDI value for the note that would be produced for a given string.

Since I’ve made a promise regarding formulae, I will present instead a table-driven conversion routine which extrapolates the voltage measured to an actual fret number.

In the following I’ve assumed that your guitar has 24 frets – so that there are 25 distinct notes per string if we include the open position.

fret_ratios
Fret Multiplier
Open 0.0
1st 0.056126
2nd 0.109101
3rd 0.159104
4th 0.206291
5th 0.250847
6th 0.292893
7th 0.33258
8th 0.370039
9th 0.405396
10th 0.438769
11th 0.470268
12th 0.5
13 0.528063
14 0.554551
15 0.579552
16 0.60315
17 0.625423
18 0.646447
19 0.66629
20 0.68502
21 0.702698
22 0.719385
23 0.735134
24 0.75
Don’t be intimidated by the table on the left – it’s not new, but has been used by generations of Luthiers to calculate the fret positions of stringed instruments such as the Guitar. To keep things simple, let’s call it ‘fret_ratios’. Now, as per our example above, assume that the Guitar string has a resistance of 2 ohms, and the constant current is 1 amp. We have already established that across an un-fretted (i.e. open) string, the voltage will be 2 volts. Let’s assume we fret the string at the 12th fret, and apply the following simple rule:

new voltage = open string voltage – fret_ratios[fretnumber] x open string voltage

substituting for the fret number:

new voltage = 2 – fret_ratios[12] x 2

therefore: new voltage = 2 – 0.5 x 2

which gives a result of 1 volt.

If you are unfamiliar with the use of the square brackets above – just think of them as a numbered box for a given fret in the table on the left. The normal rules of arithmetic apply here, and the multiplication should be performed before the subtraction.

Now, if we measure the open string voltage before we start playing, and apply the above rule for each fret position, we should end up with 25 voltages which directly represent a given fretted position. We then hold these in a new table – let’s call it ‘fret_volts’.
The table will be created dynamically using a small program routine in the microcontroller firmware. I give an example (on the right) of a table created using the values of current and string resistance from our example above. Again, I stress that these values are for demonstration purposes only.

For those interested, the code (in ‘C’) to produce the table might look something like this:

In the following ‘openval’ is the voltage obtained from an unfretted (open) string, ‘temp’ is a temporary value and ‘i’ is an index incremented through 1 to 24. ‘C’ uses an asterisk ‘*’ to signify multiplcation, rather than ‘x’. The text after ‘//’ are comments.

	fret_volts[0] = openval; // open string val (no fretting)
	for (i = 1; i < 25; i++)    // do the calculation for each fret position 1 to 24
	{
		temp = fret_ratios[i] * openval;
		fret_volts[i] = openval - temp; // put the computed result for the
                                                // indexed fretnumber in the fret_volts table
	}


Translating a voltage to a fret is simply a matter of looking up the voltage in the table we have created, and reading off the index of the location holding the same (or more correctly, closest) value. I will be showing how this is done in the next instalment.

fret_volts
Fret Voltage
Open 2.000000
1st 1.887748
2nd 1.781798
3rd 1.681792
4th 1.587418
5th 1.498306
etc. 6th to 24th

Some observations.

  • First of all try substituting the scale length (in inches) of your guitar for ‘openval’. The resulting table will give you the position in inches for each fret. In other words I’ve simply re-used the luthier’s alogorithm, because the resistance of a wire is directly proportional to its linear length.
  • Secondly, neither the voltage nor current seem to figure in creating the table. If we regard the fret position in this system as the input, and the resulting voltage as the output, then the system is said to be ratiometric, and the output is directly proportional to the input. Both the resistance of the Guitar wire and the current used are irrelevant to the calculation. Which is good, because we can now make the current any value we like to accommodate practical implementation, bearing in mind that each string of the Guitar will have a different resistance.

Practicalities.

It’s high time we realised our ‘imaginary’ battery that supplies a constant current in the 1st section above. Fortunately these days, most electronics is integrated, it’s complexity abstracted away and hidden, the physical device presenting itself as a small blob of plastic with wires poking out, and such is the case for the device used to supply a constant current.

LM317 rigged to supply constant current

LM317 rigged to supply constant current

Referring to the circuit on the left. The LM317 is a 3-terminal voltage regulator, with input, output and adjust pins.
You could read the datasheet for this animal, but I’ll state the one salient unshakeable fact. Whatever the input or output (within reason), the device will always try to maintain the voltage between OUT and ADJ to almost exactly 1.2 volts. OK. Ignoring the input and output voltages for one moment, observe that there is a 12 ohm resistor between the OUT and ADJ terminals.
Referring back to Ohms law, we can work out what current will flow in the resistor.

I = V/R
therefore: I = 1.2/12
i.e. 0.1 amps

or, as electronics engineers prefer 100 milliamps. (ma)
Note again, that the current is virtually independent of the value of the resistor from ADJ to GND. (there are practical limitations)
The voltage across R1 will be directly proportional to it’s resistance, so choosing 2 ohms for this we would get a voltage of:

V = I x R
V = 0.1 x 2
V = 0.2 volts

We can substitute a Guitar string for R1, and then measure the resulting voltage with the string un-fretted (open), and create a table as shown in the previous section.
In fact, making the constant current 100ma is not just chance, but is the value I have selected for practical implementation, which gives reliable and measurable voltage differences for the High ‘E’ string.

Gotchas
So far we have assumed that the wiring connecting up the components is ‘perfect’ i.e. has no resistance. This of course is nonsense, it’s resistance will be significant, and must be accounted for, otherwise the system will not work.
There is a standard practise for measuring low voltages across a very low-value resistor. (such as a Guitar string) It is known as the 4-terminal method, and sounds much worse than it actually is. Put simply the two wires supplying the current to the Guitar string with constant current are kept totally separate from the two wires connected to measure the voltage across it.
Also the two wires supplying the current should have as low a resistance as possible. It’s time now to simply show a practical example on a modified Guitar, as a picture is always worth a thousand words.

Headstock of modified Squier Acoustic Guitar (Shock Horror!)

Headstock of modified Squier Acoustic Guitar (Shock Horror!)

Soundhole end of fretboard showing end of brass rod soldered to frets.

Soundhole end of fretboard showing end of brass rod soldered to frets.

A brass rod slightly longer than the distance from the nut to the end of the fretboard (soundhole) has been soldered as neatly as possible to each fret, on the bass string side of the fretboard. To this, the brass insert from a small connector block has been attached and six thick flexible wires have been soldered to the insert, and each string, close to the nut, but sufficient to allow for tuning. Ideally, these should be connected using brass inserts also – but this is my prototype.

A reasonably thick flexible wire is joined to the rod near the insert, and this is the GND return for the constant current generator(s).

The GND return for the voltage measurement is taken from the other end of the brass rod. (next to the soundhole)

Last but not least, six thickish wires, one for each constant current source, are connected to the strings just behind the bridge, together with six thinner ones which are the six feeds to the voltage measurement system.

The above arrangement ensures that the 4-terminal measurement system is set up correctly – wires carrying relatively large currents are not used to carry the voltage measurement currents.

To be continued..

Copy the code below to your web site.
x 
  • Share/Bookmark
Create PDF    Send article as PDF   

You must be logged in to post a comment.