1

I have data on sea temperatures at different depths. With these data I need to remove seasonal and non-seasonal oscillations by fitting a function that consists of two sinusoids with periods of 12 and 6 hours on temperatue data (for every depth). The function needs to be put in seasonal diagram. And this adjustment needs to be done with least- square method.

Peter Flom
  • 94,055
  • 35
  • 143
  • 276
Natalija
  • 11
  • 1
  • What tool are you using? Excel? R? Matplotlib? Please help us communicate an answer that is useful by giving us the requirements. – EngrStudent May 11 '13 at 14:36
  • Matlab. I was trying to find answer somewhere online, but useless. But I also dont know how function should look like. This is the first time that I am doing something like that, so I am a bit lost – Natalija May 11 '13 at 15:56
  • @Natalija, Can you give the raw data online, or some variation on its general form. It makes the code more useful if you don't have to figure out how to format what you have in order to make it work. I use MatLab all the time and can easily do this. If you could give dimensions of your inputs (in general) and the general form of the result, then that makes the answer more useful. – EngrStudent May 12 '13 at 04:53
  • @EngrStudent The data looks like this. I wish I could know the general form of the result but I dont. All I know is that I need to see from this are there some trends or not. And because of that I need to remove seasonal oscillations with this method. I was trying to find how the function with periods should look like, but with no luck. point year month day hour minutes depth temp 8 1952 7 30 13 30 0 23,820 8 1952 7 30 13 30 10 21,760 8 1952 7 30 13 30 20 18,070 8 1952 7 30 13 30 40 14,340 8 1952 7 30 13 30 60 13,800 8 1952 7 30 13 30 70 13,580 – Natalija May 12 '13 at 06:39
  • also see [this](http://stats.stackexchange.com/questions/60500/how-to-find-a-good-fit-for-semi-sinusoidal-model-in-r/60504#60504) and perhaps [this](http://stats.stackexchange.com/questions/60994/fit-a-sine-to-data) – Glen_b Oct 12 '13 at 08:41

2 Answers2

1

I think that the solution might depend on how you want to use the data. But I'll make a simple suggestion.

Perhaps the most simple approach would be to use a covariate to remove the seasonality. Do you have a time series of a strong driver? E.g., air temperature might correlate very well with sea surface temperature. Regress water temperature against air temperature, and check to see if the residuals contain the appropriate pattern (or lack thereof). If this approach works for surface temperature, maybe it'll work equally well for subsurface temperatures. Obviously this method will not work for certain applications.

rbatt
  • 739
  • 1
  • 8
  • 20
0

Natalija,

Notes:

  • I am hearing this is a like of constant x and y position.
  • Transformation of data: all time feeds into decimal year as a single number

Given:

$ f(time, depth) = g(temp) + A_1sin(time+\Delta t_1)+ A_2sin(0.5*time+\Delta t_2) +\epsilon$

The matlab code would be:

function Prob58708

clc;

% enable this if you have data %load; %load parsed and formatted data

%here is synthetic data time=linspace(1,10,200); Temp=pi*sin(time+pi/2)+exp(1)*sin(0.5*time+0.2)+randn(size(time));

global t; %time t=time; global T; %Temperature T=Temp;

X0=[2.87373680779043 1.59661233154352 2.89426152938692 0.10126060393764]

x = fminsearch(@(x) myfit(x),X0)

myfit(x)

return

function [out]=myfit(x)

global t; global T;

a1=x(1); dt1=x(2); a2=x(3); dt2=x(4);

T2=a1*sin(t+dt1)+a2*sin(0.5*t+dt2);

out=norm(T2-T)./norm(T); return

EngrStudent
  • 8,232
  • 2
  • 29
  • 82