Espressif DSP Library API Reference

Header Files

To use the library, include esp_dsp.h header file into the source code.

Signal (1D) Processing APIs

Signal processing APIs use dsps prefix. The following modules are available:

Dot-product

Functions

esp_err_t dsps_dotprod_s16_ansi(const int16_t *src1, const int16_t *src2, int16_t *dest, int len, int8_t shift)

dot product of two 16 bit vectors Dot product calculation for two signed 16 bit arrays: *dest += (src1[i] * src2[i]) >> (15-shift); i= [0..N) The extension (_ansi) use ANSI C and could be compiled and run on any platform. The extension (_ae32) is optimized for ESP32 chip.

Return

  • ESP_OK on success

  • One of the error codes from DSP library

Parameters
  • [in] src1: source array 1

  • [in] src2: source array 2

  • dest: destination pointer

  • [in] len: length of input arrays

  • [in] shift: shift of the result.

esp_err_t dsps_dotprod_s16_ae32(const int16_t *src1, const int16_t *src2, int16_t *dest, int len, int8_t shift)
esp_err_t dsps_dotprod_s16_arp4(const int16_t *src1, const int16_t *src2, int16_t *dest, int len, int8_t shift)
esp_err_t dsps_dotprod_f32_ansi(const float *src1, const float *src2, float *dest, int len)

dot product of two float vectors Dot product calculation for two floating point arrays: *dest += (src1[i] * src2[i]); i= [0..N) The extension (_ansi) use ANSI C and could be compiled and run on any platform. The extension (_ae32) is optimized for ESP32 chip.

Return

  • ESP_OK on success

  • One of the error codes from DSP library

Parameters
  • [in] src1: source array 1

  • [in] src2: source array 2

  • dest: destination pointer

  • [in] len: length of input arrays

esp_err_t dsps_dotprod_f32_ae32(const float *src1, const float *src2, float *dest, int len)
esp_err_t dsps_dotprod_f32_aes3(const float *src1, const float *src2, float *dest, int len)
esp_err_t dsps_dotprod_f32_arp4(const float *src1, const float *src2, float *dest, int len)
esp_err_t dsps_dotprode_f32_ansi(const float *src1, const float *src2, float *dest, int len, int step1, int step2)

dot product of two float vectors with step Dot product calculation for two floating point arrays: *dest += (src1[i*step1] * src2[i*step2]); i= [0..N) The extension (_ansi) use ANSI C and could be compiled and run on any platform. The extension (_ae32) is optimized for ESP32 chip.

Return

  • ESP_OK on success

  • One of the error codes from DSP library

Parameters
  • [in] src1: source array 1

  • [in] src2: source array 2

  • dest: destination pointer

  • [in] len: length of input arrays

  • [in] step1: step over elements in first array

  • [in] step2: step over elements in second array

esp_err_t dsps_dotprode_f32_ae32(const float *src1, const float *src2, float *dest, int len, int step1, int step2)
esp_err_t dsps_dotprode_f32_arp4(const float *src1, const float *src2, float *dest, int len, int step1, int step2)

Macros

dsps_dotprod_s16
dsps_dotprod_f32
dsps_dotprode_f32

Functions

esp_err_t dspi_dotprod_f32_ansi(image2d_t *in_image, image2d_t *filter, float *out_value, int count_x, int count_y)

dot product of two images Dot product calculation for two floating point images: out_value += image[i…] * src2[i*…]); i= [0..count_x*count_y) The extension (_ansi) use ANSI C and could be compiled and run on any platform. The extension (_ae32) is optimized for ESP32 chip.

Return

  • ESP_OK on success

  • One of the error codes from DSP library

Parameters
  • [in] in_image: descriptor of the image

  • [in] filter: descriptor of the filter

  • [out] out_value: pointer to the output value

  • [in] count_x: amount of samples by X axis (count_x*step_X <= widdth)

  • [in] count_y: amount of samples by Y axis (count_y*step_Y <= height)

esp_err_t dspi_dotprod_s16_ansi(image2d_t *in_image, image2d_t *filter, int16_t *out_value, int count_x, int count_y, int shift)

dot product of two images Dot product calculation for two floating point images: out_value += image[i…] * src2[i*…]); i= [0..count_x*count_y) The extension (_ansi) use ANSI C and could be compiled and run on any platform. The extension (_ae32) is optimized for ESP32 chip.

Return

  • ESP_OK on success

  • One of the error codes from DSP library

Parameters
  • [in] in_image: descriptor of the image

  • [in] filter: descriptor of the filter

  • [out] out_value: pointer to the output value

  • [in] count_x: amount of samples by X axis (count_x*step_X <= widdth)

  • [in] count_y: amount of samples by Y axis (count_y*step_Y <= height)

  • [in] shift: - result shift to right, by default must be 15 for int16_t or 7 for int8_t

esp_err_t dspi_dotprod_u16_ansi(image2d_t *in_image, image2d_t *filter, uint16_t *out_value, int count_x, int count_y, int shift)
esp_err_t dspi_dotprod_s8_ansi(image2d_t *in_image, image2d_t *filter, int8_t *out_value, int count_x, int count_y, int shift)
esp_err_t dspi_dotprod_u8_ansi(image2d_t *in_image, image2d_t *filter, uint8_t *out_value, int count_x, int count_y, int shift)
esp_err_t dspi_dotprod_s16_aes3(image2d_t *in_image, image2d_t *filter, int16_t *out_value, int count_x, int count_y, int shift)
esp_err_t dspi_dotprod_u16_aes3(image2d_t *in_image, image2d_t *filter, uint16_t *out_value, int count_x, int count_y, int shift)
esp_err_t dspi_dotprod_s8_aes3(image2d_t *in_image, image2d_t *filter, int8_t *out_value, int count_x, int count_y, int shift)
esp_err_t dspi_dotprod_u8_aes3(image2d_t *in_image, image2d_t *filter, uint8_t *out_value, int count_x, int count_y, int shift)
esp_err_t dspi_dotprod_s16_arp4(image2d_t *in_image, image2d_t *filter, int16_t *out_value, int count_x, int count_y, int shift)
esp_err_t dspi_dotprod_s8_arp4(image2d_t *in_image, image2d_t *filter, int8_t *out_value, int count_x, int count_y, int shift)
esp_err_t dspi_dotprod_u16_arp4(image2d_t *in_image, image2d_t *filter, uint16_t *out_value, int count_x, int count_y, int shift)
esp_err_t dspi_dotprod_u8_arp4(image2d_t *in_image, image2d_t *filter, uint8_t *out_value, int count_x, int count_y, int shift)
esp_err_t dspi_dotprod_off_f32_ansi(image2d_t *in_image, image2d_t *filter, float *out_value, int count_x, int count_y, float offset)

dot product of two images with input offset Dot product calculation for two floating point images: out_value += (image[i…] + offset) * src2[i*…]); i= [0..count_x*count_y) The extension (_ansi) use ANSI C and could be compiled and run on any platform. The extension (_ae32) is optimized for ESP32 chip.

Return

  • ESP_OK on success

  • One of the error codes from DSP library

Parameters
  • [in] in_image: descriptor of the image

  • [in] filter: descriptor of the filter

  • [out] out_value: pointer to the output value

  • [in] count_x: amount of samples by X axis (count_x*step_X <= widdth)

  • [in] count_y: amount of samples by Y axis (count_y*step_Y <= height)

  • [in] offset: - input offset value.

esp_err_t dspi_dotprod_off_s16_ansi(image2d_t *in_image, image2d_t *filter, int16_t *out_value, int count_x, int count_y, int shift, int16_t offset)

dot product of two images with input offset Dot product calculation for two floating point images: out_value += (image[i…] + offset) * src2[i*…]); i= [0..count_x*count_y) The extension (_ansi) use ANSI C and could be compiled and run on any platform. The extension (_ae32) is optimized for ESP32 chip.

Return

  • ESP_OK on success

  • One of the error codes from DSP library

Parameters
  • [in] in_image: descriptor of the image

  • [in] filter: descriptor of the filter

  • [out] out_value: pointer to the output value

  • [in] count_x: amount of samples by X axis (count_x*step_X <= widdth)

  • [in] count_y: amount of samples by Y axis (count_y*step_Y <= height)

  • [in] shift: - result shift to right, by default must be 15 for int16_t or 7 for int8_t

  • [in] offset: - input offset value.

esp_err_t dspi_dotprod_off_u16_ansi(image2d_t *in_image, image2d_t *filter, uint16_t *out_value, int count_x, int count_y, int shift, uint16_t offset)
esp_err_t dspi_dotprod_off_s8_ansi(image2d_t *in_image, image2d_t *filter, int8_t *out_value, int count_x, int count_y, int shift, int8_t offset)
esp_err_t dspi_dotprod_off_u8_ansi(image2d_t *in_image, image2d_t *filter, uint8_t *out_value, int count_x, int count_y, int shift, uint8_t offset)
esp_err_t dspi_dotprod_off_s16_aes3(image2d_t *in_image, image2d_t *filter, int16_t *out_value, int count_x, int count_y, int shift, int16_t offset)
esp_err_t dspi_dotprod_off_u16_aes3(image2d_t *in_image, image2d_t *filter, uint16_t *out_value, int count_x, int count_y, int shift, uint16_t offset)
esp_err_t dspi_dotprod_off_s8_aes3(image2d_t *in_image, image2d_t *filter, int8_t *out_value, int count_x, int count_y, int shift, int8_t offset)
esp_err_t dspi_dotprod_off_u8_aes3(image2d_t *in_image, image2d_t *filter, uint8_t *out_value, int count_x, int count_y, int shift, uint8_t offset)
esp_err_t dspi_dotprod_off_s16_arp4(image2d_t *in_image, image2d_t *filter, int16_t *out_value, int count_x, int count_y, int shift, int16_t offset)
esp_err_t dspi_dotprod_off_u16_arp4(image2d_t *in_image, image2d_t *filter, uint16_t *out_value, int count_x, int count_y, int shift, uint16_t offset)
esp_err_t dspi_dotprod_off_s8_arp4(image2d_t *in_image, image2d_t *filter, int8_t *out_value, int count_x, int count_y, int shift, int8_t offset)
esp_err_t dspi_dotprod_off_u8_arp4(image2d_t *in_image, image2d_t *filter, uint8_t *out_value, int count_x, int count_y, int shift, uint8_t offset)

FFT

Functions

esp_err_t dsps_fft2r_init_fc32(float *fft_table_buff, int table_size)

init fft tables

Initialization of Complex FFT. This function initialize coefficients table. The implementation use ANSI C and could be compiled and run on any platform

Return

  • ESP_OK on success

  • ESP_ERR_DSP_PARAM_OUTOFRANGE if table_size > CONFIG_DSP_MAX_FFT_SIZE

  • ESP_ERR_DSP_REINITIALIZED if buffer already allocated internally by other function

  • One of the error codes from DSP library

Parameters
  • [inout] fft_table_buff: pointer to floating point buffer where sin/cos table will be stored if this parameter set to NULL, and table_size value is more then 0, then dsps_fft2r_init_fc32 will allocate buffer internally

  • [in] table_size: size of the buffer in float words if fft_table_buff is NULL and table_size is not 0, buffer will be allocated internally. If table_size is 0, buffer will not be allocated.

esp_err_t dsps_fft2r_init_sc16(int16_t *fft_table_buff, int table_size)
void dsps_fft2r_deinit_fc32(void)

deinit fft tables

Free resources of Complex FFT. This function delete coefficients table if it was allocated by dsps_fft2r_init_fc32. The implementation use ANSI C and could be compiled and run on any platform

void dsps_fft2r_deinit_sc16(void)
esp_err_t dsps_fft2r_fc32_ansi_(float *data, int N, float *w)

complex FFT of radix 2

Complex FFT of radix 2 The extension (_ansi) use ANSI C and could be compiled and run on any platform. The extension (_ae32) is optimized for ESP32 chip.

Return

  • ESP_OK on success

  • One of the error codes from DSP library

Parameters
  • [inout] data: input/output complex array. An elements located: Re[0], Im[0], … Re[N-1], Im[N-1] result of FFT will be stored to this array.

  • [in] N: Number of complex elements in input array

  • [in] w: pointer to the sin/cos table

esp_err_t dsps_fft2r_fc32_ae32_(float *data, int N, float *w)
esp_err_t dsps_fft2r_fc32_aes3_(float *data, int N, float *w)
esp_err_t dsps_fft2r_fc32_arp4_(float *data, int N, float *w)
esp_err_t dsps_fft2r_sc16_ansi_(int16_t *data, int N, int16_t *w)
esp_err_t dsps_fft2r_sc16_ae32_(int16_t *data, int N, int16_t *w)
esp_err_t dsps_fft2r_sc16_aes3_(int16_t *data, int N, int16_t *w)
esp_err_t dsps_fft2r_sc16_arp4_(int16_t *data, int N, int16_t *w)
esp_err_t dsps_bit_rev_fc32_ansi(float *data, int N)

bit reverse operation for the complex input array

Bit reverse operation for the complex input array The implementation use ANSI C and could be compiled and run on any platform

Return

  • ESP_OK on success

  • One of the error codes from DSP library

Parameters
  • [inout] data: input/ complex array. An elements located: Re[0], Im[0], … Re[N-1], Im[N-1] result of FFT will be stored to this array.

  • [in] N: Number of complex elements in input array

esp_err_t dsps_bit_rev_sc16_ansi(int16_t *data, int N)
esp_err_t dsps_bit_rev2r_fc32(float *data, int N)
esp_err_t dsps_gen_w_r2_fc32(float *w, int N)

Generate coefficients table for the FFT radix 2.

Generate coefficients table for the FFT radix 2. This function called inside init. The implementation use ANSI C and could be compiled and run on any platform

Return

  • ESP_OK on success

  • One of the error codes from DSP library

Parameters
  • [inout] w: memory location to store coefficients. By default coefficients will be stored to the dsps_fft_w_table_fc32. Maximum size of the FFT must be setup in menuconfig

  • [in] N: maximum size of the FFT that will be used

esp_err_t dsps_gen_w_r2_sc16(int16_t *w, int N)
esp_err_t dsps_cplx2reC_fc32_ansi(float *data, int N)

Convert complex array to two real arrays.

Convert complex array to two real arrays in case if input was two real arrays. This function have to be used if FFT used to process real data. The implementation use ANSI C and could be compiled and run on any platform

Return

  • ESP_OK on success

  • One of the error codes from DSP library

Parameters
  • [inout] data: Input complex array and result of FFT2R. input has size of 2*N, because contains real and imaginary part. result will be stored to the same array. Input1: input[0..N-1], Input2: input[N..2*N-1]

  • [in] N: Number of complex elements in input array

esp_err_t dsps_cplx2reC_sc16(int16_t *data, int N)
esp_err_t dsps_cplx2real_sc16_ansi(int16_t *data, int N)

Convert complex FFT result to real array.

Convert FFT result of complex FFT for resl input to real array. This function have to be used if FFT used to process real data. The implementation use ANSI C and could be compiled and run on any platform

Return

  • ESP_OK on success

  • One of the error codes from DSP library

Parameters
  • [inout] data: Input complex array and result of FFT2R. input has size of 2*N, because contains real and imaginary part. result will be stored to the same array. Input1: input[0..N-1], Input2: input[N..2*N-1]

  • [in] N: Number of complex elements in input array

esp_err_t dsps_bit_rev_lookup_fc32_ansi(float *data, int reverse_size, uint16_t *reverse_tab)
esp_err_t dsps_bit_rev_lookup_fc32_ae32(float *data, int reverse_size, uint16_t *reverse_tab)
esp_err_t dsps_bit_rev_lookup_fc32_aes3(float *data, int reverse_size, uint16_t *reverse_tab)
esp_err_t dsps_cplx2real256_fc32_ansi(float *data)
esp_err_t dsps_gen_bitrev2r_table(int N, int step, char *name_ext)

Macros

CONFIG_DSP_MAX_FFT_SIZE
dsps_fft2r_fc32_ae32(data, N)
dsps_fft2r_fc32_aes3(data, N)
dsps_fft2r_fc32_arp4(data, N)
dsps_fft2r_sc16_ae32(data, N)
dsps_fft2r_sc16_aes3(data, N)
dsps_fft2r_sc16_arp4(data, N)
dsps_fft2r_fc32_ansi(data, N)
dsps_fft2r_sc16_ansi(data, N)
dsps_fft2r_fc32
dsps_bit_rev_fc32
dsps_cplx2reC_fc32
dsps_bit_rev_sc16
dsps_bit_rev_lookup_fc32
dsps_fft2r_sc16

Functions

esp_err_t dsps_fft4r_init_fc32(float *fft_table_buff, int max_fft_size)

init fft tables

Initialization of Complex FFT Radix-4. This function initialize coefficients table. The implementation use ANSI C and could be compiled and run on any platform

Return

  • ESP_OK on success

  • ESP_ERR_DSP_PARAM_OUTOFRANGE if table_size > CONFIG_DSP_MAX_FFT_SIZE

  • ESP_ERR_DSP_REINITIALIZED if buffer already allocated internally by other function

  • One of the error codes from DSP library

Parameters
  • [inout] fft_table_buff: pointer to floating point buffer where sin/cos table will be stored if this parameter set to NULL, and table_size value is more then 0, then dsps_fft4r_init_fc32 will allocate buffer internally

  • [in] max_fft_size: maximum fft size. The buffer for sin/cos table that will be used for radix-4 it’s four times maximum length of FFT. if fft_table_buff is NULL and table_size is not 0, buffer will be allocated internally. If table_size is 0, buffer will not be allocated.

void dsps_fft4r_deinit_fc32(void)

deinit fft tables

Free resources of Complex FFT Radix-4. This function delete coefficients table if it was allocated by dsps_fft4r_init_fc32. The implementation use ANSI C and could be compiled and run on any platform

esp_err_t dsps_fft4r_fc32_ansi_(float *data, int N, float *table, int table_size)

complex FFT of radix 4

Complex FFT of radix 4 The extension (_ansi) use ANSI C and could be compiled and run on any platform. The extension (_ae32) is optimized for ESP32 chip.

Return

  • ESP_OK on success

  • One of the error codes from DSP library

Parameters
  • [inout] data: input/output complex array. An elements located: Re[0], Im[0], … Re[N-1], Im[N-1] result of FFT will be stored to this array.

  • [in] N: Number of complex elements in input array

  • [in] table: pointer to sin/cos table

  • [in] table_size: size of the sin/cos table

esp_err_t dsps_fft4r_fc32_ae32_(float *data, int N, float *table, int table_size)
esp_err_t dsps_fft4r_fc32_arp4_(float *data, int N, float *table, int table_size)
esp_err_t dsps_bit_rev4r_fc32(float *data, int N)

bit reverse operation for the complex input array radix-4

Bit reverse operation for the complex input array The implementation use ANSI C and could be compiled and run on any platform

Return

  • ESP_OK on success

  • One of the error codes from DSP library

Parameters
  • [inout] data: input/ complex array. An elements located: Re[0], Im[0], … Re[N-1], Im[N-1] result of FFT will be stored to this array.

  • [in] N: Number of complex elements in input array

esp_err_t dsps_bit_rev4r_fc32_ae32(float *data, int N)
esp_err_t dsps_bit_rev4r_direct_fc32_ansi(float *data, int N)
esp_err_t dsps_bit_rev4r_sc16_ansi(int16_t *data, int N)
esp_err_t dsps_cplx2real_fc32_ansi_(float *data, int N, float *table, int table_size)

Convert FFT result to complex array for real input data.

Convert FFT result of complex FFT for real input to complex output. This function have to be used if FFT used to process real data. This function use tabels inside and can be used only it dsps_fft4r_init_fc32(…) was called and FFT4 was initialized. The implementation use ANSI C and could be compiled and run on any platform

Return

  • ESP_OK on success

  • One of the error codes from DSP library

Parameters
  • [inout] data: Input complex array and result of FFT2R/FFT4R. input has size of 2*N, because contains real and imaginary part. result will be stored to the same array. Input1: input[0..N-1] if the result is complex Re[0], Im[0]….Re[N-1], Im[N-1], and input[0…2*n-1] if result is real re[0], re[1],…,re[2*N-1].

  • [in] N: Number of complex elements in input array

  • [in] table: pointer to sin/cos table

  • [in] table_size: size of the sin/cos table

esp_err_t dsps_cplx2real_fc32_ae32_(float *data, int N, float *table, int table_size)
esp_err_t dsps_gen_bitrev4r_table(int N, int step, char *name_ext)

Macros

dsps_fft4r_fc32_ansi(data, N)
dsps_fft4r_fc32_ae32(data, N)
dsps_fft4r_fc32_arp4(data, N)
dsps_cplx2real_fc32_ansi(data, N)
dsps_cplx2real_fc32_ae32(data, N)
dsps_fft4r_fc32
dsps_fft4r_sc16
dsps_bit_rev4r_fc32
dsps_cplx2real_fc32

DCT

Functions

esp_err_t dsps_dct_f32(float *data, int N)

DCT of radix 2, unscaled.

Discrete Cosine Transform type II of radix 2, unscaled Function is FFT based The extension (_ansi) use ANSI C and could be compiled and run on any platform. The extension (_ae32) is optimized for ESP32 chip.

Return

  • ESP_OK on success

  • One of the error codes from DSP library

Parameters
  • [inout] data: input/output array with size of N*2. An elements located: Re[0],Re[1], , … Re[N-1], any data… up to N*2 result of DCT will be stored to this array from 0…N-1. Size of data array must be N*2!!!

  • [in] N: Size of DCT transform. Size of data array must be N*2!!!

esp_err_t dsps_dctiv_f32(float *data, int N)

DCT of radix 2, type IV, unscaled.

Discrete Cosine Transform type IV of radix 2, unscaled Function is FFT based The extension (_ansi) use ANSI C and could be compiled and run on any platform. The extension (_ae32) is optimized for ESP32 chip.

Return

  • ESP_OK on success

  • One of the error codes from DSP library

Parameters
  • [inout] data: input/output array with size of N. An elements located: Re[0],Re[1], , … Re[N-1] result of DST will be stored to this array from 0…N-1. Size of data array must be N

  • [in] N: Size of DCT transform. Size of data array must be N

esp_err_t dsps_dstiv_f32(float *data, int N)

DST of radix 2, type IV, unscaled.

Discrete Sine Transform type IV of radix 2, unscaled Function is FFT based The extension (_ansi) use ANSI C and could be compiled and run on any platform. The extension (_ae32) is optimized for ESP32 chip.

Return

  • ESP_OK on success

  • One of the error codes from DSP library

Parameters
  • [inout] data: input/output array with size of N*2. An elements located: Re[0],Re[1], , … Re[N-1] result of DST will be stored to this array from 0…N-1. Size of data array must be N

  • [in] N: Size of DST transform. Size of data array must be N

esp_err_t dsps_dct_inv_f32(float *data, int N)

Inverce DCT of radix 2.

Inverce Discrete Cosine Transform type II of radix 2, unscaled Function is FFT based The extension (_ansi) use ANSI C and could be compiled and run on any platform. The extension (_ae32) is optimized for ESP32 chip.

Return

  • ESP_OK on success

  • One of the error codes from DSP library

Parameters
  • [inout] data: input/output array with size of N*2. An elements located: Re[0],Re[1], , … Re[N-1], any data… up to N*2 result of DCT will be stored to this array from 0…N-1. Size of data array must be N*2!!!

  • [in] N: Size of DCT transform. Size of data array must be N*2!!!

esp_err_t dsps_dct_f32_ref(float *data, int N, float *result)

DCTs.

Direct DCT type II and Inverce DCT type III, unscaled These functions used as a reference for general purpose. These functions are not optimyzed! The extension (_ansi) use ANSI C and could be compiled and run on any platform. The extension (_ae32) is optimized for ESP32 chip.

Return

  • ESP_OK on success

  • One of the error codes from DSP library

Parameters
  • [in] data: input/output array with size of N. An elements located: Re[0],Re[1], , … Re[N-1]

  • [in] N: Size of DCT transform. Size of data array must be N*2!!!

  • [out] result: output result array with size of N.

esp_err_t dsps_dct_inverce_f32_ref(float *data, int N, float *result)

FIR

Functions

esp_err_t dsps_fir_f32_ansi(fir_f32_t *fir, const float *input, float *output, int len)

32 bit floating point FIR filter

Function implements FIR filter The extension (_ansi) uses ANSI C and could be compiled and run on any platform. The extension (_ae32) is optimized for ESP32 chip.

Return

  • ESP_OK on success

  • One of the error codes from DSP library

Parameters
  • fir: pointer to fir filter structure, that must be initialized before

  • [in] input: input array

  • [out] output: array with the result of FIR filter

  • [in] len: length of input and result arrays

esp_err_t dsps_fir_f32_ae32(fir_f32_t *fir, const float *input, float *output, int len)
esp_err_t dsps_fir_f32_aes3(fir_f32_t *fir, const float *input, float *output, int len)
int dsps_fird_f32_ansi(fir_f32_t *fir, const float *input, float *output, int len)

32 bit floating point Decimation FIR filter

Function implements FIR filter with decimation The extension (_ansi) uses ANSI C and could be compiled and run on any platform. The extension (_ae32) is optimized for ESP32 chip.

Return

: function returns the number of samples stored in the output array depends on the previous state value could be [0..len/decimation]

Parameters
  • fir: pointer to fir filter structure, that must be initialized before

  • input: input array

  • output: array with the result of FIR filter

  • len: length of result array

int dsps_fird_f32_ae32(fir_f32_t *fir, const float *input, float *output, int len)
int dsps_fird_f32_aes3(fir_f32_t *fir, const float *input, float *output, int len)
int dsps_fird_f32_arp4(fir_f32_t *fir, const float *input, float *output, int len)
int32_t dsps_fird_s16_ansi(fir_s16_t *fir, const int16_t *input, int16_t *output, int32_t len)

16 bit signed fixed point Decimation FIR filter

Function implements FIR filter with decimation The extension (_ansi) uses ANSI C and could be compiled and run on any platform. The extension (_ae32) is optimized for ESP32 chip.

Return

: function returns the number of samples stored in the output array depends on the previous state value could be [0..len/decimation]

Parameters
  • fir: pointer to fir filter structure, that must be initialized before

  • input: input array

  • output: array with the result of the FIR filter

  • len: length of the result array

int32_t dsps_fird_s16_ae32(fir_s16_t *fir, const int16_t *input, int16_t *output, int32_t len)
int32_t dsps_fird_s16_aes3(fir_s16_t *fir, const int16_t *input, int16_t *output, int32_t len)
int32_t dsps_fird_s16_arp4(fir_s16_t *fir, const int16_t *input, int16_t *output, int32_t len)
esp_err_t dsps_fird_s16_aexx_free(fir_s16_t *fir)

support arrays freeing function

Function frees all the arrays, which were created during the initialization of the fir_s16_t structure

  1. frees allocated memory for rounding buffer, for the purposes of esp32s3 ee.ld.accx.ip assembly instruction

  2. frees allocated memory in case the delay line is NULL

  3. frees allocated memory in case the length of the filter (and the delay line) is not divisible by 8 and new delay line and filter coefficients arrays are created for the purpose of the esp32s3 assembly

Return

  • ESP_OK on success

Parameters
  • fir: pointer to fir filter structure, that must be initialized before

esp_err_t dsps_fir_f32_free(fir_f32_t *fir)

support arrays freeing function

Function frees the delay line arrays, if it was allocated by the init functions.

Return

  • ESP_OK on success

Parameters
  • fir: pointer to fir filter structure, that must be initialized before

esp_err_t dsps_16_array_rev(int16_t *arr, int16_t len)

Array reversal.

Function reverses 16-bit long array members for the purpose of the dsps_fird_s16_aes3 implementation The function has to be called either during the fir struct initialization or every time the coefficients change

Return

  • ESP_OK on success

Parameters
  • arr: pointer to the array to be reversed

  • len: length of the array to be reversed

esp_err_t dsps_fir_init_f32(fir_f32_t *fir, float *coeffs, float *delay, int coeffs_len)

initialize structure for 32 bit FIR filter

Function initialize structure for 32 bit floating point FIR filter The implementation use ANSI C and could be compiled and run on any platform

Return

  • ESP_OK on success

  • One of the error codes from DSP library

Parameters
  • fir: pointer to fir filter structure, that must be preallocated

  • coeffs: array with FIR filter coefficients. Must be length N

  • delay: array for FIR filter delay line. Must have a length = coeffs_len + 4

  • coeffs_len: FIR filter length. Length of coeffs array. For esp32s3 length should be divided by 4 and aligned to 16.

esp_err_t dsps_fird_init_f32(fir_f32_t *fir, float *coeffs, float *delay, int N, int decim)

initialize structure for 32 bit Decimation FIR filter Function initialize structure for 32 bit floating point FIR filter with decimation The implementation use ANSI C and could be compiled and run on any platform

Return

  • ESP_OK on success

  • One of the error codes from DSP library

Parameters
  • fir: pointer to fir filter structure, that must be preallocated

  • coeffs: array with FIR filter coefficients. Must be length N

  • delay: array for FIR filter delay line. Must be length N

  • N: FIR filter length. Length of coeffs and delay arrays.

  • decim: decimation factor.

esp_err_t dsps_fird_init_s16(fir_s16_t *fir, int16_t *coeffs, int16_t *delay, int16_t coeffs_len, int16_t decim, int16_t start_pos, int16_t shift)

initialize structure for 16 bit Decimation FIR filter Function initialize structure for 16 bit signed fixed point FIR filter with decimation The implementation use ANSI C and could be compiled and run on any platform

Return

  • ESP_OK on success

  • One of the error codes from DSP library

Parameters
  • fir: pointer to fir filter structure, that must be preallocated

  • coeffs: array with FIR filter coefficients. Must be length N

  • delay: array for FIR filter delay line. Must be length N

  • coeffs_len: FIR filter length. Length of coeffs and delay arrays.

  • decim: decimation factor.

  • start_pos: initial value of decimation counter. Must be [0..d)

  • shift: shift position of the result

Structures

struct fir_f32_s

Data struct of f32 fir filter.

This structure is used by a filter internally. A user should access this structure only in case of extensions for the DSP Library. All fields of this structure are initialized by the dsps_fir_init_f32(…) function.

Public Members

float *coeffs

Pointer to the coefficient buffer.

float *delay

Pointer to the delay line buffer.

int N

FIR filter coefficients amount.

int pos

Position in delay line.

int decim

Decimation factor.

int16_t use_delay

The delay line was allocated by init function.

struct fir_s16_s

Data struct of s16 fir filter.

This structure is used by a filter internally. A user should access this structure only in case of extensions for the DSP Library. All fields of this structure are initialized by the dsps_fir_init_s16(…) function.

Public Members

int16_t *coeffs

Pointer to the coefficient buffer.

int16_t *delay

Pointer to the delay line buffer.

int16_t coeffs_len

FIR filter coefficients amount.

int16_t pos

Position in delay line.

int16_t decim

Decimation factor.

int16_t d_pos

Actual decimation counter.

int16_t shift

Shift value of the result.

int32_t *rounding_buff

Rounding buffer for the purposes of esp32s3 ee.ld.accx.ip assembly instruction

int32_t rounding_val

Rounding value

int16_t free_status

Indicator for dsps_fird_s16_aes3_free() function

Macros

dsps_fir_f32
dsps_fird_f32
dsps_fird_s16

Type Definitions

typedef struct fir_f32_s fir_f32_t

Data struct of f32 fir filter.

This structure is used by a filter internally. A user should access this structure only in case of extensions for the DSP Library. All fields of this structure are initialized by the dsps_fir_init_f32(…) function.

typedef struct fir_s16_s fir_s16_t

Data struct of s16 fir filter.

This structure is used by a filter internally. A user should access this structure only in case of extensions for the DSP Library. All fields of this structure are initialized by the dsps_fir_init_s16(…) function.

IIR

Functions

esp_err_t dsps_biquad_gen_lpf_f32(float *coeffs, float f, float qFactor)

LPF IIR filter coefficients Coefficients for low pass 2nd order IIR filter (bi-quad) The implementation use ANSI C and could be compiled and run on any platform.

Return

  • ESP_OK on success

  • One of the error codes from DSP library

Parameters
  • coeffs: result coefficients. b0,b1,b2,a1,a2, a0 are not placed to the array and expected by IIR as 1

  • f: filter cut off frequency in range of 0..0.5 (normalized to sample frequency)

  • qFactor: Q factor of filter

esp_err_t dsps_biquad_gen_hpf_f32(float *coeffs, float f, float qFactor)

HPF IIR filter coefficients.

Coefficients for high pass 2nd order IIR filter (bi-quad) The implementation use ANSI C and could be compiled and run on any platform

Return

  • ESP_OK on success

  • One of the error codes from DSP library

Parameters
  • coeffs: result coefficients. b0,b1,b2,a1,a2, a0 are not placed to the array and expected by IIR as 1

  • f: filter cut off frequency in range of 0..0.5 (normalized to sample frequency)

  • qFactor: Q factor of filter

esp_err_t dsps_biquad_gen_bpf_f32(float *coeffs, float f, float qFactor)

BPF IIR filter coefficients.

Coefficients for band pass 2nd order IIR filter (bi-quad) The implementation use ANSI C and could be compiled and run on any platform

Return

  • ESP_OK on success

  • One of the error codes from DSP library

Parameters
  • coeffs: result coefficients. b0,b1,b2,a1,a2, a0 are not placed to the array and expected by IIR as 1

  • f: filter center frequency in range of 0..0.5 (normalized to sample frequency)

  • qFactor: Q factor of filter

esp_err_t dsps_biquad_gen_bpf0db_f32(float *coeffs, float f, float qFactor)

0 dB BPF IIR filter coefficients

Coefficients for band pass 2nd order IIR filter (bi-quad) with 0 dB gain in passband The implementation use ANSI C and could be compiled and run on any platform

Return

  • ESP_OK on success

  • One of the error codes from DSP library

Parameters
  • coeffs: result coefficients. b0,b1,b2,a1,a2, a0 are not placed to the array and expected by IIR as 1

  • f: filter center frequency in range of 0..0.5 (normalized to sample frequency)

  • qFactor: Q factor of filter

esp_err_t dsps_biquad_gen_notch_f32(float *coeffs, float f, float gain, float qFactor)

Notch IIR filter coefficients.

Coefficients for notch 2nd order IIR filter (bi-quad) The implementation use ANSI C and could be compiled and run on any platform

Return

  • ESP_OK on success

  • One of the error codes from DSP library

Parameters
  • coeffs: result coefficients. b0,b1,b2,a1,a2, a0 are not placed to the array and expected by IIR as 1

  • f: filter notch frequency in range of 0..0.5 (normalized to sample frequency)

  • gain: gain in stopband in dB

  • qFactor: Q factor of filter

esp_err_t dsps_biquad_gen_allpass360_f32(float *coeffs, float f, float qFactor)

Allpass 360 degree IIR filter coefficients.

Coefficients for all pass 2nd order IIR filter (bi-quad) with 360 degree phase shift The implementation use ANSI C and could be compiled and run on any platform

Return

  • ESP_OK on success

  • One of the error codes from DSP library

Parameters
  • coeffs: result coefficients. b0,b1,b2,a1,a2, a0 are not placed to the array and expected by IIR as 1

  • f: filter notch frequency in range of 0..0.5 (normalized to sample frequency)

  • qFactor: Q factor of filter

esp_err_t dsps_biquad_gen_allpass180_f32(float *coeffs, float f, float qFactor)

Allpass 180 degree IIR filter coefficients.

Coefficients for all pass 2nd order IIR filter (bi-quad) with 180 degree phase shift The implementation use ANSI C and could be compiled and run on any platform

Return

  • ESP_OK on success

  • One of the error codes from DSP library

Parameters
  • coeffs: result coefficients. b0,b1,b2,a1,a2, a0 are not placed to the array and expected by IIR as 1

  • f: filter notch frequency in range of 0..0.5 (normalized to sample frequency)

  • qFactor: Q factor of filter

esp_err_t dsps_biquad_gen_peakingEQ_f32(float *coeffs, float f, float qFactor)

peak IIR filter coefficients

Coefficients for peak 2nd order IIR filter (bi-quad) The implementation use ANSI C and could be compiled and run on any platform

Return

  • ESP_OK on success

  • One of the error codes from DSP library

Parameters
  • coeffs: result coefficients. b0,b1,b2,a1,a2, a0 are not placed to the array and expected by IIR as 1

  • f: filter notch frequency in range of 0..0.5 (normalized to sample frequency)

  • qFactor: Q factor of filter

esp_err_t dsps_biquad_gen_lowShelf_f32(float *coeffs, float f, float gain, float qFactor)

low shelf IIR filter coefficients

Coefficients for low pass Shelf 2nd order IIR filter (bi-quad) The implementation use ANSI C and could be compiled and run on any platform

Return

  • ESP_OK on success

  • One of the error codes from DSP library

Parameters
  • coeffs: result coefficients. b0,b1,b2,a1,a2, a0 are not placed to the array and expected by IIR as 1

  • f: filter notch frequency in range of 0..0.5 (normalized to sample frequency)

  • gain: gain in stopband in dB

  • qFactor: Q factor of filter

esp_err_t dsps_biquad_gen_highShelf_f32(float *coeffs, float f, float gain, float qFactor)

high shelf IIR filter coefficients

Coefficients for high pass Shelf 2nd order IIR filter (bi-quad) The implementation use ANSI C and could be compiled and run on any platform

Return

  • ESP_OK on success

  • One of the error codes from DSP library

Parameters
  • coeffs: result coefficients. b0,b1,b2,a1,a2, a0 are not placed to the array and expected by IIR as 1

  • f: filter notch frequency in range of 0..0.5 (normalized to sample frequency)

  • gain: gain in stopband in dB

  • qFactor: Q factor of filter

Functions

esp_err_t dsps_biquad_f32_ansi(const float *input, float *output, int len, float *coef, float *w)

IIR filter.

IIR filter 2nd order direct form II (bi quad) The extension (_ansi) use ANSI C and could be compiled and run on any platform. The extension (_ae32) is optimized for ESP32 chip.

Return

  • ESP_OK on success

  • One of the error codes from DSP library

Parameters
  • [in] input: input array

  • output: output array

  • len: length of input and output vectors

  • coef: array of coefficients. b0,b1,b2,a1,a2 expected that a0 = 1. b0..b2 - numerator, a0..a2 - denominator

  • w: delay line w0,w1. Length of 2.

esp_err_t dsps_biquad_f32_ae32(const float *input, float *output, int len, float *coef, float *w)
esp_err_t dsps_biquad_f32_aes3(const float *input, float *output, int len, float *coef, float *w)
esp_err_t dsps_biquad_f32_arp4(const float *input, float *output, int len, float *coef, float *w)

Macros

dsps_biquad_f32

Basic math

Functions

esp_err_t dsps_mul_f32_ansi(const float *input1, const float *input2, float *output, int len, int step1, int step2, int step_out)

Multiply two arrays.

The function multiply one input array to another and store result to other array out[i*step_out] = input1[i*step1] * input2[i*step2]; i=[0..len) The implementation use ANSI C and could be compiled and run on any platform

Return

  • ESP_OK on success

  • One of the error codes from DSP library

Parameters
  • [in] input1: input array 1

  • [in] input2: input array 2

  • output: output array

  • len: amount of operations for arrays

  • step1: step over input array 1 (by default should be 1)

  • step2: step over input array 2 (by default should be 1)

  • step_out: step over output array (by default should be 1)

esp_err_t dsps_mul_f32_ae32(const float *input1, const float *input2, float *output, int len, int step1, int step2, int step_out)
esp_err_t dsps_mul_s16_ansi(const int16_t *input1, const int16_t *input2, int16_t *output, int len, int step1, int step2, int step_out, int shift)

Multiply two arrays.

The function multiply one input array to another and store result to other array out[i*step_out] = input1[i*step1] * input2[i*step2]; i=[0..len) The implementation use ANSI C and could be compiled and run on any platform

Return

  • ESP_OK on success

  • One of the error codes from DSP library

Parameters
  • [in] input1: input array 1

  • [in] input2: input array 2

  • output: output array

  • len: amount of operations for arrays

  • step1: step over input array 1 (by default should be 1)

  • step2: step over input array 2 (by default should be 1)

  • step_out: step over output array (by default should be 1)

  • shift: output shift after multiplication (by default should be 15)

esp_err_t dsps_mul_s16_ae32(const int16_t *input1, const int16_t *input2, int16_t *output, int len, int step1, int step2, int step_out, int shift)
esp_err_t dsps_mul_s16_aes3(const int16_t *input1, const int16_t *input2, int16_t *output, int len, int step1, int step2, int step_out, int shift)
esp_err_t dsps_mul_s8_ansi(const int8_t *input1, const int8_t *input2, int8_t *output, int len, int step1, int step2, int step_out, int shift)
esp_err_t dsps_mul_s8_aes3(const int8_t *input1, const int8_t *input2, int8_t *output, int len, int step1, int step2, int step_out, int shift)

Macros

dsps_mul_f32
dsps_mul_s16
dsps_mul_s8

Functions

esp_err_t dsps_addc_f32_ansi(const float *input, float *output, int len, float C, int step_in, int step_out)

add constant

The function adds constant to the input array x[i*step_out] = y[i*step_in] + C; i=[0..len) The implementation use ANSI C and could be compiled and run on any platform

Return

  • ESP_OK on success

  • One of the error codes from DSP library

Parameters
  • [in] input: input array

  • output: output array

  • len: amount of operations for arrays

  • C: constant value

  • step_in: step over input array (by default should be 1)

  • step_out: step over output array (by default should be 1)

esp_err_t dsps_addc_f32_ae32(const float *input, float *output, int len, float C, int step_in, int step_out)

Macros

dsps_addc_f32

Functions

esp_err_t dsps_mulc_f32_ansi(const float *input, float *output, int len, float C, int step_in, int step_out)

multiply constant

The function multiplies input array to the constant value x[i*step_out] = y[i*step_in]*C; i=[0..len) The implementation use ANSI C and could be compiled and run on any platform

Return

  • ESP_OK on success

  • One of the error codes from DSP library

Parameters
  • [in] input: input array

  • output: output array

  • len: amount of operations for arrays

  • C: constant value

  • step_in: step over input array (by default should be 1)

  • step_out: step over output array (by default should be 1)

esp_err_t dsps_mulc_f32_ae32(const float *input, float *output, int len, float C, int step_in, int step_out)
esp_err_t dsps_mulc_s16_ae32(const int16_t *input, int16_t *output, int len, int16_t C, int step_in, int step_out)
esp_err_t dsps_mulc_s16_ansi(const int16_t *input, int16_t *output, int len, int16_t C, int step_in, int step_out)

Macros

dsps_mulc_f32
dsps_mulc_s16

Convolution and correlation

Functions

esp_err_t dsps_conv_f32_ae32(const float *Signal, const int siglen, const float *Kernel, const int kernlen, float *convout)

Convolution.

The function convolve Signal array with Kernel array. The implementation use ANSI C and could be compiled and run on any platform

Return

  • ESP_OK on success

  • One of the error codes from DSP library

Parameters
  • [in] Signal: input array with signal

  • [in] siglen: length of the input signal

  • [in] Kernel: input array with convolution kernel

  • [in] kernlen: length of the Kernel array

  • convout: output array with convolution result length of (siglen + Kernel -1)

esp_err_t dsps_conv_f32_ansi(const float *Signal, const int siglen, const float *Kernel, const int kernlen, float *convout)

Macros

dsps_conv_f32

Functions

esp_err_t dsps_corr_f32_ansi(const float *Signal, const int siglen, const float *Pattern, const int patlen, float *dest)

Correlation with pattern.

The function correlate input sigla array with pattern array. The implementation use ANSI C and could be compiled and run on any platform

Return

  • ESP_OK on success

  • One of the error codes from DSP library (one of the input array are NULL, or if (siglen < patlen))

Parameters
  • [in] Signal: input array with signal values

  • [in] siglen: length of the signal array

  • [in] Pattern: input array with pattern values

  • [in] patlen: length of the pattern array. The siglen must be bigger then patlen!

  • dest: output array with result of correlation

esp_err_t dsps_corr_f32_ae32(const float *Signal, const int siglen, const float *Pattern, const int patlen, float *dest)

Macros

dsps_corr_f32

Generator

Functions

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.

Function initializes a structure for either 16-bit fixed point, or 32-bit floating point complex generator using LUT table. cplx_gen_free(…) must be called, once the generator is not needed anymore to free dynamically allocated memory

A user can specify his own LUT table and pass a pointer to the table (void *lut) during the initialization. If the LUT table pointer passed to the init function is a NULL, the LUT table is initialized internally.

Return

  • ESP_OK on success

  • One of the error codes from DSP library

Parameters
  • cplx_gen: pointer to the floating point generator structure

  • d_type: output data type - out_d_type enum

  • lut: pointer to a user-defined LUT, the data type is void so both (S16_FIXED, F32_FLOAT) types could be used

  • lut_len: length of the LUT

  • freq: Frequency of the output signal in a range of [-1…1], where 1 is a Nyquist frequency

  • initial_phase: initial phase of the complex signal in range of [-1..1] where 1 is related to 2Pi and -1 is related to -2Pi

esp_err_t dsps_cplx_gen_freq_set(cplx_sig_t *cplx_gen, float freq)

function sets the output frequency of the complex generator

set function can be used after the cplx_gen structure was initialized by the dsps_cplx_gen_init(…) function

Return

  • ESP_OK on success

  • ESP_ERR_DSP_INVALID_PARAM if the frequency is out of the Nyquist frequency range

Parameters
  • cplx_gen: pointer to the complex signal generator structure

  • freq: new frequency to be set in a range of [-1..1] where 1 is a Nyquist frequency

float dsps_cplx_gen_freq_get(cplx_sig_t *cplx_gen)

function gets the output frequency of the complex generator

get function can be used after the cplx_gen structure was initialized by the dsps_cplx_gen_init(…) function

Return

function returns frequency of the signal generator

Parameters
  • cplx_gen: pointer to the complex signal generator structure

esp_err_t dsps_cplx_gen_phase_set(cplx_sig_t *cplx_gen, float phase)

function sets the phase of the complex generator

set function can be used after the cplx_gen structure was initialized by the dsps_cplx_gen_init(…) function

Return

  • ESP_OK on success

  • ESP_ERR_DSP_INVALID_PARAM if the phase is out of -1 … 1 range

Parameters
  • cplx_gen: pointer to the complex signal generator structure

  • phase: new phase to be set in the range of [-1..1] where 1 is related to 2Pi and -1 is related to -2Pi

float dsps_cplx_gen_phase_get(cplx_sig_t *cplx_gen)

function gets the phase of the complex generator

get function can be used after the cplx_gen structure was initialized by the dsps_cplx_gen_init(…) function

Return

function returns phase of the signal generator

Parameters
  • cplx_gen: pointer to the complex signal generator structure

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

set function can be used after the cplx_gen structure was initialized by the dsps_cplx_gen_init(…) function

Return

  • ESP_OK on success

  • ESP_ERR_DSP_INVALID_PARAM if the frequency is out of the Nyquist frequency range if the phase is out of -1 … 1 range

Parameters
  • cplx_gen: pointer to the complex signal generator structure

  • freq: new frequency to be set in the range of [-1..1] where 1 is a Nyquist frequency

  • phase: new phase to be set in the range of [-1..1] where 1 is related to 2Pi and -1 is related to -2Pi

void cplx_gen_free(cplx_sig_t *cplx_gen)

function frees dynamically allocated memory, which was allocated in the init function

free function must be called after the dsps_cplx_gen_init(…) is called, once the complex generator is not needed anymore

Parameters
  • cplx_gen: pointer to the complex signal generator structure

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

Return

  • ESP_OK on success

  • One of the error codes from DSP library

Parameters
  • cplx_gen: pointer to the generator structure

  • output: output array (length of len*2), data type is void so both (S16_FIXED, F32_FLOAT) types could be used

  • len: length of the output signal

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

Structures

struct cplx_sig_s

Data struct of the complex signal generator.

This structure is used by a complex generator internally. A user should access this structure only in case of extensions for the DSP Library. All the fields of this structure are initialized by the dsps_cplx_gen_init(…) function.

Public Members

void *lut

Pointer to the lookup table.

int32_t lut_len

Length of the lookup table.

float freq

Frequency of the output signal. Nyquist frequency -1 … 1

float phase

Phase (initial_phase during init)

out_d_type d_type

Output data type

int16_t free_status

Indicator for cplx_gen_free(…) function

Macros

dsps_cplx_gen

Type Definitions

typedef enum output_data_type out_d_type

Ennum defining output data type of the complex generator.

typedef struct cplx_sig_s cplx_sig_t

Data struct of the complex signal generator.

This structure is used by a complex generator internally. A user should access this structure only in case of extensions for the DSP Library. All the fields of this structure are initialized by the dsps_cplx_gen_init(…) function.

Enumerations

enum output_data_type

Ennum defining output data type of the complex generator.

Values:

S16_FIXED = 0

Q15 fixed point - int16_t

F32_FLOAT = 1

Single precision floating point - float

Support

Functions

esp_err_t dsps_d_gen_f32(float *output, int len, int pos)

delta function

The function generate delta function. output[i]=0, if i=[0..N) output[i]=1, if i=pos, pos: [0..N-1) The implementation use ANSI C and could be compiled and run on any platform

Return

  • ESP_OK on success

  • One of the error codes from DSP library

Parameters
  • output: output array.

  • len: length of the input signal

  • pos: delta function position

Functions

esp_err_t dsps_h_gen_f32(float *output, int len, int pos)

Heviside function.

The Heviside function. output[i]=0, if i=[0..pos) output[i]=1, if i=[pos..N) The implementation use ANSI C and could be compiled and run on any platform

Return

  • ESP_OK on success

  • One of the error codes from DSP library

Parameters
  • output: output array.

  • len: length of the input signal

  • pos: heviside function position

Functions

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

Return

  • ESP_OK on success

  • One of the error codes from DSP library

Parameters
  • output: output array.

  • len: length of the input signal

  • Ampl: amplitude

  • freq: Naiquist frequency -1..1

  • phase: phase in degree

Functions

void dsps_view(const float *data, int32_t len, int width, int height, float min, float max, char view_char)

plot view

Generic view function. This function takes input samples and show then in console view as a plot. The main purpose to give and draft debug information to the DSP developer.

Parameters
  • [in] data: array with input samples.

  • len: length of the input array

  • width: plot width in symbols

  • height: plot height in lines

  • min: minimum value that will be limited by Axis Y.

  • max: maximum value that will be limited by Axis Y.

  • view_char: character to draw the plot calues (‘.’ or ‘|’ etc)

void dsps_view_s16(const int16_t *data, int32_t len, int width, int height, float min, float max, char view_char)
void dsps_view_spectrum(const float *data, int32_t len, float min, float max)

spectrum view

The view function to show spectrum values in 64x10 screen. The function based on dsps_view.

Parameters
  • [in] data: array with input samples.

  • len: length of the input array

  • min: minimum value that will be limited by Axis Y.

  • max: maximum value that will be limited by Axis Y.

Functions

float dsps_snr_f32(const float *input, int32_t len, uint8_t use_dc)

SNR.

The function calculates signal to noise ration in case if signal is sine tone. The function makes FFT of the input, then search a spectrum maximum, and then calculated SNR as sum of all harmonics to the maximum value. This function have to be used for debug and unit tests only. It’s not optimized for real-time processing. The implementation use ANSI C and could be compiled and run on any platform

Return

  • SNR in dB

Parameters
  • input: input array.

  • len: length of the input signal

  • use_dc: this parameter define will be DC value used for calculation or not. 0 - SNR will not include DC power 1 - SNR will include DC power

float dsps_snr_fc32(const float *input, int32_t len)

Functions

float dsps_sfdr_f32(const float *input, int32_t len, int8_t use_dc)

SFDR.

The function calculates Spurious-Free Dynamic Range. The function makes FFT of the input, then search a spectrum maximum, and then compare maximum value with all others. Result calculated as minimum value. This function have to be used for debug and unit tests only. It’s not optimized for real-time processing. The implementation use ANSI C and could be compiled and run on any platform

Return

  • SFDR in DB

Parameters
  • [in] input: input array.

  • len: length of the input signal

  • use_dc: this parameter define will be DC value used for calculation or not. 0 - SNR will not include DC power 1 - SNR will include DC power

float dsps_sfdr_fc32(const float *input, int32_t len)

Kalman Filer

Classes

class ekf

The ekf is a base class for Extended Kalman Filter. It contains main matrix operations and define the processing flow.

Subclassed by ekf_imu13states

Public Functions

ekf(int x, int w)

Constructor of EKF. THe constructor allocate main memory for the matrixes.

Parameters
  • [in] x: - amount of states in EKF. x[n] = F*x[n-1] + G*u + W. Size of matrix F

  • [in] w: - amount of control measurements and noise inputs. Size of matrix G

virtual ~ekf()

Distructor of EKF

virtual void Process(float *u, float dt)

Main processing method of the EKF.

Parameters
  • [in] u: - input measurements

  • [in] dt: - time difference from the last call in seconds

virtual void Init() = 0

Initialization of EKF. The method should be called befare the first use of the filter.

void RungeKutta(dspm::Mat &x, float *u, float dt)

Runge-Kutta state update method. The method calculates derivatives of input vector x and control measurements u

Parameters
  • [in] x: state vector

  • [in] u: control measurement

  • [in] dt: time interval from last update in seconds

virtual dspm::Mat StateXdot(dspm::Mat &x, float *u)

Derivative of state vector X The default calculation: xDot = F*x + G*u It’s possible to implement optimized version

Return

xDot - derivative of input vector x and u

Parameters
  • [in] x: state vector

  • [in] u: control measurement

virtual void LinearizeFG(dspm::Mat &x, float *u) = 0

Calculation of system state matrices F and G

Parameters
  • [in] x: state vector

  • [in] u: control measurement

virtual void CovariancePrediction(float dt)

Calculates covariance prediction matrux P. Update matrix P

Parameters
  • [in] dt: time interval from last update

virtual void Update(dspm::Mat &H, float *measured, float *expected, float *R)

Update of current state by measured values. Optimized method for non correlated values Calculate Kalman gain and update matrix P and vector X.

Parameters
  • [in] H: derivative matrix

  • [in] measured: array of measured values

  • [in] expected: array of expected values

  • [in] R: measurement noise covariance values

virtual void UpdateRef(dspm::Mat &H, float *measured, float *expected, float *R)

Update of current state by measured values. This method just as a reference for research purpose. Not used in real calculations.

Parameters
  • [in] H: derivative matrix

  • [in] measured: array of measured values

  • [in] expected: array of expected values

  • [in] R: measurement noise covariance values

Public Members

int NUMX

xDot[n] = F*x[n] + G*u + W Number of states, X is the state vector (size of F matrix)

int NUMW

xDot[n] = F*x[n] + G*u + W The size of G matrix

dspm::Mat &X

System state vector

dspm::Mat &F

Linearized system matrices F, where xDot[n] = F*x[n] + G*u + W

dspm::Mat &G

Linearized system matrices G, where xDot[n] = F*x[n] + G*u + W

dspm::Mat &P

Covariance matrix and state vector

dspm::Mat &Q

Input noise and measurement noise variances

float *HP

Matrix for intermidieve calculations

float *Km

Matrix for intermidieve calculations

Public Static Functions

static dspm::Mat quat2rotm(float q[4])

Convert quaternion to rotation matrix.

Return

  • rotation matrix 3x3

Parameters
  • [in] q: quaternion

static dspm::Mat rotm2quat(dspm::Mat &R)

Convert rotation matrix to quaternion.

Return

  • quaternion 4x1

Parameters
  • [in] R: rotation matrix

static dspm::Mat quat2eul(const float q[4])

Convert quaternion to Euler angels.

Return

  • Euler angels 3x1

Parameters
  • [in] q: quaternion

static dspm::Mat eul2rotm(float xyz[3])

Convert Euler angels to rotation matrix.

Return

  • rotation matrix 3x3

Parameters
  • [in] xyz: Euler angels

static dspm::Mat rotm2eul(dspm::Mat &rotm)

Convert rotation matrix to Euler angels.

Return

  • Euler angels 3x1

Parameters
  • [in] rotm: rotation matrix

static dspm::Mat dFdq(dspm::Mat &vector, dspm::Mat &quat)

Df/dq: Derivative of vector by quaternion.

Return

  • Derivative matrix 3x4

Parameters
  • [in] vector: input vector

  • [in] quat: quaternion

static dspm::Mat dFdq_inv(dspm::Mat &vector, dspm::Mat &quat)

Df/dq: Derivative of vector by inverted quaternion.

Return

  • Derivative matrix 3x4

Parameters
  • [in] vector: input vector

  • [in] quat: quaternion

static dspm::Mat SkewSym4x4(float *w)

Make skew-symmetric matrix of vector.

Return

  • skew-symmetric matrix 4x4

Parameters
  • [in] w: source vector

static dspm::Mat qProduct(float *q)

Make right quaternion-product matrices.

Return

  • right quaternion-product matrix 4x4

Parameters
  • [in] q: source quaternion

For more details about implementation of 13 states EKF, please read: modules/kalman/ekf_imu13states/docs/README.md

Classes

class ekf_imu13states : public ekf

This class is used to process and calculate attitude from imu sensors.

The class use state vector with 13 follows values X[0..3] - attitude quaternion X[4..6] - gyroscope bias error, rad/sec X[7..9] - magnetometer vector value - magn_ampl X[10..12] - magnetometer offset value - magn_offset

where, reference magnetometer value = magn_ampl*rotation_matrix’ + magn_offset

Public Functions

virtual void Init()

Initialization of EKF. The method should be called befare the first use of the filter.

virtual dspm::Mat StateXdot(dspm::Mat &x, float *u)

Derivative of state vector X The default calculation: xDot = F*x + G*u It’s possible to implement optimized version

Return

xDot - derivative of input vector x and u

Parameters
  • [in] x: state vector

  • [in] u: control measurement

virtual void LinearizeFG(dspm::Mat &x, float *u)

Calculation of system state matrices F and G

Parameters
  • [in] x: state vector

  • [in] u: control measurement

void Test()

Method for development and tests only.

void TestFull(bool enable_att)

Method for development and tests only.

Parameters
  • [in] enable_att: - enable attitude as input reference value

void UpdateRefMeasurement(float *accel_data, float *magn_data, float R[6])

Update part of system state by reference measurements accelerometer and magnetometer. Only attitude and gyro bias will be updated. This method should be used as main method after calibration.

Parameters
  • [in] accel_data: accelerometer measurement vector XYZ in g, where 1 g ~ 9.81 m/s^2

  • [in] magn_data: magnetometer measurement vector XYZ

  • [in] R: measurement noise covariance values for diagonal covariance matrix. Then smaller value, then more you trust them.

void UpdateRefMeasurementMagn(float *accel_data, float *magn_data, float R[6])

Update full system state by reference measurements accelerometer and magnetometer. This method should be used at calibration phase.

Parameters
  • [in] accel_data: accelerometer measurement vector XYZ in g, where 1 g ~ 9.81 m/s^2

  • [in] magn_data: magnetometer measurement vector XYZ

  • [in] R: measurement noise covariance values for diagonal covariance matrix. Then smaller value, then more you trust them.

void UpdateRefMeasurement(float *accel_data, float *magn_data, float *attitude, float R[10])

Update system state by reference measurements accelerometer, magnetometer and attitude quaternion. This method could be used when system on constant state or in initialization phase.

Parameters
  • [in] accel_data: accelerometer measurement vector XYZ in g, where 1 g ~ 9.81 m/s^2

  • [in] magn_data: magnetometer measurement vector XYZ

  • [in] attitude: attitude quaternion

  • [in] R: measurement noise covariance values for diagonal covariance matrix. Then smaller value, then more you trust them.

Public Members

dspm::Mat mag0

Initial reference valie for magnetometer.

dspm::Mat accel0

Initial reference valie for accelerometer.

int NUMU

number of control measurements

Window Functions

Functions

void dsps_wind_hann_f32(float *window, int len)

Hann window.

The function generates Hann window.

Parameters
  • window: buffer to store window array.

  • len: length of the window array

Functions

void dsps_wind_blackman_f32(float *window, int len)

Blackman window.

The function generates Blackman window for plpha = 0.16.

Parameters
  • window: buffer to store window array.

  • len: length of the window array

Functions

void dsps_wind_blackman_harris_f32(float *window, int len)

Blackman-Harris window.

The function generates Blackman-Harris window.

Parameters
  • window: buffer to store window array.

  • len: length of the window array

Functions

void dsps_wind_blackman_nuttall_f32(float *window, int len)

Blackman-Nuttall window.

The function generates Blackman-Nuttall window.

Parameters
  • window: buffer to store window array.

  • len: length of the window array

Functions

void dsps_wind_flat_top_f32(float *window, int len)

Flat-Top window.

The function generates Flat-Top window.

Parameters
  • window: buffer to store window array.

  • len: length of the window array

Functions

void dsps_wind_nuttall_f32(float *window, int len)

Nuttall window.

The function generates Nuttall window.

Parameters
  • window: buffer to store window array.

  • len: length of the window array

Matrix Operations APIs

Matrix operations APIs use dspm prefix. The following modules are available:

  • Multiplication - basic matrix multiplication operations

Matrix Multiplication

Functions

esp_err_t dspm_mult_ex_f32_ansi(const float *A, const float *B, float *C, int m, int n, int k, int A_padd, int B_padd, int C_padd)

Matrix subset multiplication.

One or all of the matrices are matrix subsets, described with pointers and strides Matrix multiplication for two floating point matrices: C[m][k] = A[m][n] * B[n][k] The extension (_ansi) use ANSI C and could be compiled and run on any platform. The extension (_ae32) is optimized for ESP32 chip.

Return

  • ESP_OK on success

  • One of the error codes from DSP library

Parameters
  • [in] A: input matrix A[m][n]

  • [in] B: input matrix B[n][k]

  • [out] C: result matrix C[m][k]

  • [in] m: matrix dimension

  • [in] n: matrix dimension

  • [in] k: matrix dimension

  • [in] A_padd: input matrix A padding

  • [in] B_padd: input matrix B padding

  • [in] C_padd: result matrix C padding

esp_err_t dspm_mult_ex_f32_ae32(const float *A, const float *B, float *C, int m, int n, int k, int A_padd, int B_padd, int C_padd)
esp_err_t dspm_mult_ex_f32_aes3(const float *A, const float *B, float *C, int m, int n, int k, int A_padd, int B_padd, int C_padd)
esp_err_t dspm_mult_ex_f32_arp4(const float *A, const float *B, float *C, int m, int n, int k, int A_padd, int B_padd, int C_padd)
esp_err_t dspm_mult_f32_ansi(const float *A, const float *B, float *C, int m, int n, int k)

Matrix multiplication.

Matrix multiplication for two floating point matrices: C[m][k] = A[m][n] * B[n][k] The extension (_ansi) use ANSI C and could be compiled and run on any platform. The extension (_ae32) is optimized for ESP32 chip.

Return

  • ESP_OK on success

  • One of the error codes from DSP library

Parameters
  • [in] A: input matrix A[m][n]

  • [in] B: input matrix B[n][k]

  • C: result matrix C[m][k]

  • [in] m: matrix dimension

  • [in] n: matrix dimension

  • [in] k: matrix dimension

esp_err_t dspm_mult_f32_ae32(const float *A, const float *B, float *C, int m, int n, int k)
esp_err_t dspm_mult_f32_aes3(const float *A, const float *B, float *C, int m, int n, int k)
esp_err_t dspm_mult_f32_arp4(const float *A, const float *B, float *C, int m, int n, int k)
esp_err_t dspm_mult_s16_ansi(const int16_t *A, const int16_t *B, int16_t *C, int m, int n, int k, int shift)

Matrix multiplication 16 bit signeg int.

Matrix multiplication for two signed 16 bit fixed point matrices: C[m][k] = (A[m][n] * B[n][k]) >> (15- shift) The extension (_ansi) use ANSI C and could be compiled and run on any platform. The extension (_ae32) is optimized for ESP32 chip.

Return

  • ESP_OK on success

  • One of the error codes from DSP library

Parameters
  • [in] A: input matrix A[m][n]

  • [in] B: input matrix B[n][k]

  • C: result matrix C[m][k]

  • [in] m: matrix dimension

  • [in] n: matrix dimension

  • [in] k: matrix dimension

  • [in] shift: every result will be shifted and stored as 16 bit signed value.

esp_err_t dspm_mult_s16_ae32(const int16_t *A, const int16_t *B, int16_t *C, int m, int n, int k, int shift)
esp_err_t dspm_mult_s16_aes3(const int16_t *A, const int16_t *B, int16_t *C, int m, int n, int k, int shift)
esp_err_t dspm_mult_s16_arp4(const int16_t *A, const int16_t *B, int16_t *C, int m, int n, int k, int shift)
esp_err_t dspm_mult_3x3x1_f32_ae32(const float *A, const float *B, float *C)

Matrix multiplication A[3x3]xB[3x1].

Matrix multiplication for two floating point matrices 3x3 and 3x1: C[1][3] = A[3][3] * B[3][1] The implementation is optimized for ESP32 chip.

Return

  • ESP_OK on success

  • One of the error codes from DSP library

Parameters
  • [in] A: input matrix A[3][3]

  • [in] B: input matrix/vector B[3][1]

  • C: result matrix/vector C[3][3]

esp_err_t dspm_mult_3x3x3_f32_ae32(const float *A, const float *B, float *C)

Matrix multiplication A[3x3]xB[3x3].

Matrix multiplication for two square 3x3 floating point matrices: C[3][3] = A[3][3] * B[3][3] The implementation is optimized for ESP32 chip.

Return

  • ESP_OK on success

  • One of the error codes from DSP library

Parameters
  • [in] A: input matrix A[3][3]

  • [in] B: input matrix B[3][3]

  • C: result matrix C[3][3]

esp_err_t dspm_mult_4x4x1_f32_ae32(const float *A, const float *B, float *C)

Matrix multiplication A[4x4]xB[4x1].

Matrix multiplication for two floating point matrices 4x4 and 4x1: C[1][4] = A[4][4] * B[4][1] The implementation is optimized for ESP32 chip.

Return

  • ESP_OK on success

  • One of the error codes from DSP library

Parameters
  • [in] A: input matrix A[4][4]

  • [in] B: input matrix/vector B[4][1]

  • C: result matrix/vector C[4][4]

esp_err_t dspm_mult_4x4x4_f32_ae32(const float *A, const float *B, float *C)

Matrix multiplication A[4x4]xB[4x4].

Matrix multiplication for two square 3x3 floating point matrices: C[4][4] = A[4][4] * B[4][4] The implementation is optimized for ESP32 chip.

Return

  • ESP_OK on success

  • One of the error codes from DSP library

Parameters
  • [in] A: input matrix A[4][4]

  • [in] B: input matrix B[4][4]

  • C: result matrix C[4][4]

Macros

dspm_mult_s16
dspm_mult_f32
dspm_mult_3x3x1_f32(A, B, C)
dsps_sub_f32
dsps_add_f32
dspm_mult_4x4x4_f32(A, B, C)
dspm_mult_ex_f32
dspm_mult_3x3x3_f32(A, B, C)
dspm_mult_4x4x1_f32(A, B, C)

Matrix Operations

Classes

class Mat

Matrix.

The Mat class provides basic matrix operations on single-precision floating point values.

Public Functions

Mat(int rows, int cols)

Constructor allocate internal buffer.

Parameters
  • [in] rows: amount of matrix rows

  • [in] cols: amount of matrix columns

Mat(float *data, int rows, int cols)

Constructor use external buffer.

Parameters
  • [in] data: external buffer with row-major matrix data

  • [in] rows: amount of matrix rows

  • [in] cols: amount of matrix columns

Mat(float *data, int rows, int cols, int stride)

Constructor

Parameters
  • [in] data: external buffer with row-major matrix data

  • [in] rows: amount of matrix rows

  • [in] cols: amount of matrix columns

  • [in] stride: col stride

Mat()

Allocate matrix with undefined size.

Mat(const Mat &src)

Make copy of matrix.

if src matrix is sub matrix, only the header is copied if src matrix is matrix, header and data are copied

Parameters
  • [in] src: source matrix

Mat getROI(int startRow, int startCol, int roiRows, int roiCols)

Create a subset of matrix as ROI (Region of Interest)

Return

  • result matrix size roiRows x roiCols

Parameters
  • [in] startRow: start row position of source matrix to get the subset matrix from

  • [in] startCol: start col position of source matrix to get the subset matrix from

  • [in] roiRows: size of row elements of source matrix to get the subset matrix from

  • [in] roiCols: size of col elements of source matrix to get the subset matrix from

Mat getROI(int startRow, int startCol, int roiRows, int roiCols, int stride)

Create a subset of matrix as ROI (Region of Interest)

Return

  • result matrix size roiRows x roiCols

Parameters
  • [in] startRow: start row position of source matrix to get the subset matrix from

  • [in] startCol: start col position of source matrix to get the subset matrix from

  • [in] roiRows: size of row elements of source matrix to get the subset matrix from

  • [in] roiCols: size of col elements of source matrix to get the subset matrix from

  • [in] stride: number of cols + padding between 2 rows

Mat getROI(const Mat::Rect &rect)

Create a subset of matrix as ROI (Region of Interest)

Return

  • result matrix size rect.rectRows x rect.rectCols

Parameters
  • [in] rect: rectangular area of interest

void Copy(const Mat &src, int row_pos, int col_pos)

Make copy of matrix.

Parameters
  • [in] src: source matrix

  • [in] row_pos: start row position of destination matrix

  • [in] col_pos: start col position of destination matrix

void CopyHead(const Mat &src)

copy header of matrix

Make a shallow copy of matrix (no data copy)

Parameters
  • [in] src: source matrix

void PrintHead(void)

print matrix header

Print all information about matrix to the terminal

Parameters
  • [in] src: source matrix

Mat Get(int row_start, int row_size, int col_start, int col_size)

Make copy of matrix.

Return

  • result matrix size row_size x col_size

Parameters
  • [in] row_start: start row position of source matrix to copy

  • [in] row_size: size of wor elements of source matrix to copy

  • [in] col_start: start col position of source matrix to copy

  • [in] col_size: size of wor elements of source matrix to copy

Mat Get(const Mat::Rect &rect)

Make copy of matrix.

Return

  • result matrix size row_size x col_size

Parameters
  • [in] rect: rectangular area of interest

Mat &operator=(const Mat &src)

Copy operator

Return

  • matrix copy

Parameters
  • [in] src: source matrix

float &operator()(int row, int col)

Access to the matrix elements.

Return

  • element of matrix M[row][col]

Parameters
  • [in] row: row position

  • [in] col: column position

const float &operator()(int row, int col) const

Access to the matrix elements.

Return

  • element of matrix M[row][col]

Parameters
  • [in] row: row position

  • [in] col: column position

Mat &operator+=(const Mat &A)

+= operator The operator use DSP optimized implementation of multiplication.

Return

  • result matrix: result += A

Parameters
  • [in] A: source matrix

Mat &operator+=(float C)

+= operator The operator use DSP optimized implementation of multiplication.

Return

  • result matrix: result += C

Parameters
  • [in] C: constant

Mat &operator-=(const Mat &A)

-= operator The operator use DSP optimized implementation of multiplication.

Return

  • result matrix: result -= A

Parameters
  • [in] A: source matrix

Mat &operator-=(float C)

-= operator The operator use DSP optimized implementation of multiplication.

Return

  • result matrix: result -= C

Parameters
  • [in] C: constant

Mat &operator*=(const Mat &A)

*= operator The operator use DSP optimized implementation of multiplication.

Return

  • result matrix: result -= A

Parameters
  • [in] A: source matrix

Mat &operator*=(float C)

+= with constant operator The operator use DSP optimized implementation of multiplication.

Return

  • result matrix: result *= C

Parameters
  • [in] C: constant value

Mat &operator/=(float C)

/= with constant operator The operator use DSP optimized implementation of multiplication.

Return

  • result matrix: result /= C

Parameters
  • [in] C: constant value

Mat &operator/=(const Mat &B)

/= operator

Return

  • result matrix: result[i,j] = result[i,j]/B[i,j]

Parameters
  • [in] B: source matrix

Mat operator^(int C)

^= xor with constant operator The operator use DSP optimized implementation of multiplication.

Return

  • result matrix: result ^= C

Parameters
  • [in] C: constant value

void swapRows(int row1, int row2)

Swap two rows between each other.

Parameters
  • [in] row1: position of first row

  • [in] row2: position of second row

Mat t()

Matrix transpose. Change rows and columns between each other.

Return

  • transposed matrix

Mat block(int startRow, int startCol, int blockRows, int blockCols)

Return part of matrix from defined position (startRow, startCol) as a matrix[blockRows x blockCols].

Return

  • matrix [blockRows]x[blockCols]

Parameters
  • [in] startRow: start row position

  • [in] startCol: start column position

  • [in] blockRows: amount of rows in result matrix

  • [in] blockCols: amount of columns in the result matrix

void normalize(void)

Normalizes the vector, i.e. divides it by its own norm. If it’s matrix, calculate matrix norm

float norm(void)

Return norm of the vector. If it’s matrix, calculate matrix norm

Return

  • matrix norm

void clear(void)

The method fill 0 to the matrix structure.

Mat gaussianEliminate()

Gaussian Elimination.

Gaussian Elimination of matrix

Return

  • result matrix

Mat rowReduceFromGaussian()

Row reduction for Gaussian elimination

Return

  • result matrix

Mat inverse()

Find the inverse matrix

Return

  • inverse matrix

Mat pinv()

Find pseudo inverse matrix

Return

  • inverse matrix

float det(int n)

Find determinant

Return

  • determinant value

Parameters
  • [in] n: element number in first row

Public Members

int rows

Amount of rows

int cols

Amount of columns

int stride

Stride = (number of elements in a row) + padding

int padding

Padding between 2 rows

float *data

Buffer with matrix data

int length

Total amount of data in data array

bool ext_buff

Flag indicates that matrix use external buffer

bool sub_matrix

Flag indicates that matrix is a subset of another matrix

Public Static Functions

static Mat eye(int size)

Create identity matrix. Create a square matrix and fill diagonal with 1.

Return

  • matrix [N]x[N] with 1 in diagonal

Parameters
  • [in] size: matrix size

static Mat ones(int size)

Create matrix with all elements 1. Create a square matrix and fill all elements with 1.

Return

  • matrix [N]x[N] with 1 in all elements

Parameters
  • [in] size: matrix size

static Mat ones(int rows, int cols)

Create matrix with all elements 1. Create a matrix and fill all elements with 1.

Return

  • matrix [N]x[N] with 1 in all elements

Parameters
  • [in] rows: matrix rows

  • [in] cols: matrix cols

static Mat solve(Mat A, Mat b)

Solve the matrix.

Solve matrix. Find roots for the matrix A*x = b

Return

  • matrix [N]x[1] with roots

Parameters
  • [in] A: matrix [N]x[N] with input coefficients

  • [in] b: vector [N]x[1] with result values

static Mat bandSolve(Mat A, Mat b, int k)

Band solve the matrix.

Solve band matrix. Find roots for the matrix A*x = b with bandwidth k.

Return

  • matrix [N]x[1] with roots

Parameters
  • [in] A: matrix [N]x[N] with input coefficients

  • [in] b: vector [N]x[1] with result values

  • [in] k: upper bandwidth value

static Mat roots(Mat A, Mat y)

Solve the matrix.

Different way to solve the matrix. Find roots for the matrix A*x = y

Return

  • matrix [N]x[1] with roots

Parameters
  • [in] A: matrix [N]x[N] with input coefficients

  • [in] y: vector [N]x[1] with result values

static float dotProduct(Mat A, Mat B)

Dotproduct of two vectors.

The method returns dotproduct of two vectors

Return

  • dotproduct value

Parameters
  • [in] A: Input vector A Nx1

  • [in] B: Input vector B Nx1

static Mat augment(Mat A, Mat B)

Augmented matrices.

Augmented matrices

Return

  • Augmented matrix Mx(N+K)

Parameters
  • [in] A: Input vector A MxN

  • [in] B: Input vector B MxK

Public Static Attributes

float abs_tol

Max acceptable absolute tolerance

struct Rect

Rectangular area.

The Rect is used for creating regions of interest ROI(s). The ROI is then used as a sub-matrix

Public Functions

Rect(int x = 0, int y = 0, int width = 0, int height = 0)

Constructor with initialization to 0.

Parameters
  • [in] x: x starting position (start col) of the rectangular area

  • [in] y: y starting position (start row) of the rectangular area

  • [in] width: width (number of cols) of the rectangular area

  • [in] height: height (number of rows) of the rectangular area

void resizeRect(int x, int y, int width, int height)

Resize rect area.

Parameters
  • [in] x: x starting position (start col) of the new rectangular area

  • [in] y: y starting position (start row) of the new rectangular area

  • [in] width: width (number of cols) of the new rectangular area

  • [in] height: height (number of rows) of the new rectangular area

int areaRect(void)

Get amount of elements in the rect area.

Public Members

int x

x starting position (start col) of the rectangular area

int y

y starting position (start row) of the rectangular area

int width

width (number of cols) of the rectangular area

int height

height (number of rows) of the rectangular area

Miscellaneous

Various common functions used by other modules are included in this module.

Common APIs

Functions

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 and could be compiled and run on any platform

Return

  • true if x is power of two

  • false if no

int dsp_power_of_two(int x)

Power of two The function return power of 2 for values 2^N. The implementation use ANSI C and could be compiled and run on any platform.

Return

  • power of two

esp_err_t tie_log(int n_regs, ...)

Logginng for esp32s3 TIE core Registers covered q0 to q7, ACCX and SAR_BYTE.

Return

ESP_OK

Parameters
  • n_regs: number of registers to be logged at once

  • ...: register codes 0, 1, 2, 3, 4, 5, 6, 7, ‘a’, ‘s’

Macros

dsp_get_cpu_cycle_count