ECGDlg.cpp.bak ( File view )

  • By c654162067 2013-10-31
  • View(s):227
  • Download(s):9
  • Point(s): 3
			// ECGDlg.cpp : implementation file
//
#include <stdio.h>
#include "stdafx.h"
#include "ECG.h"
#include "ECGDlg.h"
#include "Parameter.h"
#include "HeartAnalyse.h"
#include <afxdlgs.h>    //调用CFileDialog类
#include <iostream.h>
#include <math.h>
#include "wavelet.h"
#include <fstream>
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{

public:
	CAboutDlg();

// Dialog Data
	//{
{
AFX_DATA(CAboutDlg)
	enum {
 IDD = IDD_ABOUTBOX 
};
	//
}
}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{
{
AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//
}
}AFX_VIRTUAL

// Implementation
protected:
	//{
{
AFX_MSG(CAboutDlg)
	//
}
}AFX_MSG
	DECLARE_MESSAGE_MAP()

};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{

	//{
{
AFX_DATA_INIT(CAboutDlg)
	//
}
}AFX_DATA_INIT

}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{

	CDialog::DoDataExchange(pDX);
	//{
{
AFX_DATA_MAP(CAboutDlg)
	//
}
}AFX_DATA_MAP

}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{
{
AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//
}
}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CECGDlg dialog

CECGDlg::CECGDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CECGDlg::IDD, pParent)
{

	memset(temp, 0, sizeof(float)*N);
	memset(temp1, 0, sizeof(double)*N);
	memset(t3, 0, sizeof(double)*N);
	memset(t4, 0, sizeof(double)*N);
   iLen=0;
memset(a1, 0, sizeof(double)*N);

  memset(temp7, 0, sizeof(float)*N);
	memset(buffer1, 0, sizeof(double)*6*N);
	memset(buffer2, 0, sizeof(unsigned char)*12*N);
	btn=false;
	btn1=false;
	orpoint=0;
	btn2=false;
	type=0;

//	memset(R_num,0,sizeof(int)*15);
	//{
{
AFX_DATA_INIT(CECGDlg)

	m_View = _T("");
	//
}
}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

//	memset(temp, 0, sizeof(long)*N);

}

void CECGDlg::DoDataExchange(CDataExchange* pDX)
{

	CDialog::DoDataExchange(pDX);
	//{
{
AFX_DATA_MAP(CECGDlg)


	DDX_Text(pDX, IDC_SHOW, m_View);
	//
}
}AFX_DATA_MAP

}

BEGIN_MESSAGE_MAP(CECGDlg, CDialog)
	//{
{
AFX_MSG_MAP(CECGDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_QRS, OnQrs)
	ON_BN_CLICKED(IDC_FFT, OnFft)
	ON_BN_CLICKED(IDC_PARAMETER, OnParameter)
	ON_BN_CLICKED(IDC_HTANALYSE, OnHtanalyse)
	ON_BN_CLICKED(IDC_CHOOSEAREA, OnChoosearea)
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONUP()
	ON_BN_CLICKED(IDC_MAGNIFY, OnMagnify)
	ON_COMMAND(ID_MENUITEM1, OnMenuitem1)
	ON_COMMAND(ID_MENUITEM3, OnMenuitem3)
	ON_BN_CLICKED(IDC_LPFILTER, OnLpfilter)
	ON_COMMAND(ID_MENUITEM4, OnMenuitem4)
	ON_COMMAND(ID_MENUITEM5, OnMenuitem5)
	ON_COMMAND(ID_MENUITEM2, OnMenuitem2)
	ON_COMMAND(ID_Button1, OnButton1)
	ON_COMMAND(ID_ButterWorth2, OnButterWorth2)
	ON_COMMAND(ID_ButterWorth4, OnButterWorth4)
	ON_COMMAND(ID_WAVEPARASET, OnWaveparaset)
	ON_COMMAND(ID_WAVELET, OnWavelet)
	//
}
}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CECGDlg message handlers

BOOL CECGDlg::OnInitDialog()
{

	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{

		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{

			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		
}
	
}
	
	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here
	m_hMenu1=LoadMenu(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDR_MENU1));//导入资源,创建菜单
    ::SetMenu(this->GetSafeHwnd(),m_hMenu1);//添加到对话框

	return TRUE;  // return TRUE  unless you set the focus to a control

}

void CECGDlg::OnSysCommand(UINT nID, LPARAM lParam)
{

	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{

		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	
}
	else
	{

		CDialog::OnSysCommand(nID, lParam);
	
}

}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CECGDlg::OnPaint() 
{

	if (IsIconic())
	{

		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;
		
		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);		
	
}
	else
	{

		CDialog::OnPaint();
	
}

}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CECGDlg::OnQueryDragIcon()
{

	return (HCURSOR) m_hIcon;

}

void CECGDlg::OnQrs() 
{

	// TODO: Add your control notification handler code here


switch(type)
{
case 1:
{


	drawing1(buffer,iLen);
	R_Detect();
	btn1=true;
	break;

}
case 2:
	{
	drawing1(buffer1,N);
	R_Detect1();
	btn1=true;
	break;
	
}

}

}
/*******************************************************************/

//低通滤波

//高通滤波
int CECGDlg::HighPassFilter(int data)
{

	static int y1=0,x[66],n=32;
	int y0;
	x[n] = x[n + 33] = data;
	y0=y1+x[n]-x[n+32];
	y1 = y0;

	if(--n<0)
	{

		n=32;
	
}

	return(x[n+16]-(y0>>5));

}
//微分
int CECGDlg::Derivative(int data)
{

	int y,i;
	static int x_derv[4];
	/*y=1/8(2x(nT)+x(nT-T)-x(nT-3T)-2x(nT-4T))*/
	y=(data<<1)+x_derv[3]-x_derv[1]-(x_derv[0]<<1);
	y>>=3;
	for(i=0;i<3;i++)
		x_derv[i]=x_derv[i+1];
	x_derv[3]=data;
	return(y);

}

/**********************************FFT************************************/
void CECGDlg::OnFft() 
{

	// TODO: Add your control notification handler code here

	double fun[N];
		CWnd* pWnd = GetDlgItem(IDC_FFT);           
		CDC* pDC;	
		pDC = pWnd->GetDC();
		int i;
	switch(type)
{
case 1:
{



	for(int i=0;i<N;i++)
	{

		fun[i] = (double)buffer[i]/N;
	
}
break;

}
	case 2:
		{
	for(int k=0;k<N;k++)
	{

		fun[k] = (double)buffer1[k]/N;
		
}
		break;
	
		
}
	
}
	exchangeOrder(fun);

	CcplxCput W[N/2];

	computeW(W);

	CcplxCput C[N];

	for(i = 0;i<N; i++)
	{

		C[i].real = fun[i];
		C[i].imag = 0;
	
}

	int wnum,p;  //w的个数,也是间隔数
	int step;  //计算W需加的位数
	CcplxCput A,B;

	for(int l=0;l<12;l++)
	{

		wnum = 1<<l;  //即pow(2,l);
		step = wnum<<1;	//即pow(2,l+1);
		for(i =0; i<N-wnum-1; i+=step)
		{

			for(int j=0;j<wnum;j++)
			{

				p = j*(1<<(11-l));//(int)pow(2,m-l); //确定W[p]
				A = C[i+j];
				B = C[i+j+wnum]* W[p];
				C[i+j] = A+B;
				C[i+j+wnum] = A-B;
			
}
		
}
	
}

	for(i=0;i<N;i++)
	{

	a1[i]=sqrt((C[i].real*C[i].real+C[i].imag*C[i].imag));
	
}
		CString str;
		pWnd->GetWindowText(str);
if(str=="功率谱分析")
		{
pWnd->SetWindowText("时域波形");
drawing2(a1,N/2);
		
}
else if(type==1)
        {
pWnd->SetWindowText("功率谱分析");
	drawing1(buffer,N);
		
}
else
        {
pWnd->SetWindowText("功率谱分析");
	drawing1(buffer1,N);
		
}

}


//倒序
void CECGDlg::exchangeOrder(double *a)
{

	
	double q;
	int b,n,i,j;
	int k[12]={
0
};
	for (i = 0; i<N; i++)
	{

		
		b = i;
		n = 0;
		for (j =0; j<12; j++)
		{

			k[j] = b%2;
			b=b/2;
			n += k[j]*(int)pow(2,11-j);
		
}
		if(i<n )
		{

			q = a[i];
			a[i] = a[n];
			a[n] = q;
		
}
	
}

}
void CECGDlg::computeW(CcplxCput W[])
{

//计算W
	
	CcplxCput w(cos(2*3.14159/N),sin(-2*3.14159/N));
	for(int i=1; i<N/2; i++)
	{

		W[i]=W[i-1]*w;
	
}

}
	
//初始化画图
/******************************************************************/






/**********************************************************************/
void CECGDlg::R_Detect()
{
  
	int  i,j,m=0,R_num[100]={
0
}; 
//	int  i,j,m=0;

	int d=21; //NF is filter length.  k is resample interval, d is delay time of filter
	//R_num 存放R波的顶点坐标m为R顶点的个数,R_result 存放心率,data_y[Num]
	double thtemp=0,threshold=0,max1=0,max2=0,maxtempt;

	for(i=d+500;i<400+d+500;i++)                   //seek maxinum in first 1.2s
	{

		if(max1<buffer[i])
		{

			max1=buffer[i];
		
}
	
}
	for(i=421+500;i<1021+500;i++)
	{

		if(max2<buffer[i])                          //seek maxinum in second 1.2s
		{

			max2=buffer[i];
		
}
	
}
   
	threshold=(max1+max2)*0.35;
	// find the position of R wave 
	for(i=d;i<iLen-100;i++)                 
	{

		if(buffer[i]>threshold)
		{

			maxtempt=buffer[i];
			for(j=i;j<i+100;j++)                       //100=200 / (1000 / sample_rate
			{

				if(buffer[j]>=maxtempt)
				{

					 R_num[m]=j;
					 maxtempt=buffer[j];
				
}
                      
			
}    
			//Change the threshold value with time gone
          
			if(m>1)
			{

				 max1=max2;
				 max2=maxtempt;
				 threshold=(max1+max2)*0.35; 
			
}
			                          
			//Change the threshold value with time gone
			
			i=R_num[m++]+100;
		
}
	
}
	   

	CWnd* pWnd = GetDlgItem(IDC_SHOW);
	// 获取设备上下文
	CDC* pDC = pWnd->GetDC();
			pDC = pWnd->GetDC();		
		 CRect rect;
		pWnd->GetClientRect(&rect);


int w=rect.right, h=rect.bottom, h0 = h / 2;
	int leftMargin=w/10;
	int rightMargin=w/20;
	int upperMargin=h/20;
	int lowerMargin=h/10;
    SIZE docSize;		//文档大小
	docSize.cx=(w-leftMargin-rightMargin);
float xRatio=(float)docSize.cx/iLen;
	docSize
...
...
(Not finished, please download and read the complete file)
			
...
Expand> <Close

Want complete source code? Download it here

Point(s): 3

Download
0 lines left, continue to read
Sponsored links

File list

Tips: You can preview the content of files by clicking file names^_^
Name Size Date
01.96 kB
~$?+?+?-+?-?+???+?final.doc162.00 B2013-10-21 17:36
01.96 kB
01.96 kB
1001099ECG.txt303.95 kB2011-10-27 09:55
1001104ECG.txt449.72 kB2011-10-27 09:55
1001105ECG.txt300.11 kB2011-10-27 09:55
1002122ECG.txt298.52 kB2011-10-27 09:55
20090010ECG.txt306.25 kB2011-10-27 09:55
01.96 kB
01.96 kB
1002093ECG.txt298.05 kB2011-10-27 09:55
1002113ECG.txt297.83 kB2011-10-27 09:55
20080962ECG.txt300.06 kB2011-10-27 09:55
20080983ECG.txt302.18 kB2011-10-27 09:55
20091662ECG.txt302.89 kB2011-10-27 09:55
01.96 kB
cplxCput.cpp1.31 kB2011-10-27 09:55
cplxCput.h816.00 B2011-10-27 09:55
01.96 kB
cplxCput.obj21.55 kB2011-10-27 15:16
cplxCput.sbr1.33 MB2011-10-27 15:16
ECG.bsc5.12 MB2011-10-27 09:55
ECG.exe176.07 kB2013-10-24 18:12
ECG.ilk537.42 kB2013-10-24 18:12
ECG.obj25.34 kB2011-10-27 15:16
ECG.pch6.93 MB2011-10-27 15:16
ECG.pdb593.00 kB2013-10-24 18:12
ECG.res4.60 kB2011-10-27 15:16
ECG.sbr1.34 MB2011-10-27 15:16
ECGDlg.obj153.13 kB2013-10-24 18:12
ECGDlg.sbr1.56 MB2013-10-24 18:12
HeartAnalyse.obj20.09 kB2011-10-27 15:16
HeartAnalyse.sbr1.31 MB2011-10-27 15:16
mfc42d.dll908.05 kB2011-10-27 09:55
mfco42d.dll780.05 kB2011-10-27 09:55
MSVCIRTD.DLL92.08 kB2011-10-27 09:55
msvcrt.dll335.00 kB2011-10-27 09:55
msvcrtd.dll392.07 kB2011-10-27 09:55
Parameter.obj19.91 kB2011-10-27 15:16
Parameter.sbr1.31 MB2011-10-27 15:16
StdAfx.obj103.36 kB2011-10-27 15:16
StdAfx.sbr1.31 MB2011-10-27 15:16
vc60.idb601.00 kB2013-10-25 10:15
vc60.pdb484.00 kB2013-10-24 18:12
WaveCoef.obj13.76 kB2011-10-27 15:16
WaveCoef.sbr1.31 MB2011-10-27 15:16
wavelet.obj75.29 kB2011-10-27 09:55
wavelet.sbr22.38 kB2011-10-27 09:55
WaveParamSet.obj25.86 kB2011-10-27 15:16
WaveParamSet.sbr1.31 MB2011-10-27 15:16
ECG.APS24.64 kB2011-11-10 20:30
ECG.clw5.99 kB2011-11-10 21:56
ECG.cpp2.01 kB2011-10-27 09:55
ECG.dsp4.88 kB2011-10-27 09:55
ECG.dsw531.00 B2011-10-27 09:55
ECG.h1.26 kB2011-10-27 09:55
ECG.ncb553.00 kB2013-10-25 18:56
ECG.opt452.00 kB2013-10-25 18:56
ECG.plg240.00 B2013-10-25 10:15
ECG.rc9.51 kB2011-10-27 09:55
ECGDlg.cpp52.35 kB2013-10-24 18:12
ECGDlg.cpp.bak49.92 kB2013-10-24 13:59
ECGDlg.h3.12 kB2011-10-27 09:55
HeartAnalyse.cpp1.25 kB2011-10-27 09:55
HeartAnalyse.h1.29 kB2011-10-27 09:55
Parameter.cpp1.03 kB2011-10-27 09:55
Parameter.h1.22 kB2011-10-27 09:55
ReadMe.txt3.44 kB2011-10-27 09:55
01.96 kB
resource.h2.47 kB2011-10-27 09:55
cursor1.cur326.00 B2011-10-27 09:55
ECG.ico1.05 kB2011-10-27 09:55
ECG.rc2395.00 B2011-10-27 09:55
StdAfx.cpp205.00 B2011-10-27 09:55
StdAfx.h1.03 kB2011-10-27 09:55
WaveCoef.cpp667.00 B2011-10-27 09:55
WaveCoef.h703.00 B2011-10-27 09:55
wavelet.cpp33.78 kB2011-10-27 09:55
wavelet.h8.32 kB2011-10-27 09:55
WaveParamSet.cpp1.75 kB2011-10-27 09:55
WaveParamSet.h1.26 kB2011-10-27 09:55
~VCBAE.tmp432.00 kB2013-10-23 19:28
<~VCBAF.tmp>0.00 B2013-10-23 19:28
?-???+?+?-+?-?+???+?final.doc495.50 kB2011-11-10 20:06
-?-???4.33 MB2012-01-28 17:39
...
Sponsored links

ECGDlg.cpp.bak (14.44 MB)

Need 3 point
Your Point(s)

Your Point isn't enough.

Get point immediately by PayPal

More(Debit card / Credit card / PayPal Credit / Online Banking)

Submit your source codes. Get more point

LOGIN

Don't have an account? Register now
Need any help?
Mail to: support@codeforge.com

切换到中文版?

CodeForge Chinese Version
CodeForge English Version

Where are you going?

^_^"Oops ...

Sorry!This guy is mysterious, its blog hasn't been opened, try another, please!
OK

Warm tip!

CodeForge to FavoriteFavorite by Ctrl+D