Estimate transfer function from input output data

天涯浪子 提交于 2019-12-03 03:33:13
thewaywewalk

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!