pyvib.statespace module¶
-
class
pyvib.statespace.NonlinearStateSpace(*system, **kwargs)[source]¶ Bases:
pyvib.statespace.StateSpace-
E¶ State matrix of the StateSpace system.
-
F¶ Input matrix of the StateSpace system.
-
npar¶
-
weight¶
-
-
class
pyvib.statespace.StateSpace(*system, **kwargs)[source]¶ Bases:
object-
A¶ State matrix of the StateSpace system.
-
B¶ Input matrix of the StateSpace system.
-
C¶ Output matrix of the StateSpace system.
-
D¶ Feedthrough matrix of the StateSpace system.
-
dt¶ Return the sampling time of the system.
-
modal¶ Calculate modal properties using cont. time matrices
-
npar¶
-
simulate(u, t=None, x0=None, T1=None, T2=None)[source]¶ Return the response of the discrete-time system to input u with transient handling.
See
scipy.signal.dlsim()for details.
-
-
class
pyvib.statespace.StateSpaceIdent[source]¶ Bases:
object
-
pyvib.statespace.costfcn_time(x0, system, weight=False)[source]¶ Compute the vector of residuals such that the function to mimimize is
res = ∑ₖ e[k]ᴴ*e[k], where the error is given by e = weight*(ŷ - y) and the weight is the square inverse of the covariance matrix of y
-
pyvib.statespace.remove_transient_indices_nonperiodic(T2, N, p)[source]¶ Remove transients from arbitrary data.
Computes the indices to be used with a (N,p) matrix containing p output signals of length N, such that y[indices] contains the transient-free output(s) of length NT stacked on top of each other (if more than one output). The transient samples to be removed are specified in T2 (T2 = np.arange(T2) if T2 is scalar).
Parameters: - T2 (int) – scalar indicating how many samples from the start are removed or array indicating which samples are removed
- N (int) – length of the total signal
- p (int) – number of outputs
Returns: - indices (ndarray(int)) – vector of indices, such that y[indices] contains the output(s) without transients. If more than one output (p > 1), then y[indices] stacks the transient-free outputs on top of each other.
- nt (int) – length of the signal without transients
Examples
# One output, T2 scalar >>> N = 1000 # Total number of samples >>> T2 = 200 # First 200 samples should be removed after filtering >>> p = 1 # One output >>> indices, NT = remove_transient_indices_nonperiodic(T2,N,p) np.r_[200:1000] # Indices of the transient-free output NT = 800 # Number of samples in the transient-free output
# Two outputs, T2 scalar >>> N = 1000 # Total number of samples >>> T2 = 200 # First 200 samples should be removed after filtering >>> p = 2 # Two outputs >>> indices, NT = remove_transient_indices_nonperiodic(T2,N,p) np.r_[200:1000, 1200:2000] NT = 800 If y = [y1, y2] is a 1000 x 2 matrix with the two outputs y1 and y2, then y[indices] = [y1(200:1000]
y2(200:1000)]is a vector with the transient-free outputs stacked on top of each other
One output, T2 is a vector >>> N1 = 1000 # Number of samples in a first data set >>> N2 = 500 # Number of samples in a second data set >>> N = N1 + N2 # Total number of samples >>> T2_1 = np.r_[:200] # Transient samples in first data set >>> T2_2 = np.r_[:100] # Transient samples in second data set >>> T2 = np.r_[T2_1, N1+T2_2] # Transient samples >>> p = 1 # One output >>> indices, NT = remove_transient_indices_nonperiodic(T2,N,p) np.r_[200:1000, 1100:1500] NT = 1200
-
pyvib.statespace.remove_transient_indices_periodic(T1, N, p)[source]¶ Computes indices for transient handling for periodic signals after filtering
Let u be a vector of length N containing (several realizations of) a periodic signal. Let uTot be a vector containing the signal(s) in u with T1[0] transient points prepended to each realization (see
transient_indices_periodic()). The starting samples of each realization can be specified in T1[1:]. Let yTot be a vector/matrix containing the p outputs of a PNLSS model after applying the input uTot. Then this function computes the indices to be used with the vectorized form of yTot such that the transient samples are removed from yTot, i.e. y = yTot[indices] contains the steady-state output(s) stacked on top of each other.Parameters: - T1 (ndarray(int)) – vector that indicates how the transient is handled. The first element T1[0] is the number of transient samples that were prepended to each realization. The other elements T1[1:] indicate the starting sample of each realization in the input signal. If T1 has only one element, T1[1] is put to zero.
- N (int) – length of the input signal containing all realizations
- p (int) – number of outputs
Returns: indices – If uTot is a vector containing (several realizations of) a periodic signal to which T1[0] transient points were added before each realization, and if yTot is the corresponding output vector (or matrix if more than one output), then indices is such that the transient points are removed from y = yTot.flat[indices]. If p > 1, then indices is a vector and y = yTot.flat[indices] is a vector with the steady state outputs stacked after each other.
Return type: ndarray(int)
Examples
>>> npp = 1000 # Number of points per period >>> R = 2 # Number of phase realizations >>> T = 100 # Number of transient samples >>> T1 = np.r_[T, np.r_[0:(R-1)*npp+1:npp]] # Transient handling vector >>> N = R*npp # Total number of samples >>> indices_tot = transient_indices_periodic(T1,N) indices_tot = np.r_[900:1000, 0:1000, 1900:2000, 1000:2000] >>> p = 1 # One output >>> indices_removal = remove_transient_indices_periodic(T1,N,p) np.r_[100:1100, 1200:2200] >>> indices_tot[indices_removal] np.r_[:2000] # [realization 1, realization 2] >>> p = 2 # More than one output >>> indices_removal = remove_transient_indices_periodic(T1,N,p) np.r_[100:1100, 1200:2200, 2300:3300, 3400:4400]
Let u be a vector containing [input realization 1, input realization 2] then uTot = u[indices_tot] is a vector containing:
[transient samples realization 1, input realization 1, transient samples realization 2, input realization 2]
Let y1 be a vector containing the first output and y2 be a vector containing the second output when applying uTot as an input to a PNLSS model, and let yTot = [y1, y2].T be a 2 x 2200 matrix with y1 and y2 in its first and second row, respectively. Note that y1 = yTot.flat[:2200] and y2 = yTot.flat[2200:4400] Then `yTot.flat[indices_removal] = np.r_[y1[100:1100], y1[1200:2200],
y2[100:1100], y2[1200:2200]]`:- [output 1 corresponding to input realization 1,
- output 1 corresponding to input realization 2, output 2 corresponding to input realization 1, output 2 corresponding to input realization 2]
-
pyvib.statespace.transient_indices_periodic(T1, N)[source]¶ Computes indices for transient handling of periodic signals.
Computes the indices to be used with a vector u of length N that contains (several realizations of) a periodic signal, such that u[indices] has T1[0] transient samples prepended to each realization. The starting samples of each realization can be specified in T1[1:]. Like this, steady-state data can be obtained from a PNLSS model by using u[indices] as an input signal to a PNLSS model (see
pyvib.PNLSS.simulate()) and removing the transient samples afterwards (seeremove_transient_indices_periodic()Parameters: - T1 (int | ndarray(int)) – array that indicates how the transient is handled. The first element T1[0] is the number of transient samples that should be prepended to each realization. The other elements T1[1:] indicate the starting sample of each realization in the signal. If T1 has only one element, T1[1] is put to zero, ie. first element.
- N (int) – length of the signal containing all realizations
Returns: indices – indices of a vector u that contains (several realizations of) a periodic signal, such that u[indices] has a number of transient samples added before each realization
Return type: ndarray(int)
Examples
>>> npp = 1000 # Number of points per period >>> R = 2 # Number of phase realizations >>> T = 100 # Number of transient samples >>> T1 = np.r_[T, np.r_[0:(R-1)*npp+1:npp]] # Transient handling vector >>> N = R*npp # Total number of samples >>> indices = transient_indices_periodic(T1,N) indices = np.r_[900:1000, 0:1000, 1900:2000, 1000:2000] = [transient samples realization 1, ... realization 1, ... transient samples realization 2, ... realization 2]