summaryrefslogtreecommitdiff
path: root/gr-filter/examples
diff options
context:
space:
mode:
authorMarcus Müller <marcus@hostalia.de>2018-08-24 23:00:55 +0200
committerMarcus Müller <marcus@hostalia.de>2018-11-02 22:15:53 +0100
commit797994a11ac5ec6bee9ea01c092947d0c34115f1 (patch)
tree7381f53008ba56e6b93398fa92be482d12da4f43 /gr-filter/examples
parente07751acc8424f4dd987f79c32dd247ed347902c (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/examples')
-rw-r--r--gr-filter/examples/channelize.py32
-rw-r--r--gr-filter/examples/chirp_channelize.py32
-rw-r--r--gr-filter/examples/decimate.py37
-rw-r--r--gr-filter/examples/fft_filter_ccc.py21
-rw-r--r--gr-filter/examples/fir_filter_ccc.py21
-rw-r--r--gr-filter/examples/fir_filter_fff.py21
-rw-r--r--gr-filter/examples/interpolate.py36
-rw-r--r--gr-filter/examples/reconstruction.py32
-rw-r--r--gr-filter/examples/resampler.py19
-rw-r--r--gr-filter/examples/synth_filter.py17
-rw-r--r--gr-filter/examples/synth_to_chan.py21
11 files changed, 115 insertions, 174 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()