Mbed to Matlab plotting graph with peaks

Hi all, I am, Chong and I am very new to programming and hope someone can help me:) I am currently using a Mbed with an accelerator which is placed on the chest to measure the chest expanding and compressing ,therefore there should be a change in the Z axis of the sensor.
The mbed program will store up to 1000 data in 10 seconds.
The current problem I am facing now is I need to find solutions to
1)how to program matlab and to plot the graph,Z axis only
2)Point out the number of peaks in the waveform , which equal to the number of chest rising or breaths the user took within that 10 seconds time frame.
3) Hence or otherwise display the number of peaks found in the waveform
Thank you all in advance
Have a great day!
Here is the current code for my mbed
#include "mbed.h" LocalFileSystem local("local"); Serial pc(USBTX,USBRX); Ticker in; AnalogIn x_in(p17); AnalogIn y_in(p18); AnalogIn z_in(p19);
const int maxReadings = 1000; float measurmentArray[maxReadings][3]; volatile int readingNumber = 0;
void update() { if (readingNumber < maxReadings) { measurmentArray[readingNumber][0]=x_in; measurmentArray[readingNumber][1]=y_in; measurmentArray[readingNumber][2]=z_in; readingNumber++;}}
main () {
int nextReading = 0;
in.attach_us(&update,10000);//1000 hertz
while (nextReading<maxReadings ) { //process until no more space
if (readingNumber > nextReading) { // there is new data
nextReading = readingNumber-1; // the index of the last value written to the array
float x,y,z; // copy values to a local variables
x=measurmentArray[nextReading][0];
y=measurmentArray[nextReading][1];
z=measurmentArray[nextReading][2];
pc.printf("X-%5.2f Y-%5.2f Z-%5.2f \n",x, y, z);
nextReading++;
}
}
// write array in the file txt/csv
FILE *fp = fopen("/local/Record.csv", "a");
if (fp) {
for (int i=0;i<maxReadings;i++) {
fprintf(fp, "%f , %f , %f \r ",measurmentArray[i][0],measurmentArray[i][1],measurmentArray[i][2]);
}
fclose(fp);
} else {
pc.printf("ERROR. Failed to open output file\r\n");
}
}

Answers (0)

Asked:

on 4 Nov 2016

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!