Python numpy.polymul() Examples

The following are 22 code examples for showing how to use numpy.polymul(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module , or try the search function .

Example 1
```def _polysqr(pol):
"""return a polynomial squared"""
return np.polymul(pol, pol)

# Took the framework for the old function by
# Sawyer B. Fuller <minster@caltech.edu>, removed a lot of the innards
# and replaced with analytical polynomial functions for LTI systems.
#
# idea for the frequency data solution copied/adapted from
# Rene van Paassen <rene.vanpaassen@gmail.com>
#
# RvP, July 8, 2014, corrected to exclude phase=0 crossing for the gain
#                    margin polynomial
# RvP, July 8, 2015, augmented to calculate all phase/gain crossings with
#                    frd data. Correct to return smallest phase
#                    margin, smallest gain margin and their frequencies
# RvP, Jun 10, 2017, modified the inclusion of roots found for phase
#                    crossing to include all >= 0, made subsequent calc
#                    insensitive to div by 0
#                    also changed the selection of which crossings to
#                    return on basis of "A note on the Gain and Phase
#                    Margin Concepts" Journal of Control and Systems
#                    Engineering, Yazdan Bavafi-Toosi, Dec 2015, vol 3
#                    issue 1, pp 51-59, closer to Matlab behavior, but
#                    not completely identical in edge cases, which don't
#                    cross but touch gain=1 ```
Example 2
```def phase_crossover_frequencies(sys):
"""Compute frequencies and gains at intersections with real axis
in Nyquist plot.

Call as:
omega, gain = phase_crossover_frequencies()

Returns
-------
omega: 1d array of (non-negative) frequencies where Nyquist plot
intersects the real axis

gain: 1d array of corresponding gains

Examples
--------
>>> tf = TransferFunction([1], [1, 2, 3, 4])
>>> PhaseCrossoverFrequenies(tf)
(array([ 1.73205081,  0.        ]), array([-0.5 ,  0.25]))
"""

# Convert to a transfer function
tf = xferfcn._convert_to_transfer_function(sys)

# if not siso, fall back to (0,0) element
#! TODO: should add a check and warning here
num = tf.num[0][0]
den = tf.den[0][0]

# Compute frequencies that we cross over the real axis
numj = (1.j)**np.arange(len(num)-1,-1,-1)*num
denj = (-1.j)**np.arange(len(den)-1,-1,-1)*den
allfreq = np.roots(np.imag(np.polymul(numj,denj)))
realfreq = np.real(allfreq[np.isreal(allfreq)])
realposfreq = realfreq[realfreq >= 0.]

# using real() to avoid rounding errors and results like 1+0j
# it would be nice to have a vectorized version of self.evalfr here
gain = np.real(np.asarray([tf._evalfr(f)[0][0] for f in realposfreq]))

return realposfreq, gain ```
Example 3
```def test_mem_polymul(self):
# Ticket #448
np.polymul([], [1.]) ```
Example 4
```def sos2tf(sos):
"""
Return a single transfer function from a series of second-order sections

Parameters
----------
sos : array_like
Array of second-order filter coefficients, must have shape
``(n_sections, 6)``. See `sosfilt` for the SOS filter format
specification.

Returns
-------
b : ndarray
Numerator polynomial coefficients.
a : ndarray
Denominator polynomial coefficients.

Notes
-----
"""
sos = np.asarray(sos)
b = [1.]
a = [1.]
n_sections = sos.shape[0]
for section in range(n_sections):
b = np.polymul(b, sos[section, :3])
a = np.polymul(a, sos[section, 3:])
return b, a ```
Example 5
```def test_mem_polymul(self, level=rlevel):
# Ticket #448
np.polymul([], [1.]) ```
Example 6
```def test_mem_polymul(self, level=rlevel):
# Ticket #448
np.polymul([], [1.]) ```
Example 7
```def test_mem_polymul(self):
# Ticket #448
np.polymul([], [1.]) ```
Example 8
```def test_mem_polymul(self, level=rlevel):
"""Ticket #448"""
np.polymul([], [1.]) ```
Example 9
```def test_mem_polymul(self):
# Ticket #448
np.polymul([], [1.]) ```
Example 10
```def test_mem_polymul(self):
# Ticket #448
np.polymul([], [1.]) ```
Example 11
```def sos2tf(sos):
"""
Return a single transfer function from a series of second-order sections

Parameters
----------
sos : array_like
Array of second-order filter coefficients, must have shape
``(n_sections, 6)``. See `sosfilt` for the SOS filter format
specification.

Returns
-------
b : ndarray
Numerator polynomial coefficients.
a : ndarray
Denominator polynomial coefficients.

Notes
-----
"""
sos = np.asarray(sos)
b = [1.]
a = [1.]
n_sections = sos.shape[0]
for section in range(n_sections):
b = np.polymul(b, sos[section, :3])
a = np.polymul(a, sos[section, 3:])
return b, a ```
Example 12
```def test_mem_polymul(self):
# Ticket #448
np.polymul([], [1.]) ```
Example 13
```def test_mem_polymul(self):
# Ticket #448
np.polymul([], [1.]) ```
Example 14
```def test_mem_polymul(self, level=rlevel):
# Ticket #448
np.polymul([], [1.]) ```
Example 15
```def test_mem_polymul(self, level=rlevel):
# Ticket #448
np.polymul([], [1.]) ```
Example 16
```def sos2tf(sos):
"""
Return a single transfer function from a series of second-order sections

Parameters
----------
sos : array_like
Array of second-order filter coefficients, must have shape
``(n_sections, 6)``. See `sosfilt` for the SOS filter format
specification.

Returns
-------
b : ndarray
Numerator polynomial coefficients.
a : ndarray
Denominator polynomial coefficients.

Notes
-----
"""
sos = np.asarray(sos)
b = [1.]
a = [1.]
n_sections = sos.shape[0]
for section in range(n_sections):
b = np.polymul(b, sos[section, :3])
a = np.polymul(a, sos[section, 3:])
return b, a ```
Example 17
```def test_mem_polymul(self, level=rlevel):
# Ticket #448
np.polymul([], [1.]) ```
Example 18
```def test_mem_polymul(self):
# Ticket #448
np.polymul([], [1.]) ```
Example 19
```def A_weighting(fs):
"""Design of an A-weighting filter.

b, a = A_weighting(fs) designs a digital A-weighting filter for
sampling frequency `fs`. Usage: y = scipy.signal.lfilter(b, a, x).
Warning: `fs` should normally be higher than 20 kHz. For example,
fs = 48000 yields a class 1-compliant filter.

References:
[1] IEC/CD 1672: Electroacoustics-Sound Level Meters, Nov. 1996.

"""
# Definition of analog A-weighting filter according to IEC/CD 1672.
f1 = 20.598997
f2 = 107.65265
f3 = 737.86223
f4 = 12194.217
A1000 = 1.9997

NUMs = [(2*numpy.pi * f4)**2 * (10**(A1000/20)), 0, 0, 0, 0]
DENs = numpy.polymul([1, 4*numpy.pi * f4, (2*numpy.pi * f4)**2],
[1, 4*numpy.pi * f1, (2*numpy.pi * f1)**2])
DENs = numpy.polymul(numpy.polymul(DENs, [1, 2*numpy.pi * f3]),
[1, 2*numpy.pi * f2])

# Use the bilinear transformation to get the digital filter.
# (Octave, MATLAB, and PyLab disagree about Fs vs 1/Fs)
return bilinear(NUMs, DENs, fs) ```
Example 20
```def test_mem_polymul(self):
```def test_mem_polymul(self):
```def test_mem_polymul(self, level=rlevel):