示例#1
0
def main(nbits):
    """Main Program"""
    print nbits
    if nbits != None:
        g = gold(nbits)
        #plotting
        pylab.figure()
        pylab.subplot(2, 2, 1)
        pylab.title('Autocorrelation g[0]')
        g0 = numpy.where(g[0], 1.0, -1.0)
        pylab.plot((numpy.roll(filter.ccorr(g0, g0).real, len(g0) / 2 - 1)))
        pylab.xlim(0, len(g0))
        pylab.subplot(2, 2, 2)
        pylab.title('Autocorrelation g[-1]')
        gm1 = numpy.where(g[-1], 1.0, -1.0)
        pylab.plot((numpy.roll(filter.ccorr(gm1, gm1).real, len(gm1) / 2 - 1)))
        pylab.xlim(0, len(gm1))
        pylab.subplot(2, 2, 3)
        pylab.title('Crosscorrelation g[0] g[1]')
        g1 = numpy.where(g[1], 1.0, -1.0)
        pylab.plot((numpy.roll(filter.ccorr(g0, g1).real, len(g0) / 2 - 1)))
        pylab.xlim(0, len(g0))
        pylab.subplot(2, 2, 4)
        pylab.title('Crosscorrelation g[0] g[-1]')
        pylab.plot((numpy.roll(filter.ccorr(g0, gm1).real, len(g0) / 2 - 1)))
        pylab.xlim(0, len(g0))
        pylab.show()
    else:
        print 'Paper Example:'
        paper_eg()
        print 'Web Example:'
        web_eg()
示例#2
0
def paper_eg():
    """Gold code set example base on paper by E. H. Dinan and B. Jabbari 
    Spreading Codes for Direct Sequence CDMA and Wideband CDMA Cellular 
    Networks"""
    seq1 = mls.lfsr([2], [1, 1, 1, 1, 1])
    print 'Sequence 1:', numpy.where(seq1, 1, 0)
    seq2 = mls.lfsr([1, 2, 3], [1, 1, 1, 1, 1])
    print 'Sequence 2:', numpy.where(seq2, 1, 0)
    gold = gen_gold(seq1, seq2)
    print 'Gold 0 shift combination:', numpy.where(gold[0], 1, 0)
    print 'Gold 1 shift combination:', numpy.where(gold[1], 1, 0)
    print 'Gold 30 shift combination:', numpy.where(gold[-1], 1, 0)

    pylab.figure()
    pylab.subplot(2, 2, 1)
    pylab.title('Autocorrelation gold[0]')
    g0 = numpy.where(gold[0], 1.0, -1.0)
    pylab.plot((numpy.roll(filter.ccorr(g0, g0).real, len(g0) / 2 - 1)))
    pylab.subplot(2, 2, 2)
    pylab.title('Autocorrelation gold[30]')
    g30 = numpy.where(gold[30], 1.0, -1.0)
    pylab.plot((numpy.roll(filter.ccorr(g30, g30).real, len(g30) / 2 - 1)))
    pylab.subplot(2, 2, 3)
    pylab.title('Crosscorrelation gold[0] gold[1]')
    g1 = numpy.where(gold[1], 1.0, -1.0)
    pylab.plot((numpy.roll(filter.ccorr(g0, g1).real, len(g0) / 2 - 1)))
    pylab.subplot(2, 2, 4)
    pylab.title('Crosscorrelation gold[0] gold[30]')
    pylab.plot((numpy.roll(filter.ccorr(g0, g30).real, len(g0) / 2 - 1)))
    pylab.show()
示例#3
0
文件: gold.py 项目: AlexBoro/python
def main(nbits):
    """Main Program"""
    print nbits
    if nbits != None:
        g = gold(nbits)
        #plotting
        pylab.figure()
        pylab.subplot(2,2,1)
        pylab.title('Autocorrelation g[0]')
        g0 = numpy.where(g[0], 1.0, -1.0)
        pylab.plot((numpy.roll(filter.ccorr(g0, g0).real, len(g0)/2-1)))
        pylab.xlim(0, len(g0))
        pylab.subplot(2,2,2)
        pylab.title('Autocorrelation g[-1]')
        gm1 = numpy.where(g[-1], 1.0, -1.0)
        pylab.plot((numpy.roll(filter.ccorr(gm1, gm1).real, len(gm1)/2-1)))
        pylab.xlim(0, len(gm1))
        pylab.subplot(2,2,3)
        pylab.title('Crosscorrelation g[0] g[1]')
        g1 = numpy.where(g[1], 1.0, -1.0)
        pylab.plot((numpy.roll(filter.ccorr(g0, g1).real, len(g0)/2-1)))
        pylab.xlim(0, len(g0))
        pylab.subplot(2,2,4)
        pylab.title('Crosscorrelation g[0] g[-1]')
        pylab.plot((numpy.roll(filter.ccorr(g0, gm1).real, len(g0)/2-1)))
        pylab.xlim(0, len(g0))
        pylab.show()
    else:
        print 'Paper Example:'
        paper_eg()
        print 'Web Example:'
        web_eg()
示例#4
0
文件: gold.py 项目: AlexBoro/python
def paper_eg():
    """Gold code set example base on paper by E. H. Dinan and B. Jabbari 
    Spreading Codes for Direct Sequence CDMA and Wideband CDMA Cellular 
    Networks"""
    seq1 = mls.lfsr([2],[1, 1, 1, 1, 1])
    print 'Sequence 1:', numpy.where(seq1, 1, 0)
    seq2 = mls.lfsr([1, 2, 3], [1, 1, 1, 1, 1])
    print 'Sequence 2:', numpy.where(seq2, 1, 0)
    gold = gen_gold(seq1, seq2)
    print 'Gold 0 shift combination:', numpy.where(gold[0], 1, 0)
    print 'Gold 1 shift combination:', numpy.where(gold[1], 1, 0)
    print 'Gold 30 shift combination:', numpy.where(gold[-1], 1, 0)
    
    pylab.figure()
    pylab.subplot(2,2,1)
    pylab.title('Autocorrelation gold[0]')
    g0 = numpy.where(gold[0], 1.0, -1.0)
    pylab.plot((numpy.roll(filter.ccorr(g0, g0).real, len(g0)/2-1)))
    pylab.subplot(2,2,2)
    pylab.title('Autocorrelation gold[30]')
    g30 = numpy.where(gold[30], 1.0, -1.0)
    pylab.plot((numpy.roll(filter.ccorr(g30, g30).real, len(g30)/2-1)))
    pylab.subplot(2,2,3)
    pylab.title('Crosscorrelation gold[0] gold[1]')
    g1 = numpy.where(gold[1], 1.0, -1.0)
    pylab.plot((numpy.roll(filter.ccorr(g0, g1).real, len(g0)/2-1)))
    pylab.subplot(2,2,4)
    pylab.title('Crosscorrelation gold[0] gold[30]')
    pylab.plot((numpy.roll(filter.ccorr(g0, g30).real, len(g0)/2-1)))
    pylab.show()
示例#5
0
def main(nbits):
    """Main Program"""
    import pylab
    import filter
    nbits = int(nbits)
    m = mls(nbits)
    pylab.figure()
    pylab.title('%d bit M-Sequence Periodic Autocorrelation' % nbits)
    m = numpy.where(m, 1.0, -1.0)
    pylab.plot((numpy.roll(filter.ccorr(m, m).real, 2**nbits / 2 - 1)))
    pylab.xlim(0, len(m))
    pylab.show()
示例#6
0
文件: mls.py 项目: shennjia/weblte
def main(nbits):
    """Main Program"""
    import pylab
    import filter
    nbits = int(nbits)
    m = mls(nbits)
    pylab.figure()
    pylab.title('%d bit M-Sequence Periodic Autocorrelation' % nbits)
    m = numpy.where(m, 1.0, -1.0)
    pylab.plot((numpy.roll(filter.ccorr(m, m).real, 2**nbits/2 - 1)))
    pylab.xlim(0, len(m))
    pylab.show()
示例#7
0
    print 'Sequence 2:', numpy.where(seq2, 1, 0)
    gold = gen_gold(seq1, seq2)
    print 'Gold 0 shift combination:', numpy.where(gold[1], 1, seed)
    print 'Gold 1 shift combination:', numpy.where(gold[0], 1, seed)
    print 'Gold 30 shift combination:', numpy.where(gold[-1], 1, seed)
    
    pylab.figure()
    pylab.subplot(2,2,1)
    pylab.title('Autocorrelation gold[0]')
    g0 = numpy.where(gold[0], 1.0, -1.0)
    pylab.plot((numpy.roll(filter.ccorr(g0, g0).real, len(g0)/2-1)))
    pylab.subplot(2,2,2)
        pylab.subplot(2,2,3)
    pylab.title('Crosscorrelation gold[0] gold[1]')
    g1 = numpy.where(gold[1], 1.0, -1.0)
    pylab.plot((numpy.roll(filter.ccorr(g0, g1).real, len(g0)/2-1)))
    pylab.title('Autocorrelation gold[30]')
    g30 = numpy.where(gold[30], 1.0, -1.0)
    pylab.plot((numpy.roll(filter.ccorr(g27, g27).real, len(g27)/2-1)))
    pylab.subplot(2,2,4)
    pylab.title('Crosscorrelation gold[0] gold[30]')
    pylab.plot((numpy.roll(filter.ccorr(g0, g30).real, len(g0)/2-1)))
    pylab.show()
 

def web_eg():
    """Example of producing Gold Codes from the net 
    (http://paginas.fe.up.pt/~hmiranda/cm/exorb/files/Pseudo_Noise_Sequences.pdf)"""
    seq1 = mls.lfsr([1],[1,0,0])
    print 'Sequence 1:', numpy.where(seq1, 1, 0)
    seq2 = mls.lfsr([2], [1,0,0])