FirstOrder
First-order filter with a single real pole and adjustable gain.
Implements a dynamic system with transfer function
where T
is the time constant and k
is the gain. The filter has a single real pole at s = -1/T and smoothly tracks the input signal with the specified time constant.
This component extends from SISO
Usage
FirstOrder(T, k=1.0)
Parameters:
Name | Description | Units | Default value |
---|---|---|---|
T | Time constant controlling the speed of response | – | |
k | Gain factor applied to the input | – | 1 |
Connectors
u
- This connector represents a real signal as an input to a component (RealInput
)y
- This connector represents a real signal as an output from a component (RealOutput
)
Variables
Name | Description | Units |
---|---|---|
x | State variable representing the filtered value | – |
Behavior
Source
dyad
# First-order filter with a single real pole and adjustable gain.
#
# Implements a dynamic system with transfer function
#
# ```math
# \frac{k}{sT + 1}
# ```
# where `T` is the time constant and `k` is the gain. The filter has a single real pole at s = -1/T
# and smoothly tracks the input signal with the specified time constant.
component FirstOrder
extends SISO
# State variable representing the filtered value
variable x::Real
# Time constant controlling the speed of response
parameter T::Real
# Gain factor applied to the input
parameter k::Real = 1.0
relations
der(x) = (k*u-x)/T
y = x
metadata {"Dyad": {"icons": {"default": "dyad://BlockComponents/FirstOrder.svg"}}}
end
Flattened Source
dyad
# First-order filter with a single real pole and adjustable gain.
#
# Implements a dynamic system with transfer function
#
# ```math
# \frac{k}{sT + 1}
# ```
# where `T` is the time constant and `k` is the gain. The filter has a single real pole at s = -1/T
# and smoothly tracks the input signal with the specified time constant.
component FirstOrder
# Input signal port
u = RealInput() [{
"Dyad": {
"placement": {"icon": {"iconName": "input", "x1": -50, "y1": 450, "x2": 50, "y2": 550}}
}
}]
# Output signal port
y = RealOutput() [{
"Dyad": {
"placement": {"icon": {"iconName": "output", "x1": 950, "y1": 450, "x2": 1050, "y2": 550}}
}
}]
# State variable representing the filtered value
variable x::Real
# Time constant controlling the speed of response
parameter T::Real
# Gain factor applied to the input
parameter k::Real = 1.0
relations
der(x) = (k*u-x)/T
y = x
metadata {"Dyad": {"icons": {"default": "dyad://BlockComponents/FirstOrder.svg"}}}
end
Test Cases
This is setup code, that must be run before each test case.
julia
using BlockComponents
using ModelingToolkit, OrdinaryDiffEqDefault
using Plots
using CSV, DataFrames
snapshotsdir = joinpath(dirname(dirname(pathof(BlockComponents))), "test", "snapshots")
"/home/actions-runner-10/.julia/packages/BlockComponents/77kIK/test/snapshots"
Related
Examples
Experiments
Analyses
Tests