StateSpace
- class sharpy.linear.src.libss.StateSpace(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
- Parameters:
K (np.array or Gain) – gain matrix or Gain object
where (str) –
in
orout
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()
- freqresp(wv)[source]
Calculate frequency response over frequencies wv
Note: this wraps frequency response function.
- classmethod from_scipy(scipy_ss)[source]
Transforms a
scipy.signal.lti
or dlti into a StateSpace class- Parameters:
scipy_ss (scipy.signal.ltisys.StateSpaceContinous or scipy.signal.ltisys.StateSpaceDiscrete) – Scipy State Space object.
- Returns:
SHARPy state space object
- Return type:
- property inputs
Number of inputs \(m\) to the system.
- classmethod load_from_h5(h5_file_name)[source]
Loads a state-space object from an h5 file, including variable information
- Parameters:
h5_file_name (str) – Path to file
- Returns:
loaded state-space from file
- Return type:
- 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.
- Parameters:
wt (Gain or np.ndarray) – Left projection matrix
v (Gain or np.ndarray) – Righty projection matrix
- remove_inputs(*input_remove_list)[source]
Removes inputs through their variable names.
Needs that the
StateSpace
attributeinput_variables
is defined.- Parameters:
input_remove_list (list(str)) – List of inputs to remove
- remove_outputs(*output_remove_list)[source]
Removes outputs through their variable names.
Needs that the
StateSpace
attributeoutput_variables
is defined.- Parameters:
output_remove_list (list(str)) – List of outputs to remove
- retain_inout_channels(retain_channels, where)[source]
Retain selected input or output channels only.
- Parameters:
retain_channels (list) – List of channels to retain
where (str) –
in
orout
for input/output channels
- 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.