# Differentiation of a sinusoidal signal

In the subsequent sections a simple example demonstrating the use of the differentiator block is given.

### Obtaining the first and second derivatives

This example shows how to set up a Simulink simulation differentiating the sinusoidal signal given by sin(t+pi/2). To do so, a block diagram as depicted in the following Figure is implemented.

The following setting of the differentiator is used:

• differentiator order: 2
• convergence rate / robustness factor: 1
• step size: -1

The following Simulink solver options are used (to enter the window in order to modify this setting use the hot key Crtl+E):

• Stop time: 20
• Type: Fixed-step
• Solver: ode3 (Bogacki-Shampine)
• Fixed-step size (fundamental sample time): 0.001

All the remaining Simulink options are set to their default values.The results achieved by this simulation are shown in the following figure.

(A)  Evolution of the estimated first and second derivative  (Simulation results with convergence rate/ robustness factor:1)

(B)  Behaviour of the convergence output of the differentiator (Simulation results with convergence rate/ robustness factor: 1)

(C)  Evolution of the estimated first and second derivative   (Simulation results with convergence rate/ robustness

factor: 2)

(D)  Behaviour of the convergence output of the differentiator (Simulation results with convergence rate/ robustness factor: 2)

The speed of convergence of the estimation errors may be adjusted to a desired level using
the convergence rate / robustness factor. Double click the di erentiator block to open the
parameter window and modify the convergence rate / robustness factor. Using the same
solver and the di erentiator as in Section  Obtaining the rst and second derivatives and setting the
convergence rate / robustness factor to 2 yields the simulation results shown in Figure 4.
Note that by increasing the convergence rate, the absolute value of the estimated derivatives
during the initial transient phase will typically reach higher values as seen by comparing
Figure A with Figure C. However, by increasing the convergence rate, the time required
by the di erentiator to converge reduces as seen by comparing Figure B with Figure D.



Typically the input signal of the di erentiator is not exactly known and therefore it may
happen that the convergence signal of the di erentiator does not vanish using the default
settings of the di erentiator block. This phenomenon can be illustrated by changing the
input signal used in Section Obtaining the fi rst and second derivatives from sin(t +pi =2) to sin(2t +pi =2) so that the frequency of the input signal is doubled. Increasing the robustness factor / convergence rate parameter from 1 to 2 causes the convergence output signal of the di erentiator block to vanish. The results of this experiment are shown in Figure 5. Figure 5: Simulation results with convergence rate / robustness factor: 2, the applied input signal is sin(2t + pi =2).

(A) Evolution of the estimated first and second derivative.

(B) Behaviour of the convergence output of the differentiator.

### Impact of the selected solver

It is well known that the accuracy achieved by the di erentiator depends on the step size
of the solver, see e.g. . This example demonstrates this behaviour. The same Simulink
block diagram as used in Section Obtaining thef first and second derivatives is used in this section. However, the solver settings
used are now

•  Stop time: 20
•  Type: Variable-step
•  Solver: ode45 (Dormand-Prince)
•  Max. step size: auto
•  Min. step size: auto
•  Initial step size: auto

The simulation results achieved by this setting is shown in Figure 6. Figure 6: Simulation results: A Variable-step solver is used. The achieved accuracy is re- duced drastically when compared to the results from Section Obtaining the first and second derivatives.

(A) Evolution of the estimated first and second derivative.
(B) Behaviour of the convergence output of the differentiator.

### Obtaining higher derivatives Figure 7 : Simulation results and differentiator parameter settings used to obtain the first five derivatives of the sinusoidal input signal also used in Section Obtaining the first and second derivatives .

(A) Evolution of the first five derivatives.

(B) parameters used to obtain derivatives up to order five.

### Impact of noise

In order to demonstrate the possibility of reducing the impact of noise, the block diagram
shown in Figure 9 is implemented. It consists of three instances of the di erentiator block.
Two second order di erentiators and one di erentiator of order ve are supplied with the
input signal used in Section Obtaining the fi rst and second derivatives. However, the input signal of one second order di erentiator and the fith order di erentiator are corrupted by noise (using the Uniform Random Number block with maximum amplitude 0:0001 for a sample time of 0:001). Figure 9: Block diagram implemented showing the reduction in the impact of noise using higher order differentiators Figure 10: Comparison of the second derivatives obtained by second order differentiators and a fifth order differentiator. The result achieved for the second derivative by the fifth order differentiator is much closer to the result achieved by the second order differentiator which has the noise-free input signal.

(c) 2015 The MathWorks, Inc. MATLAB and Simulink are registered trademarks of The
Other product or brand names may be trademarks or registered trademarks of their respec-
tive holders.

## References

 A. Levant. Robust exact di erentiation via sliding mode technique. Automatica, 34(3):379
384, 1998.
 A. Levant. Higher-order sliding modes, di erentiation and output-feedback control. In-
ternational Journal of Control, 76(9-10):924941, 2003.
 K. D. Listmann and Z. Zhao. A comparison of methods for higher-order numerical
di erentiation. In European Control Conference (ECC), pages 3676{3681, July 2013.
 M. Livne and A. Levant. Proper discretization of homogeneous di erentiators. Automat-
ica, 50(8):2007  2014, 2014.
 M. Mboup, C. Join, and M. Fliess. A revised look at numerical di erentiation with
an application to nonlinear feedback control. In Control Automation, 2007. MED '07.
Mediterranean Conference on, pages 1-6, June 2007.