# Equation to calculate the expected frequency of a natural harmonic at any location on the fretboard

On guitar you can play a "natural harmonic" by gently resting your finger directly over a fretwire and plucking the string. I am trying to determine the pattern to natural harmonics. I would like to be able to just name a string and a fret and instantly know which note would ring out if I did a natural harmonic on that fret.

I am aware that natural harmonics do not ring out clearly on every fret so for some frets the result may just be that there is no viable natural harmonic at that point... Also some natural harmonics seem to fall between the frets. But I am just struggling to find a pattern to them.

The reason I am trying to determine a pattern is I am working on tablature software and the MIDI sounds played when a harmonic is tabbed does not currently match the correct pitch. I need to come up with an algorithm to determine what pitch should be played for every possible harmonic on the fretboard so I can tell it to play the correct MIDI note when the tab includes harmonics.

• Does this answer help: music.stackexchange.com/a/84308/63781 Commented Apr 20 at 16:09
• You might also want to bear in mind that your guitar frets will be based on equal temperament, which spaces the pitches evenly, but means that the frequency at a given fret is not in a simple relationship to that of the open string (unless you bend the note). On the other hand, a harmonic has an exact multiple of the base frequency, and is not positioned exactly at any fret. Commented Apr 26 at 13:39

There are theoretically hundreds of harmonics available- although only a few actually ring out clearly and get any use. Rather than a general solution, the best approach may be to hard-code the few that are typically used.

For an open string with frequency f:

12th fret- 2f

7th fret or 19th fret- 3f

5th fret or 24th fret- 4f

4th/9th/16th fret (roughly)- 5f

3rd fret (roughly)- 6f - at this point, the harmonics are very close together and fairly difficult to play accurately and cleanly.

Also, note that these harmonics don't necessarily fall directly over a fretwire.

Relevant image, pulled from wikimedia, showing this relationship:

• Thank you, that chart helps a lot in figuring this out. Commented Apr 20 at 19:39
• An electric guitar with lots of distortion can get a few more upper harmonics between the first and third frets, but they are so high and not as close to equal tempered pitches that it's more of an effect than usable notes. Commented Apr 21 at 15:18

I don't think trying to make an equation for that would be viable, but let's try.

If you touch the string in half, you will get double frequency. If you touch it in one-third of two-thirds of its length, you will get triple frequency. All in all, let n > 1, k < n be relatively prime natural numbers; then touching the string in k/n of its length will produce n times the frequency. You then can convert that to a note using the fact that raising the tone by s semitones means multiplying the frequency by 2^(s/12), at least in equal temperament (having 2^(s/12) = n means s = 12 log_2 n).

On the other hand, the frequency of a note is proportional to 1/length of the string, so fret f is at 2^(-f/12) of the length of the string. This, being put equal to k/n, can be plugged into the previous equation to get what you want.

However, the bigger n you have, the more of the full sound of the open string you are muting and the less useful the harmonics are. In practice, I don't think you can get higher than n = 7 or 8 and get a good tone, and most harmonics people play don't get higher than n = 4. So, according to the equation, there are arbitrary harmonics to be gotten at every rational multiple of the length of the string, but the overwhelming majority of them is no use. Hence, I'd suggest just making a lookup table like this: fret 12 means +1 octave, frets 7 or 19 mean +octave+fifth, etc.

(If it's not clear why the things should be as I'm writing, you should probably have a look at this question: Why do harmonics played on guitar sound lower as you move to higher frets while fretted notes sound higher?)

In theory if you touch the fret in position k/n the nth overtone will be allowed to sound. Now, if k and n have common divisors then this will be part of the harmonic spectrum for a lower harmonic (position 2/4 produces 4th harmonic, but also 1/2, so the 2nd).

So in this sense it makes sense to assume k and n to be coprime (so all common factors are cancelled out). This way if the position ratio r is a rational number there is one unique overtone produced by blocking string vibration at that position. If x is an irrational number there will be no such overtone.

Now, in practice this does not make sense: If you happen to be slightly off — say you touch instead of 1/2 the position 999999/2000000 you should get the 2000000th overtone — but instead you still get the second position.

The reason for this is that touching the string does not in fact stop the string from vibrating at that point, but it applies a strong dampening around that point. The dampening especially affect frequencies with a high amplitude in that part of the string, which means that such frequencies are muted away, with only the close harmonics remaining. So you do not produce a certain overtone, you produce the full spectrum and then take away stuff. And this means that a slight deviation in position will result in only partially filtering out the intended overtone, which means that response will suffer, but it won’t immediately change the produced harmonic.

In fact there are positions that are close enough to two different nodes to produce two different harmonics (where none is part of the other’s spectrum). For example the 10th fret (≈ 0.561) will most likely produce both the 7th (4/7 ≈ 0.571) and the 9th (5/9 ≈ 0.555...) harmonics (as long as these are produced in sufficient quality).

The concept of close enough will depend on the order: A fundamental offers much more space for error than a high harmonic.

So one way to go about it:

1. Estimate some error tolerance threshold `ths` (the value will also depend on the instrument), say 10% of the wavelength.
2. Estimate a set of relevant harmonics (depends on the instrument, but you won’t go to the 2000000th harmonic)
3. Take an arbitrary position ratio `r`.
4. For each harmonic `n`:
1. Determine the `k` so that `k/n` is as close to `r` as possible. This is the case if `k` is close to `r * n`, so take `k := round(r * n)`
2. If `k, n` are coprime determine the error `err := abs(r - k/n)`
3. Check if the normalized error falls under the threshold: `err * n < ths`

See here for an example implementation: