Hacker News new | ask | show | jobs
by whiw 1972 days ago
Great idea, I love the idea of getting real-time transcription of what I'm attempting to play.

As others have commented, it seems to struggle with the low E and A strings of guitar. Thinking about this:

1. The smallest note interval is from open low E (82Hz) up to the next semitone (82*(2^(1/12) -1)), which is about 5Hz. This gives the maximum bin width.

2. The guitar range is approx 4 octaves, ie up to about 330Hz. The min sampling freq must be double this.

3.In practice the bin edges wont line up with the semitone boundaries, so we ought to aim for bin widths smaller than half of 5Hz above, say 2Hz. This guarantees that a bin exists that doesn't cross semitone boundaries.

4. As lower frequencies probably wont be sampled across an integer number of cycles, spectral smearing will occur. This can be reduced by making the binwidth even smaller, and by use of windowing in the time domain.

5. My environment has background noise (eg computer fan). Unless the noise is filtered out pre-sampling (which it probably isn't for most users) then this will fold back into the signal of interest. Sampling at a higher rate than 2 x 330Hz would allow separation of the noise from the signal. I'm not sure what sample rate is used in the app. If the noise goes up to 4kz (I'm guessing) then this implies a sample rate of 8kHz to remove it.

6. From the above: sample at 8kHz for 1 second, use a window funtion to reduce spectral leakage. 8192 samples is a handy power of 2. Smaller sized ffts are likely to struggle to identify the right bin at lower frequencies, and/or have more noise in the signal band to confuse the peak detector.

7. An oscilloscope display would be handy to verify that signal levels were ok, and that noise isn't too intrusive.

2 comments

Not a DSP expect by any means, but I think you can do better pitch detection without using an FFT. Instead, you want something like auto-correlation:

https://en.wikipedia.org/wiki/Autocorrelation

I'm not sure it is better, unless you can do autocorrelation in hardware without using an fft. This option is unavailable on standard PCs.

If done in software then a simple implementation of autocorrelation is O(n^2). An efficient implemementation is O(n.log(n)) (it uses two ffts).

I've just noticed an error in the above: 330Hz should read 1312Hz.

The remaining figures still look ok though.