Estimate transfer function from input output data
You already got the right idea, I don't know where you got stucked. Here is the code which solves your problem, I tested it, its works fine. Be aware that a simpler input probably gets you better results, that means for example a single step instead of a square wave.
% load your data (text file with your two columns)
load data.txt;
% sample index, reducing of input to get single step instead of square wave
x = 1:1:length(data);
data(x > 2900,:)=[];
x(x > 2900)=[];
% plot data
figure(1)
plot(x,data(:,1)); hold on
plot(x,data(:,2)); hold off
% prepare data for tftest, 100 is a random chosen sampling time
tfdata = iddata(data(:,1),data(:,2),100);
% estimate system, factor 5 -> number of poles (variable as desired)
sys = tfest(tfdata,5);
% plot step response (factor 5 comes from input)
figure(2)
step(5*sys)
Edit: the output for number of poles np=5:
sys =
From input "u1" to output "y1":
-3.337e-05 s^4 + 1.326e-07 s^3 + 1.639e-11 s^2 + 1.221e-14 s + 1.064e-19
----------------------------------------------------------------------------
s^5 + 0.005287 s^4 + 1.516e-06 s^3 + 4.517e-10 s^2 + 2.896e-14 s + 2.037e-19
Edit#2: in your previous question you were asking whether it would be better to use idfrd
or iddata
- but do you actually have the frequency response data? I actually don't think it should make a big difference, if you choose the number of poles high enough. Just try out what it's working better for you. The workaround is the same.
Related videos on Youtube
Matt1993
Updated on September 15, 2022Comments
-
Matt1993 over 1 year
I have a two-column matrix of data obtained from NI-DAQ. The first column is the output data of a motor-generator set (with driver) and the second column is the input data (square wave). I want to find the transfer function using
tfest
without Simulink. Is it possible? I have System Identification Toolbox.How can I attach a .mat file to this post? My data on gist https://gist.github.com/anonymous/6484844
-
Werner over 10 years+1 for the pain in the … to download data and help the someone else
-
Robert Seifert over 10 yearsthanks ;) I expected to have the same problem quite soon, so I could try it also now.
-
Matt1993 over 10 yearsI was expecting (np=1): sys = 19.71 / ( s + 7.8125 ). Why are the coefficients so small when using MATLAB tfest?
-
Robert Seifert over 10 yearsThats definitely not the transfer function based on your output data, it could be the transfer function of your input step data. You may mixed something up?
-
Matt1993 over 10 yearsThank you @thewaywewalk I will now design PI (or PID) controller to get zero-ss error for step input for this plant. You said you expect to have same problem quite soon - have you found any good blog or forum page to show how to design PI from sys?
-
Robert Seifert over 10 yearsthis is an issue of basic controlling every engineneer learns at university. You can find a thousand books about that. you could start with wikipedia