forked from LetsGoRosco/grc-files
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hysteresis.py
173 lines (159 loc) · 6.32 KB
/
hysteresis.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#!/usr/bin/env python
##################################################
# Gnuradio Python Flow Graph
# Title: Hysteresis
# Generated: Sat Apr 25 14:48:55 2015
##################################################
from gnuradio import analog
from gnuradio import blocks
from gnuradio import eng_notation
from gnuradio import gr
from gnuradio import wxgui
from gnuradio.eng_option import eng_option
from gnuradio.filter import firdes
from gnuradio.wxgui import forms
from gnuradio.wxgui import histosink_gl
from gnuradio.wxgui import scopesink2
from grc_gnuradio import wxgui as grc_wxgui
from optparse import OptionParser
import wx
class hysteresis(grc_wxgui.top_block_gui):
def __init__(self):
grc_wxgui.top_block_gui.__init__(self, title="Hysteresis")
##################################################
# Variables
##################################################
self.samp_rate = samp_rate = 128000
self.noise = noise = 0.05
self.level = level = 0
##################################################
# Blocks
##################################################
_noise_sizer = wx.BoxSizer(wx.VERTICAL)
self._noise_text_box = forms.text_box(
parent=self.GetWin(),
sizer=_noise_sizer,
value=self.noise,
callback=self.set_noise,
label="Noise",
converter=forms.float_converter(),
proportion=0,
)
self._noise_slider = forms.slider(
parent=self.GetWin(),
sizer=_noise_sizer,
value=self.noise,
callback=self.set_noise,
minimum=0,
maximum=1,
num_steps=100,
style=wx.SL_HORIZONTAL,
cast=float,
proportion=1,
)
self.Add(_noise_sizer)
_level_sizer = wx.BoxSizer(wx.VERTICAL)
self._level_text_box = forms.text_box(
parent=self.GetWin(),
sizer=_level_sizer,
value=self.level,
callback=self.set_level,
label="Level",
converter=forms.float_converter(),
proportion=0,
)
self._level_slider = forms.slider(
parent=self.GetWin(),
sizer=_level_sizer,
value=self.level,
callback=self.set_level,
minimum=-1,
maximum=2,
num_steps=100,
style=wx.SL_HORIZONTAL,
cast=float,
proportion=1,
)
self.Add(_level_sizer)
self.wxgui_scopesink2_0 = scopesink2.scope_sink_f(
self.GetWin(),
title="Scope Plot",
sample_rate=samp_rate,
v_scale=0.25,
v_offset=0.5,
t_scale=0,
ac_couple=False,
xy_mode=False,
num_inputs=5,
trig_mode=wxgui.TRIG_MODE_AUTO,
y_axis_label="Counts",
size=(510,320),
)
self.Add(self.wxgui_scopesink2_0.win)
self.wxgui_histosink2_0 = histosink_gl.histo_sink_f(
self.GetWin(),
title="Histogram Plot",
num_bins=241,
frame_size=10000,
)
self.Add(self.wxgui_histosink2_0.win)
self.blocks_throttle_0_0_0 = blocks.throttle(gr.sizeof_float*1, samp_rate,True)
self.blocks_throttle_0_0 = blocks.throttle(gr.sizeof_float*1, samp_rate,True)
self.blocks_throttle_0 = blocks.throttle(gr.sizeof_float*1, samp_rate,True)
self.blocks_threshold_ff_0 = blocks.threshold_ff(0.25, 0.75, 0)
self.blocks_add_xx_0 = blocks.add_vff(1)
self.analog_noise_source_x_0 = analog.noise_source_f(analog.GR_GAUSSIAN, noise, 42)
self.analog_const_source_x_2 = analog.sig_source_f(0, analog.GR_CONST_WAVE, 0, 0, level)
self.analog_const_source_x_1 = analog.sig_source_f(0, analog.GR_CONST_WAVE, 0, 0, 0.25)
self.analog_const_source_x_0 = analog.sig_source_f(0, analog.GR_CONST_WAVE, 0, 0, 0.75)
##################################################
# Connections
##################################################
self.connect((self.analog_const_source_x_0, 0), (self.blocks_throttle_0_0_0, 0))
self.connect((self.analog_const_source_x_1, 0), (self.blocks_throttle_0_0, 0))
self.connect((self.analog_const_source_x_2, 0), (self.blocks_throttle_0, 0))
self.connect((self.analog_noise_source_x_0, 0), (self.blocks_add_xx_0, 1))
self.connect((self.analog_noise_source_x_0, 0), (self.wxgui_histosink2_0, 0))
self.connect((self.blocks_add_xx_0, 0), (self.blocks_threshold_ff_0, 0))
self.connect((self.blocks_add_xx_0, 0), (self.wxgui_scopesink2_0, 3))
self.connect((self.blocks_threshold_ff_0, 0), (self.wxgui_scopesink2_0, 2))
self.connect((self.blocks_throttle_0, 0), (self.blocks_add_xx_0, 0))
self.connect((self.blocks_throttle_0, 0), (self.wxgui_scopesink2_0, 4))
self.connect((self.blocks_throttle_0_0, 0), (self.wxgui_scopesink2_0, 0))
self.connect((self.blocks_throttle_0_0_0, 0), (self.wxgui_scopesink2_0, 1))
def get_samp_rate(self):
return self.samp_rate
def set_samp_rate(self, samp_rate):
self.samp_rate = samp_rate
self.blocks_throttle_0.set_sample_rate(self.samp_rate)
self.blocks_throttle_0_0_0.set_sample_rate(self.samp_rate)
self.blocks_throttle_0_0.set_sample_rate(self.samp_rate)
self.wxgui_scopesink2_0.set_sample_rate(self.samp_rate)
def get_noise(self):
return self.noise
def set_noise(self, noise):
self.noise = noise
self.analog_noise_source_x_0.set_amplitude(self.noise)
self._noise_slider.set_value(self.noise)
self._noise_text_box.set_value(self.noise)
def get_level(self):
return self.level
def set_level(self, level):
self.level = level
self._level_slider.set_value(self.level)
self._level_text_box.set_value(self.level)
self.analog_const_source_x_2.set_offset(self.level)
if __name__ == '__main__':
import ctypes
import sys
if sys.platform.startswith('linux'):
try:
x11 = ctypes.cdll.LoadLibrary('libX11.so')
x11.XInitThreads()
except:
print "Warning: failed to XInitThreads()"
parser = OptionParser(option_class=eng_option, usage="%prog: [options]")
(options, args) = parser.parse_args()
tb = hysteresis()
tb.Start(True)
tb.Wait()