ESP-IDF Firmware
Firmware architecture and call graph
Loading...
Searching...
No Matches
dsps_dstiv_f32.c
Go to the documentation of this file.
1// Copyright 2018-2020 Espressif Systems (Shanghai) PTE LTD
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#include "dsp_common.h"
16#include <math.h>
17
18#include "dsps_dct.h"
19#include "dsps_fft2r.h"
20
21esp_err_t dsps_dstiv_f32(float *data, int ndst)
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}
#define ESP_ERR_DSP_REINITIALIZED
esp_err_t dsps_dstiv_f32(float *data, int ndst)
DST of radix 2, type IV, unscaled.
#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