Click here to Skip to main content
Email Password   helpLost your password?

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:

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.

Sample image

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?

  1. We will push the raw ECG input signal through a system of filters � see class DSP_Filter.
    1. 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.
    2. 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.
  2. After proper filtration, ECG signal is ready to be detected.
    1. 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).

      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 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�:
    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 bigger differences, 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 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).

    This is done in the following lines of 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 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?

  1. To test your hardware ports and functions, just like typing port driver for sound card in 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 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

Sample image

QT segment detection

Sample image

PR segment detection

Sample image

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

Sample image

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

Sample image

Sample image

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.

Sample image

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.

Sample image

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...

Sample image

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

Sample image

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

Sample image

This is 6N137 chip inside.

Sample image

You must Sign In to use this message board.
 
 
Per page   
 FirstPrevNext
GeneralMath. formula(s) for ECG emulation?
WilfredoWilly
9:37 14 Oct '09  
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.

Thank you so much in advance!

PS: You can email me at willy_anime@hotmail.com

Thanks again!
GeneralRe: Math. formula(s) for ECG emulation?
Nick Alexeev
16:46 27 Feb '10  
ECG/EKG is a set of complex waveforms. Simulating them from physiological principles would be a tough problem (have anyone done it?) .

Instead of calculating, can you play back the recorded waveforms?

Which parameters are going to be variable in your simulation?

- Nick
Generalinfo about driver
hadlerz
1:59 16 Aug '09  
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's
best regards
GeneralDifferent sampling rate
nicomaco
0:29 17 Jun '09  
Congratulation for the very nice filter...

We had downloaded your code yesterday... it seam to work very well...

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...

Thank you in advance,

Guido
GeneralMuscle flutter filter
lgsaq
22:11 11 Apr '09  
I got great help from your article, thanks!
but, there's some question puzzle me, it is the muscle flutter, what frequency that Smile are, and how to filt them? thank you!
GeneralAtoD Resolution
torcomp
7:37 11 Dec '08  
Hi, wondering if you have an actual schematic of your circuit?
What is the resolution of the system? e.g. Bits/uVolt ?

Thanks,
Tony.
QuestionKnow about circuit
anikash2003
21:27 20 Jul '08  
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...

My email is gandhi.ashish@hotmail.com

I would wait for your reply.....

Thanks in advance....

ashish gandhi

AnswerRe: Know about circuit
disokgone
0:58 14 Jun '09  
I appologize for my poor English sentcents first... Rose
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 ?"

Have fun in study for all ! Smile
Generalyou are for hire
Member 4033936
23:19 23 Apr '08  
Ok
that is good!
how many hour do u want?
and $50/h USA or Euro or Belgium
This my rs232 protocol:
setbaud(BAUD9600);
puts("Test ADC Ch1-8 & Floating Point Math Display By ICC11\n");
puts("ADC1 ADC2 ADC3 ADC4 ADC5 ADC6 ADC7 ADC8\n");
OPTION = 0x93;

do
{ convert1();
result = ADR1;
printf("%3.1fV ",(float)0.019*result);
result = ADR2;
printf("%3.1fV ",(float)0.019*result);
result = ADR3;
printf("%3.1fV ",(float)0.019*result);
result = ADR4;
printf("%3.1fV ",(float)0.019*result);

convert2();
result = ADR1;
printf("%3.1fV ",(float)0.019*result);
result = ADR2;
printf("%3.1fV ",(float)0.019*result);
result = ADR3;
printf("%3.1fV ",(float)0.019*result);
result = ADR4;
printf("%3.1fV \r",(float)0.019*result);
} while(1); /* Loop Continue */

I can send to you QRS , Norva & cardioline PC installation s/w
for you as reference
Regards
JN
GeneralRe: you are for hire
Georgi Petrov
23:31 23 Apr '08  
Hi OK,
let me know more about your application
gpetrov@nbu.bg

regards,
do you like this to be done on C, C++, C#

Regards,
GeneralChange from LTP to RS232
Member 4033936
13:18 22 Apr '08  
Hi author
Can you help me change your source from LTP to Rs232?
I am a Biomedical Technician live in Brisbane Austrlia
My ECG Project
I am using Schiller patients floating circuit,
BC group Safety analyers 2010S to simulate ECG signals,
Micro-control HC11 from PMB_ZN (ADC and send through RS232)
and your source code to display on PC
If you want any info regarding about biomedical please let me know
My email: jacknguyen8@yahoo.com.au
GeneralRe: Change from LTP to RS232
Georgi Petrov
2:29 23 Apr '08  
Hi,
yesw I can consult you for 50$/h you may use my pay pal account for this.
regards
Questionbluetooth and wi-fi
Member 4613557
6:52 9 Apr '08  
please help me Iam working for 5 years Cry 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 Sigh 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-fiConfused
please help me by any information. Sigh
GeneralRe: bluetooth and wi-fi
Georgi Petrov
21:47 9 Apr '08  
Hi,
bluetooth is not good ptotocol!
please refer to FSK radio modems.

Regards,
Generalhai georgi petrov
nor haryanti
4:48 20 Jan '08  
helo georgi petrov.i'm haryanti from malaysia.i have interested about u'r ecg project.can i know what sofware u use?
GeneralNeed more help for compiling
aa_esa
18:43 23 Nov '07  
Hi....

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 email
my email address : aa_esa@yahoo.com


Thank you.


GeneralSchematic
Nick Alexeev
12:48 6 Nov '07  
Georgi, could you post a schematic for the EKG front end circuit in the next revision of the article?

Cheers,
Nikolai
GeneralCompiling
jayesch
19:15 28 Oct '07  
Hi,

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.

Thanks
Jayesch
GeneralRequire more ECG Test File
shtoh
17:35 4 Oct '07  
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

Thank You.




sinkuin
Generalneed for help
apabaelah
17:18 15 May '07  
dear G. Petrov

I need some help from you. Your source code is very brilliant. But it can't be compiled on my computer. The error message is "Can't link .obj : fatal error".

Can you help about this ?

Oh, I have another problem. Can somebody help me to make an VB program that can detect the QRS, QT, ST, and other segment and display it on the screen ?

Please contact me at i_iyan_to@yahoo.com

Thanks
GeneralRe: need for help
Georgi Petrov
22:52 15 May '07  
There is no any arrors Smile

use VC++ 6.0

.NET is something very stupid!!!

But I can reprogram it for ~2500$ in VB if you whant
Generalquery
suruchiwriter
23:47 18 Apr '07  
sir,Smile Smile i am an engneering student. i want to use this peoject as refe rence project.
i am going to makr the oher project using this, can you tell me hw we can run this downloaded files?


shalinee pandya
Questionwincore.cpp
varunbeckons
0:45 12 Mar '07  
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....
Generalemail id
project ecg
21:41 10 Dec '06  
sir could u sent me ur mail id at kannans88@yahoo.co.in
Generalhow to make a .ecg file
hgqi
17:34 6 Nov '06  
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!


Last Updated 15 Apr 2004 | Advertise | Privacy | Terms of Use | Copyright © CodeProject, 1999-2010