ESP-IDF Firmware
Firmware architecture and call graph
Loading...
Searching...
No Matches
dsps_dctiv_f32.c File Reference
#include "dsp_common.h"
#include <math.h>
#include "dsps_dct.h"
#include "dsps_fft2r.h"
Include dependency graph for dsps_dctiv_f32.c:

Go to the source code of this file.

Functions

esp_err_t dsps_dctiv_f32 (float *data, int ndct)
 DCT of radix 2, type IV, unscaled.

Function Documentation

◆ dsps_dctiv_f32()

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.

Parameters
[in,out]datainput/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]NSize of DCT transform. Size of data array must be N
Returns
  • ESP_OK on success
  • One of the error codes from DSP library

Definition at line 21 of file dsps_dctiv_f32.c.

22{
23 if (dsps_fft2r_initialized == 0) {
25 }
26
27 float factor = M_PI / (ndct * 2);
28 float in1, in2, in3, in4;
29 for (int i = 0; i < ndct / 4; i++) {
30 in1 = data[i * 2 + 0];
31 in2 = data[i * 2 + 1];
32 in3 = data[ndct - i * 2 - 1];
33 in4 = data[ndct - i * 2 - 2];
34
35 data[i * 2 + 0] = (
36 in1 * cos(factor * (i * 2 + 0))
37 + in3 * cos(factor * ((ndct - i * 2)))
38 );
39
40 data[i * 2 + 1] = (
41 -in1 * sin(factor * (i * 2))
42 + in3 * sin(factor * ((ndct - i * 2)))
43 );
44
45 data[ndct - i * 2 + 0 - 2] = (
46 in2 * cos(factor * (i * 2 + 1 + 0.5) )
47 + in4 * cos(factor * ((ndct - i * 2 - 1) - 0.5) )
48 );
49
50 data[ndct - i * 2 + 1 - 2] = (
51 in2 * sin(factor * (i * 2 + 1))
52 + in4 * sin(-factor * ((ndct - i * 2 - 1)) )
53 );
54
55 }
56 esp_err_t error = ESP_OK;
57 error = dsps_fft2r_fc32(data, ndct / 2);
58 if (error != ESP_OK) {
59 return error;
60 }
61 error = dsps_bit_rev_fc32(data, ndct / 2);
62 if (error != ESP_OK) {
63 return error;
64 }
65
66 for (int i = 0; i < ndct / 4; i++) {
67 in1 = data[2 * i + 0];
68 in2 = data[2 * i + 1];
69
70 in3 = data[ndct - 2 * i - 2];
71 in4 = data[ndct - 2 * i - 1];
72
73 data[i * 2 + 0] = (
74 in1 * cos(factor * (0 + i * 2))
75 + in2 * sin(factor * (0 + i * 2))
76 );
77
78 data[ndct - i * 2 - 1] = (
79 in1 * cos(factor * (ndct - i * 2))
80 - in2 * sin(factor * (ndct - i * 2))
81 );
82
83 data[i * 2 + 1] = (
84 in3 * cos(factor * (2 + i * 2))
85 - in4 * sin(factor * (2 + i * 2))
86 );
87
88 data[ndct - i * 2 - 2] = (
89 in3 * cos(factor * (ndct - i * 2 - 2) )
90 + in4 * sin(factor * (ndct - i * 2 - 2) )
91 );
92 }
93 return ESP_OK;
94}
#define ESP_ERR_DSP_REINITIALIZED
#define dsps_bit_rev_fc32
Definition dsps_fft2r.h:249
#define dsps_fft2r_fc32
Definition dsps_fft2r.h:248
uint8_t dsps_fft2r_initialized
int esp_err_t
Definition esp_err.h:21
#define ESP_OK
Definition esp_err.h:23
#define M_PI
Definition esp_err.h:26
static float data[128 *2]
Definition test_fft2r.c:34

References data, dsps_bit_rev_fc32, dsps_fft2r_fc32, dsps_fft2r_initialized, ESP_ERR_DSP_REINITIALIZED, ESP_OK, and M_PI.