def test_003_t (self): """ two states, random switching """ n_bytes = 10000 ber = (0, 0.5) trans_matrix = (0.5, 0.5, 0.5, 0.5) src = gr.glfsr_source_b(32) # Create some pseudo-random bits head = gr.head(1, n_bytes) chan = cc.markovchan_bb(ber, trans_matrix, 8) ber = cc.ber_b(8) sink_state = gr.vector_sink_i() self.tb.connect(src, head, chan, (ber, 0)) self.tb.connect(head, (ber, 1)) self.tb.connect((chan, 1), sink_state) self.tb.run () n_times_in_state_1 = np.sum(sink_state.data()) print "\nNumber of times in state 1 = " + str(n_times_in_state_1) print " Expected value = " + str(n_bytes/2) self.assertTrue(n_times_in_state_1 > 3500 and n_times_in_state_1 < 6500, "Due to the statistical nature of the bsc, this can actually fail (though very unlikely). Try again.") print " Measured BER = " + str(ber.ber()) print "Expected value = 0.25" self.assertTrue(abs(ber.ber()- 0.25) < 0.05, msg="Due to the statistical nature of the bsc, this can actually fail (though very unlikely). Try again.")
def __init__(self): gr.top_block.__init__(self) parser = OptionParser(option_class=eng_option) parser.add_option( "-O", "--audio-output", type="string", default="", help="pcm output device name. E.g., hw:0,0 or /dev/dsp") parser.add_option("-r", "--sample-rate", type="eng_float", default=48000, help="set sample rate to RATE (48000)") (options, args) = parser.parse_args() if len(args) != 0: parser.print_help() raise SystemExit, 1 sample_rate = int(options.sample_rate) ampl = 0.1 src = gr.glfsr_source_b(32) # Pseudorandom noise source b2f = gr.chunks_to_symbols_bf([ampl, -ampl], 1) dst = audio.sink(sample_rate, options.audio_output) self.connect(src, b2f, dst)
def test_stream_interleaving_symbols(self): n_rows = 32 n_cols = 128 src = gr.glfsr_source_b(32) head = gr.head(gr.sizeof_char, n_rows * n_cols * 3) interleaver = cc.blockinterleaver_bb(n_rows, n_cols) deinterleaver = cc.blockdeinterleaver_bb(n_rows, n_cols) ber = cc.ber_b(8) self.tb.connect(src, head, interleaver, deinterleaver, ber) self.tb.connect(head, (ber, 1)) self.tb.run() self.assertEqual(ber.ber(), 0)
def test_002_correlation_b(self): for degree in range(1,11): # Higher degrees take too long to correlate src = gr.glfsr_source_b(degree, False) b2f = gr.chunks_to_symbols_bf((-1.0,1.0), 1) dst = gr.vector_sink_f() self.fg.connect(src, b2f, dst) self.fg.run() actual_result = dst.data() R = auto_correlate(actual_result) self.assertEqual(R[0], float(len(R))) # Auto-correlation peak at origin for i in range(len(R)-1): self.assertEqual(R[i+1], -1.0) # Auto-correlation minimum everywhere else
def test_002_correlation_b(self): for degree in range(1,11): # Higher degrees take too long to correlate src = gr.glfsr_source_b(degree, False) b2f = gr.chunks_to_symbols_bf((-1.0,1.0), 1) dst = gr.vector_sink_f() del self.tb # Discard existing top block self.tb = gr.top_block() self.tb.connect(src, b2f, dst) self.tb.run() self.tb.disconnect_all() actual_result = dst.data() R = auto_correlate(actual_result) self.assertEqual(R[0], float(len(R))) # Auto-correlation peak at origin for i in range(len(R)-1): self.assertEqual(R[i+1], -1.0) # Auto-correlation minimum everywhere else
def test_002_bsc (self): """ Test on unpacked data """ src = gr.glfsr_source_b(32) # Create some pseudo-random bits head = gr.head(1, 10000) bsc = chancoding.bsc_bb(0.3) sink1 = gr.vector_sink_b() sink2 = gr.vector_sink_b() self.tb.connect(src, head, bsc, sink1) self.tb.connect(head, sink2) self.tb.run() bits1 = sink1.data() bits2 = sink2.data() bit_errors = np.sum(np.abs(np.array(bits1) - np.array(bits2))) self.assert_(bit_errors > 2500 and bit_errors < 3500, "Due to the statistical nature of the bsc, this can actually fail (though very unlikely). Try again.")
def test_002_bsc(self): """ Test on unpacked data """ src = gr.glfsr_source_b(32) # Create some pseudo-random bits head = gr.head(1, 10000) bsc = chancoding.bsc_bb(0.3) sink1 = gr.vector_sink_b() sink2 = gr.vector_sink_b() self.tb.connect(src, head, bsc, sink1) self.tb.connect(head, sink2) self.tb.run() bits1 = sink1.data() bits2 = sink2.data() bit_errors = np.sum(np.abs(np.array(bits1) - np.array(bits2))) self.assert_( bit_errors > 2500 and bit_errors < 3500, "Due to the statistical nature of the bsc, this can actually fail (though very unlikely). Try again." )
def test_003_bsc_packed (self): """ Test on packed data """ src = gr.glfsr_source_b(32) # Create some pseudo-random bits packer = gr.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST) head = gr.head(1, 8 * 1000) bsc = chancoding.bsc_bb(0.5, 8) unpacker = gr.packed_to_unpacked_bb(1, gr.GR_MSB_FIRST) sink1 = gr.vector_sink_b() sink2 = gr.vector_sink_b() self.tb.connect(src, head, packer, bsc, unpacker, sink1) self.tb.connect(head, sink2) self.tb.run() bits1 = sink1.data() bits2 = sink2.data() bit_errors = np.sum(np.abs(np.array(bits1) - np.array(bits2))) self.assert_(bit_errors > 3500 and bit_errors < 4500, "Due to the statistical nature of the bsc, this can actually fail (though very unlikely). Try again.")
def __init__(self): gr.top_block.__init__(self) parser = OptionParser(option_class=eng_option) parser.add_option("-O", "--audio-output", type="string", default="", help="pcm output device name. E.g., hw:0,0 or /dev/dsp") parser.add_option("-r", "--sample-rate", type="eng_float", default=48000, help="set sample rate to RATE (48000)") (options, args) = parser.parse_args () if len(args) != 0: parser.print_help() raise SystemExit, 1 sample_rate = int(options.sample_rate) ampl = 0.1 src = gr.glfsr_source_b(32) # Pseudorandom noise source b2f = gr.chunks_to_symbols_bf([ampl, -ampl], 1) dst = audio.sink(sample_rate, options.audio_output) self.connect(src, b2f, dst)
def test_002_t (self): """ two state: one errorless, and the other can never be reached """ n_bytes = 10000 ber = (0, 0.5) trans_matrix = (1.0, 0.0, 1.0, 0.0) src = gr.glfsr_source_b(32) # Create some pseudo-random bits head = gr.head(1, n_bytes) chan = cc.markovchan_bb(ber, trans_matrix, 8) ber = cc.ber_b(8) sink_state = gr.vector_sink_i() self.tb.connect(src, head, chan, (ber, 0)) self.tb.connect(head, (ber, 1)) self.tb.connect((chan, 1), sink_state) self.tb.run () self.assertEqual(ber.ber(), 0) self.assertEqual(sink_state.data(), (0,) * n_bytes, "State was not always 0!")
def test_003_bsc_packed(self): """ Test on packed data """ src = gr.glfsr_source_b(32) # Create some pseudo-random bits packer = gr.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST) head = gr.head(1, 8 * 1000) bsc = chancoding.bsc_bb(0.5, 8) unpacker = gr.packed_to_unpacked_bb(1, gr.GR_MSB_FIRST) sink1 = gr.vector_sink_b() sink2 = gr.vector_sink_b() self.tb.connect(src, head, packer, bsc, unpacker, sink1) self.tb.connect(head, sink2) self.tb.run() bits1 = sink1.data() bits2 = sink2.data() bit_errors = np.sum(np.abs(np.array(bits1) - np.array(bits2))) self.assert_( bit_errors > 3500 and bit_errors < 4500, "Due to the statistical nature of the bsc, this can actually fail (though very unlikely). Try again." )
def test_000_make_b(self): src = gr.glfsr_source_b(16) self.assertEquals(src.mask(), 0x8016) self.assertEquals(src.period(), 2**16-1)
def test_001_degree_b(self): self.assertRaises(RuntimeError, lambda: gr.glfsr_source_b(0)) self.assertRaises(RuntimeError, lambda: gr.glfsr_source_b(33))
def test_000_make_b(self): src = gr.glfsr_source_b(16) src.start() time.sleep(1) self.assertEquals(src.mask, 0x8016) self.assertEquals(src.period, 2**16-1)
def test_000_make_b(self): src = gr.glfsr_source_b(16) src.start() time.sleep(1) self.assertEquals(src.mask, 0x8016) self.assertEquals(src.period, 2**16 - 1)