0% found this document useful (0 votes)
63 views

CT516: Advanced Digital Communication Lab 4 201915010 Meemoh Haque

This document contains MATLAB code to simulate and analyze digital communication systems using different modulation schemes: 1. QPSK modulation is implemented and the bit error rate (BER) vs signal-to-noise ratio (SNR) plot is generated. Constellation diagrams with and without noise are also plotted. 2. The code is extended to 8PSK modulation and similar analysis is performed. 3. 16APSK modulation using two concentric circles is implemented. BER analysis and constellation diagrams are generated.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views

CT516: Advanced Digital Communication Lab 4 201915010 Meemoh Haque

This document contains MATLAB code to simulate and analyze digital communication systems using different modulation schemes: 1. QPSK modulation is implemented and the bit error rate (BER) vs signal-to-noise ratio (SNR) plot is generated. Constellation diagrams with and without noise are also plotted. 2. The code is extended to 8PSK modulation and similar analysis is performed. 3. 16APSK modulation using two concentric circles is implemented. BER analysis and constellation diagrams are generated.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 59

CT516: Advanced Digital Communication

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

ims= sin(teta);% imaginary part of circle


S= [res;ims]; % S matrix is formed which consist of both real and imaginary(S consisit of all th
symbol points )
plot(res,ims,'o');
axis([-1.5 1.5 -1.5 1.5]); % For proper allignment

Es= trace(S'*S)/M; % energy per symbol


EsNodB= 0:6:12; % EsNodB taken in the range of 0 to 20db in steps of 5
EsNolin= 10.^(EsNodB/10); % conversion of EsNodB to EsNolin
No= Es./EsNolin; % noise component
sigman= sqrt(No/2); % noise power

for ksnr= 1:length(EsNodB) % we


SER(ksnr)=0; % for minimum distance initialising SER
SER2(ksnr)=0; % for correlation method initialising SER
for i= 1:Nsim % we will the run for loop for Nsim times
x=randi([0 1],1,k); %generate a random variable
sym_index =1; % symbol index initialized
for j=1:k
sym_index= x(j).*(2.^(k-j))+sym_index;%
end
s= S(:,sym_index); % s gives us the coloumn of S matrix which gets decoded
n=sigman(ksnr)*randn(K,1); % for generating random noise(we have generated noise
intentionally)
r=s+n; % at the reciever which consist of signal and noise
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);

title(['SNR = ',num2str(j),' dB'])


%%union bound
a= S-S(:,1); % subtracting S matrix with the first coloumn of S matrix
b= a.^2; % squaring all the elements of new matrix which we got after subtracting
c= b.^0.5; % taking root
d= c(1,:)+c(2,:); %here we are adding first row with second row and hence we got distance
matrix
e= (2*No).^0.5;
t=0;
for j= 2:M % loop is run from 2 to M symbol ponits first element is neeglected as it is zero
already
t=t+qfunc(d(j)./e); % forming the probability of error using union bound

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

ims= sin(teta);% imaginary part of circle


S= [res;ims]; % S matrix is formed which consist of both real and imaginary(S consisit of all th
symbol points )
plot(res,ims,'o');
axis([-1.5 1.5 -1.5 1.5]); % For proper allignment

Es= trace(S'*S)/M; % energy per symbol


EsNodB= 0:6:12; % EsNodB taken in the range of 0 to 20db in steps of 5
EsNolin= 10.^(EsNodB/10); % conversion of EsNodB to EsNolin
No= Es./EsNolin; % noise component
sigman= sqrt(No/2); % noise power

for ksnr= 1:length(EsNodB)


SER(ksnr)=0; % for minimum distance initialising SER
SER2(ksnr)=0; % for correlation method initialising SER
for i= 1:Nsim % we will the run for loop for Nsim times
x=randi([0 1],1,k); %generate a random variable
sym_index =1; % symbol index initialized
for j=1:k
sym_index= x(j).*(2.^(k-j))+sym_index;%
end

s= S(:,sym_index); % s gives us the coloumn of S matrix which gets decoded


n=sigman(ksnr)*randn(K,1); % for generating random noise(we have generated noise
intentionally)
r=s+n; % at the reciever which consist of signal and noise
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);

title(['SNR = ',num2str(j),' dB'])


%%union bound
a= S-S(:,1); % subtracting S matrix with the first coloumn of S matrix
b= a.^2; % squaring all the elements of new matrix which we got after subtracting
c= b.^0.5; % taking root
d= c(1,:)+c(2,:); %here we are adding first row with second row and hence we got distance
matrix
e= (2*No).^0.5;
t=0;
for j= 2:M % loop is run from 2 to M symbol ponits first element is neeglected as it is zero
already
t=t+qfunc(d(j)./e); % forming the probability of error using union bound

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

OUTPUT
SER VS SNR(Db) PLOT

CONSTELLATION DIAGRAM WITHOUT NOISE


CONSTELLATION DIAGRAM WITH NOISE
SCATTER DIAGRAM 0DB
SCATTER DIAGRAM FOR 6 DB
SCATTER DIAGRAM FOR 12 DB
INFERENCE

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

ims= sin(teta);% imaginary part of circle


S1= [res;ims]; % S matrix is formed which consist of both real and imaginary(S consisit of all th
symbol points )
R=2; % here for 16 apsk we need two concentric circles one with a higher radius
S= [ S1 R*S1]; %so we have generated new matrix of higher dimension
%plot(res,ims,'o'); % plot S
%hold on
plot(S(1,:),S(2,:),'o');
%axis([-1.5 1.5 -1.5 1.5]); % For proper allignment

Es= trace(S'*S)/M; % energy per symbol


EsNodB= 0:6:12; % EsNodB taken in the range of 0 to 20db in steps of 5
EsNolin= 10.^(EsNodB/10); % conversion of EsNodB to EsNolin
No= Es./EsNolin; % noise component
sigman= sqrt(No/2); % noise power

for ksnr= 1:length(EsNodB) % we


SER(ksnr)=0; % for minimum distance initialising SER
SER2(ksnr)=0; % for correlation method initialising SER
for i= 1:Nsim % we will the run for loop for Nsim times
x=randi([0 1],1,k); %generate a random variable
sym_index =1; % symbol index initialized
for j=1:k
sym_index= x(j).*(2.^(k-j))+sym_index;%
end

s= S(:,sym_index); % s gives us the coloumn of S matrix which gets decoded


n=sigman(ksnr)*randn(K,1); % for generating random noise(we have generated noise
intentionally)
r=s+n; % at the reciever which consist of signal and noise
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);

title(['SNR = ',num2str(j),' dB'])


%%union bound
a= S-S(:,1); % subtracting S matrix with the first coloumn of S matrix
b= a.^2; % squaring all the elements of new matrix which we got after subtracting
c= b.^0.5; % taking root
d= c(1,:)+c(2,:); %here we are adding first row with second row and hence we got distance
matrix
e= (2*No).^0.5;
t=0;
for j= 2:M % loop is run from 2 to M symbol ponits first element is neeglected as it is zero
already
t=t+qfunc(d(j)./e); % forming the probability of error using union bound

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

SCATTER DIAGRAM 0DB


SCATTER DIAGRAM 6 DB
SCATTER DIAGRAM 12 DB
INFERENCE

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];

[a b]=meshgrid(c); %it returns grid cordinates of grid length of a and b


d=reshape(a,[1,M]); % reshape convert a from 2x16 to 1x16

e=reshape(b,[1,M]) ; % reshape convert b from 2x16 to 1x21


S=[d;e]; % S matrix is formed
else
k1=k+2;
c0= 1:2:k1-1;
c1= -(k1-1:-2:1);
c= [c1 c0];
[a b]=meshgrid(c);
d=reshape(a,[1,M]); % convert a from 2x16 to 1x16

e=reshape(b,[1,M]) ; % convert b from 2x16 to 1x21


S=[d;e];
end
plot(S(1,:),S(2,:),'o'); % plot S entire 1ST coloumn and then entire 2nd coloumn
grid on
axis([-5 5 -5 5])

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

%ser=zeros(1,length(EsNodB)); %ser values are generated

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);

title(['SNR = ',num2str(j),' dB'])


%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 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];

[a b]=meshgrid(c); %it returns grid cordinates of grid length of a and b


d=reshape(a,[1,M]); % reshape convert a from 2x16 to 1x16

e=reshape(b,[1,M]) ; % reshape convert b from 2x16 to 1x21


S=[d;e]; % S matrix is formed
else
k1=k+2;
c0= 1:2:k1-1;
c1= -(k1-1:-2:1);
c= [c1 c0];
[a b]=meshgrid(c);
d=reshape(a,[1,M]); % convert a from 2x16 to 1x16

e=reshape(b,[1,M]) ; % convert b from 2x16 to 1x21


S=[d;e];
end
plot(S(1,:),S(2,:),'o'); % plot S entire 1ST coloumn and then entire 2nd coloumn
grid on
axis([-5 5 -5 5])

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

%ser=zeros(1,length(EsNodB)); %ser values are generated

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);

title(['SNR = ',num2str(j),' dB'])


%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 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 PLOT


COSTELLATION DIAGRAM WITHOUT NOISE
CONSTELLATION DIAGRAM WITH NOISE
16 ARY ORTHOGONAL MODULATION
CODE

16 ARY ORTHOGONAL MODULATION


CODE

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

EsNodB=0:20; % in steps of 1 dB for Monte-Carlo simulations,


EsNolin= 10.^(EsNodB/10); % SNR linear
No=Es./EsNolin; %standard noise component
sigma=sqrt(No/2); % noise power

Nsim=1000; % no. of experiments


for ksnr=1:length(EsNodB)
ser(ksnr)=0;
ser2(ksnr)=0;
for i=1:Nsim
x=randi([0 1],1,k); % generating random variable of dimension
k
sym_index =1;
for j=1:k
sym_index= x(j).*(2.^(k-j))+sym_index; % getting different symbol
index for different random variable
end
s=S(:,sym_index); % all rows & a particular element
n=sigma(ksnr)*randn(K,1);% generating noise
r=s+n; %recieved signal
%%minimum distance (in these method will find the distance of all
%%constellation points out of which the minimum distance point will
%%be transmitted
e=r-S; %error matrix

nom=(e'*e); % finding norm of error matrix


diagnl_nom=diag(nom); % taking the diaognal elements of norm
matrix
[~,g]=min(diagnl_nom);% taking the minimum of diagnaol mtarix

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

16 ARY BIORTHOGONAL MODULATION


CODE
clc;
clear all;
close all;
M=8;
k=log2(M); % no. of symbols
K=M; % dimension
S= eye(M);
s1= eye(M/2);
s2= [s1 -1*s1];
Es=trace(S'*S)/M; % per symbol energy

EsNodB=0:20; % in steps of 1 dB for Monte-Carlo simulations,


EsNolin= 10.^(EsNodB/10); % SNR linear
No=Es./EsNolin; %standard noise component
sigma=sqrt(No/2); % noise power

Nsim=1000; % no. of experiments


for ksnr=1:length(EsNodB)
ser(ksnr)=0;
ser2(ksnr)=0;
for i=1:Nsim
x=randi([0 1],1,k); % generating random variable of dimension
k
sym_index =1;
for j=1:k
sym_index= x(j).*(2.^(k-j))+sym_index; % getting different symbol
index for different random variable
end
s=S(:,sym_index); % all rows & a particular element
n=sigma(ksnr)*randn(K,1);% generating noise
r=s+n; %recieved signal
%%minimum distance (in these method will find the distance of all
%%constellation points out of which the minimum distance point will
%%be transmitted

e=r-S; %error matrix

nom=(e'*e); % finding norm of error matrix


diagnl_nom=diag(nom); % taking the diaognal elements of norm
matrix
[~,g]=min(diagnl_nom);% taking the minimum of diagnaol mtarix

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

16 ARY BIORTHOGONAL MODULATION


CODE
clc;
clear all;
close all;
M=8;
k=log2(M); % no. of symbols
K=M; % dimension
S= eye(M);
s1= eye(M/2); % the idengtity matrix is divided by 2
s2= [s1 -1*s1]; % by these we have generated a identity matrix by which
the other half becomes negative of other
Es=trace(S'*S)/M;

EsNodB=0:6:12; % in steps of 1 dB for Monte-Carlo simulations,


EsNolin= 10.^(EsNodB/10);
No=Es./EsNolin;
sigma=sqrt(No/2);
%b1=(2^(k-1)):-1:1

Nsim=100; % no. of experiments


for ksnr=1:length(EsNodB)
ser(ksnr)=0;
ser2(ksnr)=0;
for i=1:Nsim
x=randi([0 1],1,k); % 1x2 matrix
sym_index =1;
for j=1:k
sym_index= x(j).*(2.^(k-j))+sym_index;
end
s=S(:,sym_index); % all rows & a particular element
n=sigma(ksnr)*randn(K,1);
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);

title(['SNR = ',num2str(j),' dB'])

% 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

You might also like