In [5]:
using DataFrames
using Distributions
using Gadfly
In [6]:
q(x) = (1/2) * erfc(x / sqrt(2));
p_e(x) = q(sqrt(x+1).*sqrt(log(1+x)./x)) + (1/2) - q(sqrt(log(x+1)./x));
X = linspace(1,100,1000);
PE = p_e(X);
df_pe_theoretical = DataFrame(x=X, y=PE, f="Theoretical error probability");
In [ ]:
In [7]:
# On fixe sigma_b et on fait varier sigma_s (et donc le SNR)
sigma2_b = 1;
sigma2_s = X;
SNR = sigma2_s / sigma2_b;
lambda2 = sigma2_b * ((SNR+1)/SNR) * log(SNR+1);
# Pour chaque valeur de SNR on fait n_tirages et on compare a lambda
n_tirages = 100;
ratios = zeros(length(SNR));
for i = 1:length(SNR)
detected = 0;
for j = 1:n_tirages
# Tirage aléatoire
y = rand(Normal(0, sigma2_s[i])) + rand(Normal(0, sigma2_b));
# Détection
if (y^2 > lambda2[i])
detected += 1
end
end
ratios[i] = 1 - (detected/n_tirages);
end
df_pe_simulated = DataFrame(x=X, y=ratios, f="Simulated error probability");
In [8]:
plot(vcat(df_pe_theoretical, df_pe_simulated), x=:x, y=:y, color=:f, Geom.line, Scale.x_log10)
Out[8]:
In [ ]: