### Dot Product Calculation in esp-dsp Source: https://docs.espressif.com/projects/esp-dsp/en/latest/esp32/esp-dsp-examples Demonstrates the usage of the `dsps_dotprod_f32` function for calculating the dot product of two arrays using the esp-dsp library. The example includes initializing input arrays, performing the calculation, and comparing results while measuring execution time in cycles. Requires the esp-dsp library. ```c #include "esp_dsp.h" void app_main(void) { // Initialize input arrays float array1[1024]; float array2[1024]; // ... (fill array1 and array2 with data) // Calculate dot product of two arrays float dot_product_result; // dsps_dotprod_f32(array1, array2, &dot_product_result, 1024); // Compare results and calculate execution time in cycles (implementation specific) } ``` -------------------------------- ### FFT Functionality in esp-dsp Source: https://docs.espressif.com/projects/esp-dsp/en/latest/esp32/esp-dsp-examples Illustrates the use of FFT functionality from the esp-dsp library. The example involves initializing signals, applying a window function, performing FFT on complex samples, applying bit reversal, splitting the complex spectrum into real signals, and displaying results and execution time. Requires the esp-dsp library. ```c #include "esp_dsp.h" void app_main(void) { // Initialize the library esp_dsp_init(); // Initialize input signals with 1024 samples float signal_0db[1024]; float signal_neg20db[1024]; // ... (fill signals with data) // Combine two signals as one complex input signal and apply window to input signals pair complex_float_t complex_input[1024]; float window[1024]; // ... (convert signals to complex_float_t and apply window using dsps_mul_f32) // Calculate FFT for 1024 complex samples complex_float_t fft_output[1024]; // dsps_fft_init_f32(NULL, 1024); // dsps_fft_f32(complex_input, fft_output); // Apply bit reverse operation for output complex vector // dsps_bit_rev_f32(fft_output, fft_output, 1024); // Split one complex FFT output spectrum to two real signal spectrums (example) float real_spectrum[1024]; float imag_spectrum[1024]; // ... (split complex_float_t into real and imaginary parts) // Show results on the plots and execution time (implementation specific) } ``` -------------------------------- ### FIR Filter Functionality in esp-dsp Source: https://docs.espressif.com/projects/esp-dsp/en/latest/esp32/esp-dsp-examples Demonstrates the use of FIR (Finite Impulse Response) filters with the esp-dsp library. The example involves initializing the FFT library (often a dependency for efficient FIR), initializing an input signal, and then showing the input and filtered signals. Requires the esp-dsp library. ```c #include "esp_dsp.h" void app_main(void) { // Initialize the FFT library (often a dependency for FIR implementation) // dsps_fft_init_f32(NULL, 1024); // Example initialization // Initialize input signal float input_signal[1024]; // ... (fill input_signal with data) // Show input signal (implementation specific) // Show filtered signal float fir_coefficients[256]; // Example: FIR filter coefficients // ... (load FIR coefficients) float output_signal[1024]; // dsps_fir_f32(input_signal, output_signal, fir_coefficients, 1024, 256); } ``` -------------------------------- ### FFT for Real Signals (Radix-2 and Radix-4) in esp-dsp Source: https://docs.espressif.com/projects/esp-dsp/en/latest/esp32/esp-dsp-examples Showcases FFT functionality for real input signals using both Radix-2 and Radix-4 algorithms from the esp-dsp library. The example involves signal initialization, FFT calculation, bit reversal, spectrum splitting, plotting, and measuring execution time. Requires the esp-dsp library. ```c #include "esp_dsp.h" void app_main(void) { // Initialize the library esp_dsp_init(); // Initialize input signals with 1024 samples float signal_0db[1024]; float signal_neg20db[1024]; // ... (fill signals with data) // Calculate FFT Radix-2 for 1024 complex samples complex_float_t complex_input_radix2[1024]; // ... (convert signals to complex_float_t) complex_float_t fft_output_radix2[1024]; // dsps_fft_init_f32(NULL, 1024); // dsps_fft_f32(complex_input_radix2, fft_output_radix2); // dsps_bit_rev_f32(fft_output_radix2, fft_output_radix2, 1024); // Calculate FFT Radix-4 for 1024 complex samples complex_float_t complex_input_radix4[1024]; // ... (convert signals to complex_float_t) complex_float_t fft_output_radix4[1024]; // dsps_fft_init_f32(NULL, 1024); // dsps_fft_f32(complex_input_radix4, fft_output_radix4); // dsps_bit_rev_f32(fft_output_radix4, fft_output_radix4, 1024); // Split one complex FFT output spectrum to two real signal spectrums (example) float real_spectrum_radix2[1024]; float imag_spectrum_radix2[1024]; // ... (split complex_float_t into real and imaginary parts for radix2) float real_spectrum_radix4[1024]; float imag_spectrum_radix4[1024]; // ... (split complex_float_t into real and imaginary parts for radix4) // Show results on the plots and execution time of FFTs (implementation specific) } ``` -------------------------------- ### IIR Filter Functionality in esp-dsp Source: https://docs.espressif.com/projects/esp-dsp/en/latest/esp32/esp-dsp-examples Demonstrates the usage of IIR filters, specifically LPF (Low Pass Filter) with Q factors 1 and 10, using the esp-dsp library. The example covers calculating filter coefficients, filtering a delta function input signal, displaying impulse and frequency responses, and measuring performance. Requires the esp-dsp library. ```c #include "esp_dsp.h" void app_main(void) { // Initialize the library esp_dsp_init(); // Initialize input signal float input_signal[1024]; // ... (fill input_signal with data, e.g., a delta function) // Show LPF filter with Q factor 1 float coeffs_lpf_q1[5]; // Example: b0, b1, b2, a1, a2 // dsps_iir_lpf_coeffs(1000, 1.0, 1, coeffs_lpf_q1); // Example parameters: sample_rate, cutoff_freq, q_factor float output_signal_lpf_q1[1024]; // dsps_iir_f32(input_signal, output_signal_lpf_q1, coeffs_lpf_q1, 1024); // Shows impulse response on the plot (implementation specific) // Shows frequency response on the plot (implementation specific) // Calculate execution performance (implementation specific) // The same for LPF filter with Q factor 10 float coeffs_lpf_q10[5]; // dsps_iir_lpf_coeffs(1000, 1.0, 10, coeffs_lpf_q10); float output_signal_lpf_q10[1024]; // dsps_iir_f32(input_signal, output_signal_lpf_q10, coeffs_lpf_q10, 1024); } ``` -------------------------------- ### Window and FFT Functionality in esp-dsp Source: https://docs.espressif.com/projects/esp-dsp/en/latest/esp32/esp-dsp-examples Demonstrates the combined use of window functions and FFT from the esp-dsp library. The process includes signal initialization, window application, FFT calculation on complex samples, bit reversal, splitting the spectrum, and visualizing the results. Requires the esp-dsp library. ```c #include "esp_dsp.h" void app_main(void) { // Initialize the library esp_dsp_init(); // Initialize input signals with 1024 samples float input_signal[1024]; // ... (fill input_signal with data) // Apply window to input signal float window[1024]; // ... (fill window with data) // dsps_mul_f32(input_signal, window, input_signal, 1024); // Calculate FFT for 1024 complex samples complex_float_t complex_input[1024]; // ... (convert input_signal to complex_float_t) complex_float_t fft_output[1024]; // dsps_fft_init_f32(NULL, 1024); // dsps_fft_f32(complex_input, fft_output); // Apply bit reverse operation for output complex vector // dsps_bit_rev_f32(fft_output, fft_output, 1024); // Split one complex FFT output spectrum to two real signal spectrums (example) float real_spectrum[1024]; float imag_spectrum[1024]; // ... (split complex_float_t into real and imaginary parts) // Show results on the plots (implementation specific) } ``` -------------------------------- ### Basic Math Operations in esp-dsp Source: https://docs.espressif.com/projects/esp-dsp/en/latest/esp32/esp-dsp-examples Demonstrates basic vector math operations using the esp-dsp library. It covers signal initialization, applying window functions (using both C loops and dsps_mul_f32/dsps_mulc_f32), FFT calculations, and plotting results. Requires the esp-dsp library. ```c #include "esp_dsp.h" void app_main(void) { // Initialize the library esp_dsp_init(); // Initialize input signals with 1024 samples float input_signal[1024]; // ... (fill input_signal with data) // Apply window to input signal by standard C loop (example) float window[1024]; // ... (fill window with data) for (int i = 0; i < 1024; i++) { input_signal[i] *= window[i]; } // Calculate FFT for 1024 complex samples (example) complex_float_t fft_input[1024]; // ... (convert input_signal to complex_float_t) complex_float_t fft_output[1024]; // dsps_fft_init_f32(NULL, 1024); // dsps_fft_f32(fft_input, fft_output); // Apply window to input signal by basic math functions dsps_mul_f32 and dsps_mulc_f32 float input_signal_2[1024]; // ... (fill input_signal_2 with data) float window_2[1024]; // ... (fill window_2 with data) // dsps_mul_f32(input_signal_2, window_2, input_signal_2, 1024); // Calculate FFT for 1024 complex samples (example) complex_float_t fft_input_2[1024]; // ... (convert input_signal_2 to complex_float_t) complex_float_t fft_output_2[1024]; // dsps_fft_init_f32(NULL, 1024); // dsps_fft_f32(fft_input_2, fft_output_2); // Show results on the plots (implementation specific) } ``` -------------------------------- ### Kalman Filter (EKF) for Attitude Estimation in esp-dsp Source: https://docs.espressif.com/projects/esp-dsp/en/latest/esp32/esp-dsp-examples Emulates a system with IMU sensors to demonstrate the Extended Kalman Filter (EKF) for estimating gyroscope errors and system attitude. It utilizes the esp-dsp library's matrix and vector operations. Requires the esp-dsp library and careful implementation of sensor fusion and state vector management. ```c #include "esp_dsp.h" #include "esp_log.h" // Define state vector and covariance matrix dimensions #define STATE_VECTOR_SIZE 13 #define COVARIANCE_MATRIX_SIZE 13 void app_main(void) { // Initialize the library esp_dsp_init(); // State vector X (13 values for gyroscope errors and attitude) float state_vector[STATE_VECTOR_SIZE]; // Covariance matrix P (13x13) float covariance_matrix[COVARIANCE_MATRIX_SIZE * COVARIANCE_MATRIX_SIZE]; // Initialize state vector and covariance matrix (example) // In a real system, these should be loaded or properly initialized after calibration. // Emulated sensor values (IMU data) float gyro_data[3]; float accel_data[3]; float mag_data[3]; // ... (get sensor data) // Calculate system attitude and estimate gyroscope errors using EKF // This involves several steps: // 1. Prediction step: Update state vector and covariance matrix based on motion model. // - Use matrix operations (dsps_mat_mul, dsps_mat_add) from esp-dsp. // 2. Update step: Correct state vector and covariance matrix using sensor measurements. // - Use matrix operations and vector operations (dsps_vec_...). // Example (conceptual, actual EKF implementation is complex): // dsps_matrix_t X = { .data = state_vector, .rows = STATE_VECTOR_SIZE, .cols = 1 }; // dsps_matrix_t P = { .data = covariance_matrix, .rows = COVARIANCE_MATRIX_SIZE, .cols = COVARIANCE_MATRIX_SIZE }; // ... (perform prediction and update steps using esp-dsp matrix/vector functions) // In a real system, a calibration phase should be implemented. // The state vector X and covariance matrix P should be saved and restored. ESP_LOGI("KALMAN", "EKF example executed."); } ``` -------------------------------- ### Mat Class Region of Interest (ROI) Methods Source: https://docs.espressif.com/projects/esp-dsp/en/latest/esp32/esp-dsp-apis These methods allow for the creation of sub-matrices (Regions of Interest) from an existing matrix, specifying the starting row and column, and the dimensions of the ROI. ```APIDOC ## Mat Class Region of Interest (ROI) Methods ### Description Methods to extract a sub-matrix (Region of Interest) from an existing matrix, defining the dimensions and starting position of the desired subset. ### Methods - `Mat getROI(int _startRow_, int _startCol_, int _roiRows_, int _roiCols_)` - Creates a subset of the matrix as a Region of Interest (ROI). - **Return**: - `Mat` - Resulting matrix with dimensions `roiRows` x `roiCols`. - **Parameters**: - `[in] startRow` (int) - Start row position of the source matrix. - `[in] startCol` (int) - Start column position of the source matrix. - `[in] roiRows` (int) - Number of rows in the ROI. - `[in] roiCols` (int) - Number of columns in the ROI. - `Mat getROI(int _startRow_, int _startCol_, int _roiRows_, int _roiCols_, int _stride_)` - Creates a subset of the matrix as a Region of Interest (ROI) with a specified stride. - **Return**: - `Mat` - Resulting matrix with dimensions `roiRows` x `roiCols`. - **Parameters**: - `[in] startRow` (int) - Start row position of the source matrix. - `[in] startCol` (int) - Start column position of the source matrix. - `[in] roiRows` (int) - Number of rows in the ROI. - `[in] roiCols` (int) - Number of columns in the ROI. - `[in] stride` (int) - Number of columns plus padding between two rows. - `Mat getROI(const Mat::Rect &_rect_)` - Creates a subset of the matrix as a Region of Interest (ROI) using a `Rect` structure. - **Return**: - `Mat` - Resulting matrix with dimensions `rect.rectRows` x `rect.rectCols`. - **Parameters**: - `[in] rect` (const Mat::Rect&) - Rectangular area of interest. ``` -------------------------------- ### Initialize 16-bit Fixed Point Decimation FIR Filter (ANSI C) Source: https://docs.espressif.com/projects/esp-dsp/en/latest/esp32/esp-dsp-apis Initializes a structure for a 16-bit signed fixed-point FIR filter with decimation using ANSI C. This function is compatible with any platform. It requires preallocated memory for the filter structure, coefficients, delay line, coefficient length, decimation factor, start position, and shift. ```c 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_) ``` -------------------------------- ### Reproduce ESP-DSP Benchmarks with test_dsp.c Source: https://docs.espressif.com/projects/esp-dsp/en/latest/esp32/esp-dsp-benchmarks This C code snippet indicates the location of test cases used to reproduce the benchmark results for the ESP-DSP library. It serves as a reference for users who want to verify or re-run the performance tests. ```c #include "test_dsp.c" ``` -------------------------------- ### Get Complex Generator Phase Source: https://docs.espressif.com/projects/esp-dsp/en/latest/esp32/esp-dsp-apis Retrieves the current phase of the complex generator. This function can be used after the generator has been initialized. ```APIDOC ## dsps_cplx_gen_phase_get ### Description Gets the phase of the complex generator. This function can be used after the `cplx_gen` structure was initialized by the `dsps_cplx_gen_init(…) ` function. ### Method ESP_API ### Endpoint N/A (Function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **_cplx_gen_** (cplx_sig_t*) - Pointer to the complex signal generator structure ### Request Example ```c // Assuming cplx_gen is already initialized float current_phase = dsps_cplx_gen_phase_get(cplx_gen); ``` ### Response #### Success Response - Returns the current phase of the signal generator #### Response Example ```c // 0.5f ``` ``` -------------------------------- ### Get Phase from Complex Generator (C) Source: https://docs.espressif.com/projects/esp-dsp/en/latest/esp32/esp-dsp-apis Retrieves the current initial phase of an initialized complex signal generator. ```c float dsps_cplx_gen_phase_get(cplx_sig_t *_cplx_gen_) ``` -------------------------------- ### Get Frequency from Complex Generator (C) Source: https://docs.espressif.com/projects/esp-dsp/en/latest/esp32/esp-dsp-apis Retrieves the current output frequency of an initialized complex signal generator. ```c float dsps_cplx_gen_freq_get(cplx_sig_t *_cplx_gen_) ``` -------------------------------- ### Matrix Creation Utilities Source: https://docs.espressif.com/projects/esp-dsp/en/latest/esp32/esp-dsp-apis Static methods for creating matrices with specific initial values, such as identity matrices or matrices filled with ones. ```APIDOC ## eye ### Description Creates an identity matrix of a specified square size. ### Method `static Mat eye(int size)` ### Parameters * `size` (int) - Required - The dimension of the square identity matrix. ### Return * `Mat` - An identity matrix of size [size]x[size]. ## ones (size) ### Description Creates a square matrix of a specified size filled with ones. ### Method `static Mat ones(int size)` ### Parameters * `size` (int) - Required - The dimension of the square matrix. ### Return * `Mat` - A matrix of size [size]x[size] filled with ones. ## ones (rows, cols) ### Description Creates a matrix with specified dimensions filled with ones. ### Method `static Mat ones(int rows, int cols)` ### Parameters * `rows` (int) - Required - The number of rows for the matrix. * `cols` (int) - Required - The number of columns for the matrix. ### Return * `Mat` - A matrix of size [rows]x[cols] filled with ones. ``` -------------------------------- ### Dot-product API Reference Source: https://docs.espressif.com/projects/esp-dsp/en/latest/esp32/esp-dsp-apis This section details the Dot-product functions within the Espressif DSP Library, including their descriptions, parameters, and return values. ```APIDOC ## Dot-product API Reference ### Description Provides functions for calculating the dot product of two vectors. Supports 16-bit signed integers and 32-bit floating-point numbers, with different optimizations for various platforms. ### Header File `modules/dotprod/include/dsps_dotprod.h` ### Functions #### `dsps_dotprod_s16_ansi` ##### Description Calculates the dot product of two signed 16-bit integer vectors. The result is right-shifted by `shift` bits. ##### Method (Not applicable - C function) ##### Endpoint (Not applicable - C function) ##### Parameters * `src1` (const int16_t*) - Input source array 1 * `src2` (const int16_t*) - Input source array 2 * `dest` (int16_t*) - Pointer to store the dot product result * `len` (int) - Length of the input arrays * `shift` (int8_t) - Number of bits to right-shift the result ##### Return * `ESP_OK` on success * One of the error codes from DSP library ##### Request Example (Not applicable - C function) ##### Response Example (Not applicable - C function) #### `dsps_dotprod_s16_ae32` ##### Description Optimized version of `dsps_dotprod_s16_ansi` for the ESP32 chip. ##### Method (Not applicable - C function) ##### Endpoint (Not applicable - C function) ##### Parameters * `src1` (const int16_t*) - Input source array 1 * `src2` (const int16_t*) - Input source array 2 * `dest` (int16_t*) - Pointer to store the dot product result * `len` (int) - Length of the input arrays * `shift` (int8_t) - Number of bits to right-shift the result ##### Return * `ESP_OK` on success * One of the error codes from DSP library #### `dsps_dotprod_s16_arp4` ##### Description ARM-specific optimized version of `dsps_dotprod_s16_ansi`. ##### Method (Not applicable - C function) ##### Endpoint (Not applicable - C function) ##### Parameters * `src1` (const int16_t*) - Input source array 1 * `src2` (const int16_t*) - Input source array 2 * `dest` (int16_t*) - Pointer to store the dot product result * `len` (int) - Length of the input arrays * `shift` (int8_t) - Number of bits to right-shift the result ##### Return * `ESP_OK` on success * One of the error codes from DSP library #### `dsps_dotprod_f32_ansi` ##### Description Calculates the dot product of two 32-bit floating-point vectors. ##### Method (Not applicable - C function) ##### Endpoint (Not applicable - C function) ##### Parameters * `src1` (const float*) - Input source array 1 * `src2` (const float*) - Input source array 2 * `dest` (float*) - Pointer to store the dot product result * `len` (int) - Length of the input arrays ##### Return * `ESP_OK` on success * One of the error codes from DSP library #### `dsps_dotprod_f32_ae32` ##### Description Optimized version of `dsps_dotprod_f32_ansi` for the ESP32 chip. ##### Method (Not applicable - C function) ##### Endpoint (Not applicable - C function) ##### Parameters * `src1` (const float*) - Input source array 1 * `src2` (const float*) - Input source array 2 * `dest` (float*) - Pointer to store the dot product result * `len` (int) - Length of the input arrays ##### Return * `ESP_OK` on success * One of the error codes from DSP library #### `dsps_dotprod_f32_aes3` ##### Description Optimized version of `dsps_dotprod_f32_ansi` for AES3. ##### Method (Not applicable - C function) ##### Endpoint (Not applicable - C function) ##### Parameters * `src1` (const float*) - Input source array 1 * `src2` (const float*) - Input source array 2 * `dest` (float*) - Pointer to store the dot product result * `len` (int) - Length of the input arrays ##### Return * `ESP_OK` on success * One of the error codes from DSP library #### `dsps_dotprod_f32_arp4` ##### Description ARM-specific optimized version of `dsps_dotprod_f32_ansi`. ##### Method (Not applicable - C function) ##### Endpoint (Not applicable - C function) ##### Parameters * `src1` (const float*) - Input source array 1 * `src2` (const float*) - Input source array 2 * `dest` (float*) - Pointer to store the dot product result * `len` (int) - Length of the input arrays ##### Return * `ESP_OK` on success * One of the error codes from DSP library #### `dsps_dotprode_f32_ansi` ##### Description Calculates the dot product of two 32-bit floating-point vectors with specified steps between elements. ##### Method (Not applicable - C function) ##### Endpoint (Not applicable - C function) ##### Parameters * `src1` (const float*) - Input source array 1 * `src2` (const float*) - Input source array 2 * `dest` (float*) - Pointer to store the dot product result * `len` (int) - Length of the input arrays * `step1` (int) - Step over elements in the first array * `step2` (int) - Step over elements in the second array ##### Return * `ESP_OK` on success * One of the error codes from DSP library #### `dsps_dotprode_f32_ae32` ##### Description Optimized version of `dsps_dotprode_f32_ansi` for the ESP32 chip. ##### Method (Not applicable - C function) ##### Endpoint (Not applicable - C function) ##### Parameters * `src1` (const float*) - Input source array 1 * `src2` (const float*) - Input source array 2 * `dest` (float*) - Pointer to store the dot product result * `len` (int) - Length of the input arrays * `step1` (int) - Step over elements in the first array * `step2` (int) - Step over elements in the second array ##### Return * `ESP_OK` on success * One of the error codes from DSP library #### `dsps_dotprode_f32_arp4` ##### Description ARM-specific optimized version of `dsps_dotprode_f32_ansi`. ##### Method (Not applicable - C function) ##### Endpoint (Not applicable - C function) ##### Parameters * `src1` (const float*) - Input source array 1 * `src2` (const float*) - Input source array 2 * `dest` (float*) - Pointer to store the dot product result * `len` (int) - Length of the input arrays * `step1` (int) - Step over elements in the first array * `step2` (int) - Step over elements in the second array ##### Return * `ESP_OK` on success * One of the error codes from DSP library ### Macros * `dsps_dotprod_s16` * `dsps_dotprod_f32` * `dsps_dotprode_f32 ### Header File `modules/dotprod/include/dspi_dotprod.h` ``` -------------------------------- ### Get Complex Generator Frequency Source: https://docs.espressif.com/projects/esp-dsp/en/latest/esp32/esp-dsp-apis Retrieves the current output frequency of the complex generator. This function can be used after the generator has been initialized. ```APIDOC ## dsps_cplx_gen_freq_get ### Description Gets the output frequency of the complex generator. This function can be used after the `cplx_gen` structure was initialized by the `dsps_cplx_gen_init(…) ` function. ### Method ESP_API ### Endpoint N/A (Function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **_cplx_gen_** (cplx_sig_t*) - Pointer to the complex signal generator structure ### Request Example ```c // Assuming cplx_gen is already initialized float current_freq = dsps_cplx_gen_freq_get(cplx_gen); ``` ### Response #### Success Response - Returns the current frequency of the signal generator #### Response Example ```c // 0.25f ``` ``` -------------------------------- ### Extract Matrix Block Source: https://docs.espressif.com/projects/esp-dsp/en/latest/esp32/esp-dsp-apis Extracts a sub-matrix (block) from the original matrix, defined by a starting row and column, and specified dimensions. ```C++ 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]; } ``` -------------------------------- ### Get CPU Cycle Count Source: https://docs.espressif.com/projects/esp-dsp/en/latest/esp32/esp-dsp-apis Retrieves the current CPU cycle count. This macro is useful for performance profiling and timing critical code sections. ```c #define dsp_get_cpu_cycle_count ``` -------------------------------- ### Utility Functions Source: https://docs.espressif.com/projects/esp-dsp/en/latest/esp32/esp-dsp-apis Common utility functions for DSP tasks. ```APIDOC ## GET /dsp_common/is_power_of_two ### Description Checks if a given integer is a power of two. This function uses ANSI C and is portable across different platforms. ### Method GET ### Endpoint /dsp_common/is_power_of_two ### Parameters #### Path Parameters None #### Query Parameters - **x** (int) - Required - The integer to check. ### Request Example ``` GET /dsp_common/is_power_of_two?x=16 ``` ### Response #### Success Response (200) - **is_power_of_two** (boolean) - Returns true if x is a power of two, false otherwise. #### Response Example ```json { "is_power_of_two": true } ``` ``` ```APIDOC ## GET /dsp_common/power_of_two ### Description Calculates the power of two for a given value. This function returns 2 raised to the power of N, where N is derived from the input value. It uses ANSI C for broad compatibility. ### Method GET ### Endpoint /dsp_common/power_of_two ### Parameters #### Path Parameters None #### Query Parameters - **x** (int) - Required - The input value. ### Request Example ``` GET /dsp_common/power_of_two?x=4 ``` ### Response #### Success Response (200) - **power_of_two** (int) - The calculated power of two (2^N). #### Response Example ```json { "power_of_two": 16 } ``` ``` ```APIDOC ## POST /tie_log ### Description Logs registers for the ESP32S3 TIE core. This function allows logging of specified registers (q0-q7, ACCX, SAR_BYTE) for debugging purposes. ### Method POST ### Endpoint /tie_log ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **n_regs** (int) - Required - The number of registers to log. - **registers** (array of codes) - Required - A list of register codes to log (e.g., 0, 1, 'a', 's'). ### Request Example ```json { "n_regs": 3, "registers": [0, 1, "a"] } ``` ### Response #### Success Response (200) - **status** (esp_err_t) - Indicates success (ESP_OK). #### Response Example ```json { "status": "ESP_OK" } ``` ``` -------------------------------- ### Mat Class Constructors Source: https://docs.espressif.com/projects/esp-dsp/en/latest/esp32/esp-dsp-apis This section covers the different ways to construct a Mat object, including allocating internal buffers, using external buffers, and creating copies of existing matrices. ```APIDOC ## Mat Class Constructors ### Description Constructors for the Mat class allow for the creation of matrices with specified dimensions, using either internal or external data buffers, or by copying existing matrices. ### Methods - `Mat(int _rows_, int _cols_)` - Constructor to allocate an internal buffer for the matrix. - **Parameters**: - `[in] rows` (int) - Amount of matrix rows. - `[in] cols` (int) - Amount of matrix columns. - `Mat(float *_data_, int _rows_, int _cols_)` - Constructor to use an external buffer for the matrix data. - **Parameters**: - `[in] data` (float*) - External buffer with row-major matrix data. - `[in] rows` (int) - Amount of matrix rows. - `[in] cols` (int) - Amount of matrix columns. - `Mat(float *_data_, int _rows_, int _cols_, int _stride_)` - Constructor that uses an external buffer with a specified column stride. - **Parameters**: - `[in] data` (float*) - External buffer with row-major matrix data. - `[in] rows` (int) - Amount of matrix rows. - `[in] cols` (int) - Amount of matrix columns. - `[in] stride` (int) - Column stride. - `Mat()` - Allocates a matrix with an undefined size. - `Mat(const Mat &_src_)` - Creates a copy of a source matrix. If the source matrix is a sub-matrix, only the header is copied. If it's a full matrix, both header and data are copied. - **Parameters**: - `[in] src` (const Mat&) - Source matrix. ``` -------------------------------- ### Mat Class Region of Interest (ROI) Functions (C++) Source: https://docs.espressif.com/projects/esp-dsp/en/latest/esp32/esp-dsp-apis Enables the creation of sub-matrices (Regions of Interest) from an existing matrix. Supports defining ROI by start row/column and dimensions, with or without specifying a stride. ```C++ Mat getROI(int startRow, int startCol, int roiRows, int roiCols); Mat getROI(int startRow, int startCol, int roiRows, int roiCols, int stride); Mat getROI(const Mat::Rect &rect); ``` -------------------------------- ### Nuttall Window Generation Source: https://docs.espressif.com/projects/esp-dsp/en/latest/esp32/esp-dsp-apis Generates a Nuttall window. This function populates a provided buffer with the window coefficients. ```APIDOC ## void dsps_wind_nuttall_f32(float *_window_ , int _len_) ### Description Generates the Nuttall window. This function calculates the coefficients for the Nuttall window and stores them in the provided buffer. ### Method void ### Endpoint N/A (This is a function call, not an API endpoint) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **_window_** (float*) - Required - Pointer to the buffer where the window array will be stored. * **_len_** (int) - Required - The desired length of the window array. ### Request Example ```c float window_buffer[1024]; int window_length = 1024; dsps_wind_nuttall_f32(window_buffer, window_length); ``` ### Response #### Success Response (200) N/A (This function modifies the provided buffer in-place) #### Response Example N/A ``` -------------------------------- ### ESP32 ESP-DSP Complex to Real Conversion (ANSI C) Source: https://docs.espressif.com/projects/esp-dsp/en/latest/esp32/esp-dsp-apis Converts the result of a complex FFT for real input to a real array using ANSI C. This function is used when the FFT process starts with real data. ```c esp_err_t dsps_cplx2real256_fc32_ansi(float *_data_) ``` -------------------------------- ### Mat Class Constructors (C++) Source: https://docs.espressif.com/projects/esp-dsp/en/latest/esp32/esp-dsp-apis Provides constructors for the Mat class to initialize matrices. Supports allocation of internal buffers, using external data buffers with or without strides, default allocation, and copying existing matrices. ```C++ Mat(int rows, int cols); Mat(float *data, int rows, int cols); Mat(float *data, int rows, int cols, int stride); Mat(); Mat(const Mat &src); ``` -------------------------------- ### Generate Nuttall Window (C) Source: https://docs.espressif.com/projects/esp-dsp/en/latest/esp32/esp-dsp-apis Generates a Nuttall window. The function requires a buffer to store the window array and the length of the window. ```c void dsps_wind_nuttall_f32(float *_window_ , int _len_) ``` -------------------------------- ### Blackman-Nuttall Window Generation Source: https://docs.espressif.com/projects/esp-dsp/en/latest/esp32/esp-dsp-apis Generates a Blackman-Nuttall window. This function populates a provided buffer with the window coefficients. ```APIDOC ## void dsps_wind_blackman_nuttall_f32(float *_window_ , int _len_) ### Description Generates the Blackman-Nuttall window. This function calculates the coefficients for the Blackman-Nuttall window and stores them in the provided buffer. ### Method void ### Endpoint N/A (This is a function call, not an API endpoint) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **_window_** (float*) - Required - Pointer to the buffer where the window array will be stored. * **_len_** (int) - Required - The desired length of the window array. ### Request Example ```c float window_buffer[512]; int window_length = 512; dsps_wind_blackman_nuttall_f32(window_buffer, window_length); ``` ### Response #### Success Response (200) N/A (This function modifies the provided buffer in-place) #### Response Example N/A ``` -------------------------------- ### ESP-DSP Dot Product Benchmarks Source: https://docs.espressif.com/projects/esp-dsp/en/latest/esp32/esp-dsp-benchmarks Benchmarks for `dsps_dotprod_f32`, `dsps_dotprode_f32`, and `dsps_dotprod_s16` functions, measuring CPU cycles for N=256 points with different optimizations and platforms. ```text dsps_dotprod_f32 for N=256 points | 1047 | 432 | 1319 | 1311 | 1563 | 1047 | 432 | 1320 | 4117 | 2336 dsps_dotprode_f32 for N=256 points with step 1 | 1307 | 1307 | 1314 | 2581 | 1819 | 1308 | 1309 | 1317 | 3609 | 2087 dsps_dotprod_s16 for N=256 points | 437 | 307 | 208 | 3635 | 3385 | 437 | 307 | 202 | 6708 | 4170 ``` -------------------------------- ### Window Functions Source: https://docs.espressif.com/projects/esp-dsp/en/latest/esp32/esp-dsp-apis Provides implementations for common window functions used in signal processing. ```APIDOC ## dsps_wind_hann_f32 ### Description Generates a Hann window. ### Method void ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **_window_** (float *) - Buffer to store the generated window array. - **_len_** (int) - The desired length of the window array. ### Request Example ```json { "window": [0.0, 0.0, 0.0, 0.0, 0.0], "len": 5 } ``` ### Response #### Success Response (200) None #### Response Example ```json { "window": [0.0, 0.5, 1.0, 0.5, 0.0] } ``` ## dsps_wind_blackman_f32 ### Description Generates a Blackman window with alpha = 0.16. ### Method void ### Endpoint N/A ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **_window_** (float *) - Buffer to store the generated window array. - **_len_** (int) - The desired length of the window array. ### Request Example ```json { "window": [0.0, 0.0, 0.0, 0.0, 0.0], "len": 5 } ``` ### Response #### Success Response (200) None #### Response Example ```json { "window": [...] } ``` ``` -------------------------------- ### Generate Flat-Top Window (C) Source: https://docs.espressif.com/projects/esp-dsp/en/latest/esp32/esp-dsp-apis Generates a Flat-Top window. This function takes a buffer to store the window array and its length as parameters. ```c void dsps_wind_flat_top_f32(float *_window_ , int _len_) ``` -------------------------------- ### dsps_view Source: https://docs.espressif.com/projects/esp-dsp/en/latest/esp32/esp-dsp-apis Provides a generic console plot view for input signal samples. ```APIDOC ## dsps_view ### Description 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. ### Method `void` ### Endpoint N/A (This is a C function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```c // Example usage (not a direct API request) float signal_data[] = {0.1, 0.5, 0.3, 0.8, 0.2}; int data_len = 5; int plot_width = 30; int plot_height = 5; float min_val = 0.0; float max_val = 1.0; char view_char = '*'; dsps_view(signal_data, data_len, plot_width, plot_height, min_val, max_val, view_char); ``` ### Response #### Success Response N/A (This is a void function, output is to the console) #### Response Example ``` // Console output displaying a plot of the signal data ``` ``` -------------------------------- ### Flat-Top Window Generation Source: https://docs.espressif.com/projects/esp-dsp/en/latest/esp32/esp-dsp-apis Generates a Flat-Top window. This function populates a provided buffer with the window coefficients. ```APIDOC ## void dsps_wind_flat_top_f32(float *_window_ , int _len_) ### Description Generates the Flat-Top window. This function calculates the coefficients for the Flat-Top window and stores them in the provided buffer. ### Method void ### Endpoint N/A (This is a function call, not an API endpoint) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body * **_window_** (float*) - Required - Pointer to the buffer where the window array will be stored. * **_len_** (int) - Required - The desired length of the window array. ### Request Example ```c float window_buffer[256]; int window_length = 256; dsps_wind_flat_top_f32(window_buffer, window_length); ``` ### Response #### Success Response (200) N/A (This function modifies the provided buffer in-place) #### Response Example N/A ``` -------------------------------- ### ESP-DSP Matrix Multiplication Benchmarks Source: https://docs.espressif.com/projects/esp-dsp/en/latest/esp32/esp-dsp-benchmarks Benchmarks for matrix multiplication functions (`dspm_mult_f32`, `dspm_mult_s16`, etc.), measuring CPU cycles for various matrix dimensions and data types across optimizations and platforms. ```text dspm_mult_f32 - C[16;16] = A[16;16]*B[16;16] | 24659 | 6280 | 28276 | 56915 | 31481 | 24660 | 6282 | 28239 | 66482 | 38913 dspm_mult_s16 - C[16;16] = A[16;16]*B[16;16] | 24697 | 2004 | 2138 | 71112 | 60715 | 24696 | 1831 | 2141 | 126689 | 63865 dspm_mult_3x3x1_f32 - C[3;1] = A[3;3]*B[3;1] | 70 | 71 | 144 | 247 | 161 | 69 | 131 | 159 | 258 | 164 dspm_mult_3x3x3_f32 - C[3;3] = A[3;3]*B[3;3] | 200 | 200 | 338 | 560 | 309 | 201 | 199 | 332 | 559 | 351 dspm_mult_4x4x1_f32 - C[4;1] = A[4;4]*B[4;1] | 102 | 103 | 206 | 371 | 227 | 103 | 104 | 202 | 398 | 258 dspm_mult_4x4x4_f32 - C[4;4] = A[4;4]*B[4;4] | 395 | 175 | 658 | 1150 | 608 | 394 | 174 | 658 | 1189 | 749 ``` -------------------------------- ### Generate Blackman-Nuttall Window (C) Source: https://docs.espressif.com/projects/esp-dsp/en/latest/esp32/esp-dsp-apis Generates a Blackman-Nuttall window. The function requires a buffer for the window array and the desired length. ```c void dsps_wind_blackman_nuttall_f32(float *_window_ , int _len_) ```