PDA

View Full Version : How Can i Load data from file.ecg and plot it ?



ahmed ali
19th March 2012, 20:16
hello every body, i am a student in engineering, graduation stage.
i want to read data from file has an extension of .ecg or any extension and plot these data.
how can i do this ?
i am using qt 4.7.4 version
plz help me as i am really need this program.
thanks in advance

ChrisW67
19th March 2012, 22:42
You seem to be expecting some QReadAndInterpretECGorAnyFile class for an unspecified meaning of "ECG" or "any" file... it isn't going to happen.

The general proces implied by your general requirement is; open the file (QFile), read and interpret the file content (QFile, QIODevice, and/or QTextStream), and do something with the resulting data.

Qwt (http://qwt.sourceforge.net/) offers reasonable plotting facilities and also has a sub-forum here (http://www.qtcentre.org/forums/23-Qwt).

ahmed ali
20th March 2012, 06:48
thanks a lot for your help
but when i use this code i have some errors :(
i am using GUI application
can you help me to fix this?. sorry for annoying you but i am a beginner ... thanks in advance


#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QFile>
#include<QtCore>
#include<QtGui>
#include<QTextStream>

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->label->setText("Hello User :)");

}

MainWindow::~MainWindow()
{
delete ui;
}

void MainWindow::on_pushButton_clicked()
{
QFile file("C:/ahmad/ecg test/tst.txt");
if(!file.open( QFile::ReadOnly | QFile::Text))
{
ui->label->setText(" OOP : File Cant be Opened");
return;
}
QStringList list;
QTextStream in(&file);
ui->label->setText("DONE : file opened");
while (!in.atEnd())
{
list << in.readLine();
}
file.close();
data = new double[list.size()];
for(int i = 0; i< list.size(); i++)
{
data[i] = list[i].toDouble();
}
dataSize = list.size();
}


and the errors are:
C:\examples\Plot-build-desktop-Qt_4_8_0_for_Desktop_-_MSVC2010__Qt_SDK__Debug\..\..\Examples\Plot\mainw indow.cpp:38: error: C2248: 'QWidget::data' : cannot access private member declared in class 'QWidget'
C:\examples\Plot-build-desktop-Qt_4_8_0_for_Desktop_-_MSVC2010__Qt_SDK__Debug\..\..\Examples\Plot\mainw indow.cpp:38: error: C2440: '=' : cannot convert from 'double *' to 'QWidgetData *'
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
C:\examples\Plot-build-desktop-Qt_4_8_0_for_Desktop_-_MSVC2010__Qt_SDK__Debug\..\..\Examples\Plot\mainw indow.cpp:41: error: C2248: 'QWidget::data' : cannot access private member declared in class 'QWidget'
C:\examples\Plot-build-desktop-Qt_4_8_0_for_Desktop_-_MSVC2010__Qt_SDK__Debug\..\..\Examples\Plot\mainw indow.cpp:41: error: C2679: binary '=' : no operator found which takes a right-hand operand of type 'double' (or there is no acceptable conversion)
C:\QtSDK\Desktop\Qt\4.8.0\msvc2010\include\QtGui/qwidget.h(143): could be 'QWidgetData &QWidgetData::operator =(const QWidgetData &)'
while trying to match the argument list '(QWidgetData, double)'
C:\examples\Plot-build-desktop-Qt_4_8_0_for_Desktop_-_MSVC2010__Qt_SDK__Debug\..\..\Examples\Plot\mainw indow.cpp:43: error: C2065: 'dataSize' : undeclared identifier

ChrisW67
20th March 2012, 07:02
Where is the variable data declared? It appears that it is not declared, and coincidentally there is an existing member data of incompatible type inherited from QWidget, which is what the error message is telling you.

Rather than using a bare array (i.e. data) you should consider using QList or QVector which will manage the memory for you. You could also consider going straight from the line read from file to a QList<double> without the intervening QStringList.

ahmed ali
20th March 2012, 07:29
thanks a lot ChrisW67,
I tried to use this code:

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QFile>
#include<QtCore>
#include<QtGui>
#include<QList>
#include<QTextStream>

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->label->setText("Hello User :)");

}

MainWindow::~MainWindow()
{
delete ui;
}

void MainWindow::on_pushButton_clicked()
{
QFile file("C:/ahmad/ecg test/tst.txt");
if(!file.open( QFile::ReadOnly | QFile::Text))
{
ui->label->setText(" OOP : File Cant be Opened");
return;
}
QList<double> list;
QTextStream in(&file);
ui->label->setText("DONE : file opened");
while (!in.atEnd())
{
list << in.readLine();
}
file.close();

but unfortunately have some error too :(
C:\examples\Plot-build-desktop-Qt_4_8_0_for_Desktop_-_MSVC2010__Qt_SDK__Debug\..\..\Examples\Plot\mainw indow.cpp:36: error: C2678: binary '<<' : no operator found which takes a left-hand operand of type 'QList<T>' (or there is no acceptable conversion)

and if i have loaded the data to Qlist<double> list , how can i then plot these data ?

ChrisW67
20th March 2012, 08:14
You are trying to append a QString to a list of doubles. Perhaps you need to convert to double like you were before. Is there only one number on each line?

ahmed ali
20th March 2012, 08:36
yes, every line has one value
(i.e 1.8600000e+03
1.8640000e+03
1.8660000e+03
1.8550000e+03
1.8660000e+03
1.8760000e+03

Spitfire
20th March 2012, 16:44
Hmmm you need at least two coordinates to plot anything.
The values you have are probably Y values where time increases in constant.

try this:


MainWindow::MainWindow( QWidget* p )
:
QMainWindow( p ),
plot( new QwtPlot( this ) ), // create plot widget
x( QVector< double >() ),
y( QVector< double >() )
{
QToolBar* tb = this->addToolBar( "File" );
tb->addAction( "Open File", this, SLOT( openFile() ) );
this->setCentralWidget( this->plot );
}

void MainWindow::openFile( void )
{
QString str = QFileDialog::getOpenFileName( this );
if( !str.isEmpty() )
{
QwtPlotCurve* curve = this->getCurve( str );

if( !curve )
{
return;
}

curve->attach( this->plot );
this->plot->replot();
}
}

QwtPlotCurve* MainWindow::getCurve( const QString& path )
{
int size = 0;

QFile src( path );
if( !src.open( QIODevice::ReadOnly ) )
{
return NULL;
}

while( !src.atEnd() )
{
// x is placeholder if you don't have anything better
this->x.append( size ); // this->y is QVector< double > which need to be kept alive as long as curve uses the data!
this->y.append( src.readLine().toDouble() ); // this->x is QVector< double > which need to be kept alive as long as curve uses the data!
++size;
}

QwtPlotCurve* c = new QwtPlotCurve();
c->setSamples( this->x.at( idx ).data(), this->y.at( idx ).data(), size );
return c;
}

It's all you need to load a file and plot it.

ahmed ali
20th March 2012, 16:51
thanks a lot i will try it now and i will reply :)

ahmed ali
20th March 2012, 23:25
thanks a lot
i have tried it but having some errors :(


#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QString>

#include <qwt_plot.h>


MainWindow::MainWindow( QWidget* p ):
QMainWindow( p ),
plot( new QwtPlot( this ) ), // create plot widget
x( QVector< double >() ),
y( QVector< double >() )
{
QToolBar* tb = this->addToolBar( "File" );
tb->addAction( "Open File", this, SLOT( openFile() ) );
this->setCentralWidget( this->plot );
}

void MainWindow::openFile( void )
{
QString str = QFileDialog::getOpenFileName( this );
if( !str.isEmpty() )
{
QwtPlotCurve* curve = this->getCurve( str );

if( !curve )
{
return;
}

curve->attach( this->plot );
this->plot->replot();
}
}

QwtPlotCurve* MainWindow::getCurve( const QString& path )
{
int size = 0;

QFile src( path );
if( !src.open( QIODevice::ReadOnly ) )
{
return NULL;
}

while( !src.atEnd() )
{
// x is placeholder if you don't have anything better
this->x.append( size ); // this->y is QVector< double > which need to be kept alive as long as curve uses the data!
this->y.append( src.readLine().toDouble() ); // this->x is QVector< double > which need to be kept alive as long as curve uses the data!
++size;
}

QwtPlotCurve* c = new QwtPlotCurve();
c->setSamples( this->x.at( idx ).data(), this->y.at( idx ).data(), size );
return c;
}
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
}

MainWindow::~MainWindow()
{
delete ui;
}


1st problem is i QWT library not installed and i have read lot of threads but unfortunately i cant install it :(
2nd problem is i am a beginner and i feel there is some thing wrong in my above code
can i get help to fix these errors?
thanks in advance

ChrisW67
21st March 2012, 00:13
1st problem is i QWT library not installed and i have read lot of threads but unfortunately i cant install it
If this is the case then you cannot even compile the code above.

You do not need forum threads, blogs or Google searches to install Qwt (http://qwt.sourceforge.net/). The instructions are in the INSTALL (http://qwt.sourceforge.net/qwtinstall.html) file that comes with the Qwt source (as Uwe is constantly explaining (http://www.qtcentre.org/threads/46501-how-to-install-qwt?p=210215#post210215)).

If you follow the instructions in the INSTALL file, not somewhere else, and strike a problem then post a description of exactly what you did, and what you got that seems broken or wrong. The Qwt sub-forum might be a better place for that.


2nd problem is i am a beginner and i feel there is some thing wrong in my above code
Possibly, maybe even probably, but wait until you can build it before you worry about this.

ahmed ali
21st March 2012, 00:45
Thanks a lot, but i am wondering why there is no video tutorial that show us how to install QWT library as i have tried several times but always there are errors
all i can say now i will try again and thanks for your help :)

ChrisW67
21st March 2012, 02:08
There's no video tutorial because the instructions in the INSTALL file are both complete and adequate.

Since you have not explained the problem you are experiencing actually is we are unable to help.

ahmed ali
21st March 2012, 09:23
thanks a lot,
I have done these steps to install QWT in my windows:
1.i downloaded the qwt library called qwt-6.0.1
2.unzipped it to C:/Qwt
3.then i started QT command prompt i found it in ( start > QtSDK > Desktop > Qt 4.8.0 for Desktop (MSVC 2010)
4.cd C:\QWT\qwt-6.0.1 this is the folder where i put the unzipped library
5.qmake qwt.pro this command executed successfully
6. when i try to execute nmake or nmake install i have this msg: 'nmake' is not recognized as an internal or external command, operable program or batch file

i stooped at this point :( can any body help me ?
thanks in advance

Spitfire
21st March 2012, 11:22
Try mingw32-make instead.

ahmed ali
21st March 2012, 12:40
unfortionatly i have the same error msg:(
msg: 'mingw32-make' is not recognized as an internal or external command, operable program or batch file

Added after 11 minutes:

thanks to all one tried to help me :) but can i ask you (ChrisW67) and all experts can you please make a tutorial video to help us to install QWT library? really this will help us greatly, i hope you can do this for us ... this will be great Known to us

thanks in advance
Ahmed Ali

Spitfire
21st March 2012, 13:26
So, did you managed it in the end?

On another note - I understand vieo tutorial for cooking or building fusion generator (as a help, not instead of written word), but I totally fail to see a benefit of it for compiling a library or calculating your tax return...
Maybe it's only me...

wysota
21st March 2012, 19:44
thanks to all one tried to help me :) but can i ask you (ChrisW67) and all experts can you please make a tutorial video to help us to install QWT library? really this will help us greatly, i hope you can do this for us ... this will be great Known to us

Sorry to be blunt, but if you don't even know what compiler you are using and how to use it then what good will a video tutorial on installing Qwt do? If you want to act as a programmer then you can't rely on having video tutorials on everything you are trying to do.

ChrisW67
21st March 2012, 23:17
6. when i try to execute nmake or nmake install i have this msg: 'nmake' is not recognized as an internal or external command, operable program or batch file
The Qt command prompt set the shell PATH to find the components of the Qt SDK. If, and only if, you are using the bundled MingW compiler this is also present in the environment.

You are using the Microsoft C++ compiler that expects a raft of stuff in its environment, the most important of which is the compiler/tool binaries in the PATH. When you use Microsoft's IDE this is all hidden for you (IMHO to the detriment of understanding). Microsoft, since at least the early '90s, provides a shell script called vcvars32.bat for Setting the Path and Environment Variables for Command-Line Builds (http://msdn.microsoft.com/en-us/library/f2ccy3wt%28v=vs.90%29.aspx) (there may be a 64-bit version also). Execute this first after opening the Qt command prompt and you should find that things work better. You will need this to build Qt or any third party library, module etc. built from the command line: this is not unique to Qwt. I cannot tell you which version or where you have the Microsoft compiler installed so I cannot give you the exact command to type.

I think it perfectly reasonable that every set of install instructions for a library, like Qwt, assumes that the programmer has a working compiler environment. To expect otherwise is to expect the library author to have access to every possible permutation of system and compiler and produce a blow-by-blow set of instructions for each. Having done that you can be 100% certain that they will still not match some programmer's particular environment, and they will complain. The majority of blogs and other attempts to provide blow-by-blow instructions for Qwt fail in that way and generally demonstrate the lack of understanding of the author.

ahmed ali
22nd March 2012, 07:05
Master of zen << thanks a lot for your advice, but when i asked for a video tutorial this is as i am a beginner in Qt and i thought that i have something wrong in my setting.


ChrisW67 << Lot of thanks for helping me, i have read your Reply and i will try it now.

wysota
22nd March 2012, 08:50
Master of zen << thanks a lot for your advice, but when i asked for a video tutorial this is as i am a beginner in Qt and i thought that i have something wrong in my setting.
Before you start learning how to run, first you have to learn how to stand on your feet.

ahmed ali
22nd March 2012, 12:54
ChrisW67 << again, thanks a lot for helping me :) finally i installed it correctly :)

Master of zen << thanks a lot for your Precious Advices :)

ahmed ali
26th March 2012, 22:55
Hello Everybody :)
I have a file with extension of ECG (Demo.ecg) that is contain a ECG signals, but i have a problem to load this file and plot it using Qwt :(
http://www.mediafire.com/?3ngo1nwxcbb6z9c
can any one help me?
thanks in advance

ChrisW67
26th March 2012, 23:47
Why start a new thread for the same problem? Please attach the file to your post rather than leave it on on a third-party site.

Now we know that the ECG file is not a text file this somewhat changes the solution you were attempting in the other thread. QTextStream is not the correct tool for the job: the input is not text. Do you know what the binary data layout is?

ahmed ali
27th March 2012, 11:13
thanks a lot :)
sorry for posting new thread about the same problem.

what do you mean by "binary data layout"?
if you mean the data of ecg file,
yes, the binary data layout is (for example)

-0.00300000000000000
-0.00200000000000000
-0.00100000000000000
0
0.00200000000000000
0.00400000000000000
0.00400000000000000
0.00600000000000000
0.00600000000000000
0.00700000000000000
0.00800000000000000
0.00900000000000000
0.0100000000000000
0.0100000000000000
0.00800000000000000
0.00600000000000000
0.00200000000000000
-0.00100000000000000
-0.00300000000000000
-0.00300000000000000
-0.00300000000000000
-0.00100000000000000
0.00100000000000000
0.00400000000000000
0.00500000000000000
0.00400000000000000
0.00200000000000000
-0.00200000000000000
-0.004000
My problem is how to load these data from the file of extension of ECG and plot it
can i convert this file format to txt format ? but using Qt?
thanks in advance

MarekR22
27th March 2012, 13:43
As far I could find *.ecg file is a binary file.
If you have some documentation what is the format of the file (binary layout) then I can help you how to read those data and how to plot them with Qwt6.

wysota
27th March 2012, 13:58
My problem is how to load these data from the file of extension of ECG and plot it
can i convert this file format to txt format ?
You have to understand one thing. The extension of a file does not determine its contents. There may be several types of file using the same file extension. I have seen one file format for electrocardiography but that was indeed a textual format (as far as I read on their webpage) and what you provided is a binary file. Without reverse engineering the file it is not possible for us to determine the layout of the file and I'm sure nobody here is going to spend hours of their time analyzing your file. So please do your homework and find out (maybe from a person who gave you the file?) what the file really is and whether there are already existing libraries that can read this format and output numerical data such as those you have pasted in your post. Once you have those numbers, plotting them should be simple.

ahmed ali
27th March 2012, 17:37
As far I could find *.ecg file is a binary file.
If you have some documentation what is the format of the file (binary layout) then I can help you how to read those data and how to plot them with Qwt6.

thanks in advance for your help i will try to find some documentation what is the format of the file (binary layout)

master of zen <<< OK