6

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

Robert Seifert
  • 25,078
  • 11
  • 68
  • 113
Matt1993
  • 105
  • 1
  • 3
  • 8

1 Answers1

7

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.

Buck Thorn
  • 5,024
  • 2
  • 17
  • 27
Robert Seifert
  • 25,078
  • 11
  • 68
  • 113
  • 1
    +1 for the pain in the … to download data and help the someone else – Werner Sep 08 '13 at 20:18
  • 1
    thanks ;) I expected to have the same problem quite soon, so I could try it also now. – Robert Seifert Sep 08 '13 at 20:21
  • I was expecting (np=1): sys = 19.71 / ( s + 7.8125 ). Why are the coefficients so small when using MATLAB tfest? – Matt1993 Sep 09 '13 at 03:04
  • Thats 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? – Robert Seifert Sep 09 '13 at 06:58
  • Thank 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? – Matt1993 Sep 09 '13 at 12:51
  • this is an issue of basic controlling every engineneer learns at university. You can find a thousand books about that. you could start with [wikipedia](http://en.wikipedia.org/wiki/PID_controller) – Robert Seifert Sep 09 '13 at 13:08