diff options
author | Clyne Sullivan <clyne@bitgloo.com> | 2020-11-24 10:17:52 -0500 |
---|---|---|
committer | Clyne Sullivan <clyne@bitgloo.com> | 2020-11-24 10:17:52 -0500 |
commit | 6395d1d18b2fe0ece82f3b82c35648b0419378c2 (patch) | |
tree | 386a022bbbf1a0ead2ef53b215660c3e0bc45f25 /gui/templates | |
parent | f559e9fbef98e16ebf4d72190322ca110f4940be (diff) |
oversample for lower rates; add iir templates
Diffstat (limited to 'gui/templates')
-rw-r--r-- | gui/templates/6_iir_test.cpp | 13 | ||||
-rw-r--r-- | gui/templates/7_iir_echo.cpp | 22 |
2 files changed, 35 insertions, 0 deletions
diff --git a/gui/templates/6_iir_test.cpp b/gui/templates/6_iir_test.cpp new file mode 100644 index 0000000..cdb4ab3 --- /dev/null +++ b/gui/templates/6_iir_test.cpp @@ -0,0 +1,13 @@ +adcsample_t *process_data(adcsample_t *samples, unsigned int size) +{ + constexpr float alpha = 0.7; + + static adcsample_t prev = 2048; + + samples[0] = (1 - alpha) * samples[0] + alpha * prev; + for (unsigned int i = 1; i < size; i++) + samples[i] = (1 - alpha) * samples[i] + alpha * samples[i - 1]; + prev = samples[size - 1]; + + return samples; +} diff --git a/gui/templates/7_iir_echo.cpp b/gui/templates/7_iir_echo.cpp new file mode 100644 index 0000000..8e93b35 --- /dev/null +++ b/gui/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; +} |