Note that there are some explanatory texts on larger screens.

plurals
  1. PODetecting fundamental frequency with comb filter
    text
    copied!<p>I need to use comb filter/transform to detect fundamental frequency of a wav file in java. I also needed to implement ZCR, but this was easy.</p> <p>Now I have this:</p> <pre><code> int best = 0, best_step = 0; for (int step = 3; step &lt; 400; ++step) { int sum = 0; for (i = 1; i &lt; 10 &amp;&amp; i * step &lt; spectrum.length; ++i) { for (int di = 0; di &lt; i; ++di) { sum += spectrum[i * step + di] / i; } } sum *= 100; comb.add(sum); } int sum = 0; for (i = 0; i &lt; comb.size(); ++i) { sum = comb.get(i); // 3 * comb[i] - comb[i-1] - comb[i+1]; System.out.println(i + " - " + sum); if (sum &gt; best) { best_step = i; best = sum; } } </code></pre> <p>And my problem is that this code detects the wrong frequency. ;( I have searched for an algorithm/implementation (in any language) but have not found anything. </p> <p>Note, I cannot use autocorelation, etc.. It must be comb filtering.</p> <p><strong>Edit:</strong> A little more explanation of my code:</p> <p>I load a wav file and put frames to array frames. Then I make fft on it and have array of Complex (named widmo) (simple structure to handle complex numbers).</p> <p>Now I put abs of Complex numbers into array spectrum:</p> <pre><code>double[] spectrum = new double[widmo.length]; for (i = 0; i + 1 &lt; widmo.length; ++i) { spectrum[i] = widmo[i].abs(); } ArrayList&lt;Integer&gt; comb = new ArrayList&lt;Integer&gt;(); int best = 0, best_step = 0; for (int step = 3; step &lt; 400; ++step) { int sum = 0; for (i = 1; i &lt; 10 &amp;&amp; i * step &lt; spectrum.length; ++i) { for (int di = 0; di &lt; i; ++di) { sum += spectrum[i * step + di] / i; } } // sum /= step + 100; // ta linijka pozwala usunąć sporo // niespodziewanych skoków częstotliwości sum *= 100; comb.add(sum); } int sum = 0; for (i = 0; i &lt; comb.size(); ++i) { sum = comb.get(i); // 3 * comb[i] - comb[i-1] - comb[i+1]; // ctx.fillRect(i, canvas.height, 1, -sum); System.out.println(i + " - " + sum); // tmp.add(new freqTime(sum,)); if (sum &gt; best) { best_step = i; best = sum; } } System.out.println(); System.out.println(best_step); System.out.println(4 * 44100); System.out.println((frames.length / numChanels)); System.out.println(best_step * 44100 / (frames.length / numChanels)); </code></pre> <p>The last <code>println</code> should show me my fundamental frequency, but it doesn't,.</p> <p>I got this in javascript from my friend. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload