rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
Typedefs | Functions
fft Namespace Reference

Typedefs

typedef float real_type
 
typedef std::complex< real_typecomplex_type
 

Functions

bool fft_adc_sample (float *w, float ratio, float sensitivity, const adcsample_t *data_in, complex_type *data_out, const size_t size)
 
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)
 
bool fft (const real_type *data_in, complex_type *data_out, const size_t size)
 
void rectwin (float *w, unsigned n)
 
void hann (float *w, unsigned n, bool sflag)
 
void hamming (float *w, unsigned n, bool sflag)
 
void blackman (float *w, unsigned n, bool sflag)
 
void blackmanharris (float *w, unsigned n, bool sflag)
 
float fast_sqrt (float x)
 
float amplitude (const complex_type &fft)
 
bool isPow (const size_t num)
 
void rerrange (complex_type *data, const size_t num_elements)
 
bool transform (complex_type *data, const size_t count)
 
static bool ffti (complex_type *data, const size_t size)
 
void cosine_window (float *w, unsigned n, const float *coeff, unsigned ncoeff, bool sflag)
 

Typedef Documentation

◆ complex_type

typedef std::complex<real_type> fft::complex_type

Definition at line 17 of file fft.h.

◆ real_type

Definition at line 16 of file fft.h.

Function Documentation

◆ amplitude()

float fft::amplitude ( const complex_type fft)

Definition at line 133 of file fft.hpp.

133 {
134 return fast_sqrt(fft.real()*fft.real() + fft.imag()*fft.imag());
135}
Definition fft.h:14
float fast_sqrt(float x)
Definition fft.hpp:119

Referenced by processLastKnockEvent().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ blackman()

void fft::blackman ( float w,
unsigned  n,
bool  sflag 
)

Definition at line 182 of file fft.hpp.

183{
184 const float coeff[3] = { 0.42, -0.5, 0.08 };
185 cosine_window(w, n, coeff, sizeof(coeff) / sizeof(float), sflag);
186}
Here is the call graph for this function:

◆ blackmanharris()

void fft::blackmanharris ( float w,
unsigned  n,
bool  sflag 
)

Definition at line 188 of file fft.hpp.

189{
190 const float coeff[4] = { 0.35875, -0.48829, 0.14128, -0.01168 };
191 cosine_window(w, n, coeff, sizeof(coeff) / sizeof(float), sflag);
192}

Referenced by initSoftwareKnock().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cosine_window()

void fft::cosine_window ( float w,
unsigned  n,
const float coeff,
unsigned  ncoeff,
bool  sflag 
)

Definition at line 137 of file fft.hpp.

138{
139 if (n == 1)
140 {
141 w[0] = 1.0;
142 }
143 else
144 {
145 const unsigned wlength = sflag ? (n - 1) : n;
146
147 for (unsigned i = 0; i < n; ++i)
148 {
149 float wi = 0.0;
150
151 for (unsigned j = 0; j < ncoeff; ++j)
152 {
153 wi += coeff[j] * cos(i * j * 2.0 * M_PI / wlength);
154 }
155
156 w[i] = wi;
157 }
158 }
159}

Referenced by blackman(), blackmanharris(), hamming(), and hann().

Here is the caller graph for this function:

◆ fast_sqrt()

float fft::fast_sqrt ( float  x)

Definition at line 119 of file fft.hpp.

119 {
120 union
121 {
122 float x;
123 int32_t i;
124 } u;
125 u.x = x;
126 u.i = 0x5f375a86 - (u.i >> 1);
127 float xu = x * u.x;
128 float xu2 = xu * u.x;
129 u.x = (0.125 * 3.0) * xu * (5.0 - xu2 * ((10.0 / 3.0) - xu2));
130 return u.x;
131}

Referenced by amplitude().

Here is the caller graph for this function:

◆ fft()

bool fft::fft ( const real_type data_in,
complex_type data_out,
const size_t  size 
)

Definition at line 109 of file fft.hpp.

110{
111 for(size_t i = 0; i < size; ++i) {
112 data_out[i] = complex_type(data_in[i], 0.0);
113 }
114
115 return ffti(data_out, size);
116}
std::complex< real_type > complex_type
Definition fft.h:17
composite packet size
Here is the call graph for this function:

◆ fft_adc_sample()

bool fft::fft_adc_sample ( float w,
float  ratio,
float  sensitivity,
const adcsample_t data_in,
complex_type data_out,
const size_t  size 
)

Definition at line 88 of file fft.hpp.

89{
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);
93 }
94
95 return ffti(data_out, size);
96}

Referenced by processLastKnockEvent().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ fft_adc_sample_filtered()

bool fft::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 
)

Definition at line 98 of file fft.hpp.

99{
100 for(size_t i = 0; i < size; ++i) {
101 float voltage = ratio * data_in[i];
102 float filtered = knockFilter.filter(voltage);
103 data_out[i] = complex_type(filtered * w[i] * sensitivity, 0.0);
104 }
105
106 return ffti(data_out, size);
107}
float filter(float input)
Definition biquad.cpp:74
static Biquad knockFilter

Referenced by processLastKnockEvent().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ffti()

static bool fft::ffti ( complex_type data,
const size_t  size 
)
static

Definition at line 77 of file fft.hpp.

78{
79 if(!isPow(size)) {
80 return false;
81 }
82
83 rerrange(data, size);
84
85 return transform(data, size);
86}
bool isPow(const size_t num)
Definition fft.hpp:10

Referenced by fft(), fft_adc_sample(), and fft_adc_sample_filtered().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ hamming()

void fft::hamming ( float w,
unsigned  n,
bool  sflag 
)

Definition at line 176 of file fft.hpp.

177{
178 const float coeff[2] = { 0.54, -0.46 };
179 cosine_window(w, n, coeff, sizeof(coeff) / sizeof(float), sflag);
180}
Here is the call graph for this function:

◆ hann()

void fft::hann ( float w,
unsigned  n,
bool  sflag 
)

Definition at line 169 of file fft.hpp.

170{
171 const float coeff[2] = { 0.5, -0.5 };
172
173 cosine_window(w, n, coeff, sizeof(coeff) / sizeof(float), sflag);
174}
Here is the call graph for this function:

◆ isPow()

bool fft::isPow ( const size_t  num)
inline

Definition at line 10 of file fft.hpp.

11{
12 return num && (!(num & (num - 1)));
13}

Referenced by ffti().

Here is the caller graph for this function:

◆ rectwin()

void fft::rectwin ( float w,
unsigned  n 
)

Definition at line 161 of file fft.hpp.

162{
163 for (unsigned i = 0; i < n; ++i)
164 {
165 w[i] = 1.0;
166 }
167}

◆ rerrange()

void fft::rerrange ( complex_type data,
const size_t  num_elements 
)

Definition at line 15 of file fft.hpp.

16{
17 size_t target_index = 0;
18 size_t bit_mask;
19
21 for (size_t i = 0; i < num_elements; ++i)
22 {
23 if (target_index > i)
24 {
25 buffer = data[target_index];
26 data[target_index] = data[i];
27 data[i]= buffer;
28 }
29
30 bit_mask = num_elements;
31
32 while (target_index & (bit_mask >>= 1))
33 {
34 target_index &= ~bit_mask;
35 }
36
37 target_index |= bit_mask;
38 }
39}
static BigBufferHandle buffer

Referenced by ffti().

Here is the caller graph for this function:

◆ transform()

bool fft::transform ( complex_type data,
const size_t  count 
)

Definition at line 41 of file fft.hpp.

42{
43 double local_pi = -M_PI;
44
45 size_t next, match;
46 real_type sine;
47 real_type delta;
48 complex_type mult, factor, product;
49
50 for (size_t i = 1; i < count; i <<= 1)
51 {
52 next = i << 1;
53 delta = local_pi / i;
54 sine = sin(0.5 * delta);
55
56 mult = complex_type(-2.0 * sine * sine, sin(delta));
57 factor = 1.0;
58
59 for (size_t j = 0; j < i; ++j)
60 {
61 for (size_t k = j; k < count; k += next)
62 {
63 match = k + i;
64
65 product = data[match] * factor;
66 data[match] = data[k] - product;
67 data[k] += product;
68 }
69
70 factor = mult * factor + factor;
71 }
72 }
73
74 return true;
75}
float real_type
Definition fft.h:16
uint16_t count
Definition tunerstudio.h:1

Referenced by ffti().

Here is the caller graph for this function: