几个数字信号处理算法程序
2007-03-15 21:54:17 来源:WEB开发网核心提示: typedef double(* FFuncs)(int); //h1(x) doublefunch1(intn) { doublefbase= (double)4/(double)5; double fr= std::pow(fbase, n); return fr;} //h2(x)d
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);
} //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<=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 子函数代码
更多精彩
赞助商链接