---
url: /dyad/stable/stdlib/BlockComponents/tests/Sources.Tests.VariableSinCos.md
description: >-
  Dyad Sources.Tests.VariableSinCos docs.  Test component for sine and cosine
  generators with variable frequency and amplitude inputs.
---

# `Sources.Tests.VariableSinCos` {#Sources.Tests.VariableSinCos}

Test component for sine and cosine generators with variable frequency and amplitude inputs.

Creates a test environment that connects amplitude and frequency input sources to sine and cosine wave generators. The amplitude source is a ramp that starts at 2 and decreases to 0 over 3 seconds, while the frequency is held constant at 2 Hz. This test setup allows visualization of how the wave generators respond to changing amplitude while maintaining a constant frequency.

## Usage {#Usage}

`BlockComponents.Sources.Tests.VariableSinCos()`

## Behavior {#Behavior}

$$ \begin{align}
0 &= \mathrm{connect}\left( amplitude\_{source\_{+}y}, cos\_{wave\_{+}amplitude} \right) \\
0 &= \mathrm{connect}\left( amplitude\_{source\_{+}y}, sine\_{wave\_{+}amplitude} \right) \\
0 &= \mathrm{connect}\left( frequency\_{source\_{+}y}, sine\_{wave\_{+}frequency} \right) \\
0 &= \mathrm{connect}\left( frequency\_{source\_{+}y}, cos\_{wave\_{+}frequency} \right) \\
\frac{\mathrm{d}\mathtt{sine_wave.phi}\left( t \right)}{\mathrm{d}t} &= 6.2832 ~ \mathtt{sine_wave.frequency}\left( t \right) \\
\mathtt{sine_wave.y}\left( t \right) &= \mathtt{sine_wave.offset} + \sin\left( \mathtt{sine_wave.phi}\left( t \right) \right) ~ \mathtt{sine_wave.amplitude}\left( t \right) \\
\frac{\mathrm{d}\mathtt{cos_wave.phi}\left( t \right)}{\mathrm{d}t} &= 6.2832 ~ \mathtt{cos_wave.frequency}\left( t \right) \\
\mathtt{cos_wave.y}\left( t \right) &= \mathtt{cos_wave.offset} + \cos\left( \mathtt{cos_wave.phi}\left( t \right) \right) ~ \mathtt{cos_wave.amplitude}\left( t \right) \\
\mathtt{amplitude_source.y}\left( t \right) &= ifelse\left( \mathtt{amplitude_source.start_time} < t, ifelse\left( t < \mathtt{amplitude_source.duration} + \mathtt{amplitude_source.start_time}, \mathtt{amplitude_source.offset} + \frac{\mathtt{amplitude_source.height} ~ \left(  - \mathtt{amplitude_source.start_time} + t \right)}{\mathtt{amplitude_source.duration}}, \mathtt{amplitude_source.height} + \mathtt{amplitude_source.offset} \right), \mathtt{amplitude_source.offset} \right) \\
\mathtt{frequency_source.y}\left( t \right) &= \mathtt{frequency_source.k}
\end{align}
$$

## Source {#Source}

```dyad
"""
Test component for sine and cosine generators with variable frequency and amplitude inputs.

Creates a test environment that connects amplitude and frequency input sources to sine and cosine
wave generators. The amplitude source is a ramp that starts at 2 and decreases to 0 over 3 seconds,
while the frequency is held constant at 2 Hz. This test setup allows visualization of how the wave
generators respond to changing amplitude while maintaining a constant frequency.
"""
test component VariableSinCos
  "Sine wave generator with variable frequency and amplitude inputs"
  sine_wave = BlockComponents.Sources.SineVariableFrequencyAndAmplitude() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 630, "y1": 340, "x2": 730, "y2": 440, "rot": 0}
      }
    }
  }
  "Cosine wave generator with variable frequency and amplitude inputs"
  cos_wave = BlockComponents.Sources.CosineVariableFrequencyAndAmplitude() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 640, "y1": 90, "x2": 740, "y2": 190, "rot": 0}
      }
    }
  }
  "Amplitude source that starts at 2 and linearly decreases to 0 over 3 seconds"
  amplitude_source = BlockComponents.Sources.Ramp(start_time = 0, offset = 2, duration = 3, height = -2) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 220, "y1": 100, "x2": 320, "y2": 200, "rot": 0}
      }
    }
  }
  "Frequency source providing a constant value of 2 Hz"
  frequency_source = BlockComponents.Sources.Constant(k = 2) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 210, "y1": 340, "x2": 310, "y2": 440, "rot": 0}
      }
    }
  }
relations
  connect(cos_wave.amplitude, amplitude_source.y) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 450, "y": 114}, {"x": 450, "y": 150}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(amplitude_source.y, sine_wave.amplitude) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 455, "y": 150}, {"x": 455, "y": 362}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(frequency_source.y, sine_wave.frequency) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 500, "y": 390}, {"x": 500, "y": 413}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(frequency_source.y, cos_wave.frequency) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 500, "y": 390}, {"x": 500, "y": 163}], "E": 2}],
      "renderStyle": "standard"
    }
  }
metadata {
  "Dyad": {
    "icons": {"default": "dyad://BlockComponents/Example.svg"},
    "tests": {"case1": {"stop": 10, "signals": ["sine_wave.y", "cos_wave.y"]}}
  }
}
end
```

```dyad
"""
Test component for sine and cosine generators with variable frequency and amplitude inputs.

Creates a test environment that connects amplitude and frequency input sources to sine and cosine
wave generators. The amplitude source is a ramp that starts at 2 and decreases to 0 over 3 seconds,
while the frequency is held constant at 2 Hz. This test setup allows visualization of how the wave
generators respond to changing amplitude while maintaining a constant frequency.
"""
test component VariableSinCos
  "Sine wave generator with variable frequency and amplitude inputs"
  sine_wave = BlockComponents.Sources.SineVariableFrequencyAndAmplitude() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 630, "y1": 340, "x2": 730, "y2": 440, "rot": 0}
      }
    }
  }
  "Cosine wave generator with variable frequency and amplitude inputs"
  cos_wave = BlockComponents.Sources.CosineVariableFrequencyAndAmplitude() {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 640, "y1": 90, "x2": 740, "y2": 190, "rot": 0}
      }
    }
  }
  "Amplitude source that starts at 2 and linearly decreases to 0 over 3 seconds"
  amplitude_source = BlockComponents.Sources.Ramp(start_time = 0, offset = 2, duration = 3, height = -2) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 220, "y1": 100, "x2": 320, "y2": 200, "rot": 0}
      }
    }
  }
  "Frequency source providing a constant value of 2 Hz"
  frequency_source = BlockComponents.Sources.Constant(k = 2) {
    "Dyad": {
      "placement": {
        "diagram": {"iconName": "default", "x1": 210, "y1": 340, "x2": 310, "y2": 440, "rot": 0}
      }
    }
  }
relations
  connect(cos_wave.amplitude, amplitude_source.y) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 450, "y": 114}, {"x": 450, "y": 150}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(amplitude_source.y, sine_wave.amplitude) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 455, "y": 150}, {"x": 455, "y": 362}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(frequency_source.y, sine_wave.frequency) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 500, "y": 390}, {"x": 500, "y": 413}], "E": 2}],
      "renderStyle": "standard"
    }
  }
  connect(frequency_source.y, cos_wave.frequency) {
    "Dyad": {
      "edges": [{"S": 1, "M": [{"x": 500, "y": 390}, {"x": 500, "y": 163}], "E": 2}],
      "renderStyle": "standard"
    }
  }
metadata {
  "Dyad": {
    "icons": {"default": "dyad://BlockComponents/Example.svg"},
    "tests": {"case1": {"stop": 10, "signals": ["sine_wave.y", "cos_wave.y"]}}
  }
}
end
```

## Test Cases {#Test-Cases}

### Test Case `case1` {#Test-Case-case1}

## Related {#Related}

* Examples

* Experiments

* Analyses

* Tests
  * [`Constant`](Sources.Tests.VariableSinCos.md)

  * [`CosineVariableFrequencyAndAmplitude`](Sources.Tests.VariableSinCos.md)

  * [`Ramp`](Sources.Tests.VariableSinCos.md)

  * [`SineVariableFrequencyAndAmplitude`](Sources.Tests.VariableSinCos.md)
