NucleoF401RE EMG seneor with Lissajous Analysis

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers notch.hpp Source File

notch.hpp

00001 /*
00002 #include <stdio.h>
00003 #include <stdlib.h>
00004 #include <math.h>
00005 int main(){
00006     int fs = 10000;
00007     double  B0, a1, a2, b1, c0, F0, T;
00008     F0 = 60;    // or 50
00009     B0 = 100.;
00010     T  = 1./fs;
00011     a1 = 2. * exp(-M_PI * B0 * T) * cos(2. * M_PI * F0 * T);
00012     a2 = -exp(-2. * M_PI * B0 * T);
00013     b1 = -2. * cos(2. * M_PI * F0 * T);
00014     c0 = (1-a1-a2)/(2+b1);
00015     printf("a1 = %f\n", a1);
00016     printf("a2 = %f\n", a2);
00017     printf("b1 = %f\n", b1);
00018     printf("c0 = %f\n", c0);
00019     return 0;
00020 }
00021 60Hz
00022     a1 = 1.936768
00023     a2 = -0.939101
00024     b1 = -1.998579
00025     c0 = 1.642174
00026 50Hz
00027     a1 = 1.937188
00028     a2 = -0.939101
00029     b1 = -1.999013
00030     c0 = 1.938304
00031 */
00032 
00033 float notch_filter1(float data){
00034     y1[0] = data + a1*y1[1] + a2*y1[2];
00035     float reault = y1[0] + b1*y1[1] + y1[2];
00036     y1[2] = y1[1];
00037     y1[1] = y1[0];
00038     return(reault);
00039 }
00040 
00041 float notch_filter2(float data){
00042     y2[0] = data + a1*y2[1] + a2*y2[2];
00043     float reault = y2[0] + b1*y2[1] + y2[2];
00044     y2[2] = y2[1];
00045     y2[1] = y2[0];
00046     return(reault);
00047 }