📄 spreadunitray.m
字号:
clear all ;
close all
randn('state',sum(100*clock)); %reset the randn generator
minTestLength=100000; % test length should at least reach this number
maxTestLength=100000000; %test stops at this number
% unitray matrix
matrix0=ones(6,1);
smatrix=diag(exp([i*2*pi/64 i*2*pi*18/64 i*2*pi*23/64 i*2*pi*39/64 i*2*pi*46/64 i*2*pi*57/64]));
Es=1;
Eb=Es;
index=1;
for EbN0=1:2;
N0=10^(-EbN0/10);
noiseRoot=sqrt(N0/2);
errorCount=0;
testCount=0;
while(1)
h0=(randn(1)+j*randn(1))*sqrt(0.5);
noise=(randn(16,44)+j*randn(16,44))*noiseRoot;
source=randn(1,42)>0; % source
changesource=reshape(source,6,7);
dsource=zeros(6,7); % after decesion sign matrix
spreadcode1=zeros(1,44);% spread array
unitraymatrix=zeros(6,7); % unitray modulate matrix
rmatrix=zeros(1,42); % receive matrix
rsource=zeros(1,42); % after despread sign
index1=1;
for ii=1:7 % construct unitrary matrix
number(index1)=[32 16 8 4 2 1]*changesource(:,ii);
index1=index1+1;
end
for iii=1:7 % construct matrix
smatrix1=smatrix^number(iii)*matrix0;
unitraymatrix(:,iii)=unitraymatrix(:,iii)+smatrix1;
end
spreadcode1=[reshape(unitraymatrix,1,42) zeros(1,2)];% symbols frame
% t1=(randn(1,44))+j*(randn(1,44));
source1 =spreadcode1*WQ(1);
x1 = ovsf(1)' * source1; % spreading
s1 = x1.*(scramble'*ones(1,44));
t2=(randn(1,44))+j*(randn(1,44));
source2 = t2*WQ(2);
x2 = ovsf(2)' * source2; % spreading
s2 = x2.*(scramble'*ones(1,44));
s = h0*(s1 + s2)+noise;
% s=s1+s2;
y1 = reshape(s,1,44*16) ;
%y = y + 1/sqrt(2)*( randn(size(y)) + j*randn(size(y)))*5;
r = reshape(y1,16,44);
% y2 = reshape(s,1,44*16) ;
% y = y + 1/sqrt(2)*( randn(size(y)) + j*randn(size(y)))*5;
% r2 = reshape(y2,16,44);
z1 = ones(44, 1)*scramble.*(ones(44, 1)*ovsf(1))*r;
rs1 = reshape(diag(z1)/16,1,44)./WQ(1);
%z11 = ones(44, 1)*scramble.*(ones(44, 1)*ovsf(1))*r2;
% rs11 = reshape(diag(z1)/16,1,44)./WQ(1);
% z2 = ones(44, 1)*scramble.*(ones(44, 1)*ovsf(2))*r;
% rs2 = reshape(diag(z2)/16,1,44)./WQ(2);
for mmm=1:42
rematrix(mmm)=rs1(mmm);
end
dmatrix=reshape(rematrix,6,7);
for nn=1:7
n=0;
for nnn=0:63
TR=trace( dmatrix(:,nn)'*(smatrix^nnn*matrix0)*(smatrix^nnn*matrix0)'*dmatrix(:,nn));
% max angle
if TR>n
n=TR;
length=nnn;
end
end
dst=de2bi(length,6,'left-msb');
dsource(:,nn)=dsource(:,nn)+dst';
end
rsource=reshape(dsource,1,42);
err=xor(rsource,source);
errorCount=errorCount+sum(err);
testCount=testCount+42;
if(testCount<minTestLength)
continue;
end
tempBER=errorCount/testCount;
%test if the test length is large enough
if(tempBER>0)
thresholdTestLength=100/(tempBER);
else
thresholdTestLength=maxTestLength;
end
%Stop current EbN0 test when the test threshold is reached
if(testCount>=thresholdTestLength)
myTestLength(index)=testCount;
Es=Eb/2;
myEsN0(index)=10*log10(Es/N0)
myEbN0(index)=EbN0
myBER(index)=tempBER
index=index+1;
break;
end
end
end
%Draw curves for the results,Eb/N0
figure(1)
semilogy(myEbN0,myBER,'*-');
xlabel('Eb/N0 in dB');
ylabel('bit error rate');
grid
%Draw curves for the results, Es/N0
figure(2)
semilogy(myEsN0,myBER,'+-');
xlabel('Es/N0 in dB');
ylabel('bit error rate');
grid
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -