nuha
Newbie level 1
Code:
% Array storing theoretical value of Pf for AND logic decison rule
PfAND = [];
% Array storing simulated value of Pd for AND logic decison rule
PdSimulAND = [];
% Array storing simulated value of Pf for AND logic decison rule
PfSimulAND = [];
NormalizedThrptAND = [];
for k=1:1:length(tau)
% Number of samples in the sensiing duration
N = ceil((Fs/T)*tau(k));
PftheoryOR = 0;countsOR = 0;countnOR = 0;
PftheoryAND = 0;countsAND = 0;countnAND = 0;
for j=1:1:NMonteCarlo
% Generating Random Data
Data = randint(1,N,4);
% Modulated signal
mod_sig=pskmod(Data,4);
% Finding Epsilon for this frame
h = ones(M,1);
% AWGN Channel
N0 = 1/(10^(AvgSNR/10));
Tyis = zeros(M,1);
Tyin = zeros(M,1);
% finding the decision statistic
for f=1:1:M
Noise = sqrt(N0)*((randn(1,N)+sqrt(-1)*randn(1,N))/sqrt(2));
Tyis(f) = sum((abs(h(f)*mod_sig + Noise)).^2)/N;
Tyin(f) = sum((abs(Noise)).^2)/N;
end
%------------------------OR------------------------------------
% Finding the epsiloon for OR decision rule and then finding
% the net probability of false alarm
Pdi = 1 - (0.1)^(1/M);
epsilon = zeros(M,1);
for f=1:1:M
epsilon(f) = ((qfuncinv(Pdi)*sqrt(1+2*abs(h(f))*abs(h(f))*10^(AvgSNR/10)))/(sqrt(N)) + 1 + abs(h(f))*abs(h(f))*10^(AvgSNR/10))/10^(AvgSNR/10);
end
for f=1:1:M
if(Tyin(f)>epsilon(f))
countnOR = countnOR + 1;
break;
end
end
for f=1:1:M
if(Tyis(f)>epsilon(f))
countsOR = countsOR + 1;
break;
end
end
temp = 1;
for f=1:1:M
temp = temp*(1 - qfunc(((epsilon(f)*10^(AvgSNR/10)) - 1)*sqrt(N)));
end
PftheoryOR = PftheoryOR + (1 - temp);
Last edited by a moderator: