How to generate model output given a transfer function and input signal

3 views (last 30 days)
Hello all,
I have used the systemIdentification toolbox to generate a transfer function from u to y as:
0.002879 s + 2.306e-05
----------------------------
s^2 + 0.003373 s + 0.0002227
Checking the box "Output model" gives an output y given the input vector as:
My question is how can I generate this output in code?
Thank you in advance!

Accepted Answer

Star Strider
Star Strider on 21 Feb 2023
If you have the time vector and the matching input vector, use the lsim function to generate the output, however a more robust approach would be to use the compare function, specifically as described in Obtain Initial Conditions.
  2 Comments
NiclasJ
NiclasJ on 26 Feb 2023
Edited: NiclasJ on 26 Feb 2023
Thank you for your answer. I have tried using lsim because this seems to do what I want. For this case, I wrote:
y = lsim(tf, u, T);
where T is given by T = 1:length(u) since the update step in the inputed iddata is set to 1. Plotting y gives
which is not the same as the result given in the previous plot. It seems that I am missing some important step here?
Star Strider
Star Strider on 26 Feb 2023
My guess is that you are missing the initial conditions vector. This is one reason that using state space representation is preferable to other representations, especially since the ssest function will return the initial conditions if you request it. See the documentation section on Estimate Initial States as Independent Parameters for details.
The compare function incorporates it automatically if requested, the reason I suggested it.

Sign in to comment.

More Answers (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov on 20 Feb 2023
use tfestimate() - here is documentation how to use it:

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!