本人MATLAB学习小白仅做笔记记录和分享~~clc;close all;Ts1;N_sample8;dtTs/N_sample;N1000;t0:dt:(N*N_sample-1)*dt;%码型构建%gt1ones(1,N_sample);% 1s时长高电平 NRZ波形gt2[ones(1,N_sample/2),zeros(1,N_sample/2)];% RZ波形mt3sinc((t-5)/Ts);gt3mt3(1:1000*N_sample);%plot(t(1:10*N_sample),gt3);d(sign(randn(1,N))1)/2;%生成1*N的均值为0方差为1的随机数sign函数返回值有3种1、-1、0;取0值概率为0datasigxpand(d,N_sample);%等间隔插入7个0st1conv(data,gt1);st2conv(data,gt2);d2*d-1;datasigxpand(d,N_sample);st3conv(data,gt3);figure(1);subplot(321),plot(t(1:1000),st1(1:1000));axis([0,t(1000),0,2]);subplot(323),plot(t(1:1000),st2(1:1000));axis([0,t(1000),0,2]);subplot(325),plot(t(1:1000),st3(1:1000));axis([0,t(1000),-3,3]);[f,stf1]T2F(t,st1(1:length(t)));[f,stf2]T2F(t,st2(1:length(t)));[f,stf3]T2F(t,st3(1:length(t)));subplot(322),plot(f,10*log10(abs(stf1).^2));grid;axis([-5,5,-40,100]);xlabel(单极性NRZ信号功率谱密度);subplot(324),plot(f,10*log10(abs(stf2).^2));grid;axis([-5,5,-40,100]);xlabel(单极性RZ信号功率谱密度);subplot(326),plot(f,10*log10(abs(stf3).^2));grid;axis([-5,5,-40,100]);xlabel(sinc波形功率谱密度);%%%%%%%----函数定义必须在结尾-----%%%%%%%%%%%%%%%%%%function[out]sigxpand(d,M)Nlength(d);outzeros(M,N);out(1,:)d;outreshape(out,1,M*N);end%%%%%%%--------end--------------%%%%%%%%%%%%%%%%%%%------------------FFT变换函数--------------%function[f,sf]T2F(t,st)dtt(2)-t(1);Nlength(st);fs1/dt;dffs/N;f0:df:(N-1)*df;sffft(st);sffftshift(sf);ff-N/2*df;end%------------------end-----------------%代码运行结果小结1、生成0 1相间的随机序列d(sign(randn(1,N))1)/2;% ordrandi([0,1],1,N);2、同理生成-1 1相间的随机序列drandi([0,1],1,N);d2*d-1;%在上述的基础上加上此语句3、为什么要等间隔插入N_sample-1个0呢gt1[1,1,1]%基本码元data[1,0,1,1,1,0,1];%码元序列st1conv(gt1,data);plotst1;运行结果如果data等间隔插入2个0clc;close all;gt1[1,1,1];%基本码元data[1,0,0,0,0,0,1,0,0,1,0,0,1,0,0,0,0,0,0,1,0,0];%码元序列st1conv(gt1,data);plot(st1);axis([1,24,0,1.5]);grid;这样就生成了以基本码元为基础的码元序列。——即sigxpand函数的功能.