Approximation of a times series with a given function in matlab

76 views Asked by At

I am trying to fit in matlab a temperature time series that follows this kind of functionenter image description here

I would need to retrieve the 8 parameters of the function, putting as boundary lambda=0 and sigma positive. I tried using the lsqcurvefit function in matlab, but I cannot use the y function inside this built in matlab funtion if I have a for loop in place.

Torontoless=xlsread('temp.xlsx',2);
xdata=zeros(1,6576);
x=[0,0,0,0,0,0];
ydata=Torontoless';
Toronto=[zeros(size(ydata,1),1) ydata];
fun=zeros(1,6576);
for i=1:6576
fun(i)=(1-x(1))*(Toronto(i)-(x(2)+x(3)*Toronto(i)+x(4)*(sin(x(5)*Toronto(i)+x(6)))))+x(2)+x(3)*Toronto(i+1)+x(4)*(sin(x(5)*Toronto(i+1)+x(6)))+(randn-x(7))*x(8);
end

x0=[0,0,0,0,0,0];
lb=[-1000,-1000,-1000,-1000,-1000,-1000,0,0];
ub=[1000,1000,1000,1000,1000,1000,0,1000];

Now, I don't know how to use the fun inside the function x=lsqcurvefit(fun,x0,xdata,ydata,lb,ub)

I don't know if there is a better way to fit this kind of time series, but let me know if you have something in mind to solve the problem. Thanks a lot.

PS The size of the temp vector is 1x6576. As I wanted temperature to start at 0, I added an extra column at first.

0

There are 0 answers