clc;
clear all;
close all;
alpha=0.1; %%%Regularization parameter
Eb_No_dB=[0:3:25];
iter=50;
MQ=4;
kM=log2(MQ);
hbittoint=comm.BitToInteger(kM);
Nr=2;
Nt=2;
N=128; %%%DFT
M=256; %%%%IDFT
Q=M/N;
K=2; %%No. of active users
L=20; %%%%%No. of Taps
%%%%%%M-Pt Fourier matrix%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FM=zeros(M,M);
for m=1:M
for k=1:M
FM(m,k)=sqrt(1/M)*exp(((-j*2*pi)/M)*(m-1)*(k-1));
FM_inv(m,k)=sqrt(1/M)*exp(((j*2*pi)/M)*(m-1)*(k-1));
end
end
%FM_inv=FM';
Ik=eye(K);
DFm=kron(Ik,FM);
DFm_inv=kron(Ik,FM_inv);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%N-Pt Fourier matrix%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FN=zeros(N,N);
for m=1:N
for k=1:N
FN(m,k)=sqrt(1/N)*exp(((-j*2*pi)/N)*(m-1)*(k-1));
FN_inv(m,k)=sqrt(1/N)*exp(((j*2*pi)/N)*(m-1)*(k-1));
end
end
%FN_inv=FN';
Ik=eye(K);
DFn=kron(Ik,FN);
DFn_inv=kron(Ik,FN_inv);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%Interference matrix%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
epsilonu=[0.1,0.1];
Eu(:,:,:)=zeros(M,M,K);
for u=1:K
for m=0:M-1
Eu(m+1,m+1,u)=exp((j*2*pi*epsilonu(u)*m)/M);
end
end
for u=1:K
pi_cir_u(:,:,u)=FM*Eu(:,:,u)*FM_inv;
pi_u(:,:,u)=kron(eye(Nt),pi_cir_u(:,:,u));
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%Subcarrier mapping matrix IFDMA%%%%%%%%%%%%%%%%%%%
u=1;
Ul=eye(N);
% MTu=[];
% for l=1:N
% MTu=[MTu;zeros(u-1,N);Ul(l,:);zeros(Q-u,N)];
% end
%Fn_inv=MTu.';
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
nerr=zeros(1,length(Eb_No_dB));
ercnt=zeros(1,length(Eb_No_dB));
nerr1=zeros(1,length(Eb_No_dB));
ercnt1=zeros(1,length(Eb_No_dB));
for it=1:iter
it
for kk=1:length(Eb_No_dB)
%%%%%%%%%%%%%%%%%%%%%%%User data%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
data_ref=[];
for u=1:K
xbar_u_1=[];
data1=round(rand(1,kM*N*Nt));
bit1=data1.';
data_ref=[data_ref; bit1];
xsym_int1=step(hbittoint,bit1);
xsym1=modulate(modem.qammod(MQ),xsym_int1);
xsym(:,u)=xsym1;
MTu=[];
for l=1:N
MTu=[MTu;zeros(u-1,N);Ul(l,:);zeros(Q-u,N)];
end
MTkk(:,:,u)=MTu;
for ant=1:Nt
xbar_u_inter=MTu*FN*xsym1((ant-1)*N+1:ant*N);
xbar_u_1= [xbar_u_1; xbar_u_inter];
end
xbar_u(:,u)=xbar_u_1;
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%Channel in Freq domain%%%%%%%%%%%%%%%%%%%%%%%%%
lambdau=zeros(Nr*M,Nt*M,K);
H=zeros(2*M,2*M,K);
H11=zeros(M,M,K);
H12=zeros(M,M,K);
H21=zeros(M,M,K);
H22=zeros(M,M,K);
for u=1:K
h1=(1./sqrt(2)).*(randn(1,L)+j*randn(1,L));
Hfft1=fft(h1,M);
for kl = 1:M
H11(kl,kl,u) = Hfft1(kl);
end
h1=(1./sqrt(2)).*(randn(1,L)+j*randn(1,L));
Hfft1=fft(h1,M);
for kl = 1:M
H12(kl,kl,u) = Hfft1(kl);
end
h1=(1./sqrt(2)).*(randn(1,L)+j*randn(1,L));
Hfft1=fft(h1,M);
for kl = 1:M
H21(kl,kl,u) = Hfft1(kl);
end
h1=(1./sqrt(2)).*(randn(1,L)+j*randn(1,L));
Hfft1=fft(h1,M);
for kl = 1:M
H22(kl,kl,u) = Hfft1(kl);
end
H(:,:,u)=[H11(:,:,u) H12(:,:,u); H21(:,:,u) H22(:,:,u)];
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%noise generation%%%%%%%%%%%%%%%%%%%%%%%%%%%
noise_unit_dB = 1/sqrt(2) *(randn(2*M,1)+j*randn(2*M,1));
No = 10^(-Eb_No_dB(kk)/10);
wtilda = sqrt(No)* noise_unit_dB;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%Received signal in freq domain%%%%%%%%%%%%%%%%
R=zeros(2*M,1);
for u=1:K
xbar_u_user=xbar_u(:,u);
R=R+ pi_u(:,:,u)*H(:,:,u)*xbar_u_user;
end
R=R+wtilda; %%%%Noise addition
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%Receiver M-FFT process%%%%%%%%%%%%%%%%%
FM_1=kron(eye(Nr),FM);
R_FFT= FM_1*R;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%Demapping process and Equalization%%%%%%%%%%%%%%%%%%%%%%%%%%
pi_P_k=zeros(K*N,K*N);
%xcap=zeros(K*N,K*N,K);
%Rdk=[];
xcap_blast=zeros(Nr*N,K);
for k=1:K
MTk=[];
for l=1:N
MTk=[MTk;zeros(k-1,N);Ul(l,:);zeros(Q-k,N)];
end
MRk=MTk.';
demap=kron(eye(2),MRk);
Rdk= demap*R;
%pi_d_bar_k_inter=MRk*pi_cir_u(:,:,k)*MTk;
%H_eq=kron(eye(2),pi_d_bar_k_inter)*kron(eye(2),FM)*H(:,:,k)*kron(eye(2),FM_inv)*kron(eye(2),MTk);
H_eq=kron(eye(2),MRk)*pi_u(:,:,k)*H(:,:,k)*kron(eye(2),MTk);
%H_eq=kron(eye(2),MRk)*H(:,:,k)*kron(eye(2),MTk);
%H_eq1=(kron(eye(2),MRk)*kron(eye(2),FM))*((H(:,:,1)*kron(eye(2),FM_inv)*kron(eye(2),MTkk(:,:,1)))+(H(:,:,2)*kron(eye(2),FM_inv)*kron(eye(2),MTkk(:,:,2))));
% pi_P_k=[MRk*FM*H11(:,:,k) MRk*FM*H12(:,:,k); MRk*FM*H21(:,:,k) MRk*FM*H22(:,:,k)];
c=alpha.*eye(M);% Regularization parameter
xcap_freq(:,k)= ((inv(H_eq'*H_eq+c))*H_eq')*Rdk;
H_eq_mmse=((inv(H_eq'*H_eq+c))*H_eq');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
q_her=H_eq_mmse(1:N,:);
y1_cap=FN_inv*(q_her*Rdk);
xcap_blast(1:N,k)=demodulate(modem.qamdemod(MQ),y1_cap);
hMod=modem.qammod(MQ);
x1_cap=modulate(hMod,xcap_blast(1:N,k));
x1_cap_freq=FN*x1_cap;
y2_cap=FN_inv*(H_eq_mmse(N+1:Nr*N,:)*(Rdk-(H_eq(:,1:N)*x1_cap_freq)));
xcap_blast(N+1:end,k)=demodulate(modem.qamdemod(MQ),y2_cap);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
FN_inv_1=kron(eye(2),FN_inv);
xcap(:,k)=FN_inv_1*xcap_freq(:,k);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%Multiplexing%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%