Created
March 19, 2016 18:34
-
-
Save watson0x90/69003505f618255ca529 to your computer and use it in GitHub Desktop.
SimpleRadio
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
################################################## | |
# Gnuradio Python Flow Graph | |
# Title: Top Block | |
# Generated: Sat Mar 19 12:29:45 2016 | |
################################################## | |
from gnuradio import analog | |
from gnuradio import audio | |
from gnuradio import blocks | |
from gnuradio import eng_notation | |
from gnuradio import filter | |
from gnuradio import gr | |
from gnuradio import wxgui | |
from gnuradio.eng_option import eng_option | |
from gnuradio.fft import window | |
from gnuradio.filter import firdes | |
from gnuradio.wxgui import fftsink2 | |
from gnuradio.wxgui import forms | |
from grc_gnuradio import wxgui as grc_wxgui | |
from optparse import OptionParser | |
import osmosdr | |
import wx | |
class top_block(grc_wxgui.top_block_gui): | |
def __init__(self): | |
grc_wxgui.top_block_gui.__init__(self, title="Top Block") | |
_icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png" | |
self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY)) | |
################################################## | |
# Variables | |
################################################## | |
self.channel_tune = channel_tune = 96.3e6 | |
self.samp_rate = samp_rate = 4e6 | |
self.channel_width = channel_width = 200e3 | |
self.channel_freq = channel_freq = channel_tune | |
self.center_freq = center_freq = 97.9e6 | |
self.audio_gain = audio_gain = 1 | |
################################################## | |
# Blocks | |
################################################## | |
_audio_gain_sizer = wx.BoxSizer(wx.VERTICAL) | |
self._audio_gain_text_box = forms.text_box( | |
parent=self.GetWin(), | |
sizer=_audio_gain_sizer, | |
value=self.audio_gain, | |
callback=self.set_audio_gain, | |
label='audio_gain', | |
converter=forms.float_converter(), | |
proportion=0, | |
) | |
self._audio_gain_slider = forms.slider( | |
parent=self.GetWin(), | |
sizer=_audio_gain_sizer, | |
value=self.audio_gain, | |
callback=self.set_audio_gain, | |
minimum=0, | |
maximum=10, | |
num_steps=100, | |
style=wx.SL_HORIZONTAL, | |
cast=float, | |
proportion=1, | |
) | |
self.Add(_audio_gain_sizer) | |
self.wxgui_fftsink2_0_0 = fftsink2.fft_sink_c( | |
self.GetWin(), | |
baseband_freq=channel_freq, | |
y_per_div=10, | |
y_divs=10, | |
ref_level=0, | |
ref_scale=2.0, | |
sample_rate=samp_rate, | |
fft_size=1024, | |
fft_rate=15, | |
average=True, | |
avg_alpha=None, | |
title="FFT Plot", | |
peak_hold=False, | |
) | |
self.Add(self.wxgui_fftsink2_0_0.win) | |
self.rational_resampler_xxx_0 = filter.rational_resampler_ccc( | |
interpolation=12, | |
decimation=5, | |
taps=None, | |
fractional_bw=None, | |
) | |
self.osmosdr_source_0 = osmosdr.source( args="numchan=" + str(1) + " " + "" ) | |
self.osmosdr_source_0.set_sample_rate(samp_rate) | |
self.osmosdr_source_0.set_center_freq(center_freq, 0) | |
self.osmosdr_source_0.set_freq_corr(0, 0) | |
self.osmosdr_source_0.set_dc_offset_mode(0, 0) | |
self.osmosdr_source_0.set_iq_balance_mode(0, 0) | |
self.osmosdr_source_0.set_gain_mode(False, 0) | |
self.osmosdr_source_0.set_gain(0, 0) | |
self.osmosdr_source_0.set_if_gain(20, 0) | |
self.osmosdr_source_0.set_bb_gain(20, 0) | |
self.osmosdr_source_0.set_antenna("", 0) | |
self.osmosdr_source_0.set_bandwidth(0, 0) | |
self.low_pass_filter_0 = filter.fir_filter_ccf(int(samp_rate/channel_width), firdes.low_pass( | |
1, samp_rate, 75e3, 25e3, firdes.WIN_HAMMING, 6.76)) | |
_channel_tune_sizer = wx.BoxSizer(wx.VERTICAL) | |
self._channel_tune_text_box = forms.text_box( | |
parent=self.GetWin(), | |
sizer=_channel_tune_sizer, | |
value=self.channel_tune, | |
callback=self.set_channel_tune, | |
label="channel_tune", | |
converter=forms.float_converter(), | |
proportion=0, | |
) | |
self._channel_tune_slider = forms.slider( | |
parent=self.GetWin(), | |
sizer=_channel_tune_sizer, | |
value=self.channel_tune, | |
callback=self.set_channel_tune, | |
minimum=89.1e6, | |
maximum=109.1e6, | |
num_steps=100, | |
style=wx.SL_HORIZONTAL, | |
cast=float, | |
proportion=1, | |
) | |
self.Add(_channel_tune_sizer) | |
self.blocks_multiply_xx_0 = blocks.multiply_vcc(1) | |
self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vff((audio_gain, )) | |
self.audio_sink_0 = audio.sink(48000, "", True) | |
self.analog_wfm_rcv_0 = analog.wfm_rcv( | |
quad_rate=480e3, | |
audio_decimation=10, | |
) | |
self.analog_sig_source_x_0 = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, center_freq - channel_freq, 1, 0) | |
################################################## | |
# Connections | |
################################################## | |
self.connect((self.osmosdr_source_0, 0), (self.blocks_multiply_xx_0, 0)) | |
self.connect((self.analog_sig_source_x_0, 0), (self.blocks_multiply_xx_0, 1)) | |
self.connect((self.blocks_multiply_xx_0, 0), (self.wxgui_fftsink2_0_0, 0)) | |
self.connect((self.blocks_multiply_xx_0, 0), (self.low_pass_filter_0, 0)) | |
self.connect((self.low_pass_filter_0, 0), (self.rational_resampler_xxx_0, 0)) | |
self.connect((self.rational_resampler_xxx_0, 0), (self.analog_wfm_rcv_0, 0)) | |
self.connect((self.analog_wfm_rcv_0, 0), (self.blocks_multiply_const_vxx_0, 0)) | |
self.connect((self.blocks_multiply_const_vxx_0, 0), (self.audio_sink_0, 0)) | |
def get_channel_tune(self): | |
return self.channel_tune | |
def set_channel_tune(self, channel_tune): | |
self.channel_tune = channel_tune | |
self.set_channel_freq(self.channel_tune) | |
self._channel_tune_slider.set_value(self.channel_tune) | |
self._channel_tune_text_box.set_value(self.channel_tune) | |
def get_samp_rate(self): | |
return self.samp_rate | |
def set_samp_rate(self, samp_rate): | |
self.samp_rate = samp_rate | |
self.osmosdr_source_0.set_sample_rate(self.samp_rate) | |
self.analog_sig_source_x_0.set_sampling_freq(self.samp_rate) | |
self.wxgui_fftsink2_0_0.set_sample_rate(self.samp_rate) | |
self.low_pass_filter_0.set_taps(firdes.low_pass(1, self.samp_rate, 75e3, 25e3, firdes.WIN_HAMMING, 6.76)) | |
def get_channel_width(self): | |
return self.channel_width | |
def set_channel_width(self, channel_width): | |
self.channel_width = channel_width | |
def get_channel_freq(self): | |
return self.channel_freq | |
def set_channel_freq(self, channel_freq): | |
self.channel_freq = channel_freq | |
self.analog_sig_source_x_0.set_frequency(self.center_freq - self.channel_freq) | |
self.wxgui_fftsink2_0_0.set_baseband_freq(self.channel_freq) | |
def get_center_freq(self): | |
return self.center_freq | |
def set_center_freq(self, center_freq): | |
self.center_freq = center_freq | |
self.osmosdr_source_0.set_center_freq(self.center_freq, 0) | |
self.analog_sig_source_x_0.set_frequency(self.center_freq - self.channel_freq) | |
def get_audio_gain(self): | |
return self.audio_gain | |
def set_audio_gain(self, audio_gain): | |
self.audio_gain = audio_gain | |
self.blocks_multiply_const_vxx_0.set_k((self.audio_gain, )) | |
self._audio_gain_slider.set_value(self.audio_gain) | |
self._audio_gain_text_box.set_value(self.audio_gain) | |
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 = top_block() | |
tb.Start(True) | |
tb.Wait() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment