www.pudn.com > filter_source_code.rar > FilterDlg(old).cpp


// FilterDlg.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "Filter.h" 
#include "FilterDlg.h" 
#include "calculate.h" 
#include "math.h" 
 
#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() 
 
///////////////////////////////////////////////////////////////////////////// 
// CFilterDlg dialog 
 
CFilterDlg::CFilterDlg(CWnd* pParent /*=NULL*/) 
	: CDialog(CFilterDlg::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CFilterDlg) 
	//}}AFX_DATA_INIT 
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32 
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); 
} 
 
void CFilterDlg::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CFilterDlg) 
	DDX_Control(pDX, IDC_EDIT3, m_Edit3); 
	DDX_Control(pDX, IDC_EDIT2, m_Edit2); 
	DDX_Control(pDX, IDC_SPIN3, m_Spin3); 
	DDX_Control(pDX, IDC_SPIN2, m_Spin2); 
	DDX_Control(pDX, IDC_EDIT1, m_ZoominEdit); 
	DDX_Control(pDX, IDC_SPIN1, m_ZoominSpin); 
	//}}AFX_DATA_MAP 
} 
 
BEGIN_MESSAGE_MAP(CFilterDlg, CDialog) 
	//{{AFX_MSG_MAP(CFilterDlg) 
	ON_WM_SYSCOMMAND() 
	ON_WM_PAINT() 
	ON_WM_QUERYDRAGICON() 
	ON_BN_CLICKED(IDC_WAV1, OnWav1) 
	ON_EN_UPDATE(IDC_EDIT1, OnUpdateEdit1) 
	ON_BN_CLICKED(IDC_WAV2, OnWav2) 
	ON_EN_UPDATE(IDC_EDIT2, OnUpdateEdit2) 
	ON_EN_UPDATE(IDC_EDIT3, OnUpdateEdit3) 
	ON_BN_CLICKED(IDC_WAV4, OnWav4) 
	ON_BN_CLICKED(IDC_WAV3, OnWav3) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CFilterDlg message handlers 
 
BOOL CFilterDlg::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 
	/////////////////////////初始化///////////////////// 
	CEdit* zoomin_edit=(CEdit*)GetDlgItem(IDC_EDIT1); 
	m_ZoominSpin.SetBuddy(zoomin_edit); 
	m_ZoominSpin.SetRange(1,200); 
	m_ZoominSpin.SetPos(10); 
	m_Zoomin=10; 
	m_Spin2.SetBuddy(&m_Edit2); 
	m_Spin3.SetBuddy(&m_Edit3); 
	m_Spin2.SetRange(0,100); 
	m_Spin3.SetRange(0,100); 
	m_Spin2.SetPos(30); 
	m_Spin3.SetPos(50); 
	EnableRegulate(false); 
	DataSuccess=false; 
	// TODO: Add extra initialization here 
	ShowWindow(SW_MAXIMIZE); 
	return TRUE;  // return TRUE  unless you set the focus to a control 
} 
 
void CFilterDlg::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 CFilterDlg::OnPaint()  
{ 
	CPaintDC dc(this); // device context for painting 
	if (IsIconic()) 
	{ 
		 
		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 
	{ 
		if(DataSuccess) 
		   DrawOldWave(dc); 
		CDialog::OnPaint(); 
 
	} 
} 
 
// The system calls this to obtain the cursor to display while the user drags 
//  the minimized window. 
HCURSOR CFilterDlg::OnQueryDragIcon() 
{ 
	return (HCURSOR) m_hIcon; 
} 
 
void CFilterDlg::OnWav1()  
{ 
CalWav1(); 
UpdateStaticBox(1); 
CRect rect(20,50,520,500); 
InvalidateRect(rect); 
EnableRegulate(false); 
CurrentWav=1; 
} 
 
void CFilterDlg::OnWav2()  
{ 
	// TODO: Add your control notification handler code here 
EnableRegulate(true);	 
CalWav2(); 
UpdateStaticBox(1); 
CRect rect(20,50,520,500); 
InvalidateRect(rect); 
CurrentWav=2; 
} 
 
 
 
void CFilterDlg::OnWav3()  
{ 
	// TODO: Add your control notification handler code here 
EnableRegulate(false);	 
CalWav3(); 
UpdateStaticBox(1); 
CRect rect(20,50,520,500); 
InvalidateRect(rect);	 
CurrentWav=3; 
} 
 
 
 
void CFilterDlg::OnWav4()  
{ 
	// TODO: Add your control notification handler code here 
EnableRegulate(false);	 
CalWav4(); 
UpdateStaticBox(0); 
CRect rect(20,50,520,500); 
InvalidateRect(rect); 
CurrentWav=4; 
} 
 
 
void CFilterDlg::CalWav1() 
{ 
	int m,n; 
	long seed; 
	double fs,snr; 
	double a[3]={1,1,1}; 
	double f[3]={10,20,50}; 
	double ph[3]={0,45,90}; 
	m=3; 
	n=500; 
	seed=13579l; 
	fs=1000; 
	snr=1000.0; 
	sinwn(a,f,ph,m,fs,snr,seed,y,n); 
    DataSuccess=true; 
	/////////////////////滤波后的波形///////////////// 
	double mu,pi,mean,sigma; 
	double d[501],w[501]; 
	pi=4.0*atan(1.0); 
	mean=0.0; 
	sigma=1.0; 
	seed=13579l; 
	n=500; 
	/////////////////////////////////////////////// 
 
	double a2[1]={1}; 
	double f2[1]={20}; 
	double ph2[1]={45}; 
	m=1; 
	n=500; 
	seed=13579l; 
	fs=1000; 
	snr=1000.0; 
	sinwn(a2,f2,ph2,m,fs,snr,seed,d,n); 
 
	/////////////////////////////////////////////// 
	m=50; 
	mu=0.002; 
	lms(y,d,y2,n,w,m,mu); 
	///lms(y,d,w,n,y2,m,mu); 
 
} 
 
void CFilterDlg::CalWav2() 
{ 
	int m,n,i; 
	long seed; 
	double fs,snr; 
	double a[11]; 
	double f[11]; 
	double ph[11]; 
	 
	m=10; 
	n=500; 
	seed=13579l; 
	fs=800; 
	snr=1000; 
	for(i=0;i<10;i++) 
	{ 
		a[i]=1; 
		ph[i]=rand()*90; 
		f[i]=10*i; 
	} 
	 
	sinwn(a,f,ph,m,fs,snr,seed,y,n); 
        /* for(k=0;kEnableWindow(enable); 
if(edit3) 
   edit3->EnableWindow(enable); 
m_Spin2.EnableWindow(enable); 
m_Spin3.EnableWindow(enable); 
} 
 
 
void CFilterDlg::UpdateStaticBox(bool status) 
{ 
 CStatic *static1,*static2; 
 static1=(CStatic*)GetDlgItem(IDC_STATIC1); 
 static2=(CStatic*)GetDlgItem(IDC_STATIC2); 
 if(status) 
 { 
  static1->SetWindowText("输入信号波形"); 
  static2->SetWindowText("输出信号波形"); 
 } 
 else 
 { 
  static1->SetWindowText("其它"); 
  static2->SetWindowText("误差"); 
 } 
}