Voor matthijs

Dependencies:   Encoder MODSERIAL Matrix MatrixMath QEI biquad-master mbed

Fork of frdm_gpio1 by Roy van Zijl

Revision:
0:b6c8d56842ce
Child:
2:293665548183
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Oct 13 08:59:23 2017 +0000
@@ -0,0 +1,78 @@
+/**
+ * Demo program for BiQuad and BiQuadChain classes
+ * author: T.J.W. Lankhorst <t.j.w.lankhorst@student.utwente.nl> and Matthijs and Roy and Dion
+ */
+#include "mbed.h"
+#include "HIDScope.h"
+#include <stdlib.h>
+#include <iostream>
+#include <iomanip>
+#include <complex>
+#include "BiQuad.h"
+
+AnalogIn    emg0( A0 );
+AnalogIn    emg1( A1 );
+
+Ticker      sample_timer;
+HIDScope    scope( 2 );
+DigitalOut  led(LED1);
+DigitalOut  led2(LED_GREEN);
+
+
+
+// Example: 3th order Butterworth LP (w_c = 0.1*f_nyquist)
+
+BiQuadChain bqc;
+BiQuad bq1( 0.9645651759199596, -1.5606992390030165, 0.9645651759199596, -1.5606992390030165, 0.9291303518399192 );
+BiQuad bq2( 1, 1, 1, 1, 1 );
+//BiQuad bq3( 0, 0, 0, 0, 0 );
+
+void sample()
+{
+    /* Set the sampled emg values in channel 0 (the first channel) and 1 (the second channel) in the 'HIDScope' instance named 'scope' */
+    scope.set(0, bq1.step(emg0.read()) );
+    scope.set(1, bq1.step(emg1.read()) );
+    /* Repeat the step above if required for more channels of required (channel 0 up to 5 = 6 channels) 
+    *  Ensure that enough channels are available (HIDScope scope( 2 ))
+    *  Finally, send all channels to the PC at once */
+    scope.send();
+    /* To indicate that the function is working, the LED is toggled */
+    led = !led;
+}
+
+int main()
+{   
+    led2 = 0;
+    bqc = bq1 * bq2; //* bq3;
+    /**Attach the 'sample' function to the timer 'sample_timer'.
+    * this ensures that 'sample' is executed every... 0.002 seconds = 500 Hz
+    */
+    sample_timer.attach(&sample, 0.002);
+
+    /*empty loop, sample() is executed periodically*/
+    while(true) {
+    
+    // Find the poles of the filter
+    std::cout << "Filter poles" << std::endl;
+    std::vector< std::complex<double> > poles = bqc.poles();
+    for( size_t i = 0; i < poles.size(); i++ )
+        std::cout << "\t"  << poles[i] << std::endl;
+
+    // Find the zeros of the filter
+    std::cout << "Filter zeros" << std::endl;
+    std::vector< std::complex<double> > zeros = bqc.zeros();
+    for( size_t i = 0; i < poles.size(); i++ )
+        std::cout << "\t" << zeros[i] << std::endl;
+
+    // Is the filter stable?
+    std::cout << "This filter is " << (bqc.stable() ? "stable" : "instable") << std::endl;
+
+    // Output the step-response of 20 samples
+    std::cout << "Step response 20 samples" << std::endl;
+    for( int i = 0; i < 20; i++ )
+        std::cout << "\t" << bqc.step( 1.0 ) << std::endl;
+
+    // Done0
+    }
+
+}
\ No newline at end of file