Subversion Repositories svnkaklik

Rev

Rev 515 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 515 Rev 524
1
#!/usr/bin/env python
1
#!/usr/bin/env python
2
##################################################
2
##################################################
3
# Gnuradio Python Flow Graph
3
# Gnuradio Python Flow Graph
4
# Title: Sonar
4
# Title: Sonar
5
# Author: Kaklik
5
# Author: Kaklik
6
# Description: Sonar waform generator
6
# Description: Sonar waform generator
7
# Generated: Fri Feb 20 19:31:13 2009
7
# Generated: Sat Feb 21 11:50:42 2009
8
##################################################
8
##################################################
9
 
9
 
10
from gnuradio import audio
10
from gnuradio import audio
11
from gnuradio import gr
11
from gnuradio import gr
12
from gnuradio.wxgui import scopesink2
12
from gnuradio.wxgui import scopesink2
-
 
13
from gnuradio.wxgui import waterfallsink2
13
from grc_gnuradio import wxgui as grc_wxgui
14
from grc_gnuradio import wxgui as grc_wxgui
14
import wx
15
import wx
15
 
16
 
16
class Sonar(grc_wxgui.top_block_gui):
17
class Sonar(grc_wxgui.top_block_gui):
17
 
18
 
18
	def __init__(self):
19
	def __init__(self):
19
		grc_wxgui.top_block_gui.__init__(
20
		grc_wxgui.top_block_gui.__init__(
20
			self,
21
			self,
21
			title="GRC - Executing: Sonar",
22
			title="GRC - Executing: Sonar",
22
			icon="/usr/local/share/icons/hicolor/32x32/apps/gnuradio-grc.png",
23
			icon="/usr/local/share/icons/hicolor/32x32/apps/gnuradio-grc.png",
23
		)
24
		)
24
 
25
 
25
		##################################################
26
		##################################################
26
		# Variables
27
		# Variables
27
		##################################################
28
		##################################################
28
		self.samp_rate = samp_rate = 96000
29
		self.samp_rate = samp_rate = 96000
29
		self.frequency = frequency = 20000
30
		self.frequency = frequency = 20000
30
		self.ampl = ampl = .4
31
		self.ampl = ampl = .4
31
 
32
 
32
		##################################################
33
		##################################################
33
		# Controls
34
		# Controls
34
		##################################################
35
		##################################################
35
		_frequency_control = grc_wxgui.slider_horizontal_control(
36
		_frequency_control = grc_wxgui.slider_horizontal_control(
36
			window=self.GetWin(),
37
			window=self.GetWin(),
37
			callback=self.set_frequency,
38
			callback=self.set_frequency,
38
			label='frequency',
39
			label='frequency',
39
			value=frequency,
40
			value=frequency,
40
			min=5000,
41
			min=5000,
41
			max=30000,
42
			max=30000,
42
			num_steps=1000,
43
			num_steps=1000,
43
			slider_length=500,
44
			slider_length=500,
44
		)
45
		)
45
		self.Add(_frequency_control)
46
		self.Add(_frequency_control)
46
		_ampl_control = grc_wxgui.slider_horizontal_control(
47
		_ampl_control = grc_wxgui.slider_horizontal_control(
47
			window=self.GetWin(),
48
			window=self.GetWin(),
48
			callback=self.set_ampl,
49
			callback=self.set_ampl,
49
			label="Volume",
50
			label="Volume",
50
			value=ampl,
51
			value=ampl,
51
			min=0,
52
			min=0,
52
			max=.5,
53
			max=.5,
53
			num_steps=100,
54
			num_steps=100,
54
			slider_length=200,
55
			slider_length=200,
55
		)
56
		)
56
		self.GridAdd(_ampl_control, 0, 0, 1, 2)
57
		self.GridAdd(_ampl_control, 0, 0, 1, 2)
57
 
58
 
58
		##################################################
59
		##################################################
59
		# Blocks
60
		# Blocks
60
		##################################################
61
		##################################################
61
		self.audio_sink = audio.sink(48000, "hw:1,0", True)
62
		self.audio_sink = audio.sink(48000, "hw:1,0", True)
62
		self.audio_source_0 = audio.source(48000, "hw:1,0", True)
63
		self.audio_source_0 = audio.source(48000, "hw:1,0", True)
63
		self.gr_sig_source_x = gr.sig_source_f(samp_rate, gr.GR_SIN_WAVE, frequency, ampl, 0)
64
		self.gr_sig_source_x = gr.sig_source_f(samp_rate, gr.GR_SIN_WAVE, frequency, ampl, 0)
64
		self.wxgui_scopesink2_0 = scopesink2.scope_sink_f(
65
		self.wxgui_scopesink2_0 = scopesink2.scope_sink_f(
65
			self.GetWin(),
66
			self.GetWin(),
66
			title="Scope Plot",
67
			title="Scope Plot",
67
			sample_rate=samp_rate*2,
68
			sample_rate=samp_rate*2,
68
			frame_decim=15,
69
			frame_decim=15,
69
			v_scale=None,
70
			v_scale=None,
70
			t_scale=.0001,
71
			t_scale=.0001,
71
			num_inputs=2,
72
			num_inputs=2,
72
		)
73
		)
73
		self.wxgui_scopesink2_0.win.set_format_line()
74
		self.wxgui_scopesink2_0.win.set_format_line()
74
		self.Add(self.wxgui_scopesink2_0.win)
75
		self.Add(self.wxgui_scopesink2_0.win)
-
 
76
		self.wxgui_waterfallsink2_0 = waterfallsink2.waterfall_sink_f(
-
 
77
			self.GetWin(),
-
 
78
			baseband_freq=0,
-
 
79
			y_per_div=10,
-
 
80
			ref_level=50,
-
 
81
			sample_rate=samp_rate,
-
 
82
			fft_size=512,
-
 
83
			fft_rate=15,
-
 
84
			average=True,
-
 
85
			avg_alpha=None,
-
 
86
			title="Waterfall Plot",
-
 
87
		)
-
 
88
		self.Add(self.wxgui_waterfallsink2_0.win)
75
 
89
 
76
		##################################################
90
		##################################################
77
		# Connections
91
		# Connections
78
		##################################################
92
		##################################################
79
		self.connect((self.gr_sig_source_x, 0), (self.audio_sink, 0))
93
		self.connect((self.gr_sig_source_x, 0), (self.audio_sink, 0))
80
		self.connect((self.gr_sig_source_x, 0), (self.wxgui_scopesink2_0, 0))
94
		self.connect((self.gr_sig_source_x, 0), (self.wxgui_scopesink2_0, 0))
81
		self.connect((self.audio_source_0, 0), (self.wxgui_scopesink2_0, 1))
95
		self.connect((self.audio_source_0, 0), (self.wxgui_scopesink2_0, 1))
-
 
96
		self.connect((self.audio_source_0, 0), (self.wxgui_waterfallsink2_0, 0))
82
 
97
 
83
	def set_samp_rate(self, samp_rate):
98
	def set_samp_rate(self, samp_rate):
84
		self.samp_rate = samp_rate
99
		self.samp_rate = samp_rate
85
		self.gr_sig_source_x.set_sampling_freq(self.samp_rate)
100
		self.gr_sig_source_x.set_sampling_freq(self.samp_rate)
86
		self.wxgui_scopesink2_0.set_sample_rate(self.samp_rate*2)
101
		self.wxgui_scopesink2_0.set_sample_rate(self.samp_rate*2)
-
 
102
		self.wxgui_waterfallsink2_0.set_sample_rate(self.samp_rate)
87
 
103
 
88
	def set_frequency(self, frequency):
104
	def set_frequency(self, frequency):
89
		self.frequency = frequency
105
		self.frequency = frequency
90
		self.gr_sig_source_x.set_frequency(self.frequency)
106
		self.gr_sig_source_x.set_frequency(self.frequency)
91
 
107
 
92
	def set_ampl(self, ampl):
108
	def set_ampl(self, ampl):
93
		self.ampl = ampl
109
		self.ampl = ampl
94
		self.gr_sig_source_x.set_amplitude(self.ampl)
110
		self.gr_sig_source_x.set_amplitude(self.ampl)
95
 
111
 
96
if __name__ == '__main__':
112
if __name__ == '__main__':
97
	if gr.enable_realtime_scheduling() != gr.RT_OK:
113
	if gr.enable_realtime_scheduling() != gr.RT_OK:
98
		print "Error: failed to enable realtime scheduling."
114
		print "Error: failed to enable realtime scheduling."
99
	tb = Sonar()
115
	tb = Sonar()
100
	tb.Run()
116
	tb.Run()
101
 
117