Simulink Difference Equation Implementation
Show older comments
I have a homework(a). My professor ask me for implement a discrete pid controller in difference equation form to matlab function. This function block should run as a discrete pid controller block in simulink model(b). When simulation began, the Matlab function block is executed once. Because of for loop an array occurs. Then that array signal goes the plant. And this is not usefull. During the simulation what i want is every iteration of for loop gives a value and that value must go to plant. But i could not do this. The same issue happened previous homework(c). I don't even know whether this way is proper or not.

4 Comments
Alvery
on 15 Dec 2020
Think of your function as only solving a single step - it takes the current input, applies the difference function just once to it, and then produces the next result. This leaves you with a challenge - in order to make the difference function work, you also need to know the previous value that was computed.
How do you do memory? you can either store it externally (i.e. not in Matlab code, but in a separate Simulink block) in a 1/Z block, or you can store it internally in the Matlab. Internal storage is easy if you cheat - using 'persistent' variables, but this hides the memory from the solver which potentially messes up backtracking behaviour if your solver setting uses it. The correct alternative is to use stored state.
Sezer Memis
on 16 Dec 2020
Walter Roberson
on 20 Dec 2020
If you are using a discrete system then use https://www.mathworks.com/help/simulink/slref/memory.html memory block.
If you are using a continuous system, then you would have difficulty implementing something like the trapazoid rule.
Paul
on 20 Dec 2020
Hard to say how to make the two equivalent without knowing exactly what's inside the block C(s)1.
Accepted Answer
More Answers (0)
Categories
Find more on Classical Control Design 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!




