hi David, do you have any code for this so that i can test with this or let me know what approach can i use.
i am currently using the below code added as functions which inserted in app_amd.c and calling in the answering machine detection to find a value.
#include “math.h”
#define SAMPLEFREQUENCY 8000;
//#define M_PI 3.14159265358979323846;
double goertzelFilter(int samples[], double freq, int N) {
double s_prev = 0.0;
double s_prev2 = 0.0;
double coeff,normalizedfreq,power,s;
int i;
normalizedfreq = freq / SAMPLEFREQUENCY;
coeff = 2 * cos(2 * M_PI * normalizedfreq);
for (i=0; i<N; i++) {
s = samples[i] + coeff * s_prev - s_prev2;
s_prev2 = s_prev;
s_prev = s;
}
power = s_prev2s_prev2+s_prevs_prev-coeffs_prevs_prev2;
return power;
}
float goertzel_mag(int numSamples,int TARGET_FREQUENCY,int SAMPLING_RATE, int* data)
{
int k,i;
float floatnumSamples;
float omega,sine,cosine,coeff,q0,q1,q2,magnitude,real,imag;
float scalingFactor = numSamples / 2.0;
floatnumSamples = (float) numSamples;
k = (int) (0.5 + ((floatnumSamples * TARGET_FREQUENCY) / SAMPLING_RATE));
omega = (2.0 * M_PI * k) / floatnumSamples;
sine = sin(omega);
cosine = cos(omega);
coeff = 2.0 * cosine;
q0=0;
q1=0;
q2=0;
for(i=0; i<numSamples; i++)
{
q0 = coeff * q1 - q2 + data[i];
q2 = q1;
q1 = q0;
}
// calculate the real and imaginary results
// scaling appropriately
real = (q1 - q2 * cosine) / scalingFactor;
imag = (q2 * sine) / scalingFactor;
magnitude = sqrtf(real*real + imag*imag);
return magnitude;
}
Code used in answering machine isAnsweringMachine()
int fdata[256];
int16_t *dataptr;
double sine_len;
int sine_len_i;
double beep_len_i;
int pos;
ast_verb(3, “BEEP: Channel [%s]. Beep Test Goertzel Power: %f\n”, chan->name, goertzelFilter(dataptr, 500, f->datalen ) );
ast_verb(3, “BEEP: Channel [%s]. Beep Test Goertzel Magnitude: %f\n”, chan->name, goertzel_mag(f->samples, 500, 8000, dataptr ) );