working wavelet transform

Dependencies:   CMSIS_DSP_5 include mbed

Fork of Nucleo-Heart-Rate by BAP TUDelft

Revision:
0:f39864a2bd26
Child:
2:3d6a6b9afee0
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Jun 20 09:09:34 2018 +0000
@@ -0,0 +1,73 @@
+//#include <math.h>
+#include "arm_common_tables.h"
+#include "arm_const_structs.h"
+#include "arm_math.h"
+#include "mbed.h"
+#include "../header/wavelib.h"
+
+
+
+DigitalOut myled(LED1);
+Serial usb_serial(SERIAL_TX, SERIAL_RX);                                            // tx, rx
+const int baud_rate = 115200;        
+                                                     // Baud rate.
+static float32_t cosSum[320];
+
+float32_t *cosArray(int length, int freq, int fs){
+    float *p = (float *) malloc(sizeof(float) * length);
+    double Ts = (double) 1/fs; 
+    double w = 2*PI*freq;
+        
+    for(int i = 0; i < length; i++){
+        p[i] = arm_cos_f32(w * Ts * i);
+    }
+    
+    return p;
+}
+
+int main() {
+    usb_serial.baud(baud_rate);                                                     // Set serial USB connection baud rate (variable is declared in config part).
+    
+    
+    uint32_t N = 320;
+    uint32_t fs = 100;
+    uint32_t freq1 = 1;
+    uint32_t freq2 = 12;
+    float32_t *testCos1 = cosArray(N, freq1, fs);
+    float32_t *testCos2 = cosArray(N, freq2, fs);
+    
+    wave_object obj;
+    wt_object wt;
+    
+    double *inp; //,*out,*diff;
+    int i, J = 3;
+
+    char *name = "db4";
+    obj = wave_init(name);// Initialize the wavelet
+    
+    for(i = 0; i < N; i++){
+        cosSum[i] = testCos1[i] + testCos2[i];
+    }
+    inp = (double*)malloc(sizeof(double)* N);
+    //out = (double*)malloc(sizeof(double)* N);
+//    diff = (double*)malloc(sizeof(double)* N);
+
+    for (i = 0; i < N; i++) {
+        inp[i] = cosSum[i];
+   }
+    myled = !myled;
+    
+    wt = wt_init(obj, "modwt", 320, 3);// Initialize the wavelet transform object
+    myled = !myled;
+    
+    modwt(wt, inp);// Perform MODW
+
+    while(1){
+        for (i = 0; i < wt->outlength; ++i) {
+            printf("%d %e \n",i, wt->output[i]);
+        }
+        myled = !myled;
+    }
+//   setDWTExtension(wt, "sym");// Options are "per" and "sym". Symmetric is the default option
+//    setWTConv(wt, "direct");
+}