aboutsummaryrefslogtreecommitdiffstats
path: root/examples/7_iir_echo.cpp
diff options
context:
space:
mode:
authorClyne Sullivan <clyne@bitgloo.com>2022-01-09 12:28:19 -0500
committerClyne Sullivan <clyne@bitgloo.com>2022-01-09 12:28:19 -0500
commit1b176cf6cd75c8031a140961655cdd3c16589a68 (patch)
tree8415664e40a9a768d8c3a35fd81252bfdefb72f9 /examples/7_iir_echo.cpp
parentfde531e7c44ea917f745a9f800178fbe83fa19b5 (diff)
small changes; sig gen square(), triangle(), pulse()
Diffstat (limited to 'examples/7_iir_echo.cpp')
-rw-r--r--examples/7_iir_echo.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/examples/7_iir_echo.cpp b/examples/7_iir_echo.cpp
new file mode 100644
index 0000000..57e5605
--- /dev/null
+++ b/examples/7_iir_echo.cpp
@@ -0,0 +1,22 @@
+Sample *process_data(Samples samples)
+{
+ constexpr float alpha = 0.75;
+ constexpr unsigned int D = 100;
+
+ static Sample output[samples.size()];
+ static Sample 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 < samples.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[samples.size() - (D - i)];
+
+ return output;
+}