8d3d870d8426c5b93f19a661f5b5c5209e8d9db1
[debian/gnuradio] / gr-howto-write-a-block / apps / howto_square.py
1 #!/usr/bin/env python
2 ##################################################
3 # Gnuradio Python Flow Graph
4 # Title: Howto Square
5 # Generated: Thu Nov 12 11:26:07 2009
6 ##################################################
7
8 from gnuradio import eng_notation
9 from gnuradio import gr
10 from gnuradio import howto
11 from gnuradio.eng_option import eng_option
12 from gnuradio.gr import firdes
13 from gnuradio.wxgui import scopesink2
14 from grc_gnuradio import wxgui as grc_wxgui
15 from optparse import OptionParser
16 import wx
17
18 class howto_square(grc_wxgui.top_block_gui):
19
20         def __init__(self):
21                 grc_wxgui.top_block_gui.__init__(self, title="Howto Square")
22
23                 ##################################################
24                 # Variables
25                 ##################################################
26                 self.samp_rate = samp_rate = 10e3
27
28                 ##################################################
29                 # Blocks
30                 ##################################################
31                 self.sink = scopesink2.scope_sink_f(
32                         self.GetWin(),
33                         title="Input",
34                         sample_rate=samp_rate,
35                         v_scale=20,
36                         v_offset=0,
37                         t_scale=0.002,
38                         ac_couple=False,
39                         xy_mode=False,
40                         num_inputs=1,
41                 )
42                 self.Add(self.sink.win)
43                 self.sink2 = scopesink2.scope_sink_f(
44                         self.GetWin(),
45                         title="Output",
46                         sample_rate=samp_rate,
47                         v_scale=0,
48                         v_offset=0,
49                         t_scale=0.002,
50                         ac_couple=False,
51                         xy_mode=False,
52                         num_inputs=1,
53                 )
54                 self.Add(self.sink2.win)
55                 self.sqr = howto.square_ff()
56                 self.src = gr.vector_source_f(([float(n)-50 for n in range(100)]), True, 1)
57                 self.thr = gr.throttle(gr.sizeof_float*1, samp_rate)
58
59                 ##################################################
60                 # Connections
61                 ##################################################
62                 self.connect((self.thr, 0), (self.sqr, 0))
63                 self.connect((self.src, 0), (self.thr, 0))
64                 self.connect((self.thr, 0), (self.sink, 0))
65                 self.connect((self.sqr, 0), (self.sink2, 0))
66
67         def set_samp_rate(self, samp_rate):
68                 self.samp_rate = samp_rate
69                 self.sink.set_sample_rate(self.samp_rate)
70                 self.sink2.set_sample_rate(self.samp_rate)
71
72 if __name__ == '__main__':
73         parser = OptionParser(option_class=eng_option, usage="%prog: [options]")
74         (options, args) = parser.parse_args()
75         tb = howto_square()
76         tb.Run(True)
77