当前位置: 首页 > 图文教程 > 开发语言 > VC++ > 几个数字信号处理算法程序

VC++
透明窗体的又一实现
橡皮区矩形 CRectTracker C# 实现
Visual Basic .NET 中多 Windows 窗体的同步
轻松实现类 MSDN 2002 界面(二)
轻松实现类 MSDN 2002 界面
数据库开发之窗体编程
一个打印报表的简单的类
SDK 程序使用SkinMagic工具包换皮肤
Windows SDK笔记(七):创建MDI窗口
Windows SDK笔记(六):使用对话框资源建立窗口
Windows SDK笔记(五):非模式对话框
Windows SDK笔记(四):模式对话框
也谈如何隐藏显示在任务栏中的对话框程序
一个托盘程序演示 -闹钟 Alert
think window procedure
再谈 CFileDialog 对话框的定制
获得 Win32 窗口句柄的更好的方法
个人考勤软件开发实例配套代码 2.1版(Update)
介绍一个操作DHTML表格的C++对象
Windows资源管理器Web视图界面

VC++ 中的 几个数字信号处理算法程序


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-10-30   浏览: 56 ::
收藏到网摘: n/a

几个数字信号处理算法程序

作者:liu_sir

下载源代码
 

摘要

在学习数字信号处理算法程序中用VC编写的几个通用算法程序。

关键词 离散卷积 FIR

在学习信号处理的过程中,看到书上的大部分算法都是用Fortan或者Basic实现,于是自己试验着用VC实现了一下。

1、卷积计算

 

离散卷积公式的算法实现

图1 卷积计算界面

1.1 主程序代码(省略了部分不关键代码)

	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;//函数选择 if(pbtn->GetCheck())	{	nChoseItem	= 0; }	else	{	nChoseItem	= 1; }	for(int	i= 0;i<2*(n+1);i++)	{	if(i< n+1)	{	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<2*(n+1);i++)	{	y[i] = Calcy(x,h,i);	}	//显示结果	delete[] x;	delete[] y;	delete[] h;}	
1.2 各个子函数实现
typedef double (* FFuncs)(int); //h1(x) doublefunch1(intn) { doublefbase	= (double)4/(double)5; double fr	= std::pow(fbase, n); return fr;	} //h2(x)doublefunch2(intn) { doublefpi	= 3.1415927; return 0.5*sin((double)0.5*n);	} //y(n)//y(n)=sum(x(m)*y(n-m))m=0..n doubleCalcy(double x[],double h[],int n) {double	yvalue = 0; for(int	m= 0;m<=n;m++)	{	yvalue += x[m]*h[n-m];	}	return yvalue;}
2、DFT与FFT实现

程序界面,具体实现见注释及代码:


图2 DFT与FFT实现界面

2.1 主程序代码
void CFFTConversionDlg::OnBnClickedBtncal() {	this->UpdateData(TRUE);	int	nN = this->m_NumN; float	fF = this->m_NumF; float	fT = this->m_NumT; bool	bIsTimesof2 = false;	for(int i= 0;i<100;i++)	{ if(nN==(2 < < i))	{	bIsTimesof2 = true;	break;	}	}	if(!bIsTimesof2)	{	AfxMessageBox("N请输入一个以2为底的幂级数!");	this->GetDlgItem(IDC_EDTN)->SetFocus();	return;	}	COMP* x = new COMP[nN];//x(n)	COMP* X = new COMP[nN];//X(k)	initX(nN,x,fF,fT);	CButton* pRadio = (CButton*)this->GetDlgItem(IDC_RADIODFT);	if(pRadio->GetCheck())	{	DFT(nN,x,X);	}	else	{	FFT(nN,x,X);	}	char buffer[256];	COMP source = X[nN-1];	sprintf(buffer,"%f+%fi",source.real(),source.imag());	CWnd* pwnd = this->GetDlgItem(IDC_EDTRET);	pwnd->SetWindowText(buffer);	CListCtrl* pList=(CListCtrl*) this->GetDlgItem(IDC_LIST1);	CListOper oper;	oper.FillList(*pList,nN,x,X);	delete[] x;	delete[] X;}
2.2 子函数代码

说明:其中COMP为复数类型
/******************************************* Name :DFT* Function :Disperse Fuliye Transformation* Params :N -- Total count of sampling points* X -- Input sequence* Return :XN(k)=sum[x(n)*Pow(e,j2*Pi/N)] * k,n:0..N-1*******************************************/void DFT(int N,COMP x[],COMP XK[]){	double C = (2*pi)/N;	COMP t(0,0),ret(0,0);	for(int k=0;k < N;k++)	{	ret = COMP(0,0);	for(int i=0;i< N;i++)	{	t = COMP(cos(C*k*i),-sin(C*k*i));	ret += x[i]*t;	}	XK[k] = ret;	}	}/******************************************* Name :FFT* Function :Fast Fuliye Transformation* Params :N -- Total count of sampling points* X -- Input sequence* Return :XN(k)=sum[x(n)*Pow(e,j2*Pi/N)] * k,n:0..N-1*******************************************/void FFT(int N,COMP X[],COMP XK[]){	int j=0;	COMP U=0,W=0;	COMP* A = XK;	//Adjust sequence	f