ECG Recorder

12
Before I start, I would like to excuse myself about my poor English skills, my writing, and bad quality of the published materials. But this is done because writing is a time consuming  job, and when it is on English I think you will understand me.  Introduction This progra m is a full ended open code project. It concerns to long time medical ECG single channel record & one additional sensor record - signal from velo test power generator. You can find code for how you can build your drivers without using DMA con troller, this is very good for data acquisition systems just like medical ECG recorders. To use this code, you need to compile all 3 DLL files: y driver y visualization On the end of this work, compile the application pr ogram using just built DLL files. So, use a demo file to see what it can do for you. Application can make DSP on the input signal and can detect ECG QRS-PR-QT segments. Electro Cardio Graph or simply ECG (EKG) is a very useful medical instrument, its purpose is to h elp doctors easily diagnose human or animals' heart activity and t o detect abnormal functions of the heart muscle. Today, it is not so difficult to construct such a device, but there are many standards concerned to human safety (direct & indirect) especially for intensive health care usage. So, I dont mind to t alk about them! But there are many other ECG applications, such as rehabilitation holter monitors (long time ECG recorders), remote holter monitors and some sports applications such as veloergometry ECG testers. The last application can be met in many types and varieties from special MEDICAL to ACTIVE TRAINER ECG TESTERS. "ECG_1" software is concerned to sport ECG veloergome try. Researches that can be made using such a software and non professional ECG instrumentation PC card can help a lot for these people (students) who are int erested in these fields: sports, medicine, medical electronics and much more. The main purpose of the project is not to construct and design software and hardware; there is a bigger objective! Creating free, fully opened, database for medical (physiological) chemical, electrical and image records. I know, this is already done in big hospitals and universities, but it is still too hard for beginner students and any others to get this information correct and free! In additio n, I think that this one must be corrected! Why? Because making an object oriented medical (sports & physiological) database system containing different long time records and results, such as veloergometry, can be very helpful for research (not only for students). This is my opinion, you may have another, but let's begin! ECG signal. Before you try t o understand the software, I think that it is necessary to explain some of the parameters of the normal ECG signal. This signal contains the main segments: P, Q, R, S, T, c. You can see them on the next picture. Red line fixes the QRS time interval; it was made in software to h elp to see the time segments in the electrocardiogram.

Transcript of ECG Recorder

Page 1: ECG Recorder

8/3/2019 ECG Recorder

http://slidepdf.com/reader/full/ecg-recorder 1/12

Before I start, I would like to excuse myself about my poor English skills, my writing, and bad quality of the published materials. But this is done because writing is a time consuming job, and when it is on English I think you will understand me. 

Introduction

This program is a full ended open code project. It concerns to long time medical ECG singlechannel record & one additional sensor record - signal from velo test power generator. Youcan find code for how you can build your drivers without using DMA controller, this is verygood for data acquisition systems just like medical ECG recorders. To use this code, youneed to compile all 3 DLL files:

y  drivery  visualization

On the end of this work, compile the application program using just built DLL files. So, use ademo file to see what it can do for you. Application can make DSP on the input signal andcan detect ECG QRS-PR-QT segments.

Electro Cardio Graph or simply ECG (EKG) is a very useful medical instrument, itspurpose is to help doctors easily diagnose human or animals' heart activity and to detectabnormal functions of the heart muscle.

Today, it is not so difficult to construct such a device, but there are many standardsconcerned to human safety (direct & indirect) especially for intensive health care usage. So,I dont mind to talk about them! But there are many other ECG applications, such asrehabilitation holter monitors (long time ECG recorders), remote holter monitors and somesports applications such as veloergometry ECG testers. The last application can be met inmany types and varieties from special MEDICAL to ACTIVE TRAINER ECG TESTERS.

"ECG_1" software is concerned to sport ECG veloergometry. Researches that can be madeusing such a software and non professional ECG instrumentation PC card can help a lot forthese people (students) who are interested in these fields: sports, medicine, medicalelectronics and much more. The main purpose of the project is not to construct and designsoftware and hardware; there is a bigger objective! Creating free, fully opened, database formedical (physiological) chemical, electrical and image records. I know, this is already donein big hospitals and universities, but it is still too hard for beginner students and any othersto get this information correct and free! In addition, I think that this one must be corrected!Why? Because making an object oriented medical (sports & physiological) database systemcontaining different long time records and results, such as veloergometry, can be veryhelpful for research (not only for students). This is my opinion, you may have another, butlet's begin!

ECG signal. Before you try to understand the software, I think that it is necessary toexplain some of the parameters of the normal ECG signal. This signal contains the mainsegments: P, Q, R, S, T, c. You can see them on the next picture. Red line fixes the QRStime interval; it was made in software to help to see the time segments in theelectrocardiogram.

Page 2: ECG Recorder

8/3/2019 ECG Recorder

http://slidepdf.com/reader/full/ecg-recorder 2/12

 

For humans, it is not so difficult to detect them on the paper, and I maintain that is not sodifficult to show the PC to recognize them. In standard electrocardiography, we use 12recording channels, but in veloergometry applications, they are limited to one this signalis used to detect the heart rate/min. and to detect some rhythm anomalies? Search in theweb for: ECG time interval variability data. All these features are included inthe ECG  _1 main project class DSP_ ECG. Here, Ill try to explain the first and the main

detection technique, QRS segment detection.

Because I suppose that sportiest are normally healthy people, and probably have normalelectrocardiograms in this first ECG _1 version, for fast implementation of the project, Iused simplified QRS detecting algorithm, see below:? www.dsp.com?

1.  We will push the raw ECG input signal through a system of filters seeclass DSP_Filter.

a.  Use noht filter function to remove 50 or 60 Hz power line signal  

see voidDSP_Filter::RFilter_Noht and void DSP_Filter::WFilter

_Noht functions or use them directly.

b.  Use a low pass filter. If it is necessary, first try to use 100Hz low pass filter  see voidDSP_Filter::WFilter_Low100Hz, and if this filtration cant give

the proper quality, use 40Hz low pass

filter void DSP_Filter::WFilter_Low40Hz. Using lower filtration length isnot recommended because most popular ECG measurements have an interestof the signal spectrum 0.67Hz 40Hz.

2.  After proper filtration, ECG signal is ready to be detected.a.  First we will find the first difference of the ECG signal this is done by next

code:

X contains a filtered ECG signal array. Y contains a first difference of 

the ECG signal (X & Y are dynamic double precision arrays).

Collapse | Copy Code

for( i=0;i<length++;i++){*(Y+i) = *(X+i+1) - *(X+i);} 

3.  Therefore, this was the beginning! Now is the main algorithm, QRS detection. As Imentioned before in the picture above and as you can see, the standard QRScomplex contains high amplitude (approximately 0.5-3mV) short time deviationimpulse (50-200ms). From the main ECG waveform, it is simple to recognize QRScomplex. We will make this using first difference of the ECG signal (array Y). This is

done by finding the standard deviation of the signal  

Page 3: ECG Recorder

8/3/2019 ECG Recorder

http://slidepdf.com/reader/full/ecg-recorder 3/12

using double DSP_Filter::StandardDeviation. This function returns the

standard deviation of the double array signal. Using this result and going throughthe Y array, we will mark all points of this array that have values greater than

1.2*deviation:

Collapse | Copy Code

dev = dev*1.2; for(i=0;i<lenght-1;i++) { D = arD1[i]; 

Delta[i] = D; if(D>dev) *(AR_MINMAX+i) = 2; if(D<-dev) *(AR_MINMAX+i) = -2; 

There is a great chance that QRS segments are represented by these biggerdifferences, but this is not all!

4.  Finally, we have marker array (AR_MINMAX), that show to us points with bigger + & 

- deference (>1.2*dev). Using the array (AR_MINMAX), we go to the next step of our

simplified algorithm, decide what is QRS and what is not. Independent of the lowpass filtering (<40hz), in the ECG delta array Y, may be met some disturbances

(caused by physiological or physical external sources) that can produce singledeviations bigger than standard (dev). Moreover, if we suppose that eachmaximum value in the Y array is QRS, we will fall in a trap. As you can see from the

picture above, QRS is not a single pulse of logical 1, QRS is a compositewaveform, containing many bigger than standard deviation values with values + & -.Rest on this supposition, and some statistical information, QRS complex can be anyseries (at least 3 or 4) containing bigger deviation than standard dev Y. (This is a

very simplified algorithm, but it really works, and can be used in large varietiesof ECG signals after proper filtering).

This is done in the following lines of code:

Collapse | Copy Code

do{ i++;d_count++; } while(*(AR_MINMAX+i)==2); if(d_count>3) //we have QRS  

In the next steps of the function int DSP_ ECG::QRS_COUNT, we are finding and fixing the

maximum of R wave, minimum of S, and minimum of Q. Because the algorithm is not

simplified yet, I

m not going to explain it, but it works.

There are many students at technical universities all over the world, and there are manystandard projects to do. But the main difficulty for these my mates is how to show theirprojects working! It is too difficult when all that you study is not concerned about how tomake market compatible solutions, even if they are laboratory samples. To make yourhardware working on a standard PC is a nasty work. To build sample test hardware is notthe same as to write drivers, and further more applications to use them. But in many cases,it is enough to write a simple program to show your concepts on possible customers or

Page 4: ECG Recorder

8/3/2019 ECG Recorder

http://slidepdf.com/reader/full/ecg-recorder 4/12

colleagues. It is very funny to see a completed project; just ready to fly in space, but usingExcel graphs to show its operation /just like my article/.

To complete this point, it is too important to know that writing a test driver for newhardware is a very easy thing, and the main point is that you can write your drivers withoutsophisticated Windows DDK! You can spare long days and nights doing Windows Driver fully

compatible with Windows architecture, and just like my time yours will be totally lost. Insome cases, you can use this type of driving for completed version of your program.

When you can use this driving model? 

1.  To test your hardware ports and functions, just like typing port driver for sound cardin DOS.

2.  To test and to use low speed ADC, DAC modules connected to your LPT port.

Why using LPT for your projects?

Before you start vituperating me, think about the things listed below!  

First, there are many easy to program hardware chips, and it is easy to make them dosomething for you without using expensive PIC or DSP. In many cases, migrating your codefrom PC to programmable chips is a standard work; so all you beginning scientists canavoid this boring work. Many companies prefer to rewrite all your code, do not think thatyour project will be pat on the market just as you created it! If you use LPT, it is easy toemulate all serial protocols (RS232, 484, SPI, I2C, CAN and much more!). And last but notleast, buying an LPT-PCI card is much cheaper (10-12$) than buying multi (10-12) port I/Operiphery (50-100$).

Troubleshooting things concerned to LPT driver 

As I said before, direct porting may be impossible when testing high-speed hardware,like video adapters or CCD camera the data rate must be bigger, standard LPT byte rate ismaximum 1MB/s. But even then, you can make a simple show application. It is a bigmistake to start designing of PC periphery signal converters trying to make your hardwarecompatible with USB or RS232. Do not shame to say, I can't drive code for PIC toimplement USB routines, this is a standard procedure, someone can write it for you forless then 10$!

When it is possible, how to use it in real time applications? 

Before you start building time dependent applications and hardware, remember one thing:

Using direct porting on Windows is possible when using Windows Multimedia Timers, andmaximum speed you can get is 1000 times per second! /Be sure that your driver code canhold within timer events/. Read the source code fordrv ECG  _1.dll , if you have questions Illtry to answer you. The main driving process is to set multimedia timer(seetimeSetEvent() function) to clock on needed time, and to specify attached to it

driver function it must be static defined (using _inp(), _ outp() statements  

see conio.h). It is better to make a private data block to store data coming from your chip.When sampling process is done, you can activate a callback function in your application toremove data in main processing program, or simply to store it in multimedia file or DSP it.

Page 5: ECG Recorder

8/3/2019 ECG Recorder

http://slidepdf.com/reader/full/ecg-recorder 5/12

Concrete, driver attached to ECG project source files have some evil features at thismoment, it makes memory lay out after closing the program 1MB! It is important to knowthis before using, but it works. This is because indrv ECG  _1.dll file, there is static declaredfunction; soon Ill try to correct it. All ECG driver code must work on Windows 95/98; forNT, XP you may need to use special I/O DLL files, search in the web for DriverLINX. Ithink that Windows 98 is better for research projects like mine.

QRS segment detection

QT segment detection

Page 6: ECG Recorder

8/3/2019 ECG Recorder

http://slidepdf.com/reader/full/ecg-recorder 6/12

 

PR segment detection

You can recalculate all records for better detecting. If you want, it is possible to add morerecalculating properties in this dialog.

Page 7: ECG Recorder

8/3/2019 ECG Recorder

http://slidepdf.com/reader/full/ecg-recorder 7/12

 

Program can store measurements in single files, all information is so-so compatiblewith ECG-SPC standard for medical records.

Page 8: ECG Recorder

8/3/2019 ECG Recorder

http://slidepdf.com/reader/full/ecg-recorder 8/12

 

You can review all statistical information concerned to your records - tests. First and main,you can see the heart-rate in time-black line. Second, you can see the veloergometer powersensor-red line.

After long time recording, there may be errors in your automatic report, so you can confirmyour diagnosis, and this confirmation will be stored in your file.

Page 9: ECG Recorder

8/3/2019 ECG Recorder

http://slidepdf.com/reader/full/ecg-recorder 9/12

 

It is too long to explain how it works, read about this soon, just see! If you have problemswith compiling & if you need more test files, write to me just now, I'll try to send you somerecords.

For this moment, I have a problem with saving BMP graphs, so if you can help, I'll bevery thankful. Additional problem is that I cant understand FFT, so the DSP functions are alittle slow, but they work good for this time. Finally, theECG program was done for 20 days,including drivers and application. When you use it on Win95/98, you will see that it usemuch memory...

You can use this code in your applications, however you want! But I can't take anyresponsibility for its use!

So, get it and test it...

Because this is an open code project, the hardware construction is too open. And now hereit is...

Page 10: ECG Recorder

8/3/2019 ECG Recorder

http://slidepdf.com/reader/full/ecg-recorder 10/12

 

And this is scanned PCB with mounted elements. Sorry about the picture quality, but it wasscanned after mounting in a box.

This is my isolation, it is cheap 1chp 6N137 ~ 0.5$

Page 11: ECG Recorder

8/3/2019 ECG Recorder

http://slidepdf.com/reader/full/ecg-recorder 11/12

 

This is 6N137 chip inside.

License

This article has no explicit license attached to it but may contain usage terms in the articletext or the download files themselves. If in doubt please contact the author via thediscussion board below.

A list of licenses authors might use can be found here 

Page 12: ECG Recorder

8/3/2019 ECG Recorder

http://slidepdf.com/reader/full/ecg-recorder 12/12

http://www.codeproject.com/KB/cpp/ecg_dsp.aspx