+
    /iiG                         R t ^ RIt^ RIHtHtHtHtHtHtH	t	H
t
Ht ^ RIHt ^ RIHtHt ^ RIHu Ht ^RIHtHtHt . ROtR tRR ltRR ltR	 tRR
 ltRR ltR# )zr
ltisys -- a collection of functions to convert linear time invariant systems
from one representation to another.
N)	r_eye
atleast_2dpolydotasarrayzerosarrayouter)linalg)array_namespacexp_size)tf2zpkzpk2tf	normalizec                   \        W4      w  r\        V P                  4      pV^8X  d   \        V .V P                  4      p V P                  ^,          p\        V4      pW48  d   Rp\        V4      hV^ 8X  g   V^ 8X  d?   \        . \        4      \        . \        4      \        . \        4      \        . \        4      3# \        P                  ! \        P                  ! V P                  ^ ,          WC,
          3V P                  R7      V 34      p V P                  R,          ^ 8  d   \        V R,          4      pM\        ^ ..\        4      pV^8X  dc   VP                  V P                  4      p\        R4      \        ^VP                  ^,          34      \        VP                  ^ ,          ^34      V3# \        VR,          .4      ) p\        V\        V^,
          V^,
          4      3,          p\        V^,
          ^4      p	V R,          \        V R,          VR,          4      ,
          p
VP                  V
P                  ^ ,          V	P                  ^,          34      pWW3# )a)  Transfer function to state-space representation.

Parameters
----------
num, den : array_like
    Sequences representing the coefficients of the numerator and
    denominator polynomials, in order of descending degree. The
    denominator needs to be at least as long as the numerator.

Returns
-------
A, B, C, D : ndarray
    State space representation of the system, in controller canonical
    form.

Examples
--------
Convert the transfer function:

.. math:: H(s) = \frac{s^2 + 3s + 3}{s^2 + 2s + 1}

>>> num = [1, 3, 3]
>>> den = [1, 2, 1]

to the state-space representation:

.. math::

    \dot{\textbf{x}}(t) =
    \begin{bmatrix} -2 & -1 \\ 1 & 0 \end{bmatrix} \textbf{x}(t) +
    \begin{bmatrix} 1 \\ 0 \end{bmatrix} \textbf{u}(t) \\

    \textbf{y}(t) = \begin{bmatrix} 1 & 2 \end{bmatrix} \textbf{x}(t) +
    \begin{bmatrix} 1 \end{bmatrix} \textbf{u}(t)

>>> from scipy.signal import tf2ss
>>> A, B, C, D = tf2ss(num, den)
>>> A
array([[-2., -1.],
       [ 1.,  0.]])
>>> B
array([[ 1.],
       [ 0.]])
>>> C
array([[ 1.,  2.]])
>>> D
array([[ 1.]])
z7Improper transfer function. `num` is longer than `den`.)dtype   NNNNN    )r   r   )r   r   )r   lenshaper   r   
ValueErrorr	   floatnphstackr   r   reshaper   r   r
   )numdennnMKmsgDfrowABCs   &&         Z/var/www/html/photoedit/myenv/lib/python3.14/site-packages/scipy/signal/_lti_conversion.pytf2ssr,      s   p "HC	SYYB	QwseSYY'		!ACAuGoAvab% %E"2E"e4Db% " 	" ))RXXsyy|QU3399EsK
LC
yy}qs4y! A3%AvIIcii fua_5qwwqz1o&+ 	+ 3r7)D
4QUAE""#AAE1AE
U3t9c"g..A			1771:qwwqz*+A:    c           	       a V f   Vf   Vf   \        R4      hVf   Vf   \        R4      hVf   Vf   \        R4      h\        WW#4      oV3R lWW#3 4       w  rr#V P                  ^ ,          ;'       g9    VP                  ^ ,          ;'       g    VP                  ^,          ;'       g    ^ pVP                  ^,          ;'       g    VP                  ^,          ;'       g    ^ pVP                  ^ ,          ;'       g    VP                  ^ ,          ;'       g    ^ p\        V 4      ^ 8X  d   SP	                  WD34      MT p \        V4      ^ 8X  d   SP	                  WE34      MTp\        V4      ^ 8X  d   SP	                  Wd34      MTp\        V4      ^ 8X  d   SP	                  We34      MTpV P                  WD38w  d    \        RV P                   RV RV R24      hVP                  WE38w  d    \        R	VP                   RV RV R24      hVP                  Wd38w  d    \        R
VP                   RV RV R24      hVP                  We38w  d    \        RVP                   RV RV R24      hWW#3# )a  Check state-space matrices compatibility and ensure they are 2d arrays.

Converts input matrices into two-dimensional arrays as needed. Then the dimensions
n, q, p are determined by investigating the non-zero entries of the array shapes.
If a parameter is ``None``, or has shape (0, 0), it is set to a
zero-array of compatible shape. Finally, it is verified that all parameter shapes
are compatible to each other. If that fails, a ``ValueError`` is raised. Note that
the dimensions n, q, p are allowed to be zero.

Parameters
----------
A: array_like, optional
    Two-dimensional array of shape (n, n).
B: array_like, optional
    Two-dimensional array of shape (n, p).
C: array_like, optional
    Two-dimensional array of shape (q, n).
D: array_like, optional
    Two-dimensional array of shape (q, p).

Returns
-------
A, B, C, D : array
    State-space matrices as two-dimensional arrays.

Notes
-----
The :ref:`tutorial_signal_state_space_representation` section of the
:ref:`user_guide` presents the corresponding definitions of continuous-time and
disrcete time state space systems.

Raises
------
ValueError
    If the dimensions n, q, or p could not be determined or if the shapes are
    incompatible with each other.

See Also
--------
StateSpace: Linear Time Invariant system in state-space form.
dlti: Discrete-time linear time invariant system base class.
tf2ss: Transfer function to state-space representation.
ss2tf: State-space to transfer function.
ss2zpk: State-space representation to zero-pole-gain representation.
cont2discrete: Transform a continuous to a discrete state-space system.

Examples
--------
The following example demonstrates that the passed lists are converted into
two-dimensional arrays:

>>> from scipy.signal import abcd_normalize
>>> AA, BB, CC, DD = abcd_normalize(A=[[1, 2], [3, 4]], B=[[-1], [5]],
...                                 C=[[4, 5]], D=2.5)
>>> AA.shape, BB.shape, CC.shape, DD.shape
((2, 2), (2, 1), (1, 2), (1, 1))

In the following, the missing parameter C is assumed to be an array of zeros
with shape (1, 2):

>>> from scipy.signal import abcd_normalize
>>> AA, BB, CC, DD = abcd_normalize(A=[[1, 2], [3, 4]], B=[[-1], [5]], D=2.5)
>>> AA.shape, BB.shape, CC.shape, DD.shape
((2, 2), (2, 1), (1, 2), (1, 1))
>>> CC
array([[0., 0.]])
z9Dimension n is undefined for parameters A = B = C = None!z5Dimension p is undefined for parameters B = D = None!z5Dimension q is undefined for parameters C = D = None!c              3      <"   T FA  pVe(   \         P                  ! SP                  V4      ^R7      MSP                  R4      x  KC  	  R # 5i)N)ndim)r   r   )xpx
atleast_ndr   r   ).0M_xps   & r+   	<genexpr>!abcd_normalize.<locals>.<genexpr>   s@      ;-9r =?N#..Ba8((6"#-9s   A	AzParameter A has shape z but should be (z, z)!zParameter B has shape zParameter C has shape zParameter D has shape )r   r   r   r   r   )r(   r)   r*   r&   npqr5   s   &&&&   @r+   abcd_normalizer;   u   s?   H 	yQY19TUUyQYPQQyQYPQQ	q	$B;./A\;JA! 	

33aggaj33AGGAJ33!A	
%%aggaj%%AA	
%%aggaj%%AA#AJ!O!A#AJ!O!A#AJ!O!A#AJ!O!Aww1&1!'':J1#RPQsRTUVVww1&1!'':J1#RPQsRTUVVww1&1!'':J1#RPQsRTUVVww1&1!'':J1#RPQsRTUVV:r-   c                F   \        WW#4      w  rr#VP                  w  rVWF8  d   \        R4      hVRWD^,           13,          pVRWD^,           13,          p \        V 4      pVP                  ^ 8X  dO   VP                  ^ 8X  d>   \
        P                  ! V4      pVP                  ^ 8X  d   V P                  ^ 8X  d   . pW3# V P                  ^ ,          p	V R,          VR,          ,           VR,          ,           V,           R,           p
\
        P                  ! WY^,           3V
P                  4      p\        V4       FN  p\        W+R3,          4      p\        V \        W4      ,
          4      W;,          ^,
          V,          ,           W&   KP  	  W3#   \         d    ^p EL>i ; i)a  State-space to transfer function.

A, B, C, D defines a linear state-space system with `p` inputs,
`q` outputs, and `n` state variables.

Parameters
----------
A : array_like
    State (or system) matrix of shape ``(n, n)``
B : array_like
    Input matrix of shape ``(n, p)``
C : array_like
    Output matrix of shape ``(q, n)``
D : array_like
    Feedthrough (or feedforward) matrix of shape ``(q, p)``
input : int, optional
    For multiple-input systems, the index of the input to use.

Returns
-------
num : 2-D ndarray
    Numerator(s) of the resulting transfer function(s). `num` has one row
    for each of the system's outputs. Each row is a sequence representation
    of the numerator polynomial.
den : 1-D ndarray
    Denominator of the resulting transfer function(s). `den` is a sequence
    representation of the denominator polynomial.

Examples
--------
Convert the state-space representation:

.. math::

    \dot{\textbf{x}}(t) =
    \begin{bmatrix} -2 & -1 \\ 1 & 0 \end{bmatrix} \textbf{x}(t) +
    \begin{bmatrix} 1 \\ 0 \end{bmatrix} \textbf{u}(t) \\

    \textbf{y}(t) = \begin{bmatrix} 1 & 2 \end{bmatrix} \textbf{x}(t) +
    \begin{bmatrix} 1 \end{bmatrix} \textbf{u}(t)

>>> A = [[-2, -1], [1, 0]]
>>> B = [[1], [0]]  # 2-D column vector
>>> C = [[1, 2]]    # 2-D row vector
>>> D = 1

to the transfer function:

.. math:: H(s) = \frac{s^2 + 3s + 3}{s^2 + 2s + 1}

>>> from scipy.signal import ss2tf
>>> ss2tf(A, B, C, D)
(array([[1., 3., 3.]]), array([ 1.,  2.,  1.]))
z)System does not have the input specified.r           r   )r   r   )r;   r   r   r   sizer   ravelemptyr   ranger   r   )r(   r)   r*   r&   inputnoutninr!   r    
num_states	type_testkCks   &&&&&        r+   ss2tfrI      s^   t  a+JA!ID|DEE 	
!U19_
A	!U19_
A1g 	
!!&&A+hhqkFFaKaffkCxJ$!D'!AdG+a/#5I
((Dq.)9??
;C4[Q$ a#a*n%S(88  8O!  s   F F F c                (    \        \        WV4      !  # )a
  Zero-pole-gain representation to state-space representation

Parameters
----------
z, p : sequence
    Zeros and poles.
k : float
    System gain.

Returns
-------
A, B, C, D : ndarray
    State space representation of the system, in controller canonical
    form.

)r,   r   )zr9   rG   s   &&&r+   zpk2ssrL   2  s    " &q/""r-   c           
     ,    \        \        WW#VR7      !  # )aV  State-space representation to zero-pole-gain representation.

A, B, C, D defines a linear state-space system with `p` inputs,
`q` outputs, and `n` state variables.

Parameters
----------
A : array_like
    State (or system) matrix of shape ``(n, n)``
B : array_like
    Input matrix of shape ``(n, p)``
C : array_like
    Output matrix of shape ``(q, n)``
D : array_like
    Feedthrough (or feedforward) matrix of shape ``(q, p)``
input : int, optional
    For multiple-input systems, the index of the input to use.

Returns
-------
z, p : sequence
    Zeros and poles.
k : float
    System gain.

)rB   )r   rI   )r(   r)   r*   r&   rB   s   &&&&&r+   ss2zpkrN   F  s    6 5q5122r-   c                n   \        V R4      '       d/   \        V P                  4      '       d   V P                  WVR7      # \        V 4      ^8X  dY   \	        \        V ^ ,          V ^,          4      WVR7      p\        V^ ,          V^,          V^,          V^,          4      V3,           # \        V 4      ^8X  da   \	        \        V ^ ,          V ^,          V ^,          4      VW#R7      p\        V^ ,          V^,          V^,          V^,          4      V3,           # \        V 4      ^8X  d   V w  rVrxM\        R4      hVR8X  d)   Vf   \        R4      hV^ 8  g   V^8  d   \        R4      hVR8X  Ed   \        P                  ! VP                  ^ ,          4      W1,          V,          ,
          p	\        P                  ! V	\        P                  ! VP                  ^ ,          4      R	V,
          V,          V,          ,           4      p
\        P                  ! WV,          4      p\        P                  ! V	P                  4       VP                  4       4      pVP                  4       pW\        P                   ! W{4      ,          ,           pEM)VR
8X  g   VR8X  d   \	        WRRR7      # VR8X  g   VR8X  d   \	        WRRR7      # VR8X  d   \	        WRR	R7      # VR8X  Ed4   \        P"                  ! WV34      p\        P"                  ! \        P$                  ! VP                  ^,          VP                  ^ ,          34      \        P$                  ! VP                  ^,          VP                  ^,          34      34      p\        P&                  ! W34      p\        P(                  ! VV,          4      pVRVP                  ^ ,          1R3,          pVR^ VP                  ^,          13,          p
VRVP                  ^,          R13,          pTpTpEMVR8X  Ed   VP                  ^ ,          pVP                  ^,          p\        P*                  ! \        P,                  ! WV.4      V,          \        P                  ! V4      4      p\%        VV^V,          ,           34      p\        P,                  ! V.V..4      p\        P(                  ! V4      pVRV1^ V13,          pVRV1VVV,           13,          pVRV1VV,           R13,          pTp
VV,
          VV,          ,           pTpWV,          ,           pM{VR8X  df   \        P.                  ! V^ 4      '       g   \        R4      h\        P(                  ! WQ,          4      p
W,          V,          pTpWv,          V,          pM\        RV R24      hWWV3# )a(  
Transform a continuous to a discrete state-space system.

Parameters
----------
system : a tuple describing the system or an instance of `lti`
    The following gives the number of elements in the tuple and
    the interpretation:

        * 1: (instance of `lti`)
        * 2: (num, den)
        * 3: (zeros, poles, gain)
        * 4: (A, B, C, D)

dt : float
    The discretization time step.
method : str, optional
    Which method to use:

        * gbt: generalized bilinear transformation
        * bilinear: Tustin's approximation ("gbt" with alpha=0.5)
        * euler: Euler (or forward differencing) method ("gbt" with alpha=0)
        * backward_diff: Backwards differencing ("gbt" with alpha=1.0)
        * zoh: zero-order hold (default)
        * foh: first-order hold (*versionadded: 1.3.0*)
        * impulse: equivalent impulse response (*versionadded: 1.3.0*)

alpha : float within [0, 1], optional
    The generalized bilinear transformation weighting parameter, which
    should only be specified with method="gbt", and is ignored otherwise

Returns
-------
sysd : tuple containing the discrete system
    Based on the input type, the output will be of the form

    * (num, den, dt)   for transfer function input
    * (zeros, poles, gain, dt)   for zeros-poles-gain input
    * (A, B, C, D, dt) for state-space system input

Notes
-----
By default, the routine uses a Zero-Order Hold (zoh) method to perform
the transformation. Alternatively, a generalized bilinear transformation
may be used, which includes the common Tustin's bilinear approximation,
an Euler's method technique, or a backwards differencing technique.

The Zero-Order Hold (zoh) method is based on [1]_, the generalized bilinear
approximation is based on [2]_ and [3]_, the First-Order Hold (foh) method
is based on [4]_.

References
----------
.. [1] https://en.wikipedia.org/wiki/Discretization#Discretization_of_linear_state_space_models

.. [2] http://techteach.no/publications/discretetime_signals_systems/discrete.pdf

.. [3] G. Zhang, X. Chen, and T. Chen, Digital redesign via the generalized
    bilinear transformation, Int. J. Control, vol. 82, no. 4, pp. 741-754,
    2009.
    (https://www.mypolyuweb.hk/~magzhang/Research/ZCC09_IJC.pdf)

.. [4] G. F. Franklin, J. D. Powell, and M. L. Workman, Digital control
    of dynamic systems, 3rd ed. Menlo Park, Calif: Addison-Wesley,
    pp. 204-206, 1998.

Examples
--------
We can transform a continuous state-space system to a discrete one:

>>> import numpy as np
>>> import matplotlib.pyplot as plt
>>> from scipy.signal import cont2discrete, lti, dlti, dstep

Define a continuous state-space system.

>>> A = np.array([[0, 1],[-10., -3]])
>>> B = np.array([[0],[10.]])
>>> C = np.array([[1., 0]])
>>> D = np.array([[0.]])
>>> l_system = lti(A, B, C, D)
>>> t, x = l_system.step(T=np.linspace(0, 5, 100))
>>> fig, ax = plt.subplots()
>>> ax.plot(t, x, label='Continuous', linewidth=3)

Transform it to a discrete state-space system using several methods.

>>> dt = 0.1
>>> for method in ['zoh', 'bilinear', 'euler', 'backward_diff', 'foh', 'impulse']:
...    d_system = cont2discrete((A, B, C, D), dt, method=method)
...    s, x_d = dstep(d_system)
...    ax.step(s, np.squeeze(x_d), label=method, where='post')
>>> ax.axis([t[0], t[-1], x[0], 1.4])
>>> ax.legend(loc='best')
>>> fig.tight_layout()
>>> plt.show()

to_discrete)dtmethodalpha)rR   rS   zKFirst argument must either be a tuple of 2 (tf), 3 (zpk), or 4 (ss) arrays.gbtNzUAlpha parameter must be specified for the generalized bilinear transform (gbt) methodzDAlpha parameter must be within the interval [0,1] for the gbt methodg      ?bilineartusting      ?eulerforward_diffr=   backward_diffzohr   fohimpulsez<Impulse method is only applicable to strictly proper systemszUnknown transformation method '')hasattrcallablerP   r   cont2discreter,   rI   rL   rN   r   r   r   r   r   solve	transposer   r   r   vstackexpm
block_diagblockallclose)systemrQ   rR   rS   sysdabcdimaadbdcdddem_upperem_loweremmsr8   mms11ms12ms13s   &&&&                   r+   r`   r`   d  s   F v}%%(63E3E*F*F!!Re!DD
6{aU6!9fQi8"#(*T!Wd1gtAwQ8B5@@	V	VF1Ivay&)Db$*9d1gtAwQa9REAA	V	
a 6 7 	7 = K L LQY%!) 8 9 9 ffQWWQZ 58A:-\\#rvvaggaj1SYN14DDE\\#!t$ \\#--/1;;=9\\^rvva}$$	:	8!3VSAA	7	f6VSAA	?	"VSAA	599aV$ 99bhh
AGGAJ'?@ hh
AGGAJ'?@B C YY+,[[b! Q1QWWQZ< 1771:;	5GGAJGGAJ $$RXXqf%5%:BFF1IF!QQY(XXzH:./[[_ "1"ac'{"1"aAg+"1"a!ef*~D[4$;&T\	9	{{1a   : ; ; [[ Vb[URZ :6(!DEE22r-   )r,   r;   rI   rL   rN   r`   )NNNN)r   )rZ   N) __doc__numpyr   r   r   r   r   r   r   r   r	   r
   scipyr   scipy._lib._array_apir   r   scipy._lib.array_api_extra_libarray_api_extrar1   _filter_designr   r   r   __all__r,   r;   rI   rL   rN   r`    r-   r+   <module>r      s\   
 1 1 1  : ( ( 5 5^BaHVr#(3<Gr-   