Changeset 340
- Timestamp:
- 07/17/09 20:39:53 (15 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
vtcross/branches/sriram/receive_path.py
r329 r340 22 22 23 23 from gnuradio import gr, gru, blks2 24 ############## imports specific to spectrum sense ####################### 25 from gnuradio import optfir, window 26 from gnuradio import audio 27 from gnuradio.eng_option import eng_option 28 from optparse import OptionParser 29 from usrpm import usrp_dbid 30 import math 31 import struct 32 ######################################################################### 24 33 from gnuradio import usrp 25 34 from gnuradio import eng_notation … … 120 129 121 130 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. 4825e6131 self.max_freq = 462.6425e6 123 132 124 133 if self.min_freq > self.max_freq: … … 163 172 #usrp_decim = options.decim 164 173 #self.u.set_decim_rate(usrp_decim) 165 usrp_rate = adc_rate / usrp_decim166 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 s elf.s2v = gr.stream_to_vector(gr.sizeof_gr_complex, self.fft_size) # making it an attribute of the class174 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) 174 183 175 184 mywindow = window.blackmanharris(self.fft_size) 176 self.fft = gr.fft_vcc(self.fft_size, True, mywindow) #making it an attribute of the class185 fft = gr.fft_vcc(self.fft_size, True, mywindow) 177 186 power = 0 178 187 for tap in mywindow: 179 188 power += tap*tap 180 189 181 #c2mag = gr.complex_to_mag_squared(self.fft_size) # making it an attribute of the class182 self.c2mag = gr.complex_to_mag_squared(self.fft_size)190 191 c2mag = gr.complex_to_mag_squared(self.fft_size) 183 192 print "print c2mag ",c2mag,"\n" 184 193 # FIXME the log10 primitive is dog slow … … 195 204 196 205 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 200 210 201 211 self.msgq = gr.msg_queue(16) 202 212 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) 208 216 209 217 … … 211 219 # FIXME leave out the log10 until we speed it up 212 220 #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_txrx221 #self.connect(self.u, s2v, fft, c2mag, stats) 214 222 215 if options.gain is None:216 # if no gain was specified, use the mid-point in dB217 g = self.subdev.gain_range()218 options.gain = float(g[0]+g[1])/2219 220 self.set_gain(options.gain)221 print "gain =", options.gain223 #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 222 230 223 231 ########################################################################################## 224 232 225 233 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) 227 235 228 236 def _setup_usrp_source(self, options): 229 237 230 238 self.u = usrp_options.create_usrp_source(options) 231 adc_rate = self.u.adc_rate()239 self.adc_rate = self.u.adc_rate() 232 240 233 241 # derive values of bitrate, samples_per_symbol, and decim from desired info 234 242 (self._bitrate, self._samples_per_symbol, self._decim) = \ 235 243 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) 237 245 238 246 self.u.set_decim(self._decim) … … 309 317 help="Log receive signal power to file (CAUTION: lots of data)") 310 318 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 311 330 def _print_verbage(self): 312 331 """ … … 321 340 print "decim: %3d" % (self._decim) 322 341 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" 323 368 324 369 def add_freq_option(parser):