Hello everyone I'm new, can some help me little bit with my problem. I need to sum free Fourier together.

1 Ansicht (letzte 30 Tage)
I tried like this first but it gives strange value.
clc;clearvars; close all;
step = 1;
x = 1:100
a0 = 2436;
a1 = -1008;
b1 = -4210;
a2 = -2692;
b2 = 1363;
a3 = 1037;
b3 = 1234;
a4 = 379;
b4 = -502;
a5 = -147.4;
b5 = -67.34;
a6 = -4.665;
b6 = 20.64;
w = 0.02518;
aa0 = -0.004139;
aa1 = 0.03085;
bb1 = 0.006164;
aa2 = -0.01731;
bb2 = 0.001776;
aa3 = 0.00198;
bb3 = 0.003651;
aa4 = -0.01478;
bb4 = -0.001275;
aa5 = 0.003926;
bb5 = 0.0005124;
aa6 = -0.008721;
bb6 = -0.004231;
ww = 0.06636;
aaa0 = 2.637e+05;
aaa1 = -3.116e+05;
bbb1 = -3.359e+05;
aaa2 = -2.211e+04;
bbb2 = 2.973e+05;
aaa3 = 1.105e+05;
bbb3 = -8.868e+04;
aaa4 = -4.626e+04;
bbb4 = -6556;
aaa5 = 5566;
bbb5 = 7825;
aaa6 = 171.1;
bbb6 = -915.6;
www = 0.01651;
S1 = a0 + a1*cos(x*w) + b1*sin(x*w) + a2*cos(2*x*w) + b2*sin(2*x*w) + a3*cos(3*x*w) + b3*sin(3*x*w) + a4*cos(4*x*w) + b4*sin(4*x*w) + a5*cos(5*x*w) + b5*sin(5*x*w) + a6*cos(6*x*w) + b6*sin(6*x*w);
S2 = aa0 + aa1*cos(x*ww) + bb1*sin(x*ww) + aa2*cos(2*x*ww) + bb2*sin(2*x*ww) + aa3*cos(3*x*ww) + bb3*sin(3*x*ww) + aa4*cos(4*x*ww) + bb4*sin(4*x*ww) + aa5*cos(5*x*ww) + bb5*sin(5*x*ww) + aa6*cos(6*x*ww) + bb6*sin(6*x*ww);
S3 = aaa0 + aaa1*cos(x*www) + bbb1*sin(x*www) + aaa2*cos(2*x*www) + bbb2*sin(2*x*www) + aaa3*cos(3*x*www) + bbb3*sin(3*x*www) + aaa4*cos(4*x*www) + bbb4*sin(4*x*www) + aaa5*cos(5*x*www) + bbb5*sin(5*x*www) + aaa6*cos(6*x*www) + bbb6*sin(6*x*www);
SS_n5 = S1 + S2 + S3;
plot(x, SS_n5, 'b-'); title('TEST')
I tried like this.
load enso;
x = 0:100;
f1 = fit(time,Test1,'fourier8')
f2 = fit(time,Test2,'fourier8')
f3 = fit(time,Test3,'fourier8')
SS=f1+f2+f3;
plot(x, SS, 'b-'); title('TEST');
But it gives error?
Undefined operator '+' for input arguments of type 'cfit'.
Error in Untitled5 (line 9)
SS=f2+f3;
Because workspace is not array.
Can someone help me with this?
How can I see later what coefficient in sum function?
Thanks in advance!!!

Akzeptierte Antwort

Torsten
Torsten am 9 Mai 2022
Bearbeitet: Torsten am 9 Mai 2022
x = 0:100;
F1 = feval(f1,x);
F2 = feval(f2,x);
F3 = feval(f3,x);
SS = F1 + F2 + F3;
plot(x,SS)
coefficientValues1 = coeffvalues(f1);
coefficientValues2 = coeffvalues(f2);
coefficientValues3 = coeffvalues(f3);
coefficientValues_SS = coefficientValues1 + coefficientValues2 + coefficientValues3
My question is: Why don't you fit f1+f2+f3 right from the beginning instead of doing this separately for f1,f2 and f3 ?
  5 Kommentare

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by