def __init__(self): gr.top_block.__init__(self) self._nsamples = 1000000 self._audio_rate = 8000 # Set up N channels with their own baseband and IF frequencies self._N = 5 chspacing = 16000 freq = [10, 20, 30, 40, 50] f_lo = [0, 1*chspacing, -1*chspacing, 2*chspacing, -2*chspacing] self._if_rate = 4*self._N*self._audio_rate # Create a signal source and frequency modulate it self.sum = gr.add_cc () for n in xrange(self._N): sig = gr.sig_source_f(self._audio_rate, gr.GR_SIN_WAVE, freq[n], 0.5) fm = fmtx(f_lo[n], self._audio_rate, self._if_rate) self.connect(sig, fm) self.connect(fm, (self.sum, n)) self.head = gr.head(gr.sizeof_gr_complex, self._nsamples) self.snk_tx = gr.vector_sink_c() self.channel = blks2.channel_model(0.1) self.connect(self.sum, self.head, self.channel, self.snk_tx) # Design the channlizer self._M = 10 bw = chspacing/2.0 t_bw = chspacing/10.0 self._chan_rate = self._if_rate / self._M self._taps = gr.firdes.low_pass_2(1, self._if_rate, bw, t_bw, attenuation_dB=100, window=gr.firdes.WIN_BLACKMAN_hARRIS) tpc = math.ceil(float(len(self._taps)) / float(self._M)) print "Number of taps: ", len(self._taps) print "Number of channels: ", self._M print "Taps per channel: ", tpc self.pfb = blks2.pfb_channelizer_ccf(self._M, self._taps) self.connect(self.channel, self.pfb) # Create a file sink for each of M output channels of the filter and connect it self.fmdet = list() self.squelch = list() self.snks = list() for i in xrange(self._M): self.fmdet.append(blks2.nbfm_rx(self._audio_rate, self._chan_rate)) self.squelch.append(blks2.standard_squelch(self._audio_rate*10)) self.snks.append(gr.vector_sink_f()) self.connect((self.pfb, i), self.fmdet[i], self.squelch[i], self.snks[i])
def __init__(self): gr.top_block.__init__(self) self._N = 200000 # number of samples to use self._fs = 9000 # initial sampling rate self._M = 9 # Number of channels to channelize # Create a set of taps for the PFB channelizer self._taps = gr.firdes.low_pass_2(1, self._fs, 500, 20, attenuation_dB=10, window=gr.firdes.WIN_BLACKMAN_hARRIS) # Calculate the number of taps per channel for our own information tpc = scipy.ceil(float(len(self._taps)) / float(self._M)) print "Number of taps: ", len(self._taps) print "Number of channels: ", self._M print "Taps per channel: ", tpc repeated = True if (repeated): self.vco_input = gr.sig_source_f(self._fs, gr.GR_SIN_WAVE, 0.25, 110) else: amp = 100 data = scipy.arange(0, amp, amp / float(self._N)) self.vco_input = gr.vector_source_f(data, False) # Build a VCO controlled by either the sinusoid or single chirp tone # Then convert this to a complex signal self.vco = gr.vco_f(self._fs, 225, 1) self.f2c = gr.float_to_complex() self.head = gr.head(gr.sizeof_gr_complex, self._N) # Construct the channelizer filter self.pfb = blks2.pfb_channelizer_ccf(self._M, self._taps) # Construct a vector sink for the input signal to the channelizer self.snk_i = gr.vector_sink_c() # Connect the blocks self.connect(self.vco_input, self.vco, self.f2c) self.connect(self.f2c, self.head, self.pfb) self.connect(self.f2c, self.snk_i) # Create a vector sink for each of M output channels of the filter and connect it self.snks = list() for i in xrange(self._M): self.snks.append(gr.vector_sink_c()) self.connect((self.pfb, i), self.snks[i])
def __init__(self): gr.top_block.__init__(self) self._N = 2000000 # number of samples to use self._fs = 9000 # initial sampling rate self._M = 9 # Number of channels to channelize # Create a set of taps for the PFB channelizer self._taps = gr.firdes.low_pass_2(1, self._fs, 475.50, 50, attenuation_dB=100, window=gr.firdes.WIN_BLACKMAN_hARRIS) # Calculate the number of taps per channel for our own information tpc = scipy.ceil(float(len(self._taps)) / float(self._M)) print "Number of taps: ", len(self._taps) print "Number of channels: ", self._M print "Taps per channel: ", tpc # Create a set of signals at different frequencies # freqs lists the frequencies of the signals that get stored # in the list "signals", which then get summed together self.signals = list() self.add = gr.add_cc() freqs = [-4070, -3050, -2030, -1010, 10, 1020, 2040, 3060, 4080] for i in xrange(len(freqs)): self.signals.append( gr.sig_source_c(self._fs, gr.GR_SIN_WAVE, freqs[i], 1)) self.connect(self.signals[i], (self.add, i)) self.head = gr.head(gr.sizeof_gr_complex, self._N) # Construct the channelizer filter self.pfb = blks2.pfb_channelizer_ccf(self._M, self._taps, 1) # Construct a vector sink for the input signal to the channelizer self.snk_i = gr.vector_sink_c() # Connect the blocks self.connect(self.add, self.head, self.pfb) self.connect(self.add, self.snk_i) # Use this to play with the channel mapping #self.pfb.set_channel_map([5,6,7,8,0,1,2,3,4]) # Create a vector sink for each of M output channels of the filter and connect it self.snks = list() for i in xrange(self._M): self.snks.append(gr.vector_sink_c()) self.connect((self.pfb, i), self.snks[i])
def __init__(self): gr.top_block.__init__(self) self._N = 200000 # number of samples to use self._fs = 9000 # initial sampling rate self._M = 9 # Number of channels to channelize # Create a set of taps for the PFB channelizer self._taps = gr.firdes.low_pass_2(1, self._fs, 500, 20, attenuation_dB=10, window=gr.firdes.WIN_BLACKMAN_hARRIS) # Calculate the number of taps per channel for our own information tpc = scipy.ceil(float(len(self._taps)) / float(self._M)) print "Number of taps: ", len(self._taps) print "Number of channels: ", self._M print "Taps per channel: ", tpc repeated = True if(repeated): self.vco_input = gr.sig_source_f(self._fs, gr.GR_SIN_WAVE, 0.25, 110) else: amp = 100 data = scipy.arange(0, amp, amp/float(self._N)) self.vco_input = gr.vector_source_f(data, False) # Build a VCO controlled by either the sinusoid or single chirp tone # Then convert this to a complex signal self.vco = gr.vco_f(self._fs, 225, 1) self.f2c = gr.float_to_complex() self.head = gr.head(gr.sizeof_gr_complex, self._N) # Construct the channelizer filter self.pfb = blks2.pfb_channelizer_ccf(self._M, self._taps) # Construct a vector sink for the input signal to the channelizer self.snk_i = gr.vector_sink_c() # Connect the blocks self.connect(self.vco_input, self.vco, self.f2c) self.connect(self.f2c, self.head, self.pfb) self.connect(self.f2c, self.snk_i) # Create a vector sink for each of M output channels of the filter and connect it self.snks = list() for i in xrange(self._M): self.snks.append(gr.vector_sink_c()) self.connect((self.pfb, i), self.snks[i])
def __init__(self): gr.top_block.__init__(self) self._N = 2000000 # number of samples to use self._fs = 9000 # initial sampling rate self._M = 9 # Number of channels to channelize # Create a set of taps for the PFB channelizer self._taps = gr.firdes.low_pass_2(1, self._fs, 475.50, 50, attenuation_dB=100, window=gr.firdes.WIN_BLACKMAN_hARRIS) # Calculate the number of taps per channel for our own information tpc = scipy.ceil(float(len(self._taps)) / float(self._M)) print "Number of taps: ", len(self._taps) print "Number of channels: ", self._M print "Taps per channel: ", tpc # Create a set of signals at different frequencies # freqs lists the frequencies of the signals that get stored # in the list "signals", which then get summed together self.signals = list() self.add = gr.add_cc() freqs = [-4070, -3050, -2030, -1010, 10, 1020, 2040, 3060, 4080] for i in xrange(len(freqs)): self.signals.append(gr.sig_source_c(self._fs, gr.GR_SIN_WAVE, freqs[i], 1)) self.connect(self.signals[i], (self.add,i)) self.head = gr.head(gr.sizeof_gr_complex, self._N) # Construct the channelizer filter self.pfb = blks2.pfb_channelizer_ccf(self._M, self._taps, 1) # Construct a vector sink for the input signal to the channelizer self.snk_i = gr.vector_sink_c() # Connect the blocks self.connect(self.add, self.head, self.pfb) self.connect(self.add, self.snk_i) # Use this to play with the channel mapping #self.pfb.set_channel_map([5,6,7,8,0,1,2,3,4]) # Create a vector sink for each of M output channels of the filter and connect it self.snks = list() for i in xrange(self._M): self.snks.append(gr.vector_sink_c()) self.connect((self.pfb, i), self.snks[i])
def main(): N = 1000000 fs = 8000 freqs = [100, 200, 300, 400, 500] nchans = 7 sigs = list() fmtx = list() for fi in freqs: s = gr.sig_source_f(fs, gr.GR_SIN_WAVE, fi, 1) fm = blks2.nbfm_tx (fs, 4*fs, max_dev=10000, tau=75e-6) sigs.append(s) fmtx.append(fm) syntaps = gr.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 = gr.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 = gr.pfb_synthesizer_ccf(nchans, syntaps) channelizer = blks2.pfb_channelizer_ccf(nchans, chtaps) noise_level = 0.01 head = gr.head(gr.sizeof_gr_complex, N) noise = gr.noise_source_c(gr.GR_GAUSSIAN, noise_level) addnoise = gr.add_cc() snk_synth = gr.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(gr.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) #parse the options parser = OptionParser(option_class=eng_option) parser.add_option("--inputfile", type="string", default="out/out.cf", help="set the input file") parser.add_option("--arfcn", type="int", default="40", help="set center ARFCN") parser.add_option("--srate", type="int", default="10000000", help="set sample frequency") parser.add_option("--decimation", type="int", default="17", help="decimation") parser.add_option("--nchannels", type="int", default="50", help="number of channels") parser.add_option("--nsamples", type="int", default="1280000", help="number of samples") (options, args) = parser.parse_args() self._output_rate = options.srate / options.decimation # Create a set of taps for the PFB channelizer self._taps = gr.firdes.low_pass_2(1, options.srate, 145e3, 10e3, attenuation_dB=100, window=gr.firdes.WIN_BLACKMAN_hARRIS) # Calculate the number of taps per channel for our own information tpc = scipy.ceil(float(len(self._taps)) / float(options.nchannels)) print "Number of taps: ", len(self._taps) print "Number of channels: ", options.nchannels print "Taps per channel: ", tpc self._o = float(options.nchannels) / float(options.decimation) print "pfb oversampling: ", self._o self.head = gr.head(gr.sizeof_gr_complex, options.nsamples) # Construct the channelizer filter self.pfb = blks2.pfb_channelizer_ccf(options.nchannels, self._taps, self._o) # Construct a vector sink for the input signal to the channelizer self.snk_i = gr.vector_sink_c() self.input = gr.file_source(gr.sizeof_gr_complex, "./out/out.cf", False) # Connect the blocks self.connect(self.input, self.head, self.pfb) self.output_files = list() for i in xrange(int(options.nchannels / 2) + 1): self.output_files.append( gr.file_sink(gr.sizeof_gr_complex, "./out/out_" + str(options.arfcn + i) + ".cf")) if (options.nchannels % 2) != 0: ind = 1 else: ind = 0 for i in xrange(1, int(options.nchannels / 2) + ind): self.output_files.append( gr.file_sink( gr.sizeof_gr_complex, "./out/out_" + str(options.arfcn - int(options.nchannels / 2) - ind + i) + ".cf")) # Create a vector sink for each of nchannels output channels of the filter and connect it self.snks = list() for i in xrange(options.nchannels): self.snks.append(gr.vector_sink_c()) self.connect((self.pfb, i), self.output_files[i])
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 = gr.firdes.low_pass_2(1, nchans*fs, bw, tb, 80, gr.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 = gr.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 = gr.channel_model(npwr) rrc = gr.fft_filter_ccc(1, rrc_taps) # Split it up into pieces channelizer = blks2.pfb_channelizer_ccf(nchans, proto_taps, 2) # Put the pieces back together again syn_taps = [nchans*t for t in proto_taps] synthesizer = gr.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 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 = gr.firdes.low_pass_2(1, nchans * fs, bw, tb, 80, gr.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 = gr.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 = gr.channel_model(npwr) rrc = gr.fft_filter_ccc(1, rrc_taps) # Split it up into pieces channelizer = blks2.pfb_channelizer_ccf(nchans, proto_taps, 2) # Put the pieces back together again syn_taps = [nchans * t for t in proto_taps] synthesizer = gr.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) # parse the options parser = OptionParser(option_class=eng_option) parser.add_option("--inputfile", type="string", default="out/out.cf", help="set the input file") parser.add_option("--arfcn", type="int", default="40", help="set center ARFCN") parser.add_option("--srate", type="int", default="10000000", help="set sample frequency") parser.add_option("--decimation", type="int", default="17", help="decimation") parser.add_option("--nchannels", type="int", default="50", help="number of channels") parser.add_option("--nsamples", type="int", default="1280000", help="number of samples") (options, args) = parser.parse_args() self._output_rate = options.srate / options.decimation # Create a set of taps for the PFB channelizer self._taps = gr.firdes.low_pass_2( 1, options.srate, 145e3, 10e3, attenuation_dB=100, window=gr.firdes.WIN_BLACKMAN_hARRIS ) # Calculate the number of taps per channel for our own information tpc = scipy.ceil(float(len(self._taps)) / float(options.nchannels)) print "Number of taps: ", len(self._taps) print "Number of channels: ", options.nchannels print "Taps per channel: ", tpc self._o = float(options.nchannels) / float(options.decimation) print "pfb oversampling: ", self._o self.head = gr.head(gr.sizeof_gr_complex, options.nsamples) # Construct the channelizer filter self.pfb = blks2.pfb_channelizer_ccf(options.nchannels, self._taps, self._o) # Construct a vector sink for the input signal to the channelizer self.snk_i = gr.vector_sink_c() self.input = gr.file_source(gr.sizeof_gr_complex, "./out/out.cf", False) # Connect the blocks self.connect(self.input, self.head, self.pfb) self.output_files = list() for i in xrange(int(options.nchannels / 2) + 1): self.output_files.append(gr.file_sink(gr.sizeof_gr_complex, "./out/out_" + str(options.arfcn + i) + ".cf")) if (options.nchannels % 2) != 0: ind = 1 else: ind = 0 for i in xrange(1, int(options.nchannels / 2) + ind): self.output_files.append( gr.file_sink( gr.sizeof_gr_complex, "./out/out_" + str(options.arfcn - int(options.nchannels / 2) - ind + i) + ".cf", ) ) # Create a vector sink for each of nchannels output channels of the filter and connect it self.snks = list() for i in xrange(options.nchannels): self.snks.append(gr.vector_sink_c()) self.connect((self.pfb, i), self.output_files[i])