The block Derivative approximates the derivative of the input signal over the simulation time . The true value of the derivative is approximated by the relation , where is the increment of the input signal and is the change in time since the previous (main) calculation step.
This block takes one input signal and produces one output signal. The initial value of the output signal is zero.
The exact relationship between the input and output of the block:
where
- is the current modelling time;
- the calculation time of the previous value, which coincides with the time of the last main time step.
The output signal of the block Derivative can be sensitive to the dynamics of the whole model. The accuracy of the output signal depends on the step size of the model calculation. Smaller steps result in a smoother and more accurate curve at the block output. However, unlike blocks that have continuous states, the solver does not perform smaller steps when the input to that block changes rapidly. Depending on the dynamics of the control signal and the model, the block output may contain unexpected fluctuations. These fluctuations are primarily due to the error of the output signal and the step size of the solver.
Because of these features, structure your models to use integrators (e.g., blocks Integrator) instead of blocks Derivative. The Integrator blocks have states that allow the solver to adjust the step size and increase the accuracy of the simulation.
If you need to use the Derivative block with a variable step size solver, set the maximum step size of the solver to a value such that the Derivative block can do the calculations with sufficient accuracy. To determine this value, you may need to run the simulation several times with different solver settings.
If the input to this block represents a discrete signal, the continuous derivative of the input signal produces a pulse as the value of the input signal changes. Otherwise, it is equal to 0. Alternatively, you can determine the discrete derivative of a discrete signal using the difference of the last two values of the signal:
Taking the -transform of this equation results in:
The Discrete Derivative block models this behaviour. Use this block instead of the Derivative block to approximate the time derivative of a discrete signal.