0% found this document useful (0 votes)
47 views11 pages

Mohit S Ec372 Lab4

The document contains MATLAB code to simulate and plot the channel capacity of QAM, PSK, and PAM modulation schemes. For each modulation, the code calculates capacity for different modulation sizes (e.g. 4-QAM, 16-QAM) across a range of SNR values, and plots the results alongside the Gaussian channel capacity for comparison. Capacity is calculated using a Gauss-Hermite numerical integration method defined in separate M-files for each modulation type.

Uploaded by

Ritwik Ghorui
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views11 pages

Mohit S Ec372 Lab4

The document contains MATLAB code to simulate and plot the channel capacity of QAM, PSK, and PAM modulation schemes. For each modulation, the code calculates capacity for different modulation sizes (e.g. 4-QAM, 16-QAM) across a range of SNR values, and plots the results alongside the Gaussian channel capacity for comparison. Capacity is calculated using a Gauss-Hermite numerical integration method defined in separate M-files for each modulation type.

Uploaded by

Ritwik Ghorui
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

QAM:

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:

function InstCap = QAMCapacity(SNR,fading,QAMsize)

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:

function InstCap = PSKCapacity(SNR,fading,QAMsize)

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 = zeros(1,16); % BPSK Gaussi Hermite


C2 = zeros(16,16); % Two dimensional signals
Capforx = zeros(1,QAMsize);
if (QAMsize==2) % BPSK
SNRaffBPSK = sqrt(2).*SNRaff; % see page 363 of Digital Communications 5th
A/sigma
for m=1:16

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:

function InstCap = PAMCapacity(SNR,fading,PAMsize)

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

NormFactor = sqrt(PAMsize/sum(abs (h.Constellation).^2));


Constellation = NormFactor.*h.Constellation;

C1 = zeros(1,16); % BPSK Gaussi Hermite


C2 = zeros(16,16); % Two dimensional signals
Capforx = zeros(1,PAMsize);
if (PAMsize==2) % BPSK
SNRaffBPSK = sqrt(2).*SNRaff; % see page 363 of Digital Communications
5th A/sigma
for m=1:16
C1(m)=1/2*(w(m)*(1/sqrt(pi))*log2(2/(1+exp(-2*(sqrt(2)*x(m)+SNRaffBPSK)*SNR
affBPSK)))+...
w(m)*(1/sqrt(pi))*log2(2/(1+exp(
2*(sqrt(2)*x(m)-SNRaffBPSK)*SNRaffBPSK))));
end
InstCap = sum(C1);
elseif
(PAMsize==4)||(PAMsize==16)||(PAMsize==64)||(PAMsize==8)||(PAMsize==32)
for xindex = 1:PAMsize
for m1=1:16
for m2=1:16
sumoverxprime = 0;
for xprimeindex=1:PAMsize
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(PAMsize) - 1/PAMsize *sum (Capforx);
else
error('the modulation size %d is not supported!', PAMsize);
end

Plot:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy