From: <cd...@us...> - 2012-08-10 13:17:39
|
Revision: 10854 http://octave.svn.sourceforge.net/octave/?rev=10854&view=rev Author: cdf Date: 2012-08-10 13:17:33 +0000 (Fri, 10 Aug 2012) Log Message: ----------- vectorization example Added Paths: ----------- trunk/octave-forge/extra/lssa/inst/fastlscomplex.m Added: trunk/octave-forge/extra/lssa/inst/fastlscomplex.m =================================================================== --- trunk/octave-forge/extra/lssa/inst/fastlscomplex.m (rev 0) +++ trunk/octave-forge/extra/lssa/inst/fastlscomplex.m 2012-08-10 13:17:33 UTC (rev 10854) @@ -0,0 +1,55 @@ +## Copyright (C) 2012 Benjamin Lewis <be...@gm...> +## +## 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); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |