diff options
author | Clyne Sullivan <clyne@clyne-lp.lan> | 2021-08-08 22:02:52 -0400 |
---|---|---|
committer | Clyne Sullivan <clyne@clyne-lp.lan> | 2021-08-08 22:02:52 -0400 |
commit | 707b24dd07236243269cf092728f85172e94e8a4 (patch) | |
tree | c136716a5fc9ed9cbf570e24f8f6ab715adc73a2 /templates/7_iir_echo.cpp |
initial commit
Diffstat (limited to 'templates/7_iir_echo.cpp')
-rw-r--r-- | templates/7_iir_echo.cpp | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/templates/7_iir_echo.cpp b/templates/7_iir_echo.cpp new file mode 100644 index 0000000..8e93b35 --- /dev/null +++ b/templates/7_iir_echo.cpp @@ -0,0 +1,22 @@ +adcsample_t *process_data(adcsample_t *samples, unsigned int size) +{ + constexpr float alpha = 0.75; + constexpr unsigned int D = 100; + + static adcsample_t output[SIZE]; + static adcsample_t prev[D]; // prev[0] = output[0 - D] + + // 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 + for (unsigned int i = D; i < size; i++) + output[i] = samples[i] + alpha * (output[i - D] - 2048); + + // Save outputs for next computation + for (unsigned int i = 0; i < D; i++) + prev[i] = output[size - (D - i)]; + + return output; +} |