ESP-IDF Firmware
Firmware architecture and call graph
Loading...
Searching...
No Matches
dsps_cplx_gen.c File Reference
#include "dsps_cplx_gen.h"
Include dependency graph for dsps_cplx_gen.c:

Go to the source code of this file.

Functions

esp_err_t dsps_cplx_gen_ansi (cplx_sig_t *cplx_gen, void *output, int32_t len)
 The function generates a complex signal.

Function Documentation

◆ dsps_cplx_gen_ansi()

esp_err_t dsps_cplx_gen_ansi ( cplx_sig_t * cplx_gen,
void * output,
int32_t len )

The function generates a complex signal.

the generated complex signal is in the form of two harmonics signals in either 16-bit signed fixed point or 32-bit floating point

x[i]= A*sin(step*i + ph/180*Pi) x[i+1]= B*cos(step*i + ph/180*Pi) where step = 2*Pi*frequency

dsps_cplx_gen_ansi() - The implementation uses ANSI C and could be compiled and run on any platform dsps_cplx_gen_ae32() - Is targetted for Xtensa cores

Parameters
cplx_genpointer to the generator structure
outputoutput array (length of len*2), data type is void so both (S16_FIXED, F32_FLOAT) types could be used
lenlength of the output signal
Returns
  • ESP_OK on success
  • One of the error codes from DSP library

Definition at line 9 of file dsps_cplx_gen.c.

10{
11 // angle frequency is already cplx_gen->freq
12 const int sin_to_cos = cplx_gen->lut_len / 4;
13 float ph = cplx_gen->phase;
14 const float fr = cplx_gen->freq;
15 int sin_pos, cos_pos;
16
17 for (int i = 0 ; i < len; i++) {
18
19 if (ph < 0) {
20 ph += 1.0;
21 }
22 if (ph >= 1.0) {
23 ph -= 1.0;
24 }
25
26 sin_pos = (int)(ph * (cplx_gen->lut_len));
27 cos_pos = (sin_pos + sin_to_cos) & (cplx_gen->lut_len - 1);
28
29 if (cplx_gen->d_type == S16_FIXED) {
30 ((int16_t *)output)[i * 2 + 0] = ((int16_t *)cplx_gen->lut)[cos_pos];
31 ((int16_t *)output)[i * 2 + 1] = ((int16_t *)cplx_gen->lut)[sin_pos];
32 } else {
33 ((float *)output)[i * 2 + 0] = ((float *)cplx_gen->lut)[cos_pos];
34 ((float *)output)[i * 2 + 1] = ((float *)cplx_gen->lut)[sin_pos];
35 }
36 ph += fr;
37 }
38
39 return ESP_OK;
40}
@ S16_FIXED
#define ESP_OK
Definition esp_err.h:23
int32_t lut_len
out_d_type d_type

References cplx_sig_s::d_type, ESP_OK, cplx_sig_s::freq, cplx_sig_s::lut, cplx_sig_s::lut_len, cplx_sig_s::phase, and S16_FIXED.