]> code.bitgloo.com Git - clyne/stmdsp.git/commitdiff
gui: fix buffer size; add differentiator template
authorClyne Sullivan <clyne@bitgloo.com>
Wed, 18 Nov 2020 17:43:21 +0000 (12:43 -0500)
committerClyne Sullivan <clyne@bitgloo.com>
Wed, 18 Nov 2020 17:43:21 +0000 (12:43 -0500)
gui/templates/5_iir_differentiator.cpp [new file with mode: 0644]
gui/wxmain.cpp

diff --git a/gui/templates/5_iir_differentiator.cpp b/gui/templates/5_iir_differentiator.cpp
new file mode 100644 (file)
index 0000000..f63bba9
--- /dev/null
@@ -0,0 +1,28 @@
+/**
+ * 5_iir_differentiator.cpp
+ * Written by Clyne Sullivan.
+ *
+ * Does an IIR 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.
+ */
+
+adcsample_t *process_data(adcsample_t *samples, unsigned int size)
+{
+    constexpr int scaling_factor = 4;
+    static adcsample_t prev = 2048;
+
+    // Compute the first output value using the saved sample.
+    samples[0] = 2048 + ((samples[0] - prev) * scaling_factor;
+    // Save the last sample for the next iteration.
+    prev = samples[size - 1];
+
+       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.
+               samples[i] = 2048 + ((samples[i] - samples[i - 1]) * scaling_factor);
+    }
+
+    return samples;
+}
+
index 26297019ef8e44364893b933cb502738a248f01b..de2799e1446feaec7959dc72cea35db005edfefa 100644 (file)
@@ -239,7 +239,7 @@ static wxString file_header (R"cpp(
 #include <cstdint>
 
 using adcsample_t = uint16_t;
-constexpr unsigned int SIZE = 4000;
+constexpr unsigned int SIZE = 3000;
 
 adcsample_t *process_data(adcsample_t *samples, unsigned int size);
 
@@ -482,7 +482,7 @@ void MainFrame::onRunLogResults(wxCommandEvent& ce)
 void MainFrame::onRunEditBSize([[maybe_unused]] wxCommandEvent&)
 {
     if (m_device != nullptr && m_device->connected()) {
-        wxTextEntryDialog dialog (this, "Enter new buffer size (100-4000)", "Set Buffer Size");
+        wxTextEntryDialog dialog (this, "Enter new buffer size (100-3000)", "Set Buffer Size");
         if (dialog.ShowModal() == wxID_OK) {
             if (wxString value = dialog.GetValue(); !value.IsEmpty()) {
                 if (unsigned long n; value.ToULong(&n)) {