0
\$\begingroup\$

I am wanting to measure the pitch of a single guitar string and convert into MIDI within 10ms.

FFT takes too much time, I was wondering what other options are worth looking at? The main issue is latency.

Can this be done using an analogue method? I.E Frequency to voltage converter?

\$\endgroup\$
  • \$\begingroup\$ in 10 milliSeconds, you only have 100Hertz bin-spacing (resolution) using the FFT. Thus you need analysis that uses the phase-rotation as an additional part of the frequency measurement. \$\endgroup\$ – analogsystemsrf Jul 26 at 3:43
  • \$\begingroup\$ @analogsystemsrf Are you saying this can be achieved using phase-locked-loops? I don't want to use FFT at all, my question is about alternatives that could work. Thanks \$\endgroup\$ – David Jul 26 at 4:50
6
\$\begingroup\$

There isn’t enough information in 10 mS of sampled audio to reliably tell the difference in frequency between a low E and a low F or D# notes.

10 mS is barely more than 1 full pitch cycle at those low frequencies, and there’s tons of non-pitched noise from the attack (pluck or strum) interfering with any measurement of the rate of phase change of the higher harmonics, assuming a pitch has even stabilized. (Just look at a plot of the beginning of a notes waveform to see this!) And you have to analyze the harmonics, as the higher overtones might be stronger (e.g. have the largest magnitudes in an FFT result) than the fundamental pitch frequency of the lowest string notes (search "missing fundamental" for details). And the odd harmonics are not even the same musical note as the fundamental pitch.

For an FFT to show semitone different (5.9%) note fundamentals in completely separate FFT result bins, you would need at least 17 full pitch cycles, up to 2X more if you window before the FFT.

The loop filter of a stable PLL might have a similar delay.

Once the pitch has stabilized (entered sustained ringing after the attack transient phase), up-sampled or interpolated autocorrelation (or AMDF or ASDF) might provide a decent pitch estimate faster than an FFT.

A better bet would be to try to measure the reflection time of the traveling wave down the string from the pluck to the fret and back before the pitch stabilizes to a constant frequency standing wave. From the reflection time, you can make a guess about which fret is pressed. And then guess which note corresponds to that fret.

Or feed a complete set of note attack transients to train a DNN via machine learning, since that might be closer to how humans recognize notes quickly.

\$\endgroup\$
5
\$\begingroup\$

Since your guitar string can only produce a handful of pitches, a full FFT is wasteful.

Take the lower E string. The tones are approximately 5Hz apart.

Assume a sampling rate of 11025 Hz. To get your FFT bins spaced closely enough together, you will need an FFT length of at least 2048 resulting in 1024 bins. You calculate 1024 bins, then discard 1000 of them because there are only 20 notes on a guitar string. Along with that, you also have a time resolution of 185 milliseconds.

You can do overlapping FFTs and improve your time resolution. That works, and may be all the solution you need.

An alternativ would be to use the Goertzel algorithm. It implements a discrete fourier transformation for individual frequenicies. It is efficient enough that it is used in small microprocessors to do DTMF decoding - simultaneous decoding of 8 frequencies and short decoding times.

Using the Goertzel algorithm, you only get the tones you are interested in. You can also "tune" the computation of the values so that you get a clear separation of notes - without changing the computation time.

You can get an update on the intensity for each audio sample.

It does take at least one or two complete cycles of a note for the output value to reach maximum. That's like 23 milliseconds for the low E - but only 3 milliseconds for the high E string. That's to reach full output.

In the FFT, your time resolution is fixed by the length of the FFT and the overlap. Thing is, you *need** better time resolution on the higher notes, and can live with lower time resolution on lower notes.

A similar thing applies to the frequency bins. You need closer bins to separate the low notes, but could live with wider spaced bins at the high notes.

Using the FFT, you have to compromise and end up doing long FFTs with large overlap to get the time and frequency resolution you need.


This isn't a theoretical solution. I actually have a Goertzel based analyser that can detect all notes on a guitar and translate it to a note name in realtime. Has a graphical display of which note is currently playing. Just don't play more than one note at a time...

I was working on recognizing chords when I got sidetracked on a different project and never got back to the guitar thing.

\$\endgroup\$
  • \$\begingroup\$ ... and then you want to get pitch bends, vibrato, etc. \$\endgroup\$ – Transistor Jul 26 at 6:21
  • \$\begingroup\$ @Transistor: In which case the FFT isn't much help, either. \$\endgroup\$ – JRE Jul 26 at 7:43
  • \$\begingroup\$ Neither a Goertzel nor a bare FFT magnitude peak will work on low guitar notes with weak or missing fundamental frequency peaks in the audio spectrum. Very common, depending on guitar and mic placement, etc. \$\endgroup\$ – hotpaw2 Jul 26 at 22:46
  • 1
    \$\begingroup\$ "when I got sidetracked on a different project and never got back"... pff, that would never happen to any of my projects! \$\endgroup\$ – pipe Jul 27 at 4:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.