#include #include "esp_dsp.h" #define N 8 // 向量长度 void app_main(void) { // 输入向量(信号示例) float x[N] = {1.0, -2.0, 3.0, -4.0, 2.5, -1.5, 0.0, 4.5}; float y[N]; // 输出向量 // 初始化 ESP-DSP esp_err_t ret = dsps_fft2r_init_fc32(NULL, CONFIG_DSP_MAX_FFT_SIZE); if (ret != ESP_OK) { printf("Failed to initialize ESP-DSP!\n"); return; } printf("Sinal de entrada:\n"); for (int i = 0; i < N; i++) { printf("%f ", x[i]); } printf("\n"); // 计算每个值的平方 dsps_mulc_f32(x, y, N, 1.0f); dsps_mul_f32(y, y, y, N, 1, 1, 1); // 对所有平方值求和 float soma = 0; dsps_sum_f32(y, N, &soma, 1); // 计算幅值(平方和的平方根) float magnitude = sqrtf(soma); printf("Magnitude do vetor: %f\n", magnitude); }