MATLAB Answers

0

LSQCURVEFIT for transfer function frequency response magnitude and phase curve fitting

Asked by PRAKASH G on 24 Aug 2019 at 8:21
Latest activity Commented on by PRAKASH G on 30 Aug 2019 at 5:47
Hi all, can somebody please help me to find out transfer function time constants from LSQCURVEFIT function for identifying the transfer function through curvefitting the data available.
  • Avaiable data frequency points (xdata)
  • Magnitude and phase data(ydata)
tau1Omega to tau6Omega are time constants required to be find out.
current code is attached below, i'm encountering error
----------------------------------------------------------------------------------------------
Error using lsqcurvefit (line 251)
Function value and YDATA sizes are not equal.
Error in Untitled (line 32)
e = lsqcurvefit(ObjFun01,var01,xdata,ydata2,lb,ub);
-------------------------------------------------------------------------------------------------
cnst11 = 0.002777;
lb = [0 0 0 0 0 0 0 0];
ub = [10 10 10 10 10 10 10 10];
var01 = [0 0 0 0 0 0 0 0];
xdata = load('xdata.txt');
ydata = load('ydata_in_magnitude_phase_form.txt');
ydata1 = ydata(1:1:end,:);
ydata1(:,1) = ydata(:,1) ; %Load frequency
ydata1(:,2) = ydata(:,2) ; %Load magnitude
ydata1(:,3) = ydata(:,3) ; %Load frequency
ydata1(:,4) = ydata(:,4) ; %Load phase
ydata1(:,5) = 1; % weights
ydata2 = ydata1(:,2).*exp(1i.*ydata1(:,4)); %converting to complex number form
tau1Omga = var01(1,1) ;
tau2Omga = var01(1,2) ;
tau3Omga = var01(1,3) ;
tau4Omga = var01(1,4) ;
tau5Omga = var01(1,5) ;
tau6Omga = var01(1,6) ;
tau7Omga = var01(1,7) ;
tau8Omga = var01(1,8) ;
ObjFun01 = @(x,xdata)cnst11*((1+ tau1Omga*1i*x).*(1+ tau2Omga*1i*x).*(1+ tau3Omga*1i*x))./ ( (1+ tau4Omga*1i*x).*(1+ tau5Omga*1i*x).*(1+ tau6Omga*1i*x) );
e = lsqcurvefit(ObjFun01,var01,xdata,ydata2,lb,ub);
any help in this regard would be greatly appreciated.

  7 Comments

Dear Matt,
Thanks for your comments.
Actually i need real roots (time constants for the transfer function mentioned)
Moreover my code results are not mathing with the curve, when plotted.
Am i making anything wrong...?
Your ydata and model function have complex numbers. Did you read the documentation link I gave you to see why that might be a problem?
Checked complex numbers, there is no issue.

Sign in to comment.

0 Answers