Click here to Skip to main content
15,896,154 members
Articles / Programming Languages / C++

ECG recording, storing, filtering and recognition

Rate me:
Please Sign up or sign in to vote.
4.72/5 (110 votes)
14 Apr 200411 min read 734.9K   38.4K   156  
Full open code project for making driver and application software for ECG medical measurements.
// ECG_Data.cpp: implementation of the ECG_Data class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "ECG_1.h"
#include "ECG_Data.h"
#include "Person.h"
#include "Ecg_Info.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CECG_Data::CECG_Data()
{

}

CECG_Data::~CECG_Data()
{

}

void CECG_Data::SetDataNew(double *source, int lenght,CString comment,int QRS_count,int QRS_ms,int PR_ms,int QT_QTc_ms,BYTE hh,BYTE mm)
{
	for(int i = 0;i<lenght;i++)
	{
		DATA.Add(short(*(source+i)));
	}
	COMMENT.Add(comment);
	QRS_COUNT.Add(QRS_count);
	QRS_MS.Add(QRS_ms);
	PR_MS.Add(PR_ms);
	QT_QTc_MS.Add(QT_QTc_ms);
	TIME.Add(SetTime(hh,mm));
}

void CECG_Data::SetDataAt(double *source,int start, int lenght)
{
	//Set data at specific position in start
	//Chect for overloading DATA array
	if(start+lenght<=GetAllDataLenght())
	{
		for(int i=0;i<lenght;i++)
		{
			DATA.SetAt(start+i,short(*(source+i)));
		}
	}
}

void CECG_Data::GetFrom(double *dest,int start, int lenght)
{
	//gets data from specific position start
	//Chect for overloading DATA array
	if(start+lenght<=GetAllDataLenght())
	{
		for(int i=0;i<lenght;i++)
		{
			*(dest+i) = double(short(DATA.GetAt(start+i)));
		}
	}
}

void CECG_Data::Message(double msg)
{
	short i = -32000;
	DATA.Add(i);
	CString str;
	str.Format("%d",short(DATA.GetAt(0)));
	str.Format("%d",GetAllDataLenght());
	MessageBox(NULL,str,"Message",MB_OK);
}

int CECG_Data::GetAllDataLenght()
{
	return DATA.GetSize();
}

void CECG_Data::SaveData(CString File_Name)
{
	CFile sFile(File_Name,CFile::modeCreate|CFile::modeWrite);
	CArchive dArchive(&sFile,CArchive::store);
	
	//Serialize the arrays
	SerializeAll(&dArchive);
}

void CECG_Data::OpenFile(CString File_Name)
{
	RemoveAll();
	CFile oFile(File_Name,CFile::modeRead);
	//Move file pointer to the file begining
	oFile.Seek(0,CFile::begin);
	DWORD f_lenght = oFile.GetLength();
	CArchive dArchive(&oFile,CArchive::load);
	
	//Serialize the arrays
	SerializeAll(&dArchive);
}

void CECG_Data::RemoveAll()
{
	//Free the memory
	DATA.RemoveAll();
	COMMENT.RemoveAll();
	QRS_COUNT.RemoveAll();
	QRS_MS.RemoveAll();
	PR_MS.RemoveAll();
	QT_QTc_MS.RemoveAll();
	TIME.RemoveAll();
}

void CECG_Data::SerializeAll(CArchive* ar)
{
	//Serialize the arrays
	DATA.Serialize(*ar);
	COMMENT.Serialize(*ar);
	QRS_COUNT.Serialize(*ar);
	QRS_MS.Serialize(*ar);
	PR_MS.Serialize(*ar);
	QT_QTc_MS.Serialize(*ar);
	TIME.Serialize(*ar);

	person.Serialize(*ar);
	ecg_info.Serialize(*ar);
}

void CECG_Data::SetInfoAt(int pos, CString comment, int qrs_count, int qrs_ms, int pr_ms, int qt_qtc_ms,BYTE hh,BYTE mm)
{
	if(pos<=QRS_COUNT.GetSize())
	{
		QRS_COUNT.SetAt(pos,qrs_count);
		COMMENT.SetAt(pos,comment);
		QRS_MS.SetAt(pos,qrs_ms);
		PR_MS.SetAt(pos,pr_ms);
		QT_QTc_MS.SetAt(pos,qt_qtc_ms);	
		TIME.SetAt(pos,SetTime(hh,mm));
	}
}

CString CECG_Data::GetInfoFrom(int pos, int *qrs_count, int *qrs_ms, int *pr_ms, int *qt_qtc_ms,BYTE* hh,BYTE* mm)
{
	if(pos<=QRS_COUNT.GetSize())
	{
		*qrs_count = QRS_COUNT.GetAt(pos);
		*qrs_ms = QRS_MS.GetAt(pos);
		*pr_ms = PR_MS.GetAt(pos);
		*qt_qtc_ms = QT_QTc_MS.GetAt(pos);
		GetTime(TIME.GetAt(pos),hh,mm);
	}
	return COMMENT.GetAt(pos);
}


WORD CECG_Data::SetTime(BYTE hh, BYTE mm)
{
	//converts hh & mm in to one word variable
	WORD w_time;
	w_time = hh;
	w_time = w_time << 8;
	w_time = w_time|mm;

	return w_time;

}

void CECG_Data::GetTime(WORD w_time, BYTE *hh, BYTE *mm)
{
	*mm = w_time & 0xFF;
	w_time = w_time >> 8;
	*hh = w_time & 0xFF;

}

int CECG_Data::GetQRSCount(int pos)
{
	//returns the QRS count for a specific record
	int count=0;
	if(pos<=QRS_COUNT.GetSize())
		count = QRS_COUNT.GetAt(pos);

	return count;
}

void CECG_Data::GetPosTime(int pos, BYTE *hh, BYTE *mm)
{
	if(pos<=TIME.GetSize())
	{
		if(pos<=TIME.GetSize())
		{
			GetTime(TIME.GetAt(pos),hh,mm);
		}
	}
}

int CECG_Data::GetQRSms(int pos)
{
	int count=0;
	if(pos<=QRS_MS.GetSize())
		count = QRS_MS.GetAt(pos);

	return count;

}

int CECG_Data::GetPRms(int pos)
{
	int count=0;
	if(pos<=PR_MS.GetSize())
		count = PR_MS.GetAt(pos);

	return count;
}

int CECG_Data::GetQTQTcms(int pos)
{
	int count=0;
	if(pos<=QT_QTc_MS.GetSize())
		count = QT_QTc_MS.GetAt(pos);

	return count;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

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.

A list of licenses authors might use can be found here


Written By
Systems Engineer
Bulgaria Bulgaria
PhD, Cum Laude in digital automation systems
M.S. in Telemommunication management
B.S. in Telecommunication systems engineering
Programming: CUDA, C/C++, VHDL
Software and Hardware development and consulting:
data acquisition, image processing, medical instrumentation

Comments and Discussions