example of non direct feed through using matlab function block

2 visualizzazioni (ultimi 30 giorni)
I'm using a matlab function block in a feedback loop and have an algebraic loop. Simulink can solve it but I need to run it on target hardware so I have to get rid of the algebraic loop. Based on this link
I think that I need to utilize non direct feedthrough on the matlab function block. I created a simplified example based on the link but I always get the following error when I disable direct feedthrough:
Output variables of MATLAB Function 'alg_loop_test/MATLAB Function2' cannot depend on input data 'cnt', because the 'Allow Direct Feedthrough' property has been disabled for this block.
I can't upload my model but I've attached a screenshot. It seems to me that you cannot use the inputs to the function in the calculation of the output of the function if you disable direct feed through. But how can you calculate the output if not by using the input? Clearly I'm missing the concept here and could use an example of a matlab function block that uses non direct feedthrough to explain.

Risposta accettata

Diego Kuratli
Diego Kuratli il 17 Ott 2019
By looking at the example provided in the doc link you shared, I think you are confusing/mixing inputs and persistent values.
If you want to use a persistent value (cnt), you should define
persistent cnt;
if isempty(cnt)
cnt = 1;
end
Attached a model which shows three different examples, one with non-direct feedthrough (the output value can already affect the input value at the same sample step), and two with direct feedthrough (unit delay is required to avoid algebric loop). In the two direct feedthrough examples, note how the order of the code can affect the results.
  4 Commenti
rs
rs il 17 Ott 2019
Thank you. Very helpful. I totally missed the concept of persistent variables.
So I'm noticing that the output of case1 and case3 are the same. Also if you take case1 but put a unit delay in the feedback you can get the same result as case2. So you can come to the same answer whether you use direct or non direct feedthrough as long as you take in to account the order of code and add a unit delay if needed. How then do you know when to choose direct vs non-direct feedthrough? Are there simulation pros and cons to each approach? I'm assuming direct feedthrough is more common as that's the default option?
Also, I noticed that I had started with some simulink models from 2015 that used the MATLAB Function Block. If I run the old model in 2019a I get an algebraic loop warning on the MATLAB Function Block. If I drag in a new MATLAB Function Block from the simulink library and copy the same code in to the new block I do not get the algebraic loop warning. So it also seems like there's something about the old block that is different compared to the new block.
Diego Kuratli
Diego Kuratli il 22 Ott 2019
You could double check the generated code to see differences. The best approach, probably depends on your application.
I can't comment much on pros and cons, or in differences between releases. You may want to contact technical support.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Simulink Functions in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by