Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project!

[4ad237]: inst / lscomplex.m Maximize Restore History

 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68``` ```## Copyright (C) 2012 Benjamin Lewis ## ## 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 . ## -*- 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 = lscomplex (t, x, omegamax, ncoeff, noctave) ## VECTOR ONLY, and since t and x have the same number of ## entries, there's no problem. n = length (t); transform = zeros (1, ncoeff * noctave); o = omegamax; omul = 2 ^ (- 1 / ncoeff); for iter = 1:ncoeff * noctave ot = o .* t; ## See the paper for the expression below transform(iter) = sum ((cos (ot) - (sin (ot) .* i)) .* x) / n; ## Advance the transform to the next coefficient in the octave o *= omul; endfor 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)); %! o = [ maxfreq , 3 / 4 * maxfreq , 1 / 4 * maxfreq ]; %! assert (lscomplex (t, x, maxfreq, 2, 2), %! [(-0.400924546169395 - 2.371555305867469i), ... %! (1.218065147708429 - 2.256125004156890i), ... %! (1.935428592212907 - 1.539488163739336i), ... %! (2.136692292751917 - 0.980532175174563i)], 5e-10); ```