📄 lookber.m
字号:
close all
clear all
randn('state',sum(100*clock))
A=1;
ES=A*A;
Eb=ES;
minTestLength=100000;
maxTestlength=100000000;
index=1;
N=3;
% bpsk modulate
matrix0=(1/sqrt(8))*[1 1;1 exp(i*(N-1)*pi/6);1 exp(i*2*(N-1)*pi/6);1 exp(i*3*(N-1)*pi/6);1 exp(i*4*(N-1)*pi/6);1 exp(i*5*(N-1)*pi/6);1 exp(i*6*(N-1)*pi/6);1 exp(i*7*(N-1)*pi/6)];
smatrix=diag(exp([i*2*pi/256 i*2*pi*5/256 i*2*pi*16/256 i*2*pi*36/256 i*2*pi*57/256 i*2*pi*105/256 i*2*pi*151/64 i*2*pi*253/256]));
% smatrix=diag(exp([0 i*2*pi/64 i*2*pi*2/64 i*2*pi*3/64 i*2*pi*4/64 i*2*pi*5/64]));% the first design
% matrix2=matrix1';
for EbN0=0:5:20
N0=10^(-EbN0/10)
noiseRoot=sqrt(N0/2);
errorCount=0;
testCount=0;
length=0;
while(1)
% Generate the Rayleigh fading channel
h0=(randn(1)+j*randn(1))*sqrt(0.5);
h1=(randn(1)+j*randn(1))*sqrt(0.5);
% Noise generate
search=0;
for nn=1:8
n(nn)=(randn(1)+j*randn(1))*noiseRoot;
end
% Soure matrix
% matrix=ones(8,1);
% Generate Unitray Matrix
% S_matrix=diag(exp([i*pi*2/256 i*pi*2*5/256 i*pi*2*16/256 i*pi*2*36/256 i*pi*2*57/256 i*pi*2*105/256 i*pi*2*151/256 i*pi*2*253/256]));
% 8 rows 1 columns
% Transmit source matrix
src=randint(1,8);
% src1=2*src;
number=[128 64 32 16 8 4 2 1]*src';
% x=A*(2*src-1);
% max_matrix=zeros(1,4)
% Transmit matrix
Tmatrix=sqrt(8)*smatrix^number*matrix0;
Recematrix=zeros(8,2);
% Receive matrix
Recematrix(:,1)=h0*Tmatrix(:,1)+n';
Recematrix(:,2)=h1*Tmatrix(:,2)+n';
m=0;
% Decision
for ii=0:255
TR=trace( Recematrix'*(smatrix^ii*matrix0)*(smatrix^ii*matrix0)'*Recematrix);
% max angle
if TR>m
m=TR;
length=ii;
end
end
dst=de2bi(length,8,'left-msb');
error1=xor(src,dst);
errorCount=errorCount+sum(error1);
testCount=testCount+8;
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 + -