Fitting complex function to measurement values

3 vues (au cours des 30 derniers jours)
Nico Wulf
Nico Wulf le 24 Mai 2020
I try to fit a complex function to previous measured data in order to receive the general parameters of that function.
First i read in the data which is stored in 3 vectors. The data includes the frequency, magnitude and phase of an impendence measurement.
I tried to use lsqnonlin to fit the magnitude values with the absolute function of the original function:
%original funtion: impedence = ((1i.*(2*pi*frequency)*x(1))/((-((2*pi*frequency)).^2)*x(1)*x(2)+1i*(2*pi*frequency)*(x(1)/x(3))+1))+((1i*(2*pi*frequency)*x(4)*x(5))/(1i*(2*pi*frequency)*x(4)+x(5)))+1i*(2*pi*frequency)*x(6)+x(7)
% data fitting
%absolute-value fitting:
fun1=@(x) ((sqrt(((x(6)*x(4)*x(1)*x(2)).*w.^4 + (-x(1)*x(4)-x(4)*x(5)*(x(1)/x(3))-x(1)*x(2)*x(5)*x(7)-x(4)*x(7)*(x(1)/x(3))-x(6)*x(5)*(x(1)/x(3))-x(6)*x(4)).*w.^2 + (x(5)*x(7)).*w.^0).^2+(((-x(4)*x(5)*x(1)*x(2)-x(4)*x(1)*x(2)*x(7)-x(6)*x(1)*x(2)*x(5)-x(6)*x(4)*(x(1)/x(3))).*w.^3 + (x(1)*x(5)+x(4)*x(5)+x(5)*x(7)*x(1)/x(3)+x(4)*x(7)+x(6)*x(5)).*w.^1)).^2) -sqrt(((-x(1)*x(2)*x(5)-x(4)*(x(1)/x(3))).*w.^2 + (x(5)).*w.^0).^2+ (((-x(4)*x(1)*x(2)).*w.^3 + ((x(1)/x(3))*x(5)+x(4)).*w.^1)).^2)))-magnitude;
x0 = 1e-5*[1 1 1 1 1 1 1];
lb = [0 0 0 0 0 0 0];
ub = [10 10 10 10 10 10 10];
x=lsqnonlin(fun1,x0,lb,ub);
If i now try to plot the fitted function (yellow) over the original function (blue), the peak is not fitted. It seems as the phase information (red) is missing (as we only fitted the absolute value).
magnitude_plot = sqrt(((x(6)*x(4)*x(1)*x(2)).*w.^4 + (-x(1)*x(4)-x(4)*x(5)*(x(1)/x(3))-x(1)*x(2)*x(5)*x(7)-x(4)*x(7)*(x(1)/x(3))-x(6)*x(5)*(x(1)/x(3))-x(6)*x(4)).*w.^2 + (x(5)*x(7)).*w.^0).^2+(((-x(4)*x(5)*x(1)*x(2)-x(4)*x(1)*x(2)*x(7)-x(6)*x(1)*x(2)*x(5)-x(6)*x(4)*(x(1)/x(3))).*w.^3 + (x(1)*x(5)+x(4)*x(5)+x(5)*x(7)*x(1)/x(3)+x(4)*x(7)+x(6)*x(5)).*w.^1)).^2) -sqrt(((-x(1)*x(2)*x(5)-x(4)*(x(1)/x(3))).*w.^2 + (x(5)).*w.^0).^2+ (((-x(4)*x(1)*x(2)).*w.^3 + ((x(1)/x(3))*x(5)+x(4)).*w.^1)).^2);
semilogx(frequency,magnitude,frequency,phase,frequency,magnitude_plot);
The parameters are quite in range of they are expected, but still the peak is missing. Do you have any ideas how to implement the phase information into the fitting process?
Thanks in advance.
  4 commentaires
Nico Wulf
Nico Wulf le 24 Mai 2020
Hello Alex,
this is the measured data.
Best regards!
Alex Sha
Alex Sha le 25 Mai 2020
Hi, Nico, the problem I think is the range limition of each parameter is not reasonable, If relax these limits, the result below could be get:
Root of Mean Square Error (RMSE): 15.6791611038752
Sum of Squared Residual: 151435.033239503
Correlation Coef. (R): 0.912166949471863
R-Square: 0.832048543708804
Parameter Best Estimate
-------------------- -------------
x1 0.351560076838176
x2 0.000132413993963871
x3 96.3105553028458
x4 0.00693121568993447
x5 83.4472887074373
x6 0.00056654718799207
x7 -7.13280689615331

Connectez-vous pour commenter.

Réponses (1)

Rajiv Singh
Rajiv Singh le 10 Juin 2020
Let X be your data matrix.
[~,I]=unique(X(:,1),'stable');
h=X(I,2).*exp(1i*X(I,3)/180*pi);
w=X(I,1)*2*pi;
G=idfrd(h,w,'Ts',0);
m=tfest(G,6)
bode(G,m)

Community Treasure Hunt

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

Start Hunting!

Translated by