pyhctsa.robust.bf_fit_sinusoids¶
-
pyhctsa.robust.bf_fit_sinusoids(y, k, constant=
False)¶ Least-squares fit of a sum of
ksinusoids to a time series (hctsaBF_FitSinusoids).Fits
y(t) = sum_i a_i sin(2 pi f_i t) + b_i cos(2 pi f_i t),t = 0..N-1(plus a constantcifconstant). The amplitudes and phases (andc) are linear, found by least squares for given frequencies, so only thekfrequencies are searched (variable projection), deterministically and stagewise: each frequency is added at the grid frequency (2Npoints on[1/N, 1/2 - 1/(2N)]) that most reduces the residual sum of squares given those already chosen (with the constant, if there is one, fitted jointly throughout), and then all of the chosen frequencies are refined, twice in turn by 8 zooming local grids and then together by Gauss-Newton iterations (_sin_refine()), to the least-squares minimum at machine precision, before the next is added (so that the residual of an exact sum of sinusoids is rounding error, and each frequency is added to the least-squares fit of those before it rather than to the leakage left by their grid resolution).The frequencies are bounded to
[1/N, 1/2 - 1/(2N)]cycles per sample. Each sinusoid is an oscillation that completes at least one full cycle within the series: a component with less than one cycle in the window is a trend, not an oscillation (its period is not observed, and below1/(2N)its sine and cosine terms are not distinguishable from a constant and a linear trend). A frequency at 1/2 has a zero sine term.