diff options
author | Marcus Müller <marcus@hostalia.de> | 2018-08-24 23:00:55 +0200 |
---|---|---|
committer | Marcus Müller <marcus@hostalia.de> | 2018-11-02 22:15:53 +0100 |
commit | 797994a11ac5ec6bee9ea01c092947d0c34115f1 (patch) | |
tree | 7381f53008ba56e6b93398fa92be482d12da4f43 /gr-filter | |
parent | e07751acc8424f4dd987f79c32dd247ed347902c (diff) |
Replace scipy/pylab where numpy/pyplot is sufficient
This should reduce the number of times users are prompted to install
pylab || scipy when they'd actually get away with functionality fully
contained in numpy and matplotlib.
This only solves the obvious cases. There's some usage of `pylab.mlab`
that would need more than 20s of consideration.
Diffstat (limited to 'gr-filter')
-rw-r--r-- | gr-filter/examples/channelize.py | 32 | ||||
-rw-r--r-- | gr-filter/examples/chirp_channelize.py | 32 | ||||
-rw-r--r-- | gr-filter/examples/decimate.py | 37 | ||||
-rw-r--r-- | gr-filter/examples/fft_filter_ccc.py | 21 | ||||
-rw-r--r-- | gr-filter/examples/fir_filter_ccc.py | 21 | ||||
-rw-r--r-- | gr-filter/examples/fir_filter_fff.py | 21 | ||||
-rw-r--r-- | gr-filter/examples/interpolate.py | 36 | ||||
-rw-r--r-- | gr-filter/examples/reconstruction.py | 32 | ||||
-rw-r--r-- | gr-filter/examples/resampler.py | 19 | ||||
-rw-r--r-- | gr-filter/examples/synth_filter.py | 17 | ||||
-rw-r--r-- | gr-filter/examples/synth_to_chan.py | 21 | ||||
-rw-r--r-- | gr-filter/python/filter/design/filter_design.py | 67 | ||||
-rw-r--r-- | gr-filter/python/filter/gui/idealbanditems.py | 30 |
13 files changed, 164 insertions, 222 deletions
diff --git a/gr-filter/examples/channelize.py b/gr-filter/examples/channelize.py index 51f0bad20b..2f0e4c02b3 100644 --- a/gr-filter/examples/channelize.py +++ b/gr-filter/examples/channelize.py @@ -27,6 +27,7 @@ from gnuradio import gr from gnuradio import blocks from gnuradio import filter import sys, time +import numpy try: from gnuradio import analog @@ -35,13 +36,6 @@ except ImportError: sys.exit(1) try: - import scipy - from scipy import fftpack -except ImportError: - sys.stderr.write("Error: Program requires scipy (see: www.scipy.org).\n") - sys.exit(1) - -try: import pylab from pylab import mlab except ImportError: @@ -63,7 +57,7 @@ class pfb_top_block(gr.top_block): window=filter.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)) + tpc = numpy.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) @@ -119,7 +113,7 @@ def main(): Ne = 10000 fftlen = 8192 - winfunc = scipy.blackman + winfunc = numpy.blackman fs = tb._ifs # Plot the input signal on its own figure @@ -129,8 +123,8 @@ def main(): 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*scipy.log10(abs(X)) - f_in = scipy.arange(-fs / 2.0, fs / 2.0, fs / float(X_in.size)) + 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_ylim([-200.0, 50.0]) @@ -143,8 +137,8 @@ def main(): Ts = 1.0 / fs Tmax = len(d)*Ts - t_in = scipy.arange(0, Tmax, Ts) - x_in = scipy.array(d) + t_in = numpy.arange(0, Tmax, Ts) + x_in = numpy.array(d) spin_t = fig_in.add_subplot(2, 1, 2) pin_t = spin_t.plot(t_in, x_in.real, "b") pin_t = spin_t.plot(t_in, x_in.imag, "r") @@ -152,8 +146,8 @@ def main(): spin_t.set_xlabel("Time (s)") spin_t.set_ylabel("Amplitude") - Ncols = int(scipy.floor(scipy.sqrt(tb._M))) - Nrows = int(scipy.floor(tb._M / Ncols)) + Ncols = int(numpy.floor(numpy.sqrt(tb._M))) + Nrows = int(numpy.floor(tb._M / Ncols)) if(tb._M % Ncols != 0): Nrows += 1 @@ -172,8 +166,8 @@ def main(): 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*scipy.log10(abs(X)) - f_o = scipy.arange(-fs_o / 2.0, fs_o / 2.0, fs_o / float(X_o.size)) + 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_ylim([-200.0, 50.0]) @@ -182,8 +176,8 @@ def main(): sp1_f.set_xlabel("Frequency (Hz)") sp1_f.set_ylabel("Power (dBW)") - x_o = scipy.array(d) - t_o = scipy.arange(0, Tmax_o, Ts_o) + x_o = numpy.array(d) + t_o = numpy.arange(0, Tmax_o, Ts_o) 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") diff --git a/gr-filter/examples/chirp_channelize.py b/gr-filter/examples/chirp_channelize.py index 471416b6a5..1d2cab88cf 100644 --- a/gr-filter/examples/chirp_channelize.py +++ b/gr-filter/examples/chirp_channelize.py @@ -27,6 +27,7 @@ from gnuradio import gr from gnuradio import blocks from gnuradio import filter import sys, time +import numpy try: from gnuradio import analog @@ -35,13 +36,6 @@ except ImportError: sys.exit(1) try: - import scipy - from scipy import fftpack -except ImportError: - sys.stderr.write("Error: Program requires scipy (see: www.scipy.org).\n") - sys.exit(1) - -try: import pylab from pylab import mlab except ImportError: @@ -62,7 +56,7 @@ class pfb_top_block(gr.top_block): window=filter.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)) + tpc = numpy.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) @@ -72,7 +66,7 @@ class pfb_top_block(gr.top_block): self.vco_input = analog.sig_source_f(self._fs, analog.GR_SIN_WAVE, 0.25, 110) else: amp = 100 - data = scipy.arange(0, amp, amp / float(self._N)) + data = numpy.arange(0, amp, amp / float(self._N)) self.vco_input = blocks.vector_source_f(data, False) # Build a VCO controlled by either the sinusoid or single chirp tone @@ -119,7 +113,7 @@ def main(): Ne = 20000 fftlen = 8192 - winfunc = scipy.blackman + winfunc = numpy.blackman fs = tb._fs # Plot the input signal on its own figure @@ -129,8 +123,8 @@ def main(): 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*scipy.log10(abs(fftpack.fftshift(X))) - f_in = scipy.arange(-fs / 2.0, fs / 2.0, fs / float(X_in.size)) + 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_ylim([-200.0, 50.0]) @@ -143,8 +137,8 @@ def main(): Ts = 1.0 / fs Tmax = len(d)*Ts - t_in = scipy.arange(0, Tmax, Ts) - x_in = scipy.array(d) + t_in = numpy.arange(0, Tmax, Ts) + x_in = numpy.array(d) spin_t = fig_in.add_subplot(2, 1, 2) pin_t = spin_t.plot(t_in, x_in.real, "b") pin_t = spin_t.plot(t_in, x_in.imag, "r") @@ -152,8 +146,8 @@ def main(): spin_t.set_xlabel("Time (s)") spin_t.set_ylabel("Amplitude") - Ncols = int(scipy.floor(scipy.sqrt(tb._M))) - Nrows = int(scipy.floor(tb._M / Ncols)) + Ncols = int(numpy.floor(numpy.sqrt(tb._M))) + Nrows = int(numpy.floor(tb._M / Ncols)) if(tb._M % Ncols != 0): Nrows += 1 @@ -172,7 +166,7 @@ def main(): 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*scipy.log10(abs(X)) + 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]) @@ -182,8 +176,8 @@ def main(): sp1_f.set_xlabel("Frequency (Hz)") sp1_f.set_ylabel("Power (dBW)") - x_o = scipy.array(d) - t_o = scipy.arange(0, Tmax_o, Ts_o) + x_o = numpy.array(d) + t_o = numpy.arange(0, Tmax_o, Ts_o) 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") diff --git a/gr-filter/examples/decimate.py b/gr-filter/examples/decimate.py index fb37d8047e..7ebd5a28ed 100644 --- a/gr-filter/examples/decimate.py +++ b/gr-filter/examples/decimate.py @@ -27,6 +27,7 @@ from gnuradio import gr from gnuradio import blocks from gnuradio import filter import sys, time +import numpy try: from gnuradio import analog @@ -34,16 +35,10 @@ except ImportError: sys.stderr.write("Error: Program requires gr-analog.\n") sys.exit(1) -try: - import scipy - from scipy import fftpack -except ImportError: - sys.stderr.write("Error: Program requires scipy (see: www.scipy.org).\n") - sys.exit(1) try: - import pylab - from pylab import mlab + 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.exit(1) @@ -63,7 +58,7 @@ class pfb_top_block(gr.top_block): window=filter.firdes.WIN_BLACKMAN_hARRIS) # Calculate the number of taps per channel for our own information - tpc = scipy.ceil(float(len(self._taps)) / float(self._decim)) + tpc = numpy.ceil(float(len(self._taps)) / float(self._decim)) print("Number of taps: ", len(self._taps)) print("Number of filters: ", self._decim) print("Taps per channel: ", tpc) @@ -106,14 +101,14 @@ def main(): print("Run time: %f" % (tend - tstart)) if 1: - fig1 = pylab.figure(1, figsize=(16,9)) - fig2 = pylab.figure(2, figsize=(16,9)) + fig1 = pyplot.figure(1, figsize=(16,9)) + fig2 = pyplot.figure(2, figsize=(16,9)) Ns = 10000 Ne = 10000 fftlen = 8192 - winfunc = scipy.blackman + winfunc = numpy.blackman fs = tb._fs # Plot the input to the decimator @@ -124,8 +119,8 @@ def main(): 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*scipy.log10(abs(fftpack.fftshift(X))) - f_in = scipy.arange(-fs / 2.0, fs / 2.0, fs / float(X_in.size)) + 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_ylim([-200.0, 50.0]) @@ -137,8 +132,8 @@ def main(): Ts = 1.0 / fs Tmax = len(d)*Ts - t_in = scipy.arange(0, Tmax, Ts) - x_in = scipy.array(d) + 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") @@ -156,8 +151,8 @@ def main(): 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*scipy.log10(abs(fftpack.fftshift(X))) - f_o = scipy.arange(-fs_o / 2.0, fs_o / 2.0, fs_o / float(X_o.size)) + 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_ylim([-200.0, 50.0]) @@ -170,8 +165,8 @@ def main(): Ts_o = 1.0 / fs_o Tmax_o = len(d)*Ts_o - x_o = scipy.array(d) - t_o = scipy.arange(0, Tmax_o, Ts_o) + x_o = numpy.array(d) + t_o = numpy.arange(0, Tmax_o, Ts_o) sp2_t = fig2.add_subplot(2, 1, 2) p2_t = sp2_t.plot(t_o, x_o.real, "b-o") p2_t = sp2_t.plot(t_o, x_o.imag, "r-o") @@ -180,7 +175,7 @@ def main(): sp2_t.set_xlabel("Time (s)") sp2_t.set_ylabel("Amplitude") - pylab.show() + pyplot.show() if __name__ == "__main__": diff --git a/gr-filter/examples/fft_filter_ccc.py b/gr-filter/examples/fft_filter_ccc.py index 6cadddee1f..4fadce5de5 100644 --- a/gr-filter/examples/fft_filter_ccc.py +++ b/gr-filter/examples/fft_filter_ccc.py @@ -30,17 +30,12 @@ from gnuradio import eng_notation from gnuradio.eng_arg import eng_float, intx from argparse import ArgumentParser import sys +import numpy try: - import scipy + from matplotlib import pyplot except ImportError: - print("Error: could not import scipy (http://www.scipy.org/)") - sys.exit(1) - -try: - import pylab -except ImportError: - print("Error: could not import pylab (http://matplotlib.sourceforge.net/)") + print("Error: could not from matplotlib import pyplot (http://matplotlib.sourceforge.net/)") sys.exit(1) class example_fft_filter_ccc(gr.top_block): @@ -97,24 +92,24 @@ def main(): args.decimation) put.run() - data_src = scipy.array(put.vsnk_src.data()) - data_snk = scipy.array(put.vsnk_out.data()) + data_src = numpy.array(put.vsnk_src.data()) + data_snk = numpy.array(put.vsnk_out.data()) # Plot the signals PSDs nfft = 1024 - f1 = pylab.figure(1, figsize=(12,10)) + 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 = pylab.figure(2, figsize=(12,10)) + f2 = pyplot.figure(2, figsize=(12,10)) s2 = f2.add_subplot(1,1,1) s2.plot(data_src) s2.plot(data_snk.real, 'g') - pylab.show() + pyplot.show() if __name__ == "__main__": try: diff --git a/gr-filter/examples/fir_filter_ccc.py b/gr-filter/examples/fir_filter_ccc.py index fe5e7e0254..ac0c3dabdc 100644 --- a/gr-filter/examples/fir_filter_ccc.py +++ b/gr-filter/examples/fir_filter_ccc.py @@ -30,17 +30,12 @@ from gnuradio import eng_notation from gnuradio.eng_arg import eng_float, intx from argparse import ArgumentParser import sys +import numpy try: - import scipy + from matplotlib import pyplot except ImportError: - print("Error: could not import scipy (http://www.scipy.org/)") - sys.exit(1) - -try: - import pylab -except ImportError: - print("Error: could not import pylab (http://matplotlib.sourceforge.net/)") + print("Error: could not from matplotlib import pyplot (http://matplotlib.sourceforge.net/)") sys.exit(1) class example_fir_filter_ccc(gr.top_block): @@ -91,24 +86,24 @@ def main(): args.decimation) put.run() - data_src = scipy.array(put.vsnk_src.data()) - data_snk = scipy.array(put.vsnk_out.data()) + data_src = numpy.array(put.vsnk_src.data()) + data_snk = numpy.array(put.vsnk_out.data()) # Plot the signals PSDs nfft = 1024 - f1 = pylab.figure(1, figsize=(12,10)) + 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 = pylab.figure(2, figsize=(12,10)) + f2 = pyplot.figure(2, figsize=(12,10)) s2 = f2.add_subplot(1,1,1) s2.plot(data_src) s2.plot(data_snk.real, 'g') - pylab.show() + pyplot.show() if __name__ == "__main__": try: diff --git a/gr-filter/examples/fir_filter_fff.py b/gr-filter/examples/fir_filter_fff.py index c4c9ea2c83..b4e72410d4 100644 --- a/gr-filter/examples/fir_filter_fff.py +++ b/gr-filter/examples/fir_filter_fff.py @@ -30,17 +30,12 @@ from gnuradio import eng_notation from gnuradio.eng_arg import eng_float, intx from argparse import ArgumentParser import sys +import numpy try: - import scipy + from matplotlib import pyplot except ImportError: - print("Error: could not import scipy (http://www.scipy.org/)") - sys.exit(1) - -try: - import pylab -except ImportError: - print("Error: could not import pylab (http://matplotlib.sourceforge.net/)") + print("Error: could not from matplotlib import pyplot (http://matplotlib.sourceforge.net/)") sys.exit(1) class example_fir_filter_fff(gr.top_block): @@ -91,24 +86,24 @@ def main(): args.decimation) put.run() - data_src = scipy.array(put.vsnk_src.data()) - data_snk = scipy.array(put.vsnk_out.data()) + data_src = numpy.array(put.vsnk_src.data()) + data_snk = numpy.array(put.vsnk_out.data()) # Plot the signals PSDs nfft = 1024 - f1 = pylab.figure(1, figsize=(12,10)) + 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 = pylab.figure(2, figsize=(12,10)) + f2 = pyplot.figure(2, figsize=(12,10)) s2 = f2.add_subplot(1,1,1) s2.plot(data_src) s2.plot(data_snk.real, 'g') - pylab.show() + pyplot.show() if __name__ == "__main__": try: diff --git a/gr-filter/examples/interpolate.py b/gr-filter/examples/interpolate.py index 1f1357211b..94c90c2b03 100644 --- a/gr-filter/examples/interpolate.py +++ b/gr-filter/examples/interpolate.py @@ -27,6 +27,7 @@ from gnuradio import gr from gnuradio import blocks from gnuradio import filter import sys, time +import numpy try: from gnuradio import analog @@ -35,13 +36,6 @@ except ImportError: sys.exit(1) try: - import scipy - from scipy import fftpack -except ImportError: - sys.stderr.write("Error: Program requires scipy (see: www.scipy.org).\n") - sys.exit(1) - -try: import pylab from pylab import mlab except ImportError: @@ -82,7 +76,7 @@ class pfb_top_block(gr.top_block): window=filter.firdes.WIN_BLACKMAN_hARRIS) # Calculate the number of taps per channel for our own information - tpc = scipy.ceil(float(len(self._taps)) / float(self._interp)) + tpc = numpy.ceil(float(len(self._taps)) / float(self._interp)) print("Number of taps: ", len(self._taps)) print("Number of filters: ", self._interp) print("Taps per channel: ", tpc) @@ -136,7 +130,7 @@ def main(): Ne = 10000 fftlen = 8192 - winfunc = scipy.blackman + winfunc = numpy.blackman # Plot input signal fs = tb._fs @@ -147,8 +141,8 @@ def main(): 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*scipy.log10(abs(fftpack.fftshift(X))) - f_in = scipy.arange(-fs / 2.0, fs / 2.0, fs / float(X_in.size)) + 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_ylim([-200.0, 50.0]) @@ -161,8 +155,8 @@ def main(): Ts = 1.0 / fs Tmax = len(d)*Ts - t_in = scipy.arange(0, Tmax, Ts) - x_in = scipy.array(d) + 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-o") #p1_t = sp1_t.plot(t_in, x_in.imag, "r-o") @@ -181,8 +175,8 @@ def main(): 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*scipy.log10(abs(fftpack.fftshift(X))) - f_o = scipy.arange(-fs_int / 2.0, fs_int / 2.0, fs_int / float(X_o.size)) + 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_ylim([-200.0, 50.0]) @@ -194,8 +188,8 @@ def main(): Ts_int = 1.0 / fs_int Tmax = len(d)*Ts_int - t_o = scipy.arange(0, Tmax, Ts_int) - x_o1 = scipy.array(d) + t_o = numpy.arange(0, Tmax, Ts_int) + x_o1 = numpy.array(d) sp2_t = fig2.add_subplot(2, 1, 2) p2_t = sp2_t.plot(t_o, x_o1.real, "b-o") #p2_t = sp2_t.plot(t_o, x_o.imag, "r-o") @@ -214,8 +208,8 @@ def main(): 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*scipy.log10(abs(fftpack.fftshift(X))) - f_o = scipy.arange(-fs_aint / 2.0, fs_aint / 2.0, fs_aint / float(X_o.size)) + 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_ylim([-200.0, 50.0]) @@ -227,8 +221,8 @@ def main(): Ts_aint = 1.0 / fs_aint Tmax = len(d)*Ts_aint - t_o = scipy.arange(0, Tmax, Ts_aint) - x_o2 = scipy.array(d) + t_o = numpy.arange(0, Tmax, Ts_aint) + x_o2 = numpy.array(d) sp3_f = fig3.add_subplot(2, 1, 2) p3_f = sp3_f.plot(t_o, x_o2.real, "b-o") p3_f = sp3_f.plot(t_o, x_o1.real, "m-o") diff --git a/gr-filter/examples/reconstruction.py b/gr-filter/examples/reconstruction.py index c9c1cd3922..565ccef00d 100644 --- a/gr-filter/examples/reconstruction.py +++ b/gr-filter/examples/reconstruction.py @@ -27,6 +27,7 @@ from gnuradio import gr, digital from gnuradio import filter from gnuradio import blocks import sys +import numpy try: from gnuradio import channels @@ -35,14 +36,7 @@ except ImportError: sys.exit(1) try: - import scipy - from scipy import fftpack -except ImportError: - print("Error: Program requires scipy (see: www.scipy.org).") - sys.exit(1) - -try: - import pylab + from matplotlib import pyplot except ImportError: print("Error: Program requires matplotlib (see: matplotlib.sourceforge.net).") sys.exit(1) @@ -53,7 +47,7 @@ def main(): N = 10000 fs = 2000.0 Ts = 1.0 / fs - t = scipy.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. @@ -70,10 +64,10 @@ def main(): # Create a modulated signal npwr = 0.01 - data = scipy.random.randint(0, 256, N) + data = numpy.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) + src = blocks.vector_source_b(data.astype(numpy.uint8).tolist(), False) mod = digital.bpsk_mod(samples_per_symbol=2) chan = channels.channel_model(npwr) rrc = filter.fft_filter_ccc(1, rrc_taps) @@ -107,13 +101,13 @@ def main(): tb.connect(synthesizer, snk) tb.run() - sin = scipy.array(src_snk.data()[1000:]) - sout = scipy.array(snk.data()[1000:]) + sin = numpy.array(src_snk.data()[1000:]) + sout = numpy.array(snk.data()[1000:]) # Plot original signal fs_in = nchans*fs - f1 = pylab.figure(1, figsize=(16,12), facecolor='w') + 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") @@ -133,10 +127,10 @@ def main(): s13.set_ylim([-2, 2]) # Plot channels - nrows = int(scipy.sqrt(nchans)) - ncols = int(scipy.ceil(float(nchans) / float(nrows))) + nrows = int(numpy.sqrt(nchans)) + ncols = int(numpy.ceil(float(nchans) / float(nrows))) - f2 = pylab.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.psd(vsnk[n].data(), NFFT=fftlen, Fs=fs_in) @@ -145,7 +139,7 @@ def main(): # Plot reconstructed signal fs_out = 2*nchans*fs - f3 = pylab.figure(3, figsize=(16,12), facecolor='w') + 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") @@ -164,7 +158,7 @@ def main(): s33.set_xlim([-2, 2]) s33.set_ylim([-2, 2]) - pylab.show() + pyplot.show() if __name__ == "__main__": diff --git a/gr-filter/examples/resampler.py b/gr-filter/examples/resampler.py index 29b25629cc..5060622f1c 100644 --- a/gr-filter/examples/resampler.py +++ b/gr-filter/examples/resampler.py @@ -27,6 +27,7 @@ from gnuradio import gr from gnuradio import filter from gnuradio import blocks import sys +import numpy try: from gnuradio import analog @@ -35,13 +36,7 @@ except ImportError: sys.exit(1) try: - import scipy -except ImportError: - sys.stderr.write("Error: Program requires scipy (see: www.scipy.org).\n") - sys.exit(1) - -try: - import pylab + from matplotlib import pyplot except ImportError: sys.stderr.write("Error: Program requires matplotlib (see: matplotlib.sourceforge.net).\n") sys.exit(1) @@ -91,7 +86,7 @@ def main(): # Plot PSD of signals nfftsize = 2048 - fig1 = pylab.figure(1, figsize=(10,10), facecolor="w") + 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) @@ -112,10 +107,10 @@ def main(): # Plot signals in time Ts_in = 1.0 / fs_in Ts_out = 1.0 / fs_out - t_in = scipy.arange(0, len(tb.snk_in.data())*Ts_in, Ts_in) - t_out = scipy.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 = pylab.figure(2, figsize=(10,10), facecolor="w") + 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))) @@ -131,7 +126,7 @@ def main(): sp22.set_xlim([t_out[r * 100], t_out[r * 200]]) sp22.legend() - pylab.show() + pyplot.show() if __name__ == "__main__": main() diff --git a/gr-filter/examples/synth_filter.py b/gr-filter/examples/synth_filter.py index b971c4a641..01769091ee 100644 --- a/gr-filter/examples/synth_filter.py +++ b/gr-filter/examples/synth_filter.py @@ -27,6 +27,7 @@ from gnuradio import gr from gnuradio import filter from gnuradio import blocks import sys +import numpy try: from gnuradio import analog @@ -35,13 +36,7 @@ except ImportError: sys.exit(1) try: - import scipy -except ImportError: - sys.stderr.write("Error: Program requires scipy (see: www.scipy.org).\n") - sys.exit(1) - -try: - import pylab + from matplotlib import pyplot except ImportError: sys.stderr.write("Error: Program requires matplotlib (see: matplotlib.sourceforge.net).\n") sys.exit(1) @@ -76,20 +71,20 @@ def main(): tb.run() if 1: - f1 = pylab.figure(1) + f1 = pyplot.figure(1) s1 = f1.add_subplot(1,1,1) s1.plot(snk.data()[1000:]) fftlen = 2048 - f2 = pylab.figure(2) + f2 = pyplot.figure(2) s2 = f2.add_subplot(1,1,1) - winfunc = scipy.blackman + winfunc = numpy.blackman s2.psd(snk.data()[10000:], NFFT=fftlen, Fs = nchans*fs, noverlap=fftlen / 4, window = lambda d: d*winfunc(fftlen)) - pylab.show() + 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 f1f1da4ec1..bd5f5378c0 100644 --- a/gr-filter/examples/synth_to_chan.py +++ b/gr-filter/examples/synth_to_chan.py @@ -27,6 +27,7 @@ from gnuradio import gr from gnuradio import blocks from gnuradio import filter import sys +import numpy try: from gnuradio import analog @@ -35,13 +36,7 @@ except ImportError: sys.exit(1) try: - import scipy -except ImportError: - sys.stderr.write("Error: Program requires scipy (see: www.scipy.org).\n") - sys.exit(1) - -try: - import pylab + from matplotlib import pyplot except ImportError: sys.stderr.write("Error: Program requires matplotlib (see: matplotlib.sourceforge.net).\n") sys.exit(1) @@ -97,16 +92,16 @@ def main(): channel = 1 data = snk[channel].data()[1000:] - f1 = pylab.figure(1) + f1 = pyplot.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 + winfunc = numpy.blackman + #winfunc = numpy.hamming - f2 = pylab.figure(2) + f2 = pyplot.figure(2) s2 = f2.add_subplot(1,1,1) s2.psd(data, NFFT=fftlen, Fs = nchans*fs, @@ -114,7 +109,7 @@ def main(): window = lambda d: d*winfunc(fftlen)) s2.set_title(("Output PSD from Channel %d" % channel)) - f3 = pylab.figure(3) + f3 = pyplot.figure(3) s3 = f3.add_subplot(1,1,1) s3.psd(snk_synth.data()[1000:], NFFT=fftlen, Fs = nchans*fs, @@ -122,7 +117,7 @@ def main(): window = lambda d: d*winfunc(fftlen)) s3.set_title("Output of Synthesis Filter") - pylab.show() + pyplot.show() if __name__ == "__main__": main() diff --git a/gr-filter/python/filter/design/filter_design.py b/gr-filter/python/filter/design/filter_design.py index f366520ac9..786f776997 100644 --- a/gr-filter/python/filter/design/filter_design.py +++ b/gr-filter/python/filter/design/filter_design.py @@ -31,8 +31,9 @@ from optparse import OptionParser from gnuradio import filter try: - import scipy - from scipy import fftpack, poly1d, signal + import numpy + from numpy.fft import fftpack + from scipy import poly1d, signal except ImportError: print("Please install SciPy to run this script (http://www.scipy.org/)") raise SystemExit(1) @@ -106,7 +107,7 @@ class gr_plot_filter(QtGui.QMainWindow): if ind != -1: self.gui.fselectComboBox.removeItem(ind) elif restype == "fir": - ind = self.gui.fselectComboBox.findText("IIR(scipy)") + ind = self.gui.fselectComboBox.findText("IIR(numpy)") if ind != -1: self.gui.fselectComboBox.removeItem(ind) @@ -702,7 +703,7 @@ class gr_plot_filter(QtGui.QMainWindow): self.gui.mttapsPush.setEnabled(True) self.gui.addpolePush.setEnabled(False) self.gui.maddpolePush.setEnabled(False) - elif(ftype == "IIR(scipy)"): + elif(ftype == "IIR(numpy)"): self.gui.filterDesignTypeComboBox.hide() self.gui.globalParamsBox.hide() self.gui.filterTypeComboBox.hide() @@ -872,7 +873,7 @@ class gr_plot_filter(QtGui.QMainWindow): self.b, self.a=[],[] if(ret): self.design_fir(ftype, fs, gain, winstr) - elif (fsel == "IIR(scipy)"): + elif (fsel == "IIR(numpy)"): with warnings.catch_warnings(record=True) as w: # Cause all warnings to always be triggered. warnings.simplefilter("always") @@ -1047,10 +1048,10 @@ class gr_plot_filter(QtGui.QMainWindow): def iir_plot_all(self,z,p,k): self.b,self.a = signal.zpk2tf(z,p,k) w,h = signal.freqz(self.b,self.a) - self.fftdB = 20 * scipy.log10 (abs(h)) + self.fftdB = 20 * numpy.log10 (abs(h)) self.freq = w / max(w) - self.fftDeg = scipy.unwrap(scipy.arctan2(scipy.imag(h),scipy.real(h))) - self.groupDelay = -scipy.diff(self.fftDeg) + self.fftDeg = numpy.unwrap(numpy.arctan2(numpy.imag(h),numpy.real(h))) + self.groupDelay = -numpy.diff(self.fftDeg) self.phaseDelay = -self.fftDeg[1:] / self.freq[1:] if self.gridview: self.set_mfmagresponse() @@ -1083,28 +1084,28 @@ class gr_plot_filter(QtGui.QMainWindow): def get_fft(self, fs, taps, Npts): Ts = 1.0 / fs fftpts = fftpack.fft(taps, Npts) - self.freq = scipy.arange(0, fs, 1.0 / (Npts*Ts)) + self.freq = numpy.arange(0, fs, 1.0 / (Npts*Ts)) with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") - self.fftdB = 20.0*scipy.log10(abs(fftpts)) + self.fftdB = 20.0*numpy.log10(abs(fftpts)) if any(self.fftdB == float('-inf')): sys.stderr.write('Filter design failed (taking log10 of 0).\n') - self.fftdB = scipy.zeros([len(fftpts)]) + self.fftdB = numpy.zeros([len(fftpts)]) - self.fftDeg = scipy.unwrap(scipy.angle(fftpts)) - self.groupDelay = -scipy.diff(self.fftDeg) + self.fftDeg = numpy.unwrap(numpy.angle(fftpts)) + self.groupDelay = -numpy.diff(self.fftDeg) self.phaseDelay = -self.fftDeg[1:] / self.freq[1:] def update_time_curves(self): ntaps = len(self.taps) if(ntaps > 0): - if(type(self.taps[0]) == scipy.complex128): - self.rcurve.setData(scipy.arange(ntaps), self.taps.real) - self.icurve.setData(scipy.arange(ntaps), self.taps.imag) + if(type(self.taps[0]) == numpy.complex128): + self.rcurve.setData(numpy.arange(ntaps), self.taps.real) + self.icurve.setData(numpy.arange(ntaps), self.taps.imag) ymax = 1.5 * max(max(self.taps.real),max(self.taps.imag)) ymin = 1.5 * min(min(self.taps.real),min(self.taps.imag)) else: - self.rcurve.setData(scipy.arange(ntaps), self.taps) + self.rcurve.setData(numpy.arange(ntaps), self.taps) self.icurve.setData([],[]); ymax = 1.5 * max(self.taps) ymin = 1.5 * min(self.taps) @@ -1141,13 +1142,13 @@ class gr_plot_filter(QtGui.QMainWindow): ntaps=50 else: stepres=self.step_response(self.taps) - if(type(stepres[0]) == scipy.complex128): - self.steprescurve.setData(scipy.arange(ntaps), stepres.real) - self.steprescurve_i.setData(scipy.arange(ntaps), stepres.imag) + if(type(stepres[0]) == numpy.complex128): + self.steprescurve.setData(numpy.arange(ntaps), stepres.real) + self.steprescurve_i.setData(numpy.arange(ntaps), stepres.imag) symax = 1.5 * max(max(stepres.real),max(stepres.imag)) symin = 1.5 * min(min(stepres.real),min(stepres.imag)) else: - self.steprescurve.setData(scipy.arange(ntaps), stepres) + self.steprescurve.setData(numpy.arange(ntaps), stepres) self.steprescurve_i.setData([],[]) symax = 1.5 * max(stepres) symin = 1.5 * min(stepres) @@ -1184,13 +1185,13 @@ class gr_plot_filter(QtGui.QMainWindow): ntaps=50 else: impres=self.impulse_response(self.taps) - if(type(impres[0]) == scipy.complex128): - self.imprescurve.setData(scipy.arange(ntaps), impres.real) - self.imprescurve_i.setData(scipy.arange(ntaps), impres.imag) + if(type(impres[0]) == numpy.complex128): + self.imprescurve.setData(numpy.arange(ntaps), impres.real) + self.imprescurve_i.setData(numpy.arange(ntaps), impres.imag) iymax = 1.5 * max(max(impres.real),max(impres.imag)) iymin = 1.5 * min(min(impres.real),min(impres.imag)) else: - self.imprescurve.setData(scipy.arange(ntaps), impres) + self.imprescurve.setData(numpy.arange(ntaps), impres) self.imprescurve_i.setData([],[]) iymax = 1.5 * max(impres) iymin = 1.5 * min(impres) @@ -1700,7 +1701,7 @@ class gr_plot_filter(QtGui.QMainWindow): def update_fft(self, taps, params): self.params = params - self.taps = scipy.array(taps) + self.taps = numpy.array(taps) self.get_fft(self.params["fs"], self.taps, self.nfftpts) def set_mfoverlay(self): @@ -1837,7 +1838,7 @@ class gr_plot_filter(QtGui.QMainWindow): else: plot = self.gui.freqPlot - if (self.gui.actionIdeal_Band.isChecked() == 0 or fsel == "IIR(scipy)"): + if (self.gui.actionIdeal_Band.isChecked() == 0 or fsel == "IIR(numpy)"): self.idbanditems.detach_allidealcurves(plot) elif(self.params): ftype = str(self.gui.filterTypeComboBox.currentText().toAscii()) @@ -2021,9 +2022,9 @@ class gr_plot_filter(QtGui.QMainWindow): l = len(b) if self.iir: l = 50 - impulse = scipy.repeat(0.,l) + impulse = numpy.repeat(0.,l) impulse[0] =1. - x = scipy.arange(0,l) + x = numpy.arange(0,l) response = signal.lfilter(b,a,impulse) return response @@ -2031,11 +2032,11 @@ class gr_plot_filter(QtGui.QMainWindow): l = len(b) if self.iir: l = 50 - impulse = scipy.repeat(0.,l) + impulse = numpy.repeat(0.,l) impulse[0] =1. - x = scipy.arange(0,l) + x = numpy.arange(0,l) response = signal.lfilter(b,a,impulse) - step = scipy.cumsum(response) + step = numpy.cumsum(response) return step def update_fcoeff(self): @@ -2270,7 +2271,7 @@ class gr_plot_filter(QtGui.QMainWindow): def draw_plots(self, taps, params): self.params = params - self.taps = scipy.array(taps) + self.taps = numpy.array(taps) if self.params: self.get_fft(self.params["fs"], self.taps, self.nfftpts) self.update_time_curves() diff --git a/gr-filter/python/filter/gui/idealbanditems.py b/gr-filter/python/filter/gui/idealbanditems.py index 67d2223258..9cd740fd61 100644 --- a/gr-filter/python/filter/gui/idealbanditems.py +++ b/gr-filter/python/filter/gui/idealbanditems.py @@ -24,7 +24,7 @@ from __future__ import unicode_literals from PyQt4 import QtGui, QtCore, Qt import PyQt4.Qwt5 as Qwt -import scipy +import numpy class IdealBandItems(object): def __init__(self): @@ -46,11 +46,11 @@ class IdealBandItems(object): if (ftype == "Low Pass"): self.detach_unwantedcurves(plot) x=[0, self.params["pbend"]] - y=[20.0*scipy.log10(self.params["gain"])]*2 + y=[20.0*numpy.log10(self.params["gain"])]*2 self.idealbandhcurves[0].setData(x, y) x=[self.params["pbend"]]*2 - y=[20.0*scipy.log10(self.params["gain"]), + y=[20.0*numpy.log10(self.params["gain"]), plot.axisScaleDiv(Qwt.QwtPlot.yLeft).lowerBound()] self.idealbandvcurves[0].setData(x, y) @@ -66,11 +66,11 @@ class IdealBandItems(object): elif ftype == "High Pass": self.detach_unwantedcurves(plot) x=[self.params["pbstart"],self.params["fs"] / 2.0] - y=[20.0*scipy.log10(self.params["gain"])]*2 + y=[20.0*numpy.log10(self.params["gain"])]*2 self.idealbandhcurves[0].setData(x, y) x=[self.params["pbstart"]]*2 - y=[20.0*scipy.log10(self.params["gain"]), + y=[20.0*numpy.log10(self.params["gain"]), plot.axisScaleDiv(Qwt.QwtPlot.yLeft).lowerBound()] self.idealbandvcurves[0].setData(x, y) @@ -99,35 +99,35 @@ class IdealBandItems(object): self.idealbandvcurves[1].setData(x, y) x=[0,self.params["sbstart"]-self.params["tb"]] - y=[20.0*scipy.log10(self.params["gain"])]*2 + y=[20.0*numpy.log10(self.params["gain"])]*2 self.idealbandhcurves[1].setData(x, y) x=[self.params["sbstart"]-self.params["tb"]]*2 - y=[20.0*scipy.log10(self.params["gain"]), + y=[20.0*numpy.log10(self.params["gain"]), plot.axisScaleDiv(Qwt.QwtPlot.yLeft).lowerBound()] self.idealbandvcurves[2].setData(x, y) x=[self.params["sbend"]+self.params["tb"],self.params["fs"] / 2.0] - y=[20.0*scipy.log10(self.params["gain"])]*2 + y=[20.0*numpy.log10(self.params["gain"])]*2 self.idealbandhcurves[2].setData(x, y) x=[self.params["sbend"]+self.params["tb"]]*2 - y=[20.0*scipy.log10(self.params["gain"]), + y=[20.0*numpy.log10(self.params["gain"]), plot.axisScaleDiv(Qwt.QwtPlot.yLeft).lowerBound()] self.idealbandvcurves[3].setData(x, y) elif ftype == "Band Pass": x=[self.params["pbstart"],self.params["pbend"]] - y=[20.0*scipy.log10(self.params["gain"])]*2 + y=[20.0*numpy.log10(self.params["gain"])]*2 self.idealbandhcurves[0].setData(x, y) x=[self.params["pbstart"]]*2 - y=[20.0*scipy.log10(self.params["gain"]), + y=[20.0*numpy.log10(self.params["gain"]), plot.axisScaleDiv(Qwt.QwtPlot.yLeft).lowerBound()] self.idealbandvcurves[0].setData(x, y) x=[self.params["pbend"]]*2 - y=[20.0*scipy.log10(self.params["gain"]), + y=[20.0*numpy.log10(self.params["gain"]), plot.axisScaleDiv(Qwt.QwtPlot.yLeft).lowerBound()] self.idealbandvcurves[1].setData(x, y) @@ -151,16 +151,16 @@ class IdealBandItems(object): elif ftype == "Complex Band Pass": x=[self.params["pbstart"],self.params["pbend"]] - y=[20.0*scipy.log10(self.params["gain"])]*2 + y=[20.0*numpy.log10(self.params["gain"])]*2 self.idealbandhcurves[0].setData(x, y) x=[self.params["pbstart"]]*2 - y=[20.0*scipy.log10(self.params["gain"]), + y=[20.0*numpy.log10(self.params["gain"]), plot.axisScaleDiv(Qwt.QwtPlot.yLeft).lowerBound()] self.idealbandvcurves[0].setData(x, y) x=[self.params["pbend"]]*2 - y=[20.0*scipy.log10(self.params["gain"]), + y=[20.0*numpy.log10(self.params["gain"]), plot.axisScaleDiv(Qwt.QwtPlot.yLeft).lowerBound()] self.idealbandvcurves[1].setData(x, y) |