Changeset 340

Show
Ignore:
Timestamp:
07/17/09 20:39:53 (15 years ago)
Author:
sriram
Message:

Added the spec sense..Its is dirty Tim

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • vtcross/branches/sriram/receive_path.py

    r329 r340  
    2222 
    2323from gnuradio import gr, gru, blks2 
     24############## imports specific to spectrum sense ####################### 
     25from gnuradio import optfir, window 
     26from gnuradio import audio 
     27from gnuradio.eng_option import eng_option 
     28from optparse import OptionParser 
     29from usrpm import usrp_dbid 
     30import math 
     31import struct 
     32######################################################################### 
    2433from gnuradio import usrp 
    2534from gnuradio import eng_notation 
     
    120129 
    121130        self.min_freq = 462.4825e6 # setting min and max frequency inside the init rather than taking it from the command line 
    122         self.max_freq = 462.4825e6 
     131        self.max_freq = 462.6425e6 
    123132 
    124133        if self.min_freq > self.max_freq: 
     
    163172        #usrp_decim = options.decim 
    164173        #self.u.set_decim_rate(usrp_decim) 
    165         usrp_rate = adc_rate / usrp_decim 
    166  
    167         self.u.set_mux(usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec)) 
    168         self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec) 
    169         print "Using RX d'board %s" % (self.subdev.side_and_name(),) 
    170  
    171  
    172         #s2v = gr.stream_to_vector(gr.sizeof_gr_complex, self.fft_size) 
    173         self.s2v = gr.stream_to_vector(gr.sizeof_gr_complex, self.fft_size) # making it an attribute of the class 
     174        usrp_rate = self.adc_rate / self._decim 
     175 
     176        #self.u.set_mux(usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec)) 
     177        #self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec) 
     178        #print "Using RX d'board %s" % (self.subdev.side_and_name(),) 
     179 
     180 
     181         
     182        s2v = gr.stream_to_vector(gr.sizeof_gr_complex, self.fft_size) 
    174183 
    175184        mywindow = window.blackmanharris(self.fft_size) 
    176         self.fft = gr.fft_vcc(self.fft_size, True, mywindow) #making it an attribute of the class 
     185        fft = gr.fft_vcc(self.fft_size, True, mywindow)  
    177186        power = 0 
    178187        for tap in mywindow: 
    179188            power += tap*tap 
    180189 
    181         #c2mag = gr.complex_to_mag_squared(self.fft_size) # making it an attribute of the class 
    182         self.c2mag = gr.complex_to_mag_squared(self.fft_size) 
     190         
     191        c2mag = gr.complex_to_mag_squared(self.fft_size) 
    183192        print "print c2mag ",c2mag,"\n" 
    184193        # FIXME the log10 primitive is dog slow 
     
    195204 
    196205        self.next_freq = self.min_center_freq 
    197          
    198         tune_delay  = max(0, int(round(options.tune_delay * usrp_rate / self.fft_size)))  # in fft_frames 
    199         dwell_delay = max(1, int(round(options.dwell_delay * usrp_rate / self.fft_size))) # in fft_frames 
     206        tune_delay = 1e-3 
     207        dwell_delay = 1e-2 
     208        tune_delay  = max(0, int(round(tune_delay * usrp_rate / self.fft_size)))  # in fft_frames 
     209        dwell_delay = max(1, int(round(dwell_delay * usrp_rate / self.fft_size))) # in fft_frames 
    200210 
    201211        self.msgq = gr.msg_queue(16) 
    202212        self._tune_callback = tune(self)        # hang on to this to keep it from being GC'd 
    203         #stats = gr.bin_statistics_f(self.fft_size, self.msgq, 
    204         #                            self._tune_callback, tune_delay, dwell_delay) 
    205          
    206         self.stats = gr.bin_statistics_f(self.fft_size, self.msgq, 
    207                                     self._tune_callback, tune_delay, dwell_delay) #making it an attribute of the class 
     213                 
     214        stats = gr.bin_statistics_f(self.fft_size, self.msgq, 
     215                                    self._tune_callback, tune_delay, dwell_delay) 
    208216 
    209217 
     
    211219        # FIXME leave out the log10 until we speed it up 
    212220        #self.connect(self.u, s2v, fft, c2mag, log, stats) 
    213         #self.connect(self.u, s2v, fft, c2mag, stats) # taking care of the connect in benchmark_txrx 
     221        #self.connect(self.u, s2v, fft, c2mag, stats)  
    214222         
    215         if options.gain is None: 
    216             # if no gain was specified, use the mid-point in dB 
    217             g = self.subdev.gain_range() 
    218             options.gain = float(g[0]+g[1])/2 
    219  
    220         self.set_gain(options.gain) 
    221         print "gain =", options.gain 
     223        #if options.gain is None: 
     224        #    # if no gain was specified, use the mid-point in dB 
     225        #    g = self.subdev.gain_range() 
     226        #    options.gain = float(g[0]+g[1])/2 
     227 
     228        #self.set_gain(options.gain) 
     229        #print "gain =", options.gain 
    222230         
    223231        ########################################################################################## 
    224232             
    225233        self.connect(self.u, self.chan_filt, self.packet_receiver) 
    226         self.connect(self.u, s2v) 
     234        self.connect(self.u, s2v, fft, c2mag, stats)  
    227235 
    228236    def _setup_usrp_source(self, options): 
    229237 
    230238        self.u = usrp_options.create_usrp_source(options) 
    231         adc_rate = self.u.adc_rate() 
     239        self.adc_rate = self.u.adc_rate() 
    232240 
    233241        # derive values of bitrate, samples_per_symbol, and decim from desired info 
    234242        (self._bitrate, self._samples_per_symbol, self._decim) = \ 
    235243            pick_rx_bitrate(self._bitrate, self._demod_class.bits_per_symbol(), \ 
    236                             self._samples_per_symbol, self._decim, adc_rate) 
     244                            self._samples_per_symbol, self._decim, self.adc_rate) 
    237245 
    238246        self.u.set_decim(self._decim) 
     
    309317                          help="Log receive signal power to file (CAUTION: lots of data)") 
    310318 
     319    def set_next_freq(self): 
     320        target_freq = self.next_freq 
     321        self.next_freq = self.next_freq + self.freq_step 
     322        if self.next_freq >= self.max_center_freq: 
     323            self.next_freq = self.min_center_freq 
     324 
     325        if not self.set_freq(target_freq): 
     326            print "Failed to set frequency to", target_freq 
     327 
     328        return target_freq 
     329 
    311330    def _print_verbage(self): 
    312331        """ 
     
    321340        print "decim:           %3d"   % (self._decim) 
    322341        print "Rx Frequency:    %s"    % (eng_notation.num_to_str(self._rx_freq)) 
     342 
     343    def get_avg_power(self,trials): 
     344        power_sum = 0 #sum of powers(each power value is determined by adding the 'fft square' points..these fft square points are essentially points from the PSD curve...and adding them gives us the power contained in the spectrum) 
     345        counter = 0 
     346         
     347        while counter < 10 : 
     348 
     349                # Get the next message sent from the C++ code (blocking call). 
     350                # It contains the center frequency and the mag squared of the fft 
     351                m = parse_msg(self.msgq.delete_head()) 
     352                #print "printing mag sq of fft ",sum(m.data),"\n" 
     353                #if sum(m.data) > 1e12: 
     354                power_sum = power_sum + sum(m.data) 
     355                # Print center freq so we know that something is happening... 
     356                #print m.center_freq 
     357                counter +=1 
     358        # FIXME do something useful with the data... 
     359         
     360        # m.data are the mag_squared of the fft output (they are in the 
     361        # standard order.  I.e., bin 0 == DC.) 
     362        # You'll probably want to do the equivalent of "fftshift" on them 
     363        # m.raw_data is a string that contains the binary floats. 
     364        # You could write this as binary to a file. 
     365 
     366        avg_power = power_sum/counter 
     367        print "printing average power ",avg_power,"\n" 
    323368 
    324369def add_freq_option(parser):