是用c++实现的几个数字信号处理中的典型算法

源代码在线查看: intervolvedlg.cpp

软件大小: 173 K
上传用户: babydog00
关键词: 数字信号处理 典型 算法
下载地址: 免注册下载 普通下载 VIP

相关代码

				// InterVolveDlg.cpp : 实现文件
				//
				
				
				
				#include "stdafx.h"
				#include "InterVolve.h"
				#include "InterVolveDlg.h"
				#include ".\intervolvedlg.h"
				#include "afxtempl.h" 
				
				
				#include 
				#include 
				#include 
				#include 
				#include 
				//#include 
				
				using namespace std;
				#ifdef _DEBUG
				#define new DEBUG_NEW
				#endif
				
				
				// 用于应用程序“关于”菜单项的 CAboutDlg 对话框
				
				class CAboutDlg : public CDialog
				{
				public:
					CAboutDlg();
				
				// 对话框数据
					enum { IDD = IDD_ABOUTBOX };
				
					protected:
					virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持
				
				// 实现
				protected:
					DECLARE_MESSAGE_MAP()
				};
				
				CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
				{
				}
				
				void CAboutDlg::DoDataExchange(CDataExchange* pDX)
				{
					CDialog::DoDataExchange(pDX);
				}
				
				BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
				END_MESSAGE_MAP()
				
				
				// CInterVolveDlg 对话框
				
				
				
				CInterVolveDlg::CInterVolveDlg(CWnd* pParent /*=NULL*/)
					: CDialog(CInterVolveDlg::IDD, pParent)
					, m_ValueN(0)
				{
					m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
				}
				
				void CInterVolveDlg::DoDataExchange(CDataExchange* pDX)
				{
					CDialog::DoDataExchange(pDX);
					DDX_Text(pDX, IDC_EDTN, m_ValueN);
					DDV_MinMaxInt(pDX, m_ValueN, 1, 10000);
					DDX_Control(pDX, IDC_TAB1, m_Tab);
				
				}
				
				BEGIN_MESSAGE_MAP(CInterVolveDlg, CDialog)
					ON_WM_SYSCOMMAND()
					ON_WM_PAINT()
					ON_WM_QUERYDRAGICON()
					//}}AFX_MSG_MAP
					ON_BN_CLICKED(IDC_BTNCAL, OnBnClickedBtncal)
					ON_BN_CLICKED(IDC_BTNCLOSE, OnBnClickedBtnclose)
				END_MESSAGE_MAP()
				
				
				// CInterVolveDlg 消息处理程序
				
				BOOL CInterVolveDlg::OnInitDialog()
				{
					CDialog::OnInitDialog();
				
					// 将\“关于...\”菜单项添加到系统菜单中。
				
					// IDM_ABOUTBOX 必须在系统命令范围内。
					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);
						}
					}
				
					// 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
					//  执行此操作
					SetIcon(m_hIcon, TRUE);			// 设置大图标
					SetIcon(m_hIcon, FALSE);		// 设置小图标
				
					// TODO: 在此添加额外的初始化代码
					CButton* pbtn = (CButton*) this->GetDlgItem(IDC_RADIO1);
					pbtn->SetCheck(TRUE);
					CEdit* pedt = (CEdit*)this->GetDlgItem(IDC_EDTRET);
					pedt->SetReadOnly();
					pedt = (CEdit*)this->GetDlgItem(IDC_EDTN);
					pedt->SetWindowText("15");
				
				
					m_Tab.AddPage("计算结果显示",&m_dlgValues,m_dlgValues.IDD); 
					//m_dlgChart
					m_Tab.AddPage("图表显示",&m_dlgChart,m_dlgChart.IDD); 
				
				    m_Tab.Show();
					return TRUE;  // 除非设置了控件的焦点,否则返回 TRUE
				}
				
				void CInterVolveDlg::OnSysCommand(UINT nID, LPARAM lParam)
				{
					if ((nID & 0xFFF0) == IDM_ABOUTBOX)
					{
						CAboutDlg dlgAbout;
						dlgAbout.DoModal();
					}
					else
					{
						CDialog::OnSysCommand(nID, lParam);
					}
				}
				
				// 如果向对话框添加最小化按钮,则需要下面的代码
				//  来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
				//  这将由框架自动完成。
				
				void CInterVolveDlg::OnPaint() 
				{
					if (IsIconic())
					{
						CPaintDC dc(this); // 用于绘制的设备上下文
				
						SendMessage(WM_ICONERASEBKGND, reinterpret_cast(dc.GetSafeHdc()), 0);
				
						// 使图标在工作矩形中居中
						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;
				
						// 绘制图标
						dc.DrawIcon(x, y, m_hIcon);
					}
					else
					{
						CDialog::OnPaint();
					}
				}
				
				//当用户拖动最小化窗口时系统调用此函数取得光标显示。
				HCURSOR CInterVolveDlg::OnQueryDragIcon()
				{
					return static_cast(m_hIcon);
				}
				
				
				
				void CInterVolveDlg::OnOK()
				{
					// TODO: 在此添加专用代码和/或调用基类
				
					//CDialog::OnOK();
				}
				typedef double (* FFuncs)(int);
				//h1(x)
				double funch1(int n)
				{
					double fbase = (double)4/(double)5;
					double fr = std::pow(fbase, n);
					return fr;
				}
				//h2(x)
				double funch2(int n)
				{
					double fpi = 3.1415927;
					return 0.5*sin((double)0.5*n);
				}
				
				void CInterVolveDlg::OnBnClickedBtncal()
				{
					this->CalTheNumByArray();
				}
				
				//y(n)
				//y(n)=sum(x(m)*y(n-m)) m=0..n
				double Calcy(double x[],double h[],int n)
				{
					double yvalue  = 0;
					for(int m=0;m					{
						yvalue += x[m]*h[n-m];
					}
				
					return yvalue;
				}
				
				void CInterVolveDlg::CalTheNumByVector()
				{
					// TODO: 在此添加控件通知处理程序代码
					this->UpdateData(TRUE);
					FFuncs funcs[2] = {funch1,funch2};
					int n = this->m_ValueN;
					vector x;//x(n)
					vector y;//y(n)
					vector h;//h(n)
				    //1.init x(n),h(n),y(n)
					CButton* pbtn = (CButton*) this->GetDlgItem(IDC_RADIO1);
					int nChoseItem = 0;//选择那个h(n)
					if(pbtn->GetCheck())
					{
						nChoseItem = 0;
					}
					else
					{
						nChoseItem = 1;
					}
				
					for(int i=0;i					{
						x.push_back(1);
						h.push_back(funcs[nChoseItem](i));
						y.push_back(0); 
					}
					//2.y(n)=SUM(x(m)*h(n-m))  m=0..n
					double result = 0;
					for(unsigned int m=0;m					{
						double yvalue = x[m]*h[n-m];
						y[m] = yvalue;
						result += yvalue;
					}
				   
				
				   char buffer[256];
				   double source = result;
				
				    _gcvt( source, 14, buffer);
					CWnd* pwnd = this->GetDlgItem(IDC_EDTRET);
					pwnd->SetWindowText(buffer);
				
				
				}
				
				void CInterVolveDlg::CalTheNumByArray()
				{
					this->UpdateData(TRUE);
					FFuncs funcs[2] = {funch1,funch2};
					int n = this->m_ValueN;
					double* x = new double[2*(n+1)];//x(n)
					double* y = new double[2*(n+1)];//y(n)
					double* h = new double[2*(n+1)];//h(n)
				    //1.init x(n),h(n),y(n)
					CButton* pbtn = (CButton*) this->GetDlgItem(IDC_RADIO1);
					int nChoseItem = 0;//选择那个h(n)
					if(pbtn->GetCheck())
					{
						nChoseItem = 0;
					}
					else
					{
						nChoseItem = 1;
					}
				
					for(int i=0;i					{
						if(i						{
							x[i] = 1;
							h[i] = funcs[nChoseItem](i);
						}
						else
						{
							x[i] = 0;
							h[i] = 0;
						}
					}
					//2.y(i)=SUM(x(m)*h(i-m))  m=0..i
					for(i=0;i					{
						y[i] = Calcy(x,h,i);
					}
				   
				
				   char buffer[256];
				   double source = y[n];
				
				    _gcvt( source, 14, buffer);
					CWnd* pwnd = this->GetDlgItem(IDC_EDTRET);
					pwnd->SetWindowText(buffer);
				
					CDlgValues* pDlg = (CDlgValues*)this->m_Tab.GetDialog(0); 
					pDlg->SetGridValues(2*(n+1),x,h,y);
				
					delete[] x;
					delete[] y;
					delete[] h;
				}
				void CInterVolveDlg::OnBnClickedBtnclose()
				{
					// TODO: 在此添加控件通知处理程序代码
					this->DestroyWindow();
				}
				
				void CInterVolveDlg::OnCancel()
				{
					// TODO: 在此添加专用代码和/或调用基类
				
					CDialog::OnCancel();
				}
							

相关资源