Measurements


In [8]:
import subprocess
import tempfile
import os

Np = 1000

def measure(N, fc, fs):
    
    EXTRA = 250000
    
    handle, path = tempfile.mkstemp()
    os.close(handle)
    
    args = ["uhd_rx_cfile", "-v",
            "--freq=%d" % (fc,),
            "--nsamples=%d" % (N + EXTRA,),
            "--samp-rate=%f" % (fs,),
            "-ATX/RX",
            path]

    subprocess.check_call(args)
    
    x = fromfile(path, dtype=numpy.dtype(numpy.complex64))
    
    os.unlink(path)
    
    return real(x[EXTRA:])

In [9]:
def get_lambda(x, L=25):

    x0 = x - mean(x)
    Ns = len(x0)

    lbd = empty(L)
    for l in xrange(L):
        if l > 0:
            xu = x0[:-l]
        else:
            xu = x0

        lbd[l] = dot(xu, x0[l:]) / (Ns - l)
        
    return lbd

In [10]:
def plot_lambda(lbd, lbdcmp):
    plot(lbd, 'o-', label="measured")
    plot(lbdcmp, 'ko-', label="simulated")
    ylabel("$\lambda_l$")
    xlabel("$l$")
    legend()
    grid()

In [11]:
def measure_and_plot(N, fs):
    x = measure(N=N, fs=fs, fc=864e6)
    xcmp = random.normal(loc=mean(x), scale=std(x), size=len(x))
    
    lbd = get_lambda(x, 25)
    lbdcmp = get_lambda(xcmp, 25)

    plot_lambda(lbd, lbdcmp)
    title("$f_s=%d$ MHz" % (fs/1e6,))

Internal noise (signal generator off)


In [82]:
measure_and_plot(N=25000*Np, fs=1e6)
savefig("figures/1mhz_noise_lambda.png", dpi=300)



In [83]:
measure_and_plot(N=25000*Np, fs=2e6)
savefig("figures/2mhz_noise_lambda.png", dpi=300)



In [84]:
measure_and_plot(N=100000*Np, fs=10e6)
savefig("figures/10mhz_noise_lambda.png", dpi=300)


Injected noise from a signal generator

$P_{gen}=30 \mathrm{dBm}$


In [79]:
measure_and_plot(N=25000*Np, fs=1e6)
savefig("figures/1mhz_noise_lambda_gen_30dbm.png", dpi=300)



In [80]:
measure_and_plot(N=25000*Np, fs=2e6)
savefig("figures/2mhz_noise_lambda_gen_30dbm.png", dpi=300)



In [81]:
measure_and_plot(N=100000*Np, fs=10e6)
savefig("figures/10mhz_noise_lambda_gen_30dbm.png", dpi=300)


Simulations


In [4]:
sys.path.append("..")
import sensing.signals

In [5]:
Ns = 25000
fs=2e6
x1 = sensing.signals.SimulatedIEEEMicSoftSpeaker().get(N=Ns*Np, fc=864e6, fs=fs, Pgen=-200)

In [6]:
x2 = sensing.signals.Spurious(sensing.signals.SimulatedIEEEMicSoftSpeaker(), fs/128, -108).get(N=Ns*Np, fc=864e6, fs=fs, Pgen=-200)

In [7]:
plot(get_lambda(x1), 'o-')
plot(get_lambda(x2), 'o-')
title("$f_s=%d$ MHz" % (fs/1e6,))
grid()



In [8]:
x3 = sensing.signals.SimulatedIEEEMicSoftSpeaker().get(N=Ns*Np, fc=864e6, fs=fs, Pgen=-200)
#x3 = sensing.signals.Spurious(sensing.signals.SimulatedIEEEMicSoftSpeaker(), fs/32, -110).get(N=Ns*Np*2, fc=864e6, fs=fs, Pgen=-200)

In [23]:
def do_fft(x, k=1):
    x0 = reshape(x, (Np/k, Ns))
    w0 = fft.rfft(x0, axis=1)
    w1 = mean(w0, axis=0)
    
    return 10*log10(abs(w1**2))

plot(do_fft(x3, k=1))


Out[23]:
[<matplotlib.lines.Line2D at 0x6577610>]

In [24]:
from scipy.signal import decimate

In [31]:
x3d = decimate(x3, 16)

#print len(x3d)
plot(do_fft(x3d, k=8))


/usr/lib/python2.7/dist-packages/scipy/signal/filter_design.py:288: BadCoefficients: Badly conditioned filter coefficients (numerator): the results may be meaningless
  "results may be meaningless", BadCoefficients)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-31-6223d4104525> in <module>()
      2 
      3 #print len(x3d)
----> 4 plot(do_fft(x3d, k=8))

<ipython-input-23-726937e54395> in do_fft(x, k)
      1 def do_fft(x, k=1):
----> 2     x0 = reshape(x, (Np/k, Ns))
      3     w0 = fft.rfft(x0, axis=1)
      4     w1 = mean(w0, axis=0)
      5 

/usr/lib/pymodules/python2.7/numpy/core/fromnumeric.pyc in reshape(a, newshape, order)
    169     except AttributeError:
    170         return _wrapit(a, 'reshape', newshape, order=order)
--> 171     return reshape(newshape, order=order)
    172 
    173 

ValueError: total size of new array must be unchanged

In [28]:
print len(x3d)*16, len(x3)


25000000 25000000

In [40]:
plot(get_lambda(x3), 'ro-')
plot(get_lambda(x3d), 'go-')
title("$f_s=%d$ MHz" % (fs/1e6,))
grid()



In [9]:
x3 = sensing.signals.SimulatedIEEEMicSoftSpeaker().get(N=Ns*Np, fc=864e6, fs=fs, Pgen=-200)

In [70]:
import scipy.signal
b, a = scipy.signal.iirdesign(wp=.6, ws=.99, gpass=5, gstop=60, ftype='ellip')
y3 = scipy.signal.lfilter(b, a, x3)
print b, a


[ 0.23271745  0.46399545  0.23271745] [ 1.          0.10601301  0.54677386]

In [71]:
plot(do_fft(y3, k=1));



In [72]:
plot(get_lambda(y3), 'go-')


Out[72]:
[<matplotlib.lines.Line2D at 0x16b4f750>]

In [14]:
x = measure(N=Np*25000, fs=2e6, fc=864e6)

In [15]:
plot(x)


Out[15]:
[<matplotlib.lines.Line2D at 0x2fa0ad0>]

In [38]:
def do_fft(x):
    x0 = reshape(x, (8000, 12500/4))
    w0 = fft.rfft(x0, axis=1)
    w1 = mean(w0, axis=0)
    
    return 10.*log10(abs(w1**2))

plot(do_fft(x)[1:], '-')
axis([0, None, None, None])


Out[38]:
[0, None, None, None]

In [22]:
plot(get_lambda(x), 'o-')


Out[22]:
[<matplotlib.lines.Line2D at 0x4790b10>]

In [ ]: