Transfer Function
In this example we demonstrate how to use transfer functions in PathSim using the Pole-Residue-Constant (PRC) form. This representation is particularly convenient for transfer functions with complex poles.
You can also find this example as a single file in the GitHub repository.
PathSim provides multiple transfer function representations:
- TransferFunctionPRC: Pole-Residue-Constant form (poles and residues) - TransferFunctionZPG: Zero-Pole-Gain form
In this example, we use the PRC form to define a transfer function with complex conjugate poles.
First let's import the Simulation and Connection classes along with the required blocks:
Transfer Function Definition
The pole-residue-constant form represents a transfer function as:
MATHDISPLAY0ENDMATH
where:
- MATHINLINE1ENDMATH is the constant term (direct feedthrough)
- MATHINLINE2ENDMATH are the residues
- MATHINLINE3ENDMATH are the poles
Complex conjugate poles must come with corresponding complex conjugate residues to ensure a real-valued impulse response.
This transfer function has:
- One real pole at MATHINLINE0ENDMATH
- Two pairs of complex conjugate poles at MATHINLINE1ENDMATH and MATHINLINE2ENDMATH
The complex poles will produce oscillatory behavior in the step response.
Now let's create the blocks. We use a Source block to generate a step input and a TransferFunctionPRC block for our system:
We initialize the simulation with the RKCK54 solver (Runge-Kutta-Cash-Karp 5(4) method) for accurate integration:
12:44:10 - INFO - LOGGING (log: True) 12:44:10 - INFO - BLOCKS (total: 3, dynamic: 1, static: 2, eventful: 0) 12:44:10 - INFO - GRAPH (nodes: 3, edges: 3, alg. depth: 1, loop depth: 0, runtime: 0.054ms)
Now let's run the simulation and plot the step response:
12:44:10 - INFO - STARTING -> TRANSIENT (Duration: 100.00s) 12:44:10 - INFO - -------------------- 1% | 0.0s<0.2s | 1988.0 it/s 12:44:10 - INFO - ####---------------- 20% | 0.0s<0.0s | 6795.3 it/s 12:44:10 - INFO - ########------------ 40% | 0.0s<0.0s | 6818.1 it/s 12:44:10 - INFO - ############-------- 60% | 0.0s<0.0s | 6825.5 it/s 12:44:10 - INFO - ################---- 80% | 0.1s<0.0s | 6622.0 it/s 12:44:10 - INFO - #################### 100% | 0.1s<--:-- | 6730.9 it/s 12:44:10 - INFO - FINISHED -> TRANSIENT (total steps: 346, successful: 224, runtime: 59.55 ms)