直接秒杀 运行去吧%%%%%%%%%%%%% ++直接序列扩频1+++++++++++++++++++++++++++++++++++++++++++clear;clc;code_length=10;fs=4960; %每个信息码元内含fs个采样点t=0:1/fs:code_length;rand('seed',0);x=sign(rand(1,code_length)); %信息码for i=1:code_length s((1+(i-1)*fs):i*fs)=x(i);ends(i*fs+1)=x(i);figure(1);plot(t,s);axis([]);title('原始信息码');%% ++生成PN码++++++++++++++++++++++++++++++++++++++++++++++++fd=[1 0 0 1 0 1]; %反馈系数num_mreg=length(fd)-1; %移位寄存器的个数num_mseq=2^(num_mreg)-1; %一个m序列的码的个数init_mseq=ones(1,num_mreg); %m序列发生器初始化值mseq=zeros(1,num_mseq);for i=1:num_mreg mseq(i)=init_mseq(num_mreg-i+1);endi=i+1;for j=i:num_mseq for k=1:num_mreg if fd(k+1)==1 mseq(j)=xor(mseq(j),mseq(j-k)); end endendfor i=1:num_mseq mseq(i)=sign(mseq(i));endw_mseq=mseq;for i=1:code_length-1 w_mseq=[w_mseq,mseq];endfor i=1:code_length*num_mseq c_mseq(((i-1)*160+1):i*160)=w_mseq(i);endc_mseq(i*160+1)=w_mseq(i);figure(2);plot(t,c_mseq);axis([0,1,]);title('一周期m序列');%% ++扩频++++++++++++++++++++++++++++++++++++++++++++++++++k_code=s.*c_mseq;figure(3);plot(t,k_code);axis([0,1,]);title('扩频序列');%% ++跳频调制++++++++++++++++++++++++++++++++++++++++++++++++++fc0=3*fs/31;fc1=6*fs/31;fc2=9*fs/31;fc3=12*fs/31;tc=0:1/fs:159/fs;c0=2*cos(2*pi*fc0*tc);c0=[c0,2*cos(2*pi*fc3*tc)];c0=[c0,2*cos(2*pi*fc1*tc)];c0=[c0,2*cos(2*pi*fc2*tc)];c1=c0;for i=1:6 c1=[c1,c0];endc1=[c1,2*cos(2*pi*fc2*tc)];c1=[c1,2*cos(2*pi*fc3*tc)];c1=[c1,2*cos(2*pi*fc1*tc)];c=c1;for i=1:code_length-1 c=[c,c1];endc(code_length*fs+1)=0;signal=k_code.*c;figure(4);plot(t,signal);axis([100/fs,400/fs,]);%title('一个信息码元的跳频调制');%% ++解跳++++++++++++++++++++++++++++++++++++++++++++++++++signal_h=signal.*c;figure(5);plot(t,signal_h);axis([0,code_length,]);%% ++解扩+++++++++++++++++++++++++++++++++++++++++++++++++jk_code=signal_h.*c_mseq;figure(6);plot(t,jk_code);axis([0,code_length,]);%% ++低通滤波++++++++++++++++++++++++++++++++++++++++++++++wn=1/1e7;b=fir1(16,wn);H=freqz(b,1,16000);signal_d=filter(b,1,jk_code);figure(7);subplot(2,1,1);plot(t,signal_d);axis([0,code_length,]);title('恢复出来的信号波形');subplot(2,1,2);plot(t,s);axis([0,code_length,]);title('原始信号波形');