Team S - EDP 2 / Mbed 2 deprecated signal_processing

Dependencies:   mbed

Revision:
3:c9f4c9c84e36
Parent:
2:29c3d03c9231
Child:
4:878821708feb
--- a/main.cpp	Wed Feb 14 11:08:48 2018 +0000
+++ b/main.cpp	Wed Feb 14 11:47:22 2018 +0000
@@ -6,7 +6,7 @@
 AnalogIn Ain(PTB1);
 
 int const MAX_B = 10;
-int const delta = 0.5;
+int const alpha = 0.5;
 int const AVG_LEN = 160;
 
 int sample_buffer[2*MAX_B] = {};
@@ -18,19 +18,43 @@
 int avg_write = 0;
 
 int avg_sum;
-bool first ;
+bool first;
+float avg;
+float pre_avg;
 
 Ticker sampler;
 
 void sampling () {
     unsigned int sample = Ain.read_u16();
     sample_buffer[write++] = sample;
-    
     write = write%(2*MAX_B);
     
 }
 
-void avg() {  
+float scale (float point) {
+    return point*7 ;
+}
+
+float filter (float output) {
+    float point = alpha*output + (1- alpha)*pre_avg;
+    point = scale(point);
+    return point;
+}
+
+float get_trend(){
+    float point;
+    pre_avg = avg;
+    avg = avg_sum/AVG_LEN;
+    int output = avg_buffer[avg_write-1] - avg;
+    point = filter(output);
+    
+    return point;
+    
+    
+}
+
+float average() {  
+   float point ;
     if (first) {
         for (int i =0; i <MAX_B; i++) {
             avg_buffer[avg_write] = local_buffer[i];
@@ -47,15 +71,16 @@
             
             avg_buffer[avg_write] = data;
             avg_write = (++avg_write) % AVG_LEN;     
-            //get_trend();
+            point = get_trend();
             
         }
     }
+    return point;
         
 }
 
 void data_process() {
-    avg();
+    average();
 }
 
 int main() {