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:
19:04:48 - INFO - LOGGING (log: True) 19:04:48 - INFO - BLOCKS (total: 3, dynamic: 1, static: 2, eventful: 0) 19:04:48 - INFO - GRAPH (nodes: 3, edges: 3, alg. depth: 1, loop depth: 0, runtime: 0.061ms)
Now let's run the simulation and plot the step response:
19:04:48 - INFO - STARTING -> TRANSIENT (Duration: 100.00s) 19:04:48 - INFO - -------------------- 1% | 0.0s<0.2s | 1704.5 it/s 19:04:48 - INFO - ####---------------- 20% | 0.0s<0.0s | 7076.5 it/s 19:04:48 - INFO - ########------------ 40% | 0.0s<0.0s | 6880.5 it/s 19:04:48 - INFO - ############-------- 60% | 0.1s<0.0s | 6558.0 it/s 19:04:48 - INFO - ################---- 80% | 0.1s<0.0s | 7008.2 it/s 19:04:48 - INFO - #################### 100% | 0.1s<--:-- | 6915.0 it/s 19:04:48 - INFO - FINISHED -> TRANSIENT (total steps: 346, successful: 224, runtime: 67.20 ms)