Subversion Repositories svnkaklik

Rev

Rev 515 | Details | Compare with Previous | Last modification | View Log

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