3 # Copyright 2004 Free Software Foundation, Inc.
5 # This file is part of GNU Radio
7 # GNU Radio is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3, or (at your option)
12 # GNU Radio is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with GNU Radio; see the file COPYING. If not, write to
19 # the Free Software Foundation, Inc., 51 Franklin Street,
20 # Boston, MA 02110-1301, USA.
23 # Demodulate an AM signal from the TVRX or a recorded file.
24 # The file format must be 256 ksps, complex data.
27 from gnuradio import gr, gru, eng_notation
28 from gnuradio import audio_oss as audio
29 from gnuradio import usrp
30 from gnuradio import tv_rx
31 from gnuradio.eng_option import eng_option
32 from optparse import OptionParser
35 from gnuradio.wxgui import stdgui, fftsink, scopesink
39 # return a gr.flow_graph
41 class wfm_rx_graph (stdgui.gui_flow_graph):
42 def __init__(self,frame,panel,vbox,argv):
43 stdgui.gui_flow_graph.__init__ (self,frame,panel,vbox,argv)
48 # Decimation rate from USRP ADC to IF.
51 # Calculate the sampling rate of the USRP and capture file.
52 # Decimate the IF sampling rate down by 4 to 64 ksps
53 # This is a flow graph that has an input (capture file) and output (audio channel).
54 #self = gr.flow_graph ()
56 # Signal source is assumed to be 256 kspb / complex data stream.
60 src = usrp.source_c (0, usrp_decim, 1, gru.hexint(0xf0f0f0f0), 0)
62 src = usrp.source_c (0, usrp_decim, 1, gru.hexint(0xf0f0f0f2), 0)
64 if_rate = 640e3 # src.adc_freq() / usrp_decim
66 demod_rate = if_rate / if_decim
69 audio_rate = demod_rate / audio_decimation
72 dboard = tv_rx.tv_rx (src, which_side)
74 (success, actual_freq) = dboard.set_freq(rf_freq)
77 if_freq = rf_freq - actual_freq
78 src.set_rx_freq (0, -if_freq)
80 print "actual freq ", actual_freq
81 print "IF freq ", if_freq
85 #src = gr.file_source (gr.sizeof_gr_complex, "samples/atis_ffz_am_baseband_256k_complex.dat")
86 #src = gr.file_source (gr.sizeof_gr_complex, "samples/garagedoor1.dat", True)
88 #channel_coeffs = gr.firdes.band_pass (
91 # 10, # center of low transition band
92 # 10000, # center of hi transition band
93 # 200, # width of transition band
94 # gr.firdes.WIN_HAMMING)
96 channel_coeffs = gr.firdes.low_pass (1.0, if_rate, 10e3, 4e3, gr.firdes.WIN_HANN)
97 print "len(channel_coeffs) = ", len(channel_coeffs)
99 # Tune to the desired frequency.
100 ddc = gr.freq_xlating_fir_filter_ccf (if_decim, channel_coeffs, -20e3, if_rate)
102 # Demodule with classic sqrt (I*I + Q*Q)
103 magblock = gr.complex_to_mag()
106 volumecontrol = gr.multiply_const_ff(.1)
109 audio_coeffs = gr.firdes.band_pass (
112 10, # center of low transition band
113 6000, # center of hi transition band
114 200, # width of transition band
115 gr.firdes.WIN_HAMMING)
118 # Low pass filter the demodulator output
119 #audio_coeffs = gr.firdes.low_pass (1.0, demod_rate, 500, 200, gr.firdes.WIN_HANN)
120 print "len(audio_coeffs) = ", len(audio_coeffs)
122 # input: float; output: float
123 audio_filter = gr.fir_filter_fff (audio_decimation, audio_coeffs)
125 # sound card as final sink
126 audio_sink = audio.sink (int (audio_rate))
128 # now wire it all together
129 self.connect (src, ddc)
130 self.connect (ddc, magblock)
131 self.connect (magblock, volumecontrol)
132 self.connect (volumecontrol, audio_filter)
133 self.connect (audio_filter, (audio_sink, 0))
135 d_win = fftsink.fft_sink_c (self, panel, title="RF", fft_size=512, sample_rate=if_rate)
136 self.connect (src,d_win)
137 vbox.Add (d_win.win, 4, wx.EXPAND)
139 p_win = fftsink.fft_sink_c (self, panel, title="IF", fft_size=512, sample_rate=demod_rate)
140 self.connect (ddc,p_win)
141 vbox.Add (p_win.win, 4, wx.EXPAND)
143 r_win = fftsink.fft_sink_f (self, panel, title="Audio", fft_size=512, sample_rate=audio_rate)
144 self.connect (audio_filter,r_win)
145 vbox.Add (r_win.win, 4, wx.EXPAND)
147 #audio_oscope = scopesink.scope_sink_f (self, panel, "Oscope Data", audio_rate)
148 #self.connect (audio_filter, audio_oscope)
149 #vbox.Add (audio_oscope.win, 4, wx.EXPAND)
151 if __name__ == '__main__':
153 app = stdgui.stdapp (wfm_rx_graph, "TVRX AM RX")