Professional Documents
Culture Documents
CT516: Advanced Digital Communication Lab 4 201915010 Meemoh Haque
CT516: Advanced Digital Communication Lab 4 201915010 Meemoh Haque
CT516: Advanced Digital Communication Lab 4 201915010 Meemoh Haque
Lab 4
201915010
MEEMOH HAQUE
QPSK
CODE
clc;
clearvars;
close all;
M=4; %for 4 PSK;
K=2; %Dimension is 2
k= log2(M); %bits per symbol
Nsim=100; % number of simulations i have taken is 10
teta= pi/M:(2*pi/M):((2*M-1)*pi/M); % here i have generated M OF points which to generate a
circle
res= cos(teta); % real part of circle
end
%improved union bound
a= S-S(:,1);
b= a.^2;
c= b(1,:)+b(2,:);
d= c.^0.5;
e= (2*No).^0.5;
W=0;
for j= 2:4 % in improved union the only difference instead of subtaracting from all
constellaton points we
%we are subtracting with only nearest points
W=t+qfunc(d(j)./e);
end
%%method 1 (minimum euclidean distance)
e= r-S; % forming error matrix
norm= diag(e'*e); % finding the euclidean distance
[u,decodedindex ]= min(norm); % u gives us the minimum distance and decoded
index gives us the poisition of the minimum point
if (abs(decodedindex-sym_index)~=0) % if decoded index is not equal to symbol
index it will give us error
SER(ksnr)=SER(ksnr)+1;
end
%%method 2 % correlation method
ip= (2*r'*S)-diag(S'*S)'; %finding the inner product
[q,decodedindex]= max(ip); % after getting the inner product the correlation value which
is the max
% we will assume is transmitted
if (abs(decodedindex-sym_index)~=0)
SER2(ksnr)=SER2(ksnr)+1;
end
end
hold on
plot(r(1),r(2),'r o');
end
SERpract= SER/Nsim;
SERpract2= SER2/Nsim;
Serth=2*qfunc((2*EsNolin).^0.5*sin(pi/M));
figure(2)
semilogy(EsNodB,Serth,'r o');
hold on
semilogy(EsNodB,SERpract,'y');
hold on
semilogy(EsNodB,SERpract2,'o');
hold on
semilogy(EsNodB,t,'b');
hold on
semilogy(EsNodB,W,'g');
hold on
legend('serth','SERpract','SERpract2','t','W');
xlabel('EsNodB');
ylabel('SER');
grid on
OUTPUT
SER VS SNR PLOT
CONSTELLATION DIAGRAM WITHOUT NOISE
CONSTELLATION DIAGRAM WITH NOISE
SCATTER DIAGRAM FOR 0DB
SCATTER DIAGRAM FOR 6 DB
SCATTER DIAGRAM FOR 12 DB
INFERENCE
8PSK
CODE
clc;
clearvars;
close all;
M=8; %for 8 PSK
K=2; %Dimension is 2
k= log2(M); %bits per symbol
Nsim=100; % number of simulations i have taken is 10
teta= pi/M:(2*pi/M):((2*M-1)*pi/M); % here i have generated M OF points which to generate a
circle
res= cos(teta); % real part of circle
end
%improved union bound
a= S-S(:,1);
b= a.^2;
c= b(1,:)+b(2,:);
d= c.^0.5;
e= (2*No).^0.5;
W=0;
for j= 2:4 % in improved union the only difference instead of subtaracting from all
constellaton points we
%we are subtracting with only nearest points
W=t+qfunc(d(j)./e);
end
end
%%method 2 % correlation method
ip= (2*r'*S)-diag(S'*S)'; %finding the inner product
[q,decodedindex]= max(ip); % after getting the inner product the correlation value which
is the max
% we will assume is transmitted
if (abs(decodedindex-sym_index)~=0)
SER2(ksnr)=SER2(ksnr)+1;
end
end
OUTPUT
SER VS SNR(Db) PLOT
16 APSK
CODE
clc;
clearvars;
close all;
M=16; %for 16 APSK
M1=M/2;
K=2; %Dimension is 2
k= log2(M); %bits per symbol
Nsim=100; % number of simulations i have taken is 10
teta= pi/M1:(2*pi/M1):((2*M1-1)*pi/M1); % here i have generated M OF points which to generate
a circle
res= cos(teta); % real part of circle
end
%improved union bound
a= S-S(:,1);
b= a.^2;
c= b(1,:)+b(2,:);
d= c.^0.5;
e= (2*No).^0.5;
W=0;
for j= 2:4 % in improved union the only difference instead of subtaracting from all
constellaton points we
%we are subtracting with only nearest points
W=t+qfunc(d(j)./e);
end
%%method 1 (minimum euclidean distance)
e= r-S; % forming error matrix
norm= diag(e'*e); % finding the euclidean distance
[u,decodedindex ]= min(norm); % u gives us the minimum distance and decoded
index gives us the poisition of the minimum point
if (abs(decodedindex-sym_index)~=0) % if decoded index is not equal to symbol
index it will give us error
SER(ksnr)=SER(ksnr)+1;
end
%%method 2 % correlation method
ip= (2*r'*S)-diag(S'*S)'; %finding the inner product
[q,decodedindex]= max(ip); % after getting the inner product the correlation value which
is the max
% we will assume is transmitted
if (abs(decodedindex-sym_index)~=0)
SER2(ksnr)=SER2(ksnr)+1;
end
end
hold on
plot(r(1),r(2),'r o');
end
SERpract= SER/Nsim;
SERpract2= SER2/Nsim;
Serth=2*qfunc((2*EsNolin).^0.5*sin(pi/M));
figure(2)
semilogy(EsNodB,Serth,'r ');
hold on
semilogy(EsNodB,SERpract,'y');
hold on
semilogy(EsNodB,SERpract2);
hold on
semilogy(EsNodB,t,'b');
hold on
semilogy(EsNodB,W,'g');
hold on
legend('serth','SERpract','SERpract2','t','W');
xlabel('EsNodB');
ylabel('SER');
grid on
OUTPUT
SER VS SNR PLOT
CONSTELLATION DIAGRAM WITHOUT NOISE
CONSTELLATION DIAGRAM WITH NOISE
16 QAM
CODE
clc;
clear all;
close all;
M=16; % 16 QAM
k=log2(M); % no. of symbols
K=2; % dimension
if(mod(k,4)==0)
c0= 1:2:k-1;
c1= -(k-1:-2:1);
c=[c1 c0];
EsNodB=5:5:20; % SNR IN db
i=1;
j= EsNodB(i);
EsNolin=10.^(0.1*EsNodB); % SNR in lin
Es=trace(S'*S)/M; % energy per symbol
No=Es./EsNolin; %noise component
sigma=sqrt(No/2); % noise power
b1=2.^(k-1:-1:0) ; % for generating binary weights
Nsim=1000; % no. of experiments
for ksnr=1:length(EsNodB)
for i=1:Nsim
SER(ksnr)=0; % initializing SER for minimum distance
SER2(ksnr)=0; % initializing SER for correlation method
x=randi([0 1],1,k); % random variable is generated %
sym_index=sum(x.*b1)+1; %symbol index is generated
s=S(:,sym_index); %decoded index %
n=sigma(ksnr)*randn(K,1); %random noise generated
r=s+n;
figure(ksnr)
plot(S(1,:),S(2,:),'o');
hold on;
plot( r(1),r(2),'r o');
xlim([-3.5,3.5]);
ylim([-3.5,3.5]);
grid on;
title('constellation diagram with noise');
j= EsNodB(ksnr);
end
% correlation method % in these method we have found the maximum
% correlation between the symbols and the symbol which has the highest
% correlation is assumed to be transmitted. here inner product is done
ip= (2*r'*S)-diag(S'*S)'; %finding the inner product
[q,decodedindex]= max(ip); % after getting the inner product the correlation value which
is the max
% we will assume is transmitted
if (abs(decodedindex-sym_index)~=0)
SER2(ksnr)=SER2(ksnr)+1;
end
%union bound
a= S-S(:,1);
b= a.^2;
c= b(1,:)+b(2,:);
d= c.^0.5;
e= (2*No).^0.5;
t=0;
for u= 2:M
t=t+qfunc(d(u)./e);
end
%improved union bound
a= S-S(:,1);
b= a.^2;
c= b(1,:)+b(2,:);
d= c.^0.5;
e= (2*No).^0.5;
W=0;
for u= 2:8
W=t+qfunc(d(u)./e);
end
% hold on
%plot(r(1),r(2),'ro') % here r is real only so we take r(1) & r(2) instead of real(r) & img(r)
end
end
serpract= SER/Nsim;
serpract2= SER2/Nsim;
Serth=4*(1-(1/sqrt(M)))*qfunc((sqrt(3*EsNolin/(M-1)))); % theortical formula for 16 qam
figure(2)
semilogy(EsNodB,Serth,'o'); % plotting the theortical value in log scale
hold on
semilogy(EsNodB,t,'r'); % plotting the union bound
hold on
semilogy(EsNodB,W); % plotting the improved union bound
hold on
semilogy(EsNodB,serpract ,'y'); % plotting the minimum distance
hold on
semilogy(EsNodB,serpract2 ,'g'); % plotting the inner product method
legend('serth','t','serpract','serpract2','W');
xlabel('EsNodB');
ylabel('SNR');
grid on
OUTPUT
SER VS SNR(DB) PLOT
CONSTELLATION DIAGRAM WITHOUT NOISE
CONSTELLATION DIAGRAM WITHOUT NOISE
SCATTER DIAGRAM 0 DB
SCATTER DIAGRAM 6db
SCATTER DIAGRAM 12 DB
INFERENCE
64 QAM
CODE
clc;
clear all;
close all;
M=64; % 64 QAM
k=log2(M); % no. of symbols
K=2; % dimension
if(mod(k,4)==0)
c0= 1:2:k-1;
c1= -(k-1:-2:1);
c=[c1 c0];
EsNodB=0:6:12; % SNR IN db
i=1;
j= EsNodB(i);
EsNolin=10.^(0.1*EsNodB); % SNR in lin
Es=trace(S'*S)/M; % energy per symbol
No=Es./EsNolin; %noise component
sigma=sqrt(No/2); % noise power
b1=2.^(k-1:-1:0) ; % for generating binary weights
Nsim=100; % no. of experiments
for ksnr=1:length(EsNodB)
for i=1:Nsim
SER(ksnr)=0; % initializing SER for minimum distance
SER2(ksnr)=0; % initializing SER for correlation method
x=randi([0 1],1,k); % random variable is generated %
sym_index=sum(x.*b1)+1; %symbol index is generated
s=S(:,sym_index); %decoded index %
n=sigma(ksnr)*randn(K,1); %random noise generated
r=s+n;
figure(ksnr)
plot(S(1,:),S(2,:),'o');
hold on;
plot( r(1),r(2),'r o');
xlim([-3.5,3.5]);
ylim([-3.5,3.5]);
grid on;
end
% correlation method % in these method we have found the maximum
% correlation between the symbols and the symbol which has the highest
% correlation is assumed to be transmitted. here inner product is done
ip= (2*r'*S)-diag(S'*S)'; %finding the inner product
[q,decodedindex]= max(ip); % after getting the inner product the correlation value which
is the max
% we will assume is transmitted
if (abs(decodedindex-sym_index)~=0)
SER2(ksnr)=SER2(ksnr)+1;
end
%union bound
a= S-S(:,1);
b= a.^2;
c= b(1,:)+b(2,:);
d= c.^0.5;
e= (2*No).^0.5;
t=0;
for u= 2:M
t=t+qfunc(d(u)./e);
end
%improved union bound
a= S-S(:,1);
b= a.^2;
c= b(1,:)+b(2,:);
d= c.^0.5;
e= (2*No).^0.5;
W=0;
for u= 2:8
W=t+qfunc(d(u)./e);
end
hold on
plot(r(1),r(2),'ro') % here r is real only so we take r(1) & r(2) instead of real(r) & img(r)
end
end
serpract= SER/Nsim;
serpract2= SER2/Nsim;
Serth=4*(1-(1/sqrt(M)))*qfunc((sqrt(3*EsNolin/(M-1)))); % theortical formula for 16 qam
figure(2)
semilogy(EsNodB,Serth,'o'); % plotting the theortical value in log scale
hold on
semilogy(EsNodB,t,'r'); % plotting the union bound
hold on
semilogy(EsNodB,W); % plotting the improved union bound
hold on
semilogy(EsNodB,serpract ,'y'); % plotting the minimum distance
hold on
semilogy(EsNodB,serpract2 ,'g'); % plotting the inner product method
legend('serth','t','serpract','serpract2','W');
xlabel('EsNodB');
ylabel('SNR');
grid on
OUTPUT
clc;
clear all
close all
q=0.5; % p(X=1)=0.5
M=8;
k=log2(M); % no. of symbols
K=M; % dimension
S= eye(M);%returns an n-by-n identity matrix with ones on the main
diagonal and zeros elsewhere.
Es=trace(S'*S)/M; % per symbol energy
decoded_symbol=g;
if sym_index~=decoded_symbol % find which symbol is in error
ser(ksnr)=ser(ksnr)+1;
end
% correlation (in these method we will find the symbol which has the
% maximum correlation or similarity and then that symbol is assume
% to be transmitted
[~,g1]=max(2*r'*S-diag(S'*S)');
decoded_symbol=g1;
if sym_index~=decoded_symbol % find which symbol is in error
ser2(ksnr)=ser2(ksnr)+1;
end
% hold on
%plot(r(1),r(2),'ro') % here r is real only so we take r(1) & r(2) instead
of real(r) & img(r)
serpract=ser/Nsim;
serpract2= ser2/Nsim;
%union bound
a= S-S(:,1);
b= a.^2;
c=0;
for j=1:K
c= c+b(j,:);
end
d= c.^0.5;
e= (2*No).^0.5;
t=0;
for j= 2:M
t=t+qfunc(d(j)./e);
end
%improved union bound
a= S-S(:,1);
b= a.^2;
c=0;
for j=1:K
c= c+b(j,:);
end
d= c.^0.5;
e= (2*No).^0.5;
W=0;
for j= 2:4
W=W+qfunc(d(j)./e);
end
end
end
yb= 1.485;
v=(M-1)*(qfunc(sqrt(log2(M)*yb)));
serth=2*qfunc(v);
figure(2)
semilogy(EsNodB,serpract,'o');
hold on
semilogy(EsNodB,t);
hold on
semilogy(EsNodB,serth);
hold on
semilogy(EsNodB,W);
legend('serpract','t','serpract2','W');
grid on
OUTPUT
INFERENCE
decoded_symbol=g;
if sym_index~=decoded_symbol % find which symbol is in error
ser(ksnr)=ser(ksnr)+1;
end
% correlation (in these method we will find the symbol which has the
% maximum correlation or similarity and then that symbol is assume
% to be transmitted
[~,g1]=max(2*r'*S-diag(S'*S)');
decoded_symbol=g1;
if sym_index~=decoded_symbol % find which symbol is in error
ser2(ksnr)=ser2(ksnr)+1;
end
% hold on
%plot(r(1),r(2),'ro') % here r is real only so we take r(1) & r(2) instead
of real(r) & img(r)
serpract=ser/Nsim;
serpract2= ser2/Nsim;
%union bound
a= S-S(:,1);
b= a.^2;
c=0;
for j=1:K
c= c+b(j,:);
end
d= c.^0.5;
e= (2*No).^0.5;
t=0;
for j= 2:M
t=t+qfunc(d(j)./e);
end
%improved union bound
a= S-S(:,1);
b= a.^2;
c=0;
for j=1:K
c= c+b(j,:);
end
d= c.^0.5;
e= (2*No).^0.5;
W=0;
for j= 2:4
W=W+qfunc(d(j)./e);
end
end
end
yb= 1.485;
v=(M-2)*(qfunc(sqrt(log2(M)*yb)));
serth=2*qfunc(v);
figure(2)
semilogy(EsNodB,serpract,'o');
hold on
semilogy(EsNodB,t);
hold on
semilogy(EsNodB,serth);
hold on
semilogy(EsNodB,W);
legend('serpract','t','serpract2','W');
grid on
OUTPUT
SER VS SNR PLOT
CONSTELLATION DIAGRAM
SCATTER DIAGRAM 0DB
SCATTER DIAGRAM 6db
SCATTER DIAGRAM 12 DB
INFERENCE
% minimum distance
e= r-S; % forming error matrix
norm= diag(e'*e); % finding the euclidean distance
[u,decodedindex ]= min(norm); % u gives us the minimum
distance and decoded index gives us the poisition of the minimum point
if (abs(decodedindex-sym_index)~=0) % if decoded index is not
equal to symbol index it will give us error
ser(ksnr)=ser(ksnr)+1;
end
% correlation
ip= (2*r'*S)-diag(S'*S)'; %finding the inner product
[q,decodedindex]= max(ip); % after getting the inner product the
correlation value which is the max
% we will assume is transmitted
if (abs(decodedindex-sym_index)~=0)
ser2(ksnr)=ser2(ksnr)+1;
end
end
hold on
plot(r(1),r(2),ro') % here r is real only so we take r(1) & r(2) instead of
real(r) & img(r)'
serpract=ser/Nsim;
serpract2= ser2/Nsim;
%union bound
a= S-S(:,1);
b= a.^2;
c=0;
for j=1:K
c= c+b(j,:);
end
d= c.^0.5;
e= (2*No).^0.5;
t=0;
for j= 2:M
t=t+qfunc(d(j)./e);
end
%improved union bound
a= S-S(:,1);
b= a.^2;
c=0;
for j=1:K
c= c+b(j,:);
end
d= c.^0.5;
e= (2*No).^0.5;
W=0;
for j= 2:4
W=W+qfunc(d(j)./e);
end
end
yb= 1.485;
v=(M-2)*(qfunc(sqrt(log2(M)*yb)));
serth=2*qfunc(v);
figure(2)
semilogy(EsNodB,serpract);
hold on
semilogy(EsNodB,t);
hold on
semilogy(EsNodB,serpract2);
hold on
semilogy(EsNodB,serth);
hold on
semilogy(EsNodB,W);
legend('serpract','t','serpract2','serth','W');
grid on
OUTPUT
SER VS SNR PLOT
CONSTELLATION DIAGRAM
SCATTER DIAGRAM 0DB
SCATTER DIAGRAM 6db
SCATTER DIAGRAM 12 DB