8 #include "libFiles/QRSDET.H" 9 #include "libFiles/QRSFILT.CPP" 17 #include <QTextStream> 18 #include <QRegularExpression> 37 if (myFile.open(QIODevice::ReadOnly | QIODevice::Text)) {
39 QTextStream ecgInfo(&myFile);
40 QVector<int > ecgVals;
41 QVector<double> timeData;
43 if (!ecgInfo.atEnd()) {
44 QString strVals = ecgInfo.readLine();
49 while (!ecgInfo.atEnd()) {
51 strVals = ecgInfo.readLine();
52 QStringList strPieces = strVals.split(QRegularExpression(
"\\s+"));
55 if (strPieces.length()==4) {
56 tmp=strPieces[2].toDouble();
57 ecgVals.append((tmp*500));
60 else if (strPieces.length()==3) {
61 tmp=strPieces[2].toDouble();
62 ecgVals.append((tmp*500));
64 else if (strPieces.length()==5){
66 tmp=strPieces[2].toDouble();
67 ecgVals.append((tmp*500));
70 std::cerr <<
"Wrong File" << std::endl;
75 QVector<double> qrsPeaks;
76 extractRtoR(&ecgVals, &qrsPeaks);
81 for (
int i; i<qrsPeaks.length(); i++){
82 tmp=tmp+(qrsPeaks.at(i));
85 if (qrsPeaks.length()>10){
87 saveAsIbiFile(&qrsPeaks);
90 std::cerr <<
"Not enough R peaks detected" << std::endl;
91 qDebug(
"Time elapsed: %d ms", time.elapsed());
103 void ConvertEcgToIbi::extractRtoR(QVector<int>* input, QVector<double>* output) {
105 output->append(
QRSDet(input->takeFirst(),1));
108 while (!input->empty()) {
109 tmpQrs=
QRSDet(input->takeFirst(),0);
111 count=count+1000/sampRate;
114 output->append((count+1000/sampRate)/1000);
122 void ConvertEcgToIbi::saveAsIbiFile(QVector<double>* input){
123 std::cerr << input->length() <<std::endl;
124 QFile outFile(fname +
"_RR.txt");
126 if (!outFile.open(QIODevice::WriteOnly | QIODevice::Text)) {
128 std::cerr <<
"Failed to open data file for write" << std::endl;
130 QTextStream out(&outFile);
132 qDebug() <<
"Writing " << input->length() <<
" samples to " << fname <<
"..." << endl;
134 out <<
"Length:" <<
"\t" << QString::number(input->length()) <<
"\n";
135 out <<
"[s]" <<
"\t" <<
"[s]" <<
"\n";
136 while (!input->empty()){
137 tmp=input->takeFirst();
139 out << QString::number(time,
'f', 3) <<
"\t" 140 << QString::number(tmp,
'f', 3) <<
"\n";
144 std::cerr <<
"Samples saved in text format" << std::endl;
void sendFileData(QVector< double > qrsPeaks, QVector< double > timeData)
sendFileData
ConvertEcgToIbi(QString fileName, QObject *parent=NULL)
ConvertEcgToIbi.
int QRSDet(int, int)
QRSDet Function used for the QRS-detection.