DSP实验程序及结果
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
#include"math.h"
#define PI 3.1415926
#define WANG 16
#define RUI 1024
int FIRLOW(int *nx,float *nh,int nError,int nCoeffNumber);
float h[WANG],fU;
int xx[RUI],rr[RUI],wc[RUI];
main()
{
int i,n_Output=0;
fU=0.0005;
for ( i=0;i for ( i=0;i { xx[i]=256*sin(i*2*PI/34); rr[i]=wc[i]=0; } for ( i=WANG+1;i { n_Output=FIRLOW(xx+i,h,n_Output-xx[i-1],WANG); // break point rr[i]=n_Output; wc[i]=rr[i]-xx[i]; } exit(0); } int FIRLOW(int *nx,float *nh,int nError,int nCoeffNumber) { int i,r; float fWork; r=0; for ( i=0;i { fWork=nx[i]*nError*fU; nh[i]+=fWork; r+=(nx[i-i]*nh[i]); } r/=128; return r; } FIR #include #define RUI 25 #define RUI1 1000 #define RUI2 4500 #define SAMPLEF 10000 #define PI 3.1415926 float Wave(); float FIR(); float fHn[RUI]={ 0.0,0.0,0.001,-0.002,-0.002,0.01,-0.009, -0.018,0.049,-0.02,0.11,0.28,0.64,0.28, -0.11,-0.02,0.049,-0.018,-0.009,0.01, -0.002,-0.002,0.001,0.0,0.0 }; float fXn[RUI]={ 0.0 }; float fInput,fOutput; float fSignal1,fSignal2; float fStepSignal1,fStepSignal2; float f2PI; int i; float fIn[256],fOut[256]; int nIn,nOut; main() { nIn=0; nOut=0; f2PI=2*PI; fSignal1=0.0; fSignal2=PI*0.1; fStepSignal1=2*PI/30; fStepSignal2=2*PI*1.4; while ( 1 ) { fInput=Wave(); fIn[nIn]=fInput; nIn++; nIn%=256; fOutput=FIR(); fOut[nOut]=fOutput; nOut++; /* break point */ if ( nOut>=256 ) { nOut=0; } } } float Wave() { for ( i=RUI-1;i>0;i-- ) fXn[i]=fXn[i-1]; fXn[0]=sin((double)fSignal1)+cos((double)fSignal2)/6.0; fSignal1+=fStepSignal1; if ( fSignal1>=f2PI ) fSignal1-=f2PI; fSignal2+=fStepSignal2; if ( fSignal2>=f2PI ) fSignal2-=f2PI; return(fXn[0]); } float FIR() { float fSum; fSum=0; for ( i=0;i { fSum+=(fXn[i]*fHn[i]); } return(fSum); } IIR #include #define wang 2 #define RUI1 1000 #define RUI2 4500 #define SAMP 10000 #define PI 3.1415926 float InputWave(); float IIR(); float fBn[wang]={ 0.0,0.7757 }; float fAn[wang]={ 0.1122,0.1122 }; float fXn[wang]={ 0.0 };