def test_000(self): N = 10000 # number of samples to use M = 5 # Number of channels fs = 1000 # baseband sampling rate ofs = M * fs # input samp rate to decimator taps = filter.firdes.low_pass_2( M, ofs, fs / 2, fs / 10, attenuation_dB=80, window=filter.firdes.WIN_BLACKMAN_hARRIS ) signals = list() freqs = [0, 100, 200, -200, -100] for i in xrange(len(freqs)): data = sig_source_c(fs, freqs[i], 1, N) signals.append(blocks.vector_source_c(data)) pfb = filter.pfb_synthesizer_ccf(M, taps) snk = blocks.vector_sink_c() for i in xrange(M): self.tb.connect(signals[i], (pfb, i)) self.tb.connect(pfb, snk) self.tb.run() # Adjusted phase rotations for data p0 = 0 p1 = 2 * math.pi * 1.0 / M p2 = 2 * math.pi * 2.0 / M p3 = 2 * math.pi * 3.0 / M p4 = 2 * math.pi * 4.0 / M Ntest = 1000 L = len(snk.data()) t = map(lambda x: float(x) / ofs, xrange(L)) # Create known data as sum of complex sinusoids at freqs # of the output channels. freqs = [-2200, -1100, 0, 1100, 2200] expected_data = len(t) * [0] for i in xrange(len(t)): expected_data[i] = ( math.cos(2.0 * math.pi * freqs[0] * t[i] + p3) + 1j * math.sin(2.0 * math.pi * freqs[0] * t[i] + p3) + math.cos(2.0 * math.pi * freqs[1] * t[i] + p4) + 1j * math.sin(2.0 * math.pi * freqs[1] * t[i] + p4) + math.cos(2.0 * math.pi * freqs[2] * t[i] + p0) + 1j * math.sin(2.0 * math.pi * freqs[2] * t[i] + p0) + math.cos(2.0 * math.pi * freqs[3] * t[i] + p1) + 1j * math.sin(2.0 * math.pi * freqs[3] * t[i] + p1) + math.cos(2.0 * math.pi * freqs[4] * t[i] + p2) + 1j * math.sin(2.0 * math.pi * freqs[4] * t[i] + p2) ) dst_data = snk.data() self.assertComplexTuplesAlmostEqual(expected_data[2000 : 2000 + Ntest], dst_data[2000 : 2000 + Ntest], 4)
def test_000(self): N = 10000 # number of samples to use M = 5 # Number of channels fs = 1000 # baseband sampling rate ofs = M*fs # input samp rate to decimator taps = filter.firdes.low_pass_2(M, ofs, fs / 2, fs / 10, attenuation_dB=80, window=filter.firdes.WIN_BLACKMAN_hARRIS) signals = list() freqs = [0, 100, 200, -200, -100] for i in range(len(freqs)): data = sig_source_c(fs, freqs[i], 1, N) signals.append(blocks.vector_source_c(data)) pfb = filter.pfb_synthesizer_ccf(M, taps) snk = blocks.vector_sink_c() for i in range(M): self.tb.connect(signals[i], (pfb,i)) self.tb.connect(pfb, snk) self.tb.run() # Adjusted phase rotations for data p0 = 0 p1 = 2*math.pi*1.0/M p2 = 2*math.pi*2.0/M p3 = 2*math.pi*3.0/M p4 = 2*math.pi*4.0/M Ntest = 1000 L = len(snk.data()) t = [float(x) / ofs for x in range(L)] # Create known data as sum of complex sinusoids at freqs # of the output channels. freqs = [-2200, -1100, 0, 1100, 2200] expected_data = len(t)*[0,] for i in range(len(t)): expected_data[i] = math.cos(2.*math.pi*freqs[0]*t[i] + p3) + \ 1j*math.sin(2.*math.pi*freqs[0]*t[i] + p3) + \ math.cos(2.*math.pi*freqs[1]*t[i] + p4) + \ 1j*math.sin(2.*math.pi*freqs[1]*t[i] + p4) + \ math.cos(2.*math.pi*freqs[2]*t[i] + p0) + \ 1j*math.sin(2.*math.pi*freqs[2]*t[i] + p0) + \ math.cos(2.*math.pi*freqs[3]*t[i] + p1) + \ 1j*math.sin(2.*math.pi*freqs[3]*t[i] + p1) + \ math.cos(2.*math.pi*freqs[4]*t[i] + p2) + \ 1j*math.sin(2.*math.pi*freqs[4]*t[i] + p2) dst_data = snk.data() self.assertComplexTuplesAlmostEqual(expected_data[2000:2000+Ntest], dst_data[2000:2000+Ntest], 4)
def main(): N = 1000000 fs = 8000 freqs = [100, 200, 300, 400, 500] nchans = 7 sigs = list() for fi in freqs: s = gr.sig_source_c(fs, gr.GR_SIN_WAVE, fi, 1) sigs.append(s) taps = filter.firdes.low_pass_2(len(freqs), fs, fs / float(nchans) / 2, 100, 100) print "Num. Taps = %d (taps per filter = %d)" % (len(taps), len(taps) / nchans) filtbank = filter.pfb_synthesizer_ccf(nchans, taps) head = gr.head(gr.sizeof_gr_complex, N) snk = gr.vector_sink_c() tb = gr.top_block() tb.connect(filtbank, head, snk) for i, si in enumerate(sigs): tb.connect(si, (filtbank, i)) tb.run() if 1: f1 = pylab.figure(1) s1 = f1.add_subplot(1, 1, 1) s1.plot(snk.data()[1000:]) fftlen = 2048 f2 = pylab.figure(2) s2 = f2.add_subplot(1, 1, 1) winfunc = scipy.blackman s2.psd(snk.data()[10000:], NFFT=fftlen, Fs=nchans * fs, noverlap=fftlen / 4, window=lambda d: d * winfunc(fftlen)) pylab.show()
def __init__(self, params, filename): # Super gr.hier_block2.__init__( self, "PFBOutputBranch", gr.io_signature(params.width, params.width, gr.sizeof_gr_complex), gr.io_signature(0, 0, 0)) prev = self # Synthesizer if params.width > 1: self.synth = filter.pfb_synthesizer_ccf( params.width_synth, params.taps_synth, True # 2x oversample ) for i in range(params.width): self.connect((prev, i), (self.synth, i)) prev = self.synth # Delay if params.delay: self.delay = blocks.delay( gr.sizeof_gr_complex, int(round(params.delay * params.width_synth)), ) self.connect((prev, 0), (self.delay, 0)) prev = self.delay # Post synth rotation if params.rotation != 0: self.rotator = blocks.rotator_cc(params.rotation) self.connect((prev, 0), (self.rotator, 0)) prev = self.rotator # PFB Arb Resampler if params.resamp != 1: self.resamp = pfb.arb_resampler_ccf(params.resamp, params.taps_resamp, flt_size=32) self.connect((prev, 0), (self.resamp, 0)) prev = self.resamp # Output file self.sink = blocks.file_sink(gr.sizeof_gr_complex, filename, False) self.connect((prev, 0), (self.sink, 0))
def main(): N = 1000000 fs = 8000 freqs = [100, 200, 300, 400, 500] nchans = 7 sigs = list() for fi in freqs: s = analog.sig_source_c(fs, analog.GR_SIN_WAVE, fi, 1) sigs.append(s) taps = filter.firdes.low_pass_2(len(freqs), fs, fs/float(nchans)/2, 100, 100) print("Num. Taps = %d (taps per filter = %d)" % (len(taps), len(taps) / nchans)) filtbank = filter.pfb_synthesizer_ccf(nchans, taps) head = blocks.head(gr.sizeof_gr_complex, N) snk = blocks.vector_sink_c() tb = gr.top_block() tb.connect(filtbank, head, snk) for i,si in enumerate(sigs): tb.connect(si, (filtbank, i)) tb.run() if 1: f1 = pyplot.figure(1) s1 = f1.add_subplot(1,1,1) s1.plot(snk.data()[1000:]) fftlen = 2048 f2 = pyplot.figure(2) s2 = f2.add_subplot(1,1,1) winfunc = numpy.blackman s2.psd(snk.data()[10000:], NFFT=fftlen, Fs = nchans*fs, noverlap=fftlen / 4, window = lambda d: d*winfunc(fftlen)) pyplot.show()
def __init__(self, args): gr.top_block.__init__(self, "Nordic Single-Channel Receiver Example") self.freq = 2414e6 self.gain = args.gain self.symbol_rate = 2e6 self.sample_rate = 4e6 # Channel map channel_count = 3 channel_map = [14, 18, 10] # Data rate index dr = 2 # 2M # SDR sink (gr-osmosdr sink) self.osmosdr_sink = osmosdr.sink() self.osmosdr_sink.set_sample_rate(self.sample_rate * channel_count) self.osmosdr_sink.set_center_freq(self.freq) self.osmosdr_sink.set_gain(self.gain) self.osmosdr_sink.set_antenna('TX/RX') # PFB channelizer taps = firdes.low_pass_2(1, self.sample_rate, self.symbol_rate / 2, 100e3, 30) self.synthesizer = filter.pfb_synthesizer_ccf(channel_count, taps) # Modulators and packet framers self.nordictap_transmitter = nordictap_transmitter(channel_map) self.mods = [] self.tx = nordic.nordic_tx(channel_count) for x in range(channel_count): self.mods.append(digital.gfsk_mod()) self.connect((self.tx, x), self.mods[x]) self.connect(self.mods[x], (self.synthesizer, x)) self.connect(self.synthesizer, self.osmosdr_sink) # Wire up output packet connection self.msg_connect(self.nordictap_transmitter, "nordictap_out", self.tx, "nordictap_in")
def main(): N = 10000 fs = 100e3 Ts = 1.0/fs t = scipy.arange(0, N*Ts, Ts) # When playing with the number of channels, be careful about the # filter specs and the channel map of the synthesizer set below. # The two synthesis filterbanks must also each have an even number # of channels. nchans = 6 nchans0 = 4 nchans1 = nchans - nchans0 # Build the filters bw = fs/2 # Bandwidth of the channel tb = fs/5 #20e3 proto_taps = filter.firdes.low_pass_2(1, nchans*fs, bw, tb, 80, filter.firdes.WIN_BLACKMAN_hARRIS) # Each synthesis filter is based on the number of channels it will # recombine. syn0_taps = filter.firdes.low_pass_2(nchans/2, nchans0*fs, bw, tb, 80, filter.firdes.WIN_BLACKMAN_hARRIS) syn1_taps = filter.firdes.low_pass_2(nchans/2, nchans1*fs, bw, tb, 80, filter.firdes.WIN_BLACKMAN_hARRIS) tpc = int(scipy.ceil(len(proto_taps)/float(nchans))) print "Filter length: ", len(proto_taps) print "Taps/Channel: {0} ({1})".format(tpc, len(proto_taps)/float(nchans)) # Construct the filterbanks channelizer = filter.pfb.channelizer_ccf(nchans, proto_taps, 2) synthesizer0 = filter.pfb_synthesizer_ccf(nchans0, syn0_taps, True) synthesizer1 = filter.pfb_synthesizer_ccf(nchans1, syn1_taps, True) synthesizer0.set_channel_map([ 7, 0, 1, 2, 3, 4, 5, 6]) nfft = 10000 src = blocks.vector_source_c(10*[0,] + [1,] + (nfft-11)*[0,], False) snk0 = blocks.vector_sink_c() snk1 = blocks.vector_sink_c() tb = gr.top_block() tb.connect(src, channelizer) tb.connect(synthesizer0, snk0) tb.connect(synthesizer1, snk1) snks = [] # Plug the first nchans0 channels from the channelizer to the # first synthesis filterbank. for i in xrange(nchans0): snks.append(blocks.vector_sink_c()) tb.connect((channelizer,i), snks[i]) tb.connect((channelizer,i), (synthesizer0,i)) # Now connect the last nchans - nchans0 channels into the second # synthesis filterbank. j = 0 for i in xrange(nchans0, nchans): snks.append(blocks.vector_sink_c()) tb.connect((channelizer,i), snks[i]) tb.connect((channelizer,i), (synthesizer1,j)) j += 1 tb.run() # Set axes (and other default) fonts font = {'size': 18} matplotlib.rc('font', **font) # Plot original prototype filter used in the channelizer fig1 = plt.figure(1, figsize=(12,10), facecolor='w') sp11 = fig1.add_subplot(1,1,1) H = 20.0*scipy.log10(abs(fftpack.fftshift(fftpack.fft(proto_taps, nfft)))) freq = scipy.linspace(-2*nchans*fs/2, 2*fs*nchans/2, nfft) sp11.plot(freq, H, linewidth=3) sp11.grid() sp11.set_xlim([-2*nchans*fs/2, 2*fs*nchans/2]) sp11.set_ylim([-160, 20]) sp11.set_xlabel("Frequency (Hz)", fontsize=18, fontweight='bold') sp11.set_ylabel("Magnitude (dB)", fontsize=18, fontweight='bold') # Plot the results. We will plot each channelizer output on one # subfigure and the output of each synthesis filterbank in two # other subfigures so that we can properly represent the frequency # domain or each. fig2 = plt.figure(2, figsize=(12,10), facecolor='w') data = [] sp21 = plt.subplot2grid((2,2), (0,0), colspan=2) sp22 = plt.subplot2grid((2,2), (1,0)) sp23 = plt.subplot2grid((2,2), (1,1)) for i in xrange(nchans): data.append(scipy.array(snks[i].data())) X = 10.0*scipy.log10(abs(fftpack.fftshift(fftpack.fft(data[0], nfft)))) freq = scipy.linspace(-2*fs/2, 2*fs/2, nfft) if(i == nchans/2): f0 = scipy.linspace(fs*(nchans/2 - 1), fs*(nchans/2), nfft/2) f1 = scipy.linspace(-fs*(nchans/2), -fs*(nchans/2 - 1), nfft/2) p = sp21.plot(f0, X[0:nfft/2], linewidth=2) sp21.plot(f1, X[nfft/2:nfft], color=p[0].get_color(), linewidth=2) else: x = i if(x > nchans/2): x -= nchans f0 = scipy.linspace(-fs, fs, nfft) f0 = f0 + x*fs sp21.plot(f0, X, linewidth=2) data_s0 = scipy.array(snk0.data()) Y0 = 10.0*scipy.log10(abs(fftpack.fftshift(fftpack.fft(data_s0, nfft)))) data_s1 = scipy.array(snk1.data()) Y1 = 10.0*scipy.log10(abs(fftpack.fftshift(fftpack.fft(data_s1, nfft)))) freq0 = scipy.linspace(-2*nchans0*fs/2, 2*fs*nchans0/2, nfft) freq1 = scipy.linspace(-2*nchans1*fs/2, 2*fs*nchans1/2, nfft) sp22.plot(freq0, Y0, linewidth=3) sp23.plot(freq1, Y1, linewidth=3) sp21.grid() sp21.set_xticks(map(lambda x: x*fs, range(-nchans/2, nchans/2+1))) #sp21.set_xticklabels([-nchans*fs/2/1000, -nchans*fs/4/1000, 0, nchans*fs/4/1000, fs*nchans/2/1000]) sp21.set_xticklabels(map(lambda x: x*fs/1000.0, range(-nchans/2, nchans/2+1))) sp22.grid() sp22.set_xlim([-2*nchans0*fs/2, 2*nchans0*fs/2]) sp22.set_ylim([-80, 5]) sp22.set_xticks(map(lambda x: x*fs, range(-2*nchans0/2, 2*nchans0/2+1, 2))) sp22.set_xticklabels(map(lambda x: x*fs/1000.0, range(-2*nchans0/2, 2*nchans0/2+1, 2))) sp23.grid() sp23.set_xlim([-2*nchans1*fs/2, 2*nchans1*fs/2]) sp23.set_ylim([-80, 5]) sp23.set_xticks(map(lambda x: x*fs, range(-2*nchans1/2, 2*nchans1/2+1, 1))) sp23.set_xticklabels(map(lambda x: x*fs/1000.0, range(-2*nchans1/2, 2*nchans1/2+1, 1))) sp21.set_xlabel("Frequency (kHz)", fontsize=18, fontweight='bold') sp21.set_ylabel("Magnitude (dB)", fontsize=18, fontweight='bold') sp22.set_xlabel("Frequency (kHz)", fontsize=18, fontweight='bold') sp22.set_ylabel("Magnitude (dB)", fontsize=18, fontweight='bold') sp23.set_xlabel("Frequency (kHz)", fontsize=18, fontweight='bold') sp23.set_ylabel("Magnitude (dB)", fontsize=18, fontweight='bold') fig1.tight_layout() fig2.tight_layout() #fig1.savefig("2x_prototype_filter.png", # dpi=300, format='png', # facecolor='w', edgecolor='w') # fig2.savefig("2x_chan_and_synth.png", dpi=300, format='png', facecolor='w', edgecolor='w') plt.show()
def __init__(self): gr.top_block.__init__(self, "Not titled yet") Qt.QWidget.__init__(self) self.setWindowTitle("Not titled yet") qtgui.util.check_set_qss() try: self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc')) except: pass self.top_scroll_layout = Qt.QVBoxLayout() self.setLayout(self.top_scroll_layout) self.top_scroll = Qt.QScrollArea() self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame) self.top_scroll_layout.addWidget(self.top_scroll) self.top_scroll.setWidgetResizable(True) self.top_widget = Qt.QWidget() self.top_scroll.setWidget(self.top_widget) self.top_layout = Qt.QVBoxLayout(self.top_widget) self.top_grid_layout = Qt.QGridLayout() self.top_layout.addLayout(self.top_grid_layout) self.settings = Qt.QSettings("GNU Radio", "polyphase") try: if StrictVersion(Qt.qVersion()) < StrictVersion("5.0.0"): self.restoreGeometry( self.settings.value("geometry").toByteArray()) else: self.restoreGeometry(self.settings.value("geometry")) except: pass ################################################## # Variables ################################################## self.samp_rate = samp_rate = 33333 self.quad_mul = quad_mul = 6 self.quad_rate = quad_rate = samp_rate * quad_mul self.num_banks = num_banks = 20 self.taps = taps = firdes.low_pass_2(5, num_banks * quad_rate, 60e3, 60e3, 80, firdes.WIN_BLACKMAN_HARRIS) self.variable_qtgui_entry_0 = variable_qtgui_entry_0 = len(taps) self.preemphasis_high_corner = preemphasis_high_corner = 13e3 ################################################## # Blocks ################################################## self.xmlrpc_server_0 = SimpleXMLRPCServer.SimpleXMLRPCServer( ('localhost', 8080), allow_none=True) self.xmlrpc_server_0.register_instance(self) self.xmlrpc_server_0_thread = threading.Thread( target=self.xmlrpc_server_0.serve_forever) self.xmlrpc_server_0_thread.daemon = True self.xmlrpc_server_0_thread.start() self._variable_qtgui_entry_0_tool_bar = Qt.QToolBar(self) self._variable_qtgui_entry_0_tool_bar.addWidget( Qt.QLabel('filter length' + ": ")) self._variable_qtgui_entry_0_line_edit = Qt.QLineEdit( str(self.variable_qtgui_entry_0)) self._variable_qtgui_entry_0_tool_bar.addWidget( self._variable_qtgui_entry_0_line_edit) self._variable_qtgui_entry_0_line_edit.returnPressed.connect( lambda: self.set_variable_qtgui_entry_0( int(str(self._variable_qtgui_entry_0_line_edit.text())))) self.top_grid_layout.addWidget(self._variable_qtgui_entry_0_tool_bar) self.rational_resampler_xxx_0_0_0_0_0 = filter.rational_resampler_fff( interpolation=quad_mul, decimation=1, taps=None, fractional_bw=None) self.rational_resampler_xxx_0_0_0_0 = filter.rational_resampler_fff( interpolation=quad_mul, decimation=1, taps=None, fractional_bw=None) self.rational_resampler_xxx_0_0_0 = filter.rational_resampler_fff( interpolation=quad_mul, decimation=1, taps=None, fractional_bw=None) self.rational_resampler_xxx_0_0 = filter.rational_resampler_fff( interpolation=quad_mul, decimation=1, taps=None, fractional_bw=None) self.rational_resampler_xxx_0 = filter.rational_resampler_fff( interpolation=quad_mul, decimation=1, taps=None, fractional_bw=None) self.qtgui_sink_x_0 = qtgui.sink_c( 1024, #fftsize firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc quad_rate * num_banks, #bw "", #name True, #plotfreq True, #plotwaterfall True, #plottime True #plotconst ) self.qtgui_sink_x_0.set_update_time(1.0 / 10) self._qtgui_sink_x_0_win = sip.wrapinstance( self.qtgui_sink_x_0.pyqwidget(), Qt.QWidget) self.qtgui_sink_x_0.enable_rf_freq(False) self.top_grid_layout.addWidget(self._qtgui_sink_x_0_win) self.pfb_synthesizer_ccf_0 = filter.pfb_synthesizer_ccf( num_banks, taps, False) self.pfb_synthesizer_ccf_0.set_channel_map([1, 2, 6, 7, 8]) self.pfb_synthesizer_ccf_0.declare_sample_delay(0) self.osmosdr_sink_0 = osmosdr.sink(args="numchan=" + str(1) + " " + "") self.osmosdr_sink_0.set_sample_rate(quad_rate * num_banks) self.osmosdr_sink_0.set_center_freq(93200000, 0) self.osmosdr_sink_0.set_freq_corr(0, 0) self.osmosdr_sink_0.set_gain(0, 0) self.osmosdr_sink_0.set_if_gain(0, 0) self.osmosdr_sink_0.set_bb_gain(0, 0) self.osmosdr_sink_0.set_antenna('', 0) self.osmosdr_sink_0.set_bandwidth(0, 0) self.blocks_short_to_float_0_0_0 = blocks.short_to_float(1, 1) self.blocks_short_to_float_0_0 = blocks.short_to_float(1, 1) self.blocks_short_to_float_0 = blocks.short_to_float(1, 1) self.blocks_multiply_const_vxx_0_0_0 = blocks.multiply_const_ff(0) self.blocks_multiply_const_vxx_0_0 = blocks.multiply_const_ff(30e-6) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_ff(30e-6) self.blocks_file_source_0_0_0 = blocks.file_source( gr.sizeof_short * 1, '../../samples/3.aud', True, 0, 0) self.blocks_file_source_0_0_0.set_begin_tag(pmt.PMT_NIL) self.blocks_file_source_0_0 = blocks.file_source( gr.sizeof_short * 1, '../../samples/2.aud', True, 0, 0) self.blocks_file_source_0_0.set_begin_tag(pmt.PMT_NIL) self.blocks_file_source_0 = blocks.file_source(gr.sizeof_short * 1, '../../samples/1.aud', True, 0, 0) self.blocks_file_source_0.set_begin_tag(pmt.PMT_NIL) self.analog_frequency_modulator_fc_0_0_0_0_0 = analog.frequency_modulator_fc( 0.8) self.analog_frequency_modulator_fc_0_0_0_0 = analog.frequency_modulator_fc( 0.8) self.analog_frequency_modulator_fc_0_0_0 = analog.frequency_modulator_fc( 0.8) self.analog_frequency_modulator_fc_0_0 = analog.frequency_modulator_fc( 0.8) self.analog_frequency_modulator_fc_0 = analog.frequency_modulator_fc( 0.8) self.analog_fm_preemph_0_0_0_0_0 = analog.fm_preemph( fs=quad_rate, tau=50e-6, fh=preemphasis_high_corner) self.analog_fm_preemph_0_0_0_0 = analog.fm_preemph( fs=quad_rate, tau=50e-6, fh=preemphasis_high_corner) self.analog_fm_preemph_0_0_0 = analog.fm_preemph( fs=quad_rate, tau=50e-6, fh=preemphasis_high_corner) self.analog_fm_preemph_0_0 = analog.fm_preemph( fs=quad_rate, tau=50e-6, fh=preemphasis_high_corner) self.analog_fm_preemph_0 = analog.fm_preemph( fs=quad_rate, tau=50e-6, fh=preemphasis_high_corner) self.analog_const_source_x_0_0 = analog.sig_source_f( 0, analog.GR_CONST_WAVE, 0, 0, 0) self.analog_const_source_x_0 = analog.sig_source_f( 0, analog.GR_CONST_WAVE, 0, 0, 0) ################################################## # Connections ################################################## self.connect((self.analog_const_source_x_0, 0), (self.rational_resampler_xxx_0_0_0_0, 0)) self.connect((self.analog_const_source_x_0_0, 0), (self.rational_resampler_xxx_0_0_0_0_0, 0)) self.connect((self.analog_fm_preemph_0, 0), (self.analog_frequency_modulator_fc_0, 0)) self.connect((self.analog_fm_preemph_0_0, 0), (self.analog_frequency_modulator_fc_0_0, 0)) self.connect((self.analog_fm_preemph_0_0_0, 0), (self.analog_frequency_modulator_fc_0_0_0, 0)) self.connect((self.analog_fm_preemph_0_0_0_0, 0), (self.analog_frequency_modulator_fc_0_0_0_0, 0)) self.connect((self.analog_fm_preemph_0_0_0_0_0, 0), (self.analog_frequency_modulator_fc_0_0_0_0_0, 0)) self.connect((self.analog_frequency_modulator_fc_0, 0), (self.pfb_synthesizer_ccf_0, 0)) self.connect((self.analog_frequency_modulator_fc_0_0, 0), (self.pfb_synthesizer_ccf_0, 1)) self.connect((self.analog_frequency_modulator_fc_0_0_0, 0), (self.pfb_synthesizer_ccf_0, 2)) self.connect((self.analog_frequency_modulator_fc_0_0_0_0, 0), (self.pfb_synthesizer_ccf_0, 3)) self.connect((self.analog_frequency_modulator_fc_0_0_0_0_0, 0), (self.pfb_synthesizer_ccf_0, 4)) self.connect((self.blocks_file_source_0, 0), (self.blocks_short_to_float_0, 0)) self.connect((self.blocks_file_source_0_0, 0), (self.blocks_short_to_float_0_0, 0)) self.connect((self.blocks_file_source_0_0_0, 0), (self.blocks_short_to_float_0_0_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.rational_resampler_xxx_0, 0)) self.connect((self.blocks_multiply_const_vxx_0_0, 0), (self.rational_resampler_xxx_0_0, 0)) self.connect((self.blocks_multiply_const_vxx_0_0_0, 0), (self.rational_resampler_xxx_0_0_0, 0)) self.connect((self.blocks_short_to_float_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.blocks_short_to_float_0_0, 0), (self.blocks_multiply_const_vxx_0_0, 0)) self.connect((self.blocks_short_to_float_0_0_0, 0), (self.blocks_multiply_const_vxx_0_0_0, 0)) self.connect((self.pfb_synthesizer_ccf_0, 0), (self.osmosdr_sink_0, 0)) self.connect((self.pfb_synthesizer_ccf_0, 0), (self.qtgui_sink_x_0, 0)) self.connect((self.rational_resampler_xxx_0, 0), (self.analog_fm_preemph_0, 0)) self.connect((self.rational_resampler_xxx_0_0, 0), (self.analog_fm_preemph_0_0, 0)) self.connect((self.rational_resampler_xxx_0_0_0, 0), (self.analog_fm_preemph_0_0_0, 0)) self.connect((self.rational_resampler_xxx_0_0_0_0, 0), (self.analog_fm_preemph_0_0_0_0, 0)) self.connect((self.rational_resampler_xxx_0_0_0_0_0, 0), (self.analog_fm_preemph_0_0_0_0_0, 0))
def main(): N = 10000 fs = 2000.0 Ts = 1.0/fs t = scipy.arange(0, N*Ts, Ts) # When playing with the number of channels, be careful about the filter # specs and the channel map of the synthesizer set below. nchans = 10 # Build the filter(s) bw = 1000 tb = 400 proto_taps = filter.firdes.low_pass_2(1, nchans*fs, bw, tb, 80, filter.firdes.WIN_BLACKMAN_hARRIS) print "Filter length: ", len(proto_taps) # Create a modulated signal npwr = 0.01 data = scipy.random.randint(0, 256, N) rrc_taps = filter.firdes.root_raised_cosine(1, 2, 1, 0.35, 41) src = gr.vector_source_b(data.astype(scipy.uint8).tolist(), False) mod = digital.bpsk_mod(samples_per_symbol=2) chan = filter.channel_model(npwr) rrc = filter.fft_filter_ccc(1, rrc_taps) # Split it up into pieces channelizer = filter.pfb.channelizer_ccf(nchans, proto_taps, 2) # Put the pieces back together again syn_taps = [nchans*t for t in proto_taps] synthesizer = filter.pfb_synthesizer_ccf(nchans, syn_taps, True) src_snk = gr.vector_sink_c() snk = gr.vector_sink_c() # Remap the location of the channels # Can be done in synth or channelizer (watch out for rotattions in # the channelizer) synthesizer.set_channel_map([ 0, 1, 2, 3, 4, 15, 16, 17, 18, 19]) tb = gr.top_block() tb.connect(src, mod, chan, rrc, channelizer) tb.connect(rrc, src_snk) vsnk = [] for i in xrange(nchans): tb.connect((channelizer,i), (synthesizer, i)) vsnk.append(gr.vector_sink_c()) tb.connect((channelizer,i), vsnk[i]) tb.connect(synthesizer, snk) tb.run() sin = scipy.array(src_snk.data()[1000:]) sout = scipy.array(snk.data()[1000:]) # Plot original signal fs_in = nchans*fs f1 = pylab.figure(1, figsize=(16,12), facecolor='w') s11 = f1.add_subplot(2,2,1) s11.psd(sin, NFFT=fftlen, Fs=fs_in) s11.set_title("PSD of Original Signal") s11.set_ylim([-200, -20]) s12 = f1.add_subplot(2,2,2) s12.plot(sin.real[1000:1500], "o-b") s12.plot(sin.imag[1000:1500], "o-r") s12.set_title("Original Signal in Time") start = 1 skip = 4 s13 = f1.add_subplot(2,2,3) s13.plot(sin.real[start::skip], sin.imag[start::skip], "o") s13.set_title("Constellation") s13.set_xlim([-2, 2]) s13.set_ylim([-2, 2]) # Plot channels nrows = int(scipy.sqrt(nchans)) ncols = int(scipy.ceil(float(nchans)/float(nrows))) f2 = pylab.figure(2, figsize=(16,12), facecolor='w') for n in xrange(nchans): s = f2.add_subplot(nrows, ncols, n+1) s.psd(vsnk[n].data(), NFFT=fftlen, Fs=fs_in) s.set_title("Channel {0}".format(n)) s.set_ylim([-200, -20]) # Plot reconstructed signal fs_out = 2*nchans*fs f3 = pylab.figure(3, figsize=(16,12), facecolor='w') s31 = f3.add_subplot(2,2,1) s31.psd(sout, NFFT=fftlen, Fs=fs_out) s31.set_title("PSD of Reconstructed Signal") s31.set_ylim([-200, -20]) s32 = f3.add_subplot(2,2,2) s32.plot(sout.real[1000:1500], "o-b") s32.plot(sout.imag[1000:1500], "o-r") s32.set_title("Reconstructed Signal in Time") start = 2 skip = 4 s33 = f3.add_subplot(2,2,3) s33.plot(sout.real[start::skip], sout.imag[start::skip], "o") s33.set_title("Constellation") s33.set_xlim([-2, 2]) s33.set_ylim([-2, 2]) pylab.show()
def __init__(self): gr.top_block.__init__(self, "Fm Channels") Qt.QWidget.__init__(self) self.setWindowTitle("Fm Channels") qtgui.util.check_set_qss() try: self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc')) except: pass self.top_scroll_layout = Qt.QVBoxLayout() self.setLayout(self.top_scroll_layout) self.top_scroll = Qt.QScrollArea() self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame) self.top_scroll_layout.addWidget(self.top_scroll) self.top_scroll.setWidgetResizable(True) self.top_widget = Qt.QWidget() self.top_scroll.setWidget(self.top_widget) self.top_layout = Qt.QVBoxLayout(self.top_widget) self.top_grid_layout = Qt.QGridLayout() self.top_layout.addLayout(self.top_grid_layout) self.settings = Qt.QSettings("GNU Radio", "fm_channels") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Variables ################################################## self.delta_f = delta_f = 75e3 self.chan_rate = chan_rate = 192e3 self.tx_ch_2 = tx_ch_2 = 3 self.tx_ch_1 = tx_ch_1 = 1 self.tx_ch_0 = tx_ch_0 = 0 self.tx_amp_2 = tx_amp_2 = 1 self.tx_amp_1 = tx_amp_1 = 1 self.tx_amp_0 = tx_amp_0 = 1 self.sensitivity = sensitivity = 2 * math.pi * delta_f / chan_rate self.rx_vol = rx_vol = 0.75 self.rx_chan = rx_chan = 0 self.nchans = nchans = 21 self.audio_rate = audio_rate = 32e3 ################################################## # Blocks ################################################## self._tx_ch_2_tool_bar = Qt.QToolBar(self) self._tx_ch_2_tool_bar.addWidget(Qt.QLabel('TX Channel 2' + ": ")) self._tx_ch_2_line_edit = Qt.QLineEdit(str(self.tx_ch_2)) self._tx_ch_2_tool_bar.addWidget(self._tx_ch_2_line_edit) self._tx_ch_2_line_edit.returnPressed.connect(lambda: self.set_tx_ch_2( int(str(self._tx_ch_2_line_edit.text().toAscii())))) self.top_grid_layout.addWidget(self._tx_ch_2_tool_bar, 0, 3, 1, 1) for r in range(0, 1): self.top_grid_layout.setRowStretch(r, 1) for c in range(3, 4): self.top_grid_layout.setColumnStretch(c, 1) self._tx_ch_1_tool_bar = Qt.QToolBar(self) self._tx_ch_1_tool_bar.addWidget(Qt.QLabel('TX Channel 1' + ": ")) self._tx_ch_1_line_edit = Qt.QLineEdit(str(self.tx_ch_1)) self._tx_ch_1_tool_bar.addWidget(self._tx_ch_1_line_edit) self._tx_ch_1_line_edit.returnPressed.connect(lambda: self.set_tx_ch_1( int(str(self._tx_ch_1_line_edit.text().toAscii())))) self.top_grid_layout.addWidget(self._tx_ch_1_tool_bar, 0, 2, 1, 1) for r in range(0, 1): self.top_grid_layout.setRowStretch(r, 1) for c in range(2, 3): self.top_grid_layout.setColumnStretch(c, 1) self._tx_ch_0_tool_bar = Qt.QToolBar(self) self._tx_ch_0_tool_bar.addWidget(Qt.QLabel('TX Channel 0' + ": ")) self._tx_ch_0_line_edit = Qt.QLineEdit(str(self.tx_ch_0)) self._tx_ch_0_tool_bar.addWidget(self._tx_ch_0_line_edit) self._tx_ch_0_line_edit.returnPressed.connect(lambda: self.set_tx_ch_0( int(str(self._tx_ch_0_line_edit.text().toAscii())))) self.top_grid_layout.addWidget(self._tx_ch_0_tool_bar, 0, 1, 1, 1) for r in range(0, 1): self.top_grid_layout.setRowStretch(r, 1) for c in range(1, 2): self.top_grid_layout.setColumnStretch(c, 1) self._tx_amp_2_range = Range(0, 1, 0.01, 1, 200) self._tx_amp_2_win = RangeWidget(self._tx_amp_2_range, self.set_tx_amp_2, 'TX Amp 2', "counter_slider", float) self.top_grid_layout.addWidget(self._tx_amp_2_win, 1, 3, 1, 1) for r in range(1, 2): self.top_grid_layout.setRowStretch(r, 1) for c in range(3, 4): self.top_grid_layout.setColumnStretch(c, 1) self._tx_amp_1_range = Range(0, 1, 0.01, 1, 200) self._tx_amp_1_win = RangeWidget(self._tx_amp_1_range, self.set_tx_amp_1, 'TX Amp 1', "counter_slider", float) self.top_grid_layout.addWidget(self._tx_amp_1_win, 1, 2, 1, 1) for r in range(1, 2): self.top_grid_layout.setRowStretch(r, 1) for c in range(2, 3): self.top_grid_layout.setColumnStretch(c, 1) self._tx_amp_0_range = Range(0, 1, 0.01, 1, 200) self._tx_amp_0_win = RangeWidget(self._tx_amp_0_range, self.set_tx_amp_0, 'TX Amp 0', "counter_slider", float) self.top_grid_layout.addWidget(self._tx_amp_0_win, 1, 1, 1, 1) for r in range(1, 2): self.top_grid_layout.setRowStretch(r, 1) for c in range(1, 2): self.top_grid_layout.setColumnStretch(c, 1) self._rx_vol_range = Range(0, 1, 0.01, 0.75, 200) self._rx_vol_win = RangeWidget(self._rx_vol_range, self.set_rx_vol, 'RX Volume', "counter_slider", float) self.top_grid_layout.addWidget(self._rx_vol_win, 1, 0, 1, 1) for r in range(1, 2): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 1): self.top_grid_layout.setColumnStretch(c, 1) self._rx_chan_tool_bar = Qt.QToolBar(self) self._rx_chan_tool_bar.addWidget(Qt.QLabel('RX Channel' + ": ")) self._rx_chan_line_edit = Qt.QLineEdit(str(self.rx_chan)) self._rx_chan_tool_bar.addWidget(self._rx_chan_line_edit) self._rx_chan_line_edit.returnPressed.connect(lambda: self.set_rx_chan( int(str(self._rx_chan_line_edit.text().toAscii())))) self.top_grid_layout.addWidget(self._rx_chan_tool_bar, 0, 0, 1, 1) for r in range(0, 1): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 1): self.top_grid_layout.setColumnStretch(c, 1) self.qtgui_waterfall_sink_x_0 = qtgui.waterfall_sink_c( 1024, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc nchans * chan_rate, #bw "", #name 1 #number of inputs ) self.qtgui_waterfall_sink_x_0.set_update_time(0.01) self.qtgui_waterfall_sink_x_0.enable_grid(False) self.qtgui_waterfall_sink_x_0.enable_axis_labels(True) if not True: self.qtgui_waterfall_sink_x_0.disable_legend() if "complex" == "float" or "complex" == "msg_float": self.qtgui_waterfall_sink_x_0.set_plot_pos_half(not True) labels = ['', '', '', '', '', '', '', '', '', ''] colors = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(1): if len(labels[i]) == 0: self.qtgui_waterfall_sink_x_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_waterfall_sink_x_0.set_line_label(i, labels[i]) self.qtgui_waterfall_sink_x_0.set_color_map(i, colors[i]) self.qtgui_waterfall_sink_x_0.set_line_alpha(i, alphas[i]) self.qtgui_waterfall_sink_x_0.set_intensity_range(-70, 0) self._qtgui_waterfall_sink_x_0_win = sip.wrapinstance( self.qtgui_waterfall_sink_x_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_waterfall_sink_x_0_win, 2, 2, 1, 2) for r in range(2, 3): self.top_grid_layout.setRowStretch(r, 1) for c in range(2, 4): self.top_grid_layout.setColumnStretch(c, 1) self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c( 1024, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc nchans * chan_rate, #bw "", #name 2 #number of inputs ) self.qtgui_freq_sink_x_0.set_update_time(0.01) self.qtgui_freq_sink_x_0.set_y_axis(-70, 0) self.qtgui_freq_sink_x_0.set_y_label('Relative Gain', 'dB') self.qtgui_freq_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "") self.qtgui_freq_sink_x_0.enable_autoscale(False) self.qtgui_freq_sink_x_0.enable_grid(False) self.qtgui_freq_sink_x_0.set_fft_average(0.2) self.qtgui_freq_sink_x_0.enable_axis_labels(True) self.qtgui_freq_sink_x_0.enable_control_panel(False) if not False: self.qtgui_freq_sink_x_0.disable_legend() if "complex" == "float" or "complex" == "msg_float": self.qtgui_freq_sink_x_0.set_plot_pos_half(not True) labels = ['', '', '', '', '', '', '', '', '', ''] widths = [2, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = [ "blue", "magenta", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "dark blue" ] alphas = [1.0, 0.5, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(2): if len(labels[i]) == 0: self.qtgui_freq_sink_x_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_freq_sink_x_0.set_line_label(i, labels[i]) self.qtgui_freq_sink_x_0.set_line_width(i, widths[i]) self.qtgui_freq_sink_x_0.set_line_color(i, colors[i]) self.qtgui_freq_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_freq_sink_x_0_win = sip.wrapinstance( self.qtgui_freq_sink_x_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_freq_sink_x_0_win, 2, 0, 1, 2) for r in range(2, 3): self.top_grid_layout.setRowStretch(r, 1) for c in range(0, 2): self.top_grid_layout.setColumnStretch(c, 1) self.pfb_synthesizer_ccf_0 = filter.pfb_synthesizer_ccf( nchans, (firdes.low_pass_2(nchans, nchans * chan_rate, 100e3, 20e3, 50)), False) self.pfb_synthesizer_ccf_0.set_channel_map( ([tx_ch_0, tx_ch_1, tx_ch_2])) self.pfb_synthesizer_ccf_0.declare_sample_delay(0) self.pfb_decimator_ccf_0 = pfb.decimator_ccf( nchans, (firdes.low_pass_2(rx_vol, nchans * chan_rate, chan_rate / 2, chan_rate / 4, 50)), rx_chan, 100, True, True) self.pfb_decimator_ccf_0.declare_sample_delay(0) self.fft_filter_xxx_0 = filter.fft_filter_ccc( 1, (firdes.complex_band_pass_2( 1, nchans * chan_rate, (rx_chan * chan_rate) - chan_rate / 2, (rx_chan * chan_rate) + chan_rate / 2, chan_rate / 10, 80)), 1) self.fft_filter_xxx_0.declare_sample_delay(0) self.broadcast_fm_tx_0_0_0 = broadcast_fm_tx( audio_rate=audio_rate, chan_rate=chan_rate, sensitivity=sensitivity, ) self.broadcast_fm_tx_0_0 = broadcast_fm_tx( audio_rate=audio_rate, chan_rate=chan_rate, sensitivity=sensitivity, ) self.broadcast_fm_tx_0 = broadcast_fm_tx( audio_rate=audio_rate, chan_rate=chan_rate, sensitivity=sensitivity, ) self.broadcast_fm_rx_0 = broadcast_fm_rx( audio_rate=audio_rate, bw=10e3, chan_rate=chan_rate, sensitivity=sensitivity, ) self.blocks_wavfile_source_0_1 = blocks.wavfile_source( '/home/prabhat/Downloads/Untitled folder/PIERS project/fm tx rx/Martin Garrix - Animals.wav', True) self.blocks_wavfile_source_0_0 = blocks.wavfile_source( '/home/prabhat/Downloads/Untitled folder/PIERS project/fm tx rx/Charlie Puth (Feat. Selena Gomez) - We Don_t Talk Anymore.wav', True) self.blocks_wavfile_source_0 = blocks.wavfile_source( '/home/prabhat/Downloads/Untitled folder/PIERS project/fm tx rx/Charlie Puth - Attention Official Video (1).wav', True) self.blocks_multiply_const_vxx_0_1 = blocks.multiply_const_vcc( (tx_amp_2, )) self.blocks_multiply_const_vxx_0_0 = blocks.multiply_const_vcc( (tx_amp_1, )) self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vcc( (tx_amp_0, )) self.blocks_add_xx_0 = blocks.add_vcc(1) self.audio_sink_0 = audio.sink(int(audio_rate), 'pulse', True) self.analog_fastnoise_source_x_0 = analog.fastnoise_source_c( analog.GR_GAUSSIAN, 0.1, 0, 8192) ################################################## # Connections ################################################## self.connect((self.analog_fastnoise_source_x_0, 0), (self.blocks_add_xx_0, 1)) self.connect((self.blocks_add_xx_0, 0), (self.fft_filter_xxx_0, 0)) self.connect((self.blocks_add_xx_0, 0), (self.pfb_decimator_ccf_0, 0)) self.connect((self.blocks_add_xx_0, 0), (self.qtgui_freq_sink_x_0, 0)) self.connect((self.blocks_add_xx_0, 0), (self.qtgui_waterfall_sink_x_0, 0)) self.connect((self.blocks_multiply_const_vxx_0, 0), (self.pfb_synthesizer_ccf_0, 0)) self.connect((self.blocks_multiply_const_vxx_0_0, 0), (self.pfb_synthesizer_ccf_0, 1)) self.connect((self.blocks_multiply_const_vxx_0_1, 0), (self.pfb_synthesizer_ccf_0, 2)) self.connect((self.blocks_wavfile_source_0, 0), (self.broadcast_fm_tx_0, 0)) self.connect((self.blocks_wavfile_source_0, 1), (self.broadcast_fm_tx_0, 1)) self.connect((self.blocks_wavfile_source_0_0, 0), (self.broadcast_fm_tx_0_0, 0)) self.connect((self.blocks_wavfile_source_0_0, 1), (self.broadcast_fm_tx_0_0, 1)) self.connect((self.blocks_wavfile_source_0_1, 0), (self.broadcast_fm_tx_0_0_0, 0)) self.connect((self.blocks_wavfile_source_0_1, 1), (self.broadcast_fm_tx_0_0_0, 1)) self.connect((self.broadcast_fm_rx_0, 1), (self.audio_sink_0, 1)) self.connect((self.broadcast_fm_rx_0, 0), (self.audio_sink_0, 0)) self.connect((self.broadcast_fm_tx_0, 0), (self.blocks_multiply_const_vxx_0, 0)) self.connect((self.broadcast_fm_tx_0_0, 0), (self.blocks_multiply_const_vxx_0_0, 0)) self.connect((self.broadcast_fm_tx_0_0_0, 0), (self.blocks_multiply_const_vxx_0_1, 0)) self.connect((self.fft_filter_xxx_0, 0), (self.qtgui_freq_sink_x_0, 1)) self.connect((self.pfb_decimator_ccf_0, 0), (self.broadcast_fm_rx_0, 0)) self.connect((self.pfb_synthesizer_ccf_0, 0), (self.blocks_add_xx_0, 0))
def __init__(self): gr.top_block.__init__(self, "Ofdm Channelizer Tx") Qt.QWidget.__init__(self) self.setWindowTitle("Ofdm Channelizer Tx") try: self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc')) except: pass self.top_scroll_layout = Qt.QVBoxLayout() self.setLayout(self.top_scroll_layout) self.top_scroll = Qt.QScrollArea() self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame) self.top_scroll_layout.addWidget(self.top_scroll) self.top_scroll.setWidgetResizable(True) self.top_widget = Qt.QWidget() self.top_scroll.setWidget(self.top_widget) self.top_layout = Qt.QVBoxLayout(self.top_widget) self.top_grid_layout = Qt.QGridLayout() self.top_layout.addLayout(self.top_grid_layout) self.settings = Qt.QSettings("GNU Radio", "ofdm_channelizer_tx") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Variables ################################################## self.samp_rate = samp_rate = 100e3 self.taps = taps = firdes.low_pass_2(6, 6*samp_rate, samp_rate/3.0, samp_rate/4.0, 60) ################################################## # Blocks ################################################## self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c( 1024, #size firdes.WIN_FLATTOP, #wintype 0, #fc samp_rate*6, #bw "QT GUI Plot", #name 1 #number of inputs ) self.qtgui_freq_sink_x_0.set_update_time(0.10) self.qtgui_freq_sink_x_0.set_y_axis(-140, 10) self.qtgui_freq_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "") self.qtgui_freq_sink_x_0.enable_autoscale(False) self.qtgui_freq_sink_x_0.enable_grid(False) self.qtgui_freq_sink_x_0.set_fft_average(1.0) if complex == type(float()): self.qtgui_freq_sink_x_0.set_plot_pos_half(not True) labels = ["", "", "", "", "", "", "", "", "", ""] widths = [2, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = ["blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "dark blue"] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(1): if len(labels[i]) == 0: self.qtgui_freq_sink_x_0.set_line_label(i, "Data {0}".format(i)) else: self.qtgui_freq_sink_x_0.set_line_label(i, labels[i]) self.qtgui_freq_sink_x_0.set_line_width(i, widths[i]) self.qtgui_freq_sink_x_0.set_line_color(i, colors[i]) self.qtgui_freq_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_freq_sink_x_0_win = sip.wrapinstance(self.qtgui_freq_sink_x_0.pyqwidget(), Qt.QWidget) self.top_layout.addWidget(self._qtgui_freq_sink_x_0_win) self.pfb_synthesizer_ccf_0 = filter.pfb_synthesizer_ccf( 6, (taps), False) self.pfb_synthesizer_ccf_0.set_channel_map(([5])) self.pfb_synthesizer_ccf_0.declare_sample_delay(0) self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate,True) self.analog_sig_source_x_0_2 = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, -20000, 1, 0) self.analog_sig_source_x_0_1 = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, 20000, 1, 0) self.analog_sig_source_x_0_0 = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, -10000, 1, 0) self.analog_sig_source_x_0 = analog.sig_source_c(samp_rate, analog.GR_COS_WAVE, 10000, 1, 0) ################################################## # Connections ################################################## self.connect((self.analog_sig_source_x_0, 0), (self.pfb_synthesizer_ccf_0, 0)) self.connect((self.analog_sig_source_x_0_0, 0), (self.pfb_synthesizer_ccf_0, 1)) self.connect((self.analog_sig_source_x_0_1, 0), (self.pfb_synthesizer_ccf_0, 2)) self.connect((self.analog_sig_source_x_0_2, 0), (self.pfb_synthesizer_ccf_0, 3)) self.connect((self.blocks_throttle_0, 0), (self.qtgui_freq_sink_x_0, 0)) self.connect((self.pfb_synthesizer_ccf_0, 0), (self.blocks_throttle_0, 0))
def __init__(self): gr.top_block.__init__(self, "multi_fm_transmit") ################################################## # Variables ################################################## self.num_banks = num_banks = 30 self.mod_rate = mod_rate = 200000 self.taps_rs = taps_rs = firdes.low_pass_2(25.0, 25.0, 0.1, 0.1, 60, firdes.WIN_KAISER, 7.0) self.taps = taps = firdes.low_pass_2(8, num_banks*mod_rate, 120e3, 50e3, 80, firdes.WIN_BLACKMAN_HARRIS) self.aud_rate = aud_rate = 48000 ################################################## # Blocks ################################################## self.rational_resampler_xxx_0_0_0 = filter.rational_resampler_fff( interpolation=25, decimation=6, taps=taps_rs, fractional_bw=0.3) self.rational_resampler_xxx_0_0 = filter.rational_resampler_fff( interpolation=25, decimation=6, taps=taps_rs, fractional_bw=0.3) self.rational_resampler_xxx_0 = filter.rational_resampler_fff( interpolation=25, decimation=6, taps=taps_rs, fractional_bw=0.3) self.pfb_synthesizer_ccf_0 = filter.pfb_synthesizer_ccf( num_banks, taps, False) self.pfb_synthesizer_ccf_0.set_channel_map([1,9,8]) self.pfb_synthesizer_ccf_0.declare_sample_delay(0) self.osmosdr_sink_1 = osmosdr.sink( args="numchan=" + str(1) + " " + "buffers=1" ) self.osmosdr_sink_1.set_sample_rate(mod_rate*num_banks) self.osmosdr_sink_1.set_center_freq(96000000, 0) self.osmosdr_sink_1.set_freq_corr(0, 0) self.osmosdr_sink_1.set_gain(0, 0) self.osmosdr_sink_1.set_if_gain(0, 0) self.osmosdr_sink_1.set_bb_gain(0, 0) self.osmosdr_sink_1.set_antenna('', 0) self.osmosdr_sink_1.set_bandwidth(0, 0) self.audio_source_0 = audio.source(aud_rate, 'plughw:UMC1820', False) self.analog_wfm_tx_0_0_0 = analog.wfm_tx( audio_rate=mod_rate, quad_rate=mod_rate, tau=75e-6, max_dev=75e3, fh=10e3, ) self.analog_wfm_tx_0_0 = analog.wfm_tx( audio_rate=mod_rate, quad_rate=mod_rate, tau=75e-6, max_dev=75e3, fh=10e3, ) self.analog_wfm_tx_0 = analog.wfm_tx( audio_rate=mod_rate, quad_rate=mod_rate, tau=75e-6, max_dev=75e3, fh=10e3, ) ################################################## # Connections ################################################## self.connect((self.analog_wfm_tx_0, 0), (self.pfb_synthesizer_ccf_0, 0)) self.connect((self.analog_wfm_tx_0_0, 0), (self.pfb_synthesizer_ccf_0, 1)) self.connect((self.analog_wfm_tx_0_0_0, 0), (self.pfb_synthesizer_ccf_0, 2)) self.connect((self.audio_source_0, 0), (self.rational_resampler_xxx_0, 0)) self.connect((self.audio_source_0, 1), (self.rational_resampler_xxx_0_0, 0)) self.connect((self.audio_source_0, 2), (self.rational_resampler_xxx_0_0_0, 0)) self.connect((self.pfb_synthesizer_ccf_0, 0), (self.osmosdr_sink_1, 0)) self.connect((self.rational_resampler_xxx_0, 0), (self.analog_wfm_tx_0, 0)) self.connect((self.rational_resampler_xxx_0_0, 0), (self.analog_wfm_tx_0_0, 0)) self.connect((self.rational_resampler_xxx_0_0_0, 0), (self.analog_wfm_tx_0_0_0, 0))
def main(): N = 10000 fs = 100e3 Ts = 1.0/fs t = scipy.arange(0, N*Ts, Ts) # When playing with the number of channels, be careful about the filter # specs and the channel map of the synthesizer set below. nchans = 10 # Build the filter(s) bw = fs/2 # Bandwidth of the channel tb = 20e3 proto_taps = filter.firdes.low_pass_2(1, nchans*fs, bw, tb, 80, filter.firdes.WIN_BLACKMAN_hARRIS) proto_taps = list(proto_taps) proto_taps = proto_taps syn_taps = [((nchans)/2)*t for t in proto_taps] tpc = int(scipy.ceil(len(proto_taps)/float(nchans))) print "Filter length: ", len(proto_taps) print "Taps/Channel: {0} ({1})".format(tpc, len(proto_taps)/float(nchans)) print "Taps/Channel: {0} ({1})".format(tpc, len(syn_taps)/float(nchans)) channelizer = filter.pfb.channelizer_ccf(nchans, proto_taps, 2) synthesizer = filter.pfb_synthesizer_ccf(nchans, syn_taps, True) ch_taps = channelizer.taps() sy_taps = synthesizer.taps() # Set the synthesizer map. The numbers are the output channel # locations and the indices are the input channel numbers. #synthesizer.set_channel_map([4, 8, 10, 0, 2, 6]) nfft = 10000 sig = blocks.vector_source_c(10*[0,] + [1,] + (nfft-11)*[0,], False) noise = analog.noise_source_c(analog.GR_GAUSSIAN, 0.000) src = blocks.add_cc() snk = blocks.vector_sink_c() tb = gr.top_block() tb.connect(sig, (src,0)) tb.connect(noise, (src,1)) tb.connect(src, channelizer) tb.connect(synthesizer, snk) snks = [] for i in xrange(nchans): snks.append(blocks.vector_sink_c()) tb.connect((channelizer,i), snks[i]) tb.connect((channelizer,i), (synthesizer,i)) tb.run() # Set axes (and other default) fonts font = {'size': 18} matplotlib.rc('font', **font) # Plot original prototype filter used in the channelizer #fig1 = plt.figure(1, figsize=(12,10), facecolor='w') #sp11 = fig1.add_subplot(1,1,1) #H = 20.0*scipy.log10(abs(fftpack.fftshift(fftpack.fft(proto_taps, nfft)))) #freq = scipy.linspace(-nchans*fs/2, fs*nchans/2, nfft) #sp11.plot(freq, H, linewidth=3) #sp11.grid() #sp11.set_xlim([-nchans*fs/2, fs*nchans/2]) #sp11.set_ylim([-160, 20]) #sp11.set_xlabel("Frequency (kHz)", fontsize=18, fontweight='bold') #sp11.set_ylabel("Magnitude (dB)", fontsize=18, fontweight='bold') #sp11.set_xticks([-nchans*fs/2, -nchans*fs/4, 0, nchans*fs/4, fs*nchans/2]) #sp11.set_xticklabels([-nchans*fs/2/1000, -nchans*fs/4/1000, 0, nchans*fs/4/1000, fs*nchans/2/1000]) #a = plt.axes([0.125, 0.725, 0.2, 0.2], axisbg='w') #a.plot(freq, H, linewidth=3) #a.set_xlim([-fs, fs]) #a.set_ylim([-1e-4, 2e-4]) #a.set_yticks([-1e-4, 2e-4]) #a.set_xticks([-fs/2, fs/2]) #a.ticklabel_format(style='sci', axis='y', scilimits=(0,0)) # Plot the results. We will plot each channelizer output on one # subfigure and the output of each synthesis filterbank in two # other subfigures so that we can properly represent the frequency # domain or each. fig2 = plt.figure(2, figsize=(12,10), facecolor='w') data = [] sp21 = fig2.add_subplot(2,1,1) sp22 = fig2.add_subplot(2,1,2) for i in xrange(nchans): data.append(scipy.array(snks[i].data())) X = 10.0*scipy.log10(abs(fftpack.fftshift(fftpack.fft(data[0], nfft)))) freq = scipy.linspace(-2*fs/2, 2*fs/2, nfft) if(i == nchans/2): f0 = scipy.linspace(fs*(nchans/2 - 1), fs*(nchans/2), nfft/2) f1 = scipy.linspace(-fs*(nchans/2), -fs*(nchans/2 - 1), nfft/2) p = sp21.plot(f0, X[0:nfft/2], linewidth=2) sp21.plot(f1, X[nfft/2:nfft], color=p[0].get_color(), linewidth=2) else: x = i if(x > nchans/2): x -= nchans f0 = scipy.linspace(-fs, fs, nfft) f0 = f0 + x*fs sp21.plot(f0, X, linewidth=2) data_s = scipy.array(snk.data()) Y = 10.0*scipy.log10(abs(fftpack.fftshift(fftpack.fft(data_s, nfft)))) freq = scipy.linspace(-2*nchans*fs/2, 2*fs*nchans/2, nfft) sp22.plot(freq, Y, linewidth=3) sp21.grid() sp22.grid() sp21.set_xlim([-nchans*fs/2, fs*nchans/2]) sp22.set_xlim([-2*nchans*fs/2, 2*fs*nchans/2]) sp21.set_xticks([-nchans*fs/2, -nchans*fs/4, 0, nchans*fs/4, fs*nchans/2]) sp21.set_xticklabels([-nchans*fs/2/1000, -nchans*fs/4/1000, 0, nchans*fs/4/1000, fs*nchans/2/1000]) sp22.set_xticks([-2*nchans*fs/2, -2*nchans*fs/4, 0, 2*fs*nchans/4, 2*fs*nchans/2]) sp22.set_xticklabels([-2*nchans*fs/2/1000, -2*nchans*fs/4/1000, 0, 2*fs*nchans/4/1000, 2*fs*nchans/2/1000]) #a = plt.axes([0.125, 0.25, 0.2, 0.2], axisbg='w') #a.plot(freq, Y, linewidth=3) #a.set_xlim([-fs, nchans*fs]) #a.set_ylim([-1e-4, 2e-4]) #a.set_yticks([-1e-4, 2e-4]) #a.set_xticks([-fs/2, nchans*fs]) #a.set_xticklabels([-fs/2/1000, (nchans*fs)/1000]) #a.ticklabel_format(style='sci', axis='y', scilimits=(0,0)) sp21.set_xlabel("Frequency (kHz)", fontsize=18, fontweight='bold') sp21.set_ylabel("Magnitude (dB)", fontsize=18, fontweight='bold') sp22.set_xlabel("Frequency (kHz)", fontsize=18, fontweight='bold') sp22.set_ylabel("Magnitude (dB)", fontsize=18, fontweight='bold') #fig1.tight_layout() fig2.tight_layout() #fig1.savefig("impulse_prototype_filter.png", # dpi=300, format='png', # facecolor='w', edgecolor='w') # #fig2.savefig("impulse_chan_and_synth.png", # dpi=300, format='png', # facecolor='w', edgecolor='w') plt.show()
def __init__(self, num_streams, fs_in, delta_f_in): gr.hier_block2.__init__( self, 'coh_stream_synth', gr.io_signature(num_streams, num_streams, gr.sizeof_gr_complex), gr.io_signature(2 * num_streams, 2 * num_streams, gr.sizeof_gr_complex)) assert (num_streams >= 2 and num_streams <= 6) fsr = delta_f_in factor = gru.gcd(fsr, fs_in) interp = fsr / factor decim = fs_in / factor self._align_streams = align_streams(num_streams, True) self._rotators = rotator_proxy(num_streams, fs_in, delta_f_in) self._taps_resampler = taps_resampler = filter.firdes.low_pass_2( gain=2 * interp, sampling_freq=2.0, cutoff_freq=0.5 / decim, transition_width=0.4 / decim, attenuation_dB=80.0, window=filter.firdes.WIN_BLACKMAN_HARRIS) self._rational_resamplers = [ filter.rational_resampler_ccc(interpolation=2 * interp, decimation=decim, taps=(taps_resampler), fractional_bw=None) for _ in range(num_streams) ] self._taps_pfb = taps_pfb = filter.firdes.low_pass_2( gain=4, sampling_freq=4 * fsr, cutoff_freq=0.5 * fsr, transition_width=0.2 * fsr, attenuation_dB=80.0, window=filter.firdes.WIN_BLACKMAN_HARRIS) self._pfb_synthesizer = filter.pfb_synthesizer_ccf(numchans=6, taps=(taps_pfb), twox=True) channel_map = [] if num_streams == 2: channel_map = [0, 1] if num_streams == 3: channel_map = [7, 0, 1] if num_streams == 4: channel_map = [7, 0, 1, 2] if num_streams == 5: channel_map = [10, 11, 0, 1, 2] if num_streams == 6: channel_map = [6, 7, 0, 1, 2, 3] self._pfb_synthesizer.set_channel_map(channel_map) self._poc = [ phase_offset_corrector(2 * delta_f_in) for _ in range(1, num_streams) ] for i in range(num_streams): self.connect((self, i), (self._align_streams, i), (self._rotators, i), (self._rotators.get(i)), (self._rational_resamplers[i])) ## the phase offset corrector are cascading: ## #0 ---------------------- 0 self.connect((self._rational_resamplers[0]), (self._pfb_synthesizer, 0)) ## (#0,#1) -> poc[0] ------- 1 self.connect((self._rational_resamplers[0]), (self._poc[0], 0)) self.connect((self._rational_resamplers[1]), (self._poc[0], 1)) self.connect((self._poc[0], 0), (self._pfb_synthesizer, 1)) ## (poc[0],#2) -> poc[1] --- 2 ## (poc[1],#3) -> poc[2] --- 3 ## ... for i in range(2, num_streams): self.connect((self._poc[i - 2], 0), (self._poc[i - 1], 0)) self.connect((self._rational_resamplers[i]), (self._poc[i - 1], 1)) self.connect((self._poc[i - 1], 0), (self._pfb_synthesizer, i)) ## resampled coherent input streams + rel. phase offsets self.connect((self._rational_resamplers[0]), (self, 1)) for i in range(1, num_streams): self.connect((self._poc[i - 1], 0), (self, 1 + i)) self.connect((self._poc[i - 1], 1), (self, num_streams + i)) ## combined IQ output stream ## out: 4*delta_f_in if num_streams <= 3 else 8*delta_f_in self._final_processing = final_processing(num_streams, delta_f_in) self.connect((self._pfb_synthesizer, 0), (self._final_processing), (self, 0)) ##self.msg_connect((self._align_streams.get_find_offsets(), 'fs'), (self._rotators, 'fs')) self.msg_connect((self._align_streams, 'fs'), (self._rotators, 'fs'))
def __init__(self): gr.top_block.__init__(self, "FDM channalizer TX") Qt.QWidget.__init__(self) self.setWindowTitle("FDM channalizer TX") try: self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc')) except: pass self.top_scroll_layout = Qt.QVBoxLayout() self.setLayout(self.top_scroll_layout) self.top_scroll = Qt.QScrollArea() self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame) self.top_scroll_layout.addWidget(self.top_scroll) self.top_scroll.setWidgetResizable(True) self.top_widget = Qt.QWidget() self.top_scroll.setWidget(self.top_widget) self.top_layout = Qt.QVBoxLayout(self.top_widget) self.top_grid_layout = Qt.QGridLayout() self.top_layout.addLayout(self.top_grid_layout) self.settings = Qt.QSettings("GNU Radio", "fdm_chanalizer_tx") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Variables ################################################## self.samp_rate = samp_rate = 100000 self.taps = taps = firdes.low_pass_2(6, 6 * samp_rate, samp_rate / 3.0, samp_rate / 4.0, 60) self.channel_map = channel_map = [5, 0, 1, 2, 3, 4] ################################################## # Blocks ################################################## self.qtgui_freq_sink_x_0_0 = qtgui.freq_sink_c( 1024, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate, #bw "Before Polyphase Synthesizer", #name 4 #number of inputs ) self.qtgui_freq_sink_x_0_0.set_update_time(0.10) self.qtgui_freq_sink_x_0_0.set_y_axis(-140, 10) self.qtgui_freq_sink_x_0_0.set_y_label('Relative Gain', 'dB') self.qtgui_freq_sink_x_0_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "") self.qtgui_freq_sink_x_0_0.enable_autoscale(True) self.qtgui_freq_sink_x_0_0.enable_grid(False) self.qtgui_freq_sink_x_0_0.set_fft_average(1.0) self.qtgui_freq_sink_x_0_0.enable_axis_labels(True) self.qtgui_freq_sink_x_0_0.enable_control_panel(False) if not True: self.qtgui_freq_sink_x_0_0.disable_legend() if "complex" == "float" or "complex" == "msg_float": self.qtgui_freq_sink_x_0_0.set_plot_pos_half(not True) labels = ['', '', '', '', '', '', '', '', '', ''] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = [ "blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "dark blue" ] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(4): if len(labels[i]) == 0: self.qtgui_freq_sink_x_0_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_freq_sink_x_0_0.set_line_label(i, labels[i]) self.qtgui_freq_sink_x_0_0.set_line_width(i, widths[i]) self.qtgui_freq_sink_x_0_0.set_line_color(i, colors[i]) self.qtgui_freq_sink_x_0_0.set_line_alpha(i, alphas[i]) self._qtgui_freq_sink_x_0_0_win = sip.wrapinstance( self.qtgui_freq_sink_x_0_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_freq_sink_x_0_0_win, 0, 0, 1, 1) self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c( 1024, #size firdes.WIN_BLACKMAN_hARRIS, #wintype 0, #fc samp_rate, #bw "After polyphase synthesizer", #name 1 #number of inputs ) self.qtgui_freq_sink_x_0.set_update_time(0.10) self.qtgui_freq_sink_x_0.set_y_axis(-140, 10) self.qtgui_freq_sink_x_0.set_y_label('Relative Gain', 'dB') self.qtgui_freq_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "") self.qtgui_freq_sink_x_0.enable_autoscale(True) self.qtgui_freq_sink_x_0.enable_grid(False) self.qtgui_freq_sink_x_0.set_fft_average(1.0) self.qtgui_freq_sink_x_0.enable_axis_labels(True) self.qtgui_freq_sink_x_0.enable_control_panel(False) if not True: self.qtgui_freq_sink_x_0.disable_legend() if "complex" == "float" or "complex" == "msg_float": self.qtgui_freq_sink_x_0.set_plot_pos_half(not True) labels = ['', '', '', '', '', '', '', '', '', ''] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = [ "blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "dark blue" ] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(1): if len(labels[i]) == 0: self.qtgui_freq_sink_x_0.set_line_label( i, "Data {0}".format(i)) else: self.qtgui_freq_sink_x_0.set_line_label(i, labels[i]) self.qtgui_freq_sink_x_0.set_line_width(i, widths[i]) self.qtgui_freq_sink_x_0.set_line_color(i, colors[i]) self.qtgui_freq_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_freq_sink_x_0_win = sip.wrapinstance( self.qtgui_freq_sink_x_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_freq_sink_x_0_win, 0, 1, 1, 1) self.pfb_synthesizer_ccf_0 = filter.pfb_synthesizer_ccf( 6, (taps), False) self.pfb_synthesizer_ccf_0.set_channel_map((channel_map)) self.pfb_synthesizer_ccf_0.declare_sample_delay(0) self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex * 1, samp_rate, True) self.analog_sig_source_x_0_0_0_0 = analog.sig_source_c( samp_rate, analog.GR_COS_WAVE, -20000, 1, 0) self.analog_sig_source_x_0_0_0 = analog.sig_source_c( samp_rate, analog.GR_COS_WAVE, 20000, 1, 0) self.analog_sig_source_x_0_0 = analog.sig_source_c( samp_rate, analog.GR_COS_WAVE, -10000, 1, 0) self.analog_sig_source_x_0 = analog.sig_source_c( samp_rate, analog.GR_COS_WAVE, 10000, 1, 0) ################################################## # Connections ################################################## self.connect((self.analog_sig_source_x_0, 0), (self.pfb_synthesizer_ccf_0, 0)) self.connect((self.analog_sig_source_x_0, 0), (self.qtgui_freq_sink_x_0_0, 0)) self.connect((self.analog_sig_source_x_0_0, 0), (self.pfb_synthesizer_ccf_0, 1)) self.connect((self.analog_sig_source_x_0_0, 0), (self.qtgui_freq_sink_x_0_0, 1)) self.connect((self.analog_sig_source_x_0_0_0, 0), (self.pfb_synthesizer_ccf_0, 2)) self.connect((self.analog_sig_source_x_0_0_0, 0), (self.qtgui_freq_sink_x_0_0, 2)) self.connect((self.analog_sig_source_x_0_0_0_0, 0), (self.pfb_synthesizer_ccf_0, 3)) self.connect((self.analog_sig_source_x_0_0_0_0, 0), (self.qtgui_freq_sink_x_0_0, 3)) self.connect((self.blocks_throttle_0, 0), (self.qtgui_freq_sink_x_0, 0)) self.connect((self.pfb_synthesizer_ccf_0, 0), (self.blocks_throttle_0, 0))
def main(): N = 10000 fs = 2000.0 Ts = 1.0 / fs t = scipy.arange(0, N*Ts, Ts) # When playing with the number of channels, be careful about the filter # specs and the channel map of the synthesizer set below. nchans = 10 # Build the filter(s) bw = 1000 tb = 400 proto_taps = filter.firdes.low_pass_2(1, nchans*fs, bw, tb, 80, filter.firdes.WIN_BLACKMAN_hARRIS) print("Filter length: ", len(proto_taps)) # Create a modulated signal npwr = 0.01 data = scipy.random.randint(0, 256, N) rrc_taps = filter.firdes.root_raised_cosine(1, 2, 1, 0.35, 41) src = blocks.vector_source_b(data.astype(scipy.uint8).tolist(), False) mod = digital.bpsk_mod(samples_per_symbol=2) chan = channels.channel_model(npwr) rrc = filter.fft_filter_ccc(1, rrc_taps) # Split it up into pieces channelizer = filter.pfb.channelizer_ccf(nchans, proto_taps, 2) # Put the pieces back together again syn_taps = [nchans*t for t in proto_taps] synthesizer = filter.pfb_synthesizer_ccf(nchans, syn_taps, True) src_snk = blocks.vector_sink_c() snk = blocks.vector_sink_c() # Remap the location of the channels # Can be done in synth or channelizer (watch out for rotattions in # the channelizer) synthesizer.set_channel_map([ 0, 1, 2, 3, 4, 15, 16, 17, 18, 19]) tb = gr.top_block() tb.connect(src, mod, chan, rrc, channelizer) tb.connect(rrc, src_snk) vsnk = [] for i in range(nchans): tb.connect((channelizer,i), (synthesizer, i)) vsnk.append(blocks.vector_sink_c()) tb.connect((channelizer,i), vsnk[i]) tb.connect(synthesizer, snk) tb.run() sin = scipy.array(src_snk.data()[1000:]) sout = scipy.array(snk.data()[1000:]) # Plot original signal fs_in = nchans*fs f1 = pylab.figure(1, figsize=(16,12), facecolor='w') s11 = f1.add_subplot(2,2,1) s11.psd(sin, NFFT=fftlen, Fs=fs_in) s11.set_title("PSD of Original Signal") s11.set_ylim([-200, -20]) s12 = f1.add_subplot(2,2,2) s12.plot(sin.real[1000:1500], "o-b") s12.plot(sin.imag[1000:1500], "o-r") s12.set_title("Original Signal in Time") start = 1 skip = 2 s13 = f1.add_subplot(2,2,3) s13.plot(sin.real[start::skip], sin.imag[start::skip], "o") s13.set_title("Constellation") s13.set_xlim([-2, 2]) s13.set_ylim([-2, 2]) # Plot channels nrows = int(scipy.sqrt(nchans)) ncols = int(scipy.ceil(float(nchans) / float(nrows))) f2 = pylab.figure(2, figsize=(16,12), facecolor='w') for n in range(nchans): s = f2.add_subplot(nrows, ncols, n+1) s.psd(vsnk[n].data(), NFFT=fftlen, Fs=fs_in) s.set_title("Channel {0}".format(n)) s.set_ylim([-200, -20]) # Plot reconstructed signal fs_out = 2*nchans*fs f3 = pylab.figure(3, figsize=(16,12), facecolor='w') s31 = f3.add_subplot(2,2,1) s31.psd(sout, NFFT=fftlen, Fs=fs_out) s31.set_title("PSD of Reconstructed Signal") s31.set_ylim([-200, -20]) s32 = f3.add_subplot(2,2,2) s32.plot(sout.real[1000:1500], "o-b") s32.plot(sout.imag[1000:1500], "o-r") s32.set_title("Reconstructed Signal in Time") start = 0 skip = 4 s33 = f3.add_subplot(2,2,3) s33.plot(sout.real[start::skip], sout.imag[start::skip], "o") s33.set_title("Constellation") s33.set_xlim([-2, 2]) s33.set_ylim([-2, 2]) pylab.show()
def main(): N = 1000000 fs = 8000 freqs = [100, 200, 300, 400, 500] nchans = 7 sigs = list() fmtx = list() for fi in freqs: s = analog.sig_source_f(fs, analog.GR_SIN_WAVE, fi, 1) fm = analog.nbfm_tx(fs, 4*fs, max_dev=10000, tau=75e-6, fh=0.925*(4*fs)/2.0) sigs.append(s) fmtx.append(fm) syntaps = filter.firdes.low_pass_2(len(freqs), fs, fs/float(nchans)/2, 100, 100) print "Synthesis Num. Taps = %d (taps per filter = %d)" % (len(syntaps), len(syntaps)/nchans) chtaps = filter.firdes.low_pass_2(len(freqs), fs, fs/float(nchans)/2, 100, 100) print "Channelizer Num. Taps = %d (taps per filter = %d)" % (len(chtaps), len(chtaps)/nchans) filtbank = filter.pfb_synthesizer_ccf(nchans, syntaps) channelizer = filter.pfb.channelizer_ccf(nchans, chtaps) noise_level = 0.01 head = blocks.head(gr.sizeof_gr_complex, N) noise = analog.noise_source_c(analog.GR_GAUSSIAN, noise_level) addnoise = blocks.add_cc() snk_synth = blocks.vector_sink_c() tb = gr.top_block() tb.connect(noise, (addnoise,0)) tb.connect(filtbank, head, (addnoise, 1)) tb.connect(addnoise, channelizer) tb.connect(addnoise, snk_synth) snk = list() for i,si in enumerate(sigs): tb.connect(si, fmtx[i], (filtbank, i)) for i in xrange(nchans): snk.append(blocks.vector_sink_c()) tb.connect((channelizer, i), snk[i]) tb.run() if 1: channel = 1 data = snk[channel].data()[1000:] f1 = pylab.figure(1) s1 = f1.add_subplot(1,1,1) s1.plot(data[10000:10200] ) s1.set_title(("Output Signal from Channel %d" % channel)) fftlen = 2048 winfunc = scipy.blackman #winfunc = scipy.hamming f2 = pylab.figure(2) s2 = f2.add_subplot(1,1,1) s2.psd(data, NFFT=fftlen, Fs = nchans*fs, noverlap=fftlen/4, window = lambda d: d*winfunc(fftlen)) s2.set_title(("Output PSD from Channel %d" % channel)) f3 = pylab.figure(3) s3 = f3.add_subplot(1,1,1) s3.psd(snk_synth.data()[1000:], NFFT=fftlen, Fs = nchans*fs, noverlap=fftlen/4, window = lambda d: d*winfunc(fftlen)) s3.set_title("Output of Synthesis Filter") pylab.show()
def __init__(self): gr.top_block.__init__(self, "Fm Channelizer") Qt.QWidget.__init__(self) self.setWindowTitle("Fm Channelizer") try: self.setWindowIcon(Qt.QIcon.fromTheme("gnuradio-grc")) except: pass self.top_scroll_layout = Qt.QVBoxLayout() self.setLayout(self.top_scroll_layout) self.top_scroll = Qt.QScrollArea() self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame) self.top_scroll_layout.addWidget(self.top_scroll) self.top_scroll.setWidgetResizable(True) self.top_widget = Qt.QWidget() self.top_scroll.setWidget(self.top_widget) self.top_layout = Qt.QVBoxLayout(self.top_widget) self.top_grid_layout = Qt.QGridLayout() self.top_layout.addLayout(self.top_grid_layout) self.settings = Qt.QSettings("GNU Radio", "fm_channelizer") self.restoreGeometry(self.settings.value("geometry").toByteArray()) ################################################## # Variables ################################################## self.synth_channels = synth_channels = 6 self.channels = channels = 10 self.ch_rate = ch_rate = 100e3 self.samp_rate = samp_rate = ch_rate * channels self.gain = gain = 20 self.fm_quad_rate = fm_quad_rate = ch_rate * synth_channels self.ch_tb = ch_tb = 20e3 self.ch_bw = ch_bw = ch_rate / 2 self.audio_rate = audio_rate = 60e3 self.atten = atten = 80 self.volume = volume = 0.1 self.tun_gain = tun_gain = gain self.pfb_taps = pfb_taps = firdes.low_pass_2(1, samp_rate, ch_bw, ch_tb, atten, firdes.WIN_BLACKMAN_HARRIS) self.pfb_synth_taps = pfb_synth_taps = firdes.low_pass_2( channels / 2, synth_channels * ch_rate, ch_bw, ch_tb, atten, firdes.WIN_BLACKMAN_HARRIS ) self.freq_corr = freq_corr = 0 self.fm_audio_decim = fm_audio_decim = int(fm_quad_rate / audio_rate) * 2 self.channel = channel = 0 self.center_freq = center_freq = 101.1e6 + 0e3 self.address = address = "" ################################################## # Blocks ################################################## self._volume_layout = Qt.QVBoxLayout() self._volume_tool_bar = Qt.QToolBar(self) self._volume_layout.addWidget(self._volume_tool_bar) self._volume_tool_bar.addWidget(Qt.QLabel("Volume" + ": ")) class qwt_counter_pyslot(Qwt.QwtCounter): def __init__(self, parent=None): Qwt.QwtCounter.__init__(self, parent) @pyqtSlot("double") def setValue(self, value): super(Qwt.QwtCounter, self).setValue(value) self._volume_counter = qwt_counter_pyslot() self._volume_counter.setRange(0, 10, 0.1) self._volume_counter.setNumButtons(2) self._volume_counter.setValue(self.volume) self._volume_tool_bar.addWidget(self._volume_counter) self._volume_counter.valueChanged.connect(self.set_volume) self._volume_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot) self._volume_slider.setRange(0, 10, 0.1) self._volume_slider.setValue(self.volume) self._volume_slider.setMinimumWidth(200) self._volume_slider.valueChanged.connect(self.set_volume) self._volume_layout.addWidget(self._volume_slider) self.top_grid_layout.addLayout(self._volume_layout, 3, 0, 1, 1) self._tun_gain_layout = Qt.QVBoxLayout() self._tun_gain_tool_bar = Qt.QToolBar(self) self._tun_gain_layout.addWidget(self._tun_gain_tool_bar) self._tun_gain_tool_bar.addWidget(Qt.QLabel("Gain (dB)" + ": ")) class qwt_counter_pyslot(Qwt.QwtCounter): def __init__(self, parent=None): Qwt.QwtCounter.__init__(self, parent) @pyqtSlot("double") def setValue(self, value): super(Qwt.QwtCounter, self).setValue(value) self._tun_gain_counter = qwt_counter_pyslot() self._tun_gain_counter.setRange(0, 70, 1) self._tun_gain_counter.setNumButtons(2) self._tun_gain_counter.setValue(self.tun_gain) self._tun_gain_tool_bar.addWidget(self._tun_gain_counter) self._tun_gain_counter.valueChanged.connect(self.set_tun_gain) self._tun_gain_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot) self._tun_gain_slider.setRange(0, 70, 1) self._tun_gain_slider.setValue(self.tun_gain) self._tun_gain_slider.setMinimumWidth(200) self._tun_gain_slider.valueChanged.connect(self.set_tun_gain) self._tun_gain_layout.addWidget(self._tun_gain_slider) self.top_grid_layout.addLayout(self._tun_gain_layout, 2, 1, 1, 1) self._freq_corr_layout = Qt.QVBoxLayout() self._freq_corr_tool_bar = Qt.QToolBar(self) self._freq_corr_layout.addWidget(self._freq_corr_tool_bar) self._freq_corr_tool_bar.addWidget(Qt.QLabel("Frequency Correction" + ": ")) class qwt_counter_pyslot(Qwt.QwtCounter): def __init__(self, parent=None): Qwt.QwtCounter.__init__(self, parent) @pyqtSlot("double") def setValue(self, value): super(Qwt.QwtCounter, self).setValue(value) self._freq_corr_counter = qwt_counter_pyslot() self._freq_corr_counter.setRange(-40e3, 40e3, 100) self._freq_corr_counter.setNumButtons(2) self._freq_corr_counter.setValue(self.freq_corr) self._freq_corr_tool_bar.addWidget(self._freq_corr_counter) self._freq_corr_counter.valueChanged.connect(self.set_freq_corr) self._freq_corr_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot) self._freq_corr_slider.setRange(-40e3, 40e3, 100) self._freq_corr_slider.setValue(self.freq_corr) self._freq_corr_slider.setMinimumWidth(200) self._freq_corr_slider.valueChanged.connect(self.set_freq_corr) self._freq_corr_layout.addWidget(self._freq_corr_slider) self.top_grid_layout.addLayout(self._freq_corr_layout, 3, 1, 1, 1) self.uhd_usrp_source_0 = uhd.usrp_source( ",".join((address, "")), uhd.stream_args(cpu_format="fc32", channels=range(1)) ) self.uhd_usrp_source_0.set_time_now(uhd.time_spec(time.time()), uhd.ALL_MBOARDS) self.uhd_usrp_source_0.set_samp_rate(samp_rate) self.uhd_usrp_source_0.set_center_freq(center_freq + freq_corr, 0) self.uhd_usrp_source_0.set_gain(tun_gain, 0) self.uhd_usrp_source_0.set_antenna("RX2", 0) self.qtgui_freq_sink_x_0_0_0 = qtgui.freq_sink_c( 1024, # size firdes.WIN_FLATTOP, # wintype 0, # fc ch_rate * synth_channels, # bw "QT GUI Plot", # name 1, # number of inputs ) self.qtgui_freq_sink_x_0_0_0.set_update_time(0.10) self.qtgui_freq_sink_x_0_0_0.set_y_axis(-140, 10) self.qtgui_freq_sink_x_0_0_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "") self.qtgui_freq_sink_x_0_0_0.enable_autoscale(False) self.qtgui_freq_sink_x_0_0_0.enable_grid(False) self.qtgui_freq_sink_x_0_0_0.set_fft_average(1.0) if complex == type(float()): self.qtgui_freq_sink_x_0_0_0.set_plot_pos_half(not True) labels = ["", "", "", "", "", "", "", "", "", ""] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = ["blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "dark blue"] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(1): if len(labels[i]) == 0: self.qtgui_freq_sink_x_0_0_0.set_line_label(i, "Data {0}".format(i)) else: self.qtgui_freq_sink_x_0_0_0.set_line_label(i, labels[i]) self.qtgui_freq_sink_x_0_0_0.set_line_width(i, widths[i]) self.qtgui_freq_sink_x_0_0_0.set_line_color(i, colors[i]) self.qtgui_freq_sink_x_0_0_0.set_line_alpha(i, alphas[i]) self._qtgui_freq_sink_x_0_0_0_win = sip.wrapinstance(self.qtgui_freq_sink_x_0_0_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_freq_sink_x_0_0_0_win, 1, 1, 1, 1) self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c( 1024, # size firdes.WIN_BLACKMAN_hARRIS, # wintype 0, # fc samp_rate, # bw "QT GUI Plot", # name 1, # number of inputs ) self.qtgui_freq_sink_x_0.set_update_time(0.10) self.qtgui_freq_sink_x_0.set_y_axis(-140, 10) self.qtgui_freq_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "") self.qtgui_freq_sink_x_0.enable_autoscale(False) self.qtgui_freq_sink_x_0.enable_grid(False) self.qtgui_freq_sink_x_0.set_fft_average(1.0) if complex == type(float()): self.qtgui_freq_sink_x_0.set_plot_pos_half(not True) labels = ["", "", "", "", "", "", "", "", "", ""] widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] colors = ["blue", "red", "green", "black", "cyan", "magenta", "yellow", "dark red", "dark green", "dark blue"] alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0] for i in xrange(1): if len(labels[i]) == 0: self.qtgui_freq_sink_x_0.set_line_label(i, "Data {0}".format(i)) else: self.qtgui_freq_sink_x_0.set_line_label(i, labels[i]) self.qtgui_freq_sink_x_0.set_line_width(i, widths[i]) self.qtgui_freq_sink_x_0.set_line_color(i, colors[i]) self.qtgui_freq_sink_x_0.set_line_alpha(i, alphas[i]) self._qtgui_freq_sink_x_0_win = sip.wrapinstance(self.qtgui_freq_sink_x_0.pyqwidget(), Qt.QWidget) self.top_grid_layout.addWidget(self._qtgui_freq_sink_x_0_win, 0, 0, 1, 2) self.pfb_synthesizer_ccf_0 = filter.pfb_synthesizer_ccf(synth_channels, (pfb_synth_taps), True) self.pfb_synthesizer_ccf_0.set_channel_map(([10, 11, 0, 1, 2, 3])) self.pfb_synthesizer_ccf_0.declare_sample_delay(0) self.pfb_channelizer_ccf_0 = pfb.channelizer_ccf(channels, (pfb_taps), 2.0, atten) self.pfb_channelizer_ccf_0.set_channel_map(()) self.pfb_channelizer_ccf_0.declare_sample_delay(0) self.pfb_arb_resampler_xxx_0 = pfb.arb_resampler_fff( 44.1e3 / (fm_quad_rate / fm_audio_decim), taps=None, flt_size=32 ) self.pfb_arb_resampler_xxx_0.declare_sample_delay(0) self.fir_filter_xxx_0 = filter.fir_filter_ccc( 2, (firdes.low_pass_2(1, ch_rate * synth_channels, 250e3, 300e3, 40, firdes.WIN_BLACKMAN_HARRIS)) ) self.fir_filter_xxx_0.declare_sample_delay(0) self._channel_layout = Qt.QVBoxLayout() self._channel_tool_bar = Qt.QToolBar(self) self._channel_layout.addWidget(self._channel_tool_bar) self._channel_tool_bar.addWidget(Qt.QLabel("Output Channel" + ": ")) class qwt_counter_pyslot(Qwt.QwtCounter): def __init__(self, parent=None): Qwt.QwtCounter.__init__(self, parent) @pyqtSlot("double") def setValue(self, value): super(Qwt.QwtCounter, self).setValue(value) self._channel_counter = qwt_counter_pyslot() self._channel_counter.setRange(0, channels - 1, 1) self._channel_counter.setNumButtons(2) self._channel_counter.setValue(self.channel) self._channel_tool_bar.addWidget(self._channel_counter) self._channel_counter.valueChanged.connect(self.set_channel) self._channel_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot) self._channel_slider.setRange(0, channels - 1, 1) self._channel_slider.setValue(self.channel) self._channel_slider.setMinimumWidth(200) self._channel_slider.valueChanged.connect(self.set_channel) self._channel_layout.addWidget(self._channel_slider) self.top_grid_layout.addLayout(self._channel_layout, 2, 0, 1, 1) self.blocks_null_sink_0 = blocks.null_sink(gr.sizeof_gr_complex * 1) self.blocks_multiply_const_vxx = blocks.multiply_const_vff((volume,)) self.audio_sink = audio.sink(44100, "", True) self.analog_wfm_rcv = analog.wfm_rcv(quad_rate=fm_quad_rate, audio_decimation=fm_audio_decim) self.analog_agc2_xx_0 = analog.agc2_cc(1e-1, 1e-2, 1.0, 1.0) self.analog_agc2_xx_0.set_max_gain(65536) ################################################## # Connections ################################################## self.connect((self.analog_agc2_xx_0, 0), (self.pfb_channelizer_ccf_0, 0)) self.connect((self.analog_agc2_xx_0, 0), (self.qtgui_freq_sink_x_0, 0)) self.connect((self.analog_wfm_rcv, 0), (self.pfb_arb_resampler_xxx_0, 0)) self.connect((self.blocks_multiply_const_vxx, 0), (self.audio_sink, 0)) self.connect((self.fir_filter_xxx_0, 0), (self.analog_wfm_rcv, 0)) self.connect((self.fir_filter_xxx_0, 0), (self.qtgui_freq_sink_x_0_0_0, 0)) self.connect((self.pfb_arb_resampler_xxx_0, 0), (self.blocks_multiply_const_vxx, 0)) self.connect((self.pfb_channelizer_ccf_0, 6), (self.blocks_null_sink_0, 0)) self.connect((self.pfb_channelizer_ccf_0, 7), (self.blocks_null_sink_0, 1)) self.connect((self.pfb_channelizer_ccf_0, 8), (self.blocks_null_sink_0, 2)) self.connect((self.pfb_channelizer_ccf_0, 9), (self.blocks_null_sink_0, 3)) self.connect((self.pfb_channelizer_ccf_0, 0), (self.pfb_synthesizer_ccf_0, 0)) self.connect((self.pfb_channelizer_ccf_0, 1), (self.pfb_synthesizer_ccf_0, 1)) self.connect((self.pfb_channelizer_ccf_0, 2), (self.pfb_synthesizer_ccf_0, 2)) self.connect((self.pfb_channelizer_ccf_0, 3), (self.pfb_synthesizer_ccf_0, 3)) self.connect((self.pfb_channelizer_ccf_0, 4), (self.pfb_synthesizer_ccf_0, 4)) self.connect((self.pfb_channelizer_ccf_0, 5), (self.pfb_synthesizer_ccf_0, 5)) self.connect((self.pfb_synthesizer_ccf_0, 0), (self.fir_filter_xxx_0, 0)) self.connect((self.uhd_usrp_source_0, 0), (self.analog_agc2_xx_0, 0))