MATLAB: Does the derivative block not produce results that I expect in Simulink 7.6 (R2010b)

simulink

Using Simulink, I have the following block diagram configuration :
sine —-> du/dt —-> du/dt —–> scope1
|--------------------------------> scope
NOTE: The results in scope1 should be, u''=-sin.
See test3.mdl for a demo of this.

Best Answer

What you are seeing is a consequence of the way the derivative block is implemented. This block performs the MATLAB equivalent of diff(). In theory, once you have a sine, you can integrate or take the derivative and you should always get back a sinusoid + some offset. The output data shows that they are all sinewaves, but d2/dt^2 has a spike at the input. If you send the 3 outputs to To Workspace blocks, run it, and plot(t,diff(D(u)) where D is d/dt. (set t(101) = []), the spike is there as well. Why the spike? The difference between the first two values of the generated sine is a very small number.
NOTE: Our simulation algorithm is EULER
[yout(1:10) yout1(1:10) yout2(1:10)]
ans =
0 0 0
0.0628 6.2791 627.9052 <=== NOTE: [ 100 x yout1(2)]!
0.1253 6.2543 -2.4781
0.1874 6.2048 -4.9463
0.2487 6.1309 -7.3951
0.3090 6.0327 -9.8147
0.3681 5.9108 -12.1955
0.4258 5.7655 -14.5282
0.4818 5.5974 -16.8036
0.5358 5.4073 -19.0126
Now what MATLAB sees as the diff of the first two inputs:
ans =
|---------------------- 2 orders of magnitude (100x) larger than the |
rest...
==>6.2791 0.0628
-0.0248 0.0625
-0.0495 0.0620
-0.0740 0.0613
-0.0981 0.0603
-0.1220 0.0591
-0.1453 0.0577
-0.1680 0.0560
-0.1901 0.0541
-0.2115 0.0520
If you plot the diff() of the signals, you'll see basically the same thing as the output of the simulation. The bottom line here is that the derivative block does not get a true derivative, especially when the order of the integration is varying (not true for the above discrete model, there are no continuous states). The online help for the block tells you how the derivative is calculated.
NOTE: This may cause problems when linearizing a model. Type "extrlin" at the MATLAB prompt for derivative blocks to be used when linearizing a model via LINMOD.