Beispiel #1
0
    def __init__(self, frame, panel, vbox, argv):
        stdgui2.std_top_block.__init__ (self, frame, panel, vbox, argv)
        pspectrum_len = 1024
        # build our flow graph
        input_rate = 2e6
        #Generate some noise
        noise = analog.noise_source_c(analog.GR_GAUSSIAN, 1.0/10)
        # Generate a complex sinusoid
        #source = gr.file_source(gr.sizeof_gr_complex, 'foobar2.dat', repeat=True)
        src1 = analog.sig_source_c (input_rate, analog.GR_SIN_WAVE, -500e3, 1)
        src2 = analog.sig_source_c (input_rate, analog.GR_SIN_WAVE, 500e3, 1)
        src3 = analog.sig_source_c (input_rate, analog.GR_SIN_WAVE, -250e3, 2)

        # We add these throttle blocks so that this demo doesn't
        # suck down all the CPU available.  Normally you wouldn't use these.
        thr1 = blocks.throttle(gr.sizeof_gr_complex, input_rate)
        sink1 = spectrum_sink_c (panel, title="Spectrum Sink", pspectrum_len=pspectrum_len,
                            sample_rate=input_rate, baseband_freq=0,
                            ref_level=0, y_per_div=20, y_divs=10, m = 70, n = 3, nsamples = 1024)
        vbox.Add (sink1.win, 1, wx.EXPAND)
        combine1 = blocks.add_cc()
        self.connect(src1, (combine1, 0))
        self.connect(src2, (combine1, 1))
        self.connect(src3, (combine1, 2))
        self.connect(noise, (combine1, 3))
        self.connect(combine1, thr1, sink1)
 def run_flow_graph(sync_sym1, sync_sym2, data_sym):
     top_block = gr.top_block()
     carr_offset = random.randint(-max_offset/2, max_offset/2) * 2
     tx_data = shift_tuple(sync_sym1, carr_offset) + \
               shift_tuple(sync_sym2, carr_offset) + \
               shift_tuple(data_sym,  carr_offset)
     channel = [rand_range(min_chan_ampl, max_chan_ampl) * numpy.exp(1j * rand_range(0, 2 * numpy.pi)) for x in range(fft_len)]
     src = blocks.vector_source_c(tx_data, False, fft_len)
     chan = blocks.multiply_const_vcc(channel)
     noise = analog.noise_source_c(analog.GR_GAUSSIAN, wgn_amplitude)
     add = blocks.add_cc(fft_len)
     chanest = digital.ofdm_chanest_vcvc(sync_sym1, sync_sym2, 1)
     sink = blocks.vector_sink_c(fft_len)
     top_block.connect(src, chan, (add, 0), chanest, sink)
     top_block.connect(noise, blocks.stream_to_vector(gr.sizeof_gr_complex, fft_len), (add, 1))
     top_block.run()
     channel_est = None
     carr_offset_hat = 0
     rx_sym_est = [0,] * fft_len
     tags = sink.tags()
     for tag in tags:
         if pmt.symbol_to_string(tag.key) == 'ofdm_sync_carr_offset':
             carr_offset_hat = pmt.to_long(tag.value)
             self.assertEqual(carr_offset, carr_offset_hat)
         if pmt.symbol_to_string(tag.key) == 'ofdm_sync_chan_taps':
             channel_est = shift_tuple(pmt.c32vector_elements(tag.value), carr_offset)
     shifted_carrier_mask = shift_tuple(carrier_mask, carr_offset)
     for i in range(fft_len):
         if shifted_carrier_mask[i] and channel_est[i]:
             self.assertAlmostEqual(channel[i], channel_est[i], places=0)
             rx_sym_est[i] = (sink.data()[i] / channel_est[i]).real
     return (carr_offset, list(shift_tuple(rx_sym_est, -carr_offset_hat)))
 def test_001_detect (self):
     """ Send two bursts, with zeros in between, and check
     they are both detected at the correct position and no
     false alarms occur """
     n_zeros = 15
     fft_len = 32
     cp_len = 4
     sig_len = (fft_len + cp_len) * 10
     sync_symbol = [(random.randint(0, 1)*2)-1 for x in range(fft_len/2)] * 2
     tx_signal = [0,] * n_zeros + \
                 sync_symbol[-cp_len:] + \
                 sync_symbol + \
                 [(random.randint(0, 1)*2)-1 for x in range(sig_len)]
     tx_signal = tx_signal * 2
     add = blocks.add_cc()
     sync = digital.ofdm_sync_sc_cfb(fft_len, cp_len)
     sink_freq   = blocks.vector_sink_f()
     sink_detect = blocks.vector_sink_b()
     self.tb.connect(blocks.vector_source_c(tx_signal), (add, 0))
     self.tb.connect(analog.noise_source_c(analog.GR_GAUSSIAN, .01), (add, 1))
     self.tb.connect(add, sync)
     self.tb.connect((sync, 0), sink_freq)
     self.tb.connect((sync, 1), sink_detect)
     self.tb.run()
     sig1_detect = sink_detect.data()[0:len(tx_signal)/2]
     sig2_detect = sink_detect.data()[len(tx_signal)/2:]
     self.assertTrue(abs(sig1_detect.index(1) - (n_zeros + fft_len + cp_len)) < cp_len)
     self.assertTrue(abs(sig2_detect.index(1) - (n_zeros + fft_len + cp_len)) < cp_len)
     self.assertEqual(numpy.sum(sig1_detect), 1)
     self.assertEqual(numpy.sum(sig2_detect), 1)
Beispiel #4
0
 def __init__(self, Np=32, P=128, L=2,
              filename=None, sample_type='complex', verbose=True):
     gr.top_block.__init__(self)
     if filename is None:
         src = analog.noise_source_c(analog.GR_GAUSSIAN, 1)
         if verbose:
             print "Using Gaussian noise source."
     else:
         if sample_type == 'complex':
             src = blocks.file_source(gr.sizeof_gr_complex, filename, True)
         else:
             fsrc = blocks.file_source(gr.sizeof_float, filename, True)
             src = blocks.float_to_complex()
             self.connect(fsrc, src)
         if verbose:
             print "Reading data from %s" % filename
     if verbose:
         print "FAM configuration:"
         print "N'   = %d" % Np
         print "P    = %d" % P
         print "L    = %d" % L
         #print "Δf   = %f" % asfd
     sink = blocks.null_sink(gr.sizeof_float * 2 * Np)
     self.cyclo_fam = specest.cyclo_fam(Np, P, L)
     self.connect(src, self.cyclo_fam, sink)
    def __init__(self, N, fs, bw0, bw1, tw, atten, D):
        gr.top_block.__init__(self)

        self._nsamps = N
        self._fs = fs
        self._bw0 = bw0
        self._bw1 = bw1
        self._tw = tw
        self._at = atten
        self._decim = D
        taps = filter.firdes.complex_band_pass_2(1, self._fs,
                                                 self._bw0, self._bw1,
                                                 self._tw, self._at)
        print "Num. Taps: ", len(taps)

        self.src  = analog.noise_source_c(analog.GR_GAUSSIAN, 1)
        self.head = blocks.head(gr.sizeof_gr_complex, self._nsamps)

        self.filt0 = filter.fft_filter_ccc(self._decim, taps)

        self.vsnk_src = blocks.vector_sink_c()
        self.vsnk_out = blocks.vector_sink_c()

        self.connect(self.src, self.head, self.vsnk_src)
        self.connect(self.head, self.filt0, self.vsnk_out)
Beispiel #6
0
    def run_noise_source_c(self):
        ntype = analog.GR_GAUSSIAN
        ampl = 10
        seed = 0

        self.blocks = []
        self.tb = gr.top_block()
        self.blocks.append(analog.noise_source_c(ntype, ampl, seed))
        self.blocks.append(blocks.head(gr.sizeof_gr_complex, self.N))
        self.blocks.append(blocks.null_sink(gr.sizeof_gr_complex))
        self.tb.connect(*self.blocks)
        self.tb.run()
Beispiel #7
0
    def __init__(self, fpga_frequency = -10.7e6, decim_factor = 250, channels = 4, variance = 0.0):
        gr.top_block.__init__(self)

        # Gaussian distributed signal source. 
        noise_src = gr_analog.noise_source_c(gr_analog.GR_GAUSSIAN, variance, int(time.time()))

        # Throttle signal to the same sampling rate as the USRP. 
        throttle  = gr_blocks.throttle(gr.sizeof_gr_complex, 
                                params.usrp_sampling_rate / float(decim_factor) * channels)
                
        #: Gaussian distributed signal source, deinterleaved to the number of channels. 
        self.u = gr_blocks.deinterleave(gr.sizeof_gr_complex)
        self.connect(noise_src,throttle,self.u)
Beispiel #8
0
 def test_002 (self):
     """ Stream some data through the block to see it all works. """
     Np = 128
     P = 512
     L = 4
     src = analog.noise_source_c(analog.GR_GAUSSIAN, 1)
     head = blocks.head(gr.sizeof_gr_complex, P * L)
     cyclo_fam = specest.cyclo_fam (Np,P,L)
     dst = blocks.vector_sink_f(2*Np)
     self.tb.connect(src, head, cyclo_fam, dst)
     try:
         self.tb.run()
     except:
         self.fail("Something's wrong -- an exception was thrown during runtime.")
    def __init__(self, options):
        gr.top_block.__init__(self, name = "top_block")


        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 1e6
        self.fft_len = fft_len = options.fft_length
        self.ebn0 = ebn0 = options.ebn0
        self.cp_len = cp_len = options.cp_length
        self.bits_per_symbol = bits_per_symbol = 8

        ##################################################
        # Blocks
        ##################################################
        self.digital_ofdm_mod_0 = grc_blks2.packet_mod_i(digital.ofdm_mod(
        		options=grc_blks2.options(
        			modulation="qam256",
        			fft_length=fft_len,
        			occupied_tones=40,
        			cp_length=cp_len,
        			pad_for_usrp=True,
        			log=None,
        			verbose=None,
        		),
        	),
        	payload_length=0,
        )
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate)
        self.blocks_skiphead_0 = blocks.skiphead(gr.sizeof_gr_complex*1, (fft_len+cp_len)*1)
        self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_gr_complex*1, "./%d_%d_%d_%d_%s.bin" % (fft_len, cp_len, options.ebn0, options.it, options.type), False)
        self.blocks_file_sink_0.set_unbuffered(False)
        self.blocks_add_xx_0 = blocks.add_vcc(1)
        self.analog_random_source_x_0 = blocks.vector_source_i(map(int, numpy.random.randint(0, 2, 1000)), True)
        self.analog_noise_source_x_0 = analog.noise_source_c(analog.GR_GAUSSIAN, 1.0 / math.sqrt(2.0 * bits_per_symbol * 10**(ebn0/10.0)), 0)

        self.channels_selective_fading_model_0 = channels.selective_fading_model( 8, 10.0/samp_rate, False, 4.0, 0, options.delay, options.mag, 128 )

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_throttle_0, 0), (self.blocks_file_sink_0, 0))
        self.connect((self.analog_random_source_x_0, 0), (self.digital_ofdm_mod_0, 0))
        self.connect((self.digital_ofdm_mod_0, 0), (self.channels_selective_fading_model_0, 0))
        self.connect((self.blocks_skiphead_0, 0), (self.blocks_throttle_0, 0))
        self.connect((self.blocks_add_xx_0, 0), (self.blocks_skiphead_0, 0))
        self.connect((self.channels_selective_fading_model_0, 0), (self.blocks_add_xx_0, 0))
        self.connect((self.analog_noise_source_x_0, 0), (self.blocks_add_xx_0, 1))
Beispiel #10
0
    def _build(self, input_signature, output_signature):
        """
        Build the internal structure of this hierarchical block.
        @param input_signature
        @param output_signature
        """

        self._adder = blocks.add_vcc(1)
        self._ch_effect = analog.noise_source_c(analog.GR_GAUSSIAN, 1, 0)

        self._add_connections([self._component, (self._adder, 0)])  #pylint: disable = E1101
        self._add_connections([self._ch_effect, (self._adder, 1)])  #pylint: disable = E1101

        # We return the adder, i.e., the original signal is connected in port 0.
        return self._adder
Beispiel #11
0
 def test_002_stream (self):
     """ Stream some data through the block to see it all works. """
     block_len = 256
     fft_len = 128
     order = 6
     n_blocks = 100
     src = analog.noise_source_c(analog.GR_GAUSSIAN, 1)
     head = blocks.head(gr.sizeof_gr_complex, n_blocks * block_len)
     fcov = specest.fcov(block_len, fft_len, order)
     dst = blocks.vector_sink_f(fft_len)
     self.tb.connect(src, head, fcov, dst)
     try:
         self.tb.run()
     except:
         self.fail("Something's wrong -- an exception was thrown during runtime.")
Beispiel #12
0
    def test_depuncture_viterbi_cb(self):
        """
        Performs some very basic tests of the depuncture-viterbi block
        """
        # 1. Random data
        expected_result = ()

        src = analog.noise_source_c(analog.GR_GAUSSIAN, ampl=math.sqrt(1/2), seed=0)
        head = blocks.head(gr.sizeof_gr_complex, 100000)
        depuncture_viterbi = dvb.depuncture_viterbi_cb([1,1])
        dst = blocks.vector_sink_b()

        self.tb.connect(src, head, depuncture_viterbi, dst)
        self.tb.run()
        self.assertEqual(expected_result, dst.data());
Beispiel #13
0
    def __init__(self,EbN0db,semente):
        gr.top_block.__init__(self)

        ##################################################
        # Variables
        ##################################################
        self.d = d = 0.1633
        self.dj = dj = d*1j
        self.cj = cj = d*3j
        self.c = c = 3*d
        self.bj = bj = d*5j
        self.b = b = 5*d
        self.aj = aj = d*7j
        self.a = a = 7*d
        self.value = value = 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63
        self.symbol = symbol = (-a-aj),(-b-aj),(-c-aj),(-d-aj),(+a-aj),(+b-aj),(+c-aj),(+d-aj),(-a-bj),(-b-bj),(-c-bj),(-d-bj),(+a-bj),(+b-bj),(+c-bj),(+d-bj),(-a-cj),(-b-cj),(-c-cj),(-d-cj),(+a-cj),(+b-cj),(+c-cj),(+d-cj),(-a-dj),(-b-dj),(-c-dj),(-d-dj),(+a-dj),(+b-dj),(+c-dj),(+d-dj),(-a+aj),(-b+aj),(-c+aj),(-d+aj),(+a+aj),(+b+aj),(+c+aj),(+d+aj),(-a+bj),(-b+bj),(-c+bj),(-d+bj),(+a+bj),(+b+bj),(+c+bj),(+d+bj),(-a+cj),(-b+cj),(-c+cj),(-d+cj),(+a+cj),(+b+cj),(+c+cj),(+d+cj),(-a+dj),(-b+dj),(-c+dj),(-d+dj),(+a+dj),(+b+dj),(+c+dj),(+d+dj)
        self.samp_rate = samp_rate = 200000
        self.constellation = constellation = digital.constellation_calcdist((symbol), (value), 0, 1).base()

        ##################################################
        # Blocks
        ##################################################
        self.vectorSink = blocks.vector_sink_f(1)
        self.digital_constellation_decoder_cb_0 = digital.constellation_decoder_cb(constellation)
        self.digital_chunks_to_symbols_xx_0 = digital.chunks_to_symbols_bc((symbol), 1)
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_char*1, samp_rate,True)
        self.blocks_add_xx_0 = blocks.add_vcc(1)
        self.blks2_error_rate_0 = grc_blks2.error_rate(
        	type='BER',
        	win_size=10000000,
        	bits_per_symbol=int(math.log(len(symbol))/math.log(2)),
        )
        self.analog_random_source_x_0 = blocks.vector_source_b(map(int, numpy.random.randint(0, 64, 4000000)), False)
        self.analog_noise_source_x_0 =analog.noise_source_c(analog.GR_GAUSSIAN,self.EbN0_to_noise_voltage(EbN0db,int(6)),semente)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_noise_source_x_0, 0), (self.blocks_add_xx_0, 1))    
        self.connect((self.analog_random_source_x_0, 0), (self.blocks_throttle_0, 0))    
        self.connect((self.blks2_error_rate_0, 0), (self.vectorSink, 0))    
        self.connect((self.blocks_add_xx_0, 0), (self.digital_constellation_decoder_cb_0, 0))    
        self.connect((self.blocks_throttle_0, 0), (self.blks2_error_rate_0, 0))    
        self.connect((self.blocks_throttle_0, 0), (self.digital_chunks_to_symbols_xx_0, 0))    
        self.connect((self.digital_chunks_to_symbols_xx_0, 0), (self.blocks_add_xx_0, 0))    
        self.connect((self.digital_constellation_decoder_cb_0, 0), (self.blks2_error_rate_0, 1))    
Beispiel #14
0
 def __init__(self, EbN0):
     gr.top_block.__init__(self)
     self.const = digital.qpsk_constellation()
     # Source is N_BITS bits, non-repeated
     data = list(map(int, numpy.random.randint(0, self.const.arity(), N_BITS / self.const.bits_per_symbol())))
     src   = blocks.vector_source_b(data, False)
     mod   = digital.chunks_to_symbols_bc((self.const.points()), 1)
     add   = blocks.add_vcc()
     noise = analog.noise_source_c(analog.GR_GAUSSIAN,
                                   self.EbN0_to_noise_voltage(EbN0),
                                   RAND_SEED)
     demod = digital.constellation_decoder_cb(self.const.base())
     ber   = BitErrors(self.const.bits_per_symbol())
     self.sink  = blocks.vector_sink_f()
     self.connect(src, mod, add, demod, ber, self.sink)
     self.connect(noise, (add, 1))
     self.connect(src, (ber, 1))
 def __init__(self, frame, panel, vbox, argv):
     stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv)
     self.frame = frame
     self.panel = panel
     parser = OptionParser(usage="%prog: [options]")
     parser.add_option("-N", "--dpsslength", type="int",
             help="Length of the DPSS", default="512")
     parser.add_option("-B", "--timebandwidthproduct", type="float",
             help="Time Bandwidthproduct used to calculate the DPSS", default="3")
     parser.add_option("-K", "--tapers", type="int",
             help="Number of Tapers used to calculate the Spectrum", default="5")
     parser.add_option("-W", "--weighting", type="choice", choices=("unity", "eigenvalues" ,"adaptive" ),
             help="weighting-type to be used (unity, eigenvalues, adaptive) ", default="adaptive")
     (options, args) = parser.parse_args ()
     self.options = options
     #setting up our signal
     self.samplingrate = 48000
     self.source = analog.sig_source_c(self.samplingrate, analog.GR_SIN_WAVE, 3000, 1)
     self.noise = analog.noise_source_c(analog.GR_GAUSSIAN,0.5)
     self.add = blocks.add_cc()
     self.throttle = blocks.throttle(gr.sizeof_gr_complex, self.samplingrate)
     #the actual spectrum estimator
     self.v2s = blocks.vector_to_stream(gr.sizeof_float, self.options.dpsslength)
     self.mtm = specest.mtm(
             N = self.options.dpsslength,
             NW = self.options.timebandwidthproduct,
             K = self.options.tapers,
             weighting = self.options.weighting
     )
     self.scope = specest.spectrum_sink_f(
             panel,
             title='Spectrum with %s weighting, Length %i and %i Tapers' % (
                 self.options.weighting, self.options.dpsslength, self.options.tapers
             ),
             spec_size=self.options.dpsslength,
             sample_rate=self.samplingrate,
             ref_level=80,
             avg_alpha=0.8,
             y_per_div=20
     )
     self.connect(self.source, (self.add, 0) )
     self.connect(self.noise, (self.add, 1) )
     self.connect(self.add, self.throttle, self.mtm)
     self.connect(self.mtm, self.v2s, self.scope)
     self._build_gui(vbox)
Beispiel #16
0
    def __init__(self, constellation, f, N0=0.25, seed=-666L):
        """
        constellation - a constellation object used for modulation.
        f - a finite state machine specification used for coding.
        N0 - noise level
        seed - random seed
        """
        super(trellis_tb, self).__init__()
        # packet size in bits (make it multiple of 16 so it can be packed in a short)
        packet_size = 1024*16
        # bits per FSM input symbol
        bitspersymbol = int(round(math.log(f.I())/math.log(2))) # bits per FSM input symbol
        # packet size in trellis steps
        K = packet_size/bitspersymbol

        # TX
        src = blocks.lfsr_32k_source_s()
        # packet size in shorts
        src_head = blocks.head(gr.sizeof_short, packet_size/16)
        # unpack shorts to symbols compatible with the FSM input cardinality
        s2fsmi = blocks.packed_to_unpacked_ss(bitspersymbol, gr.GR_MSB_FIRST)
        # initial FSM state = 0
        enc = trellis.encoder_ss(f, 0)
        mod = digital.chunks_to_symbols_sc(constellation.points(), 1)

        # CHANNEL
        add = blocks.add_cc()
        noise = analog.noise_source_c(analog.GR_GAUSSIAN,math.sqrt(N0/2),seed)

        # RX
        # data preprocessing to generate metrics for Viterbi
        metrics = trellis.constellation_metrics_cf(constellation.base(), digital.TRELLIS_EUCLIDEAN)
        # Put -1 if the Initial/Final states are not set.
        va = trellis.viterbi_s(f, K, 0, -1)
        # pack FSM input symbols to shorts
        fsmi2s = blocks.unpacked_to_packed_ss(bitspersymbol, gr.GR_MSB_FIRST)
        # check the output
        self.dst = blocks.check_lfsr_32k_s()

        self.connect (src, src_head, s2fsmi, enc, mod)
        self.connect (mod, (add, 0))
        self.connect (noise, (add, 1))
        self.connect (add, metrics, va, fsmi2s, self.dst)
Beispiel #17
0
    def __init__(self, frame, panel, vbox, argv):
        stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv)

        fft_size = 256

        # build our flow graph
        input_rate = 2048.0e3

        #Generate some noise
        noise = analog.noise_source_c(analog.GR_UNIFORM, 1.0/10)

        # Generate a complex sinusoid
        #src1 = analog.sig_source_c(input_rate, analog.GR_SIN_WAVE, 2e3, 1)
        src1 = analog.sig_source_c(input_rate, analog.GR_CONST_WAVE, 57.50e3, 1)

        # We add these throttle blocks so that this demo doesn't
        # suck down all the CPU available.  Normally you wouldn't use these.
        thr1 = blocks.throttle(gr.sizeof_gr_complex, input_rate)

        sink1 = fft_sink_c(panel, title="Complex Data", fft_size=fft_size,
			   sample_rate=input_rate, baseband_freq=100e3,
			   ref_level=0, y_per_div=20, y_divs=10)
        vbox.Add(sink1.win, 1, wx.EXPAND)

        combine1 = blocks.add_cc()
        self.connect(src1, (combine1,0))
        self.connect(noise,(combine1,1))
        self.connect(combine1,thr1, sink1)

        #src2 = analog.sig_source_f(input_rate, analog.GR_SIN_WAVE, 2e3, 1)
        src2 = analog.sig_source_f (input_rate, analog.GR_CONST_WAVE, 57.50e3, 1)
        thr2 = blocks.throttle(gr.sizeof_float, input_rate)
        sink2 = fft_sink_f(panel, title="Real Data", fft_size=fft_size*2,
			   sample_rate=input_rate, baseband_freq=100e3,
			   ref_level=0, y_per_div=20, y_divs=10)
        vbox.Add(sink2.win, 1, wx.EXPAND)

        combine2 = blocks.add_ff()
        c2f2 = blocks.complex_to_float()

        self.connect(src2, (combine2,0))
        self.connect(noise,c2f2,(combine2,1))
        self.connect(combine2, thr2,sink2)
    def __init__(self, noise_voltage, freq, timing):
        gr.hier_block2.__init__(self, "channel_model",
                                gr.io_signature(1, 1, gr.sizeof_gr_complex),
                                gr.io_signature(1, 1, gr.sizeof_gr_complex))


        timing_offset = filter.mmse_resampler_cc(0, timing)
        noise_adder = blocks.add_cc()
        noise = analog.noise_source_c(analog.GR_GAUSSIAN,
                                      noise_voltage, 0)
        freq_offset = analog.sig_source_c(1, analog.GR_SIN_WAVE,
                                          freq, 1.0, 0.0)
        mixer_offset = blocks.multiply_cc();

        self.connect(self, timing_offset)
        self.connect(timing_offset, (mixer_offset,0))
        self.connect(freq_offset, (mixer_offset,1))
        self.connect(mixer_offset, (noise_adder,1))
        self.connect(noise, (noise_adder,0))
        self.connect(noise_adder, self)
Beispiel #19
0
    def __init__(self,EbN0db,semente):
        gr.top_block.__init__(self)
        


        ##################################################
        # Variables
        ##################################################
        self.value = value = 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
        self.symbol = symbol = (0.33333+1/3j),(0.33333+1j),1+1/3j,1+1j,-0.33333+1/3j,-1+1/3j,-0.33333+1j,-1+1j,-0.33333-1/3j,-0.33333-1j,-1-1/3j,-1-1j,0.33333-1/3j,1-1/3j,0.33333-1j,1-1j
        self.samp_rate = samp_rate = 200000
        self.constellation = constellation = digital.constellation_calcdist((symbol), (value), 4, 1).base()

        ##################################################
        # Blocks
        ##################################################
        self.vectorSink = blocks.vector_sink_f(1)
        self.digital_constellation_decoder_cb_0 = digital.constellation_decoder_cb(constellation)
        self.digital_chunks_to_symbols_xx_0 = digital.chunks_to_symbols_bc((symbol), 1)
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_char*1, samp_rate,True)
        self.blocks_add_xx_0 = blocks.add_vcc(1)
        self.blks2_error_rate_0 = grc_blks2.error_rate(
        	type='BER',
        	win_size=10000000,
        	bits_per_symbol=int(math.log(len(symbol))/math.log(2)),
        )
        self.analog_random_source_x_0 = blocks.vector_source_b(map(int, numpy.random.randint(0, 16, 10000000)), False)
        self.analog_noise_source_x_0 =analog.noise_source_c(analog.GR_GAUSSIAN,self.EbN0_to_noise_voltage(EbN0db,int(4)),semente)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_noise_source_x_0, 0), (self.blocks_add_xx_0, 1))    
        self.connect((self.analog_random_source_x_0, 0), (self.blocks_throttle_0, 0))    
        self.connect((self.blks2_error_rate_0, 0), (self.vectorSink, 0))    
        self.connect((self.blocks_add_xx_0, 0), (self.digital_constellation_decoder_cb_0, 0))    
        self.connect((self.blocks_throttle_0, 0), (self.blks2_error_rate_0, 0))    
        self.connect((self.blocks_throttle_0, 0), (self.digital_chunks_to_symbols_xx_0, 0))    
        self.connect((self.digital_chunks_to_symbols_xx_0, 0), (self.blocks_add_xx_0, 0))    
        self.connect((self.digital_constellation_decoder_cb_0, 0), (self.blks2_error_rate_0, 1))      
    def __init__(self):
        gr.top_block.__init__(self, "BER AWGN Test OQPSK")

        ##################################################
        # Variables
        ##################################################
        self.snr = snr = 0
        self.c = c = ieee802_15_4.css_phy(slow_rate=True, phy_packetsize_bytes=127)

        ##################################################
        # Blocks
        ##################################################
        self.ieee802_15_4_oqpsk_phy_nosync_0 = ieee802_15_4_oqpsk_phy_nosync(
            payload_len=c.phy_packetsize_bytes,
        )
        self.ieee802_15_4_make_pair_with_blob_0 = ieee802_15_4.make_pair_with_blob(np.random.randint(0,256,(c.phy_packetsize_bytes,)))
        self.foo_periodic_msg_source_0 = foo.periodic_msg_source(pmt.cons(pmt.PMT_NIL, pmt.string_to_symbol("trigger")), 1, 5, True, False)
        # self.msg_trigger = blocks.message_strobe(pmt.cons(pmt.intern("trigger"), pmt.intern("dummy")), 1000)
        self.comp_bits = ieee802_15_4.compare_blobs(packet_error_mode=False)
        self.blocks_add_xx_0_0 = blocks.add_vcc(1)
        self.analog_noise_source_x_0_0 = analog.noise_source_c(analog.GR_GAUSSIAN, 10**(-snr/10), 0)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_noise_source_x_0_0, 0), (self.blocks_add_xx_0_0, 1))
        self.connect((self.blocks_add_xx_0_0, 0), (self.ieee802_15_4_oqpsk_phy_nosync_0, 0))
        self.connect((self.ieee802_15_4_oqpsk_phy_nosync_0, 0), (self.blocks_add_xx_0_0, 0))

        ##################################################
        # Asynch Message Connections
        ##################################################
        self.msg_connect(self.ieee802_15_4_make_pair_with_blob_0, "out", self.ieee802_15_4_oqpsk_phy_nosync_0, "txin")
        self.msg_connect(self.foo_periodic_msg_source_0, "out", self.ieee802_15_4_make_pair_with_blob_0, "in")
        # self.msg_connect(self.msg_trigger, "strobe", self.ieee802_15_4_make_pair_with_blob_0, "in")
        self.msg_connect(self.ieee802_15_4_make_pair_with_blob_0, "out", self.comp_bits, "ref")
        self.msg_connect(self.ieee802_15_4_oqpsk_phy_nosync_0, "rxout", self.comp_bits, "test")
        self.msg_connect(self.ieee802_15_4_oqpsk_phy_nosync_0, "rxout", self.ieee802_15_4_make_pair_with_blob_0, "in")
Beispiel #21
0
 def __init__(self, n_sinusoids = 1, SNR = 10, samp_rate = 32e3, nsamples = 2048):
     gr.hier_block2.__init__(self, "ESPRIT/MUSIC signal generator",
                             gr.io_signature(0, 0, gr.sizeof_float),
                             gr.io_signature(1, 1, gr.sizeof_gr_complex))
     sigampl = 10.0**(SNR/10.0) # noise power is 1
     self.srcs = list()
     self.n_sinusoids = n_sinusoids
     self.samp_rate = samp_rate
     # create our signals ...
     for s in range(n_sinusoids):
         self.srcs.append(analog.sig_source_c(samp_rate,
             analog.GR_SIN_WAVE, 1000 * s + 2000,
             numpy.sqrt(sigampl/n_sinusoids)))
     seed = ord(os.urandom(1))
     self.noise = analog.noise_source_c(analog.GR_GAUSSIAN, 1, seed)
     self.add = blocks.add_cc()
     self.head = blocks.head(gr.sizeof_gr_complex, nsamples)
     self.sink = blocks.vector_sink_f(vlen=n_sinusoids)
     # wire it up ...
     for s in range(n_sinusoids):
         self.connect(self.srcs[s], (self.add, s))
     # Additive noise
     self.connect(self.noise, (self.add, n_sinusoids))
     self.connect(self.add, self.head, self)
Beispiel #22
0
	def __init__(self):
		grc_wxgui.top_block_gui.__init__(self, title="OFDM Rx")
		_icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
		self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

		##################################################
		# Variables
		##################################################
		self.occupied_carriers = occupied_carriers = (range(-26, -21) + range(-20, -7) + range(-6, 0) + range(1, 7) + range(8, 21) + range(22, 27),)
		self.length_tag_name = length_tag_name = "frame_len"
		self.sync_word2 = sync_word2 = (0, 0, 0, 0, 0, 1, 1, -1.0, -1, 1.0, 1, 1.0, -1, -1.0, -1, 1.0, 1, -1.0, 1, 1.0, 1, -1.0, -1, -1.0, -1, 1.0, -1, 1.0, -1, 1.0, 1, -1.0, 0, 1.0, 1, -1.0, 1, 1.0, -1, -1.0, 1, -1.0, -1, -1.0, 1, 1.0, 1, -1.0, 1, 1.0, -1, 1.0, -1, -1.0, -1, 1.0, 1, -1.0, 0, 0, 0, 0, 0, 0)
		self.sync_word1 = sync_word1 = (0, 0, 0, 0, 0, 0, 0, -1.0, 0, 1.0, 0, 1.0, 0, -1.0, 0, 1.0, 0, -1.0, 0, 1.0, 0, -1.0, 0, -1.0, 0, 1.0, 0, 1.0, 0, 1.0, 0, -1.0, 0, 1.0, 0, -1.0, 0, 1.0, 0, -1.0, 0, -1.0, 0, -1.0, 0, 1.0, 0, -1.0, 0, 1.0, 0, 1.0, 0, -1.0, 0, 1.0, 0, -1.0, 0, 0, 0, 0, 0, 0)
		self.samp_rate = samp_rate = 3200000
		self.pilot_symbols = pilot_symbols = ((1, 1, 1, -1,),)
		self.pilot_carriers = pilot_carriers = ((-21, -7, 7, 21,),)
		self.payload_mod = payload_mod = digital.constellation_qpsk()
		self.header_mod = header_mod = digital.constellation_bpsk()
		self.header_formatter = header_formatter = digital.packet_header_ofdm(occupied_carriers, 1, length_tag_name)
		self.fft_len = fft_len = 64

		##################################################
		# Blocks
		##################################################
		self.gr_delay_0 = gr.delay(gr.sizeof_gr_complex*1, fft_len+fft_len/4)
		self.fft_vxx_0_0 = fft.fft_vcc(fft_len, True, (), True, 1)
		self.fft_vxx_0 = fft.fft_vcc(fft_len, True, (), True, 1)
		self.digital_packet_headerparser_b_0 = digital.packet_headerparser_b(header_formatter.formatter())
		self.digital_ofdm_sync_sc_cfb_0 = digital.ofdm_sync_sc_cfb(fft_len, fft_len/4, False)
		self.digital_ofdm_serializer_vcc_1 = digital.ofdm_serializer_vcc(fft_len, occupied_carriers, "length_tag_key", "", 1, "", True)
		self.digital_ofdm_serializer_vcc_0 = digital.ofdm_serializer_vcc(fft_len, occupied_carriers, length_tag_name, "", 0, "", True)
		self.digital_ofdm_frame_equalizer_vcvc_0_0 = digital.ofdm_frame_equalizer_vcvc(digital.ofdm_equalizer_simpledfe(fft_len, header_mod.base(), occupied_carriers, pilot_carriers, pilot_symbols).base(), fft_len/4, length_tag_name, True, 0)
		self.digital_ofdm_frame_equalizer_vcvc_0 = digital.ofdm_frame_equalizer_vcvc(digital.ofdm_equalizer_simpledfe(fft_len, header_mod.base(), occupied_carriers, pilot_carriers, pilot_symbols, 2).base(), fft_len/4, "length_tag_key", False, 0)
		self.digital_ofdm_chanest_vcvc_0 = digital.ofdm_chanest_vcvc((sync_word1), (sync_word2), 2, 0, -1, False)
		self.digital_header_payload_demux_0 = digital.header_payload_demux(3, fft_len, fft_len/4, length_tag_name, "", True, gr.sizeof_gr_complex)
		self.digital_constellation_decoder_cb_0_0 = digital.constellation_decoder_cb(header_mod.base())
		self.digital_constellation_decoder_cb_0 = digital.constellation_decoder_cb(payload_mod.base())
		self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate)
		self.blocks_tag_debug_0 = blocks.tag_debug(gr.sizeof_char*1, "Rx Packets")
		self.blocks_multiply_xx_0 = blocks.multiply_vcc(1)
		self.analog_noise_source_x_0 = analog.noise_source_c(analog.GR_GAUSSIAN, 1, 0)
		self.analog_frequency_modulator_fc_0 = analog.frequency_modulator_fc(-2.0/fft_len)

		##################################################
		# Connections
		##################################################
		self.connect((self.digital_ofdm_frame_equalizer_vcvc_0_0, 0), (self.digital_ofdm_serializer_vcc_0, 0))
		self.connect((self.digital_header_payload_demux_0, 0), (self.fft_vxx_0, 0))
		self.connect((self.fft_vxx_0, 0), (self.digital_ofdm_chanest_vcvc_0, 0))
		self.connect((self.digital_ofdm_chanest_vcvc_0, 0), (self.digital_ofdm_frame_equalizer_vcvc_0_0, 0))
		self.connect((self.digital_constellation_decoder_cb_0_0, 0), (self.digital_packet_headerparser_b_0, 0))
		self.connect((self.digital_ofdm_serializer_vcc_0, 0), (self.digital_constellation_decoder_cb_0_0, 0))
		self.connect((self.digital_constellation_decoder_cb_0, 0), (self.blocks_tag_debug_0, 0))
		self.connect((self.fft_vxx_0_0, 0), (self.digital_ofdm_frame_equalizer_vcvc_0, 0))
		self.connect((self.digital_ofdm_frame_equalizer_vcvc_0, 0), (self.digital_ofdm_serializer_vcc_1, 0))
		self.connect((self.digital_header_payload_demux_0, 1), (self.fft_vxx_0_0, 0))
		self.connect((self.digital_ofdm_serializer_vcc_1, 0), (self.digital_constellation_decoder_cb_0, 0))
		self.connect((self.blocks_throttle_0, 0), (self.digital_ofdm_sync_sc_cfb_0, 0))
		self.connect((self.blocks_throttle_0, 0), (self.gr_delay_0, 0))
		self.connect((self.analog_noise_source_x_0, 0), (self.blocks_throttle_0, 0))
		self.connect((self.analog_frequency_modulator_fc_0, 0), (self.blocks_multiply_xx_0, 0))
		self.connect((self.digital_ofdm_sync_sc_cfb_0, 0), (self.analog_frequency_modulator_fc_0, 0))
		self.connect((self.gr_delay_0, 0), (self.blocks_multiply_xx_0, 1))
		self.connect((self.digital_ofdm_sync_sc_cfb_0, 1), (self.digital_header_payload_demux_0, 1))
		self.connect((self.blocks_multiply_xx_0, 0), (self.digital_header_payload_demux_0, 0))

		##################################################
		# Asynch Message Connections
		##################################################
		self.msg_connect(self.digital_packet_headerparser_b_0, "header_data", self.digital_header_payload_demux_0, "header_data")
Beispiel #23
0
def run_test(seed,blocksize):
        tb = gr.top_block()

	##################################################
	# Variables
	##################################################
	M = 2
	K = 1
	P = 2
	h = (1.0*K)/P
	L = 3
	Q = 4
        frac = 0.99
        f = trellis.fsm(P,M,L)

        # CPFSK signals
        #p = numpy.ones(Q)/(2.0)
        #q = numpy.cumsum(p)/(1.0*Q)

        # GMSK signals
        BT=0.3;
        tt=numpy.arange(0,L*Q)/(1.0*Q)-L/2.0;
        #print tt
        p=(0.5*scipy.special.erfc(2*math.pi*BT*(tt-0.5)/math.sqrt(math.log(2.0))/math.sqrt(2.0))-0.5*scipy.special.erfc(2*math.pi*BT*(tt+0.5)/math.sqrt(math.log(2.0))/math.sqrt(2.0)))/2.0;
        p=p/sum(p)*Q/2.0;
        #print p
        q=numpy.cumsum(p)/Q;
        q=q/q[-1]/2.0;
        #print q

        (f0T,SS,S,F,Sf,Ff,N) = fsm_utils.make_cpm_signals(K,P,M,L,q,frac)
        #print N
        #print Ff
        Ffa = numpy.insert(Ff,Q,numpy.zeros(N),axis=0)
        #print Ffa
        MF = numpy.fliplr(numpy.transpose(Ffa))
        #print MF
        E = numpy.sum(numpy.abs(Sf)**2,axis=0)
        Es = numpy.sum(E)/f.O()
        #print Es

        constellation = numpy.reshape(numpy.transpose(Sf),N*f.O())
        #print Ff
        #print Sf
        #print constellation
        #print numpy.max(numpy.abs(SS - numpy.dot(Ff , Sf)))

	EsN0_db = 10.0
        N0 =  Es * 10.0**(-(1.0*EsN0_db)/10.0)
        #N0 = 0.0
        #print N0
        head = 4
        tail = 4
        numpy.random.seed(seed*666)
        data = numpy.random.randint(0, M, head+blocksize+tail+1)
        #data = numpy.zeros(blocksize+1+head+tail,'int')
        for i in range(head):
            data[i]=0
        for i in range(tail+1):
            data[-i]=0



	##################################################
	# Blocks
	##################################################
	random_source_x_0 = blocks.vector_source_b(data.tolist(), False)
	digital_chunks_to_symbols_xx_0 = digital.chunks_to_symbols_bf((-1, 1), 1)
	filter_interp_fir_filter_xxx_0 = filter.interp_fir_filter_fff(Q, p)
	analog_frequency_modulator_fc_0 = analog.frequency_modulator_fc(2*math.pi*h*(1.0/Q))

	blocks_add_vxx_0 = blocks.add_vcc(1)
	analog_noise_source_x_0 = analog.noise_source_c(analog.GR_GAUSSIAN, (N0/2.0)**0.5, -long(seed))

	blocks_multiply_vxx_0 = blocks.multiply_vcc(1)
	analog_sig_source_x_0 = analog.sig_source_c(Q, analog.GR_COS_WAVE, -f0T, 1, 0)
        # only works for N=2, do it manually for N>2...
	filter_fir_filter_xxx_0_0 = filter.fir_filter_ccc(Q, MF[0].conjugate())
	filter_fir_filter_xxx_0_0_0 = filter.fir_filter_ccc(Q, MF[1].conjugate())
	blocks_streams_to_stream_0 = blocks.streams_to_stream(gr.sizeof_gr_complex*1, int(N))
	blocks_skiphead_0 = blocks.skiphead(gr.sizeof_gr_complex*1, int(N*(1+0)))
	viterbi = trellis.viterbi_combined_cb(f, head+blocksize+tail, 0, -1, int(N),
					      constellation, digital.TRELLIS_EUCLIDEAN)

        blocks_vector_sink_x_0 = blocks.vector_sink_b()

	##################################################
	# Connections
	##################################################
	tb.connect((random_source_x_0, 0), (digital_chunks_to_symbols_xx_0, 0))
	tb.connect((digital_chunks_to_symbols_xx_0, 0), (filter_interp_fir_filter_xxx_0, 0))
	tb.connect((filter_interp_fir_filter_xxx_0, 0), (analog_frequency_modulator_fc_0, 0))
	tb.connect((analog_frequency_modulator_fc_0, 0), (blocks_add_vxx_0, 0))
	tb.connect((analog_noise_source_x_0, 0), (blocks_add_vxx_0, 1))
	tb.connect((blocks_add_vxx_0, 0), (blocks_multiply_vxx_0, 0))
	tb.connect((analog_sig_source_x_0, 0), (blocks_multiply_vxx_0, 1))
	tb.connect((blocks_multiply_vxx_0, 0), (filter_fir_filter_xxx_0_0, 0))
	tb.connect((blocks_multiply_vxx_0, 0), (filter_fir_filter_xxx_0_0_0, 0))
	tb.connect((filter_fir_filter_xxx_0_0, 0), (blocks_streams_to_stream_0, 0))
	tb.connect((filter_fir_filter_xxx_0_0_0, 0), (blocks_streams_to_stream_0, 1))
	tb.connect((blocks_streams_to_stream_0, 0), (blocks_skiphead_0, 0))
	tb.connect((blocks_skiphead_0, 0), (viterbi, 0))
	tb.connect((viterbi, 0), (blocks_vector_sink_x_0, 0))


        tb.run()
        dataest = blocks_vector_sink_x_0.data()
        #print data
        #print numpy.array(dataest)
        perr = 0
        err = 0
        for i in range(blocksize):
          if data[head+i] != dataest[head+i]:
            #print i
            err += 1
        if err != 0 :
          perr = 1
        return (err,perr)
    def __init__(self, tx_gain=0, index=0):
        gr.top_block.__init__(self, "uhd_b200_tx_rand_freq_hop")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("uhd_b200_tx_rand_freq_hop")
        try:
             self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc'))
        except:
             pass
        self.top_scroll_layout = Qt.QVBoxLayout()
        self.setLayout(self.top_scroll_layout)
        self.top_scroll = Qt.QScrollArea()
        self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame)
        self.top_scroll_layout.addWidget(self.top_scroll)
        self.top_scroll.setWidgetResizable(True)
        self.top_widget = Qt.QWidget()
        self.top_scroll.setWidget(self.top_widget)
        self.top_layout = Qt.QVBoxLayout(self.top_widget)
        self.top_grid_layout = Qt.QGridLayout()
        self.top_layout.addLayout(self.top_grid_layout)

        self.settings = Qt.QSettings("GNU Radio", "uhd_b200_tx_rand_freq_hop")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())


        ##################################################
        # Parameters
        ##################################################
        self.tx_gain = tx_gain
        self.index = index

        ##################################################
        # Variables
        ##################################################
        self.freq_list = freq_list = [902e6,928e6,910e6,906e6,912e6,922e6,923e6,907e6,918e6,909e6,911e6,916e6]
        self.freq_index = freq_index = index
        self.variable_qtgui_label = variable_qtgui_label = freq_list[freq_index]
        self.samp_rate = samp_rate = 4e6

        ##################################################
        # Blocks
        ##################################################
        self.probe_index = blocks.probe_signal_i()
        def _freq_index_probe():
            while True:
                val = self.probe_index.level()
                try:
                    self.set_freq_index(val)
                except AttributeError:
                    pass
                time.sleep(1.0 / (20))
        _freq_index_thread = threading.Thread(target=_freq_index_probe)
        _freq_index_thread.daemon = True
        _freq_index_thread.start()
        self._variable_qtgui_label_tool_bar = Qt.QToolBar(self)
        
        if None:
          self._variable_qtgui_label_formatter = None
        else:
          self._variable_qtgui_label_formatter = lambda x: x
        
        self._variable_qtgui_label_tool_bar.addWidget(Qt.QLabel("Center_Frequency"+": "))
        self._variable_qtgui_label_label = Qt.QLabel(str(self._variable_qtgui_label_formatter(self.variable_qtgui_label)))
        self._variable_qtgui_label_tool_bar.addWidget(self._variable_qtgui_label_label)
        self.top_layout.addWidget(self._variable_qtgui_label_tool_bar)
          
        self.uhd_usrp_sink_0 = uhd.usrp_sink(
        	",".join(("", "")),
        	uhd.stream_args(
        		cpu_format="fc32",
        		channels=range(1),
        	),
        )
        self.uhd_usrp_sink_0.set_samp_rate(samp_rate)
        self.uhd_usrp_sink_0.set_center_freq(freq_list[freq_index], 0)
        self.uhd_usrp_sink_0.set_gain(tx_gain, 0)
        self.uhd_usrp_sink_0.set_antenna("TX/RX", 0)
        self.analog_sig_source_x_1 = analog.sig_source_i(samp_rate, analog.GR_SAW_WAVE, 10, len(freq_list), 0)
        self.analog_noise_source_x_0 = analog.noise_source_c(analog.GR_GAUSSIAN, 1, 0)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_noise_source_x_0, 0), (self.uhd_usrp_sink_0, 0))    
        self.connect((self.analog_sig_source_x_1, 0), (self.probe_index, 0))    
Beispiel #25
0
 def set_waveform(self, type):
     self.vprint("Selecting waveform...")
     self.lock()
     self.disconnect_all()
     if type == analog.GR_SIN_WAVE or type == analog.GR_CONST_WAVE:
         self._src = analog.sig_source_c(self[SAMP_RATE_KEY],      # Sample rate
                                         type,                # Waveform type
                                         self[WAVEFORM_FREQ_KEY], # Waveform frequency
                                         self[AMPLITUDE_KEY],     # Waveform amplitude
                                         self[WAVEFORM_OFFSET_KEY])        # Waveform offset
     elif type == analog.GR_GAUSSIAN or type == analog.GR_UNIFORM:
         self._src = analog.noise_source_c(type, self[AMPLITUDE_KEY])
     elif type == "2tone":
         self._src1 = analog.sig_source_c(self[SAMP_RATE_KEY],
                                          analog.GR_SIN_WAVE,
                                          self[WAVEFORM_FREQ_KEY],
                                          self[AMPLITUDE_KEY]/2.0,
                                          0)
         if self[WAVEFORM2_FREQ_KEY] is None:
             self[WAVEFORM2_FREQ_KEY] = -self[WAVEFORM_FREQ_KEY]
         self._src2 = analog.sig_source_c(self[SAMP_RATE_KEY],
                                          analog.GR_SIN_WAVE,
                                          self[WAVEFORM2_FREQ_KEY],
                                          self[AMPLITUDE_KEY]/2.0,
                                          0)
         self._src = blocks.add_cc()
         self.connect(self._src1,(self._src,0))
         self.connect(self._src2,(self._src,1))
     elif type == "sweep":
         # rf freq is center frequency
         # waveform_freq is total swept width
         # waveform2_freq is sweep rate
         # will sweep from (rf_freq-waveform_freq/2) to (rf_freq+waveform_freq/2)
         if self[WAVEFORM2_FREQ_KEY] is None:
             self[WAVEFORM2_FREQ_KEY] = 0.1
         self._src1 = analog.sig_source_f(self[SAMP_RATE_KEY],
                                          analog.GR_TRI_WAVE,
                                          self[WAVEFORM2_FREQ_KEY],
                                          1.0,
                                          -0.5)
         self._src2 = analog.frequency_modulator_fc(self[WAVEFORM_FREQ_KEY]*2*math.pi/self[SAMP_RATE_KEY])
         self._src = blocks.multiply_const_cc(self[AMPLITUDE_KEY])
         self.connect(self._src1, self._src2, self._src)
     else:
         raise RuntimeError("[UHD-SIGGEN] Unknown waveform type")
     for c in xrange(len(self.channels)):
         self.connect(self._src, (self.usrp, c))
     if self.extra_sink is not None:
         self.connect(self._src, self.extra_sink)
     self.unlock()
     self.vprint("Set baseband modulation to:", waveforms[type])
     if type == analog.GR_SIN_WAVE:
         self.vprint("Modulation frequency: %sHz" % (n2s(self[WAVEFORM_FREQ_KEY]),))
         self.vprint("Initial phase:", self[WAVEFORM_OFFSET_KEY])
     elif type == "2tone":
         self.vprint("Tone 1: %sHz" % (n2s(self[WAVEFORM_FREQ_KEY]),))
         self.vprint("Tone 2: %sHz" % (n2s(self[WAVEFORM2_FREQ_KEY]),))
     elif type == "sweep":
         self.vprint("Sweeping across %sHz to %sHz" % (n2s(-self[WAVEFORM_FREQ_KEY]/2.0),n2s(self[WAVEFORM_FREQ_KEY]/2.0)))
         self.vprint("Sweep rate: %sHz" % (n2s(self[WAVEFORM2_FREQ_KEY]),))
     self.vprint("TX amplitude:", self[AMPLITUDE_KEY])
Beispiel #26
0
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="Top Block")
        _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
        self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 88200
        self.noiseAmp = noiseAmp = 0
        self.consMultiply = consMultiply = 1.333

        ##################################################
        # Blocks
        ##################################################
        _noiseAmp_sizer = wx.BoxSizer(wx.VERTICAL)
        self._noiseAmp_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_noiseAmp_sizer,
        	value=self.noiseAmp,
        	callback=self.set_noiseAmp,
        	label='noiseAmp',
        	converter=forms.float_converter(),
        	proportion=0,
        )
        self._noiseAmp_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_noiseAmp_sizer,
        	value=self.noiseAmp,
        	callback=self.set_noiseAmp,
        	minimum=0,
        	maximum=2,
        	num_steps=1000,
        	style=wx.SL_HORIZONTAL,
        	cast=float,
        	proportion=1,
        )
        self.Add(_noiseAmp_sizer)
        self.n = self.n = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
        self.n.AddPage(grc_wxgui.Panel(self.n), "tab1")
        self.n.AddPage(grc_wxgui.Panel(self.n), "tab2")
        self.n.AddPage(grc_wxgui.Panel(self.n), "tab3")
        self.n.AddPage(grc_wxgui.Panel(self.n), "tab4")
        self.Add(self.n)
        _consMultiply_sizer = wx.BoxSizer(wx.VERTICAL)
        self._consMultiply_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_consMultiply_sizer,
        	value=self.consMultiply,
        	callback=self.set_consMultiply,
        	label='consMultiply',
        	converter=forms.float_converter(),
        	proportion=0,
        )
        self._consMultiply_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_consMultiply_sizer,
        	value=self.consMultiply,
        	callback=self.set_consMultiply,
        	minimum=0,
        	maximum=3,
        	num_steps=1000,
        	style=wx.SL_HORIZONTAL,
        	cast=float,
        	proportion=1,
        )
        self.Add(_consMultiply_sizer)
        self.wxgui_fftsink2_0_2 = fftsink2.fft_sink_c(
        	self.n.GetPage(2).GetWin(),
        	baseband_freq=0,
        	y_per_div=10,
        	y_divs=10,
        	ref_level=0,
        	ref_scale=2.0,
        	sample_rate=samp_rate,
        	fft_size=1024,
        	fft_rate=15,
        	average=False,
        	avg_alpha=None,
        	title="FFT After AWGN Addition",
        	peak_hold=False,
        )
        self.n.GetPage(2).Add(self.wxgui_fftsink2_0_2.win)
        self.wxgui_fftsink2_0_1 = fftsink2.fft_sink_c(
        	self.n.GetPage(1).GetWin(),
        	baseband_freq=0,
        	y_per_div=10,
        	y_divs=10,
        	ref_level=0,
        	ref_scale=2.0,
        	sample_rate=samp_rate,
        	fft_size=1024,
        	fft_rate=15,
        	average=False,
        	avg_alpha=None,
        	title="FFT AFter WSBM Transmit",
        	peak_hold=False,
        )
        self.n.GetPage(1).Add(self.wxgui_fftsink2_0_1.win)
        self.wxgui_fftsink2_0_0 = fftsink2.fft_sink_f(
        	self.n.GetPage(0).GetWin(),
        	baseband_freq=0,
        	y_per_div=10,
        	y_divs=10,
        	ref_level=0,
        	ref_scale=2.0,
        	sample_rate=samp_rate,
        	fft_size=1024,
        	fft_rate=15,
        	average=False,
        	avg_alpha=None,
        	title="FFT of File Source",
        	peak_hold=False,
        )
        self.n.GetPage(0).Add(self.wxgui_fftsink2_0_0.win)
        self.wxgui_fftsink2_0 = fftsink2.fft_sink_f(
        	self.n.GetPage(3).GetWin(),
        	baseband_freq=0,
        	y_per_div=10,
        	y_divs=10,
        	ref_level=0,
        	ref_scale=2.0,
        	sample_rate=samp_rate,
        	fft_size=1024,
        	fft_rate=15,
        	average=False,
        	avg_alpha=None,
        	title="FFT After WSBM Receive (We listen to this)",
        	peak_hold=False,
        )
        self.n.GetPage(3).Add(self.wxgui_fftsink2_0.win)
        self.blocks_wavfile_source_0 = blocks.wavfile_source("/home/students/btech/b13236/EE304P/Lab_8/zeno_lp.wav", True)
        self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff((consMultiply, ))
        self.blocks_add_xx_0 = blocks.add_vcc(1)
        self.audio_sink_0 = audio.sink(44100, "", True)
        self.analog_wfm_tx_0 = analog.wfm_tx(
        	audio_rate=44100,
        	quad_rate=88200,
        	tau=75e-6,
        	max_dev=75e3,
        )
        self.analog_wfm_rcv_0 = analog.wfm_rcv(
        	quad_rate=88200,
        	audio_decimation=2,
        )
        self.analog_noise_source_x_0 = analog.noise_source_c(analog.GR_GAUSSIAN, noiseAmp, 0)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_noise_source_x_0, 0), (self.blocks_add_xx_0, 0))
        self.connect((self.analog_wfm_rcv_0, 0), (self.blocks_multiply_const_vxx_0, 0))
        self.connect((self.analog_wfm_rcv_0, 0), (self.wxgui_fftsink2_0, 0))
        self.connect((self.analog_wfm_tx_0, 0), (self.blocks_add_xx_0, 1))
        self.connect((self.analog_wfm_tx_0, 0), (self.wxgui_fftsink2_0_1, 0))
        self.connect((self.blocks_add_xx_0, 0), (self.analog_wfm_rcv_0, 0))
        self.connect((self.blocks_add_xx_0, 0), (self.wxgui_fftsink2_0_2, 0))
        self.connect((self.blocks_multiply_const_vxx_0, 0), (self.audio_sink_0, 0))
        self.connect((self.blocks_wavfile_source_0, 0), (self.analog_wfm_tx_0, 0))
        self.connect((self.blocks_wavfile_source_0, 0), (self.wxgui_fftsink2_0_0, 0))
    def __init__(self, angle=0, samp_rate=1e6, threshold_dB=-70, rx_gain=0, samp_rate_sink=8000, tx_amp=10e-3, lowpass_cutoff_freq=1700, RF=2.49e9, fft_len=pow(2,20), speed_samp_rate=1, DC_filter_num_elements=4, highpass_cutoff_freq=0):
        grc_wxgui.top_block_gui.__init__(self, title="CW Doppler Radar Simulator Single Target")
        _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
        self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

        ##################################################
        # Parameters
        ##################################################
        self.angle = angle
        self.samp_rate = samp_rate
        self.threshold_dB = threshold_dB
        self.rx_gain = rx_gain
        self.samp_rate_sink = samp_rate_sink
        self.tx_amp = tx_amp
        self.lowpass_cutoff_freq = lowpass_cutoff_freq
        self.RF = RF
        self.fft_len = fft_len
        self.speed_samp_rate = speed_samp_rate
        self.DC_filter_num_elements = DC_filter_num_elements
        self.highpass_cutoff_freq = highpass_cutoff_freq

        ##################################################
        # Variables
        ##################################################
        self.target_speed = target_speed = 0
        self.target_direction = target_direction = 0
        self.tx_amp_tuner = tx_amp_tuner = tx_amp
        self.threshold_dB_tuner = threshold_dB_tuner = threshold_dB
        self.speed_textbox = speed_textbox = target_speed
        self.rx_gain_tuner = rx_gain_tuner = rx_gain
        self.lowpass_cutoff_freq_tuner = lowpass_cutoff_freq_tuner = lowpass_cutoff_freq
        self.highpass_cutoff_freq_tuner = highpass_cutoff_freq_tuner = highpass_cutoff_freq
        self.doppler_freq_sim_tuner = doppler_freq_sim_tuner = 100
        self.direction_textbox = direction_textbox = target_direction
        self.angle_tuner = angle_tuner = angle
        self.RF_tuner = RF_tuner = RF

        ##################################################
        # Blocks
        ##################################################
        _tx_amp_tuner_sizer = wx.BoxSizer(wx.VERTICAL)
        self._tx_amp_tuner_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_tx_amp_tuner_sizer,
        	value=self.tx_amp_tuner,
        	callback=self.set_tx_amp_tuner,
        	label="TX Signal Amp",
        	converter=forms.float_converter(),
        	proportion=0,
        )
        self._tx_amp_tuner_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_tx_amp_tuner_sizer,
        	value=self.tx_amp_tuner,
        	callback=self.set_tx_amp_tuner,
        	minimum=0,
        	maximum=100e-3,
        	num_steps=1000,
        	style=wx.SL_HORIZONTAL,
        	cast=float,
        	proportion=1,
        )
        self.GridAdd(_tx_amp_tuner_sizer, 0, 17, 1, 26)
        _threshold_dB_tuner_sizer = wx.BoxSizer(wx.VERTICAL)
        self._threshold_dB_tuner_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_threshold_dB_tuner_sizer,
        	value=self.threshold_dB_tuner,
        	callback=self.set_threshold_dB_tuner,
        	label="Detected Target Threshold (dB)",
        	converter=forms.float_converter(),
        	proportion=0,
        )
        self._threshold_dB_tuner_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_threshold_dB_tuner_sizer,
        	value=self.threshold_dB_tuner,
        	callback=self.set_threshold_dB_tuner,
        	minimum=-90,
        	maximum=-30,
        	num_steps=60,
        	style=wx.SL_HORIZONTAL,
        	cast=float,
        	proportion=1,
        )
        self.GridAdd(_threshold_dB_tuner_sizer, 2, 0, 1, 17)
        self.speed_probe = blocks.probe_signal_f()
        self.notebook = self.notebook = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
        self.notebook.AddPage(grc_wxgui.Panel(self.notebook), "FFT CW Doppler Radar Receiver")
        self.notebook.AddPage(grc_wxgui.Panel(self.notebook), "Frequency/Time CW Doppler Radar Receiver")
        self.notebook.AddPage(grc_wxgui.Panel(self.notebook), "FFT CW Doppler Radar Receiver Full Spectrum")
        self.GridAdd(self.notebook, 5, 0, 13, 75)
        _lowpass_cutoff_freq_tuner_sizer = wx.BoxSizer(wx.VERTICAL)
        self._lowpass_cutoff_freq_tuner_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_lowpass_cutoff_freq_tuner_sizer,
        	value=self.lowpass_cutoff_freq_tuner,
        	callback=self.set_lowpass_cutoff_freq_tuner,
        	label="Lowpass Cutoff Frequency (Hz)",
        	converter=forms.float_converter(),
        	proportion=0,
        )
        self._lowpass_cutoff_freq_tuner_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_lowpass_cutoff_freq_tuner_sizer,
        	value=self.lowpass_cutoff_freq_tuner,
        	callback=self.set_lowpass_cutoff_freq_tuner,
        	minimum=0,
        	maximum=3000,
        	num_steps=1000,
        	style=wx.SL_HORIZONTAL,
        	cast=float,
        	proportion=1,
        )
        self.GridAdd(_lowpass_cutoff_freq_tuner_sizer, 1, 43, 1, 32)
        _highpass_cutoff_freq_tuner_sizer = wx.BoxSizer(wx.VERTICAL)
        self._highpass_cutoff_freq_tuner_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_highpass_cutoff_freq_tuner_sizer,
        	value=self.highpass_cutoff_freq_tuner,
        	callback=self.set_highpass_cutoff_freq_tuner,
        	label="High-Pass Cutoff Frequency (Hz)",
        	converter=forms.float_converter(),
        	proportion=0,
        )
        self._highpass_cutoff_freq_tuner_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_highpass_cutoff_freq_tuner_sizer,
        	value=self.highpass_cutoff_freq_tuner,
        	callback=self.set_highpass_cutoff_freq_tuner,
        	minimum=0,
        	maximum=1600,
        	num_steps=1000,
        	style=wx.SL_HORIZONTAL,
        	cast=float,
        	proportion=1,
        )
        self.GridAdd(_highpass_cutoff_freq_tuner_sizer, 0, 43, 1, 32)
        _doppler_freq_sim_tuner_sizer = wx.BoxSizer(wx.VERTICAL)
        self._doppler_freq_sim_tuner_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_doppler_freq_sim_tuner_sizer,
        	value=self.doppler_freq_sim_tuner,
        	callback=self.set_doppler_freq_sim_tuner,
        	label="Doppler Frequency Simulator (Hz)",
        	converter=forms.float_converter(),
        	proportion=0,
        )
        self._doppler_freq_sim_tuner_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_doppler_freq_sim_tuner_sizer,
        	value=self.doppler_freq_sim_tuner,
        	callback=self.set_doppler_freq_sim_tuner,
        	minimum=-2000,
        	maximum=2000,
        	num_steps=1000,
        	style=wx.SL_HORIZONTAL,
        	cast=float,
        	proportion=1,
        )
        self.GridAdd(_doppler_freq_sim_tuner_sizer, 2, 17, 1, 58)
        self.direction_probe = blocks.probe_signal_i()
        _angle_tuner_sizer = wx.BoxSizer(wx.VERTICAL)
        self._angle_tuner_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_angle_tuner_sizer,
        	value=self.angle_tuner,
        	callback=self.set_angle_tuner,
        	label="Angle of Approach of the Target (Deg)",
        	converter=forms.float_converter(),
        	proportion=0,
        )
        self._angle_tuner_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_angle_tuner_sizer,
        	value=self.angle_tuner,
        	callback=self.set_angle_tuner,
        	minimum=0,
        	maximum=89,
        	num_steps=890,
        	style=wx.SL_HORIZONTAL,
        	cast=float,
        	proportion=1,
        )
        self.GridAdd(_angle_tuner_sizer, 1, 17, 1, 26)
        _RF_tuner_sizer = wx.BoxSizer(wx.VERTICAL)
        self._RF_tuner_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_RF_tuner_sizer,
        	value=self.RF_tuner,
        	callback=self.set_RF_tuner,
        	label="Radar Frequency (Hz)",
        	converter=forms.float_converter(),
        	proportion=0,
        )
        self._RF_tuner_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_RF_tuner_sizer,
        	value=self.RF_tuner,
        	callback=self.set_RF_tuner,
        	minimum=2.4e9,
        	maximum=2.5e9,
        	num_steps=1000,
        	style=wx.SL_HORIZONTAL,
        	cast=float,
        	proportion=1,
        )
        self.GridAdd(_RF_tuner_sizer, 1, 0, 1, 17)
        self.wxgui_waterfallsink2_0 = waterfallsink2.waterfall_sink_c(
        	self.notebook.GetPage(1).GetWin(),
        	baseband_freq=0,
        	dynamic_range=100,
        	ref_level=0,
        	ref_scale=2.0,
        	sample_rate=samp_rate_sink,
        	fft_size=1024,
        	fft_rate=15,
        	average=True,
        	avg_alpha=None,
        	title="Time/Frequency CW Doppler Radar",
        	win=window.blackmanharris,
        )
        self.notebook.GetPage(1).Add(self.wxgui_waterfallsink2_0.win)
        self.wxgui_fftsink2_full_spectrum = fftsink2.fft_sink_c(
        	self.notebook.GetPage(2).GetWin(),
        	baseband_freq=0,
        	y_per_div=10,
        	y_divs=10,
        	ref_level=0,
        	ref_scale=2.0,
        	sample_rate=samp_rate,
        	fft_size=4096,
        	fft_rate=15,
        	average=False,
        	avg_alpha=None,
        	title="FFT CW Doppler Radar Receiver Full Spectrum",
        	peak_hold=False,
        	win=window.blackmanharris,
        )
        self.notebook.GetPage(2).Add(self.wxgui_fftsink2_full_spectrum.win)
        self.wxgui_fftsink2_0 = fftsink2.fft_sink_c(
        	self.notebook.GetPage(0).GetWin(),
        	baseband_freq=0,
        	y_per_div=10,
        	y_divs=10,
        	ref_level=0,
        	ref_scale=2.0,
        	sample_rate=samp_rate_sink,
        	fft_size=1024,
        	fft_rate=15,
        	average=False,
        	avg_alpha=None,
        	title="FFT CW Doppler Radar Receiver ",
        	peak_hold=False,
        	win=window.blackmanharris,
        )
        self.notebook.GetPage(0).Add(self.wxgui_fftsink2_0.win)
        self.tx_signal = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, 0, 0.5, 0)
        def _target_speed_probe():
            while True:
                val = self.speed_probe.level()
                try:
                    self.set_target_speed(val)
                except AttributeError:
                    pass
                time.sleep(1.0 / (2))
        _target_speed_thread = threading.Thread(target=_target_speed_probe)
        _target_speed_thread.daemon = True
        _target_speed_thread.start()
        def _target_direction_probe():
            while True:
                val = self.direction_probe.level()
                try:
                    ##############################################
                    if val == 1: #if the value is 1 the target is approaching.
                        val = "Approaching"
                    elif val == 2: #if the value is 2 the target is receding.
                        val = "Receding"
                    elif val == 0: #if the value is 0 there is no target in sight.
                        val = "No Target Detected"
                    self.set_target_direction(val)
                    ###############################################
                except AttributeError:
                    pass
                time.sleep(1.0 / (2))
        _target_direction_thread = threading.Thread(target=_target_direction_probe)
        _target_direction_thread.daemon = True
        _target_direction_thread.start()
        self._speed_textbox_text_box = forms.text_box(
        	parent=self.GetWin(),
        	value=self.speed_textbox,
        	callback=self.set_speed_textbox,
        	label="Target Speed (Kph)",
        	converter=forms.float_converter(),
        )
        self.GridAdd(self._speed_textbox_text_box, 3, 0, 1, 17)
        self.rx_signal_0 = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, doppler_freq_sim_tuner, tx_amp_tuner, 0)
        _rx_gain_tuner_sizer = wx.BoxSizer(wx.VERTICAL)
        self._rx_gain_tuner_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_rx_gain_tuner_sizer,
        	value=self.rx_gain_tuner,
        	callback=self.set_rx_gain_tuner,
        	label="USRP RX Gain (dB)",
        	converter=forms.float_converter(),
        	proportion=0,
        )
        self._rx_gain_tuner_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_rx_gain_tuner_sizer,
        	value=self.rx_gain_tuner,
        	callback=self.set_rx_gain_tuner,
        	minimum=0,
        	maximum=70,
        	num_steps=70,
        	style=wx.SL_HORIZONTAL,
        	cast=float,
        	proportion=1,
        )
        self.GridAdd(_rx_gain_tuner_sizer, 0, 0, 1, 17)
        self.rational_resampler = filter.rational_resampler_ccc(
                interpolation=1,
                decimation=int(samp_rate/samp_rate_sink),
                taps=None,
                fractional_bw=None,
        )
        self.mixer = blocks.multiply_vcc(1)
        self.fft = fft.fft_vcc(fft_len, True, (window.blackmanharris(fft_len)), True, 1)
        self._direction_textbox_text_box = forms.text_box(
        	parent=self.GetWin(),
        	value=self.direction_textbox,
        	callback=self.set_direction_textbox,
        	label="Target Direction",
        	converter=forms.str_converter(),
        )
        self.GridAdd(self._direction_textbox_text_box, 4, 0, 1, 17)
        self.cwradar_vector_flip_ff = cwradar.vector_flip_ff(fft_len/2)
        self.cwradar_doppler_velocity_single_target_ff_0 = cwradar.doppler_velocity_single_target_ff(fft_len/2, samp_rate, RF_tuner, threshold_dB_tuner, angle_tuner, lowpass_cutoff_freq_tuner, highpass_cutoff_freq_tuner)
        self.blocks_vector_to_stream_0_0 = blocks.vector_to_stream(gr.sizeof_float*1, fft_len)
        self.blocks_vector_to_stream_0 = blocks.vector_to_stream(gr.sizeof_float*1, fft_len)
        self.blocks_throttle_0_1_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate,True)
        self.blocks_stream_to_vector_1_0 = blocks.stream_to_vector(gr.sizeof_float*1, fft_len/2)
        self.blocks_stream_to_vector_1 = blocks.stream_to_vector(gr.sizeof_float*1, fft_len/2)
        self.blocks_stream_to_vector_0 = blocks.stream_to_vector(gr.sizeof_gr_complex*1, fft_len)
        self.blocks_keep_m_in_n_0_0 = blocks.keep_m_in_n(gr.sizeof_float, fft_len/2, fft_len, fft_len/2)
        self.blocks_keep_m_in_n_0 = blocks.keep_m_in_n(gr.sizeof_float, fft_len/2, fft_len, 0)
        self.blocks_complex_to_mag = blocks.complex_to_mag(fft_len)
        self.blocks_add_xx_1 = blocks.add_vcc(1)
        self.blocks_add_xx_0 = blocks.add_vcc(1)
        self.awgn_channel_simulator = analog.noise_source_c(analog.GR_GAUSSIAN, 1e-3, 0)
        self.DC_filter_0 = blocks.multiply_const_vff(([0]*DC_filter_num_elements+[1]*((fft_len/2)-DC_filter_num_elements)))
        self.DC_filter = blocks.multiply_const_vff(([0]*DC_filter_num_elements+[1]*((fft_len/2)-DC_filter_num_elements)))

        ##################################################
        # Connections
        ##################################################
        self.connect((self.awgn_channel_simulator, 0), (self.blocks_add_xx_1, 0))
        self.connect((self.tx_signal, 0), (self.blocks_add_xx_1, 1))
        self.connect((self.rx_signal_0, 0), (self.blocks_add_xx_1, 2))
        self.connect((self.mixer, 0), (self.blocks_throttle_0_1_0, 0))
        self.connect((self.mixer, 0), (self.blocks_stream_to_vector_0, 0))
        self.connect((self.blocks_throttle_0_1_0, 0), (self.wxgui_fftsink2_full_spectrum, 0))
        self.connect((self.rational_resampler, 0), (self.wxgui_fftsink2_0, 0))
        self.connect((self.blocks_throttle_0_1_0, 0), (self.rational_resampler, 0))
        self.connect((self.rational_resampler, 0), (self.wxgui_waterfallsink2_0, 0))
        self.connect((self.blocks_add_xx_1, 0), (self.mixer, 1))
        self.connect((self.blocks_stream_to_vector_0, 0), (self.fft, 0))
        self.connect((self.fft, 0), (self.blocks_complex_to_mag, 0))
        self.connect((self.blocks_complex_to_mag, 0), (self.blocks_vector_to_stream_0, 0))
        self.connect((self.blocks_complex_to_mag, 0), (self.blocks_vector_to_stream_0_0, 0))
        self.connect((self.blocks_vector_to_stream_0_0, 0), (self.blocks_keep_m_in_n_0_0, 0))
        self.connect((self.blocks_keep_m_in_n_0, 0), (self.blocks_stream_to_vector_1, 0))
        self.connect((self.blocks_keep_m_in_n_0_0, 0), (self.blocks_stream_to_vector_1_0, 0))
        self.connect((self.blocks_vector_to_stream_0, 0), (self.blocks_keep_m_in_n_0, 0))
        self.connect((self.blocks_stream_to_vector_1_0, 0), (self.DC_filter_0, 0))
        self.connect((self.blocks_stream_to_vector_1, 0), (self.cwradar_vector_flip_ff, 0))
        self.connect((self.cwradar_vector_flip_ff, 0), (self.DC_filter, 0))
        self.connect((self.blocks_add_xx_0, 0), (self.mixer, 0))
        self.connect((self.tx_signal, 0), (self.blocks_add_xx_0, 1))
        self.connect((self.awgn_channel_simulator, 0), (self.blocks_add_xx_0, 0))
        self.connect((self.DC_filter_0, 0), (self.cwradar_doppler_velocity_single_target_ff_0, 1))
        self.connect((self.DC_filter, 0), (self.cwradar_doppler_velocity_single_target_ff_0, 0))
        self.connect((self.cwradar_doppler_velocity_single_target_ff_0, 1), (self.direction_probe, 0))
        self.connect((self.cwradar_doppler_velocity_single_target_ff_0, 0), (self.speed_probe, 0))
Beispiel #28
0
def main():
    N = 1000000
    fs = 8000

    freqs = [100, 200, 300, 400, 500]
    nchans = 7

    sigs = list()
    fmtx = list()
    for fi in freqs:
        s = analog.sig_source_f(fs, analog.GR_SIN_WAVE, fi, 1)
        fm = analog.nbfm_tx(fs, 4*fs, max_dev=10000, tau=75e-6, fh=0.925*(4*fs)/2.0)
        sigs.append(s)
        fmtx.append(fm)

    syntaps = filter.firdes.low_pass_2(len(freqs), fs, fs/float(nchans)/2, 100, 100)
    print "Synthesis Num. Taps = %d (taps per filter = %d)" % (len(syntaps),
                                                               len(syntaps)/nchans)
    chtaps = filter.firdes.low_pass_2(len(freqs), fs, fs/float(nchans)/2, 100, 100)
    print "Channelizer Num. Taps = %d (taps per filter = %d)" % (len(chtaps),
                                                                 len(chtaps)/nchans)
    filtbank = filter.pfb_synthesizer_ccf(nchans, syntaps)
    channelizer = filter.pfb.channelizer_ccf(nchans, chtaps)

    noise_level = 0.01
    head = blocks.head(gr.sizeof_gr_complex, N)
    noise = analog.noise_source_c(analog.GR_GAUSSIAN, noise_level)
    addnoise = blocks.add_cc()
    snk_synth = blocks.vector_sink_c()

    tb = gr.top_block()

    tb.connect(noise, (addnoise,0))
    tb.connect(filtbank, head, (addnoise, 1))
    tb.connect(addnoise, channelizer)
    tb.connect(addnoise, snk_synth)

    snk = list()
    for i,si in enumerate(sigs):
        tb.connect(si, fmtx[i], (filtbank, i))

    for i in xrange(nchans):
        snk.append(blocks.vector_sink_c())
        tb.connect((channelizer, i), snk[i])

    tb.run()

    if 1:
        channel = 1
        data = snk[channel].data()[1000:]

        f1 = pylab.figure(1)
        s1 = f1.add_subplot(1,1,1)
        s1.plot(data[10000:10200] )
        s1.set_title(("Output Signal from Channel %d" % channel))

        fftlen = 2048
        winfunc = scipy.blackman
        #winfunc = scipy.hamming

        f2 = pylab.figure(2)
        s2 = f2.add_subplot(1,1,1)
        s2.psd(data, NFFT=fftlen,
               Fs = nchans*fs,
               noverlap=fftlen/4,
               window = lambda d: d*winfunc(fftlen))
        s2.set_title(("Output PSD from Channel %d" % channel))

        f3 = pylab.figure(3)
        s3 = f3.add_subplot(1,1,1)
        s3.psd(snk_synth.data()[1000:], NFFT=fftlen,
               Fs = nchans*fs,
               noverlap=fftlen/4,
               window = lambda d: d*winfunc(fftlen))
        s3.set_title("Output of Synthesis Filter")

        pylab.show()
Beispiel #29
0
    def __init__(self, seed, samp_rate, noise_amp, modulation, delay, samples_to_receive, freq, rx_id):
        gr.hier_block2.__init__(self, "ModulatorBlock",
                       gr.io_signature(0, 0, 0),
                       gr.io_signature(1, 1, gr.sizeof_gr_complex))

        # Timing tag: This is preserved and updated:
        timing_tag = gr.tag_t()
        timing_tag.offset = 0
        timing_tag.key = pmt.string_to_symbol('rx_time')
        timing_tag.value = pmt.to_pmt((float(seed), 0.6))
        timing_tag.srcid = pmt.string_to_symbol(str('gr uhd usrp source1'))
        # Rx freq tags:
        #print "In source emulation (before tag)" 
        #print freq
        rx_freq_tag = gr.tag_t()
        rx_freq_tag.offset = 0
        rx_freq_tag.key = pmt.string_to_symbol('rx_freq')
        rx_freq_tag.value = pmt.from_double(freq)
        rx_freq_tag.srcid = pmt.string_to_symbol(str('gr uhd usrp source1'))
        # Samp_rate tags:
        rx_rate_tag = gr.tag_t()
        rx_rate_tag.offset = 0
        rx_rate_tag.key = pmt.string_to_symbol('rx_rate')
        rx_rate_tag.value = pmt.from_double(samp_rate)
        rx_rate_tag.srcid = pmt.string_to_symbol(str('gr uhd usrp source1'))

        add = blocks.add_vcc(1, )

        tag_debug = blocks.tag_debug(gr.sizeof_gr_complex*1, "", "")
        tag_debug.set_display(True)
    
        #if modulation == "bpsk":
        #    mod = digital.psk.psk_mod(
        #      constellation_points=2,
        #      mod_code="none",
        #      differential=True,
        #      samples_per_symbol=2,
        #      excess_bw=0.1,
        #      verbose=False,
        #      log=False,
        #      )
        #else:
        #    mod = grc_blks2.packet_mod_b(digital.ofdm_mod(
        #                    options=grc_blks2.options(
        #                            modulation="qpsk",
        #                            fft_length=4096,
        #                            occupied_tones=200,
        #                            cp_length=0,
        #                            pad_for_usrp=False,
        #                            log=None,
        #                            verbose=None,
        #                    ),
        #            ),
        #            payload_length=0,
        #    )
        #print "in source emulation(after_tag)"
        #print  pmt.to_double(rx_freq_tag.value)
        pulse_width = 4
        np.random.seed(seed=seed)
        
        tx_vector = np.reshape(np.matlib.repmat(np.random.randint(0,2,(5*samples_to_receive)/pulse_width)*2-1,pulse_width,1).T,[1,5*samples_to_receive])[0].tolist()
        # delay signal vector -> insert zeros at beginnig; nothing happens if signal has not reached the receiver:
        tx_vector_delayed = np.hstack((np.zeros(delay),tx_vector))
        #tx_vector_delayed = tx_vector_delayed[:600]
        self.vector_source = blocks.vector_source_c(tx_vector_delayed, False, 1, (timing_tag, rx_freq_tag, rx_rate_tag)) 
        #clip first 600 samples
        self.head = blocks.head(gr.sizeof_gr_complex*1, samples_to_receive + 300)
        # skiphead= blocks.skiphead(gr.sizeof_gr_complex*1,delay)
        throttle = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate,True)
        noise = analog.noise_source_c(analog.GR_GAUSSIAN, noise_amp, -seed)
        # connects
        #self.connect(vector_source, mod, (add,0))
        self.connect(self.vector_source, (add,0))
        self.connect(noise, (add,1))
        self.connect(add, throttle, self.head, self)
        self.connect(add, tag_debug)
        '''
Beispiel #30
0
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="Top Block")
        _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
        self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

        ##################################################
        # Variables
        ##################################################
        self.quad_rate = quad_rate = 640000
        self.audio_rate = audio_rate = 40000

        ##################################################
        # Blocks
        ##################################################
        self.n = self.n = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
        self.n.AddPage(grc_wxgui.Panel(self.n), "FM")
        self.n.AddPage(grc_wxgui.Panel(self.n), "FFT")
        self.Add(self.n)
        self.wxgui_scopesink2_0 = scopesink2.scope_sink_f(
        	self.n.GetPage(0).GetWin(),
        	title="Scope Plot",
        	sample_rate=audio_rate,
        	v_scale=0,
        	v_offset=0,
        	t_scale=0,
        	ac_couple=False,
        	xy_mode=False,
        	num_inputs=1,
        	trig_mode=wxgui.TRIG_MODE_AUTO,
        	y_axis_label="Counts",
        )
        self.n.GetPage(0).Add(self.wxgui_scopesink2_0.win)
        self.wxgui_fftsink2_0 = fftsink2.fft_sink_f(
        	self.n.GetPage(1).GetWin(),
        	baseband_freq=0,
        	y_per_div=10,
        	y_divs=10,
        	ref_level=0,
        	ref_scale=2.0,
        	sample_rate=audio_rate,
        	fft_size=1024,
        	fft_rate=15,
        	average=False,
        	avg_alpha=None,
        	title="FFT Plot",
        	peak_hold=False,
        )
        self.n.GetPage(1).Add(self.wxgui_fftsink2_0.win)
        self.rational_resampler_xxx_0 = filter.rational_resampler_fff(
                interpolation=16,
                decimation=1,
                taps=None,
                fractional_bw=None,
        )
        self.low_pass_filter_0 = filter.fir_filter_fff(16, firdes.low_pass(
        	1, quad_rate, 15000, 4000, firdes.WIN_HAMMING, 6.76))
        self.iir_filter_xxx_2 = filter.iir_filter_ffd(([1,0]), ([1,0.95]), True)
        self.iir_filter_xxx_1 = filter.iir_filter_ffd(([1,-0.95]), ([1,0]), True)
        self.iir_filter_xxx_0 = filter.iir_filter_ffd((25e-6, ), ([1,1]), True)
        self.dc_blocker_xx_0 = filter.dc_blocker_ff(32, True)
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_float*1, audio_rate,True)
        self.blocks_multiply_xx_1 = blocks.multiply_vcc(1)
        self.blocks_multiply_xx_0 = blocks.multiply_vcc(1)
        self.blocks_delay_0 = blocks.delay(gr.sizeof_gr_complex*1, 1)
        self.blocks_conjugate_cc_0 = blocks.conjugate_cc()
        self.blocks_complex_to_real_0 = blocks.complex_to_real(1)
        self.blocks_add_xx_1 = blocks.add_vcc(1)
        self.blocks_add_xx_0 = blocks.add_vff(1)
        self.analog_sig_source_x_2 = analog.sig_source_c(quad_rate, analog.GR_COS_WAVE, 100000, 1, 0)
        self.analog_sig_source_x_1 = analog.sig_source_f(audio_rate, analog.GR_COS_WAVE, 1100, 0.5, 0)
        self.analog_sig_source_x_0 = analog.sig_source_f(audio_rate, analog.GR_COS_WAVE, 11000, .5, 0)
        self.analog_phase_modulator_fc_0 = analog.phase_modulator_fc(2*3.14*75000)
        self.analog_noise_source_x_0 = analog.noise_source_c(analog.GR_GAUSSIAN, .2, 0)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_noise_source_x_0, 0), (self.blocks_add_xx_1, 1))    
        self.connect((self.analog_phase_modulator_fc_0, 0), (self.blocks_multiply_xx_0, 0))    
        self.connect((self.analog_sig_source_x_0, 0), (self.blocks_add_xx_0, 1))    
        self.connect((self.analog_sig_source_x_1, 0), (self.blocks_add_xx_0, 0))    
        self.connect((self.analog_sig_source_x_2, 0), (self.blocks_multiply_xx_0, 1))    
        self.connect((self.blocks_add_xx_0, 0), (self.iir_filter_xxx_1, 0))    
        self.connect((self.blocks_add_xx_1, 0), (self.blocks_delay_0, 0))    
        self.connect((self.blocks_add_xx_1, 0), (self.blocks_multiply_xx_1, 0))    
        self.connect((self.blocks_complex_to_real_0, 0), (self.low_pass_filter_0, 0))    
        self.connect((self.blocks_conjugate_cc_0, 0), (self.blocks_multiply_xx_1, 1))    
        self.connect((self.blocks_delay_0, 0), (self.blocks_conjugate_cc_0, 0))    
        self.connect((self.blocks_multiply_xx_0, 0), (self.blocks_add_xx_1, 0))    
        self.connect((self.blocks_multiply_xx_1, 0), (self.blocks_complex_to_real_0, 0))    
        self.connect((self.blocks_throttle_0, 0), (self.wxgui_fftsink2_0, 0))    
        self.connect((self.blocks_throttle_0, 0), (self.wxgui_scopesink2_0, 0))    
        self.connect((self.dc_blocker_xx_0, 0), (self.iir_filter_xxx_2, 0))    
        self.connect((self.iir_filter_xxx_0, 0), (self.rational_resampler_xxx_0, 0))    
        self.connect((self.iir_filter_xxx_1, 0), (self.iir_filter_xxx_0, 0))    
        self.connect((self.iir_filter_xxx_2, 0), (self.blocks_throttle_0, 0))    
        self.connect((self.low_pass_filter_0, 0), (self.dc_blocker_xx_0, 0))    
        self.connect((self.rational_resampler_xxx_0, 0), (self.analog_phase_modulator_fc_0, 0))