Code:///////////////////////////////////////////////////////// // INCLUDES #include <iostream.h> // delcare the header files #include <fstream.h> // to be included ///////////////////////////////////////////////////////// ///////////////////////////////////////////////////////// // DEFINES #define DEAD_BAND_LIMIT 8 ///////////////////////////////////////////////////////// ///////////////////////////////////////////////////////// // FILE STREAMS ifstream fin ; // declare the input file stream ofstream fecgA ; // delcare the output file stream for ECGA ofstream fecgB; // declare the output file stream for ECGB ///////////////////////////////////////////////////////// ///////////////////////////////////////////////////////// // PROTOTYPES void decodeData (int counter, int &relativeA, int &relativeB, int datastoreA[], int datastoreB[]) ; ///////////////////////////////////////////////////////// ///////////////////////////////////////////////////////// // used to limit the stop values from being wrapped void limitValues(int &relativeA, int &relativeB) { // Limit values for next iteration... if(relativeA > (4095 - 503)) { relativeA = 4095 - 503 ; } else if(relativeA < 503) { relativeA = 503 ; } if(relativeB > (4095 - 503)) { relativeB = 4095 - 503 ; } else if(relativeB < 503) { relativeB = 503 ; } } ///////////////////////////////////////////////////////// ///////////////////////////////////////////////////////// // getData is called from the main, it is used to read in // data from the ECG dat file and un-encodes the relative // data into absolute data .. void getData (int &counter, char block[], int &relativeA, int &relativeB, int datastoreA[], int datastoreB[]) { char holdComma ; // used to handle the commas in the file // the tempX variables are used to hold the value of // the encoded data while the absolute value is calculated fin >> block ; //cout << block << endl; fin >> relativeA ; //cout << relativeA << endl ; fin >> holdComma ; //cout << holdComma ; fin >> relativeB ; //cout << relativeB << endl ; datastoreA[0] = relativeA; datastoreB[0] = relativeB; while (counter<=191) { decodeData (counter, relativeA, relativeB, datastoreA, datastoreB) ; counter ++ ; } } ///////////////////////////////////////////////////////// ///////////////////////////////////////////////////////// // decode data void decodeData (int counter, int &relativeA, int &relativeB, int datastoreA[], int datastoreB[]) { int tempA = 0, tempB = 0 ; char holdComma ; fin >> tempA ; // hold temp value of channel A if ((0<=tempA)&&(tempA<=503)) { // computes and stores the absolute value (channel A) datastoreA [counter] = datastoreA[counter - 1] + tempA; } else if ((505<=tempA)&&(tempA<=519)) { counter-- ; cout << "ERROR - Offset is out of Range: 505 - 519 !!!" <<endl; fecgA.close() ; fecgB.close() ; //return ; can I call this as it is now??? } else if (tempA == 504) { datastoreA [counter] = 4095 - DEAD_BAND_LIMIT ; cout << "POSITIVE SATURATION: @ Element " << counter << endl ; } else if (tempA == 520) { datastoreA [counter] = DEAD_BAND_LIMIT ; cout << "NEGATIVE SATURATION: @ Element " << counter << endl ; } else { datastoreA [counter] = datastoreA[counter-1] - (1024 - tempA); } fin >> holdComma ; // holds the comma fin >> tempB ; // holds temp value of channel B if ((0<=tempB)&&(tempB<=503)) { // computes and stores the absolute value (channel A) datastoreB [counter] = datastoreB[counter - 1] + tempB; } else if ((505<=tempB)&&(tempB<=519)) { counter--; cout << "ERROR - Offset is out of Range: 505 - 519 !!!" <<endl; fecgA.close() ; fecgB.close() ; //return ; can I call this as it is now??? } else if (tempB == 504) { datastoreB [counter] = 4095 - DEAD_BAND_LIMIT ; cout << "POSITIVE SATURATION: @ Element " << counter << endl ; } else if (tempB == 520) { datastoreB [counter] = DEAD_BAND_LIMIT ; cout << "NEGATIVE SATURATION: @ Element " << counter << endl ; } else { datastoreB [counter] = datastoreB[counter-1] - (1024 - tempB); } limitValues(relativeA, relativeB) ; } ///////////////////////////////////////////////////////// ///////////////////////////////////////////////////////// // fileOutput is used to write all the computed data from // the arrays to a file void fileOutput (int datastoreA[], int datastoreB[]) { // file output for channel A! int outcount = 0 ; for (outcount = 0; outcount<=191; outcount++) { fecgA<<datastoreA[outcount] << endl ; } // open channel B output file for (outcount =0; outcount<=191; outcount++) { fecgB<<datastoreB[outcount]<< endl ; } } ///////////////////////////////////////////////////////// ///////////////////////////////////////////////////////// // VOID MAIN void main() { int relativeA = 0, relativeB = 0 ; int counter = 1 ; int datastoreA[191] ; int datastoreB[191] ; char block[4] ; fin.open("smallECG.dat") ; if (!fin) { cout << "Error Opening File ... " << endl ; } else { fecgA.open("ecgA.dat") ; fecgB.open("ecgB.dat") ; int testcount = 1 ; while(fin) { cout << "Loop run number: " << testcount << endl ; getData (counter, block, relativeA, relativeB, datastoreA, datastoreB) ; fileOutput (datastoreA, datastoreB) ; testcount++ ; // problems with the eof test.... what tested on, first 3 runs work now??? } fecgA.close(); fecgB.close(); } fin.close() ; } /////////////////////////////////////////////////////////
Some Sample Data....
Block
2048, 2048
1023, 0
1, 0
0, 1021
1022, 5
2, 1022
1, 1017
1016, 20
1019, 32
6, 1
8, 1012
1022, 8
1020, 5
7, 1012
1010, 11
956, 41
987, 1012
91, 944
294, 2
383, 96
65, 38
673, 943
701, 877
957, 927
13, 40
12, 105
23, 54
1022, 15
1021, 14
6, 1
4, 2
4, 7
3, 3
6, 1023
7, 1
8, 3
6, 0
6, 1
7, 1
10, 1
10, 3
11, 1
12, 1021
17, 1022
16, 1
12, 1022
16, 1023
11, 1
2, 1023
4, 2
1023, 3
1011, 0
1007, 1022
1012, 3
1006, 4
986, 1021
978, 1021
1004, 1
1019, 2
1010, 1021
1018, 1023
1020, 1021
1008, 0
1012, 5
2, 1
5, 1020
7, 4
10, 5
7, 1
8, 5
7, 2
1023, 0
0, 1022
13, 1023
3, 2
1011, 4
3, 0
10, 1023
1019, 3
0, 0
1, 1017
1013, 1021
1023, 4
8, 0
1, 1023
1023, 5
1019, 0
1018, 1019
1022, 1
9, 4
12, 2
1021, 0
1008, 1022
12, 5
27, 3
1011, 1021
998, 1021
5, 0
9, 1023
1022, 0
4, 3
12, 10
11, 11
3, 5
5, 9
30, 16
22, 1023
1014, 1009
1018, 1017
5, 1019
1015, 1013
1000, 1018
999, 1021
2, 1019
15, 0
1014, 1
1001, 1020
3, 1022
12, 2
1010, 5
1022, 1018
13, 1021
978, 37
955, 17
28, 943
203, 968
379, 80
241, 91
803, 1008
625, 912
865, 885
5, 988
5, 90
23, 84
14, 21
1017, 16
9, 11
8, 1
1021, 4
5, 5
17, 3
1, 4
1020, 2
10, 1023
12, 4
6, 4
8, 0
9, 1
13, 0
15, 1022
11, 2
12, 2
23, 0
16, 2
1, 2
2, 3
6, 3
1022, 2
1018, 1
1015, 0
1007, 0
1000, 0
997, 1
997, 1
1000, 0
1007, 1021
1011, 1021
1011, 1
1022, 1
5, 1023
1019, 0
1016, 1
5, 0
3, 5
1023, 2
1, 1023
1023, 0
0, 1022
9, 1023
6, 7
0, 1
1023, 1019
1023, 1
1, 1
5, 1022
1, 1021
1017, 0
1022, 0
4, 0
1022, 1022
1021, 0
0, 2



LinkBack URL
About LinkBacks


