ESP-IDF Firmware
Firmware architecture and call graph
Loading...
Searching...
No Matches
dsps_dct.h File Reference
#include "dsp_err.h"
#include "sdkconfig.h"
Include dependency graph for dsps_dct.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

esp_err_t dsps_dct_f32 (float *data, int N)
 DCT of radix 2, unscaled.
esp_err_t dsps_dctiv_f32 (float *data, int N)
 DCT of radix 2, type IV, unscaled.
esp_err_t dsps_dstiv_f32 (float *data, int N)
 DST of radix 2, type IV, unscaled.
esp_err_t dsps_dct_inv_f32 (float *data, int N)
 Inverce DCT of radix 2.
esp_err_t dsps_dct_f32_ref (float *data, int N, float *result)
 DCTs.
esp_err_t dsps_dct_inverce_f32_ref (float *data, int N, float *result)

Function Documentation

◆ dsps_dct_f32()

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.

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

Definition at line 47 of file dsps_dct_f32.c.

48{
49 esp_err_t ret = ESP_OK;
50 if (dsps_fft2r_initialized == 0) {
52 }
53
54 for (int i = 0; i < N / 2; i++) {
55 data[(N - 1 - i) * 2] = data[i * 2 + 1];
56 data[i * 2 + 1] = 0;
57 data[N + i * 2 + 1] = 0;
58 }
59
60 ret = dsps_fft2r_fc32(data, N);
61 if (ret != ESP_OK) {
62 return ret;
63 }
64
65 // // The follows code do the same as this one:
66 // //
67 // float factor = M_PI / (N * 2);
68 // ret = dsps_bit_rev_fc32(data, N);
69 // for (int i = 0; i < N; i++) {
70 // float temp = i * factor;
71 // data[i] = data[i*2] * cosf(temp) + data[i*2 + 1] * sinf(temp);
72 // }
73 int table_step = 2;
74 for (int i = 0; i < N; i++) {
75 float c = dsps_fft_w_table_fc32[i * 2 * table_step];
76 float s = dsps_fft_w_table_fc32[i * 2 * table_step + 1];
77 data[i * 2] = data[i * 2] * c;
78 data[i * 2 + 1] = data[i * 2 + 1] * s;
79 }
80 ret = dsps_bit_rev_fc32(data, N);
81 if (ret != ESP_OK) {
82 return ret;
83 }
84
85 for (int i = 0; i < N; i++) {
86 data[i] = data[i * 2] + data[i * 2 + 1];
87 }
88 return ESP_OK;
89}
#define ESP_ERR_DSP_REINITIALIZED
#define dsps_bit_rev_fc32
Definition dsps_fft2r.h:249
#define dsps_fft2r_fc32
Definition dsps_fft2r.h:248
float * dsps_fft_w_table_fc32
uint8_t dsps_fft2r_initialized
int esp_err_t
Definition esp_err.h:21
#define ESP_OK
Definition esp_err.h:23
static float data[128 *2]
Definition test_fft2r.c:34
#define N
Definition test_mmult.c:13

References data, dsps_bit_rev_fc32, dsps_fft2r_fc32, dsps_fft2r_initialized, dsps_fft_w_table_fc32, ESP_ERR_DSP_REINITIALIZED, ESP_OK, and N.

◆ dsps_dct_f32_ref()

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.

Parameters
[in]datainput/output array with size of N. An elements located: Re[0],Re[1], , ... Re[N-1]
[in]NSize of DCT transform. Size of data array must be N*2!!!
[out]resultoutput result array with size of N.
Returns
  • ESP_OK on success
  • One of the error codes from DSP library

Definition at line 21 of file dsps_dct_f32.c.

22{
23 float factor = M_PI / N;
24 for (size_t i = 0; i < N; i++) {
25 float sum = 0;
26 for (size_t j = 0; j < N; j++) {
27 sum += data[j] * cosf((j + 0.5) * i * factor);
28 }
29 result[i] = sum;
30 }
31 return ESP_OK;
32}
#define M_PI
Definition esp_err.h:26

References data, ESP_OK, M_PI, and N.

◆ dsps_dct_inv_f32()

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.

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

Definition at line 91 of file dsps_dct_f32.c.

92{
93 esp_err_t ret = ESP_OK;
94 if (dsps_fft2r_initialized == 0) {
96 }
97
98 float factor = M_PI / (N * 2);
99 data[0] *= 0.5;
100 for (int i = N - 1; i >= 0; i--) {
101 float temp = i * factor;
102 data[i * 2] = data[i] * cosf(temp);
103 data[i * 2 + 1] = data[i] * -sinf(temp);
104 }
105 ret = dsps_fft2r_fc32(data, N);
106 if (ret != ESP_OK) {
107 return ret;
108 }
109 ret = dsps_bit_rev_fc32(data, N);
110 if (ret != ESP_OK) {
111 return ret;
112 }
113 for (size_t i = 0; i < N / 2; i++) {
114 data[i * 2 + 1] = data[(N - 1 - i) * 2];
115 }
116
117 return ESP_OK;
118}

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

◆ dsps_dct_inverce_f32_ref()

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

Definition at line 34 of file dsps_dct_f32.c.

35{
36 float factor = M_PI / N;
37 for (size_t i = 0; i < N; i++) {
38 float sum = data[0] / 2;
39 for (size_t j = 0; j < N; j++) {
40 sum += data[j] * cosf(j * (i + 0.5) * factor);
41 }
42 result[i] = sum;
43 }
44 return ESP_OK;
45}

References data, ESP_OK, M_PI, and N.

◆ 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}

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

◆ dsps_dstiv_f32()

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.

Parameters
[in,out]datainput/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]NSize of DST 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_dstiv_f32.c.

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

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