How can I improve the attached code to reduce the gap between fitted curve and the original ones?

조회 수: 1 (최근 30일)
Hello friends
I have a code that I want to know the amplitude of Vabc between t=0.1 and 0.2
But the fitted curve is a bit different from the original ones.
Can you advise?
  댓글 수: 3
Atefeh
Atefeh 2023년 11월 6일
Hi Mathieu
I need the amplitude value in order to use in a machine learning process, the output waveform is extracted from a simulink model.

댓글을 달려면 로그인하십시오.

답변 (1개)

Sandeep Mishra
Sandeep Mishra 2024년 12월 3일
Hi Atefeh,
I ran the provided code in MATLAB R2024b and identified the same disparity between the curve plotted using the data and the curve obtained through curve fitting.
Upon debugging, I noticed that the code uses the ‘fit’ function across three time ranges: ‘ta’, ‘tb’, and ‘tc’. The RMSE for the ‘tb’ range is approximately 0.2, whereas for ‘ta’ and ‘tc’, it is significantly lower at 1e-6.
The discrepancy arises due to the high RMSE for the ‘tb’ time range. This occurs because the ‘fit’ function applies the ‘sin1’ ‘fittype’ parameter to data comprising a linear segment (from 0.1s to 0.2s) followed by a sine wave (from 0.2s to 0.21s), leading to inconsistent results.
To resolve the issue, you can update the time range of ‘tb’ and ‘tc’ interval to focus on a single curve type at a time.
Below is an example modification:
% Split data for straight line
tb = Vtime(1002:2000);
Vb = Vdat1(1002:2000);
% Split data for sine wave
tc = Vtime(2001:3001);
Vc = Vdat1(2001:3001);
% Updated time interval for curve fitting
t = linspace(0, 0.3, 3001);
t1 = 0.1;
t2 = 0.2;
Refer to the following MathWorks Documentation to learn about ‘fit’ function:
I hope this helps you in resolving the query

카테고리

Help CenterFile Exchange에서 Linear and Nonlinear Regression에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by