资源描述:
《QPSK和4QAM代码.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、%Defaultparameters%QOSKNN=256;%numberofsymbolstb=0.5;%bittimep0=1;%powerfs=16;%samples/symbolebn0db=[0:1:15];%Eb/N0vector[b,a]=butter(5,1/16);%transmitterfilterparameters%%EstablishQPSKsignals%x=random_binary(NN,fs)+1i*random_binary(NN,fs);%QPSKsignaly1=x;%savesignaly2a=y1*sqrt(p0);%sc
2、aleamplitude%%Transmitterfilter%y2=filter(b,a,y2a);%filteredsignal%%Matchedfilter%b=ones(1,fs);b=b/fs;a=1;%matchedfilterparametersy=filter(b,a,y2);%matchedfilteroutput%%Endofsimulation%%UsethesemianalyticBERestimator.Thefollowingsets%upthesemianalyticestimator.Findthemaximummagnitude%o
3、fthecrosscorrelationandthecorrespondinglag.%[cor,lags]=vxcorr(x,y);cmax=max(abs(cor));nmax=find(abs(cor)==cmax);timelag=lags(nmax);theta=angle(cor(nmax));y=y*exp(-1i*theta);%derotate%%NoiseBWcalibration%hh=impz(b,a);%receiverimpulseresponsenbw=(fs/2)*sum(hh.^2);%noisebandwidth%%Delayth
4、einput,anddoBERestimationonthelast128bits.%Usemiddlesample.Makesuretheindexdoesnotexceednumber%ofinputpoints.Ebshouldbecomputedatthereceiverinput.%index=(10*fs+8:fs:(NN-10)*fs+8);xx=x(index);yy=y(index-timelag+1);[n1,n2]=size(y2);ny2=n1*n2;eb=tb*sum(sum(abs(y2).^2))/ny2;eb=eb/2;[peidea
5、l,pesystem]=qpsk_berest(xx,yy,ebn0db,eb,tb,nbw);subplot(1,2,1)yscale=1.5*max(real(yy));plot(yy,'+')xlabel('DirectSample');ylabel('QuadratureSample');grid;axis([-yscaleyscale-yscaleyscale])subplot(1,2,2)semilogy(ebn0db,peideal,ebn0db,pesystem,'ro-');grid;xlabel('E_b/N_0(dB)');ylabel('Bi
6、tErrorRate')legend('AWGNReference','SystemUnderStudy')%Endofscriptfile.function[c,lags]=vxcorr(a,b)%Thisfunctioncalculatestheunscaledcross-correlationof2vectorsofthe%samelength.Theoutputlength(c)islength(a)+length(b)-1.%ItisasimplifiedfunctionofxcorrfunctioninmatlabR12usingthe%definiti
7、on:c(m)=E[a(n+m)*conj(b(n))]=E[a(n)*conj(b(n-m))]%a=a(:);%convertatocolumnvectorb=b(:);%convertbtocolumnvectorM=length(a);%sameaslength(b)maxlag=M-1;%maximumvalueoflaglags=[-maxlag:maxlag]';%vectoroflagsA=fft(a,2^nextpow2(2*M-1));%fftofAB=fft(b,2^nextpow2(2*M-1));%fftofBc=ifft(A.*con