Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 10

clear

N = 2*10^5 % number of bits or symbols


Es_N0_dB = [-3:20]; % multiple Eb/N0 values

% BPSK
theoryBer_BPSK = 0.5*erfc(sqrt(10.^(Es_N0_dB/10))); % theoretical
ber

%(QPSK)
theorySer_QPSK = erfc(sqrt(0.5*(10.^(Es_N0_dB/10)))) -
(1/4)*(erfc(sqrt(0.5*(10.^(Es_N0_dB/10))))).^2;

%16QAM
theoryBer_16QAM = 3/2*erfc(sqrt(0.1*(10.^(Es_N0_dB/10))));

%64QAM
M = 64; % number of constellation points

k = sqrt(1/((2/3)*(M-1))); % normalizing factor

theorySer = 2*(1-1/sqrt(M))*erfc(k*sqrt((10.^(Es_N0_dB/10)))) ...


- (1-2/sqrt(M) +
1/M)*(erfc(k*sqrt((10.^(Es_N0_dB/10))))).^2;

% plot
close all
figure
semilogy(Es_N0_dB, theoryBer_BPSK,'b.-');
hold on

semilogy(Es_N0_dB, theorySer_QPSK,'b.-');
hold on

semilogy(Es_N0_dB, theoryBer_16QAM,'b.-');

axis([0 25 10^-5 10^-1])


grid on
legend('BSK' , 'QPSK' , '16QAM');
xlabel('Eb/No, [dB]');
ylabel('BER');
title(' BER as a function of SNR per symbol for selected
polarizationmultiplexed and four-dimensional modulation
formats.');
%This work is licensed under a C
%Attribution-NonCommercial-Sha
%Attribute author : Mathuranatha
snrdB=-10:0.5:20; %Range of SN

clc
close all
clear all
lc = ['m','r','g','b','k','c']; %for diffrent color plot for each M-ary
nsample = 1.5; % number of samples per symbol, default it is 1
Es_N0_dB = [-3:20]; % multiple Eb/N0 values
% BPSK

theoryBer_BPSK = 0.5*erfc(sqrt(10.^(Es_N0_dB/10))); % theoretical ber


semilogy(Es_N0_dB, theoryBer_BPSK,'y.-');
hold on
%PDM-mQAM
M = 4; %starting M-ary number
for i = 1:5 
    snr = 0:25; %till 30 dB
    nbits = log2(M); %calculating the number of bits per symbol
    esym = snr + 10*log(nbits) + 10*log(nsample); %energy of symbol
    esyml = db2mag(esym); %converting dB to linear scale
    pe = 4*qfunc(sqrt(3*esyml/(M-1))); %probability of error
    semilogy(snr,pe,lc(nbits-1)) %plotting the error curve
    hold on
    M = M*2; %doubling the M in M-ary system
end

xlabel('SNR (dB)')
ylabel('Probability of Error')
title('Symbol Error Probability Curve of M-ary QAM')
axis([0 25 10^-5 10^-1])
grid on
legend('BSK',' PDM-QPSK ','PDM-8QAM',' PDM-16QAM','PDM-32QAM', 'PDM-64QAM')
snrdB=-5 : 30; %Range of SNRs to simulate
 
h= (randn(1,5000) + 1i*randn(1,5000) )/sqrt(2); %Rayleigh flat channel
sigma_z=1; %Noise power - assumed to be unity
  snr = 10.^(snrdB/10); %SNRs in linear scale
P=(sigma_z^2)*snr./(mean(abs(h).^2)); %Calculate corresponding values
for P
 C_erg_awgn= (log2(1+ mean(abs(h).^2).*P/(sigma_z^2))); %AWGN
channel capacity (Bound)
plot(snrdB,C_erg_awgn,'b');
hold on;
grid on;
legend('AWGN channel capacity');
xlabel('SNR (dB)');ylabel('Capacity (bps/Hz)');
symbol_count = 50000;
snr = -5 : 30; % dB
%qpsk---4qam
modulation = [sqrt(1/2)*(-1+i), sqrt(1/2)*(+1+i), sqrt(1/2)*(-1-i), sqrt(1/2)*(+1-i)] ;
channel = sqrt(1/2)*(randn(1,symbol_count)+i*randn(1,symbol_count));
channel = ones(1,symbol_count);
channel_capacity = zeros(size(snr));

for index = 1:length(snr)


symbols = ceil(length(modulation)*rand(1,symbol_count));
tx = modulation(symbols);
N0 = 1/(10^(snr(index)/10));
noise = sqrt(N0/2)*(randn(1,symbol_count)+i*randn(1,symbol_count));
rx = tx.*channel+noise;
probabilities = max(exp(-(abs(ones(length(modulation),1)*rx -
modulation.'*channel).^2)/N0),realmin);
probabilities = probabilities ./ (ones(length(modulation),1)*sum(probabilities));
channel_capacity(index) = log2(length(modulation))
+mean(sum(probabilities.*log2(probabilities)));
end
axis([-5 30 0 12])
plot(snr,channel_capacity);
hold on

%16qam
mod = sqrt(1/10)*[-3+3*i, -1+3*i, +1+3*i, +3+3*i, -3+1*i, -1+1*i, +1+1*i, +3+1*i,
-3-1*i, -1-1*i, +1-1*i, +3-1*i, -3-3*i, -1-3*i, +1-3*i, +3-3*i];

channel = sqrt(1/2)*(randn(1,symbol_count)+i*randn(1,symbol_count));
channel = ones(1,symbol_count);
channel_capacity = zeros(size(snr));
for index = 1:length(snr)
symbols = ceil(length(mod)*rand(1,symbol_count));
tx = mod (symbols);
N0 = 1/(10^(snr(index)/10));
noise = sqrt(N0/2)*(randn(1,symbol_count)+i*randn(1,symbol_count));
rx = tx.*channel+noise;
probabilities = max(exp(-(abs(ones(length(mod),1)*rx -
mod.'*channel).^2)/N0),realmin);

probabilities = probabilities ./ (ones(length(mod),1)*sum(probabilities));

channel_capacity(index) = log2(length(modulation))
+mean(sum(probabilities.*log2(probabilities)));
end

figure
plot(snr,channel_capacity);
hold on
xlabel('SNR [dB]');
ylabel('Capacity [bit/s/Hz]')
axis([-5 30 0 12])
clc;
clear all;
close all;

snri=(-5:30);
qam=[2,4,8,16,32,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);
grid on;
box on;
xlabel('SNR (Es/No) dB');
ylabel('Capacity ');
axis([-5 30 0 12]);

legend('PDM-BSK',' PDM-QPSK ','PDM-8QAM',' PDM-16QAM','PDM-32QAM',


'PDM-64QAM');
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==2)||(QAMsize==4)||(QAMsize==16)||...
(QAMsize==64)||(QAMsize==32)
h = modem.qammod('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)*SNRaffBPSK)))+...
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

You might also like