#!/usr/bin/env python
#
# Copyright 2004,2005,2007 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
# GNU Radio is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
#
# GNU Radio is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with GNU Radio; see the file COPYING. If not, write to
# the Free Software Foundation, Inc., 51 Franklin Street,
# Boston, MA 02110-1301, USA.
#
from gnuradio import gr, gru, audio
from gnuradio import eng_notation
from gnuradio.eng_option import eng_option
from gnuradio.wxgui import stdgui2, fftsink2, waterfallsink2, scopesink2, form, slider
from optparse import OptionParser
import wx
import sys
import time
#import ephem
class app_top_block(stdgui2.std_top_block):
def __init__(self, frame, panel, vbox, argv):
stdgui2.std_top_block.__init__(self, frame, panel, vbox, argv)
self.frame = frame
self.panel = panel
parser = OptionParser(option_class=eng_option)
parser.add_option("-O", "--audio-output", type="string", default="",
help="pcm output device name. E.g., hw:0,0 or /dev/dsp")
parser.add_option("-W", "--waterfall", action="store_true", default=False,
help="Enable waterfall display")
parser.add_option("-S", "--oscilloscope", action="store_true", default=False,
help="Enable oscilloscope display")
parser.add_option("-I", "--audio-input", type="string", default="",
help="pcm input device name. E.g., hw:0,0 or /dev/dsp")
parser.add_option("-r", "--sample-rate", type="eng_float", default=48000,
help="set sample rate to RATE (48000)")
parser.add_option("-X", "--prefix", default="./")
(options, args) = parser.parse_args()
sample_rate = 48000 #int(options.sample_rate)
# Set prefix for data files
self.prefix = options.prefix
if len(args) != 0:
parser.print_help()
sys.exit(1)
self.show_debug_info = True
# build the graph
lo_freq1 = 16400
lo_freq2 = 18300
lo_freq3 = 19550
lo_freq4 = 20900
lo_freq5 = 22100
lo_freq6 = 23400
self.audioin = audio.source (sample_rate, options.audio_input)
lo_bw=150
bw_down=100
if_rate = 1000
if_decim = sample_rate/if_rate
input_rate=if_rate
integ_rate=1
N = input_rate/integ_rate
t = range(0,N-1)
tapsN = []
for i in t:
tapsN.append(1.0/N)
conv=gr.complex_to_real()
#RXBLOK ZACIATOK1
self.mygain1=gr.multiply_const_ff(3000)
#gain, sampling_freq, low_cutoff_freq, high_cutoff_freq,transition_width, window, beta
channel_coeffs_bp1=gr.firdes.band_pass( 1, sample_rate, lo_freq1-lo_bw, lo_freq1+lo_bw, bw_down, gr.firdes.WIN_HANN, 6.76)
#audio_decimation, audio_coeffs
mybandpass1 = gr.fir_filter_fff (1, channel_coeffs_bp1)
channel_coeffs1 = gr.firdes.low_pass (20.0, sample_rate, 400, 100, gr.firdes.WIN_HANN)
ddc1 = gr.freq_xlating_fir_filter_fcf (if_decim, channel_coeffs1, lo_freq1-lo_bw-bw_down, sample_rate)
self.detector1 = gr.complex_to_mag_squared()
self.integrator11 = gr.fir_filter_fff (N, tapsN)
self.integrator31 = gr.single_pole_iir_filter_ff(1)
self.probe1 = gr.probe_signal_f();
self.connect(self.audioin, self.mygain1, mybandpass1, ddc1, self.detector1, self.integrator11, self.integrator31, self.probe1)
#RXBLOK KONIEC
#RXBLOK ZACIATOK2
self.mygain2=gr.multiply_const_ff(3000)
#gain, sampling_freq, low_cutoff_freq, high_cutoff_freq,transition_width, window, beta
channel_coeffs_bp2=gr.firdes.band_pass( 1, sample_rate, lo_freq2-lo_bw, lo_freq2+lo_bw, bw_down, gr.firdes.WIN_HANN, 6.76)
#audio_decimation, audio_coeffs
mybandpass2 = gr.fir_filter_fff (1, channel_coeffs_bp2)
channel_coeffs2 = gr.firdes.low_pass (20.0, sample_rate, 400, 100, gr.firdes.WIN_HANN)
ddc2 = gr.freq_xlating_fir_filter_fcf (if_decim, channel_coeffs2, lo_freq2-lo_bw-bw_down, sample_rate)
self.detector2 = gr.complex_to_mag_squared()
self.integrator12 = gr.fir_filter_fff (N, tapsN)
self.integrator32 = gr.single_pole_iir_filter_ff(1)
self.probe2 = gr.probe_signal_f();
self.connect(self.audioin, self.mygain2, mybandpass2, ddc2, self.detector2, self.integrator12, self.integrator32, self.probe2)
#RXBLOK KONIEC
#RXBLOK ZACIATOK3
self.mygain3=gr.multiply_const_ff(3000)
#gain, sampling_freq, low_cutoff_freq, high_cutoff_freq,transition_width, window, beta
channel_coeffs_bp3=gr.firdes.band_pass( 1, sample_rate, lo_freq3-lo_bw, lo_freq3+lo_bw, bw_down, gr.firdes.WIN_HANN, 6.76)
#audio_decimation, audio_coeffs
mybandpass3 = gr.fir_filter_fff (1, channel_coeffs_bp3)
channel_coeffs3 = gr.firdes.low_pass (20.0, sample_rate, 400, 100, gr.firdes.WIN_HANN)
ddc3 = gr.freq_xlating_fir_filter_fcf (if_decim, channel_coeffs3, lo_freq3-lo_bw-bw_down, sample_rate)
self.detector3 = gr.complex_to_mag_squared()
self.integrator13 = gr.fir_filter_fff (N, tapsN)
self.integrator33 = gr.single_pole_iir_filter_ff(1)
self.probe3 = gr.probe_signal_f();
self.connect(self.audioin, self.mygain3, mybandpass3, ddc3, self.detector3, self.integrator13, self.integrator33, self.probe3)
#RXBLOK KONIEC
#RXBLOK ZACIATOK4
self.mygain4=gr.multiply_const_ff(3000)
#gain, sampling_freq, low_cutoff_freq, high_cutoff_freq,transition_width, window, beta
channel_coeffs_bp4=gr.firdes.band_pass( 1, sample_rate, lo_freq4-lo_bw+50, lo_freq4+lo_bw-50, bw_down, gr.firdes.WIN_HANN, 6.76)
#audio_decimation, audio_coeffs
mybandpass4 = gr.fir_filter_fff (1, channel_coeffs_bp4)
channel_coeffs4 = gr.firdes.low_pass (20.0, sample_rate, 400, 100, gr.firdes.WIN_HANN)
ddc4 = gr.freq_xlating_fir_filter_fcf (if_decim, channel_coeffs4, lo_freq4-lo_bw-bw_down, sample_rate)
self.detector4 = gr.complex_to_mag_squared()
self.integrator14 = gr.fir_filter_fff (N, tapsN)
self.integrator34 = gr.single_pole_iir_filter_ff(1)
self.probe4 = gr.probe_signal_f();
self.connect(self.audioin, self.mygain4, mybandpass4, ddc4, self.detector4, self.integrator14, self.integrator34, self.probe4)
#RXBLOK KONIEC
#RXBLOK ZACIATOK5
self.mygain5=gr.multiply_const_ff(3000)
#gain, sampling_freq, low_cutoff_freq, high_cutoff_freq,transition_width, window, beta
channel_coeffs_bp5=gr.firdes.band_pass( 1, sample_rate, lo_freq5-lo_bw, lo_freq5+lo_bw, bw_down, gr.firdes.WIN_HANN, 6.76)
#audio_decimation, audio_coeffs
mybandpass5 = gr.fir_filter_fff (1, channel_coeffs_bp5)
channel_coeffs5 = gr.firdes.low_pass (20.0, sample_rate, 400, 100, gr.firdes.WIN_HANN)
ddc5 = gr.freq_xlating_fir_filter_fcf (if_decim, channel_coeffs5, lo_freq5-lo_bw-bw_down, sample_rate)
self.detector5 = gr.complex_to_mag_squared()
self.integrator15 = gr.fir_filter_fff (N, tapsN)
self.integrator35 = gr.single_pole_iir_filter_ff(1)
self.probe5 = gr.probe_signal_f();
self.connect(self.audioin, self.mygain5, mybandpass5, ddc5, self.detector5, self.integrator15, self.integrator35, self.probe5)
#RXBLOK KONIEC
#RXBLOK ZACIATOK6
self.mygain6=gr.multiply_const_ff(3000)
#gain, sampling_freq, low_cutoff_freq, high_cutoff_freq,transition_width, window, beta
channel_coeffs_bp6=gr.firdes.band_pass( 1, sample_rate, lo_freq6-lo_bw, lo_freq6+lo_bw, bw_down, gr.firdes.WIN_HANN, 6.76)
#audio_decimation, audio_coeffs
mybandpass6 = gr.fir_filter_fff (1, channel_coeffs_bp6)
channel_coeffs6 = gr.firdes.low_pass (20.0, sample_rate, 400, 100, gr.firdes.WIN_HANN)
ddc6 = gr.freq_xlating_fir_filter_fcf (if_decim, channel_coeffs6, lo_freq6-lo_bw-bw_down, sample_rate)
self.detector6 = gr.complex_to_mag_squared()
self.integrator16 = gr.fir_filter_fff (N, tapsN)
self.integrator36 = gr.single_pole_iir_filter_ff(1)
self.probe6 = gr.probe_signal_f();
self.connect(self.audioin, self.mygain6, mybandpass6, ddc6, self.detector6, self.integrator16, self.integrator36, self.probe6)
#RXBLOK KONIEC
#self.scopefft = fftsink2.fft_sink_f (panel, fft_size=512, sample_rate=1000, fft_rate=1)
#self.connect(ddc6, conv, self.scopefft)
self._build_gui(vbox)
# set initial values
def _set_status_msg(self, msg):
self.frame.GetStatusBar().SetStatusText(msg, 0)
def _build_gui(self, vbox):
#vbox.Add(self.scopefft.win, 10, wx.EXPAND)
self.lmst_timer = wx.PyTimer(self.lmst_timeout)
self.lmst_timer.Start(1000)
def lmst_timeout(self):
self.write_continuum_data(self.probe1.level(),self.probe2.level(),self.probe3.level(),self.probe4.level(),self.probe5.level(),self.probe6.level())
def write_continuum_data(self,data1,data2,data3,data4,data5,data6):
# Create localtime structure for producing filename
foo = time.localtime()
pfx = self.prefix
filenamestr = "%s/%04d%02d%02d" % (pfx, foo.tm_year,
foo.tm_mon, foo.tm_mday)
# Open the data file, appending
continuum_file = open (filenamestr+".tpdat","a")
flt1 = "%8.4f" % data1
flt2 = "%8.4f" % data2
flt3 = "%8.4f" % data3
flt4 = "%8.4f" % data4
flt5 = "%8.4f" % data5
flt6 = "%8.4f" % data6
timestampstr = "%02d:%02d:%02d" % (foo.tm_hour, foo.tm_min, foo.tm_sec)
continuum_file.write(timestampstr+" "+flt1+" "+flt2+" "+flt3+" "+flt4+" "+flt5+" "+flt6+"\n")
continuum_file.close()
return(data1)
def main ():
app = stdgui2.stdapp(app_top_block, "Audio FFT", nstatus=1)
app.MainLoop()
if __name__ == '__main__':
main ()