How do I remove initial peaks I get while differentiating a harmonic signal twice using simulink ?
6 views (last 30 days)
Show older comments
Utsav Shah on 20 Jun 2017
Commented: Atakan Zeybek on 17 Aug 2020
Please find the attached document for detailed description.
Swarooph on 22 Jun 2017
Thanks for the detailed explanation! There is a fundamental difference in how you are calculating the derivative in MATLAB and Simulink. The primary difference comes from the fact that, if X is a vector of length m, then Y = diff(X) returns a vector of length m-1. The elements of Y are the differences between adjacent elements of X. So the one less element is attributed to the fact that the first element doesn't have an adjacent one before it. This is why you don't see the initial peaks in MATLAB. You can check this using the following code snippet:
>> sineInput = sin(linspace(0,3*pi,1001));
>> invdt = 1/0.01;
>> der1 = invdt*diff(sineInput);
>> der2 = invdt*diff(der1);
However in Simulink, length of the signal at input and output of the derivative block should be equal. Because everything is time based. All signals (barring a very few exceptions) will carry a value at all times. This means even for the first instant, the previous value for all signals (initial condition) is assumed to be 0 (mostly, unless otherwise specified). So for e.g. at the first instant:
sineInput = 0.01
derivative1 = (sineInput - sineInput_prev)/dt = (0.01-0)/0.01 = 1
derivative2 = (derivative1 - derivative1_prev)/dt = (1-0)/0.01 = 100 <------ This is the peak that you see
That being said, the following information from the documentation for the derivative block might be useful: Because of the derivative block sensitivities, structure your models to use integrators (such as Integrator blocks) instead of Derivative blocks. Integrator blocks have states that allow solvers to adjust step size and improve accuracy of the simulation. See Circuit Model for an example of choosing the best-form mathematical model to avoid using Derivative blocks in your models.
Atakan Zeybek on 17 Aug 2020
I am also in trouble with the same issue. Is there anybody have the solution?
Find more on Signal Attributes and Indexing in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!