From: <cd...@us...> - 2012-08-07 06:28:03
|
Revision: 10835 http://octave.svn.sourceforge.net/octave/?rev=10835&view=rev Author: cdf Date: 2012-08-07 06:27:57 +0000 (Tue, 07 Aug 2012) Log Message: ----------- fix test syntax and beautify syntax Modified Paths: -------------- trunk/octave-forge/extra/lssa/inst/lombcoeff.m Modified: trunk/octave-forge/extra/lssa/inst/lombcoeff.m =================================================================== --- trunk/octave-forge/extra/lssa/inst/lombcoeff.m 2012-08-07 06:08:45 UTC (rev 10834) +++ trunk/octave-forge/extra/lssa/inst/lombcoeff.m 2012-08-07 06:27:57 UTC (rev 10835) @@ -22,19 +22,29 @@ ## @seealso{lombnormcoeff} ## @end deftypefn -%!test -%!shared t, x, o, maxfreq; -%! maxfreq = 4 / ( 2 * pi ); -%! t = linspace(0,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( lombcoeff(t,x,maxfreq),10788.9848389923,5e-10 ); -%!assert( lombcoeff(t,x,3/4*maxfreq),12352.6413413457,5e-10 ); -%!assert( lombcoeff(t,x,1/4*maxfreq),13673.4098969780,5e-10 ); +function coeff = lombcoeff (T, X, o) -function coeff = lombcoeff(T, X, o) - theta = atan2(sum(sin(2 .* o .* T )), sum(cos(2.*o.*T)))/ (2 * o ); - coeff = ( sum(X .* cos(o .* T - theta))**2)/(sum(cos(o.*T-theta).**2)) + ( sum(X .* sin(o .* T - theta))**2)/(sum(sin(o.*T-theta).**2)); + theta = atan2 (sum (sin (2 .* o .* T )), + sum (cos (2 .* o .* T))) / (2 * o); + + coeff = (sum (X .* cos (o .* T - theta)) ^2 / + sum (cos (o .* T - theta) .^2) + + sum (X .* sin (o .* T - theta)) ^2 / + sum (sin (o .* T - theta) .^2)); + endfunction + +%!shared t, x, o, maxfreq +%! maxfreq = 4 / (2 * pi); +%! t = linspace (0, 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 (lombcoeff (t, x, maxfreq), 10788.9848389923, 5e-10); +%!assert (lombcoeff (t, x, 3/4*maxfreq), 12352.6413413457, 5e-10); +%!assert (lombcoeff (t, x, 1/4*maxfreq), 13673.4098969780, 5e-10); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |