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

4 ビュー (過去 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.
Mathieu NOE
Mathieu NOE 2023 年 11 月 7 日
hello
why not simply use max / min of your data ?

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

回答 (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 Center および File ExchangeLinear and Nonlinear Regression についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by