TestNDelay Icon
Examples.TestNDelay
Test component that validates the NDelay component.
This component validates that a single NDelay block is equivalent to a chain of UnitDelay blocks.
Usage
DiscreteComponents.Examples.TestNDelay()
Variables
| Name | Description | Units |
|---|---|---|
ud1equalsnd | – | |
ud2equalsnd1 | – |
Behavior
\[ \begin{equation} \left[ \begin{array}{c} \mathtt{ud1equalsnd}\left( t \right) = \mathtt{unitdelay.y}\left( t \right) = \mathtt{ndelay.y}\left( t \right) \\ \mathtt{ud2equalsnd1}\left( t \right) = \mathtt{unitdelay1.y}\left( t \right) = \mathtt{ndelay1.y}\left( t \right) \\ \mathrm{connect}\left( ramp_{+}y(t), periodicsampler_{+}u(t) \right) \\ \mathrm{connect}\left( periodicsampler_{+}y(t), ndelay_{+}u(t) \right) \\ \mathrm{connect}\left( periodicsampler_{+}y(t), ndelay1_{+}u(t) \right) \\ \mathrm{connect}\left( periodicsampler_{+}y(t), unitdelay_{+}u(t) \right) \\ \mathrm{connect}\left( unitdelay_{+}y(t), unitdelay1_{+}u(t) \right) \\ \mathrm{connect}\left( unitdelay1_{+}y(t), unitdelay2_{+}u(t) \right) \\ \mathtt{ramp.y}\left( t \right) = ifelse\left( \mathtt{ramp.start\_time} < t, ifelse\left( t < \mathtt{ramp.duration} + \mathtt{ramp.start\_time}, \mathtt{ramp.offset} + \frac{\mathtt{ramp.height} \left( - \mathtt{ramp.start\_time} + t \right)}{\mathtt{ramp.duration}}, \mathtt{ramp.height} + \mathtt{ramp.offset} \right), \mathtt{ramp.offset} \right) \\ \mathrm{connect}\left( u(t), sampler_{+}u(t) \right) \\ \mathrm{connect}\left( sampler_{+}y(t), y(t), clock_{+}y(t) \right) \\ \frac{\mathrm{d} \mathtt{periodicsampler.clock.dummy.dummy}\left( t \right)}{\mathrm{d}t} = 0 \\ \mathtt{periodicsampler.sampler.y}\left( t \right) = Sample(ModelingToolkit.InferredClock.var"typeof(InferredClock)"(ModelingToolkit.InferredClock.var"##Storage#InferredDiscrete"(0)))\left( \mathtt{periodicsampler.sampler.u}\left( t \right) \right) \\ \mathtt{unitdelay.y}\left( t \right) = Shift(t, -1)\left( \mathtt{unitdelay.u}\left( t \right) \right) \\ \frac{\mathrm{d} \mathtt{unitdelay.dummy.dummy}\left( t \right)}{\mathrm{d}t} = 0 \\ \mathtt{unitdelay1.y}\left( t \right) = Shift(t, -1)\left( \mathtt{unitdelay1.u}\left( t \right) \right) \\ \frac{\mathrm{d} \mathtt{unitdelay1.dummy.dummy}\left( t \right)}{\mathrm{d}t} = 0 \\ \mathtt{unitdelay2.y}\left( t \right) = Shift(t, -1)\left( \mathtt{unitdelay2.u}\left( t \right) \right) \\ \frac{\mathrm{d} \mathtt{unitdelay2.dummy.dummy}\left( t \right)}{\mathrm{d}t} = 0 \\ \mathtt{ndelay.y}\left( t \right) = Shift(t, -2)\left( \mathtt{ndelay.u}\left( t \right) \right) \\ \frac{\mathrm{d} \mathtt{ndelay.dummy.dummy}\left( t \right)}{\mathrm{d}t} = 0 \\ \mathtt{ndelay1.y}\left( t \right) = Shift(t, -3)\left( \mathtt{ndelay1.u}\left( t \right) \right) \\ \frac{\mathrm{d} \mathtt{ndelay1.dummy.dummy}\left( t \right)}{\mathrm{d}t} = 0 \\ \end{array} \right] \end{equation} \]
Source
"""
Test component that validates the NDelay component.
This component validates that a single `NDelay` block is equivalent to a chain of `UnitDelay` blocks.
"""
test component TestNDelay
ramp = BlockComponents.Ramp(duration = 10, height = 10) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": -50, "y1": 450, "x2": 50, "y2": 550, "rot": 0}
},
"tags": []
}
}
periodicsampler = DiscreteComponents.PeriodicSampler(dt = 1) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 90, "y1": 450, "x2": 190, "y2": 550, "rot": 0}
},
"tags": []
}
}
unitdelay = DiscreteComponents.UnitDelay() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 250, "y1": 340, "x2": 350, "y2": 440, "rot": 0}
},
"tags": []
}
}
unitdelay1 = DiscreteComponents.UnitDelay() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 380, "y1": 340, "x2": 480, "y2": 440, "rot": 0}
},
"tags": []
}
}
unitdelay2 = DiscreteComponents.UnitDelay() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 510, "y1": 340, "x2": 610, "y2": 440, "rot": 0}
},
"tags": []
}
}
ndelay = DiscreteComponents.NDelay(n = 2) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 250, "y1": 530, "x2": 350, "y2": 630, "rot": 0}
},
"tags": []
}
}
ndelay1 = DiscreteComponents.NDelay(n = 3) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 250, "y1": 670, "x2": 350, "y2": 770, "rot": 0}
},
"tags": []
}
}
variable ud1equalsnd::Boolean
variable ud2equalsnd1::Boolean
relations
ud1equalsnd = unitdelay.y == ndelay.y
ud2equalsnd1 = unitdelay1.y == ndelay1.y
connect(ramp.y, periodicsampler.u) {"Dyad": {"renderStyle": "standard", "edges": [{"S": 1, "E": 2, "M": []}]}}
connect(periodicsampler.y, ndelay.u) {
"Dyad": {
"renderStyle": "standard",
"edges": [{"S": 1, "M": [{"x": 221, "y": 500}, {"x": 221, "y": 580}], "E": 2}]
}
}
connect(periodicsampler.y, ndelay1.u) {
"Dyad": {
"renderStyle": "standard",
"edges": [{"S": 1, "M": [{"x": 221, "y": 500}, {"x": 221, "y": 720}], "E": 2}]
}
}
connect(periodicsampler.y, unitdelay.u) {
"Dyad": {
"renderStyle": "standard",
"edges": [{"S": 1, "M": [{"x": 220.5, "y": 500}, {"x": 220.5, "y": 390}], "E": 2}]
}
}
connect(unitdelay.y, unitdelay1.u) {"Dyad": {"renderStyle": "standard", "edges": [{"S": 1, "E": 2, "M": []}]}}
connect(unitdelay1.y, unitdelay2.u) {"Dyad": {"renderStyle": "standard", "edges": [{"S": 1, "E": 2, "M": []}]}}
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": ["ramp.y", "ndelay.y", "ndelay1.y", "unitdelay1.y", "unitdelay2.y"]
}
}
},
"labels": [
{
"label": "This chain of unit delays approximates the n-delay blocks",
"x": 430,
"y": 240,
"rot": 0,
"layer": "diagram",
"attrs": {
"fill": "black",
"font-size": "20",
"dominant-baseline": "central",
"text-anchor": "middle"
}
},
{
"label": "== ndelay",
"x": 430,
"y": 320,
"rot": 0,
"layer": "diagram",
"attrs": {
"fill": "black",
"font-size": "20",
"dominant-baseline": "central",
"text-anchor": "middle"
}
},
{
"label": "== ndelay1",
"x": 560,
"y": 320,
"rot": 0,
"layer": "diagram",
"attrs": {
"fill": "black",
"font-size": "20",
"dominant-baseline": "central",
"text-anchor": "middle"
}
}
],
"icons": {"default": "dyad://Dyad/Default.svg"},
"path": {},
"doc": {"behavior": true}
}
}
end
Flattened Source
"""
Test component that validates the NDelay component.
This component validates that a single `NDelay` block is equivalent to a chain of `UnitDelay` blocks.
"""
test component TestNDelay
ramp = BlockComponents.Ramp(duration = 10, height = 10) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": -50, "y1": 450, "x2": 50, "y2": 550, "rot": 0}
},
"tags": []
}
}
periodicsampler = DiscreteComponents.PeriodicSampler(dt = 1) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 90, "y1": 450, "x2": 190, "y2": 550, "rot": 0}
},
"tags": []
}
}
unitdelay = DiscreteComponents.UnitDelay() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 250, "y1": 340, "x2": 350, "y2": 440, "rot": 0}
},
"tags": []
}
}
unitdelay1 = DiscreteComponents.UnitDelay() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 380, "y1": 340, "x2": 480, "y2": 440, "rot": 0}
},
"tags": []
}
}
unitdelay2 = DiscreteComponents.UnitDelay() {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 510, "y1": 340, "x2": 610, "y2": 440, "rot": 0}
},
"tags": []
}
}
ndelay = DiscreteComponents.NDelay(n = 2) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 250, "y1": 530, "x2": 350, "y2": 630, "rot": 0}
},
"tags": []
}
}
ndelay1 = DiscreteComponents.NDelay(n = 3) {
"Dyad": {
"placement": {
"diagram": {"iconName": "default", "x1": 250, "y1": 670, "x2": 350, "y2": 770, "rot": 0}
},
"tags": []
}
}
variable ud1equalsnd::Boolean
variable ud2equalsnd1::Boolean
relations
ud1equalsnd = unitdelay.y == ndelay.y
ud2equalsnd1 = unitdelay1.y == ndelay1.y
connect(ramp.y, periodicsampler.u) {"Dyad": {"renderStyle": "standard", "edges": [{"S": 1, "E": 2, "M": []}]}}
connect(periodicsampler.y, ndelay.u) {
"Dyad": {
"renderStyle": "standard",
"edges": [{"S": 1, "M": [{"x": 221, "y": 500}, {"x": 221, "y": 580}], "E": 2}]
}
}
connect(periodicsampler.y, ndelay1.u) {
"Dyad": {
"renderStyle": "standard",
"edges": [{"S": 1, "M": [{"x": 221, "y": 500}, {"x": 221, "y": 720}], "E": 2}]
}
}
connect(periodicsampler.y, unitdelay.u) {
"Dyad": {
"renderStyle": "standard",
"edges": [{"S": 1, "M": [{"x": 220.5, "y": 500}, {"x": 220.5, "y": 390}], "E": 2}]
}
}
connect(unitdelay.y, unitdelay1.u) {"Dyad": {"renderStyle": "standard", "edges": [{"S": 1, "E": 2, "M": []}]}}
connect(unitdelay1.y, unitdelay2.u) {"Dyad": {"renderStyle": "standard", "edges": [{"S": 1, "E": 2, "M": []}]}}
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": ["ramp.y", "ndelay.y", "ndelay1.y", "unitdelay1.y", "unitdelay2.y"]
}
}
},
"labels": [
{
"label": "This chain of unit delays approximates the n-delay blocks",
"x": 430,
"y": 240,
"rot": 0,
"layer": "diagram",
"attrs": {
"fill": "black",
"font-size": "20",
"dominant-baseline": "central",
"text-anchor": "middle"
}
},
{
"label": "== ndelay",
"x": 430,
"y": 320,
"rot": 0,
"layer": "diagram",
"attrs": {
"fill": "black",
"font-size": "20",
"dominant-baseline": "central",
"text-anchor": "middle"
}
},
{
"label": "== ndelay1",
"x": 560,
"y": 320,
"rot": 0,
"layer": "diagram",
"attrs": {
"fill": "black",
"font-size": "20",
"dominant-baseline": "central",
"text-anchor": "middle"
}
}
],
"icons": {"default": "dyad://Dyad/Default.svg"},
"path": {},
"doc": {"behavior": true}
}
}
endTest Cases
Test Case case1
pltpltpltpltpltRelated
- Examples
- Experiments
- Analyses
- Tests