def test_const_b(self): tb = self.tb expected_result = [1, 1, 1, 1] src1 = analog.sig_source_b(1e6, analog.waveform_type.constant, 0, 1) op = streamops.head(4) dst1 = blocks.vector_sink_b() tb.connect(src1, op) tb.connect(op, dst1) tb.run() dst_data = dst1.data() self.assertEqual(expected_result, dst_data)
def test_sqr_f(self): tb = self.tb expected_result = [0, 0, 0, 0, 1, 1, 1, 1, 0] src1 = analog.sig_source_f(8, analog.waveform_type.square, 1.0, 1.0) op = streamops.head(9) dst1 = blocks.vector_sink_f() tb.connect(src1, op) tb.connect(op, dst1) tb.run() dst_data = dst1.data() self.assertEqual(expected_result, dst_data)
def test_saw_f(self): tb = self.tb expected_result = [.5, .625, .75, .875, 0, .125, .25, .375, .5] src1 = analog.sig_source_f(8, analog.waveform_type.sawtooth, 1.0, 1.0) op = streamops.head(9) dst1 = blocks.vector_sink_f() tb.connect(src1, op) tb.connect(op, dst1) tb.run() dst_data = dst1.data() self.assertFloatTuplesAlmostEqual(expected_result, dst_data, 5)
def test_sqr_c(self): tb = self.tb # arg6 is a bit before -PI/2 expected_result = [1j, 1j, 0, 0, 1, 1, 1 + 0j, 1 + 1j, 1j] src1 = analog.sig_source_c(8, analog.waveform_type.square, 1.0, 1.0) op = streamops.head(9) dst1 = blocks.vector_sink_c() tb.connect(src1, op) tb.connect(op, dst1) tb.run() dst_data = dst1.data() self.assertEqual(expected_result, dst_data)
def __init__(self, args): gr.flowgraph.__init__(self) ################################################## # Variables ################################################## nsamples = args.samples nblocks = args.nblocks fftsize = args.fft_size bufsize = args.buffer_size ################################################## # Blocks ################################################## self.nsrc = blocks.null_source(gr.sizeof_gr_complex * fftsize) self.nsnk = blocks.null_sink(gr.sizeof_gr_complex * fftsize) self.hd = streamops.head(gr.sizeof_gr_complex * fftsize, int(nsamples) // fftsize) blks = [] if not args.cuda: for ii in range(nblocks): if ii % 2 == 0: blks.append(fft.fft_cc_fwd(fftsize, [], False)) else: blks.append(fft.fft_cc_rev(fftsize, [], False)) if (ii > 0): self.connect(blks[ii - 1], 0, blks[ii], 0) self.connect(self.hd, 0, blks[0], 0) self.connect(self.nsrc, 0, self.hd, 0) self.connect(blks[nblocks - 1], 0, self.nsnk, 0) else: for ii in range(nblocks): if ii % 2 == 0: blks.append(fft.fft_cc_fwd(fftsize, [], False)) else: blks.append(fft.fft_cc_rev(fftsize, [], False)) if (ii > 0): self.connect( blks[ii - 1], 0, blks[ii], 0).set_custom_buffer( gr.buffer_cuda_properties.make( gr.buffer_cuda_type.D2D).set_buffer_size( bufsize)) self.connect(self.hd, 0, self.blks[0], 0).set_custom_buffer( gr.buffer_cuda_properties.make( gr.buffer_cuda_type.D2H).set_buffer_size(bufsize)) self.connect(self.nsrc, 0, self.hd, 0).set_custom_buffer( gr.buffer_cuda_properties.make( gr.buffer_cuda_type.H2D).set_buffer_size(bufsize)) self.connect(blks[nblocks - 1], 0, self.nsnk).set_custom_buffer( gr.buffer_cuda_properties.make( gr.buffer_cuda_type.H2D).set_buffer_size(bufsize))
def test_tri_f(self): tb = self.tb expected_result = [1, .75, .5, .25, 0, .25, .5, .75, 1] src1 = analog.sig_source_f(8, analog.waveform_t.triangle, 1.0, 1.0) op = streamops.head(9) dst1 = blocks.vector_sink_f() tb.connect(src1, op) tb.connect(op, dst1) tb.run() dst_data = dst1.data() self.assertFloatTuplesAlmostEqual(expected_result, dst_data, 5)
def test_cosine_f(self): tb = self.tb sqrt2 = math.sqrt(2) / 2 expected_result = [1, sqrt2, 0, -sqrt2, -1, -sqrt2, 0, sqrt2, 1] src1 = analog.sig_source_f(8, analog.waveform_type.cos, 1.0, 1.0) op = streamops.head(9) dst1 = blocks.vector_sink_f() tb.connect(src1, op) tb.connect(op, dst1) tb.run() dst_data = dst1.data() self.assertFloatTuplesAlmostEqual(expected_result, dst_data, 5)
def test_saw_c(self): tb = self.tb expected_result = [ .5 + .25j, .625 + .375j, .75 + .5j, .875 + .625j, 0 + .75j, .125 + .875j, .25 + 1j, .375 + .125j, .5 + .25j ] src1 = analog.sig_source_c(8, analog.waveform_type.sawtooth, 1.0, 1.0) op = streamops.head(9) dst1 = blocks.vector_sink_c() tb.connect(src1, op) tb.connect(op, dst1) tb.run() dst_data = dst1.data() self.assertComplexTuplesAlmostEqual(expected_result, dst_data, 5)
def test_tri_c(self): tb = self.tb expected_result = [ 1 + .5j, .75 + .75j, .5 + 1j, .25 + .75j, 0 + .5j, .25 + .25j, .5 + 0j, .75 + .25j, 1 + .5j ] src1 = analog.sig_source_c(8, analog.waveform_t.triangle, 1.0, 1.0) op = streamops.head(9) dst1 = blocks.vector_sink_c() tb.connect(src1, op) tb.connect(op, dst1) tb.run() dst_data = dst1.data() self.assertComplexTuplesAlmostEqual(expected_result, dst_data, 5)
def test_sine_b(self): tb = self.tb sqrt2 = math.sqrt(2) / 2 temp_result = [0, sqrt2, 1, sqrt2, 0, -sqrt2, -1, -sqrt2, 0] amp = 8 expected_result = tuple([int(z * amp) for z in temp_result]) src1 = analog.sig_source_b(8, analog.waveform_type.sin, 1.0, amp) op = streamops.head(9) dst1 = blocks.vector_sink_b() tb.connect(src1, op) tb.connect(op, dst1) tb.run() dst_data = dst1.data() # Let the python know we are dealing with signed int behind scenes dst_data_signed = [b if b < 127 else (256 - b) * -1 for b in dst_data] self.assertFloatTuplesAlmostEqual(expected_result, dst_data_signed)
def __init__(self, args): gr.flowgraph.__init__(self) ################################################## # Variables ################################################## nsamples = args.samples nchans = args.nchans attn = args.attenuation bufsize = args.buffer_size taps = filter.firdes.low_pass_2(1, nchans, 1 / 2, 1 / 10, attenuation_dB=attn,window=fft.window.WIN_BLACKMAN_hARRIS) ################################################## # Blocks ################################################## self.nsrc = blocks.null_source(gr.sizeof_gr_complex*1) self.nsnk = blocks.null_sink(gr.sizeof_gr_complex*1, nports=nchans) self.hd = streamops.head(gr.sizeof_gr_complex*1, int(nsamples)) if not args.cuda: self.channelizer = filter.pfb_channelizer_cc( nchans, taps, 1.0) # self.s2ss = streamops.stream_to_streams(gr.sizeof_gr_complex, nchans) ################################################## # Connections ################################################## # nsnks = [] for ii in range(nchans): # nsnks.append(blocks.null_sink(gr.sizeof_gr_complex*1)) self.connect(self.channelizer, ii, self.nsnk, ii) # self.connect(self.s2ss, ii, self.channelizer, ii) # self.connect(self.channelizer, self.nsnk) # self.connect(self.hd, 0, self.s2ss, 0) self.connect([self.nsrc, self.hd, self.channelizer]) # self.connect(self.nsrc, 0, self.hd, 0) else: self.channelizer = filter.pfb_channelizer_cc( nchans, taps, 1.0, impl=filter.pfb_channelizer_cc.cuda) # self.s2ss = streamops.stream_to_streams(gr.sizeof_gr_complex, nchans, impl=streamops.stream_to_streams.cuda) ################################################## # Connections ################################################## # nsnks = [] for ii in range(nchans): # blk = blocks.null_sink(gr.sizeof_gr_complex*1) # nsnks.append(blk) self.connect(self.channelizer, ii, self.nsnk, ii).set_custom_buffer(gr.buffer_cuda_properties.make(gr.buffer_cuda_type.D2H).set_buffer_size(bufsize)) # self.connect(self.s2ss, ii, self.channelizer, ii).set_custom_buffer(gr.buffer_cuda_properties.make(gr.buffer_cuda_type.D2D).set_buffer_size(bufsize)) # self.connect(self.channelizer, ii, nsnks[ii], 0).set_custom_buffer(gr.buffer_cuda_pinned_properties.make().set_buffer_size(bufsize)) # self.connect(self.s2ss, ii, self.channelizer, ii).set_custom_buffer(gr.buffer_cuda_pinned_properties.make().set_buffer_size(bufsize)) # self.connect(self.channelizer, self.nsnk) # self.connect(self.hd, 0, self.s2ss, 0).set_custom_buffer(gr.buffer_cuda_properties.make(gr.buffer_cuda_type.H2D).set_buffer_size(bufsize)) self.connect(self.hd, 0, self.channelizer, 0).set_custom_buffer(gr.buffer_cuda_properties.make(gr.buffer_cuda_type.H2D).set_buffer_size(bufsize)) # self.connect(self.hd, 0, self.s2ss, 0).set_custom_buffer(gr.buffer_cuda_pinned_properties.make().set_buffer_size(bufsize)) self.connect(self.nsrc, 0, self.hd, 0).set_custom_buffer(gr.buffer_cpu_vmcirc_properties.make(gr.buffer_cpu_vmcirc_type.AUTO).set_buffer_size(bufsize))