コード例 #1
0
    # This test for soft decoding produces a random message of
    # nbits=1000 in length, from a fixed random seed (so each time the
    # program is run, the same behavior will occur. We encode the
    # message and then use your soft decoder (code above) to test it.
    # If the decoded stream is the same as what we expect from our
    # encoder, we consider the test case to have passed.  Note, it is
    # possible (though not likely) that your soft decoder may not pass
    # this test case, but is in fact correct.  That's why we have not
    # made the test case part of the verification before checkoff.
    K, glist = 3, (7, 5)
    soft = SoftViterbiDecoder(K, glist)
    nbits = 1000
    sigma = 0.5                # noise defined as 2*sigma^2 = 1/8
    numpy.random.seed(617617617)
    message = numpy.random.random_integers(0,1,nbits)
    expected = numpy.array([1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 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 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1])

    encoded = PS3_tests.convolutional_encoder(message, K, glist)

    noisy = numpy.random.normal(0,sigma,len(encoded))
    received = encoded + noisy

    decoded = numpy.array(soft.decode(received))
    if (decoded == expected).all() == True:
        print 'Soft decoding succeeded on test case: congratulations!'
    else:
        print 'Oops... error in soft decoding'
        print 'Decoded as', decoded
        print 'Expected  ', expected
        sys.exit(1)
コード例 #2
0
ファイル: PS3_viterbi.py プロジェクト: Edward-Wei/mit-courses
        # reconstruct message by tracing the most likely path
        # back through the matrix using self.Predecessor.
        return self.traceback(s,n)

    # print out final path metrics
    def dump_state(self):
        print self.PM[:,-1]

if __name__=='__main__':
    constraint_len = 3; glist = (7,5,3)
    d = ViterbiDecoder(constraint_len, glist)

    # first test case: example from lecture
    message = [1,0,1,0,1,1,0,0]
    received = PS3_tests.convolutional_encoder(message, constraint_len, glist)
    i = 0
    print 'TEST', i
    decoded = numpy.array(d.decode(received, debug=True))
    print 'Testing without adding noise...'
    if (message == decoded).all() == True: 
        print 'Successfully decoded no-noise Test 0: congratulations!'
        print
    else:
        print 'Oops... error in decoding no-noise Test', i
        print 'Decoded as ', decoded
        print 'Correct is', message
        sys.exit(1)

    # second batch of test cases: different constraint lengths, generators
    nbits = 29
コード例 #3
0
        1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 1, 1, 1,
        0, 0, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0,
        1, 1, 1, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 0,
        1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0,
        0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1,
        1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0,
        1, 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 1,
        0, 0, 1, 1, 0, 1, 0, 1, 1, 0, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0,
        1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1,
        1, 1, 1, 0, 0, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1,
        0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0, 0, 0,
        0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0,
        1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1,
        1, 1, 1, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,
        0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1
    ])

    encoded = PS3_tests.convolutional_encoder(message, K, glist)

    noisy = numpy.random.normal(0, sigma, len(encoded))
    received = encoded + noisy

    decoded = numpy.array(soft.decode(received))
    if (decoded == expected).all() == True:
        print 'Soft decoding succeeded on test case: congratulations!'
    else:
        print 'Oops... error in soft decoding'
        print 'Decoded as', decoded
        print 'Expected  ', expected
        sys.exit(1)
コード例 #4
0
        # reconstruct message by tracing the most likely path
        # back through the matrix using self.Predecessor.
        return self.traceback(s,n)

    # print out final path metrics
    def dump_state(self):
        print self.PM[:,-1]

if __name__=='__main__':
    constraint_len = 3; glist = (7,5,3)
    d = ViterbiDecoder(constraint_len, glist)

    # first test case: example from lecture
    message = [1,0,1,0,1,1,0,0]
    received = PS3_tests.convolutional_encoder(message, constraint_len, glist)
    i = 0
    print 'TEST', i
    decoded = numpy.array(d.decode(received, debug=True))
    print 'Testing without adding noise...'
    if (message == decoded).all() == True: 
        print 'Successfully decoded no-noise Test 0: congratulations!'
        print
    else:
        print 'Oops... error in decoding no-noise Test', i
        print 'Decoded as ', decoded
        print 'Correct is', message
        sys.exit(1)

    # second batch of test cases: different constraint lengths, generators
    nbits = 29