Search code examples
matlabdebuggingsignalssimulink

why if I put a filter on an output I modify the source signal? is this a simulink bug?


I know it sounds strange and that's a bad way to write a question,but let me show you this odd behavior.

enter image description here

as you can see this signal, r5, is nice and clean. exactly what I expected from my simulation.

now look at this: enter image description here

this is EXACTLY the same simulation,the only difference is that the filter is now not connected. I tried for hours to find a reason,but it seems like a bug. This is my file, you can test it yourself disconnecting the filter.

----edited.

Tried it with simulink 2014 and on friend's 2013,on two different computers...if Someone can test it on 2015 it would be great.

(attaching the filter to any other r,r1-r4 included ''fixes'' the noise (on ALL r1-r8),I tried putting it on other signals but the noise won't go away).

the expected result is exactly the smooth one, this file showed to be quite robust on other simulations (so I guess the math inside the blocks is good) and this case happens only with one of the two''link number'' (one input on the top left) set to 4,even if a small noise appears with one ''link number'' set to 3.

thanks in advance for any help.


Solution

  • It seems to me that the only thing the filter could affect is the time step used in the integration, assuming you are using a dynamic time step (which is the default). So, my guess is that (if this is not a bug) your system is numerically unstable/chaotic. It could also be related to noise, caused by differentiation. Differentiating noise over a smaller time step mostly makes things even worse.

    Solvers such as ode23 and ode45 use a dynamic time step. ode23 compares a second and third order integration and selects the third one if the difference between the two is not too big. If the difference is too big, it does another calculation with a smaller timestep. ode45 does the same with a fourth and fifth order calculation, more accurate, but more sensitive. Instabilities can occur if a smaller time step makes things worse, which could occur if you differentiate noise.

    To overcome the problem, try using a fixed time step, change your precision/solver, or better: avoid differentiation, use some type of state estimator to obtain derivatives or calculate analytically.