Margot Rutgers / Mbed 2 deprecated SpaghettiFilter

Dependencies:   HIDScope mbed

Fork of Biquad_Hidscope by Margot Rutgers

Committer:
margotr
Date:
Tue Oct 06 14:55:51 2015 +0000
Revision:
0:17b00659dfd2
Child:
1:15de82403661
Simple biquad;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
margotr 0:17b00659dfd2 1
margotr 0:17b00659dfd2 2 #include "mbed.h"
margotr 0:17b00659dfd2 3 #include "HIDScope.h"
margotr 0:17b00659dfd2 4
margotr 0:17b00659dfd2 5
margotr 0:17b00659dfd2 6 Serial pc(USBTX, USBRX);
margotr 0:17b00659dfd2 7
margotr 0:17b00659dfd2 8 HIDScope scope(1);
margotr 0:17b00659dfd2 9 Ticker scopeTimer;
margotr 0:17b00659dfd2 10
margotr 0:17b00659dfd2 11 // Read the analog input
margotr 0:17b00659dfd2 12 AnalogIn ain(A0);
margotr 0:17b00659dfd2 13
margotr 0:17b00659dfd2 14 const double a1=-1.993955222010733;
margotr 0:17b00659dfd2 15 const double a2=0.9939734363649758;
margotr 0:17b00659dfd2 16 const double b0=0.9969821645939272;
margotr 0:17b00659dfd2 17 const double b1=-1.9939643291878544;
margotr 0:17b00659dfd2 18 const double b2=0.9969821645939272;
margotr 0:17b00659dfd2 19
margotr 0:17b00659dfd2 20
margotr 0:17b00659dfd2 21 double v1, v2;
margotr 0:17b00659dfd2 22
margotr 0:17b00659dfd2 23
margotr 0:17b00659dfd2 24
margotr 0:17b00659dfd2 25 double biquadFilter() {
margotr 0:17b00659dfd2 26
margotr 0:17b00659dfd2 27 double v = ain.read() - a1*v1 - a2*v2;
margotr 0:17b00659dfd2 28 double y = b0*v + b1*v1 + b2*v2;
margotr 0:17b00659dfd2 29 v2 = v1;
margotr 0:17b00659dfd2 30 v1 = v;
margotr 0:17b00659dfd2 31 return y;
margotr 0:17b00659dfd2 32
margotr 0:17b00659dfd2 33 };
margotr 0:17b00659dfd2 34
margotr 0:17b00659dfd2 35 void scopeSend()
margotr 0:17b00659dfd2 36 {
margotr 0:17b00659dfd2 37 scope.set(0,ain);
margotr 0:17b00659dfd2 38 scope.send();
margotr 0:17b00659dfd2 39
margotr 0:17b00659dfd2 40 }
margotr 0:17b00659dfd2 41
margotr 0:17b00659dfd2 42 int main()
margotr 0:17b00659dfd2 43 {
margotr 0:17b00659dfd2 44
margotr 0:17b00659dfd2 45 // Attach the data read and send function at 100 Hz
margotr 0:17b00659dfd2 46 scopeTimer.attach_us(&scopeSend, 1e4);
margotr 0:17b00659dfd2 47 pc.printf("foo!\n");
margotr 0:17b00659dfd2 48
margotr 0:17b00659dfd2 49 while(1) { }
margotr 0:17b00659dfd2 50 }