vc中幾個(gè)數(shù)字信號(hào)處理算法程序
發(fā)布時(shí)間:2008/8/23 0:00:00 訪問次數(shù):456
摘要:在學(xué)習(xí)數(shù)字信號(hào)處理算法程序中用vc編寫的幾個(gè)通用算法程序。
在學(xué)習(xí)信號(hào)處理的過程中,看到書上的大部分算法都是用fortan或者basic實(shí)現(xiàn),于是自己試驗(yàn)著用vc實(shí)現(xiàn)了一下。
1、卷積計(jì)算
離散卷積公式的算法實(shí)現(xiàn)
圖1 卷積計(jì)算界面
1.1 主程序代碼(省略了部分不關(guān)鍵代碼)
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;
//函數(shù)選擇 if(pbtn->getcheck()) { nchoseitem = 0; } e
lse { 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); }
//顯示結(jié)果 delete[] x; delete[] y; delete[] h;}
1.2 各個(gè)子函數(shù)實(shí)現(xiàn)
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實(shí)現(xiàn)
程序界面,具體實(shí)現(xiàn)見注釋及代碼:
圖2 dft與fft實(shí)現(xiàn)界面
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請輸入一個(gè)以2為底的冪級(jí)數(shù)!");
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 子函數(shù)代碼
說明:其中comp為復(fù)數(shù)類型
/*******************************************
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 for(int i=0;i< n;i++) { if(i==0) { a[0] = x[0]; }
else { j=getinverse(n,j);
a[i] = x[j]; } }
//確定級(jí)別數(shù)
for(int m=0;m< n;m++) { if((1<< m)==n) break; }
for(int l=1;l<=m;l++)//1-m
摘要:在學(xué)習(xí)數(shù)字信號(hào)處理算法程序中用vc編寫的幾個(gè)通用算法程序。
在學(xué)習(xí)信號(hào)處理的過程中,看到書上的大部分算法都是用fortan或者basic實(shí)現(xiàn),于是自己試驗(yàn)著用vc實(shí)現(xiàn)了一下。
1、卷積計(jì)算
離散卷積公式的算法實(shí)現(xiàn)
圖1 卷積計(jì)算界面
1.1 主程序代碼(省略了部分不關(guān)鍵代碼)
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;
//函數(shù)選擇 if(pbtn->getcheck()) { nchoseitem = 0; } e
lse { 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); }
//顯示結(jié)果 delete[] x; delete[] y; delete[] h;}
1.2 各個(gè)子函數(shù)實(shí)現(xiàn)
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實(shí)現(xiàn)
程序界面,具體實(shí)現(xiàn)見注釋及代碼:
圖2 dft與fft實(shí)現(xiàn)界面
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請輸入一個(gè)以2為底的冪級(jí)數(shù)!");
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 子函數(shù)代碼
說明:其中comp為復(fù)數(shù)類型
/*******************************************
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 for(int i=0;i< n;i++) { if(i==0) { a[0] = x[0]; }
else { j=getinverse(n,j);
a[i] = x[j]; } }
//確定級(jí)別數(shù)
for(int m=0;m< n;m++) { if((1<< m)==n) break; }
for(int l=1;l<=m;l++)//1-m
熱門點(diǎn)擊
- CPLD開發(fā)板和FPGA開發(fā)板的區(qū)別
- 基于FPGA和AD1836的I2S接口設(shè)計(jì)
- vc中如何使用設(shè)備描述表
- Visual C++中調(diào)用DLL實(shí)現(xiàn)數(shù)據(jù)加密
- Visual C++6.0 API函數(shù)操作技
- VC++中進(jìn)程與多進(jìn)程管理的方法
- JavaCard CPU的設(shè)計(jì)與FPGA實(shí)現(xiàn)
- 如何用C語言開發(fā)DSP嵌入式系統(tǒng)
- C和C++ 字符串字面量的比較
- Xilinx針對(duì)Virtex-5 FXT F
推薦技術(shù)資料
- 聲道前級(jí)設(shè)計(jì)特點(diǎn)
- 與通常的Hi-Fi前級(jí)不同,EP9307-CRZ這臺(tái)分... [詳細(xì)]
- 電磁與聲學(xué)結(jié)合混合濾波技術(shù)(H
- 超高性能芯片式電磁濾波技術(shù)(S
- 紫、藍(lán)、綠光激光二極管工藝封測
- SPICE模型ROHM Lev
- 高性能碳化硅(SiC)MOS功
- 新一代光纖通信的光收發(fā)器接收器
- 多媒體協(xié)處理器SM501在嵌入式系統(tǒng)中的應(yīng)用
- 基于IEEE802.11b的EPA溫度變送器
- QUICCEngine新引擎推動(dòng)IP網(wǎng)絡(luò)革新
- SoC面世八年后的產(chǎn)業(yè)機(jī)遇
- MPC8xx系列處理器的嵌入式系統(tǒng)電源設(shè)計(jì)
- dsPIC及其在交流變頻調(diào)速中的應(yīng)用研究