SecondOrder
Second-order filter with configurable gain, bandwidth, and damping ratio.
A filter that implements a second-order transfer function with configurable gain k, bandwidth w, and relative damping d. The filter can be configured to achieve different response characteristics by adjusting the damping ratio: critically damped (d=1), under-damped (d<1), or over-damped (d>1). A damping value of d=1/√2 creates a Butterworth filter with maximally flat frequency response. The filter is characterized by the transfer function
This component extends from SISO
Usage
SecondOrder(k=1.0, w=1.0, d=1.0)
Parameters:
Name | Description | Units | Default value |
---|---|---|---|
k | Gain | – | 1 |
w | Bandwidth (angular frequency) | – | 1 |
d | Relative damping | – | 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 of SecondOrder filter | – |
xd | Derivative state of SecondOrder filter | – |
Behavior
Source
# Second-order filter with configurable gain, bandwidth, and damping ratio.
#
# A filter that implements a second-order transfer function with configurable gain k,
# bandwidth w, and relative damping d. The filter can be configured to achieve different
# response characteristics by adjusting the damping ratio: critically damped (d=1),
# under-damped (d<1), or over-damped (d>1). A damping value of d=1/√2 creates a Butterworth
# filter with maximally flat frequency response. The filter is characterized by the transfer
# function
#
# ```math
# Y(s)/U(s) = \frac{k \cdot w^2}{s^2 + 2d \cdot w \cdot s + w^2}
# ```
component SecondOrder
extends SISO
# State of SecondOrder filter
variable x::Real
# Derivative state of SecondOrder filter
variable xd::Real
# Gain
parameter k::Real = 1.0
# Bandwidth (angular frequency)
parameter w::Real = 1.0
# Relative damping
parameter d::Real = 1.0
relations
der(x) = xd
der(xd) = w*(w*(k*u-x)-2*d*xd)
y = x
metadata {"Dyad": {"icons": {"default": "dyad://BlockComponents/SecondOrder.svg"}}}
end
Flattened Source
# Second-order filter with configurable gain, bandwidth, and damping ratio.
#
# A filter that implements a second-order transfer function with configurable gain k,
# bandwidth w, and relative damping d. The filter can be configured to achieve different
# response characteristics by adjusting the damping ratio: critically damped (d=1),
# under-damped (d<1), or over-damped (d>1). A damping value of d=1/√2 creates a Butterworth
# filter with maximally flat frequency response. The filter is characterized by the transfer
# function
#
# ```math
# Y(s)/U(s) = \frac{k \cdot w^2}{s^2 + 2d \cdot w \cdot s + w^2}
# ```
component SecondOrder
# 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 of SecondOrder filter
variable x::Real
# Derivative state of SecondOrder filter
variable xd::Real
# Gain
parameter k::Real = 1.0
# Bandwidth (angular frequency)
parameter w::Real = 1.0
# Relative damping
parameter d::Real = 1.0
relations
der(x) = xd
der(xd) = w*(w*(k*u-x)-2*d*xd)
y = x
metadata {"Dyad": {"icons": {"default": "dyad://BlockComponents/SecondOrder.svg"}}}
end
Test Cases
This is setup code, that must be run before each test case.
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