Guitar Tuner - Which harmonic?
-
- KVRist
- 222 posts since 7 Apr, 2003 from San Francisco, CA
Let's assume I have an algorithm that can calculate the fundamental frequency of a plucked guitar string. Let's also assume that I know where the harmonics are and their individual levels.
Now as we know the fundamental frequency level could be lower than the level of the harmonics, or in some cases almost non-existent. My algorithm can correctly detect roughly where the fundamental frequency should be.
of such a case. The E string on this bass guitar has the following typical measured frequencies and levels (these are course frequency measurements):
Freq(Hz)_____Level(dB)___Note
40.75________-22.5________E1
82.28________-20.6________E2
123.9________-10.9________B2
Interestingly, most guitar tunes I tested incorrectly detects the above note as B2.
As can be seen the 3rd harmonic has a level that is 11dB higher than that of the fundamental. Note that I can calculate a much more accurate frequency for any of the harmonics at a later point in my algorithm. That is not the problem.
The problem is as follows... As I have discovered, the harmonics are usually *not* integer multiples of the fundamental. This is a know phenomenon. In my measurements, harmonics can be off by anything from 5 to 20 cents from the fundamental.
So the question becomes, which one of the three different frequencies above should be used as the "true" pitch of the guitar? One would instinctively think it should be the fundamental frequency, however I'm starting to think it should be whichever is the most dominant harmonic since it will probably mask the other frequencies. Put another way, I'm guessing that we as people will use the B2 above as the true reference of whether the string is in tune or not simply because it is so overwhelming the other notes. Although note that due to how we interpret the harmonic relationships, we would still hear it as an E1 note regardless of how low the E1 level is.
Does anyone know which would be the most "correct" frequency to reference for the true "pitch" as perceived by humans in the above example?
Now as we know the fundamental frequency level could be lower than the level of the harmonics, or in some cases almost non-existent. My algorithm can correctly detect roughly where the fundamental frequency should be.
of such a case. The E string on this bass guitar has the following typical measured frequencies and levels (these are course frequency measurements):
Freq(Hz)_____Level(dB)___Note
40.75________-22.5________E1
82.28________-20.6________E2
123.9________-10.9________B2
Interestingly, most guitar tunes I tested incorrectly detects the above note as B2.
As can be seen the 3rd harmonic has a level that is 11dB higher than that of the fundamental. Note that I can calculate a much more accurate frequency for any of the harmonics at a later point in my algorithm. That is not the problem.
The problem is as follows... As I have discovered, the harmonics are usually *not* integer multiples of the fundamental. This is a know phenomenon. In my measurements, harmonics can be off by anything from 5 to 20 cents from the fundamental.
So the question becomes, which one of the three different frequencies above should be used as the "true" pitch of the guitar? One would instinctively think it should be the fundamental frequency, however I'm starting to think it should be whichever is the most dominant harmonic since it will probably mask the other frequencies. Put another way, I'm guessing that we as people will use the B2 above as the true reference of whether the string is in tune or not simply because it is so overwhelming the other notes. Although note that due to how we interpret the harmonic relationships, we would still hear it as an E1 note regardless of how low the E1 level is.
Does anyone know which would be the most "correct" frequency to reference for the true "pitch" as perceived by humans in the above example?
- KVRAF
- 16873 posts since 8 Mar, 2005 from Utrecht, Holland
The example you gave, how realistic is that scenario in the real world? It will occur when capturing eg from laptop speakers, but it's highly unlikely to happen with a bass guitar directly plugged into an interface.
What's your goal? Just a tuner or audio -> midi conversion?
Especially the very low frequencies are troublesome for tuners to grasp. It's a well-known trick amongst bass players to play 'flageolet' at the 12th fret to improve the tracking of tuners. Not only having a higher frequency helps, but also the lesser amplitude gives a more stable tone to tune.
As you might know, the harmonic B2 is 6.6 cents off a equal temperamentally tuned B2. You can discuss how much off a string can be to be tolerable. Is it 1 cent, or 10 cents? Since you state harmonics can be off by as much as 20 cents, it won't matter that much. When tuning you'd look at the needle which needs to be in the center, not at the detected note.
What's your goal? Just a tuner or audio -> midi conversion?
Especially the very low frequencies are troublesome for tuners to grasp. It's a well-known trick amongst bass players to play 'flageolet' at the 12th fret to improve the tracking of tuners. Not only having a higher frequency helps, but also the lesser amplitude gives a more stable tone to tune.
As you might know, the harmonic B2 is 6.6 cents off a equal temperamentally tuned B2. You can discuss how much off a string can be to be tolerable. Is it 1 cent, or 10 cents? Since you state harmonics can be off by as much as 20 cents, it won't matter that much. When tuning you'd look at the needle which needs to be in the center, not at the detected note.
We are the KVR collective. Resistance is futile. You will be assimilated. 
My MusicCalc is served over https!!
My MusicCalc is served over https!!
-
- KVRist
- Topic Starter
- 222 posts since 7 Apr, 2003 from San Francisco, CA
This is for a guitar tuner, not audio -> MIDI.
The audio was captured directly from the computer line out, fed into my mixer and back into the computer and then recorded, not via laptop speakers so the frequency response is not too much off.
The problem is that in cases like these, it is much easier to track the harmonic than a fundamental that has relatively low level. However the problem is that the harmonics deviate from the expected frequency due to non-linear "stiffness" of the strings, dirty strings etc. Thus even if one expects the B2 to be 6.6 cents off, it might be much more than that due to the above mentioned issues.
So the question is not how much is tolerable, the question is, in the example I gave, are our ears tracking the B2 as what is "in tune", or do we actually track the fundamental? My feeling is that we track the B2 since in this case its level is so much higher. If this is indeed the case, I can simply track the harmonic with the loudest level and use that as what we perceive as the "true" frequency (although mentally we will clearly hear the given example as an E1 pitch no matter how low the fundamental's level).
I guess one way to test this is to have a clean reference tone at the fundamental, then tune a bass guitar by ear to that as close as possible. Afterwards the pitch is determined by the tuner and by seeing whether the E1 is in tune, or the B2, we could know which frequency our ears actually used to determine what is in tune.
The audio was captured directly from the computer line out, fed into my mixer and back into the computer and then recorded, not via laptop speakers so the frequency response is not too much off.
The problem is that in cases like these, it is much easier to track the harmonic than a fundamental that has relatively low level. However the problem is that the harmonics deviate from the expected frequency due to non-linear "stiffness" of the strings, dirty strings etc. Thus even if one expects the B2 to be 6.6 cents off, it might be much more than that due to the above mentioned issues.
So the question is not how much is tolerable, the question is, in the example I gave, are our ears tracking the B2 as what is "in tune", or do we actually track the fundamental? My feeling is that we track the B2 since in this case its level is so much higher. If this is indeed the case, I can simply track the harmonic with the loudest level and use that as what we perceive as the "true" frequency (although mentally we will clearly hear the given example as an E1 pitch no matter how low the fundamental's level).
I guess one way to test this is to have a clean reference tone at the fundamental, then tune a bass guitar by ear to that as close as possible. Afterwards the pitch is determined by the tuner and by seeing whether the E1 is in tune, or the B2, we could know which frequency our ears actually used to determine what is in tune.
-
AdmiralQuality AdmiralQuality https://www.kvraudio.com/forum/memberlist.php?mode=viewprofile&u=83902
- Banned
- 6657 posts since 10 Oct, 2005 from Toronto, Canada
You can determine the fundamental by the relationships between the frequencies of the harmonics. The fundamental is NOT necessarily the loudest harmonic, indeed you can have a fundamental that's not there at all but your ear will still determine the fundamental and hear the sound as that pitch because all the other harmonics are whole number multiples of it. So when you find the common denominator, that's the fundamental.
That said, you might get a better signal if you don't pluck the string so loudly, and if you find the source of the horrible clipping. Part of the problem with plucking so hard is that the pitch of the entire string starts out noticeably sharp due to all the extra tension applied to it.
Most guitarists I know don't pluck the open string when tuning, rather they play a harmonic at the 12th fret. This presents a far more coherent signal to any tuner, close to a pure sine wave.
That said, you might get a better signal if you don't pluck the string so loudly, and if you find the source of the horrible clipping. Part of the problem with plucking so hard is that the pitch of the entire string starts out noticeably sharp due to all the extra tension applied to it.
Most guitarists I know don't pluck the open string when tuning, rather they play a harmonic at the 12th fret. This presents a far more coherent signal to any tuner, close to a pure sine wave.
-
- KVRist
- Topic Starter
- 222 posts since 7 Apr, 2003 from San Francisco, CA
Yes this is what I've said from the 1st post. I already have an algorithm that can reliably detect the "missing" fundamental. I'm past this problem.AdmiralQuality wrote:You can determine the fundamental by the relationships between the frequencies of the harmonics. The fundamental is NOT necessarily the loudest harmonic, indeed you can have a fundamental that's not there at all but your ear will still determine the fundamental and hear the sound as that pitch because all the other harmonics are whole number multiples of it. So when you find the common denominator, that's the fundamental.
When you are talking about the "horrible clipping", I'm assuming you are talking about the YouTube video? If so, that certainly isn't me. I just used it as an example of a guitar that has a fundamental that is substantially lower than the harmonics.That said, you might get a better signal if you don't pluck the string so loudly, and if you find the source of the horrible clipping. Part of the problem with plucking so hard is that the pitch of the entire string starts out noticeably sharp due to all the extra tension applied to it.
The goal of this algorithm is to be as resilient as possible to the ways that the guitar is played. So ideally it should not be necessary to tell a player to pluck a certain way. As mentioned this algorithm is already able to pick out the correct fundamental where most other tuners get the note or octave wrong. Of course plucking the string very loud will result in a sharp attack but this is a known phenomenon.
This is true but I'm trying to understand the relationship between harmonics that are not integer multiples of the fundamental, and how we process that in our brains to come up with what we believe is the correct pitch. Obviously we can't pick 3 different notes if there are three different harmonics at non-integer intervals. We pick one. Do we know which one? Is it affected by which one is the loudest?Most guitarists I know don't pluck the open string when tuning, rather they play a harmonic at the 12th fret. This presents a far more coherent signal to any tuner, close to a pure sine wave.
BTW if you play an open string and then use the 12th fret to play the harmonic, that harmonic won't be exactly twice the frequency of the open string either. Which one will result in a more accurately tuned guitar?
-
AdmiralQuality AdmiralQuality https://www.kvraudio.com/forum/memberlist.php?mode=viewprofile&u=83902
- Banned
- 6657 posts since 10 Oct, 2005 from Toronto, Canada
Yes it will. You create an anti-node (spot with no vibration) at the half-length point of the string, rejecting any odd numbered harmonics. So you'll hear 2x, and a bit of 4x, 8x, 16x, depending on how you plucked the string.BitFlipper wrote: BTW if you play an open string and then use the 12th fret to play the harmonic, that harmonic won't be exactly twice the frequency of the open string either. Which one will result in a more accurately tuned guitar?
This is why you set a guitar's intonation to match the harmonic at the 12th fret. The harmonic is true. Mechanically, it has to be the same as the 2nd harmonic of the open string because you've placed an anti-node right where a strong node of all even harmonics wants to be. However FRETTING the string at the 12th fret may or may not introduce some offset to the pitch, depending on the string's intonation setting. But as the same entire length and mass of the string are vibrating whether you plucked it open, or while holding a harmonic, all the harmonic relationships, at least for the strongest several harmonics, should be in tune with the natural harmonic series.
And yes I meant the horrible clipping in the YouTube clip. Is this actually the test example you're using for your experiments? If so, are you sure the lossy compression isn't moving harmonics around? And that clipping is going to introduce overtones of its own. And if it's digital clipping, alias frequencies as well.
Again, guitarists usually have a technique and pickup position they use when tuning. I find the bridge pickup is usually a much better candidate than the neck. Same with plucking position. Nearer to the bridge seems to create a waveform less likely to be confused. As you move away from the bridge, you're more likely to excite the string at an anti-node, which will essentially erase part of your expected harmonic series.
-
- KVRist
- Topic Starter
- 222 posts since 7 Apr, 2003 from San Francisco, CA
It is pretty well known that in theory they should be exact multiples but in practice harmonics are often not exact multiples of the fundamental frequency. Do a Google search and you will see this mentioned many times. It has to do with the string quality, age, interference from other strings, body resonances, etc. I've seen this in my own tests where harmonics can sometimes be up to 20 cents off from where one would expect them to be based on the fundamental frequency. It is pretty obvious if you have an accurate tuner and then tune with an open string, then play the harmonic and note it is not exactly in tune.
BTW I'm testing with both YouTube clips (much larger selection of guitar tones to ensure the tuner can handle more variety) as well as with a real guitar. I'm seeing this phenomenon in all cases.
BTW I'm testing with both YouTube clips (much larger selection of guitar tones to ensure the tuner can handle more variety) as well as with a real guitar. I'm seeing this phenomenon in all cases.
-
AdmiralQuality AdmiralQuality https://www.kvraudio.com/forum/memberlist.php?mode=viewprofile&u=83902
- Banned
- 6657 posts since 10 Oct, 2005 from Toronto, Canada
It might be time to change your strings, or lower your pickups, or both.BitFlipper wrote:It is pretty well known that in theory they should be exact multiples but in practice harmonics are often not exact multiples of the fundamental frequency. Do a Google search and you will see this mentioned many times. It has to do with the string quality, age, interference from other strings, body resonances, etc. I've seen this in my own tests where harmonics can sometimes be up to 20 cents off from where one would expect them to be based on the fundamental frequency.
You should be pretty safe assuming the 2nd harmonic is double the first/fundamental. I'm not talking about changing a string's vibrating length or tension (that's why we play a harmonic to tune to, the string then still has the same tension and length as when it's vibrating open). And obviously the material properties don't change. Things like old strings and too-high pickups can cause strings to become disharmonic. But this is usually considered a bad thing and if your guitar has a lot of out-of-tune harmonics, of course you'll have trouble if you try to use them as tuning reference.
20 cents is a lot, you would hear that as a substantial beating in the tone. I find it a bit curious that you would use cents (hundredths of a semitone) as the measurement unit, as relatively few true harmonics should match with notes in an even-tempered scale. So if you're using a regular guitar tuner to test anything other than the octave harmonics (2,4,8...), of course it's going to show as off in a guitar tuner.
-
- KVRist
- Topic Starter
- 222 posts since 7 Apr, 2003 from San Francisco, CA
BTW, this effect is especially significant in a piano. This is why piano tuning is such a complex art. From wikipedia:
Now of course a guitar is not a piano, and this effect is indeed less noticeable in a guitar than in a piano. However it is still present and I have clearly seen this when carefully analyzing the frequency makeup of a guitar note. You can find enough information on the internet that basically states that using harmonics to tune a guitar is a bad idea due to this effect.
Now it is possible that my estimate of 20 cents is a bit high since the pitch is fluctuating over time so it is difficult to get an exact figure. This figure could very well be closer to roughly 15 cents or so. However if you are trying to make a guitar tuner that is accurate within a few cents, this value becomes significant enough that it needs to be factored into the calculation somewhere.
So my original question was basically that if you have a fundamental and a harmonic that is 15 cents off from the expected frequency, which one should be used as the true "pitch" of the string? My feeling is one should use the one with the highest level as it will mask the pitch of the other frequencies. The correct answer could also be to use some algorithm that calculates some compromise based on each harmonic's frequency and level. Whatever tracks with what we as humans perceive the pitch to be.
EDIT: In all cases I'm talking about open strings, not fretted.
So your notion that a harmonic is an exact multiple of the fundamental is incorrect.Inharmonicity refers to the difference between the theoretical and actual frequencies of the harmonics or overtones of a vibrating tine or string. The theoretical frequency of the second harmonic is twice the fundamental frequency, and of the third harmonic is three times the fundamental frequency, and so on. But on metal strings, tines, and reeds, the measured frequencies of those harmonics are slightly higher, and proportionately more so in the higher than in the lower harmonics. A digital emulation of these instruments must recreate this inharmonicity if it is to sound convincing.
The theory of temperaments in musical tuning do not normally take into account inharmonicity, which varies from instrument to instrument (and from string to string), but in practice the amount of inharmonicity present in a particular instrument will effect a modification to the theoretical temperament which is being applied to it.
Now of course a guitar is not a piano, and this effect is indeed less noticeable in a guitar than in a piano. However it is still present and I have clearly seen this when carefully analyzing the frequency makeup of a guitar note. You can find enough information on the internet that basically states that using harmonics to tune a guitar is a bad idea due to this effect.
Now it is possible that my estimate of 20 cents is a bit high since the pitch is fluctuating over time so it is difficult to get an exact figure. This figure could very well be closer to roughly 15 cents or so. However if you are trying to make a guitar tuner that is accurate within a few cents, this value becomes significant enough that it needs to be factored into the calculation somewhere.
So my original question was basically that if you have a fundamental and a harmonic that is 15 cents off from the expected frequency, which one should be used as the true "pitch" of the string? My feeling is one should use the one with the highest level as it will mask the pitch of the other frequencies. The correct answer could also be to use some algorithm that calculates some compromise based on each harmonic's frequency and level. Whatever tracks with what we as humans perceive the pitch to be.
EDIT: In all cases I'm talking about open strings, not fretted.
-
- KVRian
- 1329 posts since 25 Dec, 2005 from Devon, England
From what I remember (this applies especially to bass frequencies, where the human ear is less sensitive to the fundamental and where sound reproduction equipment has a limited low frequency response), the human ear infers the fundamental from the spaces between the audible overtones. I wish I could supply a reference (doubtless there's a pdf on one of my hard drives, somewhere...)
Perhaps some listening tests would be in order to back up your tuner - no point in trying to be mathematically correct if it sounds off! I think maybe that it would be worth looking for any scientific research into piano tuning and the properties of real strings and their finite flexibility too.
Perhaps some listening tests would be in order to back up your tuner - no point in trying to be mathematically correct if it sounds off! I think maybe that it would be worth looking for any scientific research into piano tuning and the properties of real strings and their finite flexibility too.
"are we there yet?"
-
- KVRist
- Topic Starter
- 222 posts since 7 Apr, 2003 from San Francisco, CA
Yes this is called the "Missing Fundamental" problem, see here.jonnyG wrote:From what I remember (this applies especially to bass frequencies, where the human ear is less sensitive to the fundamental and where sound reproduction equipment has a limited low frequency response), the human ear infers the fundamental from the spaces between the audible overtones. I wish I could supply a reference (doubtless there's a pdf on one of my hard drives, somewhere...)
The solution is to examine the intervals between harmonics and determine the most likely fundamental, even if there isn't any detected frequency at that location. One way to do this is to use a cepstrum transformation. I experimented extensively with the cepstrum but signals like the bass guitar in the linked YouTube video trips it up because the levels of the harmonics are so inconsistent. Cepstrum works best if there are a lot of harmonics with similar levels, like the human voice. I am using a technique that is loosely based on the same principle but is able to detect the correct fundamental even with a bad source like that bass guitar.
The problem with such techniques is that it only tells you roughly where the fundamental is located. Once you know that, you need to do further analysis to make an accurate pitch calculation. I can accurately enough determine the frequency of fundamental (if present) or any of the harmonics, however this is where I ran into the problem that the harmonics are not exact multiples of the fundamental. So the problem is which one to use? When the fundamental is low in level compared to the other harmonics (as in the bass guitar example), calculating the frequency of that fundamental becomes less accurate. So in cases like that, the louder harmonic's frequency can be calculated more accurately because it stands out more prominently. Except it isn't an exact multiple of the fundamental.
EDIT: The specific problem I'm running into is called inharmonicity. There is a good explanation here that describes why real-world strings don't have harmonics that are exact multiples of the fundamental.
-
AdmiralQuality AdmiralQuality https://www.kvraudio.com/forum/memberlist.php?mode=viewprofile&u=83902
- Banned
- 6657 posts since 10 Oct, 2005 from Toronto, Canada
From that Wikipedia article you like so much... http://en.wikipedia.org/wiki/Inharmonicity#Guitar
Anyway, a guitar, piano, etc all tune the fundamental. Upper harmonics being out of tune is the instrument's problem, not the tuner's. Again, this is yet another reason why guitarists will tune to the second harmonic, to reduce the harmonic complexity of the note they're measuring. You will NOT find this harmonic to be substantially out of tune with the fundamental (unless you've got mud on your strings or something).
All this said, I think you're heading down the wrong path for building a tuner. To get perfectly accurate frequency analysis you need an infinitely long time window to analyze. That obviously isn't practical or even approachable considering the short duration of a guitar note.
If I were you I'd look at matching waveform area above zero with waveform area below zero, and correlating to zero crossings. And I'd be filtering any harmonics higher than an octave above the high E string out of the equation entirely. The best guitar tuners available will sometimes still show an octave-up error, particularly if you aren't careful how you play into it. Are you really just building a guitar tuner, or is this for pitch detection?
Which is exactly what I said above. You'll also note that the part you quoted said...Even if an electronic tuner indicates that the guitar is "perfectly" in tune, some chords may not sound in tune when they are strummed, either due to string inharmonicity from worn or dirty strings, a misplaced fret, a mis-adjusted bridge, or other problems. Due to the range of factors in play, getting a guitar to sound in tune is an exercise in compromise. "Worn or dirty strings are also inharmonic and harder to tune", a problem that can be partially resolved by cleaning strings.
Exactly my point. That the first few harmonics will be relatively right-on. (As to whether the quote above means proportionately more so in linear measurement, or logarithmically, is unclear. Yay Wikipedia!)But on metal strings, tines, and reeds, the measured frequencies of those harmonics are slightly higher, and proportionately more so in the higher than in the lower harmonics.
Anyway, a guitar, piano, etc all tune the fundamental. Upper harmonics being out of tune is the instrument's problem, not the tuner's. Again, this is yet another reason why guitarists will tune to the second harmonic, to reduce the harmonic complexity of the note they're measuring. You will NOT find this harmonic to be substantially out of tune with the fundamental (unless you've got mud on your strings or something).
All this said, I think you're heading down the wrong path for building a tuner. To get perfectly accurate frequency analysis you need an infinitely long time window to analyze. That obviously isn't practical or even approachable considering the short duration of a guitar note.
If I were you I'd look at matching waveform area above zero with waveform area below zero, and correlating to zero crossings. And I'd be filtering any harmonics higher than an octave above the high E string out of the equation entirely. The best guitar tuners available will sometimes still show an octave-up error, particularly if you aren't careful how you play into it. Are you really just building a guitar tuner, or is this for pitch detection?
-
- KVRist
- Topic Starter
- 222 posts since 7 Apr, 2003 from San Francisco, CA
The inharmonicity I'm referring to is specifically when playing open strings. I'm well aware that fretting results in deviations from the ideal frequency, never said that didn't happen. I've been insisting that harmonics being off on open strings is a real issue all along although you have insisted it isn't a problem. In fact you insisted that it will be an exact multiple of the fundamental when it clearly isn't in practice.AdmiralQuality wrote:From that Wikipedia article you like so much... http://en.wikipedia.org/wiki/Inharmonicity#Guitar
Which is exactly what I said above. You'll also note that the part you quoted said...Even if an electronic tuner indicates that the guitar is "perfectly" in tune, some chords may not sound in tune when they are strummed, either due to string inharmonicity from worn or dirty strings, a misplaced fret, a mis-adjusted bridge, or other problems. Due to the range of factors in play, getting a guitar to sound in tune is an exercise in compromise. "Worn or dirty strings are also inharmonic and harder to tune", a problem that can be partially resolved by cleaning strings.
There is no indication exactly how much they will be off so you can't make any such claims. My tests show that with the bass guitar, the 3rd harmonic is deviating enough from the expected frequency to be an issue. What did your own tests show? And there is the thing, I did the test and came up with a value of ~15 cents for the 3rd harmonic while you are just speculating at this point. Yes the 2nd harmonic will be closer to the correct value but its level is way too low to be useful in the case of the bass guitar example.Exactly my point. That the first few harmonics will be relatively right-on. (As to whether the quote above means proportionately more so in linear measurement, or logarithmically, is unclear. Yay Wikipedia!)But on metal strings, tines, and reeds, the measured frequencies of those harmonics are slightly higher, and proportionately more so in the higher than in the lower harmonics.
You don't have to believe wikipedia but look at any online source of information about piano tuning to see how they need to deal with this very real phenomenon. Since pianos don't have frets we know that this happens on open strings.
This is where you are wrong. Pianos do not tune to the fundamental, at least not the lower and higher notes. Search for "piano stretch tuning" to see how piano strings are in fact not tuned to the fundamental.Anyway, a guitar, piano, etc all tune the fundamental. Upper harmonics being out of tune is the instrument's problem, not the tuner's.
...
As far as this not being a problem for a guitar tuner, it could very well be a problem if the harmonics are much louder than the fundamental, and the tuner needs to track something. If that something is not guaranteed to be a perfect multiple of the fundamental then it becomes a real problem.
It is exactly because we live in a practical world that we have to resort to alternative ways to detect pitch.All this said, I think you're heading down the wrong path for building a tuner. To get perfectly accurate frequency analysis you need an infinitely long time window to analyze. That obviously isn't practical or even approachable considering the short duration of a guitar note.
Been there done all of that. Cepstrum, autocorrelation, FFT, phase vocoder, zero-crossing, all of the above with all sorts of FIR and IIR filtering. None of them address the problem that harmonics aren't exact multiples of the fundamental.If I were you I'd look at matching waveform area above zero with waveform area below zero, and correlating to zero crossings. And I'd be filtering any harmonics higher than an octave above the high E string out of the equation entirely.
BTW in complex waveforms, matching areas above/below zero or checking zero crossings would be very inaccurate.
I'm making a general-purpose algorithm that can be used to detect the pitch of guitars or any other musical source really, including voice. Previously I've made one that tracks voice (using a modified auto-correlation algorithm), but I found that it had problems with guitars, hence this new effort to come up with a better algorithm.The best guitar tuners available will sometimes still show an octave-up error, particularly if you aren't careful how you play into it. Are you really just building a guitar tuner, or is this for pitch detection?
Overtones create challenges that make detecting the correct pitch difficult. There are two aspects really, being correct and being accurate. Being correct means detecting the correct note at the correct octave. Being accurate means detecting the real pitch to very high degree of accuracy. I've mostly solved the 1st part. The second part is difficult because of this inharmonic issue.
-
AdmiralQuality AdmiralQuality https://www.kvraudio.com/forum/memberlist.php?mode=viewprofile&u=83902
- Banned
- 6657 posts since 10 Oct, 2005 from Toronto, Canada
No, I insisted...BitFlipper wrote:The inharmonicity I'm referring to is specifically when playing open strings. I'm well aware that fretting results in deviations from the ideal frequency, never said that didn't happen. I've been insisting that harmonics being off on open strings is a real issue all along although you have insisted it isn't a problem. In fact you insisted that it will be an exact multiple of the fundamental when it clearly isn't in practice.AdmiralQuality wrote:From that Wikipedia article you like so much... http://en.wikipedia.org/wiki/Inharmonicity#Guitar
Which is exactly what I said above. You'll also note that the part you quoted said...Even if an electronic tuner indicates that the guitar is "perfectly" in tune, some chords may not sound in tune when they are strummed, either due to string inharmonicity from worn or dirty strings, a misplaced fret, a mis-adjusted bridge, or other problems. Due to the range of factors in play, getting a guitar to sound in tune is an exercise in compromise. "Worn or dirty strings are also inharmonic and harder to tune", a problem that can be partially resolved by cleaning strings.
"Pretty safe". And I'm not talking about the 15th harmonic, I'm talking about the second. Nor am I talking about fretting. My example was an OPEN string, damped at the 12th fret to produce the 2nd harmonic. (And note the OTHER points that I WAS talking about, like dirty strings.)AdmiralQuality wrote: You should be pretty safe assuming the 2nd harmonic is double the first/fundamental.
Then neither can you. You seem to want to know exactly how off each harmonic is going to be. But it depends on the guitar, the (6 different) strings, their condition, the player, the weather, pickup pull, etc...There is no indication exactly how much they will be off so you can't make any such claims.Exactly my point. That the first few harmonics will be relatively right-on. (As to whether the quote above means proportionately more so in linear measurement, or logarithmically, is unclear. Yay Wikipedia!)But on metal strings, tines, and reeds, the measured frequencies of those harmonics are slightly higher, and proportionately more so in the higher than in the lower harmonics.
Again, I find it odd that your measurement unit is cents. Cents implies distance off from a musical note. But the 3rd harmonic is NOT a musical note, it's 3 times the fundamental, which is NOT exactly the same as an octave and a fifth. http://en.wikipedia.org/wiki/Equal_temp ... intonation
My tests show that with the bass guitar, the 3rd harmonic is deviating enough from the expected frequency to be an issue. What did your own tests show? And there is the thing, I did the test and came up with a value of ~15 cents for the 3rd harmonic while you are just speculating at this point. Yes the 2nd harmonic will be closer to the correct value but its level is way too low to be useful in the case of the bass guitar.
Except when they're tuned to even temperment, which these days is ALL THE f**king TIME. http://www.kylegann.com/histune.html
You don't have to believe wikipedia but look at any online source of information about piano tuning to see how they need to deal with this very real phenomenon. Since pianos don't have frets we know that this happens on open strings.
This is where you are wrong. Pianos do not tune to the fundamental, at least not the lower and higher notes. Search for "piano stretch tuning" to see how piano strings are in fact not tuned to the fundamental.Anyway, a guitar, piano, etc all tune the fundamental. Upper harmonics being out of tune is the instrument's problem, not the tuner's.
...
I know what stretch tuning is and it's optional, not required. Most modern pianos aren't stretch tuned. This is so they can stay in tune with other instruments. A piano intended for solo performance MAY be stretch tuned (and even then, there's no set amount by which it has to be stretched).
Nothing is guaranteed. We're working in the real world here.
As far as this not being a problem for a guitar tuner, it could very well be a problem if the harmonics are much louder than the fundamental, and the tuner needs to track something. If that something is not guaranteed to be a perfect multiple of the fundamental then it becomes a real problem.
I'll just go on pretending my Boss TU-2 wasn't a waste of $110 then.
It is exactly because we live in a practical world that we have to resort to alternative ways to detect pitch.All this said, I think you're heading down the wrong path for building a tuner. To get perfectly accurate frequency analysis you need an infinitely long time window to analyze. That obviously isn't practical or even approachable considering the short duration of a guitar note.
But we know that the lower the harmonic is, the closer it gets to true. Right? So use that to approach what the fundamental SHOULD be. (Though I still think FFT or whatever you're doing is not optimal for a tuner or real-time pitch detector.)Been there done all of that. Cepstrum, autocorrelation, FFT, phase vocoder, zero-crossing, all of the above with all sorts of FIR and IIR filtering. None of them address the problem that harmonics aren't exact multiples of the fundamental.If I were you I'd look at matching waveform area above zero with waveform area below zero, and correlating to zero crossings. And I'd be filtering any harmonics higher than an octave above the high E string out of the equation entirely.
I didn't say "or". I said "and". You need to do both and apply a lot of logic in how you interpret it.
BTW in complex waveforms, matching areas above/below zero or checking zero crossings would be very inaccurate.
I'll be working on one of those soon. We can race 'em.I'm making a general-purpose algorithm that can be used to detect the pitch of guitars or any other musical source really, including voice. Previously I've made one that tracks voice (using a modified auto-correlation algorithm), but I found that it had problems with guitars, hence this new effort to come up with a better algorithm.The best guitar tuners available will sometimes still show an octave-up error, particularly if you aren't careful how you play into it. Are you really just building a guitar tuner, or is this for pitch detection?
Overtones create challenges that make detecting the correct pitch difficult. There are two aspects really, being correct and being accurate. Being correct means detecting the correct note at the correct octave. Being accurate means detecting the real pitch to very high degree of accuracy. I've mostly solved the 1st part. The second part is difficult because of this inharmonic issue.
-
- KVRist
- Topic Starter
- 222 posts since 7 Apr, 2003 from San Francisco, CA
Everything you say is overridden by the fact that I actually did the measurements and it is anything but negligible. So no matter how many times you insist that it doesn't really matter, it does. You are speculating, I am not.AdmiralQuality wrote:From that Wikipedia article you like so much... http://en.wikipedia.org/wiki/Inharmonicity#Guitar
"Pretty safe". And I'm not talking about the 15th harmonic, I'm talking about the second. Nor am I talking about fretting. My example was an OPEN string, damped at the 12th fret to produce the 2nd harmonic. (And note the OTHER points that I WAS talking about, like dirty strings.)
I can since I made the measurements. On the other hand you have not.Then neither can you...There is no indication exactly how much they will be off so you can't make any such claims.
I'll be interested to find the quote where I said (or even implied) that I want to know exactly how much the harmonic is off. Never said it once. Can you provide such a quote?You seem to want to know exactly how off each harmonic is going to be. But it depends on the guitar, the (6 different) strings, their condition, the player, the weather, pickup pull, etc...
What I did say was that I need to know how we as humans interpret the resulting smear of frequencies and come up with what we perceive to be the true pitch. It really is a simple question. Quite different from what you claim I said.
So wikipedia is ok now? Just asking. Cents doesn't imply distance from a musical note, it is simply a furher sub-division of the equal tempered scale. And we all know what cents is. If we expect a harmonic to fall on a "B", then it is convenient to specify the harmonic's deviation from that note in cents. Even the articles describing inharmonicity use cents to indicate the deviation. Do you want me to use a different unit? What should it be? Half steps? Percentage? Hz? It is a serious question since you brought this up multiple times now.Again, I find it odd that your measurement unit is cents. Cents implies distance off from a musical note. But the 3rd harmonic is NOT a musical note, it's 3 times the fundamental, which is NOT exactly the same as an octave and a fifth. http://en.wikipedia.org/wiki/Equal_temp ... intonation
No need to get so worked up, lol...Except when they're tuned to even temperment, which these days is ALL THE f**king TIME. http://www.kylegann.com/histune.html
So basically you are saying that modern times have fixed physical strings and the inharmonicity issue no longer exists? But seriously, it is more likely that these days people almost never play the very low/high keys so it doesn't really matter. Even more likely is that the piano is electronic in which case none of this applies. I can promise you that concert pianos used for classical music are still tuned this way.
Bottom line is that the phenomenon is just as real as it always have been when we talk of real strings, just that in most cases it can be ignored since modern music doesn't usually require such an extreme range from pianos.
Not sure what that is supposed to mean. Do you know how the pitch detection algorithm in that tuner is implemented? I can promise you it isn't based on some infinitely long time window so even it had deal with that reality. In other words it also had to "resort to alternative ways to detect pitch", or don't you think that is the case? Once again I'm not sure what your point is here since I'm obviously trying to work with real world problems encountered when implementing a pitch detector but you seem to think my answer lies in some perfect world solution.I'll just go on pretending my Boss TU-2 wasn't a waste of $110 then.It is exactly because we live in a practical world that we have to resort to alternative ways to detect pitch.
Unfortunately the amount of inharmonicity is different for different guitars. However my original point was that if we can accurately measure each of these harmonics, maybe we can come up with an algorithm that takes all of these into account and then comes up with a pitch that we as humans would also believe to be the "true" pitch. After all, no matter the amount of inharmonicity (within reason of course), ultimately we do believe it to be at one and only one true pitch.But we know that the lower the harmonic is, the closer it gets to true. Right? So use that to approach what the fundamental SHOULD be. (Though I still think FFT or whatever you're doing is not optimal for a tuner or real-time pitch detector.)
As for FFT not being ideal, I agree but you missed my whole explanation that the FFT is just one part of a more complex algorithm that first calculates the course pitch of where the fundamental should roughly be, and then it uses a completely different (non-FFT) algorithm to "hone in" on the true pitch. FFT is just too inaccurate (when being fed real-world signals) to do pitch detection but they are great to understand the general makeup of the whole frequency band and where the harmonics are located.
I'm already doing a lot of logic in how I interpret the harmonics. That is how I can deal with the missing fundamental problem. It is just that I have determined that the techniques you describe are not accurate enough to do reliable pitch detection with. I came to this conclusion after much experimentation.I didn't say "or". I said "and". You need to do both and apply a lot of logic in how you interpret it.
Sure that is fine with me.I'll be working on one of those soon. We can race 'em.

