A=6; x0=1; M=255; f=2; N=100; %初始化; x0=1; M=255;
for k=1: N %乘同余法递推100次;
x2=A*x0; %分别用x2和x0表示xi+1和xi-1;
x1=mod (x2,M); %取x2存储器的数除以M的余数放x1(xi)中;
v1=x1/256; %将x1存储器中的数除以256得到小于1的随机数放v1中; if(v1>0.5)
v(:,k)=v1;
else v(:,k)=(v1-0.5 )*f; %将v1中的数( )减去0.5再乘以存储器f中的系数,存放在矩阵存储器v的第k
列中,v(:,k)表示行不变、列随递推循环次数变化; end
x0=x1; % xi-1= xi; v0=v1;
end %递推100次结束; v2=v %该语句后无‘;’,实现矩阵存储器v中随机数放在v2中,且可直接显示在MATLAB的
window中; k1=k;
%grapher %以下是绘图程序; k=1:k1;
plot(k,v,k,v,'r');
xlabel('k'), ylabel('v');tktle(' (-1,+1)均匀分布的白噪声')
A=6;N=100;x0=1;M=255;w=0.5; v2=0;%初始化 s=sqrt(1/12); for k=1:N x2=A*x0;
x1=mod(x2,M); v1=x1/256; v2=v2+v1; v(:,k)=v1; x0=x1; v0=v1;
v3=(v2-k/2)/(sqrt(k/12)); e(:,k)=w+s*v3; end e2=e
k1=k; k=1:k1;
plot(k,e,k,e,'rx');
xlabel('k'),ylabel('e');title('(0,1)正态分布的随机信号') 2
e2 =
Columns 1 through 6
0.0234 -0.0911 0.2158 0.0449 0.0895 0.3134
Columns 7 through 12
0.4350 0.5193 0.4766 0.4012 0.4211 0.3714
Columns 13 through 18
0.4881 0.4708 0.5000 0.5420 0.4252 0.3426
Columns 19 through 24
0.4256 0.3340 0.3363 0.4384 0.4992 0.5454
Columns 25 through 30
0.5195 0.4717 0.4820 0.4476 0.5232 0.5107
Columns 31 through 36
0.5302 0.5594 0.4755 0.4143 0.4736 0.4043
Columns 37 through 42
0.4043 0.4804
Columns 43 through 48
0.5113 0.4835
Columns 49 through 54
0.5039 0.4530
Columns 55 through 60
0.5448 0.5746
Columns 61 through 66
0.5590 0.5501
Columns 67 through 72
0.5220 0.4711
Columns 73 through 78
0.5704 0.5418
Columns 79 through 84
0.5756 0.5939
Columns 85 through 90
0.5263 0.5618 0.5437 0.5334 0.5016 0.4437 0.5574 0.5251 0.5635 0.5840 0.4704 0.5257 0.5474 0.5260 0.5404 0.5004 0.5415 0.5036 0.5490 0.5727 0.4431 0.5064 0.5315 0.5076 0.5242 0.4798 0.5593 0.5856 0.5717 0.5637 0.5382 0.4923
0.4915 0.5413 0.5716 0.5954 0.5816 0.5556
Columns 91 through 96
0.5606 0.5411 0.5826 0.5753 0.5862 0.6029
Columns 97 through 100
0.5539 0.5174 0.5518 0.5098 >>
3 X1=1;X2=0;X3=1;X4=0;X5=1;X6=0; %移位寄存器输入Xi初T态(0101),位寄存器各级输出
m=60; %置M序列总长度 for i=1:m %1#
Y6=X6;Y5=X5;Y4=X4; Y3=X3; Y2=X2; Y1=X1; X6=Y5;X5=Y4,X4=Y3; X3=Y2; X2=Y1; X1=xor(Y5,Y6); %异或运算 if Y6==0 U(i)=-1; else
U(i)=Y6; end end M=U %绘图 i1=i
k=1:1:i1;
plot(k,U,k,U,'rx') xlabel('k')
ylabel('M序列')
title('移位寄存器产生的M序列')
Yi为移
M =
Columns 1 through 10
-1 1 -1 1 -1 1 1 1 1 1
Columns 11 through 20
1 -1 -1 -1 -1 -1 1 -1 -1 -1
Columns 21 through 30
-1 1 1 -1 -1 -1 1 -1 1 -1
Columns 31 through 40
-1 1 1 1 1 -1 1 -1 -1 -1
Columns 41 through 50
1 1 1 -1 -1 1 -1 -1 1 -1
Columns 51 through 60
1 1 -1 1 1 1 -1 1 1 -1 i1 =
60