数字双相码仿真
登录后复制
close allclear all%采样点数的设置k=14;%每码元采样数的设置L=128;N=2^k;M=N/L;%M为码元个数dt=1/L;%时域采样间隔T=N*dt;%时域截断区间df=1.0/T;%频域采样间隔Bs=N*df/2;%频域截断区间t=linspace(-T/2,T/2,N);%产生时域采样点f=linspace(-Bs,Bs,N);%产生频域采样点EP1=zeros(size(f));EP2=zeros(size(f));EP3=zeros(size(f));for x=1:1000 % 取样1000次 K=round(rand(1,M)); %产生一个长度为M的随机序列K,0和1等概出现 original=zeros(L,M); %产生一个L行M列的original矩阵,初始化为全0矩阵 Manchester =zeros(L,M); %产生一个L行M列的Manchester矩阵,初始化为全0矩阵 for i=1:M if K(i)==1 original (:,i)=1;%原码 Manchester (1:L/2,i)=1; %使manchester矩阵第i列前L/2个元素为1 else original (:,i)=0;%原码 Manchester (:,i)=1; %使manchester矩阵第i列为1 Manchester (1:L/2,i)=0; %使manchester矩阵第i列前L/2个元素为0 end end %分别重排nrz、manchester矩阵为1行N列的矩阵 original =reshape(original,1,N); Manchester =reshape(Manchester,1,N); %做傅里叶变换并算出功率谱密度 ORIGINAL =t2f(original,dt); P1=ORIGINAL.*conj(ORIGINAL)/T; MANCHESTER=t2f(Manchester,dt); P2=MANCHESTER.*conj(MANCHESTER)/T; %求功率谱密度的均值 EP1=(EP1*(x-1)+P1)/x; EP2=(EP2*(x-1)+P2)/x;endfigure(1) %开启一个编号为1的绘图窗口subplot(2,2,1);plot(t,original); %画原码的时域图axis([-3,3,min(original)-0.1,max(original)+0.1]);title('原码','fontsize',12);xlabel('t(ms)','fontsize',12);ylabel('original(t)','fontsize',12);grid onsubplot(2,2,2);plot(t,Manchester) ; %画数字双相码的时域图axis([-3,3,min(Manchester)-0.1,max(Manchester)+0.1]);title('数字双向码','fontsize',12);xlabel('t(ms)','fontsize',12);ylabel('Manchester (t)','fontsize',12);grid onsubplot(2,2,3);plot(f,EP1); %画原码的功率谱密度图axis([-5,5,0,0.3]);title('原码功率谱密度图','fontsize',12);xlabel('f(kHz)','fontsize',12);ylabel('P1(f)','fontsize',12);grid onsubplot(2,2,4);plot(f,EP2) ; %画数字双相码的功率谱密度图axis([-5,5,0,0.15]);title('数字双相码功率谱密度图','fontsize',12);xlabel('f(kHz)','fontsize',12);ylabel('P2(f)','fontsize',12);grid on1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.24.25.26.27.28.29.30.31.32.33.34.35.36.37.38.39.40.41.42.43.44.45.46.47.48.49.50.51.52.53.54.55.56.57.58.59.60.61.62.63.64.65.66.67.68.69.70.
免责声明:本文系网络转载或改编,未找到原创作者,版权归原作者所有。如涉及版权,请联系删