write Simulink block diagram to source code
4 views (last 30 days)
Pravarthana P on 14 Feb 2022
Edited: Pravarthana P on 14 Feb 2022
Hi Olivia, it can be understood from the figure and your query that you are trying to write MATLAB code equivalent to the closed loop mentioned above.
To begin with try reducing the first block to have a common denominator. Then it will be easy to code the transfer function in MATLAB using the tf() function using the following link Transfer function.
For example, I am assuming first block as G1 and second block as G2:
G1 can be re-written as:
This can be written using tf()as:
G1 = tf([ ],[ 0 0]).
G2 can also the reduced in the same manner. Assign
Next step will be to convert the closed loop to code, you can find information related to closed loop in the following link: Using FEEDBACK to Close Feedback Loops - MATLAB & Simulink Example (mathworks.com)
Try using the feedback() function, and the appropriate G and K values (in your example K=1).
To help with the process try the following documentations: