Discrete Derivative block (Simulink) behaves differently than expected

9 次查看(过去 30 天)
I'm discretizing a known-working continuous system model that includes x state outputs from the simulink Varying State Space block, but the discrete derivative block is not behaving as expected.
The SS model is a basic 2nd order plant, and I'm just giving a step input for this post for debugging/illustration purposes:
zpk(plant) =
From input "u" to output "theta":
3.1978e+05
-----------------------
(s^2 + 360s + 3.198e05)
The rate transition block is to 100 kHz (1e-5 s)
The State Space block outputs are:
y: position, and
x: x1 is position, and x2 is velocity.
I'm comparing the x (state vector) outputs to a discrete derivative on y, since the discrete derivative of position should be velocity.
I expected that they would match, but I'm seeing the discrete derivative behave very differently than expected: see red step-wise line, which is "y discDeriv", and does not seem to touch either sloped line (ie much delayed).
The other outputs "x2 @rate" and "dy/dt @ rate" match, but "y discDeriv" does not.
Why is Simulink Discrete Derivative not outputting the same result as the other output paths, specifically the x2 vel state ("x2@rate") output?
What is the Discrete Derivative block actually doing? The documentation seemed sparse, and what was there, seemed (to my interpretation) to support that it should behave the same as the other methods i tried.

回答(1 个)

Paul
Paul 2024-2-3
Hi John,
How did you get the yellow colors on the rate transition blocks on the signals coming out of those? If you turned on Sample Time Colors, I wonder why the output of the Discrete Derivative block isn't red.
Anyway, I'm pretty sure what's happening is that the solver is running a at higher rate than 1e-5. The discrete derivative block is updating at a sample time of 1e-5 secs, and at each sample time computes
y_discderiv[n] = (y@rate[n] - y@rate[n-1])/1e-5, where the samples of y@rate are taken at 1e-5.
But the continuous signal y is updated faster (is my assertion), and the output of the Derivative block is essentially
dy/dt = (y(t) - y(tprev))/(t - tprev)
where t is current sim time and tprev is the time of the last major step. If t - tprev < 1e-5 (as I expect), then dy/dt won't match y_discderiv (at the 1e-5 sample points) because they are computed based on different quantities.
If you want them to match, you can change your solver settings to fixed-step with a step size of 1e-5. But there is no guarantee that a step size of 1e-5 is small enough to accurately simulate the continuous plant dynamics (you'd have to check that), keeping in mind that whatever solver settings you have are already using a smaller time step.
  6 个评论
Paul
Paul 2024-2-6
The timing text is there, that's the "Cont" and "D2" symbols. The legend, as strange as it looks, indicates there's another discrete signal in the model at Sample Time D1 = 1e-7. Where's that in the model?
John
John 2024-2-6
编辑:John 2024-2-6
Ah, that's the fixed-step solver time. It goes away if i change back to variable-step.
Not sure why the Disc Deriv block isn't yellow, but it shows D1 so it looks okay (perhaps just a bug)

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Sources 的更多信息

产品


版本

R2022b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by