Fix UARTS and LPUART
[betaflight.git] / src / main / common / sdft.h
blob35b1d435b8090ea273b8a50d4b3ca1a12547c4e9
1 /*
2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
8 * any later version.
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
21 // Implementation of a Sliding Discrete Fourier Transform (SDFT).
22 // Complexity for calculating frequency spectrum with N bins is O(N).
24 #pragma once
26 #include <stdint.h>
27 #include <complex.h>
28 #undef I // avoid collision of imaginary unit I with variable I in pid.h
29 typedef float complex complex_t; // Better readability for type "float complex"
31 #define SDFT_SAMPLE_SIZE 72
32 #define SDFT_BIN_COUNT (SDFT_SAMPLE_SIZE / 2)
34 typedef struct sdft_s {
36 int idx; // circular buffer index
37 int startBin;
38 int endBin;
39 int batchSize;
40 int numBatches;
41 float samples[SDFT_SAMPLE_SIZE]; // circular buffer
42 complex_t data[SDFT_BIN_COUNT]; // complex frequency spectrum
44 } sdft_t;
46 void sdftInit(sdft_t *sdft, const int startBin, const int endBin, const int numBatches);
47 void sdftPush(sdft_t *sdft, const float sample);
48 void sdftPushBatch(sdft_t *sdft, const float sample, const int batchIdx);
49 void sdftMagSq(const sdft_t *sdft, float *output);
50 void sdftMagnitude(const sdft_t *sdft, float *output);
51 void sdftWinSq(const sdft_t *sdft, float *output);
52 void sdftWindow(const sdft_t *sdft, float *output);