Implementation of Goertzel algorithm in C

前端 未结 3 1207
难免孤独
难免孤独 2020-12-29 10:13

I am implementing BFSK frequency hopping communication system on a DSP processor. It was suggested by some of the forum members to use Goertzel algorithm for the demodulatio

3条回答
  •  南方客
    南方客 (楼主)
    2020-12-29 10:56

    Consider two input sample wave-forms:

    1) a sine wave with amplitude A and frequency W

    2) a cosine wave with the same amplitude and frequency A and W

    Goertzel algorithm should yield the same results for two mentioned input wave-forms but the provided code results in different return values. I think the code should be revised as follows:

    float goertzel_mag(int numSamples,int TARGET_FREQUENCY,int SAMPLING_RATE, float* 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

提交回复
热议问题