diff options
-rw-r--r-- | gnuradio-runtime/python/gnuradio/gru/CMakeLists.txt | 2 | ||||
-rw-r--r-- | gnuradio-runtime/python/gnuradio/gru/__init__.py | 2 | ||||
-rw-r--r-- | gnuradio-runtime/python/gnuradio/gru/freqz.py | 332 | ||||
-rw-r--r-- | gnuradio-runtime/python/gnuradio/gru/gnuplot_freqz.py | 90 | ||||
-rw-r--r-- | gr-analog/python/analog/fm_emph.py | 12 |
5 files changed, 0 insertions, 438 deletions
diff --git a/gnuradio-runtime/python/gnuradio/gru/CMakeLists.txt b/gnuradio-runtime/python/gnuradio/gru/CMakeLists.txt index fa3baa5221..d2e8c442d7 100644 --- a/gnuradio-runtime/python/gnuradio/gru/CMakeLists.txt +++ b/gnuradio-runtime/python/gnuradio/gru/CMakeLists.txt @@ -9,8 +9,6 @@ include(GrPython) GR_PYTHON_INSTALL(FILES __init__.py - freqz.py - gnuplot_freqz.py msgq_runner.py daemon.py DESTINATION ${GR_PYTHON_DIR}/gnuradio/gru diff --git a/gnuradio-runtime/python/gnuradio/gru/__init__.py b/gnuradio-runtime/python/gnuradio/gru/__init__.py index c78c80960a..97f4889e37 100644 --- a/gnuradio-runtime/python/gnuradio/gru/__init__.py +++ b/gnuradio-runtime/python/gnuradio/gru/__init__.py @@ -2,6 +2,4 @@ # Import gru stuff from .daemon import * -from .freqz import * -from .gnuplot_freqz import * from .msgq_runner import * diff --git a/gnuradio-runtime/python/gnuradio/gru/freqz.py b/gnuradio-runtime/python/gnuradio/gru/freqz.py deleted file mode 100644 index 0fc6c04561..0000000000 --- a/gnuradio-runtime/python/gnuradio/gru/freqz.py +++ /dev/null @@ -1,332 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2005,2007 Free Software Foundation, Inc. -# -# This file is part of GNU Radio -# -# SPDX-License-Identifier: GPL-3.0-or-later -# -# - -# This code lifted from various parts of www.scipy.org -eb 2005-01-24 - -# Copyright (c) 2001, 2002 Enthought, Inc. -# -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions are met: -# -# a. Redistributions of source code must retain the above copyright notice, -# this list of conditions and the following disclaimer. -# b. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# c. Neither the name of the Enthought nor the names of its contributors -# may be used to endorse or promote products derived from this software -# without specific prior written permission. -# -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR -# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH -# DAMAGE. -# - -__all__ = ['freqz'] - -import numpy -from numpy import * -Num=numpy - -def atleast_1d(*arys): - """ Force a sequence of arrays to each be at least 1D. - - Description: - Force an array to be at least 1D. If an array is 0D, the - array is converted to a single row of values. Otherwise, - the array is unaltered. - Arguments: - *arys -- arrays to be converted to 1 or more dimensional array. - Returns: - input array converted to at least 1D array. - """ - res = [] - for ary in arys: - ary = asarray(ary) - if len(ary.shape) == 0: - result = numpy.array([ary[0]]) - else: - result = ary - res.append(result) - if len(res) == 1: - return res[0] - else: - return res - - -def polyval(p,x): - """Evaluate the polynomial p at x. If x is a polynomial then composition. - - Description: - - If p is of length N, this function returns the value: - p[0]*(x**N-1) + p[1]*(x**N-2) + ... + p[N-2]*x + p[N-1] - - x can be a sequence and p(x) will be returned for all elements of x. - or x can be another polynomial and the composite polynomial p(x) will be - returned. - """ - p = asarray(p) - if isinstance(x,poly1d): - y = 0 - else: - x = asarray(x) - y = numpy.zeros(x.shape,x.dtype) - for i in range(len(p)): - y = x * y + p[i] - return y - -class poly1d(object): - """A one-dimensional polynomial class. - - p = poly1d([1,2,3]) constructs the polynomial x**2 + 2 x + 3 - - p(0.5) evaluates the polynomial at the location - p.r is a list of roots - p.c is the coefficient array [1,2,3] - p.order is the polynomial order (after leading zeros in p.c are removed) - p[k] is the coefficient on the kth power of x (backwards from - sequencing the coefficient array. - - polynomials can be added, subtracted, multiplied and divided (returns - quotient and remainder). - asarray(p) will also give the coefficient array, so polynomials can - be used in all functions that accept arrays. - """ - def __init__(self, c_or_r, r=0): - if isinstance(c_or_r,poly1d): - for key in list(c_or_r.__dict__.keys()): - self.__dict__[key] = c_or_r.__dict__[key] - return - if r: - c_or_r = poly(c_or_r) - c_or_r = atleast_1d(c_or_r) - if len(c_or_r.shape) > 1: - raise ValueError("Polynomial must be 1d only.") - c_or_r = trim_zeros(c_or_r, trim='f') - if len(c_or_r) == 0: - c_or_r = numpy.array([0]) - self.__dict__['coeffs'] = c_or_r - self.__dict__['order'] = len(c_or_r) - 1 - - def __array__(self,t=None): - if t: - return asarray(self.coeffs,t) - else: - return asarray(self.coeffs) - - def __coerce__(self,other): - return None - - def __repr__(self): - vals = repr(self.coeffs) - vals = vals[6:-1] - return "poly1d(%s)" % vals - - def __len__(self): - return self.order - - def __str__(self): - N = self.order - thestr = "0" - for k in range(len(self.coeffs)): - coefstr ='%.4g' % abs(self.coeffs[k]) - if coefstr[-4:] == '0000': - coefstr = coefstr[:-5] - power = (N-k) - if power == 0: - if coefstr != '0': - newstr = '%s' % (coefstr,) - else: - if k == 0: - newstr = '0' - else: - newstr = '' - elif power == 1: - if coefstr == '0': - newstr = '' - elif coefstr == '1': - newstr = 'x' - else: - newstr = '%s x' % (coefstr,) - else: - if coefstr == '0': - newstr = '' - elif coefstr == '1': - newstr = 'x**%d' % (power,) - else: - newstr = '%s x**%d' % (coefstr, power) - - if k > 0: - if newstr != '': - if self.coeffs[k] < 0: - thestr = "%s - %s" % (thestr, newstr) - else: - thestr = "%s + %s" % (thestr, newstr) - elif (k == 0) and (newstr != '') and (self.coeffs[k] < 0): - thestr = "-%s" % (newstr,) - else: - thestr = newstr - return _raise_power(thestr) - - - def __call__(self, val): - return polyval(self.coeffs, val) - - def __mul__(self, other): - if isscalar(other): - return poly1d(self.coeffs * other) - else: - other = poly1d(other) - return poly1d(polymul(self.coeffs, other.coeffs)) - - def __rmul__(self, other): - if isscalar(other): - return poly1d(other * self.coeffs) - else: - other = poly1d(other) - return poly1d(polymul(self.coeffs, other.coeffs)) - - def __add__(self, other): - other = poly1d(other) - return poly1d(polyadd(self.coeffs, other.coeffs)) - - def __radd__(self, other): - other = poly1d(other) - return poly1d(polyadd(self.coeffs, other.coeffs)) - - def __pow__(self, val): - if not isscalar(val) or int(val) != val or val < 0: - raise ValueError("Power to non-negative integers only.") - res = [1] - for k in range(val): - res = polymul(self.coeffs, res) - return poly1d(res) - - def __sub__(self, other): - other = poly1d(other) - return poly1d(polysub(self.coeffs, other.coeffs)) - - def __rsub__(self, other): - other = poly1d(other) - return poly1d(polysub(other.coeffs, self.coeffs)) - - def __div__(self, other): - if isscalar(other): - return poly1d(self.coeffs / other) - else: - other = poly1d(other) - return list(map(poly1d,polydiv(self.coeffs, other.coeffs))) - - def __rdiv__(self, other): - if isscalar(other): - return poly1d(other / self.coeffs) - else: - other = poly1d(other) - return list(map(poly1d,polydiv(other.coeffs, self.coeffs))) - - def __setattr__(self, key, val): - raise ValueError("Attributes cannot be changed this way.") - - def __getattr__(self, key): - if key in ['r','roots']: - return roots(self.coeffs) - elif key in ['c','coef','coefficients']: - return self.coeffs - elif key in ['o']: - return self.order - else: - return self.__dict__[key] - - def __getitem__(self, val): - ind = self.order - val - if val > self.order: - return 0 - if val < 0: - return 0 - return self.coeffs[ind] - - def __setitem__(self, key, val): - ind = self.order - key - if key < 0: - raise ValueError("Does not support negative powers.") - if key > self.order: - zr = numpy.zeros(key-self.order,self.coeffs.typecode()) - self.__dict__['coeffs'] = numpy.concatenate((zr,self.coeffs)) - self.__dict__['order'] = key - ind = 0 - self.__dict__['coeffs'][ind] = val - return - - def integ(self, m=1, k=0): - return poly1d(polyint(self.coeffs,m=m,k=k)) - - def deriv(self, m=1): - return poly1d(polyder(self.coeffs,m=m)) - -def freqz(b, a, worN=None, whole=0, plot=None): - """Compute frequency response of a digital filter. - - Description: - - Given the numerator (b) and denominator (a) of a digital filter compute - its frequency response. - - jw -jw -jmw - jw B(e) b[0] + b[1]e + .... + b[m]e - H(e) = ---- = ------------------------------------ - jw -jw -jnw - A(e) a[0] + a[2]e + .... + a[n]e - - Inputs: - - b, a --- the numerator and denominator of a linear filter. - worN --- If None, then compute at 512 frequencies around the unit circle. - If a single integer, the compute at that many frequencies. - Otherwise, compute the response at frequencies given in worN - whole -- Normally, frequencies are computed from 0 to pi (upper-half of - unit-circle. If whole is non-zero compute frequencies from 0 - to 2*pi. - - Outputs: (h,w) - - h -- The frequency response. - w -- The frequencies at which h was computed. - """ - b, a = list(map(atleast_1d, (b,a))) - if whole: - lastpoint = 2*pi - else: - lastpoint = pi - if worN is None: - N = 512 - w = Num.arange(0,lastpoint,lastpoint / N) - elif isinstance(worN, int): - N = worN - w = Num.arange(0,lastpoint,lastpoint / N) - else: - w = worN - w = atleast_1d(w) - zm1 = exp(-1j*w) - h = polyval(b[::-1] / zm1, polyval(a[::-1], zm1)) - # if not plot is None: - # plot(w, h) - return h, w diff --git a/gnuradio-runtime/python/gnuradio/gru/gnuplot_freqz.py b/gnuradio-runtime/python/gnuradio/gru/gnuplot_freqz.py deleted file mode 100644 index cafb8fd2ef..0000000000 --- a/gnuradio-runtime/python/gnuradio/gru/gnuplot_freqz.py +++ /dev/null @@ -1,90 +0,0 @@ -#!/usr/bin/env python -# -# Copyright 2005,2007 Free Software Foundation, Inc. -# -# This file is part of GNU Radio -# -# SPDX-License-Identifier: GPL-3.0-or-later -# -# - -__all__ = ['gnuplot_freqz'] - -import tempfile -import os -import math -import numpy - -from gnuradio import gr -from gnuradio.gru.freqz import freqz - - -def gnuplot_freqz (hw, Fs=None, logfreq=False): - - """hw is a tuple of the form (h, w) where h is sequence of complex - freq responses, and w is a sequence of corresponding frequency - points. Plot the frequency response using gnuplot. If Fs is - provide, use it as the sampling frequency, else use 2*pi. - - Returns a handle to the gnuplot graph. When the handle is reclaimed - the graph is torn down.""" - - data_file = tempfile.NamedTemporaryFile () - cmd_file = os.popen ('gnuplot', 'w') - - h, w = hw - ampl = 20 * numpy.log10 (numpy.absolute (h) + 1e-9) - phase = [math.atan2 (x.imag, x.real) for x in h] - - if Fs: - w *= (Fs / (2*math.pi)) - - for freq, a, ph in zip (w, ampl, phase): - data_file.write ("%g\t%g\t%g\n" % (freq, a, ph)) - - data_file.flush () - - cmd_file.write ("set grid\n") - if logfreq: - cmd_file.write ("set logscale x\n") - else: - cmd_file.write ("unset logscale x\n") - cmd_file.write ("plot '%s' using 1:2 with lines\n" % (data_file.name,)) - cmd_file.flush () - - return (cmd_file, data_file) - - -def test_plot (): - sample_rate = 2.0e6 - #taps = firdes.low_pass(1, sample_rate, 200000, 100000, firdes.WIN_HAMMING) - taps = (0.0007329441141337156, 0.0007755281985737383, 0.0005323155201040208, - -7.679847761841656e-19, -0.0007277769618667662, -0.001415981911122799, - -0.0017135187517851591, -0.001282231998629868, 1.61239866282397e-18, - 0.0018589380197227001, 0.0035909228026866913, 0.004260237794369459, - 0.00310456077568233, -3.0331308923229716e-18, -0.004244099836796522, - -0.007970594801008701, -0.009214458055794239, -0.006562007591128349, - 4.714311174044374e-18, 0.008654761128127575, 0.01605774275958538, - 0.01841980405151844, 0.013079923577606678, -6.2821650235090215e-18, - -0.017465557903051376, -0.032989680767059326, -0.03894065320491791, - -0.028868533670902252, 7.388111706347014e-18, 0.04517475143074989, - 0.09890196472406387, 0.14991308748722076, 0.18646684288978577, - 0.19974154233932495, 0.18646684288978577, 0.14991308748722076, - 0.09890196472406387, 0.04517475143074989, 7.388111706347014e-18, - -0.028868533670902252, -0.03894065320491791, -0.032989680767059326, - -0.017465557903051376, -6.2821650235090215e-18, 0.013079923577606678, - 0.01841980405151844, 0.01605774275958538, 0.008654761128127575, - 4.714311174044374e-18, -0.006562007591128349, -0.009214458055794239, - -0.007970594801008701, -0.004244099836796522, -3.0331308923229716e-18, - 0.00310456077568233, 0.004260237794369459, 0.0035909228026866913, - 0.0018589380197227001, 1.61239866282397e-18, -0.001282231998629868, - -0.0017135187517851591, -0.001415981911122799, -0.0007277769618667662, - -7.679847761841656e-19, 0.0005323155201040208, 0.0007755281985737383, - 0.0007329441141337156) - - # print len (taps) - return gnuplot_freqz (freqz (taps, 1), sample_rate) - -if __name__ == '__main__': - handle = test_plot () - input ('Press Enter to continue: ') diff --git a/gr-analog/python/analog/fm_emph.py b/gr-analog/python/analog/fm_emph.py index 594a59aa89..9c1107bb14 100644 --- a/gr-analog/python/analog/fm_emph.py +++ b/gr-analog/python/analog/fm_emph.py @@ -116,12 +116,6 @@ class fm_deemph(gr.hier_block2): # Since H(s = 0) = 1.0, then H(z = 1) = 1.0 and has 0 dB gain at DC - if 0: - print("btaps =", btaps) - print("ataps =", ataps) - global plot1 - plot1 = gru.gnuplot_freqz(gru.freqz(btaps, ataps), fs, True) - deemph = filter.iir_filter_ffd(btaps, ataps, False) self.connect(self, deemph, self) @@ -280,11 +274,5 @@ class fm_preemph(gr.hier_block2): btaps = [ g * b0 * 1.0, g * b0 * -z1 ] ataps = [ 1.0, -p1 ] - if 0: - print("btaps =", btaps) - print("ataps =", ataps) - global plot2 - plot2 = gru.gnuplot_freqz(gru.freqz(btaps, ataps), fs, True) - preemph = filter.iir_filter_ffd(btaps, ataps, False) self.connect(self, preemph, self) |