# 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)

### Adjusting the convergence rate

The speed of convergence of the estimation errors may be adjusted to a desired level using

the convergence rate / robustness factor. Double click the dierentiator block to open the

parameter window and modify the convergence rate / robustness factor. Using the same

settings of the Simulink R

solver and the dierentiator 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 dierentiator to converge reduces as seen by comparing Figure B with Figure D.

### Adjusting the robustness factor

Typically the input signal of the dierentiator is not exactly known and therefore it may

happen that the convergence signal of the dierentiator does not vanish using the default

settings of the dierentiator block. This phenomenon can be illustrated by changing the

input signal used in Section Obtaining the first 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 dierentiator block to vanish. The results of this experiment are shown in Figure 5.

(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 dierentiator depends on the step size

of the solver, see e.g. [4]. 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.

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

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

### Obtaining higher 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 dierentiator block.

Two second order dierentiators and one dierentiator of order ve are supplied with the

input signal used in Section Obtaining the first and second derivatives. However, the input signal of one second order dierentiator and the fith order dierentiator are corrupted by noise (using the Uniform Random Number block with maximum amplitude 0:0001 for a sample time of 0:001).

# Copyright and trademark notice

(c) 2015 The MathWorks, Inc. MATLAB and Simulink are registered trademarks of The

MathWorks, Inc. See www.mathworks.com/trademarks for a list of additional trademarks.

Other product or brand names may be trademarks or registered trademarks of their respec-

tive holders.

## References

[1] A. Levant. Robust exact dierentiation via sliding mode technique. Automatica, 34(3):379

384, 1998.

[2] A. Levant. Higher-order sliding modes, dierentiation and output-feedback control. In-

ternational Journal of Control, 76(9-10):924941, 2003.

[3] K. D. Listmann and Z. Zhao. A comparison of methods for higher-order numerical

dierentiation. In European Control Conference (ECC), pages 3676{3681, July 2013.

[4] M. Livne and A. Levant. Proper discretization of homogeneous dierentiators. Automat-

ica, 50(8):2007 2014, 2014.

[5] M. Mboup, C. Join, and M. Fliess. A revised look at numerical dierentiation with

an application to nonlinear feedback control. In Control Automation, 2007. MED '07.

Mediterranean Conference on, pages 1-6, June 2007.