Problem with persistent variables within embedded function
Mostrar comentarios más antiguos
Hi,
I am currently implementing a second order lowpass filter as an embedded function and can be found as attachment. I tested it against a native simulink block employng the same state-space representation and the results are exactly, so the implementation itself should be correct.
My issue is the following: let's say that I have three signals that I intend to filter, hence I would be calling the following snippet:
sig1 = SecondOrderLowpassFilterTustin(u(1),fn,dn,Ts);
sig2 = SecondOrderLowpassFilterTustin(u(2),fn,dn,Ts);
sig3 = SecondOrderLowpassFilterTustin(u(3),fn,dn,Ts);
Unfortunately, this does not work as expected, and I assume that happen because of the persistent xs variable within the function. On the other hand, if let's say only u(1) was to be filtered, sig1 would be representing the proper results.
How can I make the function safe, so that the persistent variable are reset every time I call the function?
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Event Functions en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!