📄 mimo.m
字号:
close all;
clear all;
randn('state',sum(100*clock)); %reset the randn generator
A=1;
Es=A*A;
myCst=A*[1,-1]; %the constellation
myMap=[1,0];
Eb=2*Es;
minTestLength=100000; % test length should at least reach this number
maxTestLength=100000000; %test stops at this number
index=1;
for EbN0=0:1:15 %EbN0 in dB
N0=Eb*10^(-EbN0/10);
noiseRoot=sqrt(N0/2);
errorCount=0;
testCount=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);
h2=(randn(1)+j*randn(1))*sqrt(0.5);
h3=(randn(1)+j*randn(1))*sqrt(0.5);
%Noise generator
n0=(randn(1)+j*randn(1))*noiseRoot;
n1=(randn(1)+j*randn(1))*noiseRoot;
n2=(randn(1)+j*randn(1))*noiseRoot;
n3=(randn(1)+j*randn(1))*noiseRoot;
%Binary source
src=randn(2,2)>0; %binary source with equal probability
x=A*(2*src-1); %'0' maps to -A, '1' maps to A
for i=1:2
%Simulate the MIMO channel with noise
S0=x(i,1);
S1=x(i,2);
r0=h0*S0+h1*S1+n0;
r1=-h0*conj(S1)+h1*conj(S0)+n1;
r2=h2*S0+h3*S1+n2;
r3=-h2*conj(S1)+h3*conj(S0)+n3;
%MRC receiver
S0_MRC=conj(h0)*r0+h1*conj(r1)+conj(h2)*r2+h3*conj(r3);
S1_MRC=conj(h1)*r0-h0*conj(r1)+conj(h3)*r2-h2*conj(r3);
%Decision
myDist0=(S0_MRC-myCst).*conj(S0_MRC-myCst);
myDist1=(S1_MRC-myCst).*conj(S1_MRC-myCst);
[temp0,myIndex0]=min(myDist0);
[temp1,myIndex1]=min(myDist1);
dst=[myMap(myIndex0),myMap(myIndex1)];
err=xor(src(i,:),dst);
errorCount=errorCount+sum(err);
testCount=testCount+2;
end
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 + -