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 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 controller, 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:<?p>

driver

visualization

On the end of this work, compile the application program 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 help doctors easily diagnose human or animals' heart activity and to 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 don’t mind to talk 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 veloergometry. 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 interested 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 addition, 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 to 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 help to see the time segments in the electrocardiogram.

For humans, it is not so difficult to detect them on the paper, and I maintain that is not so difficult to show the PC to recognize them. In standard electrocardiography, we use 12 recording channels, but in veloergometry applications, they are limited to one – this signal is used to detect the heart rate/min. and to detect some rhythm anomalies? – Search in the web for: “ECG time interval variability data”. All these features are included in the ECG_1 main project – class DSP_ECG. Here, I’ll 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 normal electrocardiograms in this first “ECG_1” version, for fast implementation of the project, I used simplified QRS detecting algorithm, see below:? www.dsp.com?

We will push the raw ECG input signal through a system of filters – see class DSP_Filter.

Use noht filter function to remove 50 or 60 Hz power line signal – see void DSP_Filter::RFilter_Noht and void DSP_Filter::WFilter_Noht functions or use them directly.

Use a low pass filter. If it is necessary, first try to use 100Hz low pass filter – see void DSP_Filter::WFilter_Low100Hz, and if this filtration can’t give the proper quality, use 40Hz low pass filter void DSP_Filter::WFilter_Low40Hz. Using lower filtration length is not recommended because most popular ECG measurements have an interest of the signal spectrum 0.67Hz – 40Hz.

After proper filtration, ECG signal is ready to be detected.

First we will find the first difference of the ECG signal – this is done by next code:

Therefore, this was the beginning! Now is the main algorithm, QRS detection. As I mentioned before in the picture above and as you can see, the standard QRS complex contains high amplitude (approximately 0.5-3mV) short time deviation impulse (50-200ms). From the main ECG waveform, it is simple to recognize QRS complex. We will make this using first difference of the ECG signal (array Y). This is done by finding the standard deviation of the signal – using double DSP_Filter::StandardDeviation. This function returns the standard deviation of the double array signal. Using this result and going through the Y array, we will mark all points of this array that have values greater than “1.2*deviation”:

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

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 low pass filtering (<40hz), in the ECG delta array Y, may be met some disturbances (caused by physiological or physical external sources) that can produce single deviations bigger than standard (“dev”). Moreover, if we suppose that each maximum 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 composite waveform, containing many bigger than standard deviation values with values + & -. Rest on this supposition, and some statistical information, QRS complex can be any series (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 varieties of ECG signals after proper filtering).

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 many standard projects to do. But the main difficulty for these my mates is how to show their projects working! It is too difficult when all that you study is not concerned about how to make market compatible solutions, even if they are laboratory samples. To make your hardware working on a standard PC is a nasty work. To build sample test hardware is not the 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 colleagues. It is very funny to see a completed project; just ready to fly in space, but using Excel 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 new hardware is a very easy thing, and the main point is that you can write your drivers without sophisticated 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. In some cases, you can use this type of driving for completed version of your program.

When you can use this driving model?

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

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 do something for you without using expensive PIC or DSP. In many cases, migrating your code from PC to programmable chips is a standard work; so all you beginning “scientists” can avoid this boring work. Many companies prefer to rewrite all your code, do not think that your project will be pat on the market just as you created it! If you use LPT, it is easy to emulate all serial protocols (RS232, 484, SPI, I2C, CAN and much more!). And last but not least, buying an LPT-PCI card is much cheaper (10-12$) than buying multi (10-12) port I/O periphery (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 is maximum 1MB/s. But even then, you can make a simple “show” application. It is a big mistake to start designing of PC periphery signal converters trying to make your hardware compatible with USB or RS232. Do not shame to say, “I can't drive code for PIC to implement USB routines”, this is a standard procedure, someone can write it for you for less 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, and maximum speed you can get is 1000 times per second! /Be sure that your driver code can hold within timer events/. Read the source code for drvECG_1.dll, if you have questions I’ll try to answer you. The main driving process is to set multimedia timer (see timeSetEvent() 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 to remove data in main processing program, or simply to store it in multimedia file or DSP it.

Concrete, driver attached to ECG project source files have some evil features at this moment, it makes memory lay out after closing the program – 1MB! It is important to know this before using, but it works. This is because in drvECG_1.dll file, there is static declared function; soon I’ll try to correct it. All ECG driver code must work on Windows 95/98; for NT, XP you may need to use special I/O DLL files, search in the web for “DriverLINX”. I think that Windows 98 is better for research projects like mine.

QRS segment detection

QT segment detection

PR segment detection

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

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

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 power sensor-red line.

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

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

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

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

So, get it and test it...

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

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

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

This is 6N137 chip inside.

License

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

Comments and Discussions

Dear Georgi Petrovi'm the MSc student of biomedical engineering in Esfahan university of iran, i want to develope an application for processing EEG (electroencephalogram) signals. for this purpose i want to write my application by using c++ programming in visual studio 2012 as a windows based application,like your appliction for ecg signal processing. i'm in start point and i'dont know what should i do exactly. i want to ask you if it's possible for you, please guide me, i mean please tell me, where should i start from? which books or tutorials should i read?i downloaded the source code of your ECG processing project and i want to see the performance of that but i don't know how can i run that. can you tell me what should i do step by step to run that?if you can help me, i never forget your helpbest regards

Hi, I am doing a project (none profit) using pic 18f2420 to genrate ECG signal, I would appreciate help on how to, as I am not good at much programming, thanks in advance for sharing your knowledge. Thanks again

I have ecge data in form of Byte array e.g data_array={-757,-671,-583,-500,-427,-343,-269,-208,-131,-61,-5,57,109,174,237,285,334,381,439,486,524,566,604,642,677,711,742,776,810,838,866,892,920,947,961,974,996,1019,1029,1037,1059,1067,1075,1090,1094,1103,1109,1109,1117,1121,1123,1125,1123,1124,1121,1114,1116,1106,1099,1102,1094,1081,1082,1081,1074,1069,1062,1055,1060,1057,1056,1063,1049,1054,1015,1040,1025,1020,1051,987,1083,964,1097,970,1050,1074,855,2088,1624,881,1067,1019,1036,926,1256,467,3321,7968,7933,7482};

Now i want to use your code to detect QRS complex .But i am unable to Detect Qrs complex of this array.please help me how to detect QRS complex form this array.

Dear Sir,Thanks for your article.I am doing a project "ECG wave classification using ANN" for MSc. Do you have any idea of reading and displaying "MIT-BIH Arrhythmia Database" files.Thanks in advance...

I’m working on one project where I need to develop a simple simulation program (non-commercial and not for profit!) for representation of normal and abnormal ECG patters depends of different physiological and pathophysiological conditions that could impact cardiac and pulmonary physiology.

I was wondering if you know math formula(s) for emulation of ECG patters. If you do know, I would deeply appreciate if you could share your knowledge.

hi i'm a university student and i'm developing a c++ .net software very similar to yours during my university thesis. My professor asked me to develop a software to plot 12 lead real time ecg. He asked me to acquire data from different sources like usb bluetooth or wifi or zigbee considering that every source send a binary flow of data with a selectable sample rate and bit resolution. Now i'm many problem with data acquisition. I've not found info or a method to acquire data. I would ask you if you know a sdk or api or .net library to develop a generic binary data acquisition from that source...thank'sbest regards

I see that the filter only works with 500Hz or lower sampling rate, while I would like to see how I could use this filter (or a similar) one with higher frequnecy ECGs, namely 1000 Hz.Can you give me some help in figuring out the coefficient for an high pass filter...

Sir..I m a .net developer. and currently as a part of r & d work i m putting my hands over EKG interfacing to PC. as u have supplied your PCB here. i wants to know how this pcb to be interfaced with the EKG machine and to pc. and Could you please mail me the Exact PCB ?? please ..becasue i m confused between the PCB you have shown and the isolation circuit..i cant understand which one to implement!! so sir please help me out...

I appologize for my poor English sentcents first... I am a medical doctor from Taiwan, I can offer some of my opinions after I reviewed the PCB above.First, you can see the PCB which contains AD623 (OP-amp) and MCP3002 (10-bit AD).There were two "V" symbols at left side of this PCB, the two "V" symbols may connect to the insulator PCB below.So you can know that two PCB which contains OP-Amp and AD converter were needed.Only one insulator PCB was needed in this case, the problem I am not clear is "How is the connections between human and insulator PCB ?"

please help me Iam working for 5 years on transmitting ECG signal from the device to the PPC by bluetooth and drawing it on the PPC screen collecting some data from the ECG signal then transmitting the signal by wi-fi to the computer my big problem that X|how can I Receive the data bu bluetooth to the PPC and how can I transmitting this data by wi-fiplease help me by any information.

I'm beginner in C++, and now i still learn about this code. learning about your code, I'm very excited. because it can be a subject addition for my task. but i have a problem to compile it.can you explain me about your code which has been given by you in your article??

i will be appreciate it if you can help me.. please.....

so you can reply my question in my emailmy email address : aa_esa@yahoo.com

I am sure there is a lot of interest in your project even after four years. I am trying to compile your project on VS-2005, I know it was made to compile on VC++-6.0 but I tried compiling two separate projects and created library files. I overwrote the library files which came with ECG1 project with the libraries I got after compiling ECG_VIEW and ECG_Statistic_View projects. But yet it complains about symbol references. I am not sure if you have latest version of your project which compiles on VS-2005.

Can you send me more ECG Test File ? May I know that how is your ECG Test File looked like?(I can't open the file to view).Is that same like the standard MIT/BIH or AHA database? If I wish to know more about your way to write the source code, is that any documentation available or others methods?

I will be very appreciate it if you able to reply me.my email address is : sinkuin_toh@yahoo.com

sir, we have connected the external circuit...but when we are recording ..we met with an error wincore.cpp something in 879..will you please give the instructions for the proper running of the software .. is there any changes required in the external circuit..expecting your reply....

hi,first,thank you for job.i have a question.i have some ecg data,but how can i make this data file into a .ecg file and usd your ECG_1.Or,can you send me some more test files.Thank you very much.best wish!

i am very new at ecg. if you have got a circuit picture can u send it to me. Because i have to use your circuit with proteus in my project. i want to be sure about the circuit i use in proteus. Thanks for your help....

Hello sir,i want some more test files as right now i am working on ECG and filters so please if you can get it for me i will be thankful to you.so please send it to me on my mail-idThanks for ur cooperation Yours sincerely - Anay Kulkarni

Hello Mr. Georgi, My name is Sérgio Vaz da Silva, i am a computer programer here in Goiânia - Goiás -Brazil, i working in a final high school project, and my project proposed is a portable ECG using a Nintendo GameBoy Advance, i have a GBA Movie Player Card and i am developing the ECG softwares with PE Visual Ham, my dificult is converter digital signals to draw a curve on a GBA display. I make very donwloads about FFT, but nothing help-me how to draw a curve. I know how make filters, and conversions with FFT but i like know how to draw a curve with digital data entered in a serial port of Gameboy. The PE Visual Ham language is a C or C++ compiler dedicated to GameBoy development. Please help-me.

hello all, I am new this Visual studio environment and am unable to start the execution of the software. I have downloaded all the zip files and unzipped them. I have compiled the source file without any errors but the building is giving me some errors. I need to solve this problem, Can anybody answer?

Hi,I am working on the project of Sleep apnea related to ECG.If you can help me out in reading the ECG data into my system, it will be very helpful to me. also if you have any code to detect the QRS segment.My email id is rakesh_306@rediffmail.comThanks for the help.

I'm very new to this ECG thing and I have the following problem:I can identify the QRS and to get the points between the peaks.What I need to do is to fix the baseline. If the patient moves while the ECG test my base line looks like a sine instead of a straight line. In this case I must fix the curve. If anyone has an idea (or a code )for the baseline fix I will be grateful