%mmwavechannelestimation.m
%Illustration of Estimation of mmWave channel matrix using pilot
%transmission during uplink transmission
%Number of transmitting antenna (M)
%Number of receiving antenna (N)
%Number of paths (L)
%Number of symbols (S)
%P is the pilot symbol matrix and is chosen as identity matrix
%Number of blocks (nob)
%Number of RF chain (RF)
%Analog precoder (PR)
%Discrete precoder (PB)
%Analog combiner (CR)
%Discrete combiner (CB)
S=4;
P=diag(ones(1,4));
M=4;
N=8;
L=3;
RF=2;
nob=2;
PR=dftmatrix(M);
Block1=[dftmatrix(2);zeros(2,2)];
Block2=[zeros(2,2);dftmatrix(2)];
PB=[Block1 Block2];
Block1=[dftmatrix(2);zeros(6,2)];
Block2=[zeros(2,2);dftmatrix(2);zeros(4,2)];
Block3=[zeros(4,2);dftmatrix(2);zeros(2,2)];
Block4=[zeros(6,2);dftmatrix(2)];
CB=[Block1 Block2 Block3 Block4];
CR=dftmatrix(N);
lambda=5*10ˆ(-3);
dr=lambda/4;
dt=lambda/4;
resolution=256;
DT=dictionarymatrix(M,resolution,dr,lambda);
DR=dictionarymatrix(N,resolution,dt,lambda);
G=rand(1,L)*10;
PART1=DT*PR*PB;
PART2=CR'*CB'*DR';
Q=kron(transpose(PART1),PART2);
AOA=rand(1,L)*pi;
AOD=rand(1,L)*pi;
[H]=raychannelmatrix(M,N,L,AOA,AOD,dr,dt,lambda,G);
%Receivedsignal matrix
Y=sqrt(10)*CR'*CB'*H*PR*PB+0.1*(randn(8,4)+j*randn(8,4));
y=reshape(Y,size(Y,1)*size(Y,2),1);
hest=ompsol(Q,y,L);
[P,Q]=sort(-1*hest);
Hest=DR'*reshape(hest,255,255)*DT;
figure(1)
subplot(2,2,1)
imagesc(abs(H))
title('Absolute value of the actual channel matrix')
subplot(2,2,2)
imagesc(angle(H))
title('Phase value of the actual channel matrix')
subplot(2,2,3)
imagesc(abs(Hest))
title('Absolute value of the actual channel matrix')
subplot(2,2,4)
imagesc(angle(Hest))
title('Phase value of the estimaged channel matrix')
figure(2)
plot(abs(hest))
title('Illustration of identified number of paths between the transmitter antennas and the receiver antennas ')
