pySimBlocks.blocks.operators.discrete_derivator

class pySimBlocks.blocks.operators.discrete_derivator.DiscreteDerivator(name: str, initial_output: TypeAliasForwardRef('ArrayLike') | None = None, sample_time: float | None = None)[source]

Bases: Block

Discrete-time differentiator block.

Estimates the derivative of the input using a backward finite difference:

y[k] = (u[k] - u[k-1]) / dt

The output shape is resolved from the first non-scalar input and then frozen. If an initial_output is provided it immediately fixes the shape. A scalar (1,1) input is broadcast to the frozen shape once it is known. The output is never None — a zero placeholder is used when no shape information is yet available.

initial_output

Initial output value, or None if not provided.

direct_feedthrough = True

True if outputs depend directly on inputs.

initialize(t0: float) None[source]

Set the previous-input state and prepare the initial output.

Parameters:

t0 – Initial simulation time in seconds.

output_update(t: float, dt: float) None[source]

Compute the finite-difference derivative and write it to the output port.

At the first call the output is held at initial_output (or zero if none was provided). Afterwards:

y = (u - u_prev) / dt

Parameters:
  • t – Current simulation time in seconds.

  • dt – Current time step in seconds.

state_update(t: float, dt: float) None[source]

Store the current input as the previous value for the next step.

Parameters:
  • t – Current simulation time in seconds.

  • dt – Current time step in seconds.