diff options
author | Clyne <clyne@bitgloo.com> | 2022-05-24 17:38:05 -0400 |
---|---|---|
committer | Clyne <clyne@bitgloo.com> | 2022-05-24 17:38:05 -0400 |
commit | 5902a67796000c7546d07fa778b26619c4588c3a (patch) | |
tree | 1c1fa04635a3c248d07fde4dce8857885ca23952 /examples/5_fir_differentiator.cpp | |
parent | 1cf4908a23dc5537be0bab1089ffcaa7079d5434 (diff) | |
parent | dff847ff4455e7b8c5123167a7d01afe7c45f585 (diff) |
Merge pull request 'devel: Ready for pre-release' (#1) from devel into masterv0.1
Reviewed-on: https://code.bitgloo.com/clyne/stmdspgui/pulls/1
Diffstat (limited to 'examples/5_fir_differentiator.cpp')
-rw-r--r-- | examples/5_fir_differentiator.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/examples/5_fir_differentiator.cpp b/examples/5_fir_differentiator.cpp new file mode 100644 index 0000000..1500dee --- /dev/null +++ b/examples/5_fir_differentiator.cpp @@ -0,0 +1,30 @@ +/** + * 5_fir_differentiator.cpp + * Written by Clyne Sullivan. + * + * Does an FIR differentiation on the incoming signal, so that the output is representative of the + * rate of change of the input. + * A scaling factor is applied so that the output's form is more clearly visible. + */ + +Sample* process_data(Samples samples) +{ + constexpr int scaling_factor = 4; + static Samples output; + static Sample prev = 2048; + + // Compute the first output value using the saved sample. + output[0] = 2048 + ((samples[0] - prev) * scaling_factor); + + for (unsigned int i = 1; i < SIZE; i++) { + // Take the rate of change and scale it. + // 2048 is added as the output should be centered in the voltage range. + output[i] = 2048 + ((samples[i] - samples[i - 1]) * scaling_factor); + } + + // Save the last sample for the next iteration. + prev = samples[SIZE - 1]; + + return output; +} + |