matlabsignal-processingfftguitar

How to generate accurate FFT plot of guitar harmonics with only 256 data points @ 44.1khz Fs ?[Matlab]


I'm trying to make a realtime(ish) monophonic guitar to midi program. I want a latency of <=6 milli secs. To find what note was played i aim to sample 256 points (should take approx 6 millis) , run an fft and analyze mag plot to determine pitch of note played.

When i do this in matlab, it gives me back very unstable/inaccurate results with peaks appearing in random places etc.

The note being inputted is 110Hz sampled @ 44.1khz. I've applied a high pass filter at 500hz with a roll off of 48db/octave.. so only the higher harmonics of signal should remain. The audio last for 1 second ( filled with zeros after 256 samples)

Code:

%fft work

guitar = wavread('C:\Users\Donnacha\Desktop\Astring110hz.wav');
guitar(1:44100);
X = fft(guitar);
Xmag = abs(X);
plot(Xmag);

Zoomed in FFT plot

I was hoping to see all the harmonics of 110Hz (A note on guitar) starting at >500hz..

How would i achieve accurate results from an FFT with such little data?


Solution

  • You can't. (at least reliably for all notes in a guitar's range).

    256 samples at 44.1kHz is less than one period of most low string guitar notes. One period of vibration from a guitar's open low E string takes around 535 samples, depending on the guitar's tuning and intonation.

    Harmonics often require multiple periods (repetitions) of a guitar note waveform within the FFT window in order to reliably show up in the FFT's spectrum. The more periods within the FFT window, the more reliably and sharper the harmonics show up in the FFT spectrum. Even more periods are required if the data is Von Hann (et.al.) windowed to avoid "leakage" windowing artifacts. So you have to pick the minimum number of periods needed based on the lowest note needed, your window type, and your statistical reliability and frequency resolution requirements.

    An alternative is to concatenate several sets of your 256 samples into a longer window, at least as long as several periods of the lowest pitch you want to reliably plot.