%*****************************************************
% This program simulates the 2xnr MIMO-STBC system with %
%%%%%%%%%%%%%%%%% Alamouti code %%%%%%%%%%%%%%%%%%%%
%*****************************************************
clc;
clear all;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for w=1:4;
if w==4
Rx=3; % nr=1,2,4,6
else
Rx=2.^(w-1);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
M=8; %M=input('The modulation array scheme M-PSK M = ');
%M=4 for 4PSk and 8 for 8PSK
SNR_MAX=20; %input('Enter the max SNR of the System SNR_MAX = ');
N=100000; %input('Enter the Number of transmitted symbol N = ');
%Nr=input('Enter the number of receiving antenna Nr = ');
randn('state',0);
%rand('state',0);
%$$$$$$$$$$$$$$$$$$$$ transmitter %$$$$$$$$$$$$$$$$$$$
z=0;
for k=0:2:SNR_MAX
A=floor(M*rand(2,N)); % transmitted alphabet
Str=exp(j*2*pi/M*A)/sqrt(2); % Transmitted symbol
for i=1:N
S=[Str(1,i);Str(2,i)]; % making space-time coding matrix
snr=10.^(k/10);
sig=(0.5)/snr;
Ns=sqrt(sig).*(randn(2.*Rx,1)+j*(randn(2.*Rx,1)));
% noise matrix
H=[];
%$$$$$$$$$$$$$$$$$$$$$$$$$$ channel $$$$$$$$$$$$$$
for p=1:Rx
h=(randn(1,2)+j*(randn(1,2)))/sqrt(2);
H=[H;h(1) h(2);h(2)' -h(1)']; % channel matrix
end
p=0;
r=H*S+Ns; % $$$$$$$$$$$$$$ received signal $$$$$$$$$$$$$$$$$$$$
S_=H'*r;
ang=angle(S_); % received angles
B=mod(round(ang/(2*pi/M)),M); % received alphabet
Ses(:,i)=[B(1);B(2)]; % received symbol
end
%$$$$$$$$$$$$$$$$$$$$$$$$ BER calculation $$$$$$$$$$$$$$$$$$$$$$$$$$$$
BER=0;
ERROR=0;
for p=1:2
for i=1:N
if A(p,i)~=Ses(p,i)
ERROR=ERROR+1;
end
end
end
z=z+1;
ber(z)=ERROR/(2*N);
end
snr=0:2:SNR_MAX;
ber;
Ber(:,w)=ber';
end
semilogy(snr,Ber(:,1),'b',snr,Ber(:,2),'g',snr,Ber(:,3),'r',snr,Ber(:,4),'m');
grid on
hold on