diff options
author | Josh Morman <jmorman@gnuradio.org> | 2021-11-24 12:34:58 -0500 |
---|---|---|
committer | mormj <34754695+mormj@users.noreply.github.com> | 2021-11-24 14:41:53 -0500 |
commit | 09cd2d7cccf0a472ee2623c4a388a4ce950c0c5c (patch) | |
tree | 69655be1c0d244a68c1fe054969263d27ef99c07 /gr-filter/examples | |
parent | b4aaa48f69239e16341a59628ca7795cfeebb4da (diff) |
filter: pep8 formatting
Signed-off-by: Josh Morman <jmorman@gnuradio.org>
Diffstat (limited to 'gr-filter/examples')
-rw-r--r-- | gr-filter/examples/benchmark_filters.py | 13 | ||||
-rw-r--r-- | gr-filter/examples/channelize.py | 56 | ||||
-rw-r--r-- | gr-filter/examples/chirp_channelize.py | 55 | ||||
-rw-r--r-- | gr-filter/examples/decimate.py | 49 | ||||
-rw-r--r-- | gr-filter/examples/fft_filter_ccc.py | 28 | ||||
-rw-r--r-- | gr-filter/examples/fir_filter_ccc.py | 29 | ||||
-rw-r--r-- | gr-filter/examples/fir_filter_fff.py | 29 | ||||
-rw-r--r-- | gr-filter/examples/gr_filtdes_callback.py | 5 | ||||
-rw-r--r-- | gr-filter/examples/gr_filtdes_live_upd.py | 20 | ||||
-rw-r--r-- | gr-filter/examples/gr_filtdes_restrict.py | 5 | ||||
-rw-r--r-- | gr-filter/examples/interpolate.py | 99 | ||||
-rw-r--r-- | gr-filter/examples/reconstruction.py | 46 | ||||
-rw-r--r-- | gr-filter/examples/resampler.py | 32 | ||||
-rw-r--r-- | gr-filter/examples/synth_filter.py | 17 | ||||
-rw-r--r-- | gr-filter/examples/synth_to_chan.py | 34 |
15 files changed, 277 insertions, 240 deletions
diff --git a/gr-filter/examples/benchmark_filters.py b/gr-filter/examples/benchmark_filters.py index f447065105..2cecc57f71 100644 --- a/gr-filter/examples/benchmark_filters.py +++ b/gr-filter/examples/benchmark_filters.py @@ -15,13 +15,15 @@ from gnuradio import gr from gnuradio import blocks, filter from gnuradio.eng_arg import eng_float, intx + def make_random_complex_tuple(L): result = [] for x in range(L): - result.append(complex(random.uniform(-1000,1000), - random.uniform(-1000,1000))) + result.append(complex(random.uniform(-1000, 1000), + random.uniform(-1000, 1000))) return tuple(result) + def benchmark(name, creator, dec, ntaps, total_test_size, block_size): block_size = 32768 @@ -37,12 +39,14 @@ def benchmark(name, creator, dec, ntaps, total_test_size, block_size): stop = time.time() delta = stop - start print("%16s: taps: %4d input: %4g, time: %6.3f taps/sec: %10.4g" % ( - name, ntaps, total_test_size, delta, ntaps*total_test_size/delta)) + name, ntaps, total_test_size, delta, ntaps * total_test_size / delta)) + def main(): parser = ArgumentParser() parser.add_argument("-n", "--ntaps", type=int, default=256) - parser.add_argument("-t", "--total-input-size", type=eng_float, default=40e6) + parser.add_argument("-t", "--total-input-size", + type=eng_float, default=40e6) parser.add_argument("-b", "--block-size", type=intx, default=50000) parser.add_argument("-d", "--decimation", type=int, default=1) args = parser.parse_args() @@ -52,5 +56,6 @@ def main(): benchmark("filter.fft_filter_ccc", filter.fft_filter_ccc, args.decimation, args.ntaps, args.total_input_size, args.block_size) + if __name__ == '__main__': main() diff --git a/gr-filter/examples/channelize.py b/gr-filter/examples/channelize.py index 4d92bdce3f..83e85bc9c1 100644 --- a/gr-filter/examples/channelize.py +++ b/gr-filter/examples/channelize.py @@ -12,7 +12,8 @@ from gnuradio import gr from gnuradio import blocks from gnuradio import filter from gnuradio.fft import window -import sys, time +import sys +import time import numpy try: @@ -25,9 +26,11 @@ try: import pylab from pylab import mlab except ImportError: - sys.stderr.write("Error: Program requires matplotlib (see: matplotlib.sourceforge.net).\n") + sys.stderr.write( + "Error: Program requires matplotlib (see: matplotlib.sourceforge.net).\n") sys.exit(1) + class pfb_top_block(gr.top_block): def __init__(self): gr.top_block.__init__(self) @@ -35,7 +38,7 @@ class pfb_top_block(gr.top_block): self._N = 2000000 # number of samples to use self._fs = 1000 # initial sampling rate self._M = M = 9 # Number of channels to channelize - self._ifs = M*self._fs # initial sampling rate + self._ifs = M * self._fs # initial sampling rate # Create a set of taps for the PFB channelizer self._taps = filter.firdes.low_pass_2(1, self._ifs, 475.50, 50, @@ -55,9 +58,10 @@ class pfb_top_block(gr.top_block): self.add = blocks.add_cc() freqs = [-70, -50, -30, -10, 10, 20, 40, 60, 80] for i in range(len(freqs)): - f = freqs[i] + (M / 2-M+i+1)*self._fs - self.signals.append(analog.sig_source_c(self._ifs, analog.GR_SIN_WAVE, f, 1)) - self.connect(self.signals[i], (self.add,i)) + f = freqs[i] + (M / 2 - M + i + 1) * self._fs + self.signals.append(analog.sig_source_c( + self._ifs, analog.GR_SIN_WAVE, f, 1)) + self.connect(self.signals[i], (self.add, i)) self.head = blocks.head(gr.sizeof_gr_complex, self._N) @@ -72,7 +76,7 @@ class pfb_top_block(gr.top_block): 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]) + # 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() @@ -91,9 +95,9 @@ def main(): print("Run time: %f" % (tend - tstart)) if 1: - fig_in = pylab.figure(1, figsize=(16,9), facecolor="w") - fig1 = pylab.figure(2, figsize=(16,9), facecolor="w") - fig2 = pylab.figure(3, figsize=(16,9), facecolor="w") + fig_in = pylab.figure(1, figsize=(16, 9), facecolor="w") + fig1 = pylab.figure(2, figsize=(16, 9), facecolor="w") + fig2 = pylab.figure(3, figsize=(16, 9), facecolor="w") Ns = 1000 Ne = 10000 @@ -106,22 +110,21 @@ def main(): d = tb.snk_i.data()[Ns:Ne] spin_f = fig_in.add_subplot(2, 1, 1) - X,freq = mlab.psd(d, NFFT=fftlen, noverlap=fftlen / 4, Fs=fs, - window = lambda d: d*winfunc(fftlen), - scale_by_freq=True) - X_in = 10.0*numpy.log10(abs(X)) + X, freq = mlab.psd(d, NFFT=fftlen, noverlap=fftlen / 4, Fs=fs, + window=lambda d: d * winfunc(fftlen), + scale_by_freq=True) + X_in = 10.0 * numpy.log10(abs(X)) f_in = numpy.arange(-fs / 2.0, fs / 2.0, fs / float(X_in.size)) pin_f = spin_f.plot(f_in, X_in, "b") - spin_f.set_xlim([min(f_in), max(f_in)+1]) + spin_f.set_xlim([min(f_in), max(f_in) + 1]) spin_f.set_ylim([-200.0, 50.0]) spin_f.set_title("Input Signal", weight="bold") spin_f.set_xlabel("Frequency (Hz)") spin_f.set_ylabel("Power (dBW)") - Ts = 1.0 / fs - Tmax = len(d)*Ts + Tmax = len(d) * Ts t_in = numpy.arange(0, Tmax, Ts) x_in = numpy.array(d) @@ -141,21 +144,21 @@ def main(): # time signals on Figure 3 fs_o = tb._fs Ts_o = 1.0 / fs_o - Tmax_o = len(d)*Ts_o + Tmax_o = len(d) * Ts_o for i in range(len(tb.snks)): # remove issues with the transients at the beginning # also remove some corruption at the end of the stream # this is a bug, probably due to the corner cases d = tb.snks[i].data()[Ns:Ne] - sp1_f = fig1.add_subplot(Nrows, Ncols, 1+i) - X,freq = mlab.psd(d, NFFT=fftlen, noverlap=fftlen / 4, Fs=fs_o, - window = lambda d: d*winfunc(fftlen), - scale_by_freq=True) - X_o = 10.0*numpy.log10(abs(X)) + sp1_f = fig1.add_subplot(Nrows, Ncols, 1 + i) + X, freq = mlab.psd(d, NFFT=fftlen, noverlap=fftlen / 4, Fs=fs_o, + window=lambda d: d * winfunc(fftlen), + scale_by_freq=True) + X_o = 10.0 * numpy.log10(abs(X)) f_o = numpy.arange(-fs_o / 2.0, fs_o / 2.0, fs_o / float(X_o.size)) p2_f = sp1_f.plot(f_o, X_o, "b") - sp1_f.set_xlim([min(f_o), max(f_o)+1]) + sp1_f.set_xlim([min(f_o), max(f_o) + 1]) sp1_f.set_ylim([-200.0, 50.0]) sp1_f.set_title(("Channel %d" % i), weight="bold") @@ -164,10 +167,10 @@ def main(): x_o = numpy.array(d) t_o = numpy.arange(0, Tmax_o, Ts_o) - sp2_o = fig2.add_subplot(Nrows, Ncols, 1+i) + sp2_o = fig2.add_subplot(Nrows, Ncols, 1 + i) p2_o = sp2_o.plot(t_o, x_o.real, "b") p2_o = sp2_o.plot(t_o, x_o.imag, "r") - sp2_o.set_xlim([min(t_o), max(t_o)+1]) + sp2_o.set_xlim([min(t_o), max(t_o) + 1]) sp2_o.set_ylim([-2, 2]) sp2_o.set_title(("Channel %d" % i), weight="bold") @@ -182,4 +185,3 @@ if __name__ == "__main__": main() except KeyboardInterrupt: pass - diff --git a/gr-filter/examples/chirp_channelize.py b/gr-filter/examples/chirp_channelize.py index 03efcf873f..d37e35cb8d 100644 --- a/gr-filter/examples/chirp_channelize.py +++ b/gr-filter/examples/chirp_channelize.py @@ -12,7 +12,8 @@ from gnuradio import gr from gnuradio import blocks from gnuradio import filter from gnuradio.fft import window -import sys, time +import sys +import time import numpy try: @@ -25,9 +26,11 @@ try: import pylab from pylab import mlab except ImportError: - sys.stderr.write("Error: Program requires matplotlib (see: matplotlib.sourceforge.net).\n") + sys.stderr.write( + "Error: Program requires matplotlib (see: matplotlib.sourceforge.net).\n") sys.exit(1) + class pfb_top_block(gr.top_block): def __init__(self): gr.top_block.__init__(self) @@ -49,7 +52,8 @@ class pfb_top_block(gr.top_block): repeated = True if(repeated): - self.vco_input = analog.sig_source_f(self._fs, analog.GR_SIN_WAVE, 0.25, 110) + self.vco_input = analog.sig_source_f( + self._fs, analog.GR_SIN_WAVE, 0.25, 110) else: amp = 100 data = numpy.arange(0, amp, amp / float(self._N)) @@ -90,10 +94,10 @@ def main(): print("Run time: %f" % (tend - tstart)) if 1: - fig_in = pylab.figure(1, figsize=(16,9), facecolor="w") - fig1 = pylab.figure(2, figsize=(16,9), facecolor="w") - fig2 = pylab.figure(3, figsize=(16,9), facecolor="w") - fig3 = pylab.figure(4, figsize=(16,9), facecolor="w") + fig_in = pylab.figure(1, figsize=(16, 9), facecolor="w") + fig1 = pylab.figure(2, figsize=(16, 9), facecolor="w") + fig2 = pylab.figure(3, figsize=(16, 9), facecolor="w") + fig3 = pylab.figure(4, figsize=(16, 9), facecolor="w") Ns = 650 Ne = 20000 @@ -106,22 +110,21 @@ def main(): d = tb.snk_i.data()[Ns:Ne] spin_f = fig_in.add_subplot(2, 1, 1) - X,freq = mlab.psd(d, NFFT=fftlen, noverlap=fftlen / 4, Fs=fs, - window = lambda d: d*winfunc(fftlen), - scale_by_freq=True) - X_in = 10.0*numpy.log10(abs(numpy.fft.fftshift(X))) + X, freq = mlab.psd(d, NFFT=fftlen, noverlap=fftlen / 4, Fs=fs, + window=lambda d: d * winfunc(fftlen), + scale_by_freq=True) + X_in = 10.0 * numpy.log10(abs(numpy.fft.fftshift(X))) f_in = numpy.arange(-fs / 2.0, fs / 2.0, fs / float(X_in.size)) pin_f = spin_f.plot(f_in, X_in, "b") - spin_f.set_xlim([min(f_in), max(f_in)+1]) + spin_f.set_xlim([min(f_in), max(f_in) + 1]) spin_f.set_ylim([-200.0, 50.0]) spin_f.set_title("Input Signal", weight="bold") spin_f.set_xlabel("Frequency (Hz)") spin_f.set_ylabel("Power (dBW)") - Ts = 1.0 / fs - Tmax = len(d)*Ts + Tmax = len(d) * Ts t_in = numpy.arange(0, Tmax, Ts) x_in = numpy.array(d) @@ -141,21 +144,21 @@ def main(): # time signals on Figure 3 fs_o = tb._fs / tb._M Ts_o = 1.0 / fs_o - Tmax_o = len(d)*Ts_o + Tmax_o = len(d) * Ts_o for i in range(len(tb.snks)): # remove issues with the transients at the beginning # also remove some corruption at the end of the stream # this is a bug, probably due to the corner cases d = tb.snks[i].data()[Ns:Ne] - sp1_f = fig1.add_subplot(Nrows, Ncols, 1+i) - X,freq = mlab.psd(d, NFFT=fftlen, noverlap=fftlen / 4, Fs=fs_o, - window = lambda d: d*winfunc(fftlen), - scale_by_freq=True) - X_o = 10.0*numpy.log10(abs(X)) + sp1_f = fig1.add_subplot(Nrows, Ncols, 1 + i) + X, freq = mlab.psd(d, NFFT=fftlen, noverlap=fftlen / 4, Fs=fs_o, + window=lambda d: d * winfunc(fftlen), + scale_by_freq=True) + X_o = 10.0 * numpy.log10(abs(X)) f_o = freq p2_f = sp1_f.plot(f_o, X_o, "b") - sp1_f.set_xlim([min(f_o), max(f_o)+1]) + sp1_f.set_xlim([min(f_o), max(f_o) + 1]) sp1_f.set_ylim([-200.0, 50.0]) sp1_f.set_title(("Channel %d" % i), weight="bold") @@ -164,20 +167,19 @@ def main(): x_o = numpy.array(d) t_o = numpy.arange(0, Tmax_o, Ts_o) - sp2_o = fig2.add_subplot(Nrows, Ncols, 1+i) + sp2_o = fig2.add_subplot(Nrows, Ncols, 1 + i) p2_o = sp2_o.plot(t_o, x_o.real, "b") p2_o = sp2_o.plot(t_o, x_o.imag, "r") - sp2_o.set_xlim([min(t_o), max(t_o)+1]) + sp2_o.set_xlim([min(t_o), max(t_o) + 1]) sp2_o.set_ylim([-2, 2]) sp2_o.set_title(("Channel %d" % i), weight="bold") sp2_o.set_xlabel("Time (s)") sp2_o.set_ylabel("Amplitude") - - sp3 = fig3.add_subplot(1,1,1) + sp3 = fig3.add_subplot(1, 1, 1) p3 = sp3.plot(t_o, x_o.real) - sp3.set_xlim([min(t_o), max(t_o)+1]) + sp3.set_xlim([min(t_o), max(t_o) + 1]) sp3.set_ylim([-2, 2]) sp3.set_title("All Channels") @@ -192,4 +194,3 @@ if __name__ == "__main__": main() except KeyboardInterrupt: pass - diff --git a/gr-filter/examples/decimate.py b/gr-filter/examples/decimate.py index 8e2f3c7c36..f291e51eb4 100644 --- a/gr-filter/examples/decimate.py +++ b/gr-filter/examples/decimate.py @@ -12,7 +12,8 @@ from gnuradio import gr from gnuradio import blocks from gnuradio import filter from gnuradio.fft import window -import sys, time +import sys +import time import numpy try: @@ -26,9 +27,11 @@ try: from matplotlib import pyplot from matplotlib import pyplot as mlab except ImportError: - sys.stderr.write("Error: Program requires matplotlib (see: matplotlib.sourceforge.net).\n") + sys.stderr.write( + "Error: Program requires matplotlib (see: matplotlib.sourceforge.net).\n") sys.exit(1) + class pfb_top_block(gr.top_block): def __init__(self): gr.top_block.__init__(self) @@ -56,8 +59,9 @@ class pfb_top_block(gr.top_block): self.add = blocks.add_cc() freqs = [10, 20, 2040] for i in range(len(freqs)): - self.signals.append(analog.sig_source_c(self._fs, analog.GR_SIN_WAVE, freqs[i], 1)) - self.connect(self.signals[i], (self.add,i)) + self.signals.append(analog.sig_source_c( + self._fs, analog.GR_SIN_WAVE, freqs[i], 1)) + self.connect(self.signals[i], (self.add, i)) self.head = blocks.head(gr.sizeof_gr_complex, self._N) @@ -87,8 +91,8 @@ def main(): print("Run time: %f" % (tend - tstart)) if 1: - fig1 = pyplot.figure(1, figsize=(16,9)) - fig2 = pyplot.figure(2, figsize=(16,9)) + fig1 = pyplot.figure(1, figsize=(16, 9)) + fig2 = pyplot.figure(2, figsize=(16, 9)) Ns = 10000 Ne = 10000 @@ -99,16 +103,16 @@ def main(): # Plot the input to the decimator - d = tb.snk_i.data()[Ns:Ns+Ne] + d = tb.snk_i.data()[Ns:Ns + Ne] sp1_f = fig1.add_subplot(2, 1, 1) - X,freq = mlab.psd(d, NFFT=fftlen, noverlap=fftlen / 4, Fs=fs, - window = lambda d: d*winfunc(fftlen), - scale_by_freq=True) - X_in = 10.0*numpy.log10(abs(numpy.fft.fftshift(X))) + X, freq = mlab.psd(d, NFFT=fftlen, noverlap=fftlen / 4, Fs=fs, + window=lambda d: d * winfunc(fftlen), + scale_by_freq=True) + X_in = 10.0 * numpy.log10(abs(numpy.fft.fftshift(X))) f_in = numpy.arange(-fs / 2.0, fs / 2.0, fs / float(X_in.size)) p1_f = sp1_f.plot(f_in, X_in, "b") - sp1_f.set_xlim([min(f_in), max(f_in)+1]) + sp1_f.set_xlim([min(f_in), max(f_in) + 1]) sp1_f.set_ylim([-200.0, 50.0]) sp1_f.set_title("Input Signal", weight="bold") @@ -116,40 +120,38 @@ def main(): sp1_f.set_ylabel("Power (dBW)") Ts = 1.0 / fs - Tmax = len(d)*Ts + Tmax = len(d) * Ts t_in = numpy.arange(0, Tmax, Ts) x_in = numpy.array(d) sp1_t = fig1.add_subplot(2, 1, 2) p1_t = sp1_t.plot(t_in, x_in.real, "b") p1_t = sp1_t.plot(t_in, x_in.imag, "r") - sp1_t.set_ylim([-tb._decim*1.1, tb._decim*1.1]) + sp1_t.set_ylim([-tb._decim * 1.1, tb._decim * 1.1]) sp1_t.set_xlabel("Time (s)") sp1_t.set_ylabel("Amplitude") - # Plot the output of the decimator fs_o = tb._fs / tb._decim sp2_f = fig2.add_subplot(2, 1, 1) - d = tb.snk.data()[Ns:Ns+Ne] - X,freq = mlab.psd(d, NFFT=fftlen, noverlap=fftlen / 4, Fs=fs_o, - window = lambda d: d*winfunc(fftlen), - scale_by_freq=True) - X_o = 10.0*numpy.log10(abs(numpy.fft.fftshift(X))) + d = tb.snk.data()[Ns:Ns + Ne] + X, freq = mlab.psd(d, NFFT=fftlen, noverlap=fftlen / 4, Fs=fs_o, + window=lambda d: d * winfunc(fftlen), + scale_by_freq=True) + X_o = 10.0 * numpy.log10(abs(numpy.fft.fftshift(X))) f_o = numpy.arange(-fs_o / 2.0, fs_o / 2.0, fs_o / float(X_o.size)) p2_f = sp2_f.plot(f_o, X_o, "b") - sp2_f.set_xlim([min(f_o), max(f_o)+1]) + sp2_f.set_xlim([min(f_o), max(f_o) + 1]) sp2_f.set_ylim([-200.0, 50.0]) sp2_f.set_title("PFB Decimated Signal", weight="bold") sp2_f.set_xlabel("Frequency (Hz)") sp2_f.set_ylabel("Power (dBW)") - Ts_o = 1.0 / fs_o - Tmax_o = len(d)*Ts_o + Tmax_o = len(d) * Ts_o x_o = numpy.array(d) t_o = numpy.arange(0, Tmax_o, Ts_o) @@ -169,4 +171,3 @@ if __name__ == "__main__": main() except KeyboardInterrupt: pass - diff --git a/gr-filter/examples/fft_filter_ccc.py b/gr-filter/examples/fft_filter_ccc.py index afdc0f3127..c9a8353af2 100644 --- a/gr-filter/examples/fft_filter_ccc.py +++ b/gr-filter/examples/fft_filter_ccc.py @@ -23,6 +23,7 @@ except ImportError: print("Error: could not from matplotlib import pyplot (http://matplotlib.sourceforge.net/)") sys.exit(1) + class example_fft_filter_ccc(gr.top_block): def __init__(self, N, fs, bw0, bw1, tw, atten, D): gr.top_block.__init__(self) @@ -39,7 +40,7 @@ class example_fft_filter_ccc(gr.top_block): self._tw, self._at) print("Num. Taps: ", len(taps)) - self.src = analog.noise_source_c(analog.GR_GAUSSIAN, 1) + self.src = analog.noise_source_c(analog.GR_GAUSSIAN, 1) self.head = blocks.head(gr.sizeof_gr_complex, self._nsamps) self.filt0 = filter.fft_filter_ccc(self._decim, taps) @@ -50,22 +51,23 @@ class example_fft_filter_ccc(gr.top_block): self.connect(self.src, self.head, self.vsnk_src) self.connect(self.head, self.filt0, self.vsnk_out) + def main(): parser = ArgumentParser(conflict_handler="resolve") parser.add_argument("-N", "--nsamples", type=int, default=10000, - help="Number of samples to process [default=%(default)r]") + help="Number of samples to process [default=%(default)r]") parser.add_argument("-s", "--samplerate", type=eng_float, default=8000, - help="System sample rate [default=%(default)r]") + help="System sample rate [default=%(default)r]") parser.add_argument("-S", "--start-pass", type=eng_float, default=1000, - help="Start of Passband [default=%(default)r]") + help="Start of Passband [default=%(default)r]") parser.add_argument("-E", "--end-pass", type=eng_float, default=2000, - help="End of Passband [default=%(default)r]") + help="End of Passband [default=%(default)r]") parser.add_argument("-T", "--transition", type=eng_float, default=100, - help="Transition band [default=%(default)r]") + help="Transition band [default=%(default)r]") parser.add_argument("-A", "--attenuation", type=eng_float, default=80, - help="Stopband attenuation [default=%(default)r]") + help="Stopband attenuation [default=%(default)r]") parser.add_argument("-D", "--decimation", type=int, default=1, - help="Decmation factor [default=%(default)r]") + help="Decmation factor [default=%(default)r]") args = parser.parse_args() put = example_fft_filter_ccc(args.nsamples, @@ -82,23 +84,23 @@ def main(): # Plot the signals PSDs nfft = 1024 - f1 = pyplot.figure(1, figsize=(12,10)) - s1 = f1.add_subplot(1,1,1) + f1 = pyplot.figure(1, figsize=(12, 10)) + s1 = f1.add_subplot(1, 1, 1) s1.psd(data_src, NFFT=nfft, noverlap=nfft / 4, Fs=args.samplerate) s1.psd(data_snk, NFFT=nfft, noverlap=nfft / 4, Fs=args.samplerate) - f2 = pyplot.figure(2, figsize=(12,10)) - s2 = f2.add_subplot(1,1,1) + f2 = pyplot.figure(2, figsize=(12, 10)) + s2 = f2.add_subplot(1, 1, 1) s2.plot(data_src) s2.plot(data_snk.real, 'g') pyplot.show() + if __name__ == "__main__": try: main() except KeyboardInterrupt: pass - diff --git a/gr-filter/examples/fir_filter_ccc.py b/gr-filter/examples/fir_filter_ccc.py index 7e43735bb1..26ee561982 100644 --- a/gr-filter/examples/fir_filter_ccc.py +++ b/gr-filter/examples/fir_filter_ccc.py @@ -23,6 +23,7 @@ except ImportError: print("Error: could not from matplotlib import pyplot (http://matplotlib.sourceforge.net/)") sys.exit(1) + class example_fir_filter_ccc(gr.top_block): def __init__(self, N, fs, bw, tw, atten, D): gr.top_block.__init__(self) @@ -33,10 +34,11 @@ class example_fir_filter_ccc(gr.top_block): self._tw = tw self._at = atten self._decim = D - taps = filter.firdes.low_pass_2(1, self._fs, self._bw, self._tw, self._at) + taps = filter.firdes.low_pass_2( + 1, self._fs, self._bw, self._tw, self._at) print("Num. Taps: ", len(taps)) - self.src = analog.noise_source_c(analog.GR_GAUSSIAN, 1) + self.src = analog.noise_source_c(analog.GR_GAUSSIAN, 1) self.head = blocks.head(gr.sizeof_gr_complex, self._nsamps) self.filt0 = filter.fir_filter_ccc(self._decim, taps) @@ -47,20 +49,21 @@ class example_fir_filter_ccc(gr.top_block): self.connect(self.src, self.head, self.vsnk_src) self.connect(self.head, self.filt0, self.vsnk_out) + def main(): parser = ArgumentParser(conflict_handler="resolve") parser.add_argument("-N", "--nsamples", type=int, default=10000, - help="Number of samples to process [default=%(default)r]") + help="Number of samples to process [default=%(default)r]") parser.add_argument("-s", "--samplerate", type=eng_float, default=8000, - help="System sample rate [default=%(default)r]") + help="System sample rate [default=%(default)r]") parser.add_argument("-B", "--bandwidth", type=eng_float, default=1000, - help="Filter bandwidth [default=%(default)r]") + help="Filter bandwidth [default=%(default)r]") parser.add_argument("-T", "--transition", type=eng_float, default=100, - help="Transition band [default=%(default)r]") + help="Transition band [default=%(default)r]") parser.add_argument("-A", "--attenuation", type=eng_float, default=80, - help="Stopband attenuation [default=%(default)r]") + help="Stopband attenuation [default=%(default)r]") parser.add_argument("-D", "--decimation", type=int, default=1, - help="Decmation factor [default=%(default)r]") + help="Decmation factor [default=%(default)r]") args = parser.parse_args() put = example_fir_filter_ccc(args.nsamples, @@ -76,23 +79,23 @@ def main(): # Plot the signals PSDs nfft = 1024 - f1 = pyplot.figure(1, figsize=(12,10)) - s1 = f1.add_subplot(1,1,1) + f1 = pyplot.figure(1, figsize=(12, 10)) + s1 = f1.add_subplot(1, 1, 1) s1.psd(data_src, NFFT=nfft, noverlap=nfft / 4, Fs=args.samplerate) s1.psd(data_snk, NFFT=nfft, noverlap=nfft / 4, Fs=args.samplerate) - f2 = pyplot.figure(2, figsize=(12,10)) - s2 = f2.add_subplot(1,1,1) + f2 = pyplot.figure(2, figsize=(12, 10)) + s2 = f2.add_subplot(1, 1, 1) s2.plot(data_src) s2.plot(data_snk.real, 'g') pyplot.show() + if __name__ == "__main__": try: main() except KeyboardInterrupt: pass - diff --git a/gr-filter/examples/fir_filter_fff.py b/gr-filter/examples/fir_filter_fff.py index f634c44cf2..74c41b1ec7 100644 --- a/gr-filter/examples/fir_filter_fff.py +++ b/gr-filter/examples/fir_filter_fff.py @@ -23,6 +23,7 @@ except ImportError: print("Error: could not from matplotlib import pyplot (http://matplotlib.sourceforge.net/)") sys.exit(1) + class example_fir_filter_fff(gr.top_block): def __init__(self, N, fs, bw, tw, atten, D): gr.top_block.__init__(self) @@ -33,10 +34,11 @@ class example_fir_filter_fff(gr.top_block): self._tw = tw self._at = atten self._decim = D - taps = filter.firdes.low_pass_2(1, self._fs, self._bw, self._tw, self._at) + taps = filter.firdes.low_pass_2( + 1, self._fs, self._bw, self._tw, self._at) print("Num. Taps: ", len(taps)) - self.src = analog.noise_source_f(analog.GR_GAUSSIAN, 1) + self.src = analog.noise_source_f(analog.GR_GAUSSIAN, 1) self.head = blocks.head(gr.sizeof_float, self._nsamps) self.filt0 = filter.fir_filter_fff(self._decim, taps) @@ -47,20 +49,21 @@ class example_fir_filter_fff(gr.top_block): self.connect(self.src, self.head, self.vsnk_src) self.connect(self.head, self.filt0, self.vsnk_out) + def main(): parser = ArgumentParser(conflict_handler="resolve") parser.add_argument("-N", "--nsamples", type=int, default=10000, - help="Number of samples to process [default=%(default)r]") + help="Number of samples to process [default=%(default)r]") parser.add_argument("-s", "--samplerate", type=eng_float, default=8000, - help="System sample rate [default=%(default)r]") + help="System sample rate [default=%(default)r]") parser.add_argument("-B", "--bandwidth", type=eng_float, default=1000, - help="Filter bandwidth [default=%(default)r]") + help="Filter bandwidth [default=%(default)r]") parser.add_argument("-T", "--transition", type=eng_float, default=100, - help="Transition band [default=%(default)r]") + help="Transition band [default=%(default)r]") parser.add_argument("-A", "--attenuation", type=eng_float, default=80, - help="Stopband attenuation [default=%(default)r]") + help="Stopband attenuation [default=%(default)r]") parser.add_argument("-D", "--decimation", type=int, default=1, - help="Decmation factor [default=%(default)r]") + help="Decmation factor [default=%(default)r]") args = parser.parse_args() put = example_fir_filter_fff(args.nsamples, @@ -76,23 +79,23 @@ def main(): # Plot the signals PSDs nfft = 1024 - f1 = pyplot.figure(1, figsize=(12,10)) - s1 = f1.add_subplot(1,1,1) + f1 = pyplot.figure(1, figsize=(12, 10)) + s1 = f1.add_subplot(1, 1, 1) s1.psd(data_src, NFFT=nfft, noverlap=nfft / 4, Fs=args.samplerate) s1.psd(data_snk, NFFT=nfft, noverlap=nfft / 4, Fs=args.samplerate) - f2 = pyplot.figure(2, figsize=(12,10)) - s2 = f2.add_subplot(1,1,1) + f2 = pyplot.figure(2, figsize=(12, 10)) + s2 = f2.add_subplot(1, 1, 1) s2.plot(data_src) s2.plot(data_snk.real, 'g') pyplot.show() + if __name__ == "__main__": try: main() except KeyboardInterrupt: pass - diff --git a/gr-filter/examples/gr_filtdes_callback.py b/gr-filter/examples/gr_filtdes_callback.py index d27943174e..371f337d4d 100644 --- a/gr-filter/examples/gr_filtdes_callback.py +++ b/gr-filter/examples/gr_filtdes_callback.py @@ -23,14 +23,17 @@ or pole-zero plot is changed launch function returns gr_filter_design mainwindow object when callback is not None ''' + + def print_params(filtobj): print("Filter Count:", filtobj.get_filtercount()) print("Filter type:", filtobj.get_restype()) print("Filter params", filtobj.get_params()) print("Filter Coefficients", filtobj.get_taps()) + app = Qt.QApplication(sys.argv) -#launch function returns gr_filter_design mainwindow object +# launch function returns gr_filter_design mainwindow object main_win = filter_design.launch(sys.argv, print_params) main_win.show() app.exec_() diff --git a/gr-filter/examples/gr_filtdes_live_upd.py b/gr-filter/examples/gr_filtdes_live_upd.py index 3b1fd1e1c6..182b7535ae 100644 --- a/gr-filter/examples/gr_filtdes_live_upd.py +++ b/gr-filter/examples/gr_filtdes_live_upd.py @@ -41,6 +41,7 @@ except ImportError: sys.stderr.write("Error: Program requires gr-channels.\n") sys.exit(1) + class my_top_block(gr.top_block): def __init__(self): gr.top_block.__init__(self) @@ -53,24 +54,24 @@ class my_top_block(gr.top_block): self.qapp = QtGui.QApplication(sys.argv) - self.filt_taps = [1,] + self.filt_taps = [1, ] src1 = analog.sig_source_c(Rs, analog.GR_SIN_WAVE, f1, 0.1, 0) src2 = analog.sig_source_c(Rs, analog.GR_SIN_WAVE, f2, 0.1, 0) - src = blocks.add_cc() + src = blocks.add_cc() channel = channels.channel_model(0.01) self.filt = filter.fft_filter_ccc(1, self.filt_taps) - thr = blocks.throttle(gr.sizeof_gr_complex, 100*npts) + thr = blocks.throttle(gr.sizeof_gr_complex, 100 * npts) self.snk1 = qtgui.freq_sink_c(npts, window.WIN_BLACKMAN_hARRIS, 0, Rs, "Complex Freq Example", 1) - self.connect(src1, (src,0)) - self.connect(src2, (src,1)) - self.connect(src, channel, thr, self.filt, (self.snk1, 0)) + self.connect(src1, (src, 0)) + self.connect(src2, (src, 1)) + self.connect(src, channel, thr, self.filt, (self.snk1, 0)) # Get the reference pointer to the SpectrumDisplayForm QWidget - pyQt = self.snk1.qwidget() + pyQt = self.snk1.qwidget() # Wrap the pointer as a PyQt SIP object # This can now be manipulated as a PyQt5.QtGui.QWidget @@ -82,12 +83,11 @@ class my_top_block(gr.top_block): print("Filter params", filtobj.get_params()) self.filt.set_taps(filtobj.get_taps()) + if __name__ == "__main__": - tb = my_top_block(); + tb = my_top_block() tb.start() mw = filter_design.launch(sys.argv, tb.update_filter) mw.show() tb.qapp.exec_() tb.stop() - - diff --git a/gr-filter/examples/gr_filtdes_restrict.py b/gr-filter/examples/gr_filtdes_restrict.py index e707895717..7c734cbaf8 100644 --- a/gr-filter/examples/gr_filtdes_restrict.py +++ b/gr-filter/examples/gr_filtdes_restrict.py @@ -22,13 +22,16 @@ Callback with restrict example Function called when "design" button is pressed or pole-zero plot is changed ''' + + def print_params(filtobj): print("Filter Count:", filtobj.get_filtercount()) print("Filter type:", filtobj.get_restype()) print("Filter params", filtobj.get_params()) print("Filter Coefficients", filtobj.get_taps()) + app = Qt.QApplication(sys.argv) -main_win = filter_design.launch(sys.argv, callback = print_params, restype = "iir") +main_win = filter_design.launch(sys.argv, callback=print_params, restype="iir") main_win.show() app.exec_() diff --git a/gr-filter/examples/interpolate.py b/gr-filter/examples/interpolate.py index 8674566e25..5f6f1a5f5c 100644 --- a/gr-filter/examples/interpolate.py +++ b/gr-filter/examples/interpolate.py @@ -12,7 +12,8 @@ from gnuradio import gr from gnuradio import blocks from gnuradio import filter from gnuradio.fft import window -import sys, time +import sys +import time import numpy try: @@ -25,9 +26,11 @@ try: import pylab from pylab import mlab except ImportError: - sys.stderr.write("Error: Program requires matplotlib (see: matplotlib.sourceforge.net).\n") + sys.stderr.write( + "Error: Program requires matplotlib (see: matplotlib.sourceforge.net).\n") sys.exit(1) + class pfb_top_block(gr.top_block): def __init__(self): gr.top_block.__init__(self) @@ -44,8 +47,8 @@ class pfb_top_block(gr.top_block): # Create a set of taps for the PFB interpolator # This is based on the post-interpolation sample rate self._taps = filter.firdes.low_pass_2(self._interp, - self._interp*self._fs, - freq2+50, 50, + self._interp * self._fs, + freq2 + 50, 50, attenuation_dB=120, window=window.WIN_BLACKMAN_hARRIS) @@ -56,8 +59,8 @@ class pfb_top_block(gr.top_block): # internally as an interpolator. flt_size = 32 self._taps2 = filter.firdes.low_pass_2(flt_size, - flt_size*self._fs, - freq2+50, 150, + flt_size * self._fs, + freq2 + 50, 150, attenuation_dB=120, window=window.WIN_BLACKMAN_hARRIS) @@ -68,8 +71,10 @@ class pfb_top_block(gr.top_block): print("Taps per channel: ", tpc) # Create a couple of signals at different frequencies - self.signal1 = analog.sig_source_c(self._fs, analog.GR_SIN_WAVE, freq1, 0.5) - self.signal2 = analog.sig_source_c(self._fs, analog.GR_SIN_WAVE, freq2, 0.5) + self.signal1 = analog.sig_source_c( + self._fs, analog.GR_SIN_WAVE, freq1, 0.5) + self.signal2 = analog.sig_source_c( + self._fs, analog.GR_SIN_WAVE, freq2, 0.5) self.signal = blocks.add_cc() self.head = blocks.head(gr.sizeof_gr_complex, self._N) @@ -78,15 +83,16 @@ class pfb_top_block(gr.top_block): self.pfb = filter.pfb.interpolator_ccf(self._interp, self._taps) # Construct the PFB arbitrary resampler filter - self.pfb_ar = filter.pfb.arb_resampler_ccf(self._ainterp, self._taps2, flt_size) + self.pfb_ar = filter.pfb.arb_resampler_ccf( + self._ainterp, self._taps2, flt_size) self.snk_i = blocks.vector_sink_c() - #self.pfb_ar.pfb.print_taps() - #self.pfb.pfb.print_taps() + # self.pfb_ar.pfb.print_taps() + # self.pfb.pfb.print_taps() # Connect the blocks - self.connect(self.signal1, self.head, (self.signal,0)) - self.connect(self.signal2, (self.signal,1)) + self.connect(self.signal1, self.head, (self.signal, 0)) + self.connect(self.signal2, (self.signal, 1)) self.connect(self.signal, self.pfb) self.connect(self.signal, self.pfb_ar) self.connect(self.signal, self.snk_i) @@ -106,11 +112,10 @@ def main(): tend = time.time() print("Run time: %f" % (tend - tstart)) - if 1: - fig1 = pylab.figure(1, figsize=(12,10), facecolor="w") - fig2 = pylab.figure(2, figsize=(12,10), facecolor="w") - fig3 = pylab.figure(3, figsize=(12,10), facecolor="w") + fig1 = pylab.figure(1, figsize=(12, 10), facecolor="w") + fig2 = pylab.figure(2, figsize=(12, 10), facecolor="w") + fig3 = pylab.figure(3, figsize=(12, 10), facecolor="w") Ns = 10000 Ne = 10000 @@ -121,25 +126,24 @@ def main(): # Plot input signal fs = tb._fs - d = tb.snk_i.data()[Ns:Ns+Ne] + d = tb.snk_i.data()[Ns:Ns + Ne] sp1_f = fig1.add_subplot(2, 1, 1) - X,freq = mlab.psd(d, NFFT=fftlen, noverlap=fftlen / 4, Fs=fs, - window = lambda d: d*winfunc(fftlen), - scale_by_freq=True) - X_in = 10.0*numpy.log10(abs(numpy.fft.fftshift(X))) + X, freq = mlab.psd(d, NFFT=fftlen, noverlap=fftlen / 4, Fs=fs, + window=lambda d: d * winfunc(fftlen), + scale_by_freq=True) + X_in = 10.0 * numpy.log10(abs(numpy.fft.fftshift(X))) f_in = numpy.arange(-fs / 2.0, fs / 2.0, fs / float(X_in.size)) p1_f = sp1_f.plot(f_in, X_in, "b") - sp1_f.set_xlim([min(f_in), max(f_in)+1]) + sp1_f.set_xlim([min(f_in), max(f_in) + 1]) sp1_f.set_ylim([-200.0, 50.0]) - sp1_f.set_title("Input Signal", weight="bold") sp1_f.set_xlabel("Frequency (Hz)") sp1_f.set_ylabel("Power (dBW)") Ts = 1.0 / fs - Tmax = len(d)*Ts + Tmax = len(d) * Ts t_in = numpy.arange(0, Tmax, Ts) x_in = numpy.array(d) @@ -152,19 +156,19 @@ def main(): sp1_t.set_xlabel("Time (s)") sp1_t.set_ylabel("Amplitude") - # Plot output of PFB interpolator - fs_int = tb._fs*tb._interp + fs_int = tb._fs * tb._interp sp2_f = fig2.add_subplot(2, 1, 1) - d = tb.snk1.data()[Ns:Ns+(tb._interp*Ne)] - X,freq = mlab.psd(d, NFFT=fftlen, noverlap=fftlen / 4, Fs=fs, - window = lambda d: d*winfunc(fftlen), - scale_by_freq=True) - X_o = 10.0*numpy.log10(abs(numpy.fft.fftshift(X))) - f_o = numpy.arange(-fs_int / 2.0, fs_int / 2.0, fs_int / float(X_o.size)) + d = tb.snk1.data()[Ns:Ns + (tb._interp * Ne)] + X, freq = mlab.psd(d, NFFT=fftlen, noverlap=fftlen / 4, Fs=fs, + window=lambda d: d * winfunc(fftlen), + scale_by_freq=True) + X_o = 10.0 * numpy.log10(abs(numpy.fft.fftshift(X))) + f_o = numpy.arange(-fs_int / 2.0, fs_int / 2.0, + fs_int / float(X_o.size)) p2_f = sp2_f.plot(f_o, X_o, "b") - sp2_f.set_xlim([min(f_o), max(f_o)+1]) + sp2_f.set_xlim([min(f_o), max(f_o) + 1]) sp2_f.set_ylim([-200.0, 50.0]) sp2_f.set_title("Output Signal from PFB Interpolator", weight="bold") @@ -172,7 +176,7 @@ def main(): sp2_f.set_ylabel("Power (dBW)") Ts_int = 1.0 / fs_int - Tmax = len(d)*Ts_int + Tmax = len(d) * Ts_int t_o = numpy.arange(0, Tmax, Ts_int) x_o1 = numpy.array(d) @@ -185,27 +189,28 @@ def main(): sp2_t.set_xlabel("Time (s)") sp2_t.set_ylabel("Amplitude") - # Plot output of PFB arbitrary resampler fs_aint = tb._fs * tb._ainterp sp3_f = fig3.add_subplot(2, 1, 1) - d = tb.snk2.data()[Ns:Ns+(tb._interp*Ne)] - X,freq = mlab.psd(d, NFFT=fftlen, noverlap=fftlen / 4, Fs=fs, - window = lambda d: d*winfunc(fftlen), - scale_by_freq=True) - X_o = 10.0*numpy.log10(abs(numpy.fft.fftshift(X))) - f_o = numpy.arange(-fs_aint / 2.0, fs_aint / 2.0, fs_aint / float(X_o.size)) + d = tb.snk2.data()[Ns:Ns + (tb._interp * Ne)] + X, freq = mlab.psd(d, NFFT=fftlen, noverlap=fftlen / 4, Fs=fs, + window=lambda d: d * winfunc(fftlen), + scale_by_freq=True) + X_o = 10.0 * numpy.log10(abs(numpy.fft.fftshift(X))) + f_o = numpy.arange(-fs_aint / 2.0, fs_aint / 2.0, + fs_aint / float(X_o.size)) p3_f = sp3_f.plot(f_o, X_o, "b") - sp3_f.set_xlim([min(f_o), max(f_o)+1]) + sp3_f.set_xlim([min(f_o), max(f_o) + 1]) sp3_f.set_ylim([-200.0, 50.0]) - sp3_f.set_title("Output Signal from PFB Arbitrary Resampler", weight="bold") + sp3_f.set_title( + "Output Signal from PFB Arbitrary Resampler", weight="bold") sp3_f.set_xlabel("Frequency (Hz)") sp3_f.set_ylabel("Power (dBW)") Ts_aint = 1.0 / fs_aint - Tmax = len(d)*Ts_aint + Tmax = len(d) * Ts_aint t_o = numpy.arange(0, Tmax, Ts_aint) x_o2 = numpy.array(d) @@ -215,7 +220,8 @@ def main(): #p3_f = sp3_f.plot(t_o, x_o2.imag, "r-o") sp3_f.set_ylim([-2.5, 2.5]) - sp3_f.set_title("Output Signal from PFB Arbitrary Resampler", weight="bold") + sp3_f.set_title( + "Output Signal from PFB Arbitrary Resampler", weight="bold") sp3_f.set_xlabel("Time (s)") sp3_f.set_ylabel("Amplitude") @@ -227,4 +233,3 @@ if __name__ == "__main__": main() except KeyboardInterrupt: pass - diff --git a/gr-filter/examples/reconstruction.py b/gr-filter/examples/reconstruction.py index 8b65f70deb..2a34f9e33f 100644 --- a/gr-filter/examples/reconstruction.py +++ b/gr-filter/examples/reconstruction.py @@ -29,11 +29,12 @@ except ImportError: fftlen = 8192 + def main(): N = 10000 fs = 2000.0 Ts = 1.0 / fs - t = numpy.arange(0, N*Ts, Ts) + t = numpy.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. @@ -42,12 +43,11 @@ def main(): # Build the filter(s) bw = 1000 tb = 400 - proto_taps = filter.firdes.low_pass_2(1, nchans*fs, + proto_taps = filter.firdes.low_pass_2(1, nchans * fs, bw, tb, 80, window.WIN_BLACKMAN_hARRIS) print("Filter length: ", len(proto_taps)) - # Create a modulated signal npwr = 0.01 data = numpy.random.randint(0, 256, N) @@ -62,7 +62,7 @@ def main(): channelizer = filter.pfb.channelizer_ccf(nchans, proto_taps, 2) # Put the pieces back together again - syn_taps = [nchans*t for t in proto_taps] + 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() @@ -70,7 +70,7 @@ def main(): # 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, + synthesizer.set_channel_map([0, 1, 2, 3, 4, 15, 16, 17, 18, 19]) tb = gr.top_block() @@ -79,34 +79,33 @@ def main(): vsnk = [] for i in range(nchans): - tb.connect((channelizer,i), (synthesizer, i)) + tb.connect((channelizer, i), (synthesizer, i)) vsnk.append(blocks.vector_sink_c()) - tb.connect((channelizer,i), vsnk[i]) + tb.connect((channelizer, i), vsnk[i]) tb.connect(synthesizer, snk) tb.run() - sin = numpy.array(src_snk.data()[1000:]) + sin = numpy.array(src_snk.data()[1000:]) sout = numpy.array(snk.data()[1000:]) - # Plot original signal - fs_in = nchans*fs - f1 = pyplot.figure(1, figsize=(16,12), facecolor='w') - s11 = f1.add_subplot(2,2,1) + fs_in = nchans * fs + f1 = pyplot.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 = 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) + 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]) @@ -116,29 +115,29 @@ def main(): nrows = int(numpy.sqrt(nchans)) ncols = int(numpy.ceil(float(nchans) / float(nrows))) - f2 = pyplot.figure(2, figsize=(16,12), facecolor='w') + f2 = pyplot.figure(2, figsize=(16, 12), facecolor='w') for n in range(nchans): - s = f2.add_subplot(nrows, ncols, n+1) + 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 = pyplot.figure(3, figsize=(16,12), facecolor='w') - s31 = f3.add_subplot(2,2,1) + fs_out = 2 * nchans * fs + f3 = pyplot.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 = 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) + 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]) @@ -152,4 +151,3 @@ if __name__ == "__main__": main() except KeyboardInterrupt: pass - diff --git a/gr-filter/examples/resampler.py b/gr-filter/examples/resampler.py index 0208bac188..282eaa1286 100644 --- a/gr-filter/examples/resampler.py +++ b/gr-filter/examples/resampler.py @@ -23,15 +23,17 @@ except ImportError: try: from matplotlib import pyplot except ImportError: - sys.stderr.write("Error: Program requires matplotlib (see: matplotlib.sourceforge.net).\n") + sys.stderr.write( + "Error: Program requires matplotlib (see: matplotlib.sourceforge.net).\n") sys.exit(1) + class mytb(gr.top_block): def __init__(self, fs_in, fs_out, fc, N=10000): gr.top_block.__init__(self) rerate = float(fs_out) / float(fs_in) - print("Resampling from %f to %f by %f " %(fs_in, fs_out, rerate)) + print("Resampling from %f to %f by %f " % (fs_in, fs_out, rerate)) # Creating our own taps taps = filter.firdes.low_pass_2(32, 32, 0.25, 0.1, 80) @@ -59,6 +61,7 @@ class mytb(gr.top_block): self.connect(self.head, self.resamp_0, self.snk_0) self.connect(self.head, self.resamp_1, self.snk_1) + def main(): fs_in = 8000 fs_out = 20000 @@ -68,22 +71,21 @@ def main(): tb = mytb(fs_in, fs_out, fc, N) tb.run() - # Plot PSD of signals nfftsize = 2048 - fig1 = pyplot.figure(1, figsize=(10,10), facecolor="w") - sp1 = fig1.add_subplot(2,1,1) + fig1 = pyplot.figure(1, figsize=(10, 10), facecolor="w") + sp1 = fig1.add_subplot(2, 1, 1) sp1.psd(tb.snk_in.data(), NFFT=nfftsize, - noverlap=nfftsize / 4, Fs = fs_in) + noverlap=nfftsize / 4, Fs=fs_in) sp1.set_title(("Input Signal at f_s=%.2f kHz" % (fs_in / 1000.0))) sp1.set_xlim([-fs_in / 2, fs_in / 2]) - sp2 = fig1.add_subplot(2,1,2) + sp2 = fig1.add_subplot(2, 1, 2) sp2.psd(tb.snk_0.data(), NFFT=nfftsize, - noverlap=nfftsize / 4, Fs = fs_out, + noverlap=nfftsize / 4, Fs=fs_out, label="With our filter") sp2.psd(tb.snk_1.data(), NFFT=nfftsize, - noverlap=nfftsize / 4, Fs = fs_out, + noverlap=nfftsize / 4, Fs=fs_out, label="With auto-generated filter") sp2.set_title(("Output Signals at f_s=%.2f kHz" % (fs_out / 1000.0))) sp2.set_xlim([-fs_out / 2, fs_out / 2]) @@ -92,16 +94,16 @@ def main(): # Plot signals in time Ts_in = 1.0 / fs_in Ts_out = 1.0 / fs_out - t_in = numpy.arange(0, len(tb.snk_in.data())*Ts_in, Ts_in) - t_out = numpy.arange(0, len(tb.snk_0.data())*Ts_out, Ts_out) + t_in = numpy.arange(0, len(tb.snk_in.data()) * Ts_in, Ts_in) + t_out = numpy.arange(0, len(tb.snk_0.data()) * Ts_out, Ts_out) - fig2 = pyplot.figure(2, figsize=(10,10), facecolor="w") - sp21 = fig2.add_subplot(2,1,1) + fig2 = pyplot.figure(2, figsize=(10, 10), facecolor="w") + sp21 = fig2.add_subplot(2, 1, 1) sp21.plot(t_in, tb.snk_in.data()) sp21.set_title(("Input Signal at f_s=%.2f kHz" % (fs_in / 1000.0))) sp21.set_xlim([t_in[100], t_in[200]]) - sp22 = fig2.add_subplot(2,1,2) + sp22 = fig2.add_subplot(2, 1, 2) sp22.plot(t_out, tb.snk_0.data(), label="With our filter") sp22.plot(t_out, tb.snk_1.data(), @@ -113,6 +115,6 @@ def main(): pyplot.show() + if __name__ == "__main__": main() - diff --git a/gr-filter/examples/synth_filter.py b/gr-filter/examples/synth_filter.py index 2e8509feea..8c4f6e13ba 100644 --- a/gr-filter/examples/synth_filter.py +++ b/gr-filter/examples/synth_filter.py @@ -23,9 +23,11 @@ except ImportError: try: from matplotlib import pyplot except ImportError: - sys.stderr.write("Error: Program requires matplotlib (see: matplotlib.sourceforge.net).\n") + sys.stderr.write( + "Error: Program requires matplotlib (see: matplotlib.sourceforge.net).\n") sys.exit(1) + def main(): N = 1000000 fs = 8000 @@ -39,7 +41,7 @@ def main(): sigs.append(s) taps = filter.firdes.low_pass_2(len(freqs), fs, - fs/float(nchans)/2, 100, 100) + 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) @@ -50,26 +52,27 @@ def main(): tb = gr.top_block() tb.connect(filtbank, head, snk) - for i,si in enumerate(sigs): + 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 = f1.add_subplot(1, 1, 1) s1.plot(snk.data()[1000:]) fftlen = 2048 f2 = pyplot.figure(2) - s2 = f2.add_subplot(1,1,1) + s2 = f2.add_subplot(1, 1, 1) winfunc = numpy.blackman s2.psd(snk.data()[10000:], NFFT=fftlen, - Fs = nchans*fs, + Fs=nchans * fs, noverlap=fftlen / 4, - window = lambda d: d*winfunc(fftlen)) + window=lambda d: d * winfunc(fftlen)) pyplot.show() + if __name__ == "__main__": main() diff --git a/gr-filter/examples/synth_to_chan.py b/gr-filter/examples/synth_to_chan.py index 9a64e14ebf..450197e09e 100644 --- a/gr-filter/examples/synth_to_chan.py +++ b/gr-filter/examples/synth_to_chan.py @@ -23,9 +23,11 @@ except ImportError: try: from matplotlib import pyplot except ImportError: - sys.stderr.write("Error: Program requires matplotlib (see: matplotlib.sourceforge.net).\n") + sys.stderr.write( + "Error: Program requires matplotlib (see: matplotlib.sourceforge.net).\n") sys.exit(1) + def main(): N = 1000000 fs = 8000 @@ -37,14 +39,17 @@ def main(): 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) + 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) + 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) + 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) @@ -58,13 +63,13 @@ def main(): tb = gr.top_block() - tb.connect(noise, (addnoise,0)) + 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): + for i, si in enumerate(sigs): tb.connect(si, fmtx[i], (filtbank, i)) for i in range(nchans): @@ -78,8 +83,8 @@ def main(): data = snk[channel].data()[1000:] f1 = pyplot.figure(1) - s1 = f1.add_subplot(1,1,1) - s1.plot(data[10000:10200] ) + s1 = f1.add_subplot(1, 1, 1) + s1.plot(data[10000:10200]) s1.set_title(("Output Signal from Channel %d" % channel)) fftlen = 2048 @@ -87,22 +92,23 @@ def main(): #winfunc = numpy.hamming f2 = pyplot.figure(2) - s2 = f2.add_subplot(1,1,1) + s2 = f2.add_subplot(1, 1, 1) s2.psd(data, NFFT=fftlen, - Fs = nchans*fs, + Fs=nchans * fs, noverlap=fftlen / 4, - window = lambda d: d*winfunc(fftlen)) + window=lambda d: d * winfunc(fftlen)) s2.set_title(("Output PSD from Channel %d" % channel)) f3 = pyplot.figure(3) - s3 = f3.add_subplot(1,1,1) + s3 = f3.add_subplot(1, 1, 1) s3.psd(snk_synth.data()[1000:], NFFT=fftlen, - Fs = nchans*fs, + Fs=nchans * fs, noverlap=fftlen / 4, - window = lambda d: d*winfunc(fftlen)) + window=lambda d: d * winfunc(fftlen)) s3.set_title("Output of Synthesis Filter") pyplot.show() + if __name__ == "__main__": main() |