How To Calculate Outage Probability
How To Calculate Outage Probability
BER = zeros(1,size(snr_db,2));
sigma=1/sqrt(snr_linear(iSNR));
for i=1:iterations
transmit_bit =round(rand(1,nr_of_bits))*2-1;
h = complex(randn(1,nr_of_bits),randn(1,nr_of_bits));
noise = 1/sqrt(2)*[randn(1,nr_of_bits)+1j*randn(1,nr_of_bits)]*sigma;
received_bits = h.*transmit_bit + noise;
estmtd_h = conj(h);
detected_bits = ((received_bits.*estmtd_h)>=0)*2-1;
nr_of_errors= sum(not(detected_bits == transmit_bit));
BER(iSNR) = BER(iSNR)+ nr_of_errors;
end
BER(iSNR) = BER(iSNR) ./iterations./nr_of_bits;
end
semilogy(snr_db,BER)
//////////////////////////////////////////////
%This
Matlab
script
can be
used to
generate
Figure 2
and
Figure 3
of the
paper:
%
%Emil Björnson, Michail Matthaiou, Mérouane Debbah, "A New Look at Dual-Hop
%Relaying: Performance Limits with Hardware Impairments" accepted for
%publication in IEEE Transcations on Communications.
%
%The paper is available for free download: http://arxiv.org/pdf/1311.2634
%
%The code can also generate Figure 2 in "On the impact of transceiver
%impairments on AF relaying" by Emil Björnson, Agisilaos Papadogiannis,
%Michail Matthaiou, Mérouane Debbah, published at IEEE ICASSP 2013.
%
%Download article: http://arxiv.org/pdf/1311.2634
%
%This is version 1.2 (Last edited: 2014-03-21).
%
%License: This code is licensed under the GPLv2 license. If you in any way
%use this code for research that results in publications, please cite our
%original article listed above.
%
%Please note that the channels are generated randomly, thus the results
%will not be exactly the same as in the paper.
clear all
close all
%%Simulation parameters
rng('shuffle'); %Initiate the random number generators with a random seed
%%If rng('shuffle'); is not supported by your Matlab version, you can use
%%the following commands instead:
%randn('state',sum(100*clock));
%Relaying with transceiver hardware impairments
%Number of channel iterations. This must be a very large number to make the
%Monte Carlo simulations fit the analytic curves for small BERs, e.g. 1e-6
nbrOfIterations = 1000000;
%Two scenarios: Rayleigh fading (1), Nakagami-m fading (2)
scenario = 2;
%Select fading parameters
if scenario == 1 %Rayleigh fading scenario
alpha1 = 1; %Not used in Rayleigh fading distribution
beta1 = 1; %Variance at first hop
end
R = [2 5]; %Transmit information rate (per 2 channel uses)
x = 2.^R-1; %Corresponding outage thresholds
N1 = 1; %Normalized noise variance at relay
N2 = 1; %Normalized noise variance at destination
SNR_dB = 0:5:40; %SNR range at first hop
P1_dB = SNR_dB - 10*log10(alpha1*beta1); %Corresponding transmit power range at
source (in dB)
P1 = 10.^(P1_dB/10); %Corresponding transmit power range at source
P2 = P1; %Set same transmit power range at relay.
kappa1 = 0.1; %Error Vector Magnitude (EVM) at first hop
kappa2 = 0.1; %Error Vector Magnitude (EVM) at second hop
d = kappa1^2+kappa2^2+kappa1^2*kappa2^2; %Recurring function of kappa1 and kappa2
%Placeholders for Monte-Carlo results: Amplify-and-Forward (AF) case
OP_ideal_af_f = zeros(length(x),length(P1)); %Outage probabilities, AF fixed gain,
ideal hardware
OP_ideal_af_v = zeros(length(x),length(P1)); %Outage probabilities, AF variable
gain, ideal hardware
OP_nonideal_af_f = zeros(length(x),length(P1)); %Outage probabilities, AF fixed
gain, non-ideal hardware
OP_nonideal_af_v = zeros(length(x),length(P1)); %Outage probabilities, AF variable
gain, non-ideal hardware
%Placeholders for Monte-Carlo results: Decode-and-Forward (DF) case
OP_ideal_df = zeros(length(x),length(P1)); %Outage probabilities, DF, ideal
hardware
OP_nonideal_df = zeros(length(x),length(P1)); %Outage probabilities, DF, non-ideal
hardware
%This product will be used in relay gains
exp_rho1 = alpha1*beta1;
%Go through all cases of transmit power at the source and assume that the
%power on the relay is varied in the same way. Compute outage probabilities
%by Monte-Carlo simulations.
for p = 1:length(P1)
%Monte-Carlo simulations
for kk = 1:nbrOfIterations
%Check if the relaying channel is in outage (if SNDR < x). Store
%the number of outages in corresponding variables
for ind = 1:length(x)
end
end
%Compute outage probabilities using analytic expressions
%Use same transmit power ranges as before but evaluate the performance for
%a denser set of values (every integer in dB).
SNR_dB_dense= min(SNR_dB):max(SNR_dB);
P1_dB_dense = SNR_dB_dense - 10*log10(alpha1*beta1);
P1 = 10.^(P1_dB_dense/10);
P2 = P1;
%Placeholders for analytic results: Amplify-and-Forward (AF) case
Pout_ideal_af_f = zeros(length(x),length(P1)); %Outage probabilities, AF fixed
gain, ideal hardware
Pout_ideal_af_v = zeros(length(x),length(P1)); %Outage probabilities, AF variable
gain, ideal hardware
Pout_nonideal_af_f = zeros(length(x),length(P1)); %Outage probabilities, AF fixed
gain, non-ideal hardware
Pout_nonideal_af_v = zeros(length(x),length(P1)); %Outage probabilities, AF
variable gain, non-ideal hardware
%Placeholders for analytic results: Decode-and-Forward (DF) case
Pout_ideal_df = zeros(length(x),length(P1)); %Outage probabilities, DF, ideal
hardware
Pout_nonideal_df = zeros(length(x),length(P1)); %Outage probabilities, DF, non-
ideal hardware
if scenario == 1
Omega1 = beta1; %New notation for channel variance at first hop
Omega2 = beta2; %New notation for channel variance at second hop
%DF relaying with ideal hardware. Outage probability is given in [33, Eq. (21)]
for ind = 1:length(x)
prefactor1 = (N1*x(ind)/beta1);
prefactor2 = (N2*x(ind)/beta2);
Pout_ideal_df(ind,:) = 1 - exp(-prefactor1./P1 - prefactor2./P2);
end
if delta*x(ind)>1
Pout_nonideal_df(ind,:) = ones(size(B_nonideal_v));
else
Pout_nonideal_df(ind,:) = 1 - exp(-prefactor1./P1 - prefactor2./P2);
end
end
elseif scenario == 2
%DF relaying with ideal hardware. Outage probability is given in [33, Eq. (21)]
for ind = 1:length(x)
prefactor1 = (N1*x(ind)/beta1);
prefactor2 = (N2*x(ind)/beta2);
part1 = zeros(size(P1));
part2 = zeros(size(P1));
for j = 0:alpha1-1
part1 = part1 + exp(-prefactor1./P1) .* (prefactor1./P1).^j /
factorial(j);
end
for j = 0:alpha2-1
part2 = part2 + exp(-prefactor2./P2) .* (prefactor2./P2).^j /
factorial(j);
end
part1 = zeros(size(P1));
part2 = zeros(size(P1));
for j = 0:alpha1-1
part1 = part1 + exp(-prefactor1./P1) .* (prefactor1./P1).^j /
factorial(j);
end
for j = 0:alpha2-1
part2 = part2 + exp(-prefactor2./P2) .* (prefactor2./P2).^j /
factorial(j);
end
if delta*x(ind) > 1
Pout_nonideal_df(ind,:) = ones(size(B_nonideal_v));
else
Pout_nonideal_df(ind,:) = 1 - part1 .* part2;
end
end
end
%Plot the results for AF relaying
figure; hold on; box on;
for ind = 1:length(x)
plot(SNR_dB(1),OP_nonideal_af_f(ind,1)./nbrOfIterations,'k+-');
plot(SNR_dB(1),OP_ideal_af_f(ind,1)./nbrOfIterations,'rd-.');
plot(SNR_dB(1),OP_nonideal_af_v(ind,1)./nbrOfIterations,'bs--');
plot(SNR_dB(1),OP_ideal_af_v(ind,1)./nbrOfIterations,'go:');
plot(SNR_dB,OP_nonideal_af_f(ind,:)./nbrOfIterations,'k+');
plot(SNR_dB,OP_ideal_af_f(ind,:)./nbrOfIterations,'rd');
plot(SNR_dB,OP_nonideal_af_v(ind,:)./nbrOfIterations,'bs');
plot(SNR_dB,OP_ideal_af_v(ind,:)./nbrOfIterations,'go');
plot(SNR_dB_dense,Pout_nonideal_af_f(ind,:),'k');
plot(SNR_dB_dense,Pout_ideal_af_f(ind,:),'r-.');
plot(SNR_dB_dense,Pout_nonideal_af_v(ind,:),'b--');
plot(SNR_dB_dense,Pout_ideal_af_v(ind,:),'g:');
end
set(gca,'yscale','log')
legend('Impairments (Fixed Gain)','Ideal Hardware (Fixed Gain)','Impairments
(Variable Gain)','Ideal Hardware (Variable Gain)','Location','SouthWest')
xlabel('Average SNR [dB]');
ylabel('Outage Probability (OP)');
axis([0 40 1e-6 1]);
%Plot the results for DF relaying
figure; hold on; box on;
for ind = 1:length(x)
plot(SNR_dB(1),OP_nonideal_df(ind,1)./nbrOfIterations,'rs-.');
plot(SNR_dB(1),OP_ideal_df(ind,1)./nbrOfIterations,'ko-');
plot(SNR_dB,OP_nonideal_df(ind,:)./nbrOfIterations,'rs');
plot(SNR_dB,OP_ideal_df(ind,:)./nbrOfIterations,'ko');
plot(SNR_dB_dense,Pout_nonideal_df(ind,:),'r-.');
plot(SNR_dB_dense,Pout_ideal_df(ind,:),'k');
end
set(gca,'yscale','log')
legend('Impairments (DF)','Ideal Hardware (DF)','Location','SouthWest')
xlabel('Average SNR [dB]');
ylabel('Outage Probability (OP)');
axis([0 40 1e-6 1]);