Skip to content
LIBRARY
Examples.TestSampleWithADEffects.md

Examples.TestSampleWithADEffects ​

Test component that validates the SampleWithADEffects block.

Connects a Sine source to a SampleWithADEffects block configured with noise and 3-bit quantization, then feeds the output through a ZeroOrderHold to an integrator. The test verifies that sampling, noise addition, and quantization all work together.

Usage ​

DiscreteComponents.Examples.TestSampleWithADEffects()

Behavior ​

Behavior of this component cannot be rendered because it includes path variables.

Source ​

dyad
"""
Test component that validates the SampleWithADEffects block.

Connects a Sine source to a SampleWithADEffects block configured with noise and
3-bit quantization, then feeds the output through a ZeroOrderHold to an integrator.
The test verifies that sampling, noise addition, and quantization all work together.
"""
test component TestSampleWithADEffects
  sine = BlockComponents.Sources.Sine(frequency = 1, amplitude = 1.0) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 450, "x2": 120, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  samplewithad = DiscreteComponents.SampleWithADEffects(bits = 3) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 200, "y1": 450, "x2": 300, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  zoh = DiscreteComponents.ZeroOrderHold() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 400, "y1": 450, "x2": 500, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  integrator = BlockComponents.Continuous.Integrator() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 600, "y1": 450, "x2": 700, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  periodicclock = DiscreteComponents.PeriodicClock(dt = 0.3) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 300, "y1": 310, "x2": 200, "y2": 410, "rot": 0}
      },
      "tags": []
    }
  }
relations
  connect(sine.y, samplewithad.u) {"Dyad": {"renderStyle": "standard", "edges": [{"S": 1, "E": 2, "M": []}]}}
  connect(samplewithad.y, zoh.u, periodicclock.y) {
    "Dyad": {
      "edges": [
        {"S": 1, "M": [], "E": -1},
        {"S": -1, "M": [], "E": 2},
        {"S": 3, "M": [{"x": 340, "y": 360}], "E": -1}
      ],
      "junctions": [{"x": 340, "y": 500}],
      "renderStyle": "standard"
    }
  }
  connect(zoh.y, integrator.u) {"Dyad": {"renderStyle": "standard", "edges": [{"S": 1, "E": 2, "M": []}]}}
metadata {
  "Dyad": {
    "tests": {
      "case1": {"stop": 10, "expect": {"signals": ["sine.y", "samplewithad.y", "zoh.y"]}}
    },
    "doc": {"behavior": false}
  }
}
end
Flattened Source
dyad
"""
Test component that validates the SampleWithADEffects block.

Connects a Sine source to a SampleWithADEffects block configured with noise and
3-bit quantization, then feeds the output through a ZeroOrderHold to an integrator.
The test verifies that sampling, noise addition, and quantization all work together.
"""
test component TestSampleWithADEffects
  sine = BlockComponents.Sources.Sine(frequency = 1, amplitude = 1.0) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 20, "y1": 450, "x2": 120, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  samplewithad = DiscreteComponents.SampleWithADEffects(bits = 3) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 200, "y1": 450, "x2": 300, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  zoh = DiscreteComponents.ZeroOrderHold() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 400, "y1": 450, "x2": 500, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  integrator = BlockComponents.Continuous.Integrator() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 600, "y1": 450, "x2": 700, "y2": 550, "rot": 0}
      },
      "tags": []
    }
  }
  periodicclock = DiscreteComponents.PeriodicClock(dt = 0.3) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 300, "y1": 310, "x2": 200, "y2": 410, "rot": 0}
      },
      "tags": []
    }
  }
relations
  connect(sine.y, samplewithad.u) {"Dyad": {"renderStyle": "standard", "edges": [{"S": 1, "E": 2, "M": []}]}}
  connect(samplewithad.y, zoh.u, periodicclock.y) {
    "Dyad": {
      "edges": [
        {"S": 1, "M": [], "E": -1},
        {"S": -1, "M": [], "E": 2},
        {"S": 3, "M": [{"x": 340, "y": 360}], "E": -1}
      ],
      "junctions": [{"x": 340, "y": 500}],
      "renderStyle": "standard"
    }
  }
  connect(zoh.y, integrator.u) {"Dyad": {"renderStyle": "standard", "edges": [{"S": 1, "E": 2, "M": []}]}}
metadata {
  "Dyad": {
    "tests": {
      "case1": {"stop": 10, "expect": {"signals": ["sine.y", "samplewithad.y", "zoh.y"]}}
    },
    "doc": {"behavior": false}
  }
}
end


Test Cases ​

Test Case case1 ​

julia
plt

julia
plt

julia
plt