# Transfer Function Block

## Description

The Transfer Function block implements linear time-invariant (LTI) systems described in the Laplace domain. It takes a transfer function H(s) = num(s)/den(s) and simulates the system's response to input signals using numerical integration methods.

The block accepts numerator and denominator polynomials as text strings (e.g., "1" and "s+1" for a first-order lag) and internally converts them to a state-space representation for efficient computation.

## Mathematical Model

```
H(s) = num(s) / den(s)
```

Where:
- `num(s)` = numerator polynomial coefficients
- `den(s)` = denominator polynomial coefficients
- `s` = Laplace variable

The block uses state-space realization (controllable canonical form) for numerical simulation.

## Parameters

### numerator

Polynomial coefficients for the numerator. Examples: `1`, `s + 1`, `s^2 + 2s + 1`.

### denominator

Polynomial coefficients for the denominator. Examples: `s + 1`, `s^2 + 10s + 100`.

### initialCondition

Initial system state (output value at t=0).

## Examples

### Low-pass Filter

First-order system with 1 sec time constant:
```
Step (finalValue: 1) → TransferFunction (num: "1", den: "s+1") → Scope
```

### Damped Oscillator

Second-order system with damping:
```
Impulse → TransferFunction (num: "100", den: "s^2+10s+100") → Scope
```

## Stability Conditions (Forward Euler)

The Rust implementation uses Forward Euler integration. This method has a limited stability region: only the left half of the complex plane within a circle of radius 1/Δt centered at (-1/Δt, 0).

**Practical implications:**
- **All eigenvalues (poles) must satisfy**: |1 + λ·Δt| < 1
- **For a real pole at -a**: requires Δt < 2/a
- **For a first-order system 1/(s+1)**: Δt < 2.0 for stability
- **For faster poles** (e.g., s+100): much smaller Δt needed (Δt < 0.02)
- **For oscillatory systems**: the constraint is more restrictive

**Rule of thumb**: Use Δt ≤ 1/(5 × fastest_pole_magnitude) for both stability and accuracy.

If the simulation becomes unstable (output grows without bound), reduce the sample time.

## TypeScript Limitation

The TypeScript fallback executor only supports first-order systems (denominator order = 1). For higher-order systems, it throws an error directing the user to the Rust/WASM engine. The Rust implementation handles all orders correctly.

## Remarks

- **State-Space Realization**: Internally converted to controllable canonical form for numerically stable integration
- **Polynomial Syntax**: Use `s` for Laplace variable, `s^2` for powers. Supports negative coefficients (e.g., `s^2 - 2s + 1`)
- **Order Restriction**: The numerator degree must be less than or equal to the denominator degree (proper transfer function)
- **Time-Step Sensitivity**: Higher order systems require smaller simulation time steps for accuracy and stability

## See Also

- **Integrator**: Simple integration (1/s)
- **StateSpace**: Direct state-space system implementation
- **PIDController**: Proportional-Integral-Derivative controller
- **ZeroPole**: Pole-zero form of transfer functions
