Skip to content
Gain.md

Gain

Multiplies input signal by a constant gain factor.

Multiplies the input signal by a constant parameter k. The relationship between the input u and output y is simply y = k*u, where k is the gain factor. This block is useful for scaling signals or converting between different units.

This component extends from SISO

Usage

Gain(k)

Parameters:

NameDescriptionUnitsDefault value
kConstant gain factor that multiplies the input signal

Connectors

  • u - This connector represents a real signal as an input to a component (RealInput)

  • y - This connector represents a real signal as an output from a component (RealOutput)

Behavior

y(t)=ku(t)

Source

dyad
# Multiplies input signal by a constant gain factor.
#
# Multiplies the input signal by a constant parameter `k`. The relationship
# between the input u and output y is simply y = k*u, where `k` is the gain factor. This block is useful
# for scaling signals or converting between different units.
component Gain
  extends SISO
  # Constant gain factor that multiplies the input signal
  parameter k::Real
relations
  y = k*u
metadata {
  "Dyad": {
    "labels": [{"label": "k=$(k)", "x": 500, "y": 500, "rot": 0}],
    "icons": {"default": "dyad://BlockComponents/Gain.svg"}
  }
}
end
Flattened Source
dyad
# Multiplies input signal by a constant gain factor.
#
# Multiplies the input signal by a constant parameter `k`. The relationship
# between the input u and output y is simply y = k*u, where `k` is the gain factor. This block is useful
# for scaling signals or converting between different units.
component Gain
  # Input signal port
  u = RealInput() [{
    "Dyad": {
      "placement": {"icon": {"iconName": "input", "x1": -50, "y1": 450, "x2": 50, "y2": 550}}
    }
  }]
  # Output signal port
  y = RealOutput() [{
    "Dyad": {
      "placement": {"icon": {"iconName": "output", "x1": 950, "y1": 450, "x2": 1050, "y2": 550}}
    }
  }]
  # Constant gain factor that multiplies the input signal
  parameter k::Real
relations
  y = k*u
metadata {
  "Dyad": {
    "labels": [{"label": "k=$(k)", "x": 500, "y": 500, "rot": 0}],
    "icons": {"default": "dyad://BlockComponents/Gain.svg"}
  }
}
end


Test Cases

This is setup code, that must be run before each test case.

julia
using BlockComponents
using ModelingToolkit, OrdinaryDiffEqDefault
using Plots
using CSV, DataFrames

snapshotsdir = joinpath(dirname(dirname(pathof(BlockComponents))), "test", "snapshots")
"/home/actions-runner-10/.julia/packages/BlockComponents/77kIK/test/snapshots"
  • Examples

  • Experiments

  • Analyses