DSPRelated.com
Forums

Guitar Tuner - Low frequencies are not working

Started by noodle22 February 7, 2009
Hi,

I have been trying to create a guitar tuner for the sole purpose of
expanding my understanding of dsp.  I started by trying to use the FFT
method.  This worked pretty well but when I played an A below middle C, it
gave a frequency of 220Hz instead of 440Hz (while the A above middle C was
440Hz).  As I played lower notes, other strange things occurred.  When I
hit the C below middle C, it read 393Hz and said it was a G and the D said
it was an A (440 Hz).

When I look at the spectrum, the peaks for the low C and the low D are
very small to non-existant while the G and A were huge.  I thought it might
have been a problem with my FFT so I tried the 0 cross over method and the
same thing occurred.  The crossover method only worked for a small range of
high frequencies, I'm guessing because of too much noise of over tones or
something.  However, after a correlation, it worked a bit better and, I did
notice when play the A below middle C, it gave 440 instead of 220.

I should mention that I also tried autocorrelation.  This issue, however,
seems like it might have to do with my set up, or perhaps even my mic.  Any
ideas on how to fix this?


noodle22 wrote:
> Hi, > > I have been trying to create a guitar tuner for the sole purpose of > expanding my understanding of dsp. I started by trying to use the FFT > method. This worked pretty well but when I played an A below middle C, it > gave a frequency of 220Hz instead of 440Hz (while the A above middle C was > 440Hz).
Eh? The A below Middle C IS 220Hz. As I played lower notes, other strange things occurred. When I
> hit the C below middle C, it read 393Hz
= 3rd harmonic. and said it was a G and the D said
> it was an A (440 Hz).
ditto. (a) What size window (and srate) are you using? (b) at the moment of the attack, the fundamental has barely become established, and octave errors are very possible - so how long are you waiting (over how many FFT windows) before trying to derive the pitch? One method (CPU-permitting of course) is in fact to detect the harmonics, compute their separation (which for a harmonic sound should be close to the fundamental anyway), and derive the fundamental as the average of those intervals. The high harmonics develop first - especially if you pick close to the bridge (and use a pick rather than a naked finger).
> > When I look at the spectrum, the peaks for the low C and the low D are > very small to non-existant while the G and A were huge. I thought it might > have been a problem with my FFT so I tried the 0 cross over method and the > same thing occurred. The crossover method only worked for a small range of > high frequencies, I'm guessing because of too much noise of over tones or > something. However, after a correlation, it worked a bit better and, I did > notice when play the A below middle C, it gave 440 instead of 220. >
= 2nd harmonic. See above - better revise your assumptions about what note corresponds to what frequency! Richard Dobson
This worked pretty well but when I played an A below middle C, it
>> gave a frequency of 220Hz instead of 440Hz (while the A above middle C
was
>> 440Hz). > >Eh? The A below Middle C IS 220Hz.
I messed this up. I meant to say it gave a frequency of 440Hz instead of 220Hz. I figured this was harmonics...the real issue is with the C (and related notes)
> >As I played lower notes, other strange things occurred. When I >> hit the C below middle C, it read 393Hz > >= 3rd harmonic.
figures...I think this is going to be tricky to correct
>(a) What size window (and srate) are you using?
I've tried a few different windows but noticed no difference. Lately, I have been sticking to 16384 with a sample rate of 44100Hz
>(b) at the moment of the attack, the fundamental has barely become >established, and octave errors are very possible - so how long are you >waiting (over how many FFT windows) before trying to derive the pitch?
I'm not really waiting, but am taking continuous FFT's, so it updates the detected not every 0.4 seconds or so.
>One method (CPU-permitting of course) is in fact to detect the >harmonics, compute their separation (which for a harmonic sound should >be close to the fundamental anyway), and derive the fundamental as the >average of those intervals. The high harmonics develop first - >especially if you pick close to the bridge (and use a pick rather than a
>naked finger).
I have been doing this to some degree actually. The way I've been detecting the fundamental frequency is not really just grabbing the highest magnitude or first peak. I am looking for the minimum distance between peaks. But it isn't ideal because a) some peaks are just too small or non-existent b) What I really need is to get the greatest common factor for the minimum distance between peaks. I'm not sure exactly how to do this but you've made me think that I should work harder at refining that part of the process. Also, I updated my code so that it grabs a few samples at the beginning, averages them, and then subtracts them from all future samples (or order to remove some background spectrum) and it seems to have really improved my results.
if i were you, i would ditch the FFT and use some kinda correlation
method, like AMDF, to determine the period.  since you have to log the
f0 to get pitch, doing it to the period is no worse.

r b-j
On Sat, 07 Feb 2009 15:00:53 -0600, noodle22 wrote:

> Hi, > > I have been trying to create a guitar tuner for the sole purpose of > expanding my understanding of dsp. I started by trying to use the FFT > method. This worked pretty well but when I played an A below middle C, > it gave a frequency of 220Hz instead of 440Hz (while the A above middle > C was 440Hz). As I played lower notes, other strange things occurred. > When I hit the C below middle C, it read 393Hz and said it was a G and > the D said it was an A (440 Hz). > > When I look at the spectrum, the peaks for the low C and the low D are > very small to non-existant while the G and A were huge. I thought it > might have been a problem with my FFT so I tried the 0 cross over method > and the same thing occurred. The crossover method only worked for a > small range of high frequencies, I'm guessing because of too much noise > of over tones or something. However, after a correlation, it worked a > bit better and, I did notice when play the A below middle C, it gave 440 > instead of 220. > > I should mention that I also tried autocorrelation. This issue, > however, seems like it might have to do with my set up, or perhaps even > my mic. Any ideas on how to fix this?
How good is your sound capture system? If you're cutting off the low range before it hits the ADC, then it's going to be hard to get it to work right with signal processing. -- http://www.wescottdesign.com
First, thanks everyone for your help.

>if i were you, i would ditch the FFT and use some kinda correlation >method, like AMDF, to determine the period. since you have to log the >f0 to get pitch, doing it to the period is no worse.
I've read a few posts from other people trying to also create guitar tuners and lots of times people do suggest ditching the FFT. I wasn't quite sure how to ditch the FFT (other than 0 crossovers) and then found this site http://neural.cs.nthu.edu.tw/jang/books/audioSignalProcessing/index.asp I am looking into these methods more and would like to get some working in addition to the FFT to compare
>How good is your sound capture system? If you're cutting off the low >range before it hits the ADC, then it's going to be hard to get it to >work right with signal processing.
I am using my laptop's sound card so likely not very good. However, I have a firebox (which is a music recording device that is pretty decent) which I have not tried yet so I will try with that and let you know how it goes as well.
Ok, I've learned a couple things.

a) I have an issue with there being a background frequency of 60Hz (which
is pretty normal I guess).  Is there a way I can get rid of this frequency
in the time domain?  I had been removing it in the frequency domain with
the FFT and just subtracking the background spectrum.  I don't really want
to completely get rid of all 60Hz signals because I am actually trying to
make a chromatic tuner that I can mess around with on my piano as well as
guitar.  The lowest note on the piano is around 27 Hz or so so I still need
60Hz (unless I can use harmonics instead)

b) my sound card and/or mic is part of the issue.  When I hit the key for
A 220Hz (below middle C), I lose my nice wave and end up with just
harmonics.  Anything below that A is the same.  So, I think I will have to
use the harmonics to get tunings for these notes.  As far as I am aware,
this means I am stuck with FFTs and will just try to find the largest
frequency numbers that will divide into all the peaks with integral
numbers.

Also, I guess in this case, point (a) is moot because I can't detect 60Hz
with my computer but for argument's sake, can someone still advise on (a)?
noodle22 wrote:
> Ok, I've learned a couple things. > > a) I have an issue with there being a background frequency of 60Hz (which > is pretty normal I guess). .. > Also, I guess in this case, point (a) is moot because I can't detect 60Hz > with my computer but for argument's sake, can someone still advise on (a)?
Main hum picked up on the audio wires. Pretty normal to find a way to remove it by using ground lifts, eliminating earth loops in studio wiring, carefully managing shielding, using balanced connections where possible, keeping adc/dac outside the computer itself. There are safe and unsafe ways of eliminating hum, so best you consult an experienced studio engineer for help. Richard Dbson
noodle22 <jw970170@yahoo.com> wrote:

>b) my sound card and/or mic is part of the issue. When I hit the key for >A 220Hz (below middle C), I lose my nice wave and end up with just >harmonics. Anything below that A is the same. So, I think I will have to >use the harmonics to get tunings for these notes. As far as I am aware, >this means I am stuck with FFTs and will just try to find the largest >frequency numbers that will divide into all the peaks with integral >numbers.
Taking the GCD as part of a fundamental frequency estimate is an excellent idea, since musical tones often have a weak fundamental but the listener's brain psychoacoustically infers it. It does not mean you are stuck with FFT's, particularly. I think the transform is a good method for a first pass at deciding where the fundamental probably is. Something like BCD(three top peaks) = (probable fundamental), then operate a more specific algorithm to find the likeliest frequency in that vicinity. Musical harmonics can often be fairly off-true, as well. Steve
On Feb 7, 1:00&#4294967295;pm, "noodle22" <jw970...@yahoo.com> wrote:
> Hi, > > I have been trying to create a guitar tuner for the sole purpose of > expanding my understanding of dsp. &#4294967295;I started by trying to use the FFT > method. &#4294967295;This worked pretty well but when I played an A below middle C, it > gave a frequency of 220Hz instead of 440Hz (while the A above middle C was > 440Hz). &#4294967295;As I played lower notes, other strange things occurred. &#4294967295;When I > hit the C below middle C, it read 393Hz and said it was a G and the D said > it was an A (440 Hz). > > When I look at the spectrum, the peaks for the low C and the low D are > very small to non-existant while the G and A were huge. &#4294967295;I thought it might > have been a problem with my FFT so I tried the 0 cross over method and the > same thing occurred. &#4294967295;The crossover method only worked for a small range of > high frequencies, I'm guessing because of too much noise of over tones or > something. &#4294967295;However, after a correlation, it worked a bit better and, I did > notice when play the A below middle C, it gave 440 instead of 220.
You have (re)discovered the fact that pitch is often not the same thing as the dominant frequencies in a signals spectral (FFT) content. I have a whole page of FFT usage misconceptions on my website: http://www.nicholson.com/rhn/dsp.html Many live musical instruments and such, male singing voices, etc., produce an array of frequencies with relatively little or even no energy at the frequency of the perceived pitch. But since pitch is a psychological and physiological phenomena, humans still hear that pitch. As an exercise for the student, assume that the low strings of a guitar produce a train of harmonic overtones, none of which is at the fundamental pitch frequency. Could you deduce a pitch from that train of overtones? . IMHO. YMMV. -- rhn A.T nicholson d.0.t C-o-M