Fitting complex function to measurement values

1 回表示 (過去 30 日間)
Nico Wulf
Nico Wulf 2020 年 5 月 24 日
回答済み: Rajiv Singh 2020 年 6 月 10 日
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 件のコメント
Nico Wulf
Nico Wulf 2020 年 5 月 24 日
Hello Alex,
this is the measured data.
Best regards!
Alex Sha
Alex Sha 2020 年 5 月 25 日
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

サインインしてコメントする。

回答 (1 件)

Rajiv Singh
Rajiv Singh 2020 年 6 月 10 日
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)

カテゴリ

Help Center および File ExchangeTransfer Function Models についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by