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 ##################################################
25 import waterfall_window
27 from gnuradio import gr, blks2
28 from pubsub import pubsub
29 from constants import *
31 ##################################################
32 # Waterfall sink block (wrapper for old wxgui)
33 ##################################################
34 class _waterfall_sink_base(gr.hier_block2, common.wxgui_hb):
36 An fft block with real/complex inputs and a gui window.
46 fft_rate=waterfall_window.DEFAULT_FRAME_RATE,
50 size=waterfall_window.DEFAULT_WIN_SIZE,
54 **kwargs #do not end with a comma
57 if avg_alpha is None: avg_alpha = 2.0/fft_rate
59 gr.hier_block2.__init__(
62 gr.io_signature(1, 1, self._item_size),
63 gr.io_signature(0, 0, 0),
66 fft = self._fft_chain(
67 sample_rate=sample_rate,
74 msgq = gr.msg_queue(2)
75 sink = gr.message_sink(gr.sizeof_float*fft_size, msgq, True)
77 self.controller = pubsub()
78 self.controller.subscribe(AVERAGE_KEY, fft.set_average)
79 self.controller.publish(AVERAGE_KEY, fft.average)
80 self.controller.subscribe(AVG_ALPHA_KEY, fft.set_avg_alpha)
81 self.controller.publish(AVG_ALPHA_KEY, fft.avg_alpha)
82 self.controller.subscribe(SAMPLE_RATE_KEY, fft.set_sample_rate)
83 self.controller.publish(SAMPLE_RATE_KEY, fft.sample_rate)
84 self.controller.subscribe(DECIMATION_KEY, fft.set_decimation)
85 self.controller.publish(DECIMATION_KEY, fft.decimation)
86 self.controller.subscribe(FRAME_RATE_KEY, fft.set_vec_rate)
87 self.controller.publish(FRAME_RATE_KEY, fft.frame_rate)
89 common.input_watcher(msgq, self.controller, MSG_KEY)
91 self.win = waterfall_window.waterfall_window(
93 controller=self.controller,
99 baseband_freq=baseband_freq,
100 decimation_key=DECIMATION_KEY,
101 sample_rate_key=SAMPLE_RATE_KEY,
102 frame_rate_key=FRAME_RATE_KEY,
103 dynamic_range=dynamic_range,
105 average_key=AVERAGE_KEY,
106 avg_alpha_key=AVG_ALPHA_KEY,
109 common.register_access_methods(self, self.win)
110 setattr(self.win, 'set_baseband_freq', getattr(self, 'set_baseband_freq')) #BACKWARDS
112 self.wxgui_connect(self, fft, sink)
114 class waterfall_sink_f(_waterfall_sink_base):
115 _fft_chain = blks2.logpwrfft_f
116 _item_size = gr.sizeof_float
119 class waterfall_sink_c(_waterfall_sink_base):
120 _fft_chain = blks2.logpwrfft_c
121 _item_size = gr.sizeof_gr_complex
124 # ----------------------------------------------------------------
125 # Standalone test app
126 # ----------------------------------------------------------------
129 from gnuradio.wxgui import stdgui2
131 class test_top_block (stdgui2.std_top_block):
132 def __init__(self, frame, panel, vbox, argv):
133 stdgui2.std_top_block.__init__ (self, frame, panel, vbox, argv)
137 # build our flow graph
138 input_rate = 20.000e3
140 # Generate a complex sinusoid
141 self.src1 = gr.sig_source_c (input_rate, gr.GR_SIN_WAVE, 5.75e3, 1000)
142 #src1 = gr.sig_source_c (input_rate, gr.GR_CONST_WAVE, 5.75e3, 1000)
144 # We add these throttle blocks so that this demo doesn't
145 # suck down all the CPU available. Normally you wouldn't use these.
146 self.thr1 = gr.throttle(gr.sizeof_gr_complex, input_rate)
148 sink1 = waterfall_sink_c (panel, title="Complex Data", fft_size=fft_size,
149 sample_rate=input_rate, baseband_freq=100e3)
150 self.connect(self.src1, self.thr1, sink1)
151 vbox.Add (sink1.win, 1, wx.EXPAND)
153 # generate a real sinusoid
154 self.src2 = gr.sig_source_f (input_rate, gr.GR_SIN_WAVE, 5.75e3, 1000)
155 self.thr2 = gr.throttle(gr.sizeof_float, input_rate)
156 sink2 = waterfall_sink_f (panel, title="Real Data", fft_size=fft_size,
157 sample_rate=input_rate, baseband_freq=100e3)
158 self.connect(self.src2, self.thr2, sink2)
159 vbox.Add (sink2.win, 1, wx.EXPAND)
163 app = stdgui2.stdapp (test_top_block, "Waterfall Sink Test App")
166 if __name__ == '__main__':