@@ -840,7 +840,7 @@ def _common_den(self, imag_tol=None):
840
840
# Machine precision for floats.
841
841
eps = finfo (float ).eps
842
842
843
- # Decide on the tolerance to use in deciding of a pole is complex
843
+ # Decide on the tolerance to use in deciding if a pole is complex
844
844
if (imag_tol is None ):
845
845
imag_tol = 1e-8 # TODO: figure out the right number to use
846
846
@@ -874,7 +874,7 @@ def _common_den(self, imag_tol=None):
874
874
nothave = ones (currentpoles .shape , dtype = bool )
875
875
for ip , p in enumerate (poles [j ]):
876
876
idx , = nonzero (
877
- (abs (currentpoles - p ) < epsnm ) * nothave )
877
+ (abs (currentpoles - p ) < sqrt ( epsnm ) ) * nothave )
878
878
if len (idx ):
879
879
nothave [idx [0 ]] = False
880
880
else :
@@ -890,7 +890,8 @@ def _common_den(self, imag_tol=None):
890
890
npmax = max ([len (p ) for p in poles ])
891
891
den = zeros ((self .inputs , npmax + 1 ), dtype = float )
892
892
num = zeros ((max (1 , self .outputs , self .inputs ),
893
- max (1 , self .outputs , self .inputs ), npmax + 1 ),
893
+ max (1 , self .outputs , self .inputs ),
894
+ npmax + 1 ),
894
895
dtype = float )
895
896
denorder = zeros ((self .inputs ,), dtype = int )
896
897
@@ -901,11 +902,18 @@ def _common_den(self, imag_tol=None):
901
902
for i in range (self .outputs ):
902
903
num [i , j , 0 ] = poleset [i ][j ][2 ]
903
904
else :
904
- # create the denominator matching this input polyfromroots
905
- # gives coeffs in opposite order from what we use coefficients
906
- # should be padded on right, ending at np
905
+ # create the denominator matching this input
906
+ # polyfromroots gives coeffs in opposite order from what we use
907
+ # coefficients should be padded on right, ending at np
907
908
np = len (poles [j ])
908
- den [j , np ::- 1 ] = polyfromroots (poles [j ]).real
909
+ denpoly = polyfromroots (poles [j ])
910
+ if (abs (denpoly .imag ) > imag_tol ).any ():
911
+ warn ("The denominator of the transfer function "
912
+ "for input {j} to output {i} has a nontrivial "
913
+ "imaginary part of {imag}, which was removed" .format (
914
+ i = i , j = j , imag = max (denpoly .imag )))
915
+ denpoly = denpoly .real
916
+ den [j , np ::- 1 ] = denpoly
909
917
denorder [j ] = np
910
918
911
919
# now create the numerator, also padded on the right
@@ -926,13 +934,9 @@ def _common_den(self, imag_tol=None):
926
934
num [i , j , np + 1 - len (numpoly ):np + 1 ] = numpoly [::- 1 ]
927
935
# print(num[i, j])
928
936
929
- if (abs (den .imag ) > epsnm ).any ():
930
- print ("Warning: The denominator has a nontrivial imaginary part: "
931
- " %f" % abs (den .imag ).max ())
932
- den = den .real
933
-
934
937
return num , den , denorder
935
938
939
+
936
940
def sample (self , Ts , method = 'zoh' , alpha = None ):
937
941
"""Convert a continuous-time system to discrete time
938
942
0 commit comments