LSQCURVEFIT for transfer function frequency response magnitude and phase curve fitting

3 次查看(过去 30 天)
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 个评论
Matt J
Matt J 2019-8-26
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?

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by