Diff of /inst/fastlscomplex.m [000000] .. [895709]  Maximize  Restore

Switch to side-by-side view

--- a
+++ b/inst/fastlscomplex.m
@@ -0,0 +1,55 @@
+## Copyright (C) 2012 Benjamin Lewis <benjf5@gmail.com>
+##
+## This program is free software; you can redistribute it and/or modify it under
+## the terms of the GNU General Public License as published by the Free Software
+## Foundation; either version 3 of the License, or (at your option) any later
+## version.
+##
+## This program is distributed in the hope that it will be useful, but WITHOUT
+## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
+## details.
+##
+## You should have received a copy of the GNU General Public License along with
+## this program; if not, see <http://www.gnu.org/licenses/>.
+
+## -*- texinfo -*-
+## @deftypefn {Function File} {@var{t} =} lscomplex (@var{time}, @var{mag}, @var{maxfreq}, @var{numcoeff}, @var{numoctaves})
+## 
+## Return the complex least-squares transform of the (@var{time},@var{mag})
+## series, considering frequencies up to @var{maxfreq}, over @var{numoctaves}
+## octaves and @var{numcoeff} coefficients.
+##
+## @seealso{lsreal}
+## @end deftypefn
+
+
+function transform = fastlscomplex (t, x, omegamax, ncoeff, noctave)
+
+  ## t will be unrolled to a column vector below
+  ## no metter what its original shape is
+  n = numel (t); 
+   
+  iter = 0 : (ncoeff * noctave - 1);
+  omul = (2 .^ (- iter / ncoeff));
+
+  ot = t(:) * (omul * omegamax);
+
+  ## See the paper for the expression below
+  transform = sum ((cos (ot) - (sin (ot) .* i)) .* x(:), 1) / n; 
+  
+endfunction 
+
+%!test
+%! maxfreq = 4 / ( 2 * pi );
+%! t = [0:0.008:8];
+%! x = ( 2 .* sin (maxfreq .* t) +
+%!       3 .* sin ( (3 / 4) * maxfreq .* t)-
+%!       0.5 .* sin ((1/4) * maxfreq .* t) -
+%!       0.2 .* cos (maxfreq .* t) + 
+%!       cos ((1/4) * maxfreq .* t));
+%! assert (fastlscomplex (t, x, maxfreq, 2, 2), 
+%!       [(-0.400924546169395 - 2.371555305867469i), ...
+%!        (1.218065147708429 - 2.256125004156890i), ... 
+%!        (1.935428592212907 - 1.539488163739336i), ...
+%!        (2.136692292751917 - 0.980532175174563i)], 5e-10);