Skip to content

File syn_goertzel.c

FileList > dsp > syn_goertzel.c

Go to the source code of this file

Implementation of Integer-Only Goertzel Algorithm.

  • #include "syn_goertzel.h"
  • #include "../util/syn_qmath.h"
  • #include <string.h>

Public Functions

Type Name
uint64_t syn_goertzel_get_magnitude_sq (const SYN_Goertzel * g)
Calculate the squared magnitude |X(k)|^2 at the end of a sample block.
SYN_Status syn_goertzel_init (SYN_Goertzel * g, uint32_t sample_rate_hz, uint32_t target_freq_hz, size_t block_size)
Initialize a Goertzel Filter instance.
size_t syn_goertzel_process_block (SYN_Goertzel * g, const int16_t * samples, size_t count)
Process a buffer of 16-bit PCM samples through the Goertzel filter.
SYN_Status syn_goertzel_process_sample (SYN_Goertzel * g, int16_t sample)
Process a single 16-bit PCM sample through the Goertzel filter.
SYN_Status syn_goertzel_reset (SYN_Goertzel * g)
Reset Goertzel filter delay accumulators for a new sample block.

Macros

Type Name
define Q14_ONE 16384L

Public Functions Documentation

function syn_goertzel_get_magnitude_sq

Calculate the squared magnitude |X(k)|^2 at the end of a sample block.

uint64_t syn_goertzel_get_magnitude_sq (
    const SYN_Goertzel * g
) 

Parameters:

  • g Pointer to Goertzel instance.

Returns:

64-bit squared magnitude value |X(k)|^2 (or 0 if invalid).


function syn_goertzel_init

Initialize a Goertzel Filter instance.

SYN_Status syn_goertzel_init (
    SYN_Goertzel * g,
    uint32_t sample_rate_hz,
    uint32_t target_freq_hz,
    size_t block_size
) 

Parameters:

  • g Pointer to Goertzel instance.
  • sample_rate_hz Sampling frequency in Hz (e.g. 8000).
  • target_freq_hz Target tone frequency in Hz (e.g. 697 for DTMF row 1).
  • block_size Sample block size N (e.g. 205).

Returns:

SYN_OK on success, or SYN_INVALID_PARAM.


function syn_goertzel_process_block

Process a buffer of 16-bit PCM samples through the Goertzel filter.

size_t syn_goertzel_process_block (
    SYN_Goertzel * g,
    const int16_t * samples,
    size_t count
) 

Parameters:

  • g Pointer to Goertzel instance.
  • samples Array of 16-bit signed PCM input samples.
  • count Sample count in array.

Returns:

Number of samples actually processed.


function syn_goertzel_process_sample

Process a single 16-bit PCM sample through the Goertzel filter.

SYN_Status syn_goertzel_process_sample (
    SYN_Goertzel * g,
    int16_t sample
) 

Parameters:

  • g Pointer to Goertzel instance.
  • sample 16-bit signed PCM input sample.

Returns:

SYN_OK on success, or SYN_INVALID_PARAM.


function syn_goertzel_reset

Reset Goertzel filter delay accumulators for a new sample block.

SYN_Status syn_goertzel_reset (
    SYN_Goertzel * g
) 

Parameters:

  • g Pointer to Goertzel instance.

Returns:

SYN_OK on success, or SYN_INVALID_PARAM.


Macro Definition Documentation

define Q14_ONE

#define Q14_ONE `16384L`

Q14 fixed-point unity multiplier (2^14 = 16384)



The documentation for this class was generated from the following file src/syntropic/dsp/syn_goertzel.c