ss

class sharpy.linear.src.libss.ss(A, B, C, D, dt=None)[source]

Wrap state-space models allocation into a single class and support both full and sparse matrices. The class emulates

scipy.signal.ltisys.StateSpaceContinuous scipy.signal.ltisys.StateSpaceDiscrete

but supports sparse matrices and other functionalities.

Methods: - get_mats: return matrices as tuple - check_types: check matrices types are supported - freqresp: calculate frequency response over range. - addGain: project inputs/outputs - scale: allows scaling a system

addGain(K, where)[source]

Projects input u or output y the state-space system through the gain matrix K. The input ‘where’ determines whether inputs or outputs are projected as:

  • where=’in’: inputs are projected such that:

    u_new -> u=K*u_new -> SS -> y => u_new -> SSnew -> y

  • where=’out’: outputs are projected such that:

    u -> SS -> y -> y_new=K*y => u -> SSnew -> ynew

Warning: this is not a wrapper of the addGain method in this module, as the state-space matrices are directly overwritten.

disc2cont()[source]

Transform a discrete time system to a continuous time system using a bilinear (Tustin) transformation.

Wrapper of disc2cont()

eigvals()[source]
Returns

Eigenvalues of the system

Return type

np.ndarray

freqresp(wv)[source]

Calculate frequency response over frequencies wv

Note: this wraps frequency response function.

property inputs

Number of inputs \(m\) to the system.

max_eig()[source]

Returns most unstable eigenvalue

property outputs

Number of outputs \(p\) of the system.

project(WT, V)[source]

Given 2 transformation matrices, (WT,V) of shapes (Nk,self.states) and (self.states,Nk) respectively, this routine projects the state space model states according to:

Anew = WT A V Bnew = WT B Cnew = C V Dnew = D

The projected model has the same number of inputs/outputs as the original one, but Nk states.

scale(input_scal=1.0, output_scal=1.0, state_scal=1.0)[source]

Given a state-space system, scales the equations such that the original state, input and output, (x, u and y), are substituted by

xad=x/state_scal uad=u/input_scal yad=y/output_scal

The entries input_scal/output_scal/state_scal can be:
  • floats: in this case all input/output are scaled by the same value

  • lists/arrays of length Nin/Nout: in this case each dof will be scaled

by a different factor

If the original system has form:

xnew=A*x+B*u y=C*x+D*u

the transformation is such that:

xnew=A*x+(B*uref/xref)*uad yad=1/yref( C*xref*x+D*uref*uad )

property states

Number of states \(n\) of the system.

transfer_function_evaluation(s)[source]

Returns the transfer function of the system evaluated at \(s\in\mathbb{C}\).

Parameters

s (complex) – Point in the complex plane at which to evaluate the transfer function.

Returns

Transfer function evaluated at \(s\).

Return type

np.ndarray

truncate(N)[source]

Retains only the first N states.