Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: PID_VelocityExample TheProgram Passief_stuurprogramma Actief_stuurprogramma
Diff: EMG.h
- Revision:
- 4:963e903c2236
- Parent:
- 3:0662d78d9092
- Child:
- 5:7873900f62da
--- a/EMG.h Mon Oct 12 09:41:48 2015 +0000 +++ b/EMG.h Mon Oct 12 16:15:33 2015 +0000 @@ -2,7 +2,7 @@ #include <cmath> -int Fs = 200; // sampling frequency +const int Fs = 200; // sampling frequency const double low_b1 = 0.000944691843840; //filter coefficients - second order butterworth filters at 2 hz low and 25 hz high, coefficents based on Fs of 512. const double low_b2 = 0.001889383687680; const double low_b3 = 0.000944691843840; @@ -38,8 +38,7 @@ InterruptIn cali_button(PTA4); // initialize interrupt button for calibration stuff double cali_fact1 = 8; double cali_fact2 = 8; // calibration factor to normalize filter output to a scale of 0 - 1 -double cali_array1[2560] = {}; // array to store values in for channel 1 -double cali_array2[2560] = {}; // array to store values in for channel 2 + void sample_filter() { @@ -56,34 +55,23 @@ void calibrate() // function to calibrate the emg signals from the user. It takes 5 seconds of measurements of maximum output, then takes the max and normalizes to that. { - pc.printf("Calibration starting \n\r"); - double cali_max1 = 0; // declare max - double cali_max2 = 0; cali_fact1 = 1; cali_fact2 = 1; - - for(int cali_index = 0; cali_index < 2560; cali_index++) + double cali_max1 = 0; double cali_max2 = 0; + for(int i = 0; i < 5*Fs; i++) { sample_filter(); - cali_array1[cali_index] = y1; - cali_array2[cali_index] = y2; - wait((float)1/Fs); - } - for(int cali_index2 = 0; cali_index2<2560; cali_index2++) - { - if(cali_array1[cali_index2] > cali_max1) - { - cali_max1 = cali_array1[cali_index2]; - } - if(cali_array2[cali_index2] > cali_max2) - { - cali_max2 = cali_array2[cali_index2]; - } - } - cali_fact1 = (double)1/cali_max1; - cali_fact2 = (double)1/cali_max2; - delete[] &cali_array1; - delete[] &cali_array2; - pc.printf("Calibration factor 1: %f\n\rCalibration factor 2: %f\n\r", cali_fact1, cali_fact2); + if(y1 > cali_max1) + { + cali_max1 = y1; + } + if(y2 > cali_max2) + { + cali_max2 = y2; + } + wait(1/Fs); + } + cali_fact1 = 1.0/cali_max1; + cali_fact2 = 1.0/cali_max2; } /*