Script to represent constant offset in scaling of data
Ältere Kommentare anzeigen
Hello,
I have the attached simulink model which appears to be working as I need it to. The idea is to scale my SP input from engineering units to 0-100%, which is how the controller operates. That way, my P/I/D settings are directly identical to those entered into the controller, and I can align the matlab data with the controller data.
How would I enter this into a simple matlab script?
K = 100/(MaxEU-MinEU)
C = 100*MinEU/(MaxEU-MinEU)
It correctly multiplies the SP input value by the gain K, then after the gain block adds an offset which is completely independent of the SP input. I am struggling to deal with this 'extra constant input' in a matlab script.
My goal is to have a SISO transfer function between the step input and the output of the first summing junction, that I can easily integrate into the rest of the model with series/parallel connections.
What does not work (as far as I can tell) is EUSP = tf(100/(MaxEU-MinEU) - 100*MinEU/(MaxEU-MinEU))
since it applies a static gain to the step input, including the offset term. With or without the tf.
Perhaps I need to use sumblk and directly assign inputs/outputs? Still a little confused how to set that constant input for the offset term.
8 Kommentare
Mathieu NOE
am 13 Mai 2024
hello
I am not sure to understand what is your problem
Are MinEU, MaxEU constants ? or do they evolve with time ?
Kurt
am 13 Mai 2024
Mathieu NOE
am 13 Mai 2024
seems to me you give the answer yourself :
in your matlab (initialization script) you define
K = 100/(MaxEU-MinEU)
C = 100*MinEU/(MaxEU-MinEU)
and you use K and C as parameters names in the corresponding simulink blocks, exactly as in your picture, and you should be good
Kurt
am 13 Mai 2024
Kurt
am 13 Mai 2024
hello again
I could not guess that you wanted to move from simulink to plain matlab
yes your code seems to work fine , but why not make it even simpler ? why create tf objects for simple operators like gains and offset ?
alternative code :
MaxEU = 700;
MinEU = -300;
% EU SCALING
gain = (100/(MaxEU-MinEU));
offset = (100*MinEU/(MaxEU-MinEU));
% OPEN LOOP OF PLANT
duration = 3;
StepMag = 500; % THIS SHOULD SCALE OUT TO 80%
Fs = 100;
dt = 1/Fs;
t = (0:dt:duration)';
t_step = 0.1;
SP = StepMag*(t>=t_step); % input step
SP_normalized = SP*gain - offset; % output (normalized) step
figure('f', '1', 'Name', 'Step Response of Closed Loop')
plot(t,SP_normalized);
Kurt
am 14 Mai 2024
Mathieu NOE
am 14 Mai 2024
yes you're right , I read a bit too fast your first post - now it's obvious
I supposed indeed that this was just a small portion from a larger project , so I understand the general use of tf objects as you now describe more what the intention is.
seems to me you're on the right track to achieve your goals , I have no further comment so far
when I started matlab 30+ years ago, there where not so many advanced tools and functions to study open and closed loop systems.
so good luck for the future !
Antworten (0)
Kategorien
Mehr zu Model Interconnection finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
