October 14, 2011

sushmars sushmars
Lab Rat
13 posts

painting on qimage or qpixmap taking time in real time plotting


if i plot ECG graph on qimage or qpixmap, i wont get proper heart beat (for 180 i will get 237 —- data is missing, painting taking time). If i comment draw graph, i am getting proper heart beat value. How to synchronize my application with graph. Which method makes less time consume.

Thanks in advance…

4 replies

October 15, 2011

Kxyu Kxyu
Lab Rat
145 posts

You should provide some code, it seems that you are doing something wrong as it should not take a lot of time to draw a simple graph (basically just put some pixels). the thing you can try is to separate reading a storing data from drawing graph into different threads.

BTW if heartbeat is 237 instead of 180 doesn’t it meant that a graph is kind of being drawn FASTER then it should be? maybe you just messed with an x axis

October 15, 2011

sushmars sushmars
Lab Rat
13 posts

from one thread i am getting ecg data through SPI and writing to pipe, calculating heart beat value . on another thread i am reading from that pipe and giving signal to slot. in slot i am calling DrawECG function which has painting things.
in GUI (ui) i have qlable—ANSiscope_Graph_label

in constructor i am declaring painter and pixmap

  1. ECGImagePainter = new QPainter;
  2.     ecgpixmap = new QPixmap(236,97);
  3.     ecgpixmap->fill(Qt::white);
  5. in DrawECG(int data) function i am plotting ECG graph
  6. {
  7.   ansiscopeMainWindow->ui->ANSiscope_Graph_label->setPixmap(*ecgpixmap);
  8.    ECGImagePainter->begin(ecgpixmap);
  9.         if(firstTimeECG)
  10.         {
  11.             ECGImagePainter->setPen(Qt::black);
  12.             firstTimeECG = 0;
  13.         }
  15.         ECGgraph.Ypos = (ECGgraph.rightbottom.Y - ECGgraph.lefttop.Y) - (ECGgraph.Yunit * (data - ECGgraph.lYMin));
  16.         ECGgraph.currentplot.X=ECGgraph.currentplot.X+1;
  17.         ECGgraph.currentplot.Y=(int)ECGgraph.Ypos  ;
  19.         if(ECGgraph.currentplot.X >= ECGgraph.rightbottom.X)
  20.         {
  21.             ECGgraph.currentplot.X = 0;
  22.             ECGgraph.lastplot.X = 0;
  23.              ecgpixmap->fill(Qt::white);
  25.         }
  26.         ECGImagePainter->drawLine(ECGgraph.currentplot.X,ECGgraph.currentplot.Y,ECGgraph.lastplot.X,ECGgraph.lastplot.Y);
  29.         ECGgraph.lastplot.X = ECGgraph.currentplot.X;
  30.         ECGgraph.lastplot.Y = ECGgraph.currentplot.Y;
  31.         ECGImagePainter->end();
  33. }

two threads are in while(1), switching by sched_yield()
if i comment drawECG function in slot i will get proper results. if i plot ecg, ill get improper heart beat value.
calling once setpixmap statement in a drawecg function, i will get result but no graph on screen.
which is a real time plotting 1200 samples per second

[EDIT: code formatting, please wrap in @-tags, Volker]

October 17, 2011

Franzk Franzk
Lab Rat
830 posts

Best piece of advice: Don’t try plotting at 1200 Hz. Gather your data and draw at a maximum of 60 Hz. 30 Hz may even be sufficient for proper data. Don’t assume the operating system will provide you with the timing you need. As long as you’re sure you get all your data, store it somewhere until the next drawing moment has arrived. Getting real-time graphs is all about knowing when not to draw.

You can also optimize your drawing a bit by queueing up all lines you are going to draw, and feed them to QPainter::drawLines(), which is best practice in doing your own drawing anyway.


“Horse sense is the thing a horse has which keeps it from betting on people.”—W.C. Fields


June 12, 2012

www.swhweng.co.nr www.swhweng...
Lab Rat
184 posts

Greetings sushmars,

I am working on a similar task these days – trying to accomplish best quality plot for ECG signal from

physionet.org signals database.

Have you succeed to plot the data as required ?

Can you share the code for your application ? ( here or in private message )

If not, could that be purchased if yes how much does it cost ?


  ‹‹ help on my database class      QHeaderView: get numeric column index by name ››

You must log in to post a reply. Not a member yet? Register here!