style: macro location;
fix: hanning window width
This commit is contained in:
parent
3f22ff1a07
commit
109c1b74b0
@ -1,6 +1,12 @@
|
||||
#pragma once
|
||||
|
||||
#include "CMSIS/MKL25Z4.h"
|
||||
#include <inttypes.h>
|
||||
|
||||
#define q15_t int16_t
|
||||
#define q31_t int32_t
|
||||
#define float32_t float
|
||||
typedef unsigned char uchar;
|
||||
|
||||
// Define Clock Settings
|
||||
#define CORCLK_DEFAULT 20970000u // Default Core clock, 20.97 Mhz
|
||||
|
@ -1,11 +1,10 @@
|
||||
#pragma once
|
||||
|
||||
#include <inttypes.h>
|
||||
#include "derivative.h"
|
||||
|
||||
#define q15_t int16_t
|
||||
#define q31_t int32_t
|
||||
#define FFT_N 1024
|
||||
|
||||
#define FFT_BIN(num, re) (uint16_t)((float)(num + 0.5) * re)
|
||||
#define FFT_INDEX(freq, re) (uint16_t)((float)freq / re)
|
||||
|
||||
void FFT(q15_t *data);
|
||||
void FFT(q15_t *data, uint16_t len);
|
||||
|
@ -2,8 +2,8 @@
|
||||
|
||||
#include "fft.h"
|
||||
|
||||
extern const q15_t hanning_17[];
|
||||
extern const q15_t hanning_160[];
|
||||
extern const q15_t hanning_28[];
|
||||
extern const q15_t hanning_200[];
|
||||
|
||||
extern const uint16_t bitrevTable[];
|
||||
extern const q15_t rotCoef[];
|
||||
|
@ -1,13 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
#include <inttypes.h>
|
||||
#include "derivative.h"
|
||||
#include "fft/fft.h"
|
||||
|
||||
#define float32_t float
|
||||
|
||||
#define N 1024
|
||||
#define FS 16000
|
||||
#define RE FS / N
|
||||
#define MN 256
|
||||
#define FS 20000
|
||||
#define RE FS / FFT_N
|
||||
#define BUF_M 256
|
||||
|
||||
#define FREQ_BIT1 1100
|
||||
#define FREQ_SYNC 1200
|
||||
|
@ -29,8 +29,6 @@
|
||||
|
||||
#include "derivative.h"
|
||||
|
||||
typedef unsigned char uchar;
|
||||
|
||||
// LCD function 1 enable
|
||||
#define USE_HORIZONTAL 1 // 横屏
|
||||
#define LCD_FAST_IO 1 // 快速IO
|
||||
|
@ -1,18 +1,25 @@
|
||||
#include "fft/fft.h"
|
||||
#include "fft/table.h"
|
||||
#include <inttypes.h>
|
||||
#include <math.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define N 1024
|
||||
#define FFT_N 1024
|
||||
#define Re(x) 2 * x
|
||||
#define Im(x) 2 * x + 1
|
||||
|
||||
static q15_t res[N * 2];
|
||||
static q15_t res[FFT_N * 2];
|
||||
|
||||
static void hanning(q15_t *data, uint16_t len) {
|
||||
for (uint16_t i = len; i < FFT_N; i++) data[i] = 0;
|
||||
if (len == 200)
|
||||
for (uint16_t i = 0; i < len; i++) data[i] = (q15_t)(((q31_t)data[i] * hanning_200[i]) >> 15);
|
||||
else
|
||||
for (uint16_t i = 0; i < len; i++) data[i] = (q15_t)(((q31_t)data[i] * hanning_28[i]) >> 15);
|
||||
}
|
||||
|
||||
static inline void bitreversal(q31_t *data) {
|
||||
q31_t tmp;
|
||||
uint16_t n1 = N >> 1;
|
||||
uint16_t n1 = FFT_N >> 1;
|
||||
uint16_t n2 = n1 + 1;
|
||||
uint16_t *bitrev = (uint16_t *)&bitrevTable[0];
|
||||
|
||||
@ -39,7 +46,7 @@ static inline void butterfly(q15_t *data) {
|
||||
uint16_t step = 1;
|
||||
q15_t xt, yt, cosv, sinv;
|
||||
|
||||
for (uint16_t m = N; m > 1; m = m >> 1) {
|
||||
for (uint16_t m = FFT_N; m > 1; m = m >> 1) {
|
||||
uint16_t n1 = m;
|
||||
uint16_t n2 = m >> 1;
|
||||
|
||||
@ -48,9 +55,9 @@ static inline void butterfly(q15_t *data) {
|
||||
sinv = rotCoef[ia * 2 + 1];
|
||||
ia = ia + step;
|
||||
|
||||
for (uint16_t j = i, k; j < N; j += n1) {
|
||||
for (uint16_t j = i, k; j < FFT_N; j += n1) {
|
||||
k = j + n2;
|
||||
if (m == N) {
|
||||
if (m == FFT_N) {
|
||||
xt = (data[Re(j)] >> 2u) - (data[Re(k)] >> 2u);
|
||||
yt = (data[Im(j)] >> 2u) - (data[Im(k)] >> 2u);
|
||||
|
||||
@ -84,13 +91,14 @@ static inline void butterfly(q15_t *data) {
|
||||
}
|
||||
}
|
||||
|
||||
void FFT(q15_t *data) {
|
||||
for (uint16_t i = 0; i < N; i++) {
|
||||
void FFT(q15_t *data, uint16_t len) {
|
||||
hanning(data, len);
|
||||
for (uint16_t i = 0; i < FFT_N; i++) {
|
||||
res[Re(i)] = data[i]; // real
|
||||
res[Im(i)] = 0; // imaginary
|
||||
}
|
||||
|
||||
butterfly(res);
|
||||
bitreversal((q31_t *)res);
|
||||
for (uint16_t i = 0; i < N; i++) data[i] = (q15_t)abs(res[Re(i)]);
|
||||
for (uint16_t i = 0; i < FFT_N; i++) data[i] = (q15_t)abs(res[Re(i)]);
|
||||
}
|
||||
|
@ -1,20 +1,24 @@
|
||||
#include "fft/table.h"
|
||||
|
||||
const q15_t hanning_17[] = {
|
||||
0, 1247, 4799, 10114, 16384, 22654, 27969, 31521, 32767, 31521, 27969, 22654, 16384, 10114, 4799, 1247, 0,
|
||||
const q15_t hanning_28[] = {
|
||||
0, 442, 1743, 3833, 6600, 9895, 13539, 17337, 21083, 24576, 27627, 30073, 31780, 32657,
|
||||
32657, 31780, 30073, 27627, 24576, 21083, 17337, 13539, 9895, 6600, 3833, 1743, 442, 0,
|
||||
};
|
||||
|
||||
const q15_t hanning_160[] = {
|
||||
0, 13, 51, 115, 204, 319, 458, 623, 812, 1025, 1263, 1524, 1808, 2115, 2444, 2795,
|
||||
3167, 3560, 3973, 4405, 4856, 5325, 5811, 6314, 6832, 7366, 7913, 8474, 9047, 9631, 10226, 10831,
|
||||
11444, 12065, 12693, 13327, 13965, 14607, 15252, 15898, 16546, 17193, 17839, 18482, 19123, 19759, 20390, 21014,
|
||||
21631, 22240, 22840, 23430, 24009, 24576, 25130, 25671, 26197, 26707, 27202, 27680, 28140, 28581, 29004, 29407,
|
||||
29789, 30151, 30491, 30809, 31105, 31378, 31627, 31852, 32054, 32230, 32383, 32510, 32612, 32688, 32739, 32765,
|
||||
32765, 32739, 32688, 32612, 32510, 32383, 32230, 32054, 31852, 31627, 31378, 31105, 30809, 30491, 30151, 29789,
|
||||
29407, 29004, 28581, 28140, 27680, 27202, 26707, 26197, 25671, 25130, 24576, 24009, 23430, 22840, 22240, 21631,
|
||||
21014, 20390, 19759, 19123, 18482, 17839, 17193, 16546, 15898, 15252, 14607, 13965, 13327, 12693, 12065, 11444,
|
||||
10831, 10226, 9631, 9047, 8474, 7913, 7366, 6832, 6314, 5811, 5325, 4856, 4405, 3973, 3560, 3167,
|
||||
2795, 2444, 2115, 1808, 1524, 1263, 1025, 812, 623, 458, 319, 204, 115, 51, 13, 0,
|
||||
const q15_t hanning_200[] = {
|
||||
0, 8, 33, 73, 130, 204, 293, 399, 520, 657, 810, 978, 1162, 1361, 1575, 1803,
|
||||
2047, 2304, 2576, 2861, 3160, 3471, 3796, 4134, 4483, 4845, 5217, 5602, 5996, 6402, 6817, 7241,
|
||||
7675, 8117, 8568, 9027, 9492, 9965, 10444, 10929, 11420, 11915, 12415, 12919, 13426, 13936, 14449, 14963,
|
||||
15479, 15996, 16513, 17030, 17547, 18062, 18576, 19087, 19596, 20102, 20604, 21101, 21594, 22082, 22564, 23040,
|
||||
23509, 23972, 24426, 24873, 25311, 25740, 26160, 26570, 26970, 27360, 27738, 28106, 28461, 28805, 29136, 29454,
|
||||
29759, 30052, 30330, 30594, 30845, 31081, 31302, 31508, 31700, 31876, 32036, 32181, 32311, 32424, 32522, 32603,
|
||||
32668, 32717, 32750, 32766, 32766, 32750, 32717, 32668, 32603, 32522, 32424, 32311, 32181, 32036, 31876, 31700,
|
||||
31508, 31302, 31081, 30845, 30594, 30330, 30052, 29759, 29454, 29136, 28805, 28461, 28106, 27738, 27360, 26970,
|
||||
26570, 26160, 25740, 25311, 24873, 24426, 23972, 23509, 23040, 22564, 22082, 21594, 21101, 20604, 20102, 19596,
|
||||
19087, 18576, 18062, 17547, 17030, 16513, 15996, 15479, 14963, 14449, 13936, 13426, 12919, 12415, 11915, 11420,
|
||||
10929, 10444, 9965, 9492, 9027, 8568, 8117, 7675, 7241, 6817, 6402, 5996, 5602, 5217, 4845, 4483,
|
||||
4134, 3796, 3471, 3160, 2861, 2576, 2304, 2047, 1803, 1575, 1361, 1162, 978, 810, 657, 520,
|
||||
399, 293, 204, 130, 73, 33, 8, 0,
|
||||
};
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user