spandsp: tone_detect.c File Reference

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_t * | goertzel_init (goertzel_state_t *s, goertzel_descriptor_t *t)
| Initialise the state of a Goertzel transform.
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.
int | goertzel_update (goertzel_state_t *s, const int16_t amp[], int samples)
| Update the state of a Goertzel transform.
float | goertzel_result (goertzel_state_t *s)
| Evaluate the final result of a Goertzel transform.
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

  s | The Goertzel context. If NULL, a context is allocated with malloc.
  t | The 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

  s | The Goertzel context.

Referenced by goertzel_result().

## ◆ goertzel_result()

float goertzel_result | ( | goertzel_state_t * | s | ) |

Evaluate the final result of a Goertzel transform.

Parameters

  s | The 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] ((samples_per_goertzel_block*32768.0/1.4142)*10^((x - DBM0_MAX_SINE_POWER)/20.0))^2 [Fixed point] ((samples_per_goertzel_block*256.0/1.4142)*10^((x - DBM0_MAX_SINE_POWER)/20.0))^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

  s | The Goertzel context.
  amp | The samples to be transformed.
  samples | The 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

  coeffs | A set of coefficients generated by periodogram_generate_coeffs().
  amp | The complex amplitude of the signal.
  len | The length of the periodogram, in samples. This must be an even number.

Returns
  The periodogram result.

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

## ◆ 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

  coeffs | A set of coefficients generated by periodogram_generate_coeffs().
  sum | A vector of sums produced by periodogram_prepare().
  diff | A vector of differences produced by periodogram_prepare().
  len | The length of the periodogram, in samples. This must be an even number.

Returns
  The periodogram result.

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

## ◆ 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_offset | A point to the expected phase offset.
  scale | The scaling factor to be used.
  last_result | A pointer to the previous periodogram result.
  result | A pointer to the current periodogram result.

Returns
  The frequency error, in Hz.

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

## ◆ 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

  coeffs | The generated coefficients.
  freq | The frequency to be matched by the periodogram, in Hz.
  sample_rate | The sample rate of the signal, in samples per second.
  window_len | The 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

  offset | A point to the generated phase offset.
  freq | The frequency being matched by the periodogram, in Hz.
  sample_rate | The sample rate of the signal, in samples per second.
  interval | The 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

  sum | A vector of sums of pairs of signal samples. This will be half the length of len.
  diff | A vector of differences between pairs of signal samples. This will be half the length of len.
  amp | The complex amplitude of the signal.
  len | The length of the periodogram, in samples. This must be an even number.

Returns
  The length of the vectors sum and diff.