2 # Copyright 2008 Free Software Foundation, Inc.
4 # This file is part of GNU Radio
6 # GNU Radio is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3, or (at your option)
11 # GNU Radio is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with GNU Radio; see the file COPYING. If not, write to
18 # the Free Software Foundation, Inc., 51 Franklin Street,
19 # Boston, MA 02110-1301, USA.
22 ##################################################
24 ##################################################
27 from gnuradio import gr
28 from pubsub import pubsub
29 from constants import *
32 class ac_couple_block(gr.hier_block2):
34 AC couple the incoming stream by subtracting out the low pass signal.
35 Mute the low pass filter to disable ac coupling.
38 def __init__(self, controller, ac_couple_key, sample_rate_key):
39 gr.hier_block2.__init__(
42 gr.io_signature(1, 1, gr.sizeof_float),
43 gr.io_signature(1, 1, gr.sizeof_float),
46 lpf = gr.single_pole_iir_filter_ff(0.0)
50 self.connect(self, sub, self)
51 self.connect(self, lpf, mute, (sub, 1))
53 controller.subscribe(ac_couple_key, lambda x: mute.set_mute(not x))
54 controller.subscribe(sample_rate_key, lambda x: lpf.set_taps(0.05))
56 controller[ac_couple_key] = controller[ac_couple_key]
57 controller[sample_rate_key] = controller[sample_rate_key]
59 ##################################################
60 # Scope sink block (wrapper for old wxgui)
61 ##################################################
62 class _scope_sink_base(gr.hier_block2, common.wxgui_hb):
64 A scope block with a gui window.
72 size=scope_window.DEFAULT_WIN_SIZE,
79 frame_rate=scope_window.DEFAULT_FRAME_RATE,
82 **kwargs #do not end with a comma
85 if analog_alpha is None:
86 actual_frame_rate=float(frame_rate)
87 analog_cutoff_freq=0.5 # Hertz
88 #calculate alpha from wanted cutoff freq
89 analog_alpha = 1.0 - math.exp(-2.0*math.pi*analog_cutoff_freq/actual_frame_rate)
91 if not t_scale: t_scale = 10.0/sample_rate
93 gr.hier_block2.__init__(
96 gr.io_signature(num_inputs, num_inputs, self._item_size),
97 gr.io_signature(0, 0, 0),
100 msgq = gr.msg_queue(2)
101 scope = gr.oscope_sink_f(sample_rate, msgq)
103 self.controller = pubsub()
104 self.controller.subscribe(SAMPLE_RATE_KEY, scope.set_sample_rate)
105 self.controller.publish(SAMPLE_RATE_KEY, scope.sample_rate)
106 self.controller.subscribe(DECIMATION_KEY, scope.set_decimation_count)
107 self.controller.publish(DECIMATION_KEY, scope.get_decimation_count)
108 self.controller.subscribe(TRIGGER_LEVEL_KEY, scope.set_trigger_level)
109 self.controller.publish(TRIGGER_LEVEL_KEY, scope.get_trigger_level)
110 self.controller.subscribe(TRIGGER_MODE_KEY, scope.set_trigger_mode)
111 self.controller.publish(TRIGGER_MODE_KEY, scope.get_trigger_mode)
112 self.controller.subscribe(TRIGGER_SLOPE_KEY, scope.set_trigger_slope)
113 self.controller.publish(TRIGGER_SLOPE_KEY, scope.get_trigger_slope)
114 self.controller.subscribe(TRIGGER_CHANNEL_KEY, scope.set_trigger_channel)
115 self.controller.publish(TRIGGER_CHANNEL_KEY, scope.get_trigger_channel)
116 actual_num_inputs = self._real and num_inputs or num_inputs*2
118 for i in range(actual_num_inputs):
119 self.controller[common.index_key(AC_COUPLE_KEY, i)] = ac_couple
121 common.input_watcher(msgq, self.controller, MSG_KEY)
123 self.win = scope_window.scope_window(
125 controller=self.controller,
128 frame_rate=frame_rate,
129 num_inputs=actual_num_inputs,
130 sample_rate_key=SAMPLE_RATE_KEY,
135 ac_couple_key=AC_COUPLE_KEY,
136 trigger_level_key=TRIGGER_LEVEL_KEY,
137 trigger_mode_key=TRIGGER_MODE_KEY,
138 trigger_slope_key=TRIGGER_SLOPE_KEY,
139 trigger_channel_key=TRIGGER_CHANNEL_KEY,
140 decimation_key=DECIMATION_KEY,
142 emulate_analog=emulate_analog,
143 analog_alpha=analog_alpha,
145 common.register_access_methods(self, self.win)
148 for i in range(num_inputs):
151 ac_couple_block(self.controller, common.index_key(AC_COUPLE_KEY, i), SAMPLE_RATE_KEY),
155 for i in range(num_inputs):
156 c2f = gr.complex_to_float()
157 self.wxgui_connect((self, i), c2f)
161 ac_couple_block(self.controller, common.index_key(AC_COUPLE_KEY, 2*i+j), SAMPLE_RATE_KEY),
165 class scope_sink_f(_scope_sink_base):
166 _item_size = gr.sizeof_float
169 class scope_sink_c(_scope_sink_base):
170 _item_size = gr.sizeof_gr_complex
173 # ----------------------------------------------------------------
174 # Stand-alone test application
175 # ----------------------------------------------------------------
178 from gnuradio.wxgui import stdgui2
180 class test_top_block (stdgui2.std_top_block):
181 def __init__(self, frame, panel, vbox, argv):
182 stdgui2.std_top_block.__init__ (self, frame, panel, vbox, argv)
184 default_input_rate = 1e6
186 input_rate = int(argv[1])
188 input_rate = default_input_rate
191 v_scale = float(argv[2]) # start up at this v_scale value
193 v_scale = None # start up in autorange mode, default
196 t_scale = float(argv[3]) # start up at this t_scale value
198 t_scale = .00003*default_input_rate/input_rate # old behavior
200 print "input rate %s v_scale %s t_scale %s" % (input_rate,v_scale,t_scale)
203 # Generate a complex sinusoid
205 self.src0 = gr.sig_source_c (input_rate, gr.GR_SIN_WAVE, 25.1e3*input_rate/default_input_rate, ampl)
206 self.noise =gr.sig_source_c (input_rate, gr.GR_SIN_WAVE, 11.1*25.1e3*input_rate/default_input_rate, ampl/10)
207 #self.noise =gr.noise_source_c(gr.GR_GAUSSIAN, ampl/10)
208 self.combine=gr.add_cc()
210 # We add this throttle block so that this demo doesn't suck down
211 # all the CPU available. You normally wouldn't use it...
212 self.thr = gr.throttle(gr.sizeof_gr_complex, input_rate)
214 scope = scope_sink_c (panel,"Secret Data",sample_rate=input_rate,
215 v_scale=v_scale, t_scale=t_scale)
216 vbox.Add (scope.win, 1, wx.EXPAND)
218 # Ultimately this will be
219 # self.connect("src0 throttle scope")
220 self.connect(self.src0,(self.combine,0))
221 self.connect(self.noise,(self.combine,1))
222 self.connect(self.combine, self.thr, scope)
225 app = stdgui2.stdapp (test_top_block, "O'Scope Test App")
228 if __name__ == '__main__':