LIBRARY
Examples.TestUnitDifference ​
Test component that validates the UnitDifference block by computing the discrete difference of a sine wave.
This component connects a sine wave generator to a UnitDifference block which computes y[n] = u[n] - u[n-1]. The discrete difference approximates the derivative of the sine wave. With a sample time of 0.1s and sine frequency of 0.1 Hz, the test verifies that the difference operator produces the expected rate of change of the input signal.
Usage ​
DiscreteComponents.Examples.TestUnitDifference()
Behavior ​
Source ​
dyad
"""
Test component that validates the UnitDifference block by computing the discrete difference of a sine wave.
This component connects a sine wave generator to a UnitDifference block which computes y[n] = u[n] - u[n-1].
The discrete difference approximates the derivative of the sine wave. With a sample time of 0.1s and
sine frequency of 0.1 Hz, the test verifies that the difference operator produces the expected rate of
change of the input signal.
"""
test component TestUnitDifference
sine = BlockComponents.Sources.Sine(frequency = 0.1, amplitude = 1.0) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 20, "y1": 140, "x2": 120, "y2": 240, "rot": 0}
},
"tags": []
}
}
unitdifference = DiscreteComponents.UnitDifference(initialization = DiscreteComponents.InitialCondition.InitialState(x0 = 0.0)) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 380, "y1": 140, "x2": 480, "y2": 240, "rot": 0}
},
"tags": []
}
}
terminator = BlockComponents.Routing.Terminator() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 580, "y1": 140, "x2": 680, "y2": 240, "rot": 0}
},
"tags": []
}
}
sampler = DiscreteComponents.Sampler() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 190, "y1": 140, "x2": 290, "y2": 240, "rot": 0}
},
"tags": []
}
}
periodicclock = DiscreteComponents.PeriodicClock(dt = 0.1) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 190, "y1": 280, "x2": 290, "y2": 380, "rot": 0}
},
"tags": []
}
}
relations
connect(unitdifference.y, terminator.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
connect(sine.y, sampler.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
connect(sampler.y, unitdifference.u, periodicclock.y) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
metadata {
"Dyad": {
"experiments": {},
"tests": {
"case1": {
"solver": "Auto",
"start": 0,
"stop": 10,
"params": {},
"initial": {},
"atol": {},
"rtol": {},
"abstol": 0.000001,
"reltol": 0.000001,
"expect": {
"initial": {},
"final": {},
"signals": ["sine.y", "sampler.y", "unitdifference.y"]
}
}
},
"labels": [
{
"label": "First, we have to sample the sine function to convert it to a discrete-time signal.",
"x": 170,
"y": 80,
"rot": 0,
"layer": "diagram",
"attrs": {
"fill": "purple",
"font-size": "20",
"dominant-baseline": "central",
"text-anchor": "middle"
}
},
{
"label": "Then, we take the unit difference, which is `sin(t) - sin(t-dt)` in this case",
"x": 480,
"y": 340,
"rot": 0,
"layer": "diagram",
"attrs": {
"fill": "purple",
"font-size": "20",
"dominant-baseline": "central",
"text-anchor": "middle"
}
}
],
"icons": {"default": "dyad://Dyad/Default.svg"},
"path": {},
"doc": {"behavior": true}
}
}
endFlattened Source
dyad
"""
Test component that validates the UnitDifference block by computing the discrete difference of a sine wave.
This component connects a sine wave generator to a UnitDifference block which computes y[n] = u[n] - u[n-1].
The discrete difference approximates the derivative of the sine wave. With a sample time of 0.1s and
sine frequency of 0.1 Hz, the test verifies that the difference operator produces the expected rate of
change of the input signal.
"""
test component TestUnitDifference
sine = BlockComponents.Sources.Sine(frequency = 0.1, amplitude = 1.0) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 20, "y1": 140, "x2": 120, "y2": 240, "rot": 0}
},
"tags": []
}
}
unitdifference = DiscreteComponents.UnitDifference(initialization = DiscreteComponents.InitialCondition.InitialState(x0 = 0.0)) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 380, "y1": 140, "x2": 480, "y2": 240, "rot": 0}
},
"tags": []
}
}
terminator = BlockComponents.Routing.Terminator() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 580, "y1": 140, "x2": 680, "y2": 240, "rot": 0}
},
"tags": []
}
}
sampler = DiscreteComponents.Sampler() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 190, "y1": 140, "x2": 290, "y2": 240, "rot": 0}
},
"tags": []
}
}
periodicclock = DiscreteComponents.PeriodicClock(dt = 0.1) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 190, "y1": 280, "x2": 290, "y2": 380, "rot": 0}
},
"tags": []
}
}
relations
connect(unitdifference.y, terminator.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
connect(sine.y, sampler.u) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
connect(sampler.y, unitdifference.u, periodicclock.y) {"Dyad": {"edges": [{"S": 1, "M": [], "E": 2}], "renderStyle": "standard"}}
metadata {
"Dyad": {
"experiments": {},
"tests": {
"case1": {
"solver": "Auto",
"start": 0,
"stop": 10,
"params": {},
"initial": {},
"atol": {},
"rtol": {},
"abstol": 0.000001,
"reltol": 0.000001,
"expect": {
"initial": {},
"final": {},
"signals": ["sine.y", "sampler.y", "unitdifference.y"]
}
}
},
"labels": [
{
"label": "First, we have to sample the sine function to convert it to a discrete-time signal.",
"x": 170,
"y": 80,
"rot": 0,
"layer": "diagram",
"attrs": {
"fill": "purple",
"font-size": "20",
"dominant-baseline": "central",
"text-anchor": "middle"
}
},
{
"label": "Then, we take the unit difference, which is `sin(t) - sin(t-dt)` in this case",
"x": 480,
"y": 340,
"rot": 0,
"layer": "diagram",
"attrs": {
"fill": "purple",
"font-size": "20",
"dominant-baseline": "central",
"text-anchor": "middle"
}
}
],
"icons": {"default": "dyad://Dyad/Default.svg"},
"path": {},
"doc": {"behavior": true}
}
}
endTest Cases ​
Test Case case1 ​
julia
pltjulia
pltjulia
pltRelated ​
Examples
Experiments
Analyses
Tests