Usando o algoritmo Goertzel para detectar frequência

Eu estou tentando escrever um programa para android para detectar freqüência usando o algoritmo de Goertzel. No entanto, quando eu aplico o algoritmo nos dados que recebo do método read () AudioRecord, a magnitude não atinge o pico na frequência alvo (.ie: geralmente atinge o pico na baixa frequência). Eu estou entendendo mal alguma coisa?

protected void detect() { double[] dbSample = new double[bufferSize]; short[] sample = new short[bufferSize]; max_magnitude = 0; while(isRecording){ int bufferReadResult = recorder.read(sample,0,bufferSize); for (int j=0;j<bufferSize&&j<bufferReadResult;j++) { dbSample[j] = (double)sample[j]; } } int freq=0; while(freq<=20000){ Goertzel g = new Goertzel(RECORDER_SAMPLE_RATE,freq,bufferSize); g.initGoertzel(); for(int i=0;imax_magnitude){ max_magnitude = magnitude; detect_freq = freq; } g.resetGoertzel(); freq+=50; } } 

Goertzel.java

 public class Goertzel { private float samplingRate; private float targetFrequency; private long n; private double coeff, Q1, Q2; private double sine, cosine; public Goertzel(float samplingRate, float targetFrequency, long inN) { this.samplingRate = samplingRate; this.targetFrequency = targetFrequency; n = inN; sine = Math.sin(2 * Math.PI * (targetFrequency / samplingRate)); cosine = Math.cos(2 * Math.PI * (targetFrequency / samplingRate)); coeff = 2 * cosine; } public void resetGoertzel() { Q1 = 0; Q2 = 0; } public void initGoertzel() { int k; float floatN; double omega; floatN = (float) n; k = (int) (0.5 + ((floatN * targetFrequency) / samplingRate)); omega = (2.0 * Math.PI * k) / floatN; sine = Math.sin(omega); cosine = Math.cos(omega); coeff = 2.0 * cosine; resetGoertzel(); } public void processSample(double sample) { double Q0; Q0 = coeff * Q1 - Q2 + sample; Q2 = Q1; Q1 = Q0; } public double[] getRealImag(double[] parts) { parts[0] = (Q1 - Q2 * cosine); parts[1] = (Q2 * sine); return parts; } public double getMagnitudeSquared() { return (Q1 * Q1 + Q2 * Q2 - Q1 * Q2 * coeff); } 

}