You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
622 B
C++
23 lines
622 B
C++
3 years ago
|
Sample *process_data(Samples samples)
|
||
3 years ago
|
{
|
||
|
constexpr float alpha = 0.75;
|
||
|
constexpr unsigned int D = 100;
|
||
|
|
||
3 years ago
|
static Sample output[samples.size()];
|
||
|
static Sample prev[D]; // prev[0] = output[0 - D]
|
||
3 years ago
|
|
||
|
// Do calculations with previous output
|
||
|
for (unsigned int i = 0; i < D; i++)
|
||
|
output[i] = samples[i] + alpha * (prev[i] - 2048);
|
||
|
|
||
|
// Do calculations with current samples
|
||
3 years ago
|
for (unsigned int i = D; i < samples.size(); i++)
|
||
3 years ago
|
output[i] = samples[i] + alpha * (output[i - D] - 2048);
|
||
|
|
||
|
// Save outputs for next computation
|
||
|
for (unsigned int i = 0; i < D; i++)
|
||
3 years ago
|
prev[i] = output[samples.size() - (D - i)];
|
||
3 years ago
|
|
||
|
return output;
|
||
|
}
|