14#define Q15_MAX INT16_MAX
16static const char *
TAG =
"dsps_cplx_gen";
21 cplx_gen->
freq = freq;
25 cplx_gen->
phase = initial_phase;
29 ESP_LOGE(
TAG,
"The length of the LUT must be power of 2");
34 if ((lut == NULL) && ((cplx_gen->
lut_len > 8192) || (cplx_gen->
lut_len < 256))) {
35 ESP_LOGE(
TAG,
"The length of the LUT table out of range. Valid range is 256 to 8192");
40 if ((cplx_gen->
freq >= 1) || (cplx_gen->
freq <= -1)) {
41 ESP_LOGE(
TAG,
"The frequency is out of range. Valid range is +/- 1. ");
46 if ((cplx_gen->
phase >= 1) || (cplx_gen->
phase <= -1)) {
47 ESP_LOGE(
TAG,
"The phase is out of range. Valid range is +/- 1. ");
56 int16_t *local_lut = (int16_t *)malloc(cplx_gen->
lut_len *
sizeof(int16_t));
59 for (
int i = 0 ; i < cplx_gen->
lut_len; i++) {
60 term = (2.0 *
M_PI) * ((
float)(i) / (
float)(cplx_gen->
lut_len));
61 local_lut[i] = (int16_t)(sin(term) *
Q15_MAX);
63 cplx_gen->
lut = (
void *)local_lut;
65 float *local_lut = (
float *)malloc(cplx_gen->
lut_len *
sizeof(
float));
68 for (
int i = 0 ; i < cplx_gen->
lut_len; i++) {
69 term = (2.0 *
M_PI) * ((
float)(i) / (
float)(cplx_gen->
lut_len));
70 local_lut[i] = (float)sin(term);
72 cplx_gen->
lut = (
void *)local_lut;
83 if ((freq >= 1) || (freq <= -1)) {
84 ESP_LOGE(
TAG,
"The frequency is out of range. Valid range is +/- 1. ");
88 cplx_gen->
freq = freq;
96 ESP_LOGE(
TAG,
"cplx_gen strucure was not initialized");
100 return (cplx_gen->
freq);
105 if ((phase >= 1) || (phase <= -1)) {
106 ESP_LOGE(
TAG,
"The phase is out of range. Valid range is +/- 1. ");
110 cplx_gen->
phase = phase;
118 ESP_LOGE(
TAG,
"cplx_gen strucure was not initialized");
122 return (cplx_gen->
phase);
127 if ((freq >= 1) || (freq <= -1)) {
128 ESP_LOGE(
TAG,
"The frequency is out of range. Valid range is +/- 1. ");
132 if ((phase >= 1) || (phase <= -1)) {
133 ESP_LOGE(
TAG,
"The phase is out of range. Valid range is +/- 1. ");
137 cplx_gen->
phase = phase;
138 cplx_gen->
freq = freq;
bool dsp_is_power_of_two(int x)
check power of two The function check if the argument is power of 2. The implementation use ANSI C an...
#define ESP_ERR_DSP_INVALID_PARAM
#define ESP_ERR_DSP_PARAM_OUTOFRANGE
#define ESP_ERR_DSP_INVALID_LENGTH
struct cplx_sig_s cplx_sig_t
Data struct of the complex signal generator.
enum output_data_type out_d_type
Ennum defining output data type of the complex generator.
esp_err_t dsps_cplx_gen_freq_set(cplx_sig_t *cplx_gen, float freq)
function sets the output frequency of the complex generator
esp_err_t dsps_cplx_gen_phase_set(cplx_sig_t *cplx_gen, float phase)
function sets the phase of the complex generator
esp_err_t dsps_cplx_gen_set(cplx_sig_t *cplx_gen, float freq, float phase)
function sets the output frequency and the phase of the complex generator
float dsps_cplx_gen_freq_get(cplx_sig_t *cplx_gen)
function gets the output frequency of the complex generator
esp_err_t dsps_cplx_gen_init(cplx_sig_t *cplx_gen, out_d_type d_type, void *lut, int32_t lut_len, float freq, float initial_phase)
Initialize strucure for complex generator.
float dsps_cplx_gen_phase_get(cplx_sig_t *cplx_gen)
function gets the phase of the complex generator
void cplx_gen_free(cplx_sig_t *cplx_gen)
function frees dynamically allocated memory, which was allocated in the init function