C 实现BPSK信号的调制解调过程课题设计报告DOC 下载本文

内容发布更新时间 : 2024/12/23 3:34:37星期一 下面是文章的全部内容请认真阅读。

void CTools::GaussionNoise(float *noise, double pSig, double fSNR, long num_of_scan) { //noise:产生的噪声数据; //stddeviation:噪声的标准差; //fSNR:信噪比; //pSig:信号功率; double pNoise, stddeviation; int i, j, numofvar; double gauvar, uDx, uEx, ranvar[100], sum, tempE, tempD; double mean; //初始化变量; mean=0; uEx=1.0/2.0; uDx=1.0/12.0; numofvar=20; tempE=numofvar*uEx; tempD=sqrt(numofvar*uDx); pNoise=pSig/pow(10, fSNR/10); stddeviation=sqrt(pNoise);//计算噪声标准差 for (j=0;j

★去载波模块

float* pfDemodData = NULL;//解调数据

pfDemodData=(float*)malloc(m_nNumOfScan*sizeof(float)); for(i=0; i

★低通滤波器模块

void CTools::lowPassFilter(float *inData, double fln, long length)

{

long lengthh, n, i; float *h, *outData;

//解决卷积分块丢失部分数据问题

long length_reivse=(int)ceil((float)length/20000)*20000;

float *inData_revise=(float*)malloc(length_reivse*sizeof(float));

for (i=0;i

*(inData_revise+i)=*(inData+i);

for (;i

lengthh=12768; n=32768;

h=firwin(lengthh, 1, fln, 0, 1);

h=(float* )realloc(h, n*sizeof(float));

outData=(float* )malloc(length_reivse*sizeof(float));

for (i=lengthh;i

convold(h, lengthh, inData_revise, length_reivse, outData, n);

free(h);

for (i=0;i

free(inData_revise); free(outData); }

float *CTools::firwin(int n, int band, double fln, double fhn, int wn)

{

//n 滤波器的阶数

//band 滤波器类型,1--低通,2--高通, 3--带通, 4--带阻

//fln, 对于低通和高通滤波器:通带边界频率,对于带通和带阻 //fln:通带下边界频率,fhn:通带上边界频率

//wn 窗函数类型:1--海明窗,2--汉宁窗,3--布拉克曼窗 //h 一个指针,指向返回的h(n) //若失败,则返回一个空指针(NULL) int i, n2, mid;

double s, wc1, wc2, delay; float *h;

h=(float *) malloc((n+1)*sizeof(float)); if(!h) return NULL; if((n%2)==0) { n2=n/2-1; mid=1; } else { n2=n/2; mid=0; }

delay=n/2.0; wc1=2.0*PI*fln; if(band >= 3) wc2=2.0*PI*fhn; switch(band) { case 1: { for (i=0;i<=n2;i++) { s=i-delay; *(h+i)=float((sin(wc1*s)/(PI*s))*window(wn, n+1, i)); *(h+n-i)=*(h+i); } if(mid==1) *(h+n/2)=float(wc1/PI); break; } case 2: { for (i=0;i <= n2;i++) { s=i-delay; *(h+i)=float((sin(PI*s)-sin(wc1*s))/(PI*s)); *(h+i)=*(h+i)*window(wn, n+1, i); *(h+n-i)=*(h+i); } if(mid==1)

*(h+n/2)=float(1.0-wc1/PI); break; } case 3: { for (i=0;i<=n2;i++) { s=i-delay; *(h+i)=float((sin(wc2*s)-sin(wc1*s))/(PI*s)); *(h+i)=*(h+i)*window(wn, n+1, i); *(h+n-i)=*(h+i); } if(mid==1) *(h+n/2)=float((wc2-wc1)/PI); break; } case 4: { for (i=0;i<=n2;i++) { s=i-delay; *(h+i)=float((sin(wc1*s)+sin(PI*s)-sin(wc2*s))/(PI*s)); *(h+i)=*(h+i)*window(wn, n+1, i); *(h+n-i)=*(h+i); } if(mid==1) *(h+n/2)=float((wc1+PI-wc2)/PI); break; } }

return h; }

★判决模块

//计算判决门限 float xmax,xmin,xthreshold; int maxn; xmax=*pfDemodData;//初始最大最小值 xmin=*pfDemodData; i=0; while(ixmax)

{ xmax=*(pfDemodData+i); }

if(*(pfDemodData+i)

xthreshold=(xmax+xmin)/2;//判决门限

//抽样判决

float* pfDeput = NULL;//判决数据

pfDeput=(float*)malloc(m_nNumOfBase*sizeof(float));

m_pDemodData=(int*)malloc(m_nNumOfBase*sizeof(int));

maxn=(m_nNumOfScan/m_nNumOfBase/2-1);//最大判决点

for (i=0; i

*(pfDeput+i)=*(pfDemodData+m_nNumOfScan/m_nNumOfBase*i+ maxn ); }

for (i=0; i

if ((*(pfDeput + i)) >= xthreshold) *(pfDeput + i) = 0; else *(pfDeput + i) = 1;

}

★FFT模块

float *CTools::fft(float *y, long n, long *len)

★误码率计算模块

double CTools::CodeErrorRate(int *base_data, int *demod_data, num_of_base)

//两个文件的误比特率 {

long i, num_of_err=0; if (num_of_base>2380) { for (i=0;i<2380;i++)//误码率计算

long