‎2019-06-05 12:41 AM
Hello, I have found an implementation of the Goertzel algorithm that contains code that I don't understand. And more specifically the pre-calculation of coefficients. :pensive_face:
At the top of the code there is :
#define DTMF_697Hz 27980
#define DTMF_770Hz 26956
#define DTMF_852Hz 25701
#define DTMF_941Hz 24219
These defines are used inside the goertzel calculation like such :
for (i = 0; i < N; i++)
{
v0 = ((cos_fact * v1) >> 14) - v2 + *x;
x++;
v2 = v1;
v1 = v0;
}
x is my buffer.
v0, v1 and v2 are long int
cos_fact is the one of defines I showed above and passed as a function parameter.
My questions would be: What do these define correspond to? How to pre-calculate them for other frequencies? Is it normal that the values are so far apart?
Thank you ! :smiling_face_with_smiling_eyes:
ps: This code is part of ampm_open_lib and my goal would be to use it for detecting other frequencies than DTMFs tones.
‎2019-06-05 04:36 PM
At a first glance, it would seem the coeficients are related to 1/f + some offset. Why not just try altering the coefficients and plotting the peak detection frequencies on a graph ?
‎2019-06-07 04:43 AM
I got the answer.
This is the formula the have been used to calculate the cos_fact in the snippet above. :grinning_face_with_sweat:
coef = cos(2.0f * 3.14159f * (frequency / sample_rate)) * 256 * 128;
Hope it will help someone else :)