How to use harmonic fitting method

Hi,
Please, how can I use Harmonic fiting for the attached data to get a smooth fit.

5 件のコメント

Torsten
Torsten 2023 年 9 月 20 日
Where are the values of the variable you want to plot the data against (time or whatever) ?
TTA
TTA 2023 年 9 月 20 日
x = 10:0.1:60
Sam Chak
Sam Chak 2023 年 9 月 20 日
@TTA, Like this?
y = load('darta1.txt');
x = linspace(10, 60, numel(y));
plot(x, y, 'linewidth', 1.5), grid on
xlabel('x'), ylabel('y')
TTA
TTA 2023 年 9 月 20 日
yes but I want use harmonics to fit it to something like the attached figure
Torsten
Torsten 2023 年 9 月 20 日
Tell us precisely what you define as your approximating "harmonic".

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

 採用された回答

Sam Chak
Sam Chak 2023 年 9 月 20 日

1 投票

Hi @TTA,
I'm interpreting your 'Harmonic' model as the 'Sum of Sine' model. If this is not the case, then you will need to create a custom nonlinear model that suits the name "Harmonic" using the fittype() function.
y = load('darta1.txt');
x = linspace(10, 60, numel(y));
[f, gof] = fit(x', y, 'sin3')
f =
General model Sin3: f(x) = a1*sin(b1*x+c1) + a2*sin(b2*x+c2) + a3*sin(b3*x+c3) Coefficients (with 95% confidence bounds): a1 = 1564 (-8.752e+04, 9.065e+04) b1 = 0.04957 (-0.1147, 0.2138) c1 = 0.1819 (-4.047, 4.411) a2 = 1363 (-8.772e+04, 9.045e+04) b2 = 0.05511 (-0.1195, 0.2297) c2 = 3.18 (-1.365, 7.725) a3 = 2.975 (2.774, 3.176) b3 = 0.3159 (0.307, 0.3248) c3 = -4.138 (-4.419, -3.857)
gof = struct with fields:
sse: 465.0567 rsquare: 0.9983 dfe: 492 adjrsquare: 0.9983 rmse: 0.9722
plot(f, x, y), grid on,
legend('data', 'Sum of Sine (type-3)', 'location', 'best')

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeGet Started with Curve Fitting Toolbox についてさらに検索

質問済み:

TTA
2023 年 9 月 20 日

コメント済み:

TTA
2023 年 9 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by