Mohit S Ec372 Lab4
Mohit S Ec372 Lab4
Code:
● Main code:
%% data
clc;
clear all;
close all;
snri=(-10:2:40);
qam=[4,16,64];
capacity = zeros(length(qam),length(snri));
for qami=1:length(qam)
for index=1:length(snri)
capacity(qami,index) = QAMCapacity(snri(index),1,qam(qami));
end
end
figure;
hold
for qami=1:length(qam)
plot(snri,capacity(qami,:),'LineWidth',1.6);
end
GaussianC = zeros(1,length(snri));
for index=1:length(snri)
GaussianC(index) = log2(1+ 10^(snri(index)/10));
end
plot(snri,GaussianC);
legend('4-QAM','16-QAM','64-QAM','GaussianC');
set(gca,'FontSize', 12, 'FontName', 'Times New Roman');
grid on;
box on;
xlabel('SNR (Es/No) dB','FontSize', 14, 'FontName', 'Times New Roman');
ylabel('Capacity-QAM (bits/Tx)','FontSize',14,'FontName', 'Times New Roman');
● QAMCapacity.m:
x=[
-4.688738939
-3.869447905
-3.176999162
-2.546202158
-1.951787991
-1.380258539
-0.822951449
-0.273481046
0.273481046
0.822951449
1.380258539
1.951787991
2.546202158
3.176999162
3.869447905
4.688738939
];
w=[
2.65E-10
2.32E-07
2.71E-05
0.000932284
0.012880312
0.083810041
0.280647459
0.507929479
0.507929479
0.280647459
0.083810041
0.012880312
0.000932284
2.71E-05
2.32E-07
2.65E-10
];
SNRlin= 10^(SNR/10);
SNRaff=abs(fading)*sqrt(SNRlin);
if (QAMsize==4)||(QAMsize==16)||(QAMsize==64)
h = modem.qammod('M', QAMsize, 'SymbolOrder', 'Gray','InputType', 'Bit');
else
error('the modulation size %d is not supported!', QAMsize);
end
NormFactor = sqrt(QAMsize/sum(abs (h.Constellation).^2));
Constellation = NormFactor.*h.Constellation;
C1 = zeros(1,16);
C2 = zeros(16,16);
Capforx = zeros(1,QAMsize);
if (QAMsize==4)||(QAMsize==16)||(QAMsize==64)
for xindex = 1:QAMsize
for m1=1:16
for m2=1:16
sumoverxprime = 0;
for xprimeindex=1:QAMsize
sumoverxprime = sumoverxprime + ...
exp(-abs(SNRaff.*(Constellation(xindex)-Constellation(xprimeindex))+x(m1)+sqrt(-1).*x(
m2)).^2 ...
+x(m1).^2+x(m2).^2);
end
C2(m1,m2)=1/(pi)*w(m1)*w(m2)*log2(sumoverxprime);
end
end
Capforx(xindex) = sum(sum(C2,1),2);
end
InstCap = log2(QAMsize) - 1/QAMsize *sum (Capforx);
else
error('the modulation size %d is not supported!', QAMsize);
end
Plot:
PSK:
Code:
● Main Code:
clc;
clear all;
close all;
snri=(-10:2:40);
psk=[2,4,8,16,32,64];
capacity = zeros(length(psk),length(snri));
for pski=1:length(psk)
for index=1:length(snri)
capacity(pski,index) = PSKCapacity(snri(index),1,psk(pski));
end
end
figure;
hold
for pski=1:length(psk)
plot(snri,capacity(pski,:),'LineWidth',1.6);
end
GaussianC = zeros(1,length(snri));
for index=1:length(snri)
GaussianC(index) = log2(1+ 10^(snri(index)/10));
end
plot(snri,GaussianC);
legend('BPSK','QPSK','8-PSK','16-PSK','32-PSK','64-PSK','GaussianC');
set(gca,'FontSize', 12, 'FontName', 'Times New Roman');
grid on;
box on;
xlabel('SNR (Es/No) dB','FontSize', 14, 'FontName', 'Times New Roman');
ylabel('Capacity-PAM (bits/Tx)','FontSize',14,'FontName', 'Times New Roman');
● PSKCapacity.m:
x=[
-4.688738939
-3.869447905
-3.176999162
-2.546202158
-1.951787991
-1.380258539
-0.822951449
-0.273481046
0.273481046
0.822951449
1.380258539
1.951787991
2.546202158
3.176999162
3.869447905
4.688738939
];
w=[
2.65E-10
2.32E-07
2.71E-05
0.000932284
0.012880312
0.083810041
0.280647459
0.507929479
0.507929479
0.280647459
0.083810041
0.012880312
0.000932284
2.71E-05
2.32E-07
2.65E-10
];
SNRlin= 10^(SNR/10);
SNRaff=abs(fading)*sqrt(SNRlin);
if (QAMsize==2)||(QAMsize==4)||(QAMsize==16)||...
(QAMsize==64)||(QAMsize==32)
h = modem.pskmod('M', QAMsize, 'SymbolOrder', 'Gray','InputType', 'Bit');
elseif (QAMsize==8)
h = modem.pskmod('M', QAMsize, 'SymbolOrder', 'Gray','InputType', 'Bit');
else
error('the modulation size %d is not supported!', QAMsize);
end
NormFactor = sqrt(QAMsize/sum(abs (h.Constellation).^2));
Constellation = NormFactor.*h.Constellation;
C1(m)=1/2*(w(m)*(1/sqrt(pi))*log2(2/(1+exp(-2*(sqrt(2)*x(m)+SNRaffBPSK)*SNRaffBPS
K)))+...
w(m)*(1/sqrt(pi))*log2(2/(1+exp(
2*(sqrt(2)*x(m)-SNRaffBPSK)*SNRaffBPSK))));
end
InstCap = sum(C1);
elseif (QAMsize==4)||(QAMsize==16)||(QAMsize==64)||(QAMsize==8)||(QAMsize==32)
for xindex = 1:QAMsize
for m1=1:16
for m2=1:16
sumoverxprime = 0;
for xprimeindex=1:QAMsize
sumoverxprime = sumoverxprime + ...
exp(-abs(SNRaff.*(Constellation(xindex)-Constellation(xprimeindex))+x(m1)+sqrt(-1).*x(
m2)).^2 ...
+x(m1).^2+x(m2).^2);
end
C2(m1,m2)=1/(pi)*w(m1)*w(m2)*log2(sumoverxprime);
end
end
Capforx(xindex) = sum(sum(C2,1),2);
end
InstCap = log2(QAMsize) - 1/QAMsize *sum (Capforx);
else
error('the modulation size %d is not supported!', QAMsize);
end
Plot:
PAM:
Code:
● Main Code:
clc;
clear all;
close all;
snri=(-10:2:40);
pam=[2,4,8,16,32,64];
capacity = zeros(length(pam),length(snri));
for pami=1:length(pam)
for index=1:length(snri)
capacity(pami,index) = PAMCapacity(snri(index),1,pam(pami));
end
end
figure;
hold
for pami=1:length(pam)
plot(snri,capacity(pami,:),'LineWidth',1.6);
end
GaussianC = zeros(1,length(snri));
for index=1:length(snri)
GaussianC(index) = log2(1+ 10^(snri(index)/10));
end
plot(snri,GaussianC);
legend('2-PAM','4-PAM','8-PAM','16-PAM','32-PAM','64-PAM','GaussianC');
set(gca,'FontSize', 12, 'FontName', 'Times New Roman');
grid on;
box on;
xlabel('SNR (Es/No) dB','FontSize', 14, 'FontName', 'Times New Roman');
ylabel('Capacity-PAM (bits/Tx)','FontSize',14,'FontName', 'Times New Roman');
● PAMCapacity.m:
x=[
-4.688738939
-3.869447905
-3.176999162
-2.546202158
-1.951787991
-1.380258539
-0.822951449
-0.273481046
0.273481046
0.822951449
1.380258539
1.951787991
2.546202158
3.176999162
3.869447905
4.688738939
];
w=[
2.65E-10
2.32E-07
2.71E-05
0.000932284
0.012880312
0.083810041
0.280647459
0.507929479
0.507929479
0.280647459
0.083810041
0.012880312
0.000932284
2.71E-05
2.32E-07
2.65E-10
];
SNRlin= 10^(SNR/10);
SNRaff=abs(fading)*sqrt(SNRlin);
h = modem.pammod('M', PAMsize, 'SymbolOrder', 'Gray','InputType', 'Bit');
exp(-abs(SNRaff.*(Constellation(xindex)-Constellation(xprimeindex))+x(m1)+sqrt(
-1).*x(m2)).^2 ...
+x(m1).^2+x(m2).^2);
end
C2(m1,m2)=1/(pi)*w(m1)*w(m2)*log2(sumoverxprime);
end
end
Capforx(xindex) = sum(sum(C2,1),2);
end
InstCap = log2(PAMsize) - 1/PAMsize *sum (Capforx);
else
error('the modulation size %d is not supported!', PAMsize);
end
Plot: