DSPRelated.com
Forums

Electronic Guitar Tuners

Started by rickman August 13, 2012
On 8/18/12 8:34 AM, Robert Adams wrote:
> > I wonder if you can interpolate auto-correlation peaks, since I don't think snapping to the nearest integer number of samples will be accurate enough. I've never seen this done before but I don't see why it couldn't be done.
'morning, Bob. well, even though i had also thought of it independently (i also think something like this is in Numerical Recipes and it has a name), long, long ago, before he went to Stanford, before he worked at Ensoniq, Jon Dattorro wrote a very crude preprint for some AES convention when he worked for Lexicon. i think Jon designed Lexicon's first pitch shifter. anyway, in that preprint Jon suggested taking the discrete peak and its two neighbors and fitting a simple quadratic to it and using the quadratic's peak as the true peak. using the x[] notation for discrete and x() for continuous and assuming a unity sampling period: if Rx[q] > Rx[q-1] and Rx[q] > Rx[q+1] where q = integer the quadratic peak is at p = q + (1/2) * (Rx[q+1] - Rx[q-1]) / (2*Rx[q] - Rx[q+1] - Rx[q-1]) and there is some similar formula for Rx(p). it's pretty simple, and for a pitch detector it is necessary to get the "true" peak height, so you might have a better idea which peak to pick among several of similar height. a good pitch detector will not always pick the highest peak, but you have to put some heuristics into it. this differs from Eric Jacobson's formula for spectral peaks by a factor of 1/2. to me it doesn't matter if it's autocorrelation or the magnitude (or magnitude squared) of the DFT, that's how it comes out. if all you have is three points around the peak, i dunno how you can do much better than this. with more points, you can fit something better. -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."
Thanks. I wonder if interpolating around the peak auto-corl and interpolati=
ng around the fft peak gives the same relative frequency error.=20

Also given that harmonics may not be exact multiples of the findamental, I =
wonder if the auto corl method is better or worse than the fft method.

What happens id you are making a pitch detector that is fed from a micropho=
ne, and you may have competing instruments that are only a little less loud=
 than the desired instrumemt? In the fft world it would be relatively easy =
to reject these. In the auto corl world maybe you would get multiple correl=
ation peaks that would also allow you to reject interferers. Not sure.=20
Even in the world of guitar tuners you can have very strong hum components,=
 or maybe other strings that are hit accidentally.=20
It's a challenge because these things need to be cheap enough that the budd=
ing guitarist can eventually move out of his parents basement. 
On 8/18/12 10:11 AM, Robert Adams wrote:
> Thanks. I wonder if interpolating around the peak auto-corl and interpolating around the fft peak gives the same relative frequency error. > > Also given that harmonics may not be exact multiples of the fundamental, I wonder if the auto corl method is better or worse than the fft method. > > What happens id you are making a pitch detector that is fed from a microphone, and you may have competing instruments that are only a little less loud than the desired instrumemt? In the fft world it would be relatively easy to reject these. In the auto corl world maybe you would get multiple correlation peaks that would also allow you to reject interferers. Not sure. > Even in the world of guitar tuners you can have very strong hum components, or maybe other strings that are hit accidentally.
these monophonic pitch detectors always have a problem if the guitarist doesn't play very cleanly. at least for the case of harmonization. for the case of using a pitch shifter to slightly detune the note (or chord) for the purpose of "thickening" or "chorusing", then it doesn't matter so much. but the guitar tuner is more the former than the latter.
> It's a challenge because these things need to be cheap enough that the budding guitarist can eventually move out of his parents basement.
well, it seems that the days of simple and cheap breadboarding of modern parts are over. i dunno how anyone does this on the cheap anymore. one reason i see companies like Danville Signal Processing (a.k.a. our own Al Clark) as useful, is you can get little boards from him where the surface-mount parts are mounted along with some necessary ancillary parts. and, using the ADI software (i s'pose it's VisualDSP) or, perhaps there's something GNU and free out there, you should be able to hook it up to USB and download, run, and debug code. but i don't see this as painless, and, as far as i'm concerned, it makes no business sense at all for manufacturers to neglect the salience of the experience where an engineer receives the DSK or dev board, pulls it out of the box, downloads the necessary apps (that should exist for Windoze/DOSbox, Mac/Terminal/Xcode, and Linux, all three) from a known internet site that has a passthru.asm and passthru.c test files, plugs in the USB and wallwart power, loads code and goes. BUT IT IS NEVER THAT EASY!!! i just don't understand why, in this day and age, it is *harder* to do anything with the computer, even the same basic tasks we used to do quite readily in the 90s. it just doesn't make sense. it's like we're going backwards. it's like these comp sci guys think they're doing a good job when what they're doing is shit. the worst is this goddamm auto-correct. those engineers should be lined up and shot. http://www.damnyouautocorrect.com/ that, and Micro$hit's dancing Mac or cute little puppy. it's all crap. that is what is making all of this challenging, and that is the challenge i certainly don't need to get my work (such as it is) done. grrrr. -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."
forgot to address some questions, you got me on a rant 'n roll, Bob.

On 8/18/12 10:11 AM, Robert Adams wrote:
>> Thanks. I wonder if interpolating around the peak auto-corl and >> interpolating around the fft peak gives the same relative frequency >> error. >>
well, the delta_F is the same for all frequencies with the FFT peak thing and it's the reciprocal of delta_F that is the same for all period lengths in the autocorrelation. so, of course, one will do better at higher frequencies and the other will do better for lower, from that POV alone.
>> Also given that harmonics may not be exact multiples of the >> fundamental, I wonder if the auto corl method is better or worse than >> the fft method.
well, the autocorrelation method makes no assumption about anything except periodicity. there need not be any energy at the fundamental for autocorrelation. what would you do using an FFT if there was no or very little fundamental. all pitch detectors can potentially have octave errors, but this is a source of octave errors that autocorrelation does not have. i don't think the overtones for these kind of instruments are very much non-harmonic. and even if they are (like a bell), how do you decide what the "pitch" is without looking for some compromize frequency that would be related to something that looks like a period.
>> What happens id you are making a pitch detector that is fed from a >> microphone, and you may have competing instruments that are only a >> little less loud than the desired instrumemt? In the fft world it >> would be relatively easy to reject these.
what, reject lessor peaks? what if the 2nd or 3rd harmonic of that tuba interferes with the fundamental of your sax, Bob?
>> In the auto corl world maybe >> you would get multiple correlation peaks that would also allow you to >> reject interferers. Not sure.
autocorr makes only *one* assumption; that of periodicity. doing it in the frequency domain is harder, makes more assumptions, unless you sweep it with comb filters. but you can show that this is a frequency-domain equivalent to Average Squared Difference Function (ASDF) which is directly related to autocorrelation. -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."
There once was a tuba player who interfered with my sax harmonics. Let's just say that I took care of the problem the old fashioned way :)

I also wonder about whether some sort of injection-locked oscillator scheme might work for pitch detection. 

Bob
On 8/18/2012 11:02 AM, robert bristow-johnson wrote:
> > well, it seems that the days of simple and cheap breadboarding of modern > parts are over. i dunno how anyone does this on the cheap anymore. one > reason i see companies like Danville Signal Processing (a.k.a. our own > Al Clark) as useful, is you can get little boards from him where the > surface-mount parts are mounted along with some necessary ancillary > parts. and, using the ADI software (i s'pose it's VisualDSP) or, perhaps > there's something GNU and free out there, you should be able to hook it > up to USB and download, run, and debug code. but i don't see this as > painless, and, as far as i'm concerned, it makes no business sense at > all for manufacturers to neglect the salience of the experience where an > engineer receives the DSK or dev board, pulls it out of the box, > downloads the necessary apps (that should exist for Windoze/DOSbox, > Mac/Terminal/Xcode, and Linux, all three) from a known internet site > that has a passthru.asm and passthru.c test files, plugs in the USB and > wallwart power, loads code and goes. BUT IT IS NEVER THAT EASY!!!
RBJ, Any time you want some hardware designed, give me a shout. I may be a little weak on the algorithm side of DSP, but I know my way around a surface mount part and would like to develop a small but highly useful board to sell. Right now I am taking a hard look at the very unusual GA144 and may just put some effort into designing a low end oscilloscope around it, but I would love to get back into making an off the shelf DSP board. I did this with a little success some twelve years ago, but stopped when it became clear that the software demands were too great. People asked me for all sorts of things that expected to come for free with any number of boards they bought. Now that there is a fair amount of open source software perhaps there is room in the market for a low cost but highly functional DSP board without getting too bogged down in the supporting software. I like to work on low power apps and would love to team low power DSPs with the low power FPGAs formerly from Silicon Blue, now from Lattice. Rick
On 8/17/2012 10:09 PM, robert bristow-johnson wrote:
> On 8/16/12 7:52 PM, rickman wrote: >> On 8/14/2012 8:54 AM, Dave wrote: >>> >>> There's a whole sub-culture of there of DIY guitar players - making >>> their own stompboxes etc. >>> So using the almighty google and searching "DIY guitar tuner" gives >>> some useful results. You can take a look at the circuitry in some of >>> these links to see what they're using: >>> >>> http://www.schickt.de/comments.php?y=08&m=06&entry=entry080606-004307 >>> >>> http://www.diystompboxes.com/smfforum/index.php?topic=88097.0 >>> >>> http://www.groupdiy.com/index.php?topic=4416.0 >>> >>> http://www.instructables.com/id/Visual--Aural-Guitar-Tuner-The-Tune-Trainer/?ALLSTEPS >>> >>> >>> >>> Cheers, >>> Dave >> >> Thanks, I did that and found a few dozen myself. I learned a lot from a >> wikipedia page on commercial products including some that are high end >> and strobe based. That might be a useful way to go. I just have to find >> something that isn't too much work. > > do you think auto-correlation is too much work?
I didn't get the question until now. By auto-correlation you mean a sliding correlation so that each result is with a different delta in time. No, I think that has comparable computation to a DFT and the advantage of the DFT is that it can be done over a subset of the full frequency range rather than always having to calculate the full range like an FFT. However, to find the frequency of interest a broader auto-corr or xFT would need to be performed initially. Then a detailed analysis could be done to hone in on the exact frequency. I'm also intrigued by some of the "stroboscopic" methods, but I haven't looked at how to implement them yet. My current thinking is that no matter what method I go with, it needs to be very high "performance", meaning highly accurate and reasonably fast. I believe the market is not large for this particular device. So better to go Cadillac and charge a price premium than to try to find a spot in a crowded, high volume market. So that means, will an auto-corr approach do a good job of resolving a fraction of a cent for a tuner in less than say the two or three seconds a note will sustain? I would have to consider just how accurate the auto-corr might be. Rick
On 8/18/12 10:50 PM, rickman wrote:
> On 8/17/2012 10:09 PM, robert bristow-johnson wrote: >> On 8/16/12 7:52 PM, rickman wrote:
...
>>> Thanks, I did that and found a few dozen myself. I learned a lot from a >>> wikipedia page on commercial products including some that are high end >>> and strobe based. That might be a useful way to go. I just have to find >>> something that isn't too much work. >> >> do you think auto-correlation is too much work? > > I didn't get the question until now. By auto-correlation you mean a > sliding correlation so that each result is with a different delta in > time.
yup. i call that "delta" the "lag".
> No, I think that has comparable computation to a DFT and the > advantage of the DFT is that it can be done over a subset of the full > frequency range rather than always having to calculate the full range > like an FFT.
you can compute the autocorrelation with a subset of lags. you don't need to do it for every possible integer lag, but only the lags of interest.
> However, to find the frequency of interest a broader auto-corr or xFT > would need to be performed initially. Then a detailed analysis could be > done to hone in on the exact frequency.
yah.
> I'm also intrigued by some of the "stroboscopic" methods, but I haven't > looked at how to implement them yet. > > My current thinking is that no matter what method I go with, it needs to > be very high "performance", meaning highly accurate and reasonably fast. > I believe the market is not large for this particular device. So better > to go Cadillac and charge a price premium than to try to find a spot in > a crowded, high volume market.
then i'm pretty sure that autocorrelation or AMDF or ASDF is what you'll want to do.
> So that means, will an auto-corr approach do a good job of resolving a > fraction of a cent for a tuner in less than say the two or three seconds > a note will sustain? I would have to consider just how accurate the > auto-corr might be.
pretty accurate, but *any* pitch detector *can* possibly have octave errors (it's what can happen if you have inaudible sub-harmonics). then you need to program the thing to have a little bit of common sense to avoid some of the dumber octave errors. i think that looking for energy at the frequency of the fundamental is a dumb octave error because there could be more energy at the 2nd harmonic or the 3rd harmonic and your alg might think that either of those is the fundamental frequency. does your DSP or whatever processor have conditional branch instructions? you don't need to compute the whole autocorrelation (all of the lags) for each and every sample. in fact, you might just compute *one* lag per sample and have a couple of special states where you set up the autocorrelation and where you process or scan the results of the autocorrelation to come up with a period length. and you can do some interpolation-like stuff to get the period to a precision of a fraction of a sample period. i.e. look for the peak where it falls between two integer lags. it's not hard. that's all you get for free. -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."
robert bristow-johnson <rbj@audioimagination.com> writes:

> On 8/18/12 8:34 AM, Robert Adams wrote: >> >> I wonder if you can interpolate auto-correlation peaks, since I don't think snapping to the nearest integer number of samples will be accurate enough. I've never seen this done before but I don't see why it couldn't be done.
[snip good stuff]
> this differs from Eric Jacobson's formula for spectral peaks by a > factor of 1/2. to me it doesn't matter if it's autocorrelation or the > magnitude (or magnitude squared) of the DFT, that's how it comes > out. if all you have is three points around the peak, i dunno how you > can do much better than this. with more points, you can fit something > better.
I'm not familiar with the literature, but a trick I've used for peak detection (surely someone else invented this first) is to conceptually convolve the sample (in this case the auto-correlation) with a gaussian. This results in a function that is continuous in all its derivatives, so you can use Newton's method to find the location of the zero in the first derivative. I've used this in 2 and 3 dimensions for non-DSP type problems. Scott -- Scott Hemphill hemphill@alumni.caltech.edu "This isn't flying. This is falling, with style." -- Buzz Lightyear
>I am being asked to design a gadget that has some special features, but >also includes a guitar tuner. I have looked at the web a bit, but not >found any good references that show exactly how a tuner works. One >paper I found talked about a rather complex "constant Q transform". I >just don't think the $10 tuner I have uses anything that complex. I'm >thinking they are doing a PLL sync to the input or something more like >that. > >One reference I found talks about using a peak detect to measure period >rather than frequency like an FFT. I would think the FFT has too little >resolution unless it is very long. > >Anyone know how the commercial low end gadgets really work? Maybe I'll >take mine apart, but my bet is they are using chip on board with the die >under a dab of black goo. > >Rick
Hi Rick - although not a conventional technique you could use a short fft and then apply an interferometric measurement to improve the resolution , this is a technique which is used a lot in somar and rader with phased arrays. With phase arrays special,frequencies relate to beam direction. So to keep,the arrays short engineers useinterferometric techniques. I simulated a guitar tuner using this technique a while back and it showed promise. Colin