예제 #1
0
import csv

try:
    import pylab
except ImportError:
    print "Error: could not import pylab (http://matplotlib.sourceforge.net/)"
    sys.exit(1)

# Number of samples to use
N = 10000
# After this many samples, a tag containing the SNR (key='snr') will be sent
ntag = 10000
# The running-average coefficient
alpha = 0.001
# BPSK
bits = 2 * scipy.complex64(scipy.random.randint(0, 2, N)) - 1

general_snr = list()
snr_svr = list()
snr_m2m4 = list()
snr_skew = list()
snr_simple = list()
snr_real_value = list()


def noise_voltage(SNR):
    """ Calculate noise voltage from SNR assuming unit signal power
    :param SNR: signal to noise ratio
    """
    return 10 ** (float(-SNR) / 20)
예제 #2
0
import csv

try:
    import pylab
except ImportError:
    print "Error: could not import pylab (http://matplotlib.sourceforge.net/)"
    sys.exit(1)

# Number of samples to use
N = 10000
# After this many samples, a tag containing the SNR (key='snr') will be sent
ntag = 10000
# The running-average coefficient
alpha = 0.001
# QPSK
bits = (2*scipy.complex64(scipy.random.randint(0, 2, N)) - 1) + \
     1j*(2*scipy.complex64(scipy.random.randint(0, 2, N)) - 1)

general_snr = list()
snr_svr = list()
snr_m2m4 = list()
snr_skew = list()
snr_simple = list()
snr_real_value = list()


def noise_voltage(SNR):
    """ Calculate noise voltage from SNR assuming unit signal power
    :param SNR: signal to noise ratio
    """
    return 10 ** (float(-SNR) / 20)
예제 #3
0
def main():
    gr_estimators = {"simple": digital.SNR_EST_SIMPLE,
                     "skew": digital.SNR_EST_SKEW,
                     "m2m4": digital.SNR_EST_M2M4,
                     "svr": digital.SNR_EST_SVR}
    py_estimators = {"simple": snr_est_simple,
                     "skew": snr_est_skew,
                     "m2m4": snr_est_m2m4,
                     "svr": snr_est_svr}
    
    
    parser = OptionParser(option_class=eng_option, conflict_handler="resolve")
    parser.add_option("-N", "--nsamples", type="int", default=10000,
                      help="Set the number of samples to process [default=%default]")
    parser.add_option("", "--snr-min", type="float", default=-5,
                      help="Minimum SNR [default=%default]")
    parser.add_option("", "--snr-max", type="float", default=20,
                      help="Maximum SNR [default=%default]")
    parser.add_option("", "--snr-step", type="float", default=0.5,
                      help="SNR step amount [default=%default]")
    parser.add_option("-t", "--type", type="choice",
                      choices=gr_estimators.keys(), default="simple",
                      help="Estimator type {0} [default=%default]".format(
                            gr_estimators.keys()))
    (options, args) = parser.parse_args ()

    N = options.nsamples
    xx = scipy.random.randn(N)
    xy = scipy.random.randn(N)
    bits = 2*scipy.complex64(scipy.random.randint(0, 2, N)) - 1

    snr_known = list()
    snr_python = list()
    snr_gr = list()
    
    # when to issue an SNR tag; can be ignored in this example.
    ntag = 10000

    n_cpx = xx + 1j*xy

    py_est = py_estimators[options.type]
    gr_est = gr_estimators[options.type]

    SNR_min = options.snr_min
    SNR_max = options.snr_max
    SNR_step = options.snr_step
    SNR_dB = scipy.arange(SNR_min, SNR_max+SNR_step, SNR_step)
    for snr in SNR_dB:
        SNR = 10.0**(snr/10.0)
        scale = scipy.sqrt(SNR)
        yy = bits + n_cpx/scale
        print "SNR: ", snr

        Sknown = scipy.mean(yy**2)
        Nknown = scipy.var(n_cpx/scale)/2
        snr0 = Sknown/Nknown
        snr0dB = 10.0*scipy.log10(snr0)
        snr_known.append(snr0dB)

        snrdB, snr = py_est(yy)        
        snr_python.append(snrdB)

        gr_src = gr.vector_source_c(bits.tolist(), False)
        gr_snr = digital.mpsk_snr_est_cc(gr_est, ntag, 0.001)
        gr_chn = gr.channel_model(1.0/scale)
        gr_snk = gr.null_sink(gr.sizeof_gr_complex)
        tb = gr.top_block()
        tb.connect(gr_src, gr_chn, gr_snr, gr_snk)
        tb.run()

        snr_gr.append(gr_snr.snr())

    f1 = pylab.figure(1)
    s1 = f1.add_subplot(1,1,1)
    s1.plot(SNR_dB, snr_known, "k-o", linewidth=2, label="Known")
    s1.plot(SNR_dB, snr_python, "b-o", linewidth=2, label="Python")
    s1.plot(SNR_dB, snr_gr, "g-o", linewidth=2, label="GNU Radio")
    s1.grid(True)
    s1.set_title('SNR Estimators')
    s1.set_xlabel('SNR (dB)')
    s1.set_ylabel('Estimated SNR')
    s1.legend()

    pylab.show()
예제 #4
0
import csv

try:
    import pylab
except ImportError:
    print "Error: could not import pylab (http://matplotlib.sourceforge.net/)"
    sys.exit(1)

# Number of samples to use
N = 10000
# After this many samples, a tag containing the SNR (key='snr') will be sent
ntag = 10000
# The running-average coefficient
alpha = 0.001
# QPSK
bits = (2*scipy.complex64(scipy.random.randint(0, 2, N)) - 1) + \
     1j*(2*scipy.complex64(scipy.random.randint(0, 2, N)) - 1)

general_snr = list()
snr_svr = list()
snr_m2m4 = list()
snr_skew = list()
snr_simple = list()
snr_real_value = list()


def noise_voltage(SNR):
    """ Calculate noise voltage from SNR assuming unit signal power
    :param SNR: signal to noise ratio
    """
    return 10**(float(-SNR) / 20)