Analysis Package
The analysis package provides comprehensive tools for process control system analysis, including transfer functions, system analysis, and model identification.
Note
This is part of the modern modular structure of SPROCLIB.
Submodules
Transfer Function
Transfer Function Analysis for SPROCLIB
This module provides transfer function representation and frequency domain analysis for linear time-invariant systems in process control applications.
Author: Thorsten Gressling <gressling@paramus.ai> License: MIT License
- class sproclib.analysis.transfer_function.TransferFunction(num, den, name='G(s)')[source]
Bases:
objectTransfer function representation and analysis.
- Parameters:
- classmethod first_order_plus_dead_time(K, tau, theta, name='FOPDT')[source]
Create first-order plus dead time transfer function. G(s) = K * exp(-theta*s) / (tau*s + 1)
- Parameters:
- Returns:
TransferFunction object (without dead time for analysis)
- Return type:
- classmethod second_order(K, zeta, wn, name='Second Order')[source]
Create second-order transfer function. G(s) = K * wn² / (s² + 2*zeta*wn*s + wn²)
- Parameters:
- Returns:
TransferFunction object
- Return type:
- frequency_response(w)[source]
Calculate frequency response.
- Parameters:
w (<MagicMock id='130137681100288'>) – Frequency vector [rad/s]
- Returns:
Tuple of (magnitude, phase, frequency)
- Return type:
Tuple[<MagicMock id=’130137681674320’>, <MagicMock id=’130137681674656’>, <MagicMock id=’130137681674992’>]
System Analysis
System Analysis for SPROCLIB
This module provides comprehensive system analysis tools including stability analysis, controllability/observability tests, and performance metrics.
Author: Thorsten Gressling <gressling@paramus.ai> License: MIT License
- class sproclib.analysis.system_analysis.SystemAnalysis(name='System Analysis')[source]
Bases:
objectComprehensive system analysis tools.
- Parameters:
name (str)
- __init__(name='System Analysis')[source]
Initialize system analysis.
- Parameters:
name (str) – Analysis name
- stability_analysis(A, system_name='System')[source]
Analyze stability of linear system dx/dt = A*x.
- disturbance_rejection_analysis(plant_tf, controller_tf, disturbance_type='step', w=None)[source]
Analyze disturbance rejection performance.
- Parameters:
plant_tf (Tuple[<MagicMock id='130137681684736'>, <MagicMock id='130137681685072'>]) – Plant transfer function (num, den)
controller_tf (Tuple[<MagicMock id='130137681686752'>, <MagicMock id='130137681687088'>]) – Controller transfer function (num, den)
disturbance_type (str) – Type of disturbance (‘step’, ‘frequency’)
w (<MagicMock id='130137681681712'> | None) – Frequency vector for analysis
- Returns:
Dictionary with disturbance rejection analysis
- Return type:
- performance_metrics(t, y, setpoint=1.0)[source]
Calculate standard performance metrics for step response.
- linearization_analysis(model_func, x_ss, u_ss, epsilon=1e-06)[source]
Linearize a nonlinear model and analyze the linear approximation.
- Parameters:
model_func (callable) – Function f(x, u) returning dx/dt
x_ss (<MagicMock id='130137681688768'>) – Steady-state states
u_ss (<MagicMock id='130137681689104'>) – Steady-state inputs
epsilon (float) – Perturbation size for finite differences
- Returns:
Dictionary with linearization results
- Return type:
- sproclib.analysis.system_analysis.step_response(system, t=None, t_final=10.0, input_magnitude=1.0)[source]
Calculate step response of a system.
- Parameters:
- Returns:
Dictionary with ‘t’ and ‘y’ arrays
- Return type:
- sproclib.analysis.system_analysis.bode_plot(system, w=None, plot=True, title='Bode Plot')[source]
Generate Bode plot for frequency response analysis.
- Parameters:
- Returns:
Dictionary with frequency, magnitude, and phase data
- Return type:
Model Identification
Model Identification for SPROCLIB
This module provides tools for system identification and model fitting from experimental data or step response tests.
Author: Thorsten Gressling <gressling@paramus.ai> License: MIT License
- class sproclib.analysis.model_identification.ModelIdentification(name='Model Identification')[source]
Bases:
objectSystem identification and model fitting tools.
- Parameters:
name (str)
- __init__(name='Model Identification')[source]
Initialize model identification.
- Parameters:
name (str) – Identification name
- fit_fopdt(t_data, y_data, step_magnitude=1.0, initial_guess=None)[source]
Fit First Order Plus Dead Time model to step response data.
- Parameters:
- Returns:
Dictionary with fitted parameters and metrics
- Return type:
- fit_sopdt(t_data, y_data, step_magnitude=1.0, initial_guess=None)[source]
Fit Second Order Plus Dead Time model to step response data.
- Parameters:
- Returns:
Dictionary with fitted parameters and metrics
- Return type:
- fit_transfer_function(freq_data, magnitude_data, phase_data, model_order=(2, 2))[source]
Fit transfer function to frequency response data.
- Parameters:
freq_data (<MagicMock id='130137681090544'>) – Frequency data [rad/s]
magnitude_data (<MagicMock id='130137681093232'>) – Magnitude data (linear scale)
phase_data (<MagicMock id='130137681092896'>) – Phase data [radians]
model_order (Tuple[int, int]) – Transfer function order (numerator, denominator)
- Returns:
Dictionary with fitted transfer function
- Return type:
Quick Usage
Transfer Function Analysis:
from analysis.transfer_function import TransferFunction
from analysis.system_analysis import step_response, bode_plot
# Create a transfer function
tf = TransferFunction([1], [1, 1], name="First Order")
# Analyze step response
response = step_response(tf)
# Generate Bode plot
bode_data = bode_plot(tf, plot=True)
Model Identification:
from analysis.model_identification import fit_fopdt
import numpy as np
# Generate sample data
t = np.linspace(0, 20, 100)
y = 2 * (1 - np.exp(-t/3)) # FOPDT response
# Fit FOPDT model
result = fit_fopdt(t, y)
print(f"K={result['K']:.2f}, tau={result['tau']:.2f}")