spandsp  0.0.6
tone_detect.c File Reference
#include <inttypes.h>
#include <stdlib.h>
#include "floating_fudge.h"
#include <string.h>
#include <stdio.h>
#include <time.h>
#include <fcntl.h>
#include "spandsp/telephony.h"
#include "spandsp/complex.h"
#include "spandsp/complex_vector_float.h"
#include "spandsp/tone_detect.h"
#include "spandsp/tone_generate.h"
#include "spandsp/private/tone_detect.h"

Macros

#define M_PI   3.14159265358979323846264338327
 

Functions

void make_goertzel_descriptor (goertzel_descriptor_t *t, float freq, int samples)
 Create a descriptor for use with either a Goertzel transform.
 
goertzel_state_tgoertzel_init (goertzel_state_t *s, goertzel_descriptor_t *t)
 Initialise the state of a Goertzel transform. More...
 
int goertzel_release (goertzel_state_t *s)
 
int goertzel_free (goertzel_state_t *s)
 
void goertzel_reset (goertzel_state_t *s)
 Reset the state of a Goertzel transform. More...
 
int goertzel_update (goertzel_state_t *s, const int16_t amp[], int samples)
 Update the state of a Goertzel transform. More...
 
float goertzel_result (goertzel_state_t *s)
 Evaluate the final result of a Goertzel transform. More...
 
complexf_t periodogram (const complexf_t coeffs[], const complexf_t amp[], int len)
 
int periodogram_prepare (complexf_t sum[], complexf_t diff[], const complexf_t amp[], int len)
 
complexf_t periodogram_apply (const complexf_t coeffs[], const complexf_t sum[], const complexf_t diff[], int len)
 
int periodogram_generate_coeffs (complexf_t coeffs[], float freq, int sample_rate, int window_len)
 
float periodogram_generate_phase_offset (complexf_t *offset, float freq, int sample_rate, int interval)
 
float periodogram_freq_error (const complexf_t *phase_offset, float scale, const complexf_t *last_result, const complexf_t *result)
 

Function Documentation

◆ goertzel_init()

goertzel_state_t* goertzel_init ( goertzel_state_t s,
goertzel_descriptor_t t 
)

Initialise the state of a Goertzel transform.

Parameters
sThe Goertzel context. If NULL, a context is allocated with malloc.
tThe Goertzel descriptor.
Returns
A pointer to the Goertzel state.

◆ goertzel_reset()

void goertzel_reset ( goertzel_state_t s)

Reset the state of a Goertzel transform.

Parameters
sThe Goertzel context.

Referenced by dtmf_rx_fillin(), and goertzel_result().

◆ goertzel_result()

float goertzel_result ( goertzel_state_t s)

Evaluate the final result of a Goertzel transform.

Parameters
sThe Goertzel context.
Returns
The result of the transform. The expected result for a pure sine wave signal of level x dBm0, at the very centre of the bin is: Floating point^2 Fixed point^2

References goertzel_reset().

◆ goertzel_update()

int goertzel_update ( goertzel_state_t s,
const int16_t  amp[],
int  samples 
)

Update the state of a Goertzel transform.

Parameters
sThe Goertzel context.
ampThe samples to be transformed.
samplesThe number of samples.
Returns
The number of samples unprocessed

◆ periodogram()

complexf_t periodogram ( const complexf_t  coeffs[],
const complexf_t  amp[],
int  len 
)

Evaluate a periodogram.

Parameters
coeffsA set of coefficients generated by periodogram_generate_coeffs().
ampThe complex amplitude of the signal.
lenThe length of the periodogram, in samples. This must be an even number.
Returns
The periodogram result.

◆ periodogram_apply()

complexf_t periodogram_apply ( const complexf_t  coeffs[],
const complexf_t  sum[],
const complexf_t  diff[],
int  len 
)

Evaluate a periodogram, based on data prepared by periodogram_prepare(). This is more efficient than using periodogram() when several periodograms are to be applied to the same signal.

Parameters
coeffsA set of coefficients generated by periodogram_generate_coeffs().
sumA vector of sums produced by periodogram_prepare().
diffA vector of differences produced by periodogram_prepare().
lenThe length of the periodogram, in samples. This must be an even number.
Returns
The periodogram result.

◆ periodogram_freq_error()

float periodogram_freq_error ( const complexf_t phase_offset,
float  scale,
const complexf_t last_result,
const complexf_t result 
)

Apply a phase offset, to find the frequency error between periodogram evaluations. specified interval.

Parameters
phase_offsetA point to the expected phase offset.
scaleThe scaling factor to be used.
last_resultA pointer to the previous periodogram result.
resultA pointer to the current periodogram result.
Returns
The frequency error, in Hz.

◆ periodogram_generate_coeffs()

int periodogram_generate_coeffs ( complexf_t  coeffs[],
float  freq,
int  sample_rate,
int  window_len 
)

Generate a Hamming weighted coefficient set, to be used for a periodogram analysis.

Parameters
coeffsThe generated coefficients.
freqThe frequency to be matched by the periodogram, in Hz.
sample_rateThe sample rate of the signal, in samples per second.
window_lenThe length of the periodogram window. This must be an even number.
Returns
The number of generated coefficients.

References complexf_t::im, and complexf_t::re.

◆ periodogram_generate_phase_offset()

float periodogram_generate_phase_offset ( complexf_t offset,
float  freq,
int  sample_rate,
int  interval 
)

Generate the phase offset to be expected between successive periodograms evaluated at the specified interval.

Parameters
offsetA point to the generated phase offset.
freqThe frequency being matched by the periodogram, in Hz.
sample_rateThe sample rate of the signal, in samples per second.
intervalThe interval between periodograms, in samples.
Returns
The scaling factor.

References complexf_t::im, and complexf_t::re.

◆ periodogram_prepare()

int periodogram_prepare ( complexf_t  sum[],
complexf_t  diff[],
const complexf_t  amp[],
int  len 
)

Prepare data for evaluating a set of periodograms.

Parameters
sumA vector of sums of pairs of signal samples. This will be half the length of len.
diffA vector of differences between pairs of signal samples. This will be half the length of len.
ampThe complex amplitude of the signal.
lenThe length of the periodogram, in samples. This must be an even number.
Returns
The length of the vectors sum and diff.