clc;
clear all;
%% Generate the input data and mapping in BPSK Consetellation
X=zeros(64,64);
d=rand(64,1);
for i=1:64
if(d(i)>=0.5)
d(i)=+1;
else
d(i)=-1;
end
end
for i=1:64
X(i,i)=d(i);
end
%% Calculate the channel vector G from the channel characterstics
tau=[0.5 3.5];
for k=1:64
s=0;
for m=1:2
s=s+(exp(-j*pi*(1/64)*(k+63*tau(m))) * (( sin(pi*tau(m)) /...
sin(pi*(1/64)*(tau(m)-k)))));
end
g(k)=s/sqrt(64);
end
G=g';% Channel vector
H=fft(G);% Frequency Domain
XFG=X*H; % Recived DATA
n1=ones(64,1); % Noise Generation
n1=n1*0.000000000000000001i;% Join complex Gaussian white noise
noise=awgn(n1,8);% SNR is set to 8db
variance=var(noise);
N=fft(noise);
Y=XFG+N; % Recieved Data with Niose
%% Obtaining the autocorrelation matrix Rgg of channel G Auto-covariance for MMSE
gg=zeros(64,64);
for i=1:64
gg(i,i)=G(i);
end
gg_myu = sum(gg, 1)/64;
gg_mid = gg - gg_myu(ones(64,1),:);
sum_gg_mid= sum(gg_mid, 1);
Rgg = (gg_mid' * gg_mid- (sum_gg_mid' * sum_gg_mid) / 64) / (64 - 1);
%% MMSE algorithm and LS algorithm SER requirements
H_ls=(inv(X)) * Y;
Hls=zeros(64,64);
for i=1:64
Hls(i,i)=H_ls(i);
end
u=rand(64,64);
F=fft(u)*inv(u);
I=eye(64,64);
Rgy=Rgg * F'* X';
Ryy=X * F * Rgg * F' *X' + variance * I;
for i=1:64
yy(i,i)=Y(i);
end
Gmmse=Rgy * inv(Ryy)* Y;
H_mmse=fft(Gmmse);
for i=1:64
Hmmse(i,i)=H_mmse(i);
end
%% Initializing Error Counters
for n=1:6
SNR_send=3*n;
error_count_ls=0;%Empty error_count ..
error_count_mmse=0;%Empty error_count ..
%% Generating OFDM Symbols for simulation
for c=1:1000
% Generate a random sequence for input data
X=zeros(64,64);
d=rand(64,1);
for i=1:64
if(d(i)>=0.5)
d(i)=+1;
else
d(i)=-1;
end
end
for i=1:64
X(i,i)=d(i);
end
XFG=X*H;
n1=ones(64,1);
n1=n1*0.000000000000000001i;% Join complex Gaussian white noise
noise=awgn(n1,SNR_send);
variance=var(noise);
N=fft(noise);
Y=XFG+N; % Recieved signal
%% Receiver
% LS estimator
I=inv(Hls)* Y;
for k=1:64
if(real(I(k))>0)%Decision
I(k)=1;
else
I(k)=-1;
end
end
for k=1:64
if(I(k)~=d(k))
error_count_ls=error_count_ls+1;
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% I: MMSE estimator received:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
I=inv(Hmmse)* Y;
for k=1:64
if(real(I(k))>0)%Decision
I(k)=1;
else
I(k)=-1;
end
end
for k=1:64
if(I(k)~=d(k))
error_count_mmse=error_count_mmse+1;
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
end
ser_ls(n)=error_count_ls/64000;
ser_mmse(n)=error_count_mmse/64000;
ser_ls
ser_mmse
SNR(n)=SNR_send;
end;
%Mapping
semilogy(SNR,ser_mmse,'-vk');
axis([2,18,0.01,1]);
grid on;
xlabel('SNR in DB');
ylabel('Symbol Error Rate');
title('Compare OFDM systems MMSE and LS algorithm (SER)');
hold on;
semilogy(SNR,ser_ls,'-*b');
axis([2,18,0.01,1]);
grid on;
xlabel('SNR in DB');
ylabel('Symbol Error Rate');
title('Compare OFDM systems MMSE and LS algorithm (SER)');
legend('MMSE algorithm', 'LS algorithm');
hold off