Note that there are some explanatory texts on larger screens.

plurals
  1. PODTMF Goertzel Algorithm Not Working
    primarykey
    data
    text
    <p>So I am opening a .raw file of a DTMF tone I generated in audacity. I grabbed a canned goertzel algorithm similar to the one on the wikipedia article. It doesn't seem to decode the correct numbers though.</p> <p>The decoded number also changes depending on what value of N I pass to the algorithm. As far as I understood a higher value of N gives it better accuracy but should not change what number would get decoded correct?</p> <p>Here is the code,</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;math.h&gt; double goertzel(short samples[], double freq, int N) { double s_prev = 0.0; double s_prev2 = 0.0; double coeff, normalizedfreq, power, s; int i; normalizedfreq = freq / 8000; coeff = 2*cos(2*M_PI*normalizedfreq); for (i=0; i&lt;N; i++) { s = samples[i] + coeff * s_prev - s_prev2; s_prev2 = s_prev; s_prev = s; } power = s_prev2*s_prev2+s_prev*s_prev-coeff*s_prev*s_prev2; return power; } int main() { FILE *fp = fopen("9.raw", "rb"); short *buffer; float *sample; int sample_size; int file_size; int i=0, x=0; float frequency_row[] = {697, 770, 852, 941}; float frequency_col[] = {1209, 1336, 1477}; float magnitude_row[4]; float magnitude_col[4]; double result; fseek(fp, 0, SEEK_END); file_size = ftell(fp); fseek(fp, 0, SEEK_SET); buffer = malloc(file_size); buffer[x] = getc(fp); buffer[x] = buffer[x]&lt;&lt;8; buffer[x] = buffer[x] | getc(fp); while(!feof(fp)) { x++; buffer[x] = getc(fp); buffer[x] = buffer[x]&lt;&lt;8; buffer[x] = buffer[x] | getc(fp); } for(i=0; i&lt;x; i++) { //printf("%#x\n", (unsigned short)buffer[i]); } for(i=0; i&lt;4; i++) { magnitude_row[i] = goertzel(buffer, frequency_row[i], 8000); } for(i=0; i&lt;3; i++) { magnitude_col[i] = goertzel(buffer, frequency_col[i], 8000); } x=0; for(i=0; i&lt;4; i++) { if(magnitude_row[i] &gt; magnitude_row[x]) x = i; } printf("Freq: %f\t Mag: %f\n", frequency_row[x], magnitude_row[x]); x=0; for(i=0; i&lt;3; i++) { if(magnitude_col[i] &gt; magnitude_col[x]) x = i; } printf("Freq: %f\t Mag: %f\n", frequency_col[x], magnitude_col[x]); return 0; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload