switch source package format to 3.0 quilt
[debian/gnuradio] / gr-radio-astronomy / src / python / usrp_psr_receiver.py
index 1aeef8fd9715a33e56a445483f3fe0d09b8cc6b4..6ce4325a26426cc0df0f4ba144439cacc17be805 100755 (executable)
@@ -1,12 +1,12 @@
 #!/usr/bin/env python
 #
-# Copyright 2004,2005 Free Software Foundation, Inc.
+# Copyright 2004,2005,2007 Free Software Foundation, Inc.
 # 
 # This file is part of GNU Radio
 # 
 # GNU Radio is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2, or (at your option)
+# the Free Software Foundation; either version 3, or (at your option)
 # any later version.
 # 
 # GNU Radio is distributed in the hope that it will be useful,
@@ -16,8 +16,8 @@
 # 
 # You should have received a copy of the GNU General Public License
 # along with GNU Radio; see the file COPYING.  If not, write to
-# the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-# Boston, MA 02111-1307, USA.
+# the Free Software Foundation, Inc., 51 Franklin Street,
+# Boston, MA 02110-1301, USA.
 # 
 
 
 #  and epoch folding analysis
 #
 #
-from gnuradio import gr, gru, blks, audio
-import usrp_dbid
+from gnuradio import gr, gru, blks2, audio
+from usrpm import usrp_dbid
 from gnuradio import usrp, optfir
 from gnuradio import eng_notation
 from gnuradio.eng_option import eng_option
-from gnuradio.wxgui import stdgui, ra_fftsink, ra_stripchartsink, form, slider
+from gnuradio.wxgui import stdgui2, ra_fftsink, ra_stripchartsink, form, slider
 from optparse import OptionParser
 import wx
 import sys
 import Numeric
-import FFT
+import numpy.fft
 import ephem
 import time
 import os
 import math
 
 
-class app_flow_graph(stdgui.gui_flow_graph):
+class app_flow_graph(stdgui2.std_top_block):
     def __init__(self, frame, panel, vbox, argv):
-        stdgui.gui_flow_graph.__init__(self)
+        stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv)
 
         self.frame = frame
         self.panel = panel
@@ -84,6 +84,8 @@ class app_flow_graph(stdgui.gui_flow_graph):
         parser.add_option("-O", "--doppler", type="eng_float", default=1.0, help="Doppler ratio")
         parser.add_option("-B", "--divbase", type="eng_float", default=20, help="Y/Div menu base")
         parser.add_option("-I", "--division", type="eng_float", default=100, help="Y/Div")
+        parser.add_option("-A", "--audio_source", default="plughw:0,0", help="Audio input device spec")
+        parser.add_option("-N", "--num_pulses", default=1, type="eng_float", help="Number of display pulses")
         (options, args) = parser.parse_args()
         if len(args) != 0:
             parser.print_help()
@@ -94,6 +96,8 @@ class app_flow_graph(stdgui.gui_flow_graph):
         self.reflevel = options.reflevel
         self.divbase = options.divbase
         self.division = options.division
+        self.audiodev = options.audio_source
+        self.mult = int(options.num_pulses)
 
         # Low-pass cutoff for post-detector filter
         # Set to 100Hz usually, since lots of pulsars fit in this
@@ -218,8 +222,8 @@ class app_flow_graph(stdgui.gui_flow_graph):
         self.interp = int(interp)
         self.decim = int(decim)
 
-        # So that we can view 4 pulses in the pulse viewer window
-        FOLD_MULT=1
+        # So that we can view N pulses in the pulse viewer window
+        FOLD_MULT=self.mult
 
         # determine the daughterboard subdevice we're using
         self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec)
@@ -243,7 +247,7 @@ class app_flow_graph(stdgui.gui_flow_graph):
         #
         # We use this as a crude volume control for the audio output
         #
-        self.volume = gr.multiply_const_ff(10**(-1))
+        #self.volume = gr.multiply_const_ff(10**(-1))
         
 
         #
@@ -290,10 +294,10 @@ class app_flow_graph(stdgui.gui_flow_graph):
         #
         # Create the appropriate FFT scope
         #
-        self.scope = ra_fftsink.ra_fft_sink_f (self, panel, 
+        self.scope = ra_fftsink.ra_fft_sink_f (panel, 
            fft_size=int(options.fft_size), sample_rate=PULSAR_MAX_FREQ*2,
            title="Post-detector spectrum",  
-           cfunc=self.pulsarfunc, xydfunc=self.xydfunc, fft_rate=200)
+           ofunc=self.pulsarfunc, xydfunc=self.xydfunc, fft_rate=200)
 
         #
         # Tell scope we're looking from DC to PULSAR_MAX_FREQ
@@ -307,9 +311,10 @@ class app_flow_graph(stdgui.gui_flow_graph):
         hz = "%5.3fHz " % self.pulse_freq
         per = "(%5.3f sec)" % (1.0/self.pulse_freq)
         sr = "%d sps" % (int(self.pulse_freq*self.folding))
-        self.chart = ra_stripchartsink.stripchart_sink_f (self, panel,
+        times = " %d Pulse Intervals" % self.mult
+        self.chart = ra_stripchartsink.stripchart_sink_f (panel,
                sample_rate=1,
-               stripsize=self.folding*FOLD_MULT, parallel=True, title="Pulse Profiles: "+hz+per, 
+               stripsize=self.folding*FOLD_MULT, parallel=True, title="Pulse Profiles: "+hz+per+times
                xlabel="Seconds @ "+sr, ylabel="Level", autoscale=True,
                divbase=self.divbase, scaling=1.0/(self.folding*self.pulse_freq))
         self.chart.set_ref_level(self.reflevel)
@@ -340,7 +345,8 @@ class app_flow_graph(stdgui.gui_flow_graph):
         #
         # Audio sink
         #
-        self.audio = audio.sink(second_input_rate, "plughw:0,0")
+        #print "input_rate ", second_input_rate, "audiodev ", self.audiodev
+        #self.audio = audio.sink(second_input_rate, self.audiodev)
 
         #
         # The three post-detector filters
@@ -354,17 +360,8 @@ class app_flow_graph(stdgui.gui_flow_graph):
         self.second = gr.fir_filter_fff (int(p), second_filter)
         self.third = gr.fir_filter_fff (10, third_filter)
 
-        # Split complex USRP stream into a pair of floats
-        self.splitter = gr.complex_to_float (1);
-
-        # I squarer (detector)
-        self.multI = gr.multiply_ff();
-
-        # Q squarer (detector)
-        self.multQ = gr.multiply_ff();
-
-        # Adding squared I and Q to produce instantaneous signal power
-        self.adder = gr.add_ff();
+        # Detector
+        self.detector = gr.complex_to_mag_squared()
 
         self.enable_comb_filter = False
         # Epoch folder comb filter
@@ -373,7 +370,7 @@ class app_flow_graph(stdgui.gui_flow_graph):
             self.folder_comb = gr.fft_filter_ccc(1,bogtaps)
 
         # Rational resampler
-        self.folder_rr = blks.rational_resampler_fff(self, self.interp, self.decim)
+        self.folder_rr = blks2.rational_resampler_fff(self.interp, self.decim)
 
         # Epoch folder bandpass
         bogtaps = Numeric.zeros(1, Numeric.Float64)
@@ -400,31 +397,18 @@ class app_flow_graph(stdgui.gui_flow_graph):
         # Start connecting configured modules in the receive chain
         #
 
-        # Connect raw USRP to de-dispersion filter, complex->float splitter
-        self.connect(self.u, self.dispfilt, self.splitter)
-
-        # Connect splitter outputs to multipliers
-        # First do I^2
-        self.connect((self.splitter, 0), (self.multI,0))
-        self.connect((self.splitter, 0), (self.multI,1))
+        # Connect raw USRP to de-dispersion filter, detector
+        self.connect(self.u, self.dispfilt, self.detector)
 
-        # Then do Q^2
-        self.connect((self.splitter, 1), (self.multQ,0))
-        self.connect((self.splitter, 1), (self.multQ,1))
-
-        # Then sum the squares
-        self.connect(self.multI, (self.adder,0))
-        self.connect(self.multQ, (self.adder,1))
-
-        # Connect detector/adder output to FIR LPF
+        # Connect detector output to FIR LPF
         #  in two stages, followed by the FFT scope
-        self.connect(self.adder, self.first,
+        self.connect(self.detector, self.first,
             self.second, self.third, self.scope)
 
         # Connect audio output
-        self.connect(self.first, self.volume)
-        self.connect(self.volume, (self.audio, 0))
-        self.connect(self.volume, (self.audio, 1))
+        #self.connect(self.first, self.volume)
+        #self.connect(self.volume, (self.audio, 0))
+        #self.connect(self.volume, (self.audio, 1))
 
         # Connect epoch folder
         if self.enable_comb_filter == True:
@@ -473,7 +457,7 @@ class app_flow_graph(stdgui.gui_flow_graph):
             options.freq = float(r[0]+r[1])/2
 
         self.set_gain(options.gain)
-        self.set_volume(-10.0)
+        #self.set_volume(-10.0)
 
         if not(self.set_freq(options.freq)):
             self._set_status_msg("Failed to set initial frequency")
@@ -550,9 +534,9 @@ class app_flow_graph(stdgui.gui_flow_graph):
         myform['foldavg'] = form.slider_field(parent=self.panel, sizer=vbox2,
                     label="Folder Averaging", weight=1, min=1, max=20, callback=self.set_folder_averaging)
         vbox2.Add((6,0), 0, 0)
-        myform['volume'] = form.quantized_slider_field(parent=self.panel, sizer=vbox2,
-                    label="Audio Volume", weight=1, range=(-20, 0, 0.5), callback=self.set_volume)
-        vbox2.Add((6,0), 0, 0)
+        #myform['volume'] = form.quantized_slider_field(parent=self.panel, sizer=vbox2,
+                    #label="Audio Volume", weight=1, range=(-20, 0, 0.5), callback=self.set_volume)
+        #vbox2.Add((6,0), 0, 0)
         myform['DM'] = form.float_field(
             parent=self.panel, sizer=vbox2, label="DM", weight=1,
             callback=myform.check_input_and_call(_form_set_dm))
@@ -673,9 +657,9 @@ class app_flow_graph(stdgui.gui_flow_graph):
         self.subdev.set_gain(gain)
 
 
-    def set_volume(self, vol):
-        self.myform['volume'].set_value(vol)
-        self.volume.set_k((10**(vol/10))/8192)
+    #def set_volume(self, vol):
+        #self.myform['volume'].set_value(vol)
+        #self.volume.set_k((10**(vol/10))/8192)
 
     # Callback for spectral-averaging slider
     def set_averaging(self, avval):
@@ -1077,7 +1061,7 @@ class app_flow_graph(stdgui.gui_flow_graph):
             tmp[i] = complex(math.cos(phi), math.sin(phi))
             n += 1
         
-        self.disp_taps = FFT.inverse_fft(tmp)
+        self.disp_taps = numpy.fft.ifft(tmp)
         return(self.disp_taps)
 
     #
@@ -1105,7 +1089,7 @@ class app_flow_graph(stdgui.gui_flow_graph):
         return(int(ntaps))
 
 def main ():
-    app = stdgui.stdapp(app_flow_graph, "RADIO ASTRONOMY PULSAR RECEIVER: $Revision$", nstatus=1)
+    app = stdgui2.stdapp(app_flow_graph, "RADIO ASTRONOMY PULSAR RECEIVER: $Revision$", nstatus=1)
     app.MainLoop()
 
 if __name__ == '__main__':