NucleoF401RE EMG sensor with 2channel 16band FFT, mixed 7band XBee send, only test

Dependencies:   mbed

Committer:
nagasm
Date:
Sat Dec 20 05:22:00 2014 +0000
Revision:
0:5e2a4b964485
NucleoF401RE EMG sensor with 2channel 16band FFT, mixed 7band XBee send, only test

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nagasm 0:5e2a4b964485 1 /*
nagasm 0:5e2a4b964485 2 #include <stdio.h>
nagasm 0:5e2a4b964485 3 #include <stdlib.h>
nagasm 0:5e2a4b964485 4 #include <math.h>
nagasm 0:5e2a4b964485 5 int main(){
nagasm 0:5e2a4b964485 6 int fs = 10000;
nagasm 0:5e2a4b964485 7 double B0, a1, a2, b1, c0, F0, T;
nagasm 0:5e2a4b964485 8 F0 = 60; // or 50
nagasm 0:5e2a4b964485 9 B0 = 100.;
nagasm 0:5e2a4b964485 10 T = 1./fs;
nagasm 0:5e2a4b964485 11 a1 = 2. * exp(-M_PI * B0 * T) * cos(2. * M_PI * F0 * T);
nagasm 0:5e2a4b964485 12 a2 = -exp(-2. * M_PI * B0 * T);
nagasm 0:5e2a4b964485 13 b1 = -2. * cos(2. * M_PI * F0 * T);
nagasm 0:5e2a4b964485 14 c0 = (1-a1-a2)/(2+b1);
nagasm 0:5e2a4b964485 15 printf("a1 = %f\n", a1);
nagasm 0:5e2a4b964485 16 printf("a2 = %f\n", a2);
nagasm 0:5e2a4b964485 17 printf("b1 = %f\n", b1);
nagasm 0:5e2a4b964485 18 printf("c0 = %f\n", c0);
nagasm 0:5e2a4b964485 19 return 0;
nagasm 0:5e2a4b964485 20 }
nagasm 0:5e2a4b964485 21 60Hz
nagasm 0:5e2a4b964485 22 a1 = 1.936768
nagasm 0:5e2a4b964485 23 a2 = -0.939101
nagasm 0:5e2a4b964485 24 b1 = -1.998579
nagasm 0:5e2a4b964485 25 c0 = 1.642174
nagasm 0:5e2a4b964485 26 50Hz
nagasm 0:5e2a4b964485 27 a1 = 1.937188
nagasm 0:5e2a4b964485 28 a2 = -0.939101
nagasm 0:5e2a4b964485 29 b1 = -1.999013
nagasm 0:5e2a4b964485 30 c0 = 1.938304
nagasm 0:5e2a4b964485 31 */
nagasm 0:5e2a4b964485 32
nagasm 0:5e2a4b964485 33 float notch_filter1(float data){
nagasm 0:5e2a4b964485 34 y1[0] = data + a1*y1[1] + a2*y1[2];
nagasm 0:5e2a4b964485 35 float reault = y1[0] + b1*y1[1] + y1[2];
nagasm 0:5e2a4b964485 36 y1[2] = y1[1];
nagasm 0:5e2a4b964485 37 y1[1] = y1[0];
nagasm 0:5e2a4b964485 38 return(reault);
nagasm 0:5e2a4b964485 39 }
nagasm 0:5e2a4b964485 40
nagasm 0:5e2a4b964485 41 float notch_filter2(float data){
nagasm 0:5e2a4b964485 42 y2[0] = data + a1*y2[1] + a2*y2[2];
nagasm 0:5e2a4b964485 43 float reault = y2[0] + b1*y2[1] + y2[2];
nagasm 0:5e2a4b964485 44 y2[2] = y2[1];
nagasm 0:5e2a4b964485 45 y2[1] = y2[0];
nagasm 0:5e2a4b964485 46 return(reault);
nagasm 0:5e2a4b964485 47 }