You are on page 1of 2

%rank is coming ou to be 4

clc;
clear all;
close all;
snr_dB = [1:10]; % multiple Eb/N0 values
snr = 10.^(snr_dB /10);%snr
nTx = 4; %number of transmitters
nRx = 1; %number of receivers
T=4;
%time symbol
N=4;
%number of symbols
a=nTx*T;
l=100;
%number of realizations of A
A = (rand(a,N,l)+ 1j*rand(a,N,l)) ;
for l1= 1:100
ran = rank(A(:,:,l1));
if ran == 4
[Znew(:,:,l1),R(:,:,l1)]=qr(A(:,:,l1),0);
Z(:,:,l1) =sqrt(T/N) * Znew(:,:,l1);
M(:,:,:,l1)=reshape(Z(:,:,l1),[nTx,T,N]);
end
end
consat=0;
e=0.1;
for l1=1:100
con=(Z(:,:,l1))'* Z(:,:,l1);
if abs(det(con - ((T/N)*eye(N)))) < e
consat =consat +1;
l2(consat)=l1;
end
end
%qpsk symbol generations
x_q=[-1 -1 1 1];
y_q=[1 -1 1 -1];
QPSK_s=x_q+y_q*i;
QPSK_r=QPSK_s;
nofbit = 1000;
tot_bits1=round(rand(1,nofbit));
bitsnt = tot_bits1(1:N*2);
for symbl = 1: N
s(symbl) = QPSK_s(bi2de(bitsnt((2*symbl-1):(2*symbl)),'left-msb')+1);
end
s1=reshape(s,N,1);
snrj = 10;
for var2 = 1:consat
dif(:,:,var2) = zeros(nTx,T);
%channel
H = 1/sqrt(2)*[rand(nRx,nTx)+ 1j*(rand(nRx,nTx))]; % Rayleigh
channel
Noise = sqrt(2)* [rand(nRx*nTx,1)+ 1j*(rand(nRx*nTx,1))] .*(1 /
sqrt(snrj));
H1 = kron (eye(T),H);%modified rayleigh chanel
Y= H1 *Z(:,:,l2(var2))*s1 + Noise ;
shat = Z(:,:,l2(var2))' * H1' * Y ;
%find for S1 corresponding bits
for recsym = 1: N
[H2,I]=min(QPSK_s-shat(recsym));
shatdec(recsym) = QPSK_s(I);
end
shatdecr = reshape(shatdec,N,1);
for m=1:N

shatdecr(N));

dif(:,:,var2) = dif(:,:,var2) + M(:,:,m,var2) .* (s1(N)-

end
R(:,:,var2) = conj(dif(:,:,var2)) * (dif(:,:,var2))';
rk(var2)=rank(R(:,:,var2));
[U,dia,V]=svd(R(:,:,var2));
dia
if rk(var2) == nTx
J(var2)=det(dia .* rk(var2)) ;
end
if rk(var2) < nTx
J(var2 ) = 0;
end

end
J
[h4, Index] = max(J);
Index
N1 = 1;
gg = ones(1,N1);
Z11 =Kron( gg ,Z(:,:,Index));
snri = 1:5:26;
errortotal = zeros(1,length(snri));
for df=1:length(snri)
errrtotal = 0;
for par = 1:100
n_bits = randi([0,1],1,N*N1);
h= modem.qammod(4);
hd = modem.qamdemod(4);
H = 1/sqrt(2)*[rand(nRx,nTx)+ 1j*(rand(nRx,nTx))]; % Rayleigh channel
H1 = kron (eye(T),H);%modified rayleigh chanel
snew = modulate( h, n_bits);
s1=reshape(snew,N*N1,1);
Y1= H1 *Z11*s1;
Y = awgn(Y1 , snri(df));
shat = Z11' * H1'* Y ;
for recsym = 1: N*N1
[H21,In]=min(QPSK_s-shat(recsym));
dec_bit(recsym) = demodulate(hd,QPSK_s(In));
end
ratio = (sum(n_bits ~= dec_bit))/(N*N1);
errrtotal = errrtotal + ratio ;
end
errorsnr(df) = errrtotal / par;
df
end
semilogy(snri,errorsnr);

You might also like