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

3 views (last 30 days)
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 Comments
Atefeh
Atefeh on 6 Nov 2023
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.

Sign in to comment.

Answers (1)

Sandeep Mishra
Sandeep Mishra on 3 Dec 2024
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

Community Treasure Hunt

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

Start Hunting!