下面是得到DSSS信号的代码,怎样在dsss信号中加入噪声,以及怎样分析信噪比等

% Lab 06
% WiCom_3
% By Kashif Shahzad 
% 01-ET-31
% 3rd July 2004

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Direct Sequence Spread Spectrum
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clc
clear

% Generating the bit pattern with each bit 6 samples long
b=round(rand(1,20));  % round()为 取最近的整数,rand()产生矩阵,元素在0到1之间 ,b作为原始信号矩阵
pattern=[]; 
for k=1:20
    if b(1,k)==0
        sig=zeros(1,6);
    else
        sig=ones(1,6);
    end   
    pattern=[pattern sig];%每6个1或0作为一个,行数为1,pattern=[111111 000000 000000...]作为原始调相数字信号
end
plot(pattern);%横坐标为第几个元素, 纵坐标为对应的元素值,要么是1要么是0,但1的个数或0的个数至少是6的整数倍 
axis([-1 120 -1.5 1.5]);  % axis([xmin xmax ymin ymax]) 分别表示x轴和y轴的坐标的刻度
title('\bf\it Original Bit Sequence');


% Generating the pseudo random bit pattern for spreading
suiji=round(rand(1,120));
figure,plot(suiji); %显示矩阵,横坐标为第几个元素,纵坐标是对应的suiji的元素值
axis([-1 120 -1.5 1.5]);
title('\bf\it Pseudorandom Bit Sequence');  %每次产生的伪随机序列不同
% XORing the pattern with the spread signal
fasong=xor(pattern,suiji); % xor()异或

figure,plot(fasong);
axis([0 120 -1.5 1.5]);
title('\bf\it FaSong');
% Modulating the dsss signal
dsss_sig=[];
t=[0:10];%余弦载波周期设为10
f=0.1
c1=cos(2*pi*f*t);
c2=-c1;
for k=1:120
    if fasong(1,k)==0   
       dsss_sig=[dsss_sig c1];
    else
     dsss_sig=[dsss_sig c2];
    end  
end
figure,plot(dsss_sig);
axis([-1 1200 -1.5 1.5]);
title('\bf\it DSSS Signal');