How do I remove initial peaks I get while differentiating a harmonic signal twice using simulink ?
6 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Please find the attached document for detailed description.
0 comentarios
Respuestas (1)
Swarooph
el 22 de Jun. de 2017
Hello Utsav,
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));
>> size(sineInput)
ans =
1 1001
>> invdt = 1/0.01;
>> der1 = invdt*diff(sineInput);
>> size(der1)
ans =
1 1000
>> der2 = invdt*diff(der1);
>> size(der2)
ans =
1 999
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.
2 comentarios
Vaidyanathan Narayanan
el 24 de Jun. de 2017
Hi Swarooph,
Thank you for the detailed explanation.
Actually I was aware about the reasons of peak occurring in simulink and not occurring in matlab.
Can you also suggest a way to include double-differentiation block(or something similar) in simulink and avoid the first two data points(peak values) from going into my subsystem block ?
Atakan Zeybek
el 17 de Ag. de 2020
Hi Vaidyanathan,
I am also in trouble with the same issue. Is there anybody have the solution?
Ver también
Categorías
Más información sobre Sources en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!