c# - FFT Fundamental frequency calculation from LomontFFT -


i using lomontfft http://www.lomont.org/software/misc/fft/lomontfft.html fundamental frequency sampled values of signal. testing if fundamental frequency correctly determined, have used samples past (with known fundamental frequency).

below code have written call lomontfft algo , determine fft:

private void buttonfft_click(object sender, eventargs e)     {         //double fftavg = 0;         double fftmax = 0;         var fftdata = new byte[512];         double[] fftvalues = enumerable.repeat(0.0, 512).toarray();                             array.copy(sapmleddoublevaluesadc1, fftvalues, sapmleddoublevaluesadc1.length); var fftmethod = new lomont.lomontfft();         fftmethod.realfft(fftvalues, true);          (int = 0; < 512; += 2)         {             double fftmag = math.sqrt((fftvalues[i] * fftvalues[i]) + (fftvalues[i + 1] * fftvalues[i + 1]));             if (fftmag > fftmax)                 fftmax = fftmag;             //fftavg += fftmag;             //fftdata[i] = (byte)fftmag;             //fftdata[i + 1] = fftdata[i];         }         textboxfundafreq.text = "frey = " + fftmax.tostring();         (int x = 1; x < 512; x++)         {             this.chart2.series[0].points.addxy(x, fftvalues[x]);         }     } 

but problem magnitude of frequency wrong. fft doesn't match possible there multiple solutions, frequency should same. algo proven many years not wrong. doing wrong in calling code?

(i have real values in sampled data)

fundamental frequency extraction / pitch detection not simple algorithm. input signal (anything other single sine/cosine wave) fft show several peaks , better estimate distance between peaks.

further need interpolate fft bins acurate result single peak.

for applications better calculate auto-correlation-function (acf) anyway.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -