6#define M_PI 3.1415926535897932
10inline bool isPow(
const size_t num)
12 return num && (!(num & (num - 1)));
17 size_t target_index = 0;
21 for (
size_t i = 0; i < num_elements; ++i)
25 buffer = data[target_index];
26 data[target_index] = data[i];
30 bit_mask = num_elements;
32 while (target_index & (bit_mask >>= 1))
34 target_index &= ~bit_mask;
37 target_index |= bit_mask;
43 double local_pi = -M_PI;
50 for (
size_t i = 1; i <
count; i <<= 1)
54 sine = sin(0.5 * delta);
59 for (
size_t j = 0; j < i; ++j)
61 for (
size_t k = j; k <
count; k += next)
65 product = data[match] * factor;
66 data[match] = data[k] - product;
70 factor = mult * factor + factor;
90 for(
size_t i = 0; i <
size; ++i) {
91 float voltage = ratio * data_in[i];
92 data_out[i] =
complex_type(sensitivity * voltage * w[i], 0.0);
100 for(
size_t i = 0; i <
size; ++i) {
101 float voltage = ratio * data_in[i];
103 data_out[i] =
complex_type(filtered * w[i] * sensitivity, 0.0);
111 for(
size_t i = 0; i <
size; ++i) {
126 u.i = 0x5f375a86 - (u.i >> 1);
128 float xu2 = xu * u.x;
129 u.x = (0.125 * 3.0) * xu * (5.0 - xu2 * ((10.0 / 3.0) - xu2));
137void cosine_window(
float * w,
unsigned n,
const float * coeff,
unsigned ncoeff,
bool sflag)
145 const unsigned wlength = sflag ? (n - 1) : n;
147 for (
unsigned i = 0; i < n; ++i)
151 for (
unsigned j = 0; j < ncoeff; ++j)
153 wi += coeff[j] * cos(i * j * 2.0 * M_PI / wlength);
163 for (
unsigned i = 0; i < n; ++i)
169void hann(
float * w,
unsigned n,
bool sflag)
171 const float coeff[2] = { 0.5, -0.5 };
173 cosine_window(w, n, coeff,
sizeof(coeff) /
sizeof(
float), sflag);
176void hamming(
float * w,
unsigned n,
bool sflag)
178 const float coeff[2] = { 0.54, -0.46 };
179 cosine_window(w, n, coeff,
sizeof(coeff) /
sizeof(
float), sflag);
184 const float coeff[3] = { 0.42, -0.5, 0.08 };
185 cosine_window(w, n, coeff,
sizeof(coeff) /
sizeof(
float), sflag);
190 const float coeff[4] = { 0.35875, -0.48829, 0.14128, -0.01168 };
191 cosine_window(w, n, coeff,
sizeof(coeff) /
sizeof(
float), sflag);
float filter(float input)
uint16_t adcsample_t
ADC sample data type.
void rectwin(float *w, unsigned n)
static bool ffti(complex_type *data, const size_t size)
void blackman(float *w, unsigned n, bool sflag)
void rerrange(complex_type *data, const size_t num_elements)
std::complex< real_type > complex_type
void blackmanharris(float *w, unsigned n, bool sflag)
float amplitude(const complex_type &fft)
void hamming(float *w, unsigned n, bool sflag)
void hann(float *w, unsigned n, bool sflag)
bool transform(complex_type *data, const size_t count)
bool fft_adc_sample_filtered(Biquad &knockFilter, float *w, float ratio, float sensitivity, const adcsample_t *data_in, complex_type *data_out, const size_t size)
void cosine_window(float *w, unsigned n, const float *coeff, unsigned ncoeff, bool sflag)
bool fft_adc_sample(float *w, float ratio, float sensitivity, const adcsample_t *data_in, complex_type *data_out, const size_t size)
bool isPow(const size_t num)
static Biquad knockFilter
static BigBufferHandle buffer