F4B101A / TP2 / Détection quadratique


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


WARNING: Method definition q(Any) in module Main at In[2]:1 overwritten at In[6]:1.
WARNING: Method definition p_e(Any) in module Main at In[2]:2 overwritten at In[6]:2.

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]:
x 10-2.5 10-2.0 10-1.5 10-1.0 10-0.5 100.0 100.5 101.0 101.5 102.0 102.5 103.0 103.5 104.0 104.5 10-2.0 10-1.9 10-1.8 10-1.7 10-1.6 10-1.5 10-1.4 10-1.3 10-1.2 10-1.1 10-1.0 10-0.9 10-0.8 10-0.7 10-0.6 10-0.5 10-0.4 10-0.3 10-0.2 10-0.1 100.0 100.1 100.2 100.3 100.4 100.5 100.6 100.7 100.8 100.9 101.0 101.1 101.2 101.3 101.4 101.5 101.6 101.7 101.8 101.9 102.0 102.1 102.2 102.3 102.4 102.5 102.6 102.7 102.8 102.9 103.0 103.1 103.2 103.3 103.4 103.5 103.6 103.7 103.8 103.9 104.0 10-2 100 102 104 10-2.0 10-1.8 10-1.6 10-1.4 10-1.2 10-1.0 10-0.8 10-0.6 10-0.4 10-0.2 100.0 100.2 100.4 100.6 100.8 101.0 101.2 101.4 101.6 101.8 102.0 102.2 102.4 102.6 102.8 103.0 103.2 103.4 103.6 103.8 104.0 Theoretical error probability Simulated error probability f -0.6 -0.5 -0.4 -0.3 -0.2 -0.1 0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 -0.50 -0.48 -0.46 -0.44 -0.42 -0.40 -0.38 -0.36 -0.34 -0.32 -0.30 -0.28 -0.26 -0.24 -0.22 -0.20 -0.18 -0.16 -0.14 -0.12 -0.10 -0.08 -0.06 -0.04 -0.02 0.00 0.02 0.04 0.06 0.08 0.10 0.12 0.14 0.16 0.18 0.20 0.22 0.24 0.26 0.28 0.30 0.32 0.34 0.36 0.38 0.40 0.42 0.44 0.46 0.48 0.50 0.52 0.54 0.56 0.58 0.60 0.62 0.64 0.66 0.68 0.70 0.72 0.74 0.76 0.78 0.80 0.82 0.84 0.86 0.88 0.90 0.92 0.94 0.96 0.98 1.00 -0.5 0.0 0.5 1.0 -0.50 -0.45 -0.40 -0.35 -0.30 -0.25 -0.20 -0.15 -0.10 -0.05 0.00 0.05 0.10 0.15 0.20 0.25 0.30 0.35 0.40 0.45 0.50 0.55 0.60 0.65 0.70 0.75 0.80 0.85 0.90 0.95 1.00 y

In [ ]: