LSQCURVEFIT for transfer function frequency response magnitude and phase curve fitting

3 views (last 30 days)
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
Matt J
Matt J on 26 Aug 2019
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?

Sign in to comment.

Answers (0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!