---
url: /dyad/dev/stdlib/BlockComponents/components/Sources.CosineVariableFrequencyAndAmplitude.md
description: >-
  Dyad Sources.CosineVariableFrequencyAndAmplitude docs.  Cosine voltage source
  with variable frequency and amplitude
---

# `Sources.CosineVariableFrequencyAndAmplitude` {#Sources.CosineVariableFrequencyAndAmplitude}

Cosine voltage source with variable frequency and amplitude

Variable cosine generator with externally controlled amplitude and frequency inputs. The component generates a cosine waveform based on integration of the frequency input:

+————+ | amplitude  | +—–+——+ | v +————+ |            | |  Cosine    +—-> y | Generator  | |            | +————+ ^ | +—–+——+ | frequency  | +————+

$$\frac{d\phi}{dt} = 2\pi \cdot frequency$$

$$y = offset + amplitude \cdot \cos(\phi)$$

## Usage {#Usage}

`BlockComponents.Sources.CosineVariableFrequencyAndAmplitude(phi0=0, offset=0)`

## Parameters: {#Parameters:}

|     Name |                      Description | Units | Default value |
| --------:| --------------------------------:| -----:| -------------:|
|   `phi0` | Initial phase of the cosine wave |     – |             0 |
| `offset` |        Offset of the cosine wave |     – |             0 |

## Connectors {#Connectors}

* `amplitude` - This connector represents a real signal as an input to a component ([`RealInput`](/stdlib/Dyad/connectors/RealInput#RealInput))

* `frequency` - This connector represents a real signal as an input to a component ([`RealInput`](/stdlib/Dyad/connectors/RealInput#RealInput))

* `y` - This connector represents a real signal as an output from a component ([`RealOutput`](/stdlib/Dyad/connectors/RealOutput#RealOutput))

## Variables {#Variables}

|  Name |              Description | Units |
| -----:| ------------------------:| -----:|
| `phi` | Phase of the cosine wave |   rad |

## Behavior {#Behavior}

$$ \begin{align}
\frac{\mathrm{d}\mathtt{phi}\left( t \right)}{\mathrm{d}t} &= 6.2832 ~ \mathtt{frequency}\left( t \right) \\
y\left( t \right) &= \mathtt{offset} + \mathtt{amplitude}\left( t \right) ~ \cos\left( \mathtt{phi}\left( t \right) \right)
\end{align}
$$

## Source {#Source}

````dyad
"""
Cosine voltage source with variable frequency and amplitude

Variable cosine generator with externally controlled amplitude and frequency inputs.
The component generates a cosine waveform based on integration of the frequency input:

+------------+
| amplitude  |
+-----+------+
|
v
+------------+
|            |
|  Cosine    +----> y
| Generator  |
|            |
+------------+
^
|
+-----+------+
| frequency  |
+------------+

```math
\frac{d\phi}{dt} = 2\pi \cdot frequency
```

```math
y = offset + amplitude \cdot \cos(\phi)
```
"""
component CosineVariableFrequencyAndAmplitude
  "Input port for the amplitude of the cosine wave"
  amplitude = RealInput() {
    "Dyad": {
      "placement": {
        "icon": {"iconName": "default", "x1": -100, "y1": 190, "x2": 0, "y2": 290, "rot": 0},
        "diagram": {"iconName": "default", "x1": -100, "y1": 190, "x2": 0, "y2": 290, "rot": 0}
      }
    }
  }
  "Input port for the frequency of the cosine wave in Hz"
  frequency = RealInput() {
    "Dyad": {
      "placement": {
        "icon": {"iconName": "default", "x1": -100, "y1": 680, "x2": 0, "y2": 780, "rot": 0},
        "diagram": {"iconName": "default", "x1": -100, "y1": 680, "x2": 0, "y2": 780, "rot": 0}
      }
    }
  }
  "Output port for the resulting cosine waveform"
  y = RealOutput() {
    "Dyad": {
      "placement": {
        "icon": {
          "iconName": "default",
          "x1": 1100,
          "y1": 450,
          "x2": 1000,
          "y2": 550,
          "rot": 180
        },
        "diagram": {
          "iconName": "default",
          "x1": 1100,
          "y1": 450,
          "x2": 1000,
          "y2": 550,
          "rot": 180
        }
      }
    }
  }
  "Initial phase of the cosine wave"
  parameter phi0::Real = 0
  "Offset of the cosine wave"
  parameter offset::Real = 0
  "Phase of the cosine wave"
  variable phi::Angle
relations
  initial phi = phi0
  der(phi) = 2 * π * frequency
  y = offset + amplitude * cos(phi)
metadata {
  "Dyad": {
    "labels": [{"label": "$(instance)", "x": 500, "y": 1100, "rot": 0}],
    "icons": {"default": "dyad://BlockComponents/CosineVariableFrequencyAndAmplitude.svg"}
  }
}
end
````

````dyad
"""
Cosine voltage source with variable frequency and amplitude

Variable cosine generator with externally controlled amplitude and frequency inputs.
The component generates a cosine waveform based on integration of the frequency input:

+------------+
| amplitude  |
+-----+------+
|
v
+------------+
|            |
|  Cosine    +----> y
| Generator  |
|            |
+------------+
^
|
+-----+------+
| frequency  |
+------------+

```math
\frac{d\phi}{dt} = 2\pi \cdot frequency
```

```math
y = offset + amplitude \cdot \cos(\phi)
```
"""
component CosineVariableFrequencyAndAmplitude
  "Input port for the amplitude of the cosine wave"
  amplitude = RealInput() {
    "Dyad": {
      "placement": {
        "icon": {"iconName": "default", "x1": -100, "y1": 190, "x2": 0, "y2": 290, "rot": 0},
        "diagram": {"iconName": "default", "x1": -100, "y1": 190, "x2": 0, "y2": 290, "rot": 0}
      }
    }
  }
  "Input port for the frequency of the cosine wave in Hz"
  frequency = RealInput() {
    "Dyad": {
      "placement": {
        "icon": {"iconName": "default", "x1": -100, "y1": 680, "x2": 0, "y2": 780, "rot": 0},
        "diagram": {"iconName": "default", "x1": -100, "y1": 680, "x2": 0, "y2": 780, "rot": 0}
      }
    }
  }
  "Output port for the resulting cosine waveform"
  y = RealOutput() {
    "Dyad": {
      "placement": {
        "icon": {
          "iconName": "default",
          "x1": 1100,
          "y1": 450,
          "x2": 1000,
          "y2": 550,
          "rot": 180
        },
        "diagram": {
          "iconName": "default",
          "x1": 1100,
          "y1": 450,
          "x2": 1000,
          "y2": 550,
          "rot": 180
        }
      }
    }
  }
  "Initial phase of the cosine wave"
  parameter phi0::Real = 0
  "Offset of the cosine wave"
  parameter offset::Real = 0
  "Phase of the cosine wave"
  variable phi::Angle
relations
  initial phi = phi0
  der(phi) = 2 * π * frequency
  y = offset + amplitude * cos(phi)
metadata {
  "Dyad": {
    "labels": [{"label": "$(instance)", "x": 500, "y": 1100, "rot": 0}],
    "icons": {"default": "dyad://BlockComponents/CosineVariableFrequencyAndAmplitude.svg"}
  }
}
end
````

## Test Cases {#Test-Cases}

No test cases defined.

## Related {#Related}

* Examples

* Experiments

* Analyses

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