In [2]:
import re
import itertools

Spurious


In [101]:
ref_pinmin = {}

f = open("../pinmin/out.spurios_pinmin.dat")
for line in f:
    path, pinmin = line.split()
    pinmin = float(pinmin)
    
    if "/sim_micsoft_fs" in path:
        g = re.search("ks_(\w+(?:_l\d+)?)_\*", path)
        if g:
            det = g.group(1)
            
            ref_pinmin[det] = pinmin

In [102]:
def iter_campaigns():
    
    f = open("../pinmin/out.spurios_pinmin.dat")
    for line in f:
        path, pinmin = line.split()
        pinmin = float(pinmin)
        
        g = re.search("sim_micsoft_spurious_([0-9]+)\w+_([0-9-]+)\w+_.*ks_(\w+(?:_l\d+)?)_\*", path)
        if g:
            fn = float(g.group(1))*1e3
            pn = float(g.group(2))
            det = g.group(3)
            
            yield fn, pn, det, pinmin

In [103]:
def plot_for_det(det_name):
    l = sorted(iter_campaigns())

    a = []
    fnl = []
    for fn, g in itertools.groupby(l, key=lambda x:x[0]):
    
        # old code
        if fn == 251e3 or fn == 751e3:
            continue

        fnl.append(fn)
        b = []
        for fn, pn, det, pinmin in g:
            if det == det_name:
                b.append((pn, pinmin))
        a.append(b)

    #print fnl
    a = array(a)
    #figure(figsize=(10,8))
    
    
    for i, fn in enumerate(fnl):
        plot(a[i,:,0], a[i,:,1], 'o-', label="%.f kHz" % (fn/1e3,))
        
    ref = ref_pinmin[det_name]
    a = axis()
    plot([a[0], a[1]], [ref, ref], 'k--')
    

    xlabel("Spurious power ; $P_n$ [dB]")
    ylabel("Signal power @ $P_d = 0.9$ ; $P_{in-min}$ [dB]")
    axis([None,None,-122,-110])
    legend(loc="upper left")
    
    det_name_nice = det_name.upper().replace("_L", " L=")
    #print det_name_nice
    #title("Effect of spurious on %s" % det_name_nice)
    title(det_name_nice)
    grid()

In [104]:
plot_for_det("cav_l5")
figure()
plot_for_det("cav_l10")
figure()
plot_for_det("cav_l15")
savefig("figures/effect_of_spurious_cav_l15.eps")
figure()
plot_for_det("cav_l20")



In [105]:
plot_for_det("mac_l5")
figure()
plot_for_det("mac_l10")
figure()
plot_for_det("mac_l15")
savefig("figures/effect_of_spurious_mac_l15.eps")
figure()
plot_for_det("mac_l20")



In [120]:
from scipy.special import erfinv, erfc

def qfuncinv(x):
        return -sqrt(2.) * erfinv(2.*x - 1.)

def plot_ed_analytical():
    Ns = 25000.
    sigmaw = 10.**(-100./20.)
    Pd = .9
    Pfa = .1
    
    Pn = arange(-130, -100, .5)
    sigman = 10.**(Pn/20.)
    
    gamma0 = Ns*(sigmaw**2.+sigman**2.)*(1. + sqrt(2./Ns)*qfuncinv(Pfa))
    
    sigmas2 = gamma0 / (sqrt(2.*Ns)*qfuncinv(Pd) + Ns) - sigmaw**2. - sigman**2.
    plot(Pn, 10.*log10(sigmas2), 'k.-')

In [121]:
plot_ed_analytical()
plot_for_det("ed")
axis([None, None, -118, -110])
savefig("figures/effect_of_spurious_ed.eps")


Spurious, Gaussian


In [54]:
ref_pinmin = {}

f = open("../pinmin/out_pinmin.dat")
for line in f:
    path, pinmin = line.split()
    pinmin = float(pinmin)
    
    if "/sim_micsoft_fs" in path:
        g = re.search("ks_(\w+(?:_l\d+)?)_\*", path)
        if g:
            det = g.group(1)
            
            ref_pinmin[det] = pinmin

In [55]:
def iter_campaigns():
    
    f = open("../pinmin/out_pinmin.dat")
    for line in f:
        path, pinmin = line.split()
        pinmin = float(pinmin)
        
        g = re.search("sim_micsoft_spurious_gaussian_([0-9-]+)dbm_.*ks_(\w+(?:_l\d+)?)_\*", path)
        if g:
            pn = float(g.group(1))
            det = g.group(2)
            
            yield pn, det, pinmin

In [56]:
def plot_for_det(det_name):
    l = sorted(iter_campaigns())
    
    a = []
    for pn, det, pinmin in l:
        if det == det_name:
            a.append((pn, pinmin))

    #print fnl
    a = array(a)
    #figure(figsize=(10,8))
    
    plot(a[:,0], a[:,1], 'o-')
        
    ref = ref_pinmin[det_name]
    a = axis()
    plot([a[0], a[1]], [ref, ref], 'k--')
    

    xlabel("Spurious power ; $P_n$ [dB]")
    ylabel("Signal power @ $P_d = 0.9$ ; $P_{in-min}$ [dB]")
    axis([None,None,-122,-110])
    legend(loc="upper left")
    
    det_name_nice = det_name.upper().replace("_L", " L=")
    #print det_name_nice
    #title("Effect of spurious on %s" % det_name_nice)
    #title(det_name_nice)
    grid()

In [58]:
plot_ed_analytical()
plot_for_det("ed")
axis([None, None, -118, -110])
savefig("figures/effect_of_spurious_gaussian_ed.eps")


Digital down-conversion


In [10]:
def iter_campaigns_ddc():
    
    f = open("../pinmin/out.ddc3_pinmin.dat")
    for line in f:
        path, pinmin = line.split()
        pinmin = float(pinmin)
        
        g = re.search("sim_micsoft_ddc_([0-9]+)_.*ks_(\w+(?:_l\d+)?)_\*", path)
        if g:
            k = int(g.group(1))
            det = g.group(2)
            
            yield k, det, pinmin

In [11]:
def plot_for_det_ddc(det_names):
    if not isinstance(det_names, list):
        det_names = [det_names]
    else:
        det_names = det_names
            
    l = sorted(iter_campaigns_ddc())
    
    colors = ['b','g','r']
    
    for i, det_name in enumerate(det_names):

        a = []
        for k, det, pinmin in l:
            if det == det_name:
                a.append((k, pinmin))

        a = array(a)

        det_name_nice = det_name.upper().replace("_L", " L=")
        
        
        color = colors[i]
       
        plot(a[:,0], a[:,1], color+'o-', label=det_name_nice)

        ref = ref_pinmin[det_name]
        a = axis()
        plot([a[0], a[1]], [ref, ref], color+'--')

    xlabel("Oversampling factor ; $k$")
    ylabel("Signal power @ $P_d = 0.9$ ; $P_{in-min}$ [dB]")
    #axis([None,None,-120,-110])
    
    #title("Effect of oversampling")
    legend(loc="lower right")
    grid()

In [12]:
plot_for_det_ddc("cav_l5")
figure()
plot_for_det_ddc("cav_l10")
figure()
plot_for_det_ddc("cav_l15")
figure()
plot_for_det_ddc("cav_l20")



In [13]:
plot_for_det_ddc("mac_l5")
figure()
plot_for_det_ddc("mac_l10")
figure()
plot_for_det_ddc("mac_l15")
figure()
plot_for_det_ddc("mac_l20")



In [14]:
plot_for_det_ddc("ed")



In [15]:
plot_for_det_ddc(["ed","cav_l15","mac_l15"])
savefig("figures/oversampling.eps")



In [90]:
s1=10.**(-100./20.)
s2=10.**(-110./20.)

x1 = random.normal(loc=0, scale=s1, size=250000)
x2 = random.normal(loc=0, scale=s2, size=250000)

In [94]:
print std(x1)**2., s1**2


1.00137614022e-10 1e-10

In [95]:
print std(x2)**2., s2**2


1.00284960141e-11 1e-11

In [96]:
std(x1+x2)**2., s1**2+s2**2


Out[96]:
(1.1022921201958584e-10, 1.1000000000000002e-10)

In [ ]: