#NEWLINE# def fix_roots( poles , fix_roots = 'incr' , fix_mode = 'reflect' ) : #NEWLINE# #INDENT# "\n    Fix (stabilize) LP roots.\n\n    Parameters\n    ----------\n    poles : ndarray\n        Array of LP roots (poles).\n    fix_roots : {'incr', 'decr'}\n        Type of roots which to consider bad and to stabilize.  Either those\n        with increasing signals 'incr' or decreasing signals 'decr'.\n    fix_mode : {'on', 'reflect'}\n        Method used to stabilize bad roots, 'on' to move the roots onto the\n        unit circle, 'reflect' to reflect bad roots across the unit circle.\n\n    Returns\n    -------\n    npoles : ndarray\n        Array of stabilized LP roots (poles).\n\n    " #NEWLINE# if ( fix_roots not in [ 'incr' , 'decr' ] ) : #NEWLINE# #INDENT# raise ValueError ( "fix_roots must be 'incr' or 'decr'" ) #NEWLINE# #UNINDENT# if ( fix_mode not in [ 'on' , 'reflect' ] ) : #NEWLINE# #INDENT# raise ValueError ( "fix_mode must be 'on' or 'reflect'" ) #NEWLINE# #UNINDENT# if ( fix_roots == 'incr' ) : #NEWLINE# #INDENT# for ( i , pole ) in enumerate ( poles ) : #NEWLINE# #INDENT# if ( np . abs ( pole ) > 1 ) : #NEWLINE# #INDENT# if ( fix_mode == 'on' ) : #NEWLINE# #INDENT# poles [ i ] = ( pole / np . abs ( pole ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# poles [ i ] = ( 1 / np . conj ( pole ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# for ( i , pole ) in enumerate ( poles ) : #NEWLINE# #INDENT# if ( np . abs ( pole ) < 1 ) : #NEWLINE# #INDENT# if ( fix_mode == 'on' ) : #NEWLINE# #INDENT# poles [ pole ] = ( pole / np . abs ( pole ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# poles [ i ] = ( 1 / np . conj ( pole ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# return poles