- there is a problem with your code;
- there is problem with your equations.
How can I fit an double exponential curve?
12 次查看(过去 30 天)
显示 更早的评论
Hi! I have a problem fitting a curve. I have two curves, one voltage and the other current, and I need the Z=V/I impedance. What I need to do is: Find the fit for the voltage curve. And with the new fit curve I found new impedance.
I made a code that I got a good fit of the curve, however, when plotting the new impedance it doesn't come out anything similar to the "original" (curve without adjustments).
can anybody help me?
Here is my code and data.
load('500_CONSTANTE_2u_V.MAT');
load('500_CONSTANTE_2u_C.MAT');
load('t.MAt');
t=t(2:200000);
%Impedancia
Z_Trad_Primeira_500=tensao_at_500./corrente_at_500;
figure(1)
plot(t*10^3,Z_Trad_Primeira_500,'r.');hold on;
%FIT
fcn1 = @(b,t) b(1).*exp(b(2).*t) + b(3).*exp(b(4).*t);
[f1, fval] = fminsearch (@ (b) norm (tensao_at_500 - fcn1 (b, t)), [1; -1; -1; -1]);
figure(2)
plot(t, tensao_at_500, 'p')
hold on
plot(t, fcn1(f1,t), '-')
hold off
grid
%new Z
Znew=fcn1(f1,t)./corrente_at_500;
figure(5)
plot(t*10^3,Z_Trad_Primeira_500,'r.');hold on;
plot(t*10^3,Znew ,'g--');hold on;
16 个评论
Mathieu NOE
2021-12-20
hello Amanda
welcome back
as far as I understandthe publication you are refering to, the attempt is to do a simple two parameters exponential fit once for the voltage signal, one for the current signal
this is done here :
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/839635/image.png)
load('tensao_at_500.MAT');
load('corrente_at_500.MAT');
load('t.MAt');
figure(1)
plot(t,tensao_at_500,'b',t,corrente_at_500,'r');
title(' Voltage and current');
xlabel('time (s)');
ylabel('Amplitude');
% FIT voltage signal
% use only decaying portion of signal for the fit
[val,indm] = max(tensao_at_500);
tensao_fit = tensao_at_500(indm:end);
t_fit = t(indm:end);
fcn1 = @(b,t) b(1).*exp(b(2).*t);
[f1, fval] = fminsearch (@ (b) norm (tensao_fit - fcn1 (b, t_fit)), [val; -1e3;]);
figure(2)
plot(t, tensao_at_500, '*',t_fit, fcn1(f1,t_fit), '-')
title(' Voltage');
legend('voltage','exp fit');
xlabel('time (s)');
ylabel('Amplitude');
grid on
% FIT current signal
% use only decaying portion of signal for the fit
[val,indm] = max(corrente_at_500);
corrente_fit = corrente_at_500(indm:end);
t_fit = t(indm:end);
fcn2 = @(b,t) b(1).*exp(b(2).*t);
[f2, fval] = fminsearch (@ (b) norm (corrente_fit - fcn2 (b, t_fit)), [val; -1e3;]);
figure(3)
plot(t, corrente_at_500, '*',t_fit, fcn2(f2,t_fit), '-')
title(' Current');
legend('current','exp fit');
xlabel('time (s)');
ylabel('Amplitude');
grid on
回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!