cancel
Showing results for 
Search instead for 
Did you mean: 

Pre-calculation of Geortzel coefficient

MLamb
Associate

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.

This discussion has been locked for participation. If you have a question, please start a new topic in order to ask your question
2 REPLIES 2
MikeDB
Lead

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 ?

MLamb
Associate

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 :)