-
Notifications
You must be signed in to change notification settings - Fork 52
/
_cancelPZ.py
68 lines (52 loc) · 1.93 KB
/
_cancelPZ.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# -*- coding: utf-8 -*-
# _cancelPZ.py
# Module providing the cancelPZ function
# Copyright 2013 Giuseppe Venturini
# This file is part of python-deltasigma.
#
# python-deltasigma is a 1:1 Python replacement of Richard Schreier's
# MATLAB delta sigma toolbox (aka "delsigma"), upon which it is heavily based.
# The delta sigma toolbox is (c) 2009, Richard Schreier.
#
# python-deltasigma is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# LICENSE file for the licensing terms.
"""Module providing the cancelPZ() function
"""
from __future__ import division
import copy
import numpy as np
from scipy.signal import lti
def cancelPZ(arg1, tol=1e-6):
"""Cancel zeros/poles in a SISO transfer function.
**Parameters:**
arg1 : LTI system description
Multiple descriptions are supported for the LTI system.
If one argument is used, it is a scipy ``lti`` object.
If more arguments are used, they should be arranged in a tuple, the
following gives the number of elements in the tuple and their
interpretation:
* 2: (numerator, denominator)
* 3: (zeros, poles, gain)
* 4: (A, B, C, D)
Each argument can be an array or sequence.
tol : float, optional
the absolute tolerance for pole, zero cancellation. Defaults to 1e-6.
**Returns:**
(z, p, k) : tuple
A tuple containing zeros, poles and gain (unchanged) after poles, zeros
cancellation.
"""
if not isinstance(arg1, lti):
arg1 = lti(*arg1)
z = copy.copy(arg1.zeros)
p = copy.copy(arg1.poles)
k = arg1.gain
for i in range(max(z.shape) - 1, -1, -1):
d = z[i] - p
cancel = np.nonzero(np.abs(d) < tol)[0]
if cancel.size:
p = np.delete(p, cancel[0])
z = np.delete(z, i)
return z, p, k