ESP-IDF Firmware
Firmware architecture and call graph
Loading...
Searching...
No Matches
dsps_tone_gen.h File Reference
#include "dsp_err.h"
Include dependency graph for dsps_tone_gen.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

esp_err_t dsps_tone_gen_f32 (float *output, int len, float Ampl, float freq, float phase)
 tone

Function Documentation

◆ dsps_tone_gen_f32()

esp_err_t dsps_tone_gen_f32 ( float * output,
int len,
float Ampl,
float freq,
float phase )

tone

The function generate a tone signal. x[i]=A*sin(2*PI*i + ph/180*PI) The implementation use ANSI C and could be compiled and run on any platform

Parameters
outputoutput array.
lenlength of the input signal
Amplamplitude
freqNaiquist frequency -1..1
phasephase in degree
Returns
  • ESP_OK on success
  • One of the error codes from DSP library

Definition at line 18 of file dsps_tone_gen.c.

19{
20 if (freq >= 1) {
22 }
23 if (freq <= -1) {
25 }
26 float ph = phase / 180 * M_PI;
27 float fr = 2 * M_PI * freq;
28 for (int i = 0 ; i < len ; i++) {
29 output[i] = Ampl * sin(ph);
30 ph += fr;
31 if (ph > 2 * M_PI) {
32 ph -= 2 * M_PI;
33 }
34 if (ph < -2 * M_PI) {
35 ph += 2 * M_PI;
36 }
37 }
38 return ESP_OK;
39}
#define ESP_ERR_DSP_INVALID_PARAM
#define ESP_OK
Definition esp_err.h:23
#define M_PI
Definition esp_err.h:26

References ESP_ERR_DSP_INVALID_PARAM, ESP_OK, and M_PI.