def __init__(self, dBm, pfa, pfd, useless_bw, plot_histogram):
      gr.top_block.__init__(self)

      # Constants
      samp_rate = 2.4e6
      samples_per_band = 16
      tcme = 1.9528
      output_pfa = True
      debug_stats = False
      self.histogram = plot_histogram
      primary_user_location = 5
      mu = 0
      fft_size = 4096
      nframes_to_check = 1
      nframes_to_average = 1
      downconverter = 1

      src_data = self.generateRandomSignalSource(dBm, fft_size, mu, nframes_to_check*nframes_to_average)

		# Blocks
      src = gr.vector_source_c(src_data)
      s2v = gr.stream_to_vector(gr.sizeof_gr_complex, fft_size)
      fftb = fft.fft_vcc(fft_size, True, (window.blackmanharris(1024)), False, 1)
      self.ss = howto.spectrum_sensing_cf(samp_rate,fft_size,samples_per_band,pfd,pfa,tcme,output_pfa,debug_stats,primary_user_location,useless_bw,self.histogram,nframes_to_check,nframes_to_average,downconverter)
      self.sink = gr.vector_sink_f()

		# Connections
      self.connect(src, s2v, fftb, self.ss, self.sink)
Ejemplo n.º 2
0
   def __init__(self, dBm, pfa, pfd, nTrials):
      gr.top_block.__init__(self)

      # Constants
      samp_rate = 2.4e6
      fft_size = 4096
      samples_per_band = 16
      tcme = 1.9528
      output_pfa = True
      debug_stats = False
      histogram = False
      primary_user_location = 0
      useless_bw = 200000.0
      src_data = [0+0j]*fft_size*nTrials
      voltage = self.powerToAmplitude(dBm);

		# Blocks
      src = gr.vector_source_c(src_data)
      noise = gr.noise_source_c(gr.GR_GAUSSIAN, voltage, 42)
      add = gr.add_vcc()
      s2v = gr.stream_to_vector(gr.sizeof_gr_complex, fft_size)
      fftb = fft.fft_vcc(fft_size, True, (window.blackmanharris(1024)), False, 1)
      ss = howto.spectrum_sensing_cf(samp_rate,fft_size,samples_per_band,pfd,pfa,tcme,output_pfa,debug_stats,primary_user_location,useless_bw,histogram)
      self.sink = gr.vector_sink_f()

		# Connections
      self.connect(src, add, s2v, fftb, ss, self.sink)
      self.connect(noise, (add, 1))
   def __init__(self, dBm, pfa, pfd, useless_bw):
      gr.top_block.__init__(self)

      # Constants
      samp_rate = 2.4e6
      samples_per_band = 16
      tcme = 1.9528
      output_pfa = True
      debug_stats = False
      histogram = True
      primary_user_location = 0
      mu = 0
      fft_size = 16
      history = 3

      src_data = [1+1j]*fft_size*history

		# Blocks
      src = gr.vector_source_c(src_data)
      s2v = gr.stream_to_vector(gr.sizeof_gr_complex, fft_size)
      self.ss = howto.spectrum_sensing_cf(samp_rate,fft_size,samples_per_band,pfd,pfa,tcme,output_pfa,debug_stats,primary_user_location,useless_bw,histogram,history)
      self.sink = gr.vector_sink_f()

		# Connections
      self.connect(src, s2v, self.ss, self.sink)
Ejemplo n.º 4
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 = 2.4e6

		##################################################
		# Blocks
		##################################################
		self.howto_spectrum_sensing_cf_0 = howto.spectrum_sensing_cf(samp_rate,2048,16,0.001,0.0001,1.9528,True,True,0,200000.0,False,3,4,1,6)
		self.gr_null_sink_0 = gr.null_sink(gr.sizeof_float*1)
		self.fft_vxx_0 = fft.fft_vcc(2048, True, (window.blackmanharris(1024)), False, 1)
		self.blocks_stream_to_vector_0 = blocks.stream_to_vector(gr.sizeof_gr_complex*1, 2048)
		self.analog_sig_source_x_0 = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, 1000, 1, 0)

		##################################################
		# Connections
		##################################################
		self.connect((self.fft_vxx_0, 0), (self.howto_spectrum_sensing_cf_0, 0))
		self.connect((self.howto_spectrum_sensing_cf_0, 0), (self.gr_null_sink_0, 0))
		self.connect((self.blocks_stream_to_vector_0, 0), (self.fft_vxx_0, 0))
		self.connect((self.analog_sig_source_x_0, 0), (self.blocks_stream_to_vector_0, 0))
Ejemplo n.º 5
0
    def __init__(self, dBm, pfa, pfd, useless_bw, plot_histogram):
        gr.top_block.__init__(self)

        # Constants
        samp_rate = 2.4e6
        samples_per_band = 16
        tcme = 1.9528
        output_pfa = True
        debug_stats = False
        self.histogram = plot_histogram
        primary_user_location = 5
        mu = 0
        fft_size = 4096
        nframes_to_check = 1
        nframes_to_average = 1
        downconverter = 1

        src_data = self.generateRandomSignalSource(
            dBm, fft_size, mu, nframes_to_check * nframes_to_average)

        # Blocks
        src = gr.vector_source_c(src_data)
        s2v = gr.stream_to_vector(gr.sizeof_gr_complex, fft_size)
        fftb = fft.fft_vcc(fft_size, True, (window.blackmanharris(1024)),
                           False, 1)
        self.ss = howto.spectrum_sensing_cf(samp_rate, fft_size,
                                            samples_per_band, pfd, pfa, tcme,
                                            output_pfa, debug_stats,
                                            primary_user_location, useless_bw,
                                            self.histogram, nframes_to_check,
                                            nframes_to_average, downconverter)
        self.sink = gr.vector_sink_f()

        # Connections
        self.connect(src, s2v, fftb, self.ss, self.sink)
Ejemplo n.º 6
0
   def __init__(self, dbW, pfa, pfd):
      gr.top_block.__init__(self)

      # Parameters
      samp_rate               = 2e6
      fft_size                = 4096
      samples_per_band        = 16
      tcme                    = 1.9528
      output_pfa              = True
      debug_stats             = False
      primary_user_location   = 0
      useless_bw              = 0.0    # As we are not using any of the dongles it can be set as zero, i.e., all the band can be used.
      histogram               = False
      nframes_to_check        = 1
      nframes_to_average      = 1
      downconverter           = 1
      nsegs_to_check          = 6

      # Create AWGN noise
      noise = awgn(fft_size, dbW)

		# Blocks
      src = gr.vector_source_c(noise)
      s2v = gr.stream_to_vector(gr.sizeof_gr_complex, fft_size)
      fftb = fft.fft_vcc(fft_size, True, (window.blackmanharris(1024)), False, 1)
      self.ss = howto.spectrum_sensing_cf(samp_rate,fft_size,samples_per_band,pfd,pfa,tcme,output_pfa,debug_stats,primary_user_location,useless_bw,histogram,nframes_to_check,nframes_to_average,downconverter,nsegs_to_check)
      self.sink = gr.vector_sink_f()

		# Connections
      self.connect(src, s2v, fftb, self.ss, self.sink)
   def __init__(self, pfa, pfd, freq, useless_bw, nframes_to_check, nframes_to_average):
      gr.top_block.__init__(self)

      # Constants
      samp_rate = 2.4e6
      fft_size = 4096
      samples_per_band = 16
      tcme = 1.9528
      output_pfa = False
      debug_stats = False
      histogram = False
      primary_user_location = 20
      nsegs_to_check = 6
      downconverter = 1

		# Blocks
      rtlsdr_source = osmosdr.source_c( args="nchan=" + str(1) + " " + "" )
      rtlsdr_source.set_sample_rate(samp_rate)
      rtlsdr_source.set_center_freq(freq, 0)
      rtlsdr_source.set_freq_corr(0, 0)
      rtlsdr_source.set_gain_mode(0, 0)
      rtlsdr_source.set_gain(10, 0)
      rtlsdr_source.set_if_gain(24, 0)

      s2v = gr.stream_to_vector(gr.sizeof_gr_complex, fft_size)
      fftb = fft.fft_vcc(fft_size, True, (window.blackmanharris(1024)), False, 1)
      self.ss = howto.spectrum_sensing_cf(samp_rate,fft_size,samples_per_band,pfd,pfa,tcme,output_pfa,debug_stats,primary_user_location,useless_bw,histogram,nframes_to_check,nframes_to_average,downconverter,nsegs_to_check)
      self.sink = gr.vector_sink_f()

		# Connections
      self.connect(rtlsdr_source, s2v, fftb, self.ss, self.sink)
Ejemplo n.º 8
0
    def __init__(self, dBm, pfa, pfd, useless_bw):
        gr.top_block.__init__(self)

        # Constants
        samp_rate = 2.4e6
        samples_per_band = 16
        tcme = 1.9528
        output_pfa = True
        debug_stats = False
        histogram = True
        primary_user_location = 0
        mu = 0
        fft_size = 16
        history = 3

        src_data = [1 + 1j] * fft_size * history

        # Blocks
        src = gr.vector_source_c(src_data)
        s2v = gr.stream_to_vector(gr.sizeof_gr_complex, fft_size)
        self.ss = howto.spectrum_sensing_cf(samp_rate, fft_size,
                                            samples_per_band, pfd, pfa, tcme,
                                            output_pfa, debug_stats,
                                            primary_user_location, useless_bw,
                                            histogram, history)
        self.sink = gr.vector_sink_f()

        # Connections
        self.connect(src, s2v, self.ss, self.sink)
Ejemplo n.º 9
0
   def __init__(self, pfa, pfd, freq, useless_bw, nframes_to_check, nframes_to_average):
      gr.top_block.__init__(self)

      # Constants
      samp_rate = 2.4e6
      fft_size = 4096
      samples_per_band = 16
      tcme = 1.9528
      output_pfa = True
      debug_stats = False
      histogram = True
      primary_user_location = 42
      nsegs_to_check = 6
      downconverter = 1

		# Blocks
      rtlsdr_source = osmosdr.source_c( args="nchan=" + str(1) + " " + "" )
      rtlsdr_source.set_sample_rate(samp_rate)
      rtlsdr_source.set_center_freq(freq, 0)
      rtlsdr_source.set_freq_corr(0, 0)
      rtlsdr_source.set_gain_mode(0, 0)
      rtlsdr_source.set_gain(10, 0)
      rtlsdr_source.set_if_gain(24, 0)

      s2v = gr.stream_to_vector(gr.sizeof_gr_complex, fft_size)
      fftb = fft.fft_vcc(fft_size, True, (window.blackmanharris(1024)), False, 1)
      self.ss = howto.spectrum_sensing_cf(samp_rate,fft_size,samples_per_band,pfd,pfa,tcme,output_pfa,debug_stats,primary_user_location,useless_bw,histogram,nframes_to_check,nframes_to_average,downconverter,nsegs_to_check)
      self.sink = gr.vector_sink_f()

		# Connections
      self.connect(rtlsdr_source, s2v, fftb, self.ss, self.sink)
Ejemplo n.º 10
0
    def __init__(self, signal, signal_power, snr, pd, pfd):
        gr.top_block.__init__(self)

        # Parameters
        samp_rate = 2e6
        fft_size = 4096
        samples_per_band = 16
        tcme = 1.9528
        output_pfa = False
        debug_stats = False
        primary_user_location = 0
        useless_bw = 0.0  # As we are not using any of the dongles it can be set as zero, i.e., all the band can be used.
        histogram = False
        nframes_to_check = 1
        nframes_to_average = 1
        downconverter = 1
        nsegs_to_check = 6

        # Calculate the power of the noise vector to be generated.
        noise_power = signal_power - snr  # in dBW

        # Create AWGN noise
        noise = awgn(fft_size, noise_power)

        effective_noise_power = calculateSignalPower(noise)
        effective_snr = signal_power - effective_noise_power
        print "effective_noise_power: %f\n" % effective_noise_power
        print "effective_snr: %f\n" % effective_snr

        # Create corrupted signal
        rx_signal = signal[0:fft_size] + noise

        # Blocks
        src = gr.vector_source_c(rx_signal)
        s2v = gr.stream_to_vector(gr.sizeof_gr_complex, fft_size)
        fftb = fft.fft_vcc(fft_size, True, (window.blackmanharris(1024)),
                           False, 1)
        self.ss = howto.spectrum_sensing_cf(
            samp_rate, fft_size, samples_per_band, pfd, pfa, tcme, output_pfa,
            debug_stats, primary_user_location, useless_bw, histogram,
            nframes_to_check, nframes_to_average, downconverter,
            nsegs_to_check)
        self.sink = gr.vector_sink_f()

        # Connections
        self.connect(src, s2v, fftb, self.ss, self.sink)
Ejemplo n.º 11
0
    def __init__(self, pfa, pfd, freq, useless_bw, history):
        gr.top_block.__init__(self)

        # Constants
        samp_rate = 2.4e6
        fft_size = 4096
        samples_per_band = 16
        tcme = 1.9528
        output_pfa = True
        debug_stats = False
        histogram = True
        primary_user_location = 5

        # Blocks
        rtl2832_source = baz.rtl_source_c(defer_creation=True,
                                          output_size=gr.sizeof_gr_complex)
        rtl2832_source.set_verbose(True)
        rtl2832_source.set_vid(0x0)
        rtl2832_source.set_pid(0x0)
        rtl2832_source.set_tuner_name("")
        rtl2832_source.set_default_timeout(0)
        rtl2832_source.set_use_buffer(True)
        rtl2832_source.set_fir_coefficients(([]))
        rtl2832_source.set_read_length(0)
        if rtl2832_source.create() == False:
            raise Exception(
                "Failed to create RTL2832 Source: rtl2832_source_0")
        rtl2832_source.set_sample_rate(samp_rate)
        rtl2832_source.set_frequency(freq)
        rtl2832_source.set_auto_gain_mode(True)
        rtl2832_source.set_relative_gain(True)
        rtl2832_source.set_gain(1)

        s2v = gr.stream_to_vector(gr.sizeof_gr_complex, fft_size)
        fftb = fft.fft_vcc(fft_size, True, (window.blackmanharris(1024)),
                           False, 1)
        self.ss = howto.spectrum_sensing_cf(samp_rate, fft_size,
                                            samples_per_band, pfd, pfa, tcme,
                                            output_pfa, debug_stats,
                                            primary_user_location, useless_bw,
                                            histogram, history)
        self.sink = gr.vector_sink_f()

        # Connections
        self.connect(rtl2832_source, s2v, fftb, self.ss, self.sink)
Ejemplo n.º 12
0
   def __init__(self, signal, signal_power, snr, pd, pfd):
      gr.top_block.__init__(self)

      # Parameters
      samp_rate               = 2e6
      fft_size                = 4096
      samples_per_band        = 16
      tcme                    = 1.9528
      output_pfa              = False
      debug_stats             = False
      primary_user_location   = 0
      useless_bw              = 0.0    # As we are not using any of the dongles it can be set as zero, i.e., all the band can be used.
      histogram               = False
      nframes_to_check        = 1
      nframes_to_average      = 1
      downconverter           = 1
      nsegs_to_check          = 6

      # Calculate the power of the noise vector to be generated.
      noise_power = signal_power - snr # in dBW

      # Create AWGN noise
      noise = awgn(fft_size, noise_power)
      
      effective_noise_power = calculateSignalPower(noise);
      effective_snr = signal_power - effective_noise_power;
      print "effective_noise_power: %f\n" % effective_noise_power
      print "effective_snr: %f\n" % effective_snr

      # Create corrupted signal
      rx_signal = signal[0:fft_size] + noise

		# Blocks
      src = gr.vector_source_c(rx_signal)
      s2v = gr.stream_to_vector(gr.sizeof_gr_complex, fft_size)
      fftb = fft.fft_vcc(fft_size, True, (window.blackmanharris(1024)), False, 1)
      self.ss = howto.spectrum_sensing_cf(samp_rate,fft_size,samples_per_band,pfd,pfa,tcme,output_pfa,debug_stats,primary_user_location,useless_bw,histogram,nframes_to_check,nframes_to_average,downconverter,nsegs_to_check)
      self.sink = gr.vector_sink_f()

		# Connections
      self.connect(src, s2v, fftb, self.ss, self.sink)
Ejemplo n.º 13
0
   def __init__(self, ssblock, freq):
      gr.top_block.__init__(self)

      # Constants
      pfa = ssblock.pfa
      pfd = ssblock.pfd
      tcme = ssblock.tcme
      samp_rate = ssblock.samp_rate
      fft_size = ssblock.fft_size
      samples_per_band = ssblock.samples_per_band
      tcme = ssblock.tcme
      output_pfa = ssblock.output_pfa
      debug_stats = ssblock.debug_stats
      histogram = ssblock.histogram
      primary_user_location = ssblock.primary_user_location
      nsegs_to_check = ssblock.nsegs_to_check
      downconverter = ssblock.downconverter
      useless_bw = ssblock.useless_bw
      nframes_to_check = ssblock.nframes_to_check
      nframes_to_average = ssblock.nframes_to_average

		# Blocks
      self.rtlsdr_source = osmosdr.source_c( args="nchan=" + str(1) + " " + "" )
      self.rtlsdr_source.set_sample_rate(samp_rate)
      self.rtlsdr_source.set_center_freq(freq, 0)
      self.rtlsdr_source.set_freq_corr(0, 0)
      self.rtlsdr_source.set_gain_mode(0, 0)
      self.rtlsdr_source.set_gain(10, 0)
      self.rtlsdr_source.set_if_gain(24, 0)

      s2v = gr.stream_to_vector(gr.sizeof_gr_complex, fft_size)
      fftb = fft.fft_vcc(fft_size, True, (window.blackmanharris(1024)), False, 1)
      self.ss = howto.spectrum_sensing_cf(samp_rate,fft_size,samples_per_band,pfd,pfa,tcme,output_pfa,debug_stats,primary_user_location,useless_bw,histogram,nframes_to_check,nframes_to_average,downconverter,nsegs_to_check)
      self.sink = gr.vector_sink_f()

		# Connections
      self.connect(self.rtlsdr_source, s2v, fftb, self.ss, self.sink)
   def __init__(self, pfa, pfd, freq, useless_bw, history):
      gr.top_block.__init__(self)

      # Constants
      samp_rate = 2.4e6
      fft_size = 4096
      samples_per_band = 16
      tcme = 1.9528
      output_pfa = False
      debug_stats = False
      histogram = False
      primary_user_location = 5

		# Blocks
      rtl2832_source = baz.rtl_source_c(defer_creation=True, output_size=gr.sizeof_gr_complex)
      rtl2832_source.set_verbose(True)
      rtl2832_source.set_vid(0x0)
      rtl2832_source.set_pid(0x0)
      rtl2832_source.set_tuner_name("")
      rtl2832_source.set_default_timeout(0)
      rtl2832_source.set_use_buffer(True)
      rtl2832_source.set_fir_coefficients(([]))
      rtl2832_source.set_read_length(0)
      if rtl2832_source.create() == False: raise Exception("Failed to create RTL2832 Source: rtl2832_source_0")
      rtl2832_source.set_sample_rate(samp_rate)
      rtl2832_source.set_frequency(freq)
      rtl2832_source.set_auto_gain_mode(True)
      rtl2832_source.set_relative_gain(True)
      rtl2832_source.set_gain(1)

      s2v = gr.stream_to_vector(gr.sizeof_gr_complex, fft_size)
      fftb = fft.fft_vcc(fft_size, True, (window.blackmanharris(1024)), False, 1)
      self.ss = howto.spectrum_sensing_cf(samp_rate,fft_size,samples_per_band,pfd,pfa,tcme,output_pfa,debug_stats,primary_user_location,useless_bw,histogram,history)
      self.sink = gr.vector_sink_f()

		# Connections
      self.connect(rtl2832_source, s2v, fftb, self.ss, self.sink)