fit_n012.m
SYNTAX: [amplitudes,phases,err,dtst] = fit_n012(t,data,angs,iplot);
PURPOSE: Decompose data into n=0, n=1, n=2 components for each time
point in t.
INPUTS:
t = time vector (nt,1)
data = data array (nt,nangs)
angs = vector of nangs angles corr. to columns of data array [degrees]
iplot = (optional) flag to select plotting of error:
iplot>0 plots (iplot=fig.num.), iplot=0 doesn't. Default=0
OUTPUTS:
amplitudes = array of amplitudes over time (nt,3)
= [a0(nt,1) a1(nt,1) a2(nt,1)
phases = array of phase data over time (nt,3) (radians)
= [zeros(nt,1) phi1(nt,1) phi2(nt,1)]
(note that initial column of zeros is dummy)
err = vector of RMS av error sum over angs as fraction of a0 (nt,1)
dtst = signal composed of sum of n=0,1,2 components
RESTRICTIONS:
All elements of angs must lie in range 0<= angs <360.
Angles must monotonically increase (and no repetitions in particular).
Data must be real.
METHOD:
Simple linear fit of sin,cos basis functions. For each time point
fits to corresponding row of data. Function for fitting is:
a0 + a1*sin(1*ang + phi1) + a2*sin(2*ang + phi2)
...where rows of amplitudes contain [a0 a1 a2] and rows of phases
contain [0 phi1 phi2]. The actual representation used in the fit is
a0 + c1*sin(1*ang) + d1*cos(1*ang) + c2*sin(2*ang) + d2*cos(2*ang)
...which is converted to the amplitude,phase data for output.
Dependencies