This list is closed, nobody may subscribe to it.
2001 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(10) |
Aug
(5) |
Sep
(3) |
Oct
(41) |
Nov
(41) |
Dec
(33) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2002 |
Jan
(75) |
Feb
(10) |
Mar
(170) |
Apr
(174) |
May
(66) |
Jun
(11) |
Jul
(10) |
Aug
(44) |
Sep
(73) |
Oct
(28) |
Nov
(139) |
Dec
(52) |
2003 |
Jan
(35) |
Feb
(93) |
Mar
(62) |
Apr
(10) |
May
(55) |
Jun
(70) |
Jul
(37) |
Aug
(16) |
Sep
(56) |
Oct
(31) |
Nov
(57) |
Dec
(83) |
2004 |
Jan
(85) |
Feb
(67) |
Mar
(27) |
Apr
(37) |
May
(75) |
Jun
(85) |
Jul
(160) |
Aug
(68) |
Sep
(104) |
Oct
(25) |
Nov
(39) |
Dec
(23) |
2005 |
Jan
(10) |
Feb
(45) |
Mar
(43) |
Apr
(19) |
May
(108) |
Jun
(31) |
Jul
(41) |
Aug
(23) |
Sep
(65) |
Oct
(58) |
Nov
(44) |
Dec
(54) |
2006 |
Jan
(96) |
Feb
(27) |
Mar
(69) |
Apr
(59) |
May
(67) |
Jun
(35) |
Jul
(13) |
Aug
(461) |
Sep
(160) |
Oct
(399) |
Nov
(32) |
Dec
(72) |
2007 |
Jan
(316) |
Feb
(305) |
Mar
(318) |
Apr
(54) |
May
(194) |
Jun
(173) |
Jul
(282) |
Aug
(91) |
Sep
(227) |
Oct
(365) |
Nov
(168) |
Dec
(18) |
2008 |
Jan
(71) |
Feb
(111) |
Mar
(155) |
Apr
(173) |
May
(70) |
Jun
(67) |
Jul
(55) |
Aug
(83) |
Sep
(32) |
Oct
(68) |
Nov
(80) |
Dec
(29) |
2009 |
Jan
(46) |
Feb
(18) |
Mar
(95) |
Apr
(76) |
May
(140) |
Jun
(98) |
Jul
(84) |
Aug
(123) |
Sep
(94) |
Oct
(131) |
Nov
(142) |
Dec
(125) |
2010 |
Jan
(128) |
Feb
(158) |
Mar
(172) |
Apr
(134) |
May
(94) |
Jun
(84) |
Jul
(32) |
Aug
(127) |
Sep
(167) |
Oct
(109) |
Nov
(69) |
Dec
(78) |
2011 |
Jan
(39) |
Feb
(58) |
Mar
(52) |
Apr
(47) |
May
(56) |
Jun
(76) |
Jul
(55) |
Aug
(54) |
Sep
(165) |
Oct
(255) |
Nov
(328) |
Dec
(263) |
2012 |
Jan
(82) |
Feb
(147) |
Mar
(400) |
Apr
(216) |
May
(209) |
Jun
(160) |
Jul
(86) |
Aug
(141) |
Sep
(156) |
Oct
(6) |
Nov
|
Dec
|
2015 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(1) |
Aug
|
Sep
(1) |
Oct
|
Nov
(1) |
Dec
(2) |
2016 |
Jan
|
Feb
(2) |
Mar
(2) |
Apr
(1) |
May
(1) |
Jun
(2) |
Jul
(1) |
Aug
(1) |
Sep
|
Oct
|
Nov
(1) |
Dec
|
2019 |
Jan
|
Feb
|
Mar
(1) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
2021 |
Jan
|
Feb
|
Mar
|
Apr
(3) |
May
(4) |
Jun
(8) |
Jul
(2) |
Aug
(5) |
Sep
(9) |
Oct
|
Nov
|
Dec
|
From: <par...@us...> - 2012-08-14 20:50:49
|
Revision: 10873 http://octave.svn.sourceforge.net/octave/?rev=10873&view=rev Author: paramaniac Date: 2012-08-14 20:50:42 +0000 (Tue, 14 Aug 2012) Log Message: ----------- control: fix oct-filename Modified Paths: -------------- trunk/octave-forge/main/control/src/slib01ad.cc trunk/octave-forge/main/control/src/slib01cd.cc trunk/octave-forge/main/control/src/slident.cc Modified: trunk/octave-forge/main/control/src/slib01ad.cc =================================================================== --- trunk/octave-forge/main/control/src/slib01ad.cc 2012-08-14 20:33:19 UTC (rev 10872) +++ trunk/octave-forge/main/control/src/slib01ad.cc 2012-08-14 20:50:42 UTC (rev 10873) @@ -50,7 +50,7 @@ int& IWARN, int& INFO); } -// PKG_ADD: autoload ("slib01ad", "devel_slicot_functions.oct"); +// PKG_ADD: autoload ("slib01ad", "control_slicot_functions.oct"); DEFUN_DLD (slib01ad, args, nargout, "-*- texinfo -*-\n\ Slicot IB01AD Release 5.0\n\ Modified: trunk/octave-forge/main/control/src/slib01cd.cc =================================================================== --- trunk/octave-forge/main/control/src/slib01cd.cc 2012-08-14 20:33:19 UTC (rev 10872) +++ trunk/octave-forge/main/control/src/slib01cd.cc 2012-08-14 20:50:42 UTC (rev 10873) @@ -52,7 +52,7 @@ int& IWARN, int& INFO); } -// PKG_ADD: autoload ("slib01cd", "devel_slicot_functions.oct"); +// PKG_ADD: autoload ("slib01cd", "control_slicot_functions.oct"); DEFUN_DLD (slib01cd, args, nargout, "-*- texinfo -*-\n\ Slicot IB01CD Release 5.0\n\ Modified: trunk/octave-forge/main/control/src/slident.cc =================================================================== --- trunk/octave-forge/main/control/src/slident.cc 2012-08-14 20:33:19 UTC (rev 10872) +++ trunk/octave-forge/main/control/src/slident.cc 2012-08-14 20:50:42 UTC (rev 10873) @@ -86,7 +86,7 @@ int& IWARN, int& INFO); } -// PKG_ADD: autoload ("slident", "devel_slicot_functions.oct"); +// PKG_ADD: autoload ("slident", "control_slicot_functions.oct"); DEFUN_DLD (slident, args, nargout, "-*- texinfo -*-\n\ Slicot IB01AD Release 5.0\n\ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <par...@us...> - 2012-08-14 20:33:25
|
Revision: 10872 http://octave.svn.sourceforge.net/octave/?rev=10872&view=rev Author: paramaniac Date: 2012-08-14 20:33:19 +0000 (Tue, 14 Aug 2012) Log Message: ----------- control: fix makefile Modified Paths: -------------- trunk/octave-forge/main/control/src/Makefile Modified: trunk/octave-forge/main/control/src/Makefile =================================================================== --- trunk/octave-forge/main/control/src/Makefile 2012-08-14 20:33:09 UTC (rev 10871) +++ trunk/octave-forge/main/control/src/Makefile 2012-08-14 20:33:19 UTC (rev 10872) @@ -52,6 +52,9 @@ is_real_square_matrix.oct: is_real_square_matrix.cc $(MKOCTFILE) is_real_square_matrix.cc +is_matrix.oct: is_matrix.cc + $(MKOCTFILE) is_matrix.cc + clean: rm -rf *.o core octave-core *.oct *~ *.f slicot This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <par...@us...> - 2012-08-14 20:33:15
|
Revision: 10871 http://octave.svn.sourceforge.net/octave/?rev=10871&view=rev Author: paramaniac Date: 2012-08-14 20:33:09 +0000 (Tue, 14 Aug 2012) Log Message: ----------- control-devel: remove system identification stuff (2) Modified Paths: -------------- trunk/octave-forge/extra/control-devel/src/Makefile Modified: trunk/octave-forge/extra/control-devel/src/Makefile =================================================================== --- trunk/octave-forge/extra/control-devel/src/Makefile 2012-08-14 20:28:07 UTC (rev 10870) +++ trunk/octave-forge/extra/control-devel/src/Makefile 2012-08-14 20:33:09 UTC (rev 10871) @@ -27,10 +27,6 @@ LFLAGS="$(LFLAGS)" \ $(MKOCTFILE) devel_slicot_functions.cc common.cc slicotlibrary.a -# helpers -is_matrix.oct: is_matrix.cc - $(MKOCTFILE) is_matrix.cc - clean: rm -rf *.o core octave-core *.oct *~ *.f slicot This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <par...@us...> - 2012-08-14 20:28:13
|
Revision: 10870 http://octave.svn.sourceforge.net/octave/?rev=10870&view=rev Author: paramaniac Date: 2012-08-14 20:28:07 +0000 (Tue, 14 Aug 2012) Log Message: ----------- control: fix version string (+ not supported) Modified Paths: -------------- trunk/octave-forge/main/control/DESCRIPTION Modified: trunk/octave-forge/main/control/DESCRIPTION =================================================================== --- trunk/octave-forge/main/control/DESCRIPTION 2012-08-14 20:23:42 UTC (rev 10869) +++ trunk/octave-forge/main/control/DESCRIPTION 2012-08-14 20:28:07 UTC (rev 10870) @@ -1,5 +1,5 @@ Name: Control -Version: 2.3.52+ +Version: 2.3.53 Date: 2012-08-14 Author: Lukas Reichlin <luk...@gm...> Maintainer: Lukas Reichlin <luk...@gm...> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <par...@us...> - 2012-08-14 20:23:48
|
Revision: 10869 http://octave.svn.sourceforge.net/octave/?rev=10869&view=rev Author: paramaniac Date: 2012-08-14 20:23:42 +0000 (Tue, 14 Aug 2012) Log Message: ----------- control-devel: remove system identification stuff Modified Paths: -------------- trunk/octave-forge/extra/control-devel/DESCRIPTION trunk/octave-forge/extra/control-devel/src/Makefile trunk/octave-forge/extra/control-devel/src/devel_slicot_functions.cc Modified: trunk/octave-forge/extra/control-devel/DESCRIPTION =================================================================== --- trunk/octave-forge/extra/control-devel/DESCRIPTION 2012-08-14 20:18:25 UTC (rev 10868) +++ trunk/octave-forge/extra/control-devel/DESCRIPTION 2012-08-14 20:23:42 UTC (rev 10869) @@ -1,6 +1,6 @@ Name: Control-Devel -Version: 0.2.0 -Date: 2012-05-21 +Version: 0.3.0 +Date: 2012-08-14 Author: Lukas Reichlin <luk...@gm...> Maintainer: Lukas Reichlin <luk...@gm...> Title: Control Systems Developer's Playground Modified: trunk/octave-forge/extra/control-devel/src/Makefile =================================================================== --- trunk/octave-forge/extra/control-devel/src/Makefile 2012-08-14 20:18:25 UTC (rev 10868) +++ trunk/octave-forge/extra/control-devel/src/Makefile 2012-08-14 20:23:42 UTC (rev 10869) @@ -11,8 +11,7 @@ endif LFLAGS := $(shell $(MKOCTFILE) -p LFLAGS) $(LAPACK_LIBS) $(BLAS_LIBS) $(FLIBS) -all: devel_slicot_functions.oct \ - is_matrix.oct +all: devel_slicot_functions.oct # unpack and compile SLICOT library slicotlibrary.a: slicot.tar.gz Modified: trunk/octave-forge/extra/control-devel/src/devel_slicot_functions.cc =================================================================== --- trunk/octave-forge/extra/control-devel/src/devel_slicot_functions.cc 2012-08-14 20:18:25 UTC (rev 10868) +++ trunk/octave-forge/extra/control-devel/src/devel_slicot_functions.cc 2012-08-14 20:23:42 UTC (rev 10869) @@ -1,7 +1,3 @@ -#include "slident.cc" // system identification -#include "slib01cd.cc" // compute initial state vector -#include "slib01ad.cc" // compute singular values - #include "slident_a.cc" #include "slident_b.cc" #include "slident_c.cc" \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <par...@us...> - 2012-08-14 20:18:31
|
Revision: 10868 http://octave.svn.sourceforge.net/octave/?rev=10868&view=rev Author: paramaniac Date: 2012-08-14 20:18:25 +0000 (Tue, 14 Aug 2012) Log Message: ----------- control: update news and description Modified Paths: -------------- trunk/octave-forge/main/control/DESCRIPTION trunk/octave-forge/main/control/NEWS Modified: trunk/octave-forge/main/control/DESCRIPTION =================================================================== --- trunk/octave-forge/main/control/DESCRIPTION 2012-08-14 20:11:22 UTC (rev 10867) +++ trunk/octave-forge/main/control/DESCRIPTION 2012-08-14 20:18:25 UTC (rev 10868) @@ -1,6 +1,6 @@ Name: Control -Version: 2.3.52 -Date: 2012-06-25 +Version: 2.3.52+ +Date: 2012-08-14 Author: Lukas Reichlin <luk...@gm...> Maintainer: Lukas Reichlin <luk...@gm...> Title: Control Systems Modified: trunk/octave-forge/main/control/NEWS =================================================================== --- trunk/octave-forge/main/control/NEWS 2012-08-14 20:11:22 UTC (rev 10867) +++ trunk/octave-forge/main/control/NEWS 2012-08-14 20:18:25 UTC (rev 10868) @@ -4,6 +4,13 @@ control-2.3.53 Release Date: 2012-xx-yy Release Manager: Lukas Reichlin =============================================================================== +** Added new functions for system identification, including: + + arx iddata ifft + moen4 detrend nkshift + moesp fft plot + n4sid filter resample + ** feedback Fixed an argument check which caused false positive error messages. It was a copy-paste mistake affecting non-square systems. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <par...@us...> - 2012-08-14 20:11:28
|
Revision: 10867 http://octave.svn.sourceforge.net/octave/?rev=10867&view=rev Author: paramaniac Date: 2012-08-14 20:11:22 +0000 (Tue, 14 Aug 2012) Log Message: ----------- control: include system identification functions Modified Paths: -------------- trunk/octave-forge/main/control/INDEX trunk/octave-forge/main/control/inst/test_control.m trunk/octave-forge/main/control/src/Makefile trunk/octave-forge/main/control/src/control_slicot_functions.cc Modified: trunk/octave-forge/main/control/INDEX =================================================================== --- trunk/octave-forge/main/control/INDEX 2012-08-14 20:01:58 UTC (rev 10866) +++ trunk/octave-forge/main/control/INDEX 2012-08-14 20:11:22 UTC (rev 10867) @@ -108,7 +108,27 @@ cfconred fwcfconred spaconred -Overloaded Operators +Experimental Data Handling + iddata + @iddata/cat + @iddata/detrend + @iddata/diff + @iddata/fft + @iddata/filter + @iddata/get + @iddata/ifft + @iddata/merge + @iddata/nkshift + @iddata/plot + @iddata/resample + @iddata/set + @iddata/size +System Identification + arx + moen4 + moesp + n4sid +Overloaded LTI Operators @lti/ctranspose @lti/horzcat @lti/inv @@ -124,6 +144,11 @@ @lti/uminus @lti/uplus @lti/vertcat +Overloaded IDDATA Operators + @iddata/horzcat + @iddata/subsasgn + @iddata/subsref + @iddata/vertcat Miscellaneous options strseq Modified: trunk/octave-forge/main/control/inst/test_control.m =================================================================== --- trunk/octave-forge/main/control/inst/test_control.m 2012-08-14 20:01:58 UTC (rev 10866) +++ trunk/octave-forge/main/control/inst/test_control.m 2012-08-14 20:11:22 UTC (rev 10867) @@ -103,3 +103,10 @@ test margin test obsv test sigma + +## identification +test @iddata/iddata +test @iddata/cat +test @iddata/detrend +test @iddata/fft +test moen4 Modified: trunk/octave-forge/main/control/src/Makefile =================================================================== --- trunk/octave-forge/main/control/src/Makefile 2012-08-14 20:01:58 UTC (rev 10866) +++ trunk/octave-forge/main/control/src/Makefile 2012-08-14 20:11:22 UTC (rev 10867) @@ -15,7 +15,8 @@ is_real_scalar.oct \ is_real_vector.oct \ is_real_matrix.oct \ - is_real_square_matrix.oct + is_real_square_matrix.oct \ + is_matrix.oct # TODO: Private oct-files for control package. Modified: trunk/octave-forge/main/control/src/control_slicot_functions.cc =================================================================== --- trunk/octave-forge/main/control/src/control_slicot_functions.cc 2012-08-14 20:01:58 UTC (rev 10866) +++ trunk/octave-forge/main/control/src/control_slicot_functions.cc 2012-08-14 20:11:22 UTC (rev 10867) @@ -39,6 +39,9 @@ #include "slsb16bd.cc" // coprime factorization state-feedback controller reduction #include "slsb16cd.cc" // frequency-weighted coprime factorization state-feedback controller reduction #include "slsb10yd.cc" // fit state-space model to frequency response data +#include "slident.cc" // system identification +#include "slib01cd.cc" // compute initial state vector +#include "slib01ad.cc" // compute singular values // stub function to avoid gen_doc_cache warning upon package installation This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <par...@us...> - 2012-08-14 20:02:06
|
Revision: 10866 http://octave.svn.sourceforge.net/octave/?rev=10866&view=rev Author: paramaniac Date: 2012-08-14 20:01:58 +0000 (Tue, 14 Aug 2012) Log Message: ----------- extra/control-devel ---> main/control (2) Added Paths: ----------- trunk/octave-forge/main/control/src/is_matrix.cc trunk/octave-forge/main/control/src/slib01ad.cc trunk/octave-forge/main/control/src/slib01cd.cc trunk/octave-forge/main/control/src/slident.cc Removed Paths: ------------- trunk/octave-forge/extra/control-devel/src/is_matrix.cc trunk/octave-forge/extra/control-devel/src/slib01ad.cc trunk/octave-forge/extra/control-devel/src/slib01cd.cc trunk/octave-forge/extra/control-devel/src/slident.cc Deleted: trunk/octave-forge/extra/control-devel/src/is_matrix.cc =================================================================== --- trunk/octave-forge/extra/control-devel/src/is_matrix.cc 2012-08-14 19:59:40 UTC (rev 10865) +++ trunk/octave-forge/extra/control-devel/src/is_matrix.cc 2012-08-14 20:01:58 UTC (rev 10866) @@ -1,60 +0,0 @@ -/* - -Copyright (C) 2012 Lukas F. Reichlin - -This file is part of LTI Syncope. - -LTI Syncope 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. - -LTI Syncope 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 LTI Syncope. If not, see <http://www.gnu.org/licenses/>. - -Return true if argument is a real matrix. - -Author: Lukas Reichlin <luk...@gm...> -Created: June 2012 -Version: 0.1 - -*/ - -#include <octave/oct.h> - -DEFUN_DLD (is_matrix, args, nargout, - "-*- texinfo -*-\n\ -@deftypefn {Loadable Function} {} is_matrix (@var{a}, @dots{})\n\ -Return true if argument is a matrix.\n\ -@var{[]} is a valid matrix.\n\ -Avoid nasty stuff like @code{true = isreal (\"a\")}\n\ -@seealso{is_real_matrix, is_real_square_matrix, is_real_vector, is_real_scalar}\n\ -@end deftypefn") -{ - octave_value retval = true; - int nargin = args.length (); - - if (nargin == 0) - { - print_usage (); - } - else - { - for (int i = 0; i < nargin; i++) - { - if (args(i).ndims () != 2 || ! args(i).is_numeric_type () - || ! (args(i).is_complex_type () || args(i).is_real_type ())) - { - retval = false; - break; - } - } - } - - return retval; -} Deleted: trunk/octave-forge/extra/control-devel/src/slib01ad.cc =================================================================== --- trunk/octave-forge/extra/control-devel/src/slib01ad.cc 2012-08-14 19:59:40 UTC (rev 10865) +++ trunk/octave-forge/extra/control-devel/src/slib01ad.cc 2012-08-14 20:01:58 UTC (rev 10866) @@ -1,383 +0,0 @@ -/* - -Copyright (C) 2012 Lukas F. Reichlin - -This file is part of LTI Syncope. - -LTI Syncope 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. - -LTI Syncope 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 LTI Syncope. If not, see <http://www.gnu.org/licenses/>. - -SLICOT system identification -Uses SLICOT IB01AD, IB01BD and IB01CD by courtesy of NICONET e.V. -<http://www.slicot.org> - -Author: Lukas Reichlin <luk...@gm...> -Created: March 2012 -Version: 0.1 - -*/ - -#include <octave/oct.h> -#include <octave/f77-fcn.h> -#include <octave/Cell.h> -#include "common.h" - -extern "C" -{ - int F77_FUNC (ib01ad, IB01AD) - (char& METH, char& ALG, char& JOBD, - char& BATCH, char& CONCT, char& CTRL, - int& NOBR, int& M, int& L, - int& NSMP, - double* U, int& LDU, - double* Y, int& LDY, - int& N, - double* R, int& LDR, - double* SV, - double& RCOND, double& TOL, - int* IWORK, - double* DWORK, int& LDWORK, - int& IWARN, int& INFO); -} - -// PKG_ADD: autoload ("slib01ad", "devel_slicot_functions.oct"); -DEFUN_DLD (slib01ad, args, nargout, - "-*- texinfo -*-\n\ -Slicot IB01AD Release 5.0\n\ -No argument checking.\n\ -For internal use only.") -{ - int nargin = args.length (); - octave_value_list retval; - - if (nargin != 10) - { - print_usage (); - } - else - { -//////////////////////////////////////////////////////////////////////////////////// -// SLICOT IB01AD - preprocess the input-output data // -//////////////////////////////////////////////////////////////////////////////////// - - // arguments in - char meth_a; - char meth_b; - char alg; - char jobd; - char batch; - char conct; - char ctrl = 'N'; - - const Cell y_cell = args(0).cell_value (); - const Cell u_cell = args(1).cell_value (); - int nobr = args(2).int_value (); - int nuser = args(3).int_value (); - - const int imeth = args(4).int_value (); - const int ialg = args(5).int_value (); - const int iconct = args(6).int_value (); - const int ictrl = args(7).int_value (); // ignored - - double rcond = args(8).double_value (); - double tol_a = args(9).double_value (); - - double tol_b = rcond; - double tol_c = rcond; - - - switch (imeth) - { - case 0: - meth_a = 'M'; - meth_b = 'M'; - break; - case 1: - meth_a = 'N'; - meth_b = 'N'; - break; - case 2: - meth_a = 'N'; // no typo here - meth_b = 'C'; - break; - default: - error ("slib01ad: argument 'meth' invalid"); - } - - switch (ialg) - { - case 0: - alg = 'C'; - break; - case 1: - alg = 'F'; - break; - case 2: - alg = 'Q'; - break; - default: - error ("slib01ad: argument 'alg' invalid"); - } - - if (meth_a == 'M') - jobd = 'M'; - else // meth_a == 'N' - jobd = 'N'; // IB01AD.f says: This parameter is not relevant for METH = 'N' - - if (iconct == 0) - conct = 'C'; - else - conct = 'N'; -/* - if (ictrl == 0) - ctrl = 'C'; - else - ctrl = 'N'; -*/ - // m and l are equal for all experiments, checked by iddata class - int n_exp = y_cell.nelem (); // number of experiments - int m = u_cell.elem(0).columns (); // m: number of inputs - int l = y_cell.elem(0).columns (); // l: number of outputs - int nsmpl = 0; // total number of samples - - // arguments out - int n; - int ldr; - - if (meth_a == 'M' && jobd == 'M') - ldr = max (2*(m+l)*nobr, 3*m*nobr); - else if (meth_a == 'N' || (meth_a == 'M' && jobd == 'N')) - ldr = 2*(m+l)*nobr; - else - error ("slib01ad: could not handle 'ldr' case"); - - Matrix r (ldr, 2*(m+l)*nobr); - ColumnVector sv (l*nobr); - - - // repeat for every experiment in the dataset - for (int i = 0; i < n_exp; i++) - { - if (n_exp == 1) - batch = 'O'; // one block only - else if (i == 0) - batch = 'F'; // first block - else if (i == n_exp-1) - batch = 'L'; // last block - else - batch = 'I'; // intermediate block - - Matrix y = y_cell.elem(i).matrix_value (); - Matrix u = u_cell.elem(i).matrix_value (); - - // y.rows == u.rows is checked by iddata class - // int m = u.columns (); // m: number of inputs - // int l = y.columns (); // l: number of outputs - int nsmp = y.rows (); // nsmp: number of samples in the current experiment - nsmpl += nsmp; // nsmpl: total number of samples of all experiments - - // minimal nsmp size checked by __slicot_identification__.m - if (batch == 'O') - { - if (nsmp < 2*(m+l+1)*nobr - 1) - error ("slident: require NSMP >= 2*(M+L+1)*NOBR - 1"); - } - else - { - if (nsmp < 2*nobr) - error ("slident: require NSMP >= 2*NOBR"); - } - - int ldu; - - if (m == 0) - ldu = 1; - else // m > 0 - ldu = nsmp; - - int ldy = nsmp; - - // workspace - int liwork_a; - - if (meth_a == 'N') // if METH = 'N' - liwork_a = (m+l)*nobr; - else if (alg == 'F') // if METH = 'M' and ALG = 'F' - liwork_a = m+l; - else // if METH = 'M' and ALG = 'C' or 'Q' - liwork_a = 0; - - // TODO: Handle 'k' for DWORK - - int ldwork_a; - int ns = nsmp - 2*nobr + 1; - - if (alg == 'C') - { - if (batch == 'F' || batch == 'I') - { - if (conct == 'C') - ldwork_a = (4*nobr-2)*(m+l); - else // (conct == 'N') - ldwork_a = 1; - } - else if (meth_a == 'M') // && (batch == 'L' || batch == 'O') - { - if (conct == 'C' && batch == 'L') - ldwork_a = max ((4*nobr-2)*(m+l), 5*l*nobr); - else if (jobd == 'M') - ldwork_a = max ((2*m-1)*nobr, (m+l)*nobr, 5*l*nobr); - else // (jobd == 'N') - ldwork_a = 5*l*nobr; - } - else // meth_b == 'N' && (batch == 'L' || batch == 'O') - { - ldwork_a = 5*(m+l)*nobr + 1; - } - } - else if (alg == 'F') - { - if (batch != 'O' && conct == 'C') - ldwork_a = (m+l)*2*nobr*(m+l+3); - else if (batch == 'F' || batch == 'I') // && conct == 'N' - ldwork_a = (m+l)*2*nobr*(m+l+1); - else // (batch == 'L' || '0' && conct == 'N') - ldwork_a = (m+l)*4*nobr*(m+l+1)+(m+l)*2*nobr; - } - else // (alg == 'Q') - { - // int ns = nsmp - 2*nobr + 1; - - if (ldr >= ns && batch == 'F') - { - ldwork_a = 4*(m+l)*nobr; - } - else if (ldr >= ns && batch == 'O') - { - if (meth_a == 'M') - ldwork_a = max (4*(m+l)*nobr, 5*l*nobr); - else // (meth == 'N') - ldwork_a = 5*(m+l)*nobr + 1; - } - else if (conct == 'C' && (batch == 'I' || batch == 'L')) - { - ldwork_a = 4*(nobr+1)*(m+l)*nobr; - } - else // if ALG = 'Q', (BATCH = 'F' or 'O', and LDR < NS), or (BATCH = 'I' or 'L' and CONCT = 'N') - { - ldwork_a = 6*(m+l)*nobr; - } - } - - /* - IB01AD.f Lines 438-445 - C FURTHER COMMENTS - C - C For ALG = 'Q', BATCH = 'O' and LDR < NS, or BATCH <> 'O', the - C calculations could be rather inefficient if only minimal workspace - C (see argument LDWORK) is provided. It is advisable to provide as - C much workspace as possible. Almost optimal efficiency can be - C obtained for LDWORK = (NS+2)*(2*(M+L)*NOBR), assuming that the - C cache size is large enough to accommodate R, U, Y, and DWORK. - */ - - ldwork_a = max (ldwork_a, (ns+2)*(2*(m+l)*nobr)); - - /* - IB01AD.f Lines 291-195: - c the workspace used for alg = 'q' is - c ldrwrk*2*(m+l)*nobr + 4*(m+l)*nobr, - c where ldrwrk = ldwork/(2*(m+l)*nobr) - 2; recommended - c value ldrwrk = ns, assuming a large enough cache size. - c for good performance, ldwork should be larger. - - somehow ldrwrk and ldwork must have been mixed up here - - */ - - - OCTAVE_LOCAL_BUFFER (int, iwork_a, liwork_a); - OCTAVE_LOCAL_BUFFER (double, dwork_a, ldwork_a); - - // error indicators - int iwarn_a = 0; - int info_a = 0; - - - // SLICOT routine IB01AD - F77_XFCN (ib01ad, IB01AD, - (meth_a, alg, jobd, - batch, conct, ctrl, - nobr, m, l, - nsmp, - u.fortran_vec (), ldu, - y.fortran_vec (), ldy, - n, - r.fortran_vec (), ldr, - sv.fortran_vec (), - rcond, tol_a, - iwork_a, - dwork_a, ldwork_a, - iwarn_a, info_a)); - - - if (f77_exception_encountered) - error ("ident: exception in SLICOT subroutine IB01AD"); - - static const char* err_msg[] = { - "0: OK", - "1: a fast algorithm was requested (ALG = 'C', or 'F') " - "in sequential data processing, but it failed; the " - "routine can be repeatedly called again using the " - "standard QR algorithm", - "2: the singular value decomposition (SVD) algorithm did " - "not converge"}; - - static const char* warn_msg[] = { - "0: OK", - "1: the number of 100 cycles in sequential data " - "processing has been exhausted without signaling " - "that the last block of data was get; the cycle " - "counter was reinitialized", - "2: a fast algorithm was requested (ALG = 'C' or 'F'), " - "but it failed, and the QR algorithm was then used " - "(non-sequential data processing)", - "3: all singular values were exactly zero, hence N = 0 " - "(both input and output were identically zero)", - "4: the least squares problems with coefficient matrix " - "U_f, used for computing the weighted oblique " - "projection (for METH = 'N'), have a rank-deficient " - "coefficient matrix", - "5: the least squares problem with coefficient matrix " - "r_1 [6], used for computing the weighted oblique " - "projection (for METH = 'N'), has a rank-deficient " - "coefficient matrix"}; - - - error_msg ("ident: IB01AD", info_a, 2, err_msg); - warning_msg ("ident: IB01AD", iwarn_a, 5, warn_msg); - } - - - // resize - int rs = 2*(m+l)*nobr; - r.resize (rs, rs); - - - // return values - retval(0) = sv; - retval(1) = octave_value (n); - } - - return retval; -} Deleted: trunk/octave-forge/extra/control-devel/src/slib01cd.cc =================================================================== --- trunk/octave-forge/extra/control-devel/src/slib01cd.cc 2012-08-14 19:59:40 UTC (rev 10865) +++ trunk/octave-forge/extra/control-devel/src/slib01cd.cc 2012-08-14 20:01:58 UTC (rev 10866) @@ -1,200 +0,0 @@ -/* - -Copyright (C) 2012 Lukas F. Reichlin - -This file is part of LTI Syncope. - -LTI Syncope 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. - -LTI Syncope 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 LTI Syncope. If not, see <http://www.gnu.org/licenses/>. - -Compute initial state vector x0 -Uses IB01CD by courtesy of NICONET e.V. -<http://www.slicot.org> - -Author: Lukas Reichlin <luk...@gm...> -Created: May 2012 -Version: 0.1 - -*/ - -#include <octave/oct.h> -#include <octave/f77-fcn.h> -#include <octave/Cell.h> -#include "common.h" - -extern "C" -{ - int F77_FUNC (ib01cd, IB01CD) - (char& JOBX0, char& COMUSE, char& JOB, - int& N, int& M, int& L, - int& NSMP, - double* A, int& LDA, - double* B, int& LDB, - double* C, int& LDC, - double* D, int& LDD, - double* U, int& LDU, - double* Y, int& LDY, - double* X0, - double* V, int& LDV, - double& TOL, - int* IWORK, - double* DWORK, int& LDWORK, - int& IWARN, int& INFO); -} - -// PKG_ADD: autoload ("slib01cd", "devel_slicot_functions.oct"); -DEFUN_DLD (slib01cd, args, nargout, - "-*- texinfo -*-\n\ -Slicot IB01CD Release 5.0\n\ -No argument checking.\n\ -For internal use only.") -{ - int nargin = args.length (); - octave_value_list retval; - - if (nargin != 7) - { - print_usage (); - } - else - { - // arguments in - char jobx0 = 'X'; - char comuse = 'U'; - char jobbd = 'D'; - - const Cell y_cell = args(0).cell_value (); - const Cell u_cell = args(1).cell_value (); - - Matrix a = args(2).matrix_value (); - Matrix b = args(3).matrix_value (); - Matrix c = args(4).matrix_value (); - Matrix d = args(5).matrix_value (); - - double rcond = args(6).double_value (); - double tol_c = rcond; - - int n = a.rows (); // n: number of states - int m = b.columns (); // m: number of inputs - int l = c.rows (); // l: number of outputs - - int lda = max (1, n); - int ldb = max (1, n); - int ldc = max (1, l); - int ldd = max (1, l); - - // m and l are equal for all experiments, checked by iddata class - int n_exp = y_cell.nelem (); // number of experiments - - - // arguments out - Cell x0_cell (n_exp, 1); // cell of initial state vectors x0 - - // repeat for every experiment in the dataset - // compute individual initial state vector x0 for every experiment - for (int i = 0; i < n_exp; i++) - { - Matrix y = y_cell.elem(i).matrix_value (); - Matrix u = u_cell.elem(i).matrix_value (); - - int nsmp = y.rows (); // nsmp: number of samples - int ldv = max (1, n); - - int ldu; - - if (m == 0) - ldu = 1; - else // m > 0 - ldu = nsmp; - - int ldy = nsmp; - - // arguments out - ColumnVector x0 (n); - Matrix v (ldv, n); - - // workspace - int liwork_c = n; // if JOBX0 = 'X' and COMUSE <> 'C' - int ldwork_c; - int t = nsmp; - - int ldw1_c = 2; - int ldw2_c = t*l*(n + 1) + 2*n + max (2*n*n, 4*n); - int ldw3_c = n*(n + 1) + 2*n + max (n*l*(n + 1) + 2*n*n + l*n, 4*n); - - ldwork_c = ldw1_c + n*( n + m + l ) + max (5*n, ldw1_c, min (ldw2_c, ldw3_c)); - - OCTAVE_LOCAL_BUFFER (int, iwork_c, liwork_c); - OCTAVE_LOCAL_BUFFER (double, dwork_c, ldwork_c); - - // error indicators - int iwarn_c = 0; - int info_c = 0; - - // SLICOT routine IB01CD - F77_XFCN (ib01cd, IB01CD, - (jobx0, comuse, jobbd, - n, m, l, - nsmp, - a.fortran_vec (), lda, - b.fortran_vec (), ldb, - c.fortran_vec (), ldc, - d.fortran_vec (), ldd, - u.fortran_vec (), ldu, - y.fortran_vec (), ldy, - x0.fortran_vec (), - v.fortran_vec (), ldv, - tol_c, - iwork_c, - dwork_c, ldwork_c, - iwarn_c, info_c)); - - - if (f77_exception_encountered) - error ("slib01cd: exception in SLICOT subroutine IB01CD"); - - static const char* err_msg_c[] = { - "0: OK", - "1: the QR algorithm failed to compute all the " - "eigenvalues of the matrix A (see LAPACK Library " - "routine DGEES); the locations DWORK(i), for " - "i = g+1:g+N*N, contain the partially converged " - "Schur form", - "2: the singular value decomposition (SVD) algorithm did " - "not converge"}; - - static const char* warn_msg_c[] = { - "0: OK", - "1: warning message not specified", - "2: warning message not specified", - "3: warning message not specified", - "4: the least squares problem to be solved has a " - "rank-deficient coefficient matrix", - "5: warning message not specified", - "6: the matrix A is unstable; the estimated x(0) " - "and/or B and D could be inaccurate"}; - - - error_msg ("slib01cd", info_c, 2, err_msg_c); - warning_msg ("slib01cd", iwarn_c, 6, warn_msg_c); - - x0_cell.elem(i) = x0; // add x0 from the current experiment to cell of initial state vectors - } - - - // return values - retval(0) = x0_cell; - } - - return retval; -} Deleted: trunk/octave-forge/extra/control-devel/src/slident.cc =================================================================== --- trunk/octave-forge/extra/control-devel/src/slident.cc 2012-08-14 19:59:40 UTC (rev 10865) +++ trunk/octave-forge/extra/control-devel/src/slident.cc 2012-08-14 20:01:58 UTC (rev 10866) @@ -1,718 +0,0 @@ -/* - -Copyright (C) 2012 Lukas F. Reichlin - -This file is part of LTI Syncope. - -LTI Syncope 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. - -LTI Syncope 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 LTI Syncope. If not, see <http://www.gnu.org/licenses/>. - -SLICOT system identification -Uses SLICOT IB01AD, IB01BD and IB01CD by courtesy of NICONET e.V. -<http://www.slicot.org> - -Author: Lukas Reichlin <luk...@gm...> -Created: March 2012 -Version: 0.1 - -*/ - -#include <octave/oct.h> -#include <octave/f77-fcn.h> -#include <octave/Cell.h> -#include "common.h" - -extern "C" -{ - int F77_FUNC (ib01ad, IB01AD) - (char& METH, char& ALG, char& JOBD, - char& BATCH, char& CONCT, char& CTRL, - int& NOBR, int& M, int& L, - int& NSMP, - double* U, int& LDU, - double* Y, int& LDY, - int& N, - double* R, int& LDR, - double* SV, - double& RCOND, double& TOL, - int* IWORK, - double* DWORK, int& LDWORK, - int& IWARN, int& INFO); - - int F77_FUNC (ib01bd, IB01BD) - (char& METH, char& JOB, char& JOBCK, - int& NOBR, int& N, int& M, int& L, - int& NSMPL, - double* R, int& LDR, - double* A, int& LDA, - double* C, int& LDC, - double* B, int& LDB, - double* D, int& LDD, - double* Q, int& LDQ, - double* RY, int& LDRY, - double* S, int& LDS, - double* K, int& LDK, - double& TOL, - int* IWORK, - double* DWORK, int& LDWORK, - bool* BWORK, - int& IWARN, int& INFO); - - int F77_FUNC (ib01cd, IB01CD) - (char& JOBX0, char& COMUSE, char& JOB, - int& N, int& M, int& L, - int& NSMP, - double* A, int& LDA, - double* B, int& LDB, - double* C, int& LDC, - double* D, int& LDD, - double* U, int& LDU, - double* Y, int& LDY, - double* X0, - double* V, int& LDV, - double& TOL, - int* IWORK, - double* DWORK, int& LDWORK, - int& IWARN, int& INFO); -} - -// PKG_ADD: autoload ("slident", "devel_slicot_functions.oct"); -DEFUN_DLD (slident, args, nargout, - "-*- texinfo -*-\n\ -Slicot IB01AD Release 5.0\n\ -No argument checking.\n\ -For internal use only.") -{ - int nargin = args.length (); - octave_value_list retval; - - if (nargin != 10) - { - print_usage (); - } - else - { -//////////////////////////////////////////////////////////////////////////////////// -// SLICOT IB01AD - preprocess the input-output data // -//////////////////////////////////////////////////////////////////////////////////// - - // arguments in - char meth_a; - char meth_b; - char alg; - char jobd; - char batch; - char conct; - char ctrl; - - const Cell y_cell = args(0).cell_value (); - const Cell u_cell = args(1).cell_value (); - int nobr = args(2).int_value (); - int nuser = args(3).int_value (); - - const int imeth = args(4).int_value (); - const int ialg = args(5).int_value (); - const int iconct = args(6).int_value (); - const int ictrl = args(7).int_value (); - - double rcond = args(8).double_value (); - double tol_a = args(9).double_value (); - - double tol_b = rcond; - double tol_c = rcond; - - - switch (imeth) - { - case 0: - meth_a = 'M'; - meth_b = 'M'; - break; - case 1: - meth_a = 'N'; - meth_b = 'N'; - break; - case 2: - meth_a = 'N'; // no typo here - meth_b = 'C'; - break; - default: - error ("slib01ad: argument 'meth' invalid"); - } - - switch (ialg) - { - case 0: - alg = 'C'; - break; - case 1: - alg = 'F'; - break; - case 2: - alg = 'Q'; - break; - default: - error ("slib01ad: argument 'alg' invalid"); - } - - if (meth_a == 'M') - jobd = 'M'; - else // meth_a == 'N' - jobd = 'N'; // IB01AD.f says: This parameter is not relevant for METH = 'N' - - if (iconct == 0) - conct = 'C'; - else - conct = 'N'; - - if (ictrl == 0) - ctrl = 'C'; - else - ctrl = 'N'; - - // m and l are equal for all experiments, checked by iddata class - int n_exp = y_cell.nelem (); // number of experiments - int m = u_cell.elem(0).columns (); // m: number of inputs - int l = y_cell.elem(0).columns (); // l: number of outputs - int nsmpl = 0; // total number of samples - - // arguments out - int n; - int ldr; - - if (meth_a == 'M' && jobd == 'M') - ldr = max (2*(m+l)*nobr, 3*m*nobr); - else if (meth_a == 'N' || (meth_a == 'M' && jobd == 'N')) - ldr = 2*(m+l)*nobr; - else - error ("slib01ad: could not handle 'ldr' case"); - - Matrix r (ldr, 2*(m+l)*nobr); - ColumnVector sv (l*nobr); - - - // repeat for every experiment in the dataset - for (int i = 0; i < n_exp; i++) - { - if (n_exp == 1) - batch = 'O'; // one block only - else if (i == 0) - batch = 'F'; // first block - else if (i == n_exp-1) - batch = 'L'; // last block - else - batch = 'I'; // intermediate block - - Matrix y = y_cell.elem(i).matrix_value (); - Matrix u = u_cell.elem(i).matrix_value (); - - // y.rows == u.rows is checked by iddata class - // int m = u.columns (); // m: number of inputs - // int l = y.columns (); // l: number of outputs - int nsmp = y.rows (); // nsmp: number of samples in the current experiment - nsmpl += nsmp; // nsmpl: total number of samples of all experiments - - // minimal nsmp size checked by __slicot_identification__.m - if (batch == 'O') - { - if (nsmp < 2*(m+l+1)*nobr - 1) - error ("slident: require NSMP >= 2*(M+L+1)*NOBR - 1"); - } - else - { - if (nsmp < 2*nobr) - error ("slident: require NSMP >= 2*NOBR"); - } - - int ldu; - - if (m == 0) - ldu = 1; - else // m > 0 - ldu = nsmp; - - int ldy = nsmp; - - // workspace - int liwork_a; - - if (meth_a == 'N') // if METH = 'N' - liwork_a = (m+l)*nobr; - else if (alg == 'F') // if METH = 'M' and ALG = 'F' - liwork_a = m+l; - else // if METH = 'M' and ALG = 'C' or 'Q' - liwork_a = 0; - - // TODO: Handle 'k' for DWORK - - int ldwork_a; - int ns = nsmp - 2*nobr + 1; - - if (alg == 'C') - { - if (batch == 'F' || batch == 'I') - { - if (conct == 'C') - ldwork_a = (4*nobr-2)*(m+l); - else // (conct == 'N') - ldwork_a = 1; - } - else if (meth_a == 'M') // && (batch == 'L' || batch == 'O') - { - if (conct == 'C' && batch == 'L') - ldwork_a = max ((4*nobr-2)*(m+l), 5*l*nobr); - else if (jobd == 'M') - ldwork_a = max ((2*m-1)*nobr, (m+l)*nobr, 5*l*nobr); - else // (jobd == 'N') - ldwork_a = 5*l*nobr; - } - else // meth_b == 'N' && (batch == 'L' || batch == 'O') - { - ldwork_a = 5*(m+l)*nobr + 1; - } - } - else if (alg == 'F') - { - if (batch != 'O' && conct == 'C') - ldwork_a = (m+l)*2*nobr*(m+l+3); - else if (batch == 'F' || batch == 'I') // && conct == 'N' - ldwork_a = (m+l)*2*nobr*(m+l+1); - else // (batch == 'L' || '0' && conct == 'N') - ldwork_a = (m+l)*4*nobr*(m+l+1)+(m+l)*2*nobr; - } - else // (alg == 'Q') - { - // int ns = nsmp - 2*nobr + 1; - - if (ldr >= ns && batch == 'F') - { - ldwork_a = 4*(m+l)*nobr; - } - else if (ldr >= ns && batch == 'O') - { - if (meth_a == 'M') - ldwork_a = max (4*(m+l)*nobr, 5*l*nobr); - else // (meth == 'N') - ldwork_a = 5*(m+l)*nobr + 1; - } - else if (conct == 'C' && (batch == 'I' || batch == 'L')) - { - ldwork_a = 4*(nobr+1)*(m+l)*nobr; - } - else // if ALG = 'Q', (BATCH = 'F' or 'O', and LDR < NS), or (BATCH = 'I' or 'L' and CONCT = 'N') - { - ldwork_a = 6*(m+l)*nobr; - } - } - - /* - IB01AD.f Lines 438-445 - C FURTHER COMMENTS - C - C For ALG = 'Q', BATCH = 'O' and LDR < NS, or BATCH <> 'O', the - C calculations could be rather inefficient if only minimal workspace - C (see argument LDWORK) is provided. It is advisable to provide as - C much workspace as possible. Almost optimal efficiency can be - C obtained for LDWORK = (NS+2)*(2*(M+L)*NOBR), assuming that the - C cache size is large enough to accommodate R, U, Y, and DWORK. - */ - - ldwork_a = max (ldwork_a, (ns+2)*(2*(m+l)*nobr)); - - /* - IB01AD.f Lines 291-195: - c the workspace used for alg = 'q' is - c ldrwrk*2*(m+l)*nobr + 4*(m+l)*nobr, - c where ldrwrk = ldwork/(2*(m+l)*nobr) - 2; recommended - c value ldrwrk = ns, assuming a large enough cache size. - c for good performance, ldwork should be larger. - - somehow ldrwrk and ldwork must have been mixed up here - - */ - - - OCTAVE_LOCAL_BUFFER (int, iwork_a, liwork_a); - OCTAVE_LOCAL_BUFFER (double, dwork_a, ldwork_a); - - // error indicators - int iwarn_a = 0; - int info_a = 0; - - - // SLICOT routine IB01AD - F77_XFCN (ib01ad, IB01AD, - (meth_a, alg, jobd, - batch, conct, ctrl, - nobr, m, l, - nsmp, - u.fortran_vec (), ldu, - y.fortran_vec (), ldy, - n, - r.fortran_vec (), ldr, - sv.fortran_vec (), - rcond, tol_a, - iwork_a, - dwork_a, ldwork_a, - iwarn_a, info_a)); - - - if (f77_exception_encountered) - error ("ident: exception in SLICOT subroutine IB01AD"); - - static const char* err_msg[] = { - "0: OK", - "1: a fast algorithm was requested (ALG = 'C', or 'F') " - "in sequential data processing, but it failed; the " - "routine can be repeatedly called again using the " - "standard QR algorithm", - "2: the singular value decomposition (SVD) algorithm did " - "not converge"}; - - static const char* warn_msg[] = { - "0: OK", - "1: the number of 100 cycles in sequential data " - "processing has been exhausted without signaling " - "that the last block of data was get; the cycle " - "counter was reinitialized", - "2: a fast algorithm was requested (ALG = 'C' or 'F'), " - "but it failed, and the QR algorithm was then used " - "(non-sequential data processing)", - "3: all singular values were exactly zero, hence N = 0 " - "(both input and output were identically zero)", - "4: the least squares problems with coefficient matrix " - "U_f, used for computing the weighted oblique " - "projection (for METH = 'N'), have a rank-deficient " - "coefficient matrix", - "5: the least squares problem with coefficient matrix " - "r_1 [6], used for computing the weighted oblique " - "projection (for METH = 'N'), has a rank-deficient " - "coefficient matrix"}; - - - error_msg ("ident: IB01AD", info_a, 2, err_msg); - warning_msg ("ident: IB01AD", iwarn_a, 5, warn_msg); - } - - - // resize - int rs = 2*(m+l)*nobr; - r.resize (rs, rs); - - if (nuser > 0) - { - if (nuser < nobr) - { - n = nuser; - // warning ("ident: nuser (%d) < nobr (%d), n = nuser", nuser, nobr); - } - else - error ("ident: 'nuser' invalid"); - } - -//////////////////////////////////////////////////////////////////////////////////// -// SLICOT IB01BD - estimating system matrices, Kalman gain, and covariances // -//////////////////////////////////////////////////////////////////////////////////// - - // arguments in - char job = 'A'; - char jobck = 'K'; - - //int nsmpl = nsmp; - - if (nsmpl < 2*(m+l)*nobr) - error ("slident: nsmpl (%d) < 2*(m+l)*nobr (%d)", nsmpl, nobr); - - // arguments out - int lda = max (1, n); - int ldc = max (1, l); - int ldb = max (1, n); - int ldd = max (1, l); - int ldq = n; // if JOBCK = 'C' or 'K' - int ldry = l; // if JOBCK = 'C' or 'K' - int lds = n; // if JOBCK = 'C' or 'K' - int ldk = n; // if JOBCK = 'K' - - Matrix a (lda, n); - Matrix c (ldc, n); - Matrix b (ldb, m); - Matrix d (ldd, m); - - Matrix q (ldq, n); - Matrix ry (ldry, l); - Matrix s (lds, l); - Matrix k (ldk, l); - - // workspace - int liwork_b; - int liw1; - int liw2; - - liw1 = max (n, m*nobr+n, l*nobr, m*(n+l)); - liw2 = n*n; // if JOBCK = 'K' - liwork_b = max (liw1, liw2); - - int ldwork_b; - int ldw1; - int ldw2; - int ldw3; - - if (meth_b == 'M') - { - int ldw1a = max (2*(l*nobr-l)*n+2*n, (l*nobr-l)*n+n*n+7*n); - int ldw1b = max (2*(l*nobr-l)*n+n*n+7*n, - (l*nobr-l)*n+n+6*m*nobr, - (l*nobr-l)*n+n+max (l+m*nobr, l*nobr + max (3*l*nobr+1, m))); - ldw1 = max (ldw1a, ldw1b); - - int aw; - - if (m == 0 || job == 'C') - aw = n + n*n; - else - aw = 0; - - ldw2 = l*nobr*n + max ((l*nobr-l)*n+aw+2*n+max(5*n,(2*m+l)*nobr+l), 4*(m*nobr+n)+1, m*nobr+2*n+l ); - } - else if (meth_b == 'N') - { - ldw1 = l*nobr*n + max ((l*nobr-l)*n+2*n+(2*m+l)*nobr+l, - 2*(l*nobr-l)*n+n*n+8*n, - n+4*(m*nobr+n)+1, - m*nobr+3*n+l); - - if (m == 0 || job == 'C') - ldw2 = 0; - else - ldw2 = l*nobr*n+m*nobr*(n+l)*(m*(n+l)+1)+ max ((n+l)*(n+l), 4*m*(n+l)+1); - - } - else // (meth_b == 'C') - { - int ldw1a = max (2*(l*nobr-l)*n+2*n, (l*nobr-l)*n+n*n+7*n); - int ldw1b = l*nobr*n + max ((l*nobr-l)*n+2*n+(2*m+l)*nobr+l, - 2*(l*nobr-l)*n+n*n+8*n, - n+4*(m*nobr+n)+1, - m*nobr+3*n+l); - - ldw1 = max (ldw1a, ldw1b); - - ldw2 = l*nobr*n+m*nobr*(n+l)*(m*(n+l)+1)+ max ((n+l)*(n+l), 4*m*(n+l)+1); - - } - - ldw3 = max(4*n*n + 2*n*l + l*l + max (3*l, n*l), 14*n*n + 12*n + 5); - ldwork_b = max (ldw1, ldw2, ldw3); - - - OCTAVE_LOCAL_BUFFER (int, iwork_b, liwork_b); - OCTAVE_LOCAL_BUFFER (double, dwork_b, ldwork_b); - OCTAVE_LOCAL_BUFFER (bool, bwork, 2*n); - - - // error indicators - int iwarn_b = 0; - int info_b = 0; - - - // SLICOT routine IB01BD - F77_XFCN (ib01bd, IB01BD, - (meth_b, job, jobck, - nobr, n, m, l, - nsmpl, - r.fortran_vec (), ldr, - a.fortran_vec (), lda, - c.fortran_vec (), ldc, - b.fortran_vec (), ldb, - d.fortran_vec (), ldd, - q.fortran_vec (), ldq, - ry.fortran_vec (), ldry, - s.fortran_vec (), lds, - k.fortran_vec (), ldk, - tol_b, - iwork_b, - dwork_b, ldwork_b, - bwork, - iwarn_b, info_b)); - - - if (f77_exception_encountered) - error ("ident: exception in SLICOT subroutine IB01BD"); - - static const char* err_msg_b[] = { - "0: OK", - "1: error message not specified", - "2: the singular value decomposition (SVD) algorithm did " - "not converge", - "3: a singular upper triangular matrix was found", - "4: matrix A is (numerically) singular in discrete-" - "time case", - "5: the Hamiltonian or symplectic matrix H cannot be " - "reduced to real Schur form", - "6: the real Schur form of the Hamiltonian or " - "symplectic matrix H cannot be appropriately ordered", - "7: the Hamiltonian or symplectic matrix H has less " - "than N stable eigenvalues", - "8: the N-th order system of linear algebraic " - "equations, from which the solution matrix X would " - "be obtained, is singular to working precision", - "9: the QR algorithm failed to complete the reduction " - "of the matrix Ac to Schur canonical form, T", - "10: the QR algorithm did not converge"}; - - static const char* warn_msg_b[] = { - "0: OK", - "1: warning message not specified", - "2: warning message not specified", - "3: warning message not specified", - "4: a least squares problem to be solved has a " - "rank-deficient coefficient matrix", - "5: the computed covariance matrices are too small. " - "The problem seems to be a deterministic one; the " - "gain matrix is set to zero"}; - - - error_msg ("ident: IB01BD", info_b, 10, err_msg_b); - warning_msg ("ident: IB01BD", iwarn_b, 5, warn_msg_b); - - // resize - a.resize (n, n); - c.resize (l, n); - b.resize (n, m); - d.resize (l, m); - - q.resize (n, n); - ry.resize (l, l); - s.resize (n, l); - k.resize (n, l); - -//////////////////////////////////////////////////////////////////////////////////// -// SLICOT IB01CD - estimating the initial state // -//////////////////////////////////////////////////////////////////////////////////// - - // arguments in - char jobx0 = 'X'; - char comuse = 'U'; - char jobbd = 'D'; - - // arguments out - Cell x0_cell (n_exp, 1); // cell of initial state vectors x0 - - // repeat for every experiment in the dataset - // compute individual initial state vector x0 for every experiment - for (int i = 0; i < n_exp; i++) - { - Matrix y = y_cell.elem(i).matrix_value (); - Matrix u = u_cell.elem(i).matrix_value (); - - int nsmp = y.rows (); // nsmp: number of samples - int ldv = max (1, n); - - int ldu; - - if (m == 0) - ldu = 1; - else // m > 0 - ldu = nsmp; - - int ldy = nsmp; - - // arguments out - ColumnVector x0 (n); - Matrix v (ldv, n); - - // workspace - int liwork_c = n; // if JOBX0 = 'X' and COMUSE <> 'C' - int ldwork_c; - int t = nsmp; - - int ldw1_c = 2; - int ldw2_c = t*l*(n + 1) + 2*n + max (2*n*n, 4*n); - int ldw3_c = n*(n + 1) + 2*n + max (n*l*(n + 1) + 2*n*n + l*n, 4*n); - - ldwork_c = ldw1_c + n*( n + m + l ) + max (5*n, ldw1_c, min (ldw2_c, ldw3_c)); - - OCTAVE_LOCAL_BUFFER (int, iwork_c, liwork_c); - OCTAVE_LOCAL_BUFFER (double, dwork_c, ldwork_c); - - // error indicators - int iwarn_c = 0; - int info_c = 0; - - // SLICOT routine IB01CD - F77_XFCN (ib01cd, IB01CD, - (jobx0, comuse, jobbd, - n, m, l, - nsmp, - a.fortran_vec (), lda, - b.fortran_vec (), ldb, - c.fortran_vec (), ldc, - d.fortran_vec (), ldd, - u.fortran_vec (), ldu, - y.fortran_vec (), ldy, - x0.fortran_vec (), - v.fortran_vec (), ldv, - tol_c, - iwork_c, - dwork_c, ldwork_c, - iwarn_c, info_c)); - - - if (f77_exception_encountered) - error ("ident: exception in SLICOT subroutine IB01CD"); - - static const char* err_msg_c[] = { - "0: OK", - "1: the QR algorithm failed to compute all the " - "eigenvalues of the matrix A (see LAPACK Library " - "routine DGEES); the locations DWORK(i), for " - "i = g+1:g+N*N, contain the partially converged " - "Schur form", - "2: the singular value decomposition (SVD) algorithm did " - "not converge"}; - - static const char* warn_msg_c[] = { - "0: OK", - "1: warning message not specified", - "2: warning message not specified", - "3: warning message not specified", - "4: the least squares problem to be solved has a " - "rank-deficient coefficient matrix", - "5: warning message not specified", - "6: the matrix A is unstable; the estimated x(0) " - "and/or B and D could be inaccurate"}; - - - error_msg ("ident: IB01CD", info_c, 2, err_msg_c); - warning_msg ("ident: IB01CD", iwarn_c, 6, warn_msg_c); - - x0_cell.elem(i) = x0; // add x0 from the current experiment to cell of initial state vectors - } - - - // return values - retval(0) = a; - retval(1) = b; - retval(2) = c; - retval(3) = d; - - retval(4) = q; - retval(5) = ry; - retval(6) = s; - retval(7) = k; - - retval(8) = x0_cell; - } - - return retval; -} Copied: trunk/octave-forge/main/control/src/is_matrix.cc (from rev 10864, trunk/octave-forge/extra/control-devel/src/is_matrix.cc) =================================================================== --- trunk/octave-forge/main/control/src/is_matrix.cc (rev 0) +++ trunk/octave-forge/main/control/src/is_matrix.cc 2012-08-14 20:01:58 UTC (rev 10866) @@ -0,0 +1,60 @@ +/* + +Copyright (C) 2012 Lukas F. Reichlin + +This file is part of LTI Syncope. + +LTI Syncope 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. + +LTI Syncope 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 LTI Syncope. If not, see <http://www.gnu.org/licenses/>. + +Return true if argument is a real matrix. + +Author: Lukas Reichlin <luk...@gm...> +Created: June 2012 +Version: 0.1 + +*/ + +#include <octave/oct.h> + +DEFUN_DLD (is_matrix, args, nargout, + "-*- texinfo -*-\n\ +@deftypefn {Loadable Function} {} is_matrix (@var{a}, @dots{})\n\ +Return true if argument is a matrix.\n\ +@var{[]} is a valid matrix.\n\ +Avoid nasty stuff like @code{true = isreal (\"a\")}\n\ +@seealso{is_real_matrix, is_real_square_matrix, is_real_vector, is_real_scalar}\n\ +@end deftypefn") +{ + octave_value retval = true; + int nargin = args.length (); + + if (nargin == 0) + { + print_usage (); + } + else + { + for (int i = 0; i < nargin; i++) + { + if (args(i).ndims () != 2 || ! args(i).is_numeric_type () + || ! (args(i).is_complex_type () || args(i).is_real_type ())) + { + retval = false; + break; + } + } + } + + return retval; +} Copied: trunk/octave-forge/main/control/src/slib01ad.cc (from rev 10864, trunk/octave-forge/extra/control-devel/src/slib01ad.cc) =================================================================== --- trunk/octave-forge/main/control/src/slib01ad.cc (rev 0) +++ trunk/octave-forge/main/control/src/slib01ad.cc 2012-08-14 20:01:58 UTC (rev 10866) @@ -0,0 +1,383 @@ +/* + +Copyright (C) 2012 Lukas F. Reichlin + +This file is part of LTI Syncope. + +LTI Syncope 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. + +LTI Syncope 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 LTI Syncope. If not, see <http://www.gnu.org/licenses/>. + +SLICOT system identification +Uses SLICOT IB01AD, IB01BD and IB01CD by courtesy of NICONET e.V. +<http://www.slicot.org> + +Author: Lukas Reichlin <luk...@gm...> +Created: March 2012 +Version: 0.1 + +*/ + +#include <octave/oct.h> +#include <octave/f77-fcn.h> +#include <octave/Cell.h> +#include "common.h" + +extern "C" +{ + int F77_FUNC (ib01ad, IB01AD) + (char& METH, char& ALG, char& JOBD, + char& BATCH, char& CONCT, char& CTRL, + int& NOBR, int& M, int& L, + int& NSMP, + double* U, int& LDU, + double* Y, int& LDY, + int& N, + double* R, int& LDR, + double* SV, + double& RCOND, double& TOL, + int* IWORK, + double* DWORK, int& LDWORK, + int& IWARN, int& INFO); +} + +// PKG_ADD: autoload ("slib01ad", "devel_slicot_functions.oct"); +DEFUN_DLD (slib01ad, args, nargout, + "-*- texinfo -*-\n\ +Slicot IB01AD Release 5.0\n\ +No argument checking.\n\ +For internal use only.") +{ + int nargin = args.length (); + octave_value_list retval; + + if (nargin != 10) + { + print_usage (); + } + else + { +//////////////////////////////////////////////////////////////////////////////////// +// SLICOT IB01AD - preprocess the input-output data // +//////////////////////////////////////////////////////////////////////////////////// + + // arguments in + char meth_a; + char meth_b; + char alg; + char jobd; + char batch; + char conct; + char ctrl = 'N'; + + const Cell y_cell = args(0).cell_value (); + const Cell u_cell = args(1).cell_value (); + int nobr = args(2).int_value (); + int nuser = args(3).int_value (); + + const int imeth = args(4).int_value (); + const int ialg = args(5).int_value (); + const int iconct = args(6).int_value (); + const int ictrl = args(7).int_value (); // ignored + + double rcond = args(8).double_value (); + double tol_a = args(9).double_value (); + + double tol_b = rcond; + double tol_c = rcond; + + + switch (imeth) + { + case 0: + meth_a = 'M'; + meth_b = 'M'; + break; + case 1: + meth_a = 'N'; + meth_b = 'N'; + break; + case 2: + meth_a = 'N'; // no typo here + meth_b = 'C'; + break; + default: + error ("slib01ad: argument 'meth' invalid"); + } + + switch (ialg) + { + case 0: + alg = 'C'; + break; + case 1: + alg = 'F'; + break; + case 2: + alg = 'Q'; + break; + default: + error ("slib01ad: argument 'alg' invalid"); + } + + if (meth_a == 'M') + jobd = 'M'; + else // meth_a == 'N' + jobd = 'N'; // IB01AD.f says: This parameter is not relevant for METH = 'N' + + if (iconct == 0) + conct = 'C'; + else + conct = 'N'; +/* + if (ictrl == 0) + ctrl = 'C'; + else + ctrl = 'N'; +*/ + // m and l are equal for all experiments, checked by iddata class + int n_exp = y_cell.nelem (); // number of experiments + int m = u_cell.elem(0).columns (); // m: number of inputs + int l = y_cell.elem(0).columns (); // l: number of outputs + int nsmpl = 0; // total number of samples + + // arguments out + int n; + int ldr; + + if (meth_a == 'M' && jobd == 'M') + ldr = max (2*(m+l)*nobr, 3*m*nobr); + else if (meth_a == 'N' || (meth_a == 'M' && jobd == 'N')) + ldr = 2*(m+l)*nobr; + else + error ("slib01ad: could not handle 'ldr' case"); + + Matrix r (ldr, 2*(m+l)*nobr); + ColumnVector sv (l*nobr); + + + // repeat for every experiment in the dataset + for (int i = 0; i < n_exp; i++) + { + if (n_exp == 1) + batch = 'O'; // one block only + else if (i == 0) + batch = 'F'; // first block + else if (i == n_exp-1) + batch = 'L'; // last block + else + batch = 'I'; // intermediate block + + Matrix y = y_cell.elem(i).matrix_value (); + Matrix u = u_cell.elem(i).matrix_value (); + + // y.rows == u.rows is checked by iddata class + // int m = u.columns (); // m: number of inputs + // int l = y.columns (); // l: number of outputs + int nsmp = y.rows (); // nsmp: number of samples in the current experiment + nsmpl += nsmp; // nsmpl: total number of samples of all experiments + + // minimal nsmp size checked by __slicot_identification__.m + if (batch == 'O') + { + if (nsmp < 2*(m+l+1)*nobr - 1) + error ("slident: require NSMP >= 2*(M+L+1)*NOBR - 1"); + } + else + { + if (nsmp < 2*nobr) + error ("slident: require NSMP >= 2*NOBR"); + } + + int ldu; + + if (m == 0) + ldu = 1; + else // m > 0 + ldu = nsmp; + + int ldy = nsmp; + + // workspace + int liwork_a; + + if (meth_a == 'N') // if METH = 'N' + liwork_a = (m+l)*nobr; + else if (alg == 'F') // if METH = 'M' and ALG = 'F' + liwork_a = m+l; + else // if METH = 'M' and ALG = 'C' or 'Q' + liwork_a = 0; + + // TODO: Handle 'k' for DWORK + + int ldwork_a; + int ns = nsmp - 2*nobr + 1; + + if (alg == 'C') + { + if (batch == 'F' || batch == 'I') + { + if (conct == 'C') + ldwork_a = (4*nobr-2)*(m+l); + else // (conct == 'N') + ldwork_a = 1; + } + else if (meth_a == 'M') // && (batch == 'L' || batch == 'O') + { + if (conct == 'C' && batch == 'L') + ldwork_a = max ((4*nobr-2)*(m+l), 5*l*nobr); + else if (jobd == 'M') + ldwork_a = max ((2*m-1)*nobr, (m+l)*nobr, 5*l*nobr); + else // (jobd == 'N') + ldwork_a = 5*l*nobr; + } + else // meth_b == 'N' && (batch == 'L' || batch == 'O') + { + ldwork_a = 5*(m+l)*nobr + 1; + } + } + else if (alg == 'F') + { + if (batch != 'O' && conct == 'C') + ldwork_a = (m+l)*2*nobr*(m+l+3); + else if (batch == 'F' || batch == 'I') // && conct == 'N' + ldwork_a = (m+l)*2*nobr*(m+l+1); + else // (batch == 'L' || '0' && conct == 'N') + l... [truncated message content] |
From: <par...@us...> - 2012-08-14 19:59:49
|
Revision: 10865 http://octave.svn.sourceforge.net/octave/?rev=10865&view=rev Author: paramaniac Date: 2012-08-14 19:59:40 +0000 (Tue, 14 Aug 2012) Log Message: ----------- extra/control-devel ---> main/control Added Paths: ----------- trunk/octave-forge/main/control/inst/@iddata/ trunk/octave-forge/main/control/inst/__adjust_iddata__.m trunk/octave-forge/main/control/inst/__adjust_iddata_tsam__.m trunk/octave-forge/main/control/inst/__iddata_dim__.m trunk/octave-forge/main/control/inst/__slicot_identification__.m trunk/octave-forge/main/control/inst/arx.m trunk/octave-forge/main/control/inst/moen4.m trunk/octave-forge/main/control/inst/moesp.m trunk/octave-forge/main/control/inst/n4sid.m Removed Paths: ------------- trunk/octave-forge/extra/control-devel/inst/@iddata/ trunk/octave-forge/extra/control-devel/inst/__adjust_iddata__.m trunk/octave-forge/extra/control-devel/inst/__adjust_iddata_tsam__.m trunk/octave-forge/extra/control-devel/inst/__iddata_dim__.m trunk/octave-forge/extra/control-devel/inst/__slicot_identification__.m trunk/octave-forge/extra/control-devel/inst/arx.m trunk/octave-forge/extra/control-devel/inst/moen4.m trunk/octave-forge/extra/control-devel/inst/moesp.m trunk/octave-forge/extra/control-devel/inst/n4sid.m Deleted: trunk/octave-forge/extra/control-devel/inst/__adjust_iddata__.m =================================================================== --- trunk/octave-forge/extra/control-devel/inst/__adjust_iddata__.m 2012-08-14 19:32:00 UTC (rev 10864) +++ trunk/octave-forge/extra/control-devel/inst/__adjust_iddata__.m 2012-08-14 19:59:40 UTC (rev 10865) @@ -1,38 +0,0 @@ -## Copyright (C) 2012 Lukas F. Reichlin -## -## This file is part of LTI Syncope. -## -## LTI Syncope 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. -## -## LTI Syncope 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 LTI Syncope. If not, see <http://www.gnu.org/licenses/>. - -## Author: Lukas Reichlin <luk...@gm...> -## Created: February 2012 -## Version: 0.1 - -function [y, u] = __adjust_iddata__ (y, u) - - if (iscell (y)) - y = reshape (y, [], 1); - else - y = {y}; - endif - - if (isempty (u)) - u = {}; # avoid [](nx0) and the like - elseif (iscell (u)) - u = reshape (u, [], 1); - else - u = {u}; - endif - -endfunction Deleted: trunk/octave-forge/extra/control-devel/inst/__adjust_iddata_tsam__.m =================================================================== --- trunk/octave-forge/extra/control-devel/inst/__adjust_iddata_tsam__.m 2012-08-14 19:32:00 UTC (rev 10864) +++ trunk/octave-forge/extra/control-devel/inst/__adjust_iddata_tsam__.m 2012-08-14 19:59:40 UTC (rev 10865) @@ -1,52 +0,0 @@ -## Copyright (C) 2012 Lukas F. Reichlin -## -## This file is part of LTI Syncope. -## -## LTI Syncope 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. -## -## LTI Syncope 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 LTI Syncope. If not, see <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## Check whether tsam is a e-by-1 cell array of valid sampling times. -## If not, it tries to convert tsam accordingly. -## Empty tsam are filled with default value -1. - -## Author: Lukas Reichlin <luk...@gm...> -## Created: February 2012 -## Version: 0.1 - -function tsam = __adjust_iddata_tsam__ (tsam, e) - - if (isempty (tsam)) - tsam = num2cell (-ones (e, 1)); - elseif (iscell (tsam)) - tsam = reshape (tsam, [], 1); - else - tsam = {tsam}; - endif - - tmp = cellfun (@(x) issample (x, -1), tsam); - - if (any (! tmp)) - error ("iddata: invalid sampling time"); - endif - - nt = numel (tsam); - - if (nt == 1 && e > 1) - tsam = repmat (tsam, e, 1); - elseif (nt != e) - error ("iddata: there are %d experiments, but only %d sampling times", \ - e, nt); - endif - -endfunction Deleted: trunk/octave-forge/extra/control-devel/inst/__iddata_dim__.m =================================================================== --- trunk/octave-forge/extra/control-devel/inst/__iddata_dim__.m 2012-08-14 19:32:00 UTC (rev 10864) +++ trunk/octave-forge/extra/control-devel/inst/__iddata_dim__.m 2012-08-14 19:59:40 UTC (rev 10865) @@ -1,53 +0,0 @@ -## Author: Lukas Reichlin <luk...@gm...> -## Created: October 2011 -## Version: 0.1 - -function [p, m, e] = __iddata_dim__ (y, u) - - e = numel (y); # number of experiments - - if (isempty (u)) # time series data, outputs only - [p, m] = cellfun (@__experiment_dim__, y, "uniformoutput", false); - elseif (e == numel (u)) # outputs and inputs present - [p, m] = cellfun (@__experiment_dim__, y, u, "uniformoutput", false); - else - error ("iddata: require input and output data with matching number of experiments"); - endif - - if (e > 1 && ! isequal (p{:})) - error ("iddata: require identical number of output channels for all experiments"); - endif - - if (e > 1 && ! isequal (m{:})) - error ("iddata: require identical number of input channels for all experiments"); - endif - - p = p{1}; - m = m{1}; - -endfunction - - -function [p, m] = __experiment_dim__ (y, u = []) - - if (! is_matrix (y, u)) - error ("iddata: inputs and outputs must be real or complex matrices"); - endif - - [ly, p] = size (y); - [lu, m] = size (u); - - if (! isempty (u) && ly != lu) - error ("iddata: matrices 'y' (%dx%d) and 'u' (%dx%d) must have the same number of samples (rows)", \ - ly, p, lu, m); - endif - - if (ly < p) - warning ("iddata: more outputs than samples - matrice 'y' should probably be transposed"); - endif - - if (lu < m) - warning ("iddata: more inputs than samples - matrice 'u' should probably be transposed"); - endif - -endfunction Deleted: trunk/octave-forge/extra/control-devel/inst/__slicot_identification__.m =================================================================== --- trunk/octave-forge/extra/control-devel/inst/__slicot_identification__.m 2012-08-14 19:32:00 UTC (rev 10864) +++ trunk/octave-forge/extra/control-devel/inst/__slicot_identification__.m 2012-08-14 19:59:40 UTC (rev 10865) @@ -1,231 +0,0 @@ -## Copyright (C) 2012 Lukas F. Reichlin -## -## This file is part of LTI Syncope. -## -## LTI Syncope 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. -## -## LTI Syncope 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 LTI Syncope. If not, see <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn{Function File} {[@var{sys}, @var{x0}], @var{info} =} __slicot_identification__ (@var{method}, @var{dat}, @dots{}) -## Backend for moesp, moen4 and n4sid. -## @end deftypefn - -## Author: Lukas Reichlin <luk...@gm...> -## Created: May 2012 -## Version: 0.1 - -function [sys, x0, info] = __slicot_identification__ (method, nout, dat, varargin) - - ## determine identification method - switch (method) - case "moesp" - meth = 0; - case "n4sid" - meth = 1; - case "moen4" - meth = 2; - otherwise - error ("ident: invalid method"); # should never happen - endswitch - - if (! isa (dat, "iddata") || ! dat.timedomain) - error ("%s: first argument must be a time-domain 'iddata' dataset", method); - endif - - if (nargin > 3) # ident (dat, ...) - if (is_real_scalar (varargin{1})) # ident (dat, n, ...) - varargin = horzcat (varargin(2:end), {"order"}, varargin(1)); - endif - if (isstruct (varargin{1})) # ident (dat, opt, ...), ident (dat, n, opt, ...) - varargin = horzcat (__opt2cell__ (varargin{1}), varargin(2:end)); - endif - endif - - nkv = numel (varargin); # number of keys and values - - if (rem (nkv, 2)) - error ("%s: keys and values must come in pairs", method); - endif - - [ns, p, m, e] = size (dat); # dataset dimensions - tsam = dat.tsam; - - ## multi-experiment data requires equal sampling times - if (e > 1 && ! isequal (tsam{:})) - error ("%s: require equally sampled experiments", method); - else - tsam = tsam{1}; - endif - - ## default arguments - alg = 0; - conct = 1; # no connection between experiments - ctrl = 1; # don't confirm order n - rcond = 0.0; - tol = 0.0; # -1.0; - s = []; - n = []; - conf = []; - noise = "n"; - - ## handle keys and values - for k = 1 : 2 : nkv - key = lower (varargin{k}); - val = varargin{k+1}; - switch (key) - case {"n", "order"} - if (! issample (val, 0) || val != round (val)) - error ("%s: 'n' must be a positive integer", method); - endif - n = val; - case "s" - if (! issample (val, 0) || val != round (val)) - error ("%s: 's' must be a positive integer", method); - endif - s = val; - case {"alg", "algorithm"} - if (strncmpi (val, "c", 1)) - alg = 0; # Cholesky algorithm applied to correlation matrix - elseif (strncmpi (val, "f", 1)) - alg = 1; # fast QR algorithm - elseif (strncmpi (val, "q", 1)) - alg = 2; # QR algorithm applied to block Hankel matrices - else - error ("%s: invalid algorithm", method); - endif - case "tol" - if (! is_real_scalar (val)) - error ("%s: tolerance 'tol' must be a real scalar", method); - endif - tol = val; - case "rcond" - if (! is_real_scalar (val)) - error ("%s: 'rcond' must be a real scalar", method); - endif - rcond = val; - case "confirm" - conf = logical (val); - case {"input", "inputs"} - noise = val; - otherwise - warning ("%s: invalid property name '%s' ignored", method, key); - endswitch - endfor - - - ## handle s/nobr and n - nsmp = sum (ns); # total number of samples - nobr = fix ((nsmp+1)/(2*(m+p+1))); - if (e > 1) - nobr = min (nobr, fix (min (ns) / 2)); - endif - - if (isempty (s) && isempty (n)) - ctrl = 0; # confirm system order estimate - n = 0; - elseif (isempty (s)) - s = min (2*n, n+10); # upper bound for n - nobr = min (nobr, s); - elseif (isempty (n)) - nobr = __check_s__ (s, nobr, method); - ctrl = 0; # confirm system order estimate - n = 0; - else # s & n non-empty - nobr = __check_s__ (s, nobr, method); - if (n >= nobr) - error ("%s: n=%d, but require n < %d (s)", method, n, nobr); - endif - endif - - if (! isempty (conf)) - ctrl = ! conf; - endif - - if (nout == 0) - ## compute singular values - [sv, nrec] = slib01ad (dat.y, dat.u, nobr, n, meth, alg, conct, ctrl, rcond, tol); - - ## there is no 'logbar' function - svl = log10 (sv); - base = floor (min (svl)); - - clf - bar (svl, "basevalue", base) - xlim ([0, length(sv)+1]) - yl = ylim; - ylim ([base, yl(2)]) - title ("Singular Values") - ylabel ("Logarithm of Singular Values") - xlabel (sprintf ("Estimated System Order with current Tolerance: %d", nrec)) - grid on - else - ## perform system identification - [a, b, c, d, q, ry, s, k, x0] = slident (dat.y, dat.u, nobr, n, meth, alg, conct, ctrl, rcond, tol); - - ## compute noise variance matrix factor L - ## L L' = Ry, e = L v - ## v becomes white noise with identity covariance matrix - l = chol (ry, "lower"); - - ## assemble model - [inname, outname] = get (dat, "inname", "outname"); - if (strncmpi (noise, "e", 1)) # add error inputs e, not normalized - sys = ss (a, [b, k], c, [d, eye(p)], tsam); - in_u = __labels__ (inname, "u"); - in_e = __labels__ (outname, "y"); - in_e = cellfun (@(x) ["e@", x], in_e, "uniformoutput", false); - inname = [in_u; in_e]; - elseif (strncmpi (noise, "v", 1)) # add error inputs v, normalized - sys = ss (a, [b, k*l], c, [d, l], tsam); - in_u = __labels__ (inname, "u"); - in_v = __labels__ (outname, "y"); - in_v = cellfun (@(x) ["v@", x], in_v, "uniformoutput", false); - inname = [in_u; in_v]; - elseif (strncmpi (noise, "k", 1)) # Kalman predictor - sys = ss ([a-k*c], [b-k*d, k], c, [d, zeros(p)], tsam); - in_u = __labels__ (inname, "u"); - in_y = __labels__ (outname, "y"); - inname = [in_u; in_y]; - else # no error inputs, default - sys = ss (a, b, c, d, tsam); - endif - - sys = set (sys, "inname", inname, "outname", outname); - - ## return x0 as vector for single-experiment data - ## instead of a cell containing one vector - if (numel (x0) == 1) - x0 = x0{1}; - endif - - ## assemble info struct - ## Kalman gain matrix K - ## state covariance matrix Q - ## output covariance matrix Ry - ## state-output cross-covariance matrix S - ## noise variance matrix factor L - info = struct ("K", k, "Q", q, "Ry", ry, "S", s, "L", l); - endif - -endfunction - - -function nobr = __check_s__ (s, nobr, method) - - if (s <= nobr) - nobr = s; - else - error ("%s: require upper bound s <= %d, but the requested s is %d", method, nobr, s); - endif - -endfunction Deleted: trunk/octave-forge/extra/control-devel/inst/arx.m =================================================================== --- trunk/octave-forge/extra/control-devel/inst/arx.m 2012-08-14 19:32:00 UTC (rev 10864) +++ trunk/octave-forge/extra/control-devel/inst/arx.m 2012-08-14 19:59:40 UTC (rev 10865) @@ -1,278 +0,0 @@ -## Copyright (C) 2012 Lukas F. Reichlin -## -## This file is part of LTI Syncope. -## -## LTI Syncope 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. -## -## LTI Syncope 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 LTI Syncope. If not, see <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {[@var{sys}, @var{x0}] =} arx (@var{dat}, @var{n}, @dots{}) -## @deftypefnx {Function File} {[@var{sys}, @var{x0}] =} arx (@var{dat}, @var{n}, @var{opt}, @dots{}) -## @deftypefnx {Function File} {[@var{sys}, @var{x0}] =} arx (@var{dat}, @var{opt}, @dots{}) -## @deftypefnx {Function File} {[@var{sys}, @var{x0}] =} arx (@var{dat}, @var{'na'}, @var{na}, @var{'nb'}, @var{nb}) -## Estimate ARX model using QR factorization. -## -## @strong{Inputs} -## @table @var -## @item dat -## iddata set containing the measurements, i.e. time-domain signals. -## @item n -## The desired order of the resulting model @var{sys}. -## @item @dots{} -## Optional pairs of keys and values. @code{'key1', value1, 'key2', value2}. -## @item opt -## Optional struct with keys as field names. -## Struct @var{opt} can be created directly or -## by command @command{options}. @code{opt.key1 = value1, opt.key2 = value2}. -## @end table -## -## -## @strong{Outputs} -## @table @var -## @item sys -## Discrete-time transfer function model. -## If the second output argument @var{x0} is returned, -## @var{sys} becomes a state-space model. -## @item x0 -## Initial state vector. If @var{dat} is a multi-experiment dataset, -## @var{x0} becomes a cell vector containing an initial state vector -## for each experiment. -## @end table -## -## -## @strong{Option Keys and Values} -## @table @var -## @item 'na' -## Order of the polynomial A(q) and number of poles. -## -## @item 'nb' -## Order of the polynomial B(q)+1 and number of zeros+1. -## @var{nb} <= @var{na}. -## @end table -## -## -## @strong{Algorithm}@* -## Uses the formulae given in [1] on pages 318-319, -## 'Solving for the LS Estimate by QR Factorization'. -## For the initial conditions, SLICOT IB01CD is used by courtesy of -## @uref{http://www.slicot.org, NICONET e.V.} -## -## @strong{References}@* -## [1] Ljung, L. (1999) -## System Identification - Theory for the User -## Second Edition -## Prentice Hall, New Jersey. -## -## @end deftypefn - -## Author: Lukas Reichlin <luk...@gm...> -## Created: April 2012 -## Version: 0.1 - -function [sys, varargout] = arx (dat, varargin) - - ## TODO: delays - - if (nargin < 2) - print_usage (); - endif - - if (! isa (dat, "iddata") || ! dat.timedomain) - error ("arx: first argument must be a time-domain iddata dataset"); - endif - - if (is_real_scalar (varargin{1})) # arx (dat, n, ...) - varargin = horzcat (varargin(2:end), {"na"}, varargin(1), {"nb"}, varargin(1)); - endif - - if (isstruct (varargin{1})) # arx (dat, opt, ...), arx (dat, n, opt, ...) - varargin = horzcat (__opt2cell__ (varargin{1}), varargin(2:end)); - endif - - nkv = numel (varargin); # number of keys and values - - if (rem (nkv, 2)) - error ("arx: keys and values must come in pairs"); - endif - - - ## p: outputs, m: inputs, ex: experiments - [~, p, m, ex] = size (dat); # dataset dimensions - - ## extract data - Y = dat.y; - U = dat.u; - tsam = dat.tsam; - - ## multi-experiment data requires equal sampling times - if (ex > 1 && ! isequal (tsam{:})) - error ("arx: require equally sampled experiments"); - else - tsam = tsam{1}; - endif - - - ## default arguments - na = []; - nb = []; % ??? - nk = []; - - ## handle keys and values - for k = 1 : 2 : nkv - key = lower (varargin{k}); - val = varargin{k+1}; - switch (key) - ## TODO: proper argument checking - case "na" - na = val; - case "nb" - nb = val; - case "nk" - error ("nk"); - otherwise - warning ("arx: invalid property name '%s' ignored", key); - endswitch - endfor - - - if (is_real_scalar (na, nb)) - na = repmat (na, p, 1); # na(p-by-1) - nb = repmat (nb, p, m); # nb(p-by-m) - elseif (! (is_real_vector (na) && is_real_matrix (nb) \ - && rows (na) == p && rows (nb) == p && columns (nb) == m)) - error ("arx: require na(%dx1) instead of (%dx%d) and nb(%dx%d) instead of (%dx%d)", \ - p, rows (na), columns (na), p, m, rows (nb), columns (nb)); - endif - - max_nb = max (nb, [], 2); # one maximum for each row/output, max_nb(p-by-1) - n = max (na, max_nb); # n(p-by-1) - - ## create empty cells for numerator and denominator polynomials - num = cell (p, m+p); - den = cell (p, m+p); - - ## MIMO (p-by-m) models are identified as p MISO (1-by-m) models - ## For multi-experiment data, minimize the trace of the error - for i = 1 : p # for every output - Phi = cell (ex, 1); # one regression matrix per experiment - for e = 1 : ex # for every experiment - ## avoid warning: toeplitz: column wins anti-diagonal conflict - ## therefore set first row element equal to y(1) - PhiY = toeplitz (Y{e}(1:end-1, i), [Y{e}(1, i); zeros(na(i)-1, 1)]); - ## create MISO Phi for every experiment - PhiU = arrayfun (@(x) toeplitz (U{e}(1:end-1, x), [U{e}(1, x); zeros(nb(i,x)-1, 1)]), 1:m, "uniformoutput", false); - Phi{e} = (horzcat (-PhiY, PhiU{:}))(n(i):end, :); - endfor - - ## compute parameter vector Theta - Theta = __theta__ (Phi, Y, i, n); - - ## extract polynomial matrices A and B from Theta - ## A is a scalar polynomial for output i, i=1:p - ## B is polynomial row vector (1-by-m) for output i - A = [1; Theta(1:na(i))]; # a0 = 1, a1 = Theta(1), an = Theta(n) - ThetaB = Theta(na(i)+1:end); # all polynomials from B are in one column vector - B = mat2cell (ThetaB, nb(i,:)); # now separate the polynomials, one for each input - B = reshape (B, 1, []); # make B a row cell (1-by-m) - B = cellfun (@(x) [0; x], B, "uniformoutput", false); # b0 = 0 (leading zero required by filt) - - ## add error inputs - Be = repmat ({0}, 1, p); # there are as many error inputs as system outputs (p) - Be(i) = 1; # inputs m+1:m+p are zero, except m+i which is one - num(i, :) = [B, Be]; # numerator polynomials for output i, individual for each input - den(i, :) = repmat ({A}, 1, m+p); # in a row (output i), all inputs have the same denominator polynomial - endfor - - ## A(q) y(t) = B(q) u(t) + e(t) - ## there is only one A per row - ## B(z) and A(z) are a Matrix Fraction Description (MFD) - ## y = A^-1(q) B(q) u(t) + A^-1(q) e(t) - ## since A(q) is a diagonal polynomial matrix, its inverse is trivial: - ## the corresponding transfer function has common row denominators. - - sys = filt (num, den, tsam); # filt creates a transfer function in z^-1 - - ## compute initial state vector x0 if requested - ## this makes only sense for state-space models, therefore convert TF to SS - if (nargout > 1) - sys = prescale (ss (sys(:,1:m))); - x0 = slib01cd (Y, U, sys.a, sys.b, sys.c, sys.d, 0.0); - ## return x0 as vector for single-experiment data - ## instead of a cell containing one vector - if (numel (x0) == 1) - x0 = x0{1}; - endif - varargout{1} = x0; - endif - -endfunction - - -function theta = __theta__ (phi, y, i, n) - - if (numel (phi) == 1) # single-experiment dataset - ## use "square-root algorithm" - A = horzcat (phi{1}, y{1}(n(i)+1:end, i)); # [Phi, Y] - R0 = triu (qr (A, 0)); # 0 for economy-size R (without zero rows) - R1 = R0(1:end-1, 1:end-1); # R1 is triangular - can we exploit this in R1\R2? - R2 = R0(1:end-1, end); - theta = __ls_svd__ (R1, R2); # R1 \ R2 - - ## Theta = Phi \ Y(n+1:end, :); # naive formula - ## theta = __ls_svd__ (phi{1}, y{1}(n(i)+1:end, i)); - else # multi-experiment dataset - ## TODO: find more sophisticated formula than - ## Theta = (Phi1' Phi1 + Phi2' Phi2 + ...) \ (Phi1' Y1 + Phi2' Y2 + ...) - - ## covariance matrix C = (Phi1' Phi + Phi2' Phi2 + ...) - tmp = cellfun (@(Phi) Phi.' * Phi, phi, "uniformoutput", false); - rc = cellfun (@rcond, tmp); # C auch noch testen? QR oder SVD? - C = plus (tmp{:}); - - ## PhiTY = (Phi1' Y1 + Phi2' Y2 + ...) - tmp = cellfun (@(Phi, Y) Phi.' * Y(n(i)+1:end, i), phi, y, "uniformoutput", false); - PhiTY = plus (tmp{:}); - - ## pseudoinverse Theta = C \ Phi'Y - theta = __ls_svd__ (C, PhiTY); - endif - -endfunction - - -function x = __ls_svd__ (A, b) - - ## solve the problem Ax=b - ## x = A\b would also work, - ## but this way we have better control and warnings - - ## solve linear least squares problem by pseudoinverse - ## the pseudoinverse is computed by singular value decomposition - ## M = U S V* ---> M+ = V S+ U* - ## Th = Ph \ Y = Ph+ Y - ## Th = V S+ U* Y, S+ = 1 ./ diag (S) - - [U, S, V] = svd (A, 0); # 0 for "economy size" decomposition - S = diag (S); # extract main diagonal - r = sum (S > eps*S(1)); - if (r < length (S)) - warning ("arx: rank-deficient coefficient matrix"); - warning ("sampling time too small"); - warning ("persistence of excitation"); - endif - V = V(:, 1:r); - S = S(1:r); - U = U(:, 1:r); - x = V * (S .\ (U' * b)); # U' is the conjugate transpose - -endfunction Deleted: trunk/octave-forge/extra/control-devel/inst/moen4.m =================================================================== --- trunk/octave-forge/extra/control-devel/inst/moen4.m 2012-08-14 19:32:00 UTC (rev 10864) +++ trunk/octave-forge/extra/control-devel/inst/moen4.m 2012-08-14 19:59:40 UTC (rev 10865) @@ -1,3034 +0,0 @@ -## Copyright (C) 2012 Lukas F. Reichlin -## -## This file is part of LTI Syncope. -## -## LTI Syncope 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. -## -## LTI Syncope 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 LTI Syncope. If not, see <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {[@var{sys}, @var{x0}, @var{info}] =} moen4 (@var{dat}, @dots{}) -## @deftypefnx {Function File} {[@var{sys}, @var{x0}, @var{info}] =} moen4 (@var{dat}, @var{n}, @dots{}) -## @deftypefnx {Function File} {[@var{sys}, @var{x0}, @var{info}] =} moen4 (@var{dat}, @var{opt}, @dots{}) -## @deftypefnx {Function File} {[@var{sys}, @var{x0}, @var{info}] =} moen4 (@var{dat}, @var{n}, @var{opt}, @dots{}) -## Estimate state-space model using combined subspace method: -## @acronym{MOESP} algorithm for finding the matrices A and C, -## and @acronym{N4SID} algorithm for finding the matrices B and D. -## If no output arguments are given, the singular values are -## plotted on the screen in order to estimate the system order. -## -## @strong{Inputs} -## @table @var -## @item dat -## iddata set containing the measurements, i.e. time-domain signals. -## @item n -## The desired order of the resulting state-space system @var{sys}. -## If not specified, @var{n} is chosen automatically according -## to the singular values and tolerances. -## @item @dots{} -## Optional pairs of keys and values. @code{'key1', value1, 'key2', value2}. -## @item opt -## Optional struct with keys as field names. -## Struct @var{opt} can be created directly or -## by command @command{options}. @code{opt.key1 = value1, opt.key2 = value2}. -## @end table -## -## -## @strong{Outputs} -## @table @var -## @item sys -## Discrete-time state-space model. -## @item x0 -## Initial state vector. If @var{dat} is a multi-experiment dataset, -## @var{x0} becomes a cell vector containing an initial state vector -## for each experiment. -## @item info -## Struct containing additional information. -## @table @var -## @item info.K -## Kalman gain matrix. -## @item info.Q -## State covariance matrix. -## @item info.Ry -## Output covariance matrix. -## @item info.S -## State-output cross-covariance matrix. -## @item info.L -## Noise variance matrix factor. LL'=Ry. -## @end table -## @end table -## -## -## -## @strong{Option Keys and Values} -## @table @var -## @item 'n' -## The desired order of the resulting state-space system @var{sys}. -## @var{s} > @var{n} > 0. -## -## @item 's' -## The number of block rows @var{s} in the input and output -## block Hankel matrices to be processed. @var{s} > 0. -## In the MOESP theory, @var{s} should be larger than @var{n}, -## the estimated dimension of state vector. -## -## @item 'alg', 'algorithm' -## Specifies the algorithm for computing the triangular -## factor R, as follows: -## @table @var -## @item 'C' -## Cholesky algorithm applied to the correlation -## matrix of the input-output data. Default method. -## @item 'F' -## Fast QR algorithm. -## @item 'Q' -## QR algorithm applied to the concatenated block -## Hankel matrices. -## @end table -## -## @item 'tol' -## Absolute tolerance used for determining an estimate of -## the system order. If @var{tol} >= 0, the estimate is -## indicated by the index of the last singular value greater -## than or equal to @var{tol}. (Singular values less than @var{tol} -## are considered as zero.) When @var{tol} = 0, an internally -## computed default value, @var{tol} = @var{s}*@var{eps}*SV(1), is used, -## where SV(1) is the maximal singular value, and @var{eps} is -## the relative machine precision. -## When @var{tol} < 0, the estimate is indicated by the -## index of the singular value that has the largest -## logarithmic gap to its successor. Default value is 0. -## -## @item 'rcond' -## The tolerance to be used for estimating the rank of -## matrices. If the user sets @var{rcond} > 0, the given value -## of @var{rcond} is used as a lower bound for the reciprocal -## condition number; an m-by-n matrix whose estimated -## condition number is less than 1/@var{rcond} is considered to -## be of full rank. If the user sets @var{rcond} <= 0, then an -## implicitly computed, default tolerance, defined by -## @var{rcond} = m*n*@var{eps}, is used instead, where @var{eps} is the -## relative machine precision. Default value is 0. -## -## @item 'confirm' -## Specifies whether or not the user's confirmation of the -## system order estimate is desired, as follows: -## @table @var -## @item true -## User's confirmation. -## @item false -## No confirmation. Default value. -## @end table -## -## @item 'input' -## The desired type of noise input channels. -## @table @var -## @item 'n' -## No error inputs. Default value. -## @iftex -## @tex -## $$ x_{k+1} = A x_k + B u_k $$ -## $$ y_k = C x_k + D u_k $$ -## @end tex -## @end iftex -## @ifnottex -## @example -## x[k+1] = A x[k] + B u[k] -## y[k] = C x[k] + D u[k] -## @end example -## @end ifnottex -## -## @item 'e' -## Return @var{sys} as a (p-by-m+p) state-space model with -## both measured input channels u and noise channels e -## with covariance matrix @var{Ry}. -## @iftex -## @tex -## $$ x_{k+1} = A x_k + B u_k + K e_k $$ -## $$ y_k = C x_k + D u_k + e_k $$ -## @end tex -## @end iftex -## @ifnottex -## @example -## x[k+1] = A x[k] + B u[k] + K e[k] -## y[k] = C x[k] + D u[k] + e[k] -## @end example -## @end ifnottex -## -## @item 'v' -## Return @var{sys} as a (p-by-m+p) state-space model with -## both measured input channels u and white noise channels v -## with identity covariance matrix. -## @iftex -## @tex -## $$ x_{k+1} = A x_k + B u_k + K L v_k $$ -## $$ y_k = C x_k + D u_k + L v_k $$ -## $$ e = L v, \\ L L^T = R_y $$ -## @end tex -## @end iftex -## @ifnottex -## @example -## x[k+1] = A x[k] + B u[k] + K L v[k] -## y[k] = C x[k] + D u[k] + L v[k] -## e = L v, L L' = Ry -## @end example -## @end ifnottex -## -## @item 'k' -## Return @var{sys} as a Kalman predictor for simulation. -## @iftex -## @tex -## $$ \\widehat{x}_{k+1} = A \\widehat{x}_k + B u_k + K (y_k - \\widehat{y}_k) $$ -## $$ \\widehat{y}_k = C \\widehat{x}_k + D u_k $$ -## @end tex -## @end iftex -## @ifnottex -## @example -## ^ ^ ^ -## x[k+1] = A x[k] + B u[k] + K(y[k] - y[k]) -## ^ ^ -## y[k] = C x[k] + D u[k] -## @end example -## @end ifnottex -## -## @iftex -## @tex -## $$ \\widehat{x}_{k+1} = (A-KC) \\widehat{x}_k + (B-KD) u_k + K y_k $$ -## $$ \\widehat{y}_k = C \\widehat{x}_k + D u_k + 0 y_k $$ -## @end tex -## @end iftex -## @ifnottex -## @example -## ^ ^ -## x[k+1] = (A-KC) x[k] + (B-KD) u[k] + K y[k] -## ^ ^ -## y[k] = C x[k] + D u[k] + 0 y[k] -## @end example -## @end ifnottex -## @end table -## @end table -## -## -## @strong{Algorithm}@* -## Uses SLICOT IB01AD, IB01BD and IB01CD by courtesy of -## @uref{http://www.slicot.org, NICONET e.V.} -## -## @end deftypefn - -## Author: Lukas Reichlin <luk...@gm...> -## Created: May 2012 -## Version: 0.1 - -function [sys, x0, info] = moen4 (varargin) - - if (nargin == 0) - print_usage (); - endif - - if (nargout == 0) - __slicot_identification__ ("moen4", nargout, varargin{:}); - else - [sys, x0, info] = __slicot_identification__ ("moen4", nargout, varargin{:}); - endif - -endfunction - - -%!shared SYS, X0, INFO, Ae, Be, Ce, De, Ke, Qe, Rye, Se, X0e -%! -%! Y = [ 4.7661 5.5451 5.8503 5.3766 4.8833 5.4865 3.5378 5.3155 6.0530 4.3729 -%! 4.7637 5.1886 5.9236 5.6818 4.8858 5.1495 3.5549 5.5329 6.0799 4.7417 -%! 4.8394 4.8833 5.9212 5.8235 4.8931 4.8442 3.4938 5.4450 6.1287 5.0884 -%! 5.0030 4.6000 5.9773 5.9529 4.7148 4.5414 3.4474 5.3961 6.0799 5.1861 -%! 5.0176 4.2704 5.7405 6.0628 4.4511 4.2679 3.4401 5.2740 6.1678 5.0372 -%! 5.0567 4.0384 5.3888 6.0897 4.2337 4.0604 3.4083 5.0274 6.1947 4.7856 -%! 5.1544 3.8381 5.0005 6.0750 4.0433 3.9602 3.4108 4.7441 6.2362 4.5634 -%! 5.3619 3.7112 4.8491 6.0262 3.8650 3.7893 3.4523 4.6684 6.0530 4.5341 -%! 5.4254 3.5915 4.9444 5.9944 3.7576 3.6428 3.6818 4.6513 5.6525 4.7050 -%! 5.5695 3.5353 5.1739 6.0775 3.6696 3.5256 4.0604 4.5146 5.2740 4.7417 -%! 5.6818 3.4865 5.3693 5.8577 3.5939 3.4987 4.4413 4.2679 4.8589 4.6489 -%! 5.7429 3.4767 5.4474 5.7014 3.5475 3.4547 4.8540 4.2606 4.5341 4.4315 -%! 5.8039 3.4254 5.6037 5.7307 3.5060 3.4083 5.1544 4.2630 4.4560 4.2386 -%! 5.9187 3.3815 5.7307 5.7844 3.4547 3.3790 5.4254 4.1898 4.6196 4.0652 -%! 5.8210 3.3693 5.8503 5.8235 3.3986 3.3766 5.5964 4.2777 4.8662 3.9431 -%! 5.4474 3.3644 5.9798 5.8943 3.3619 3.3619 5.5866 4.6000 5.1177 3.8113 -%! 5.0616 3.3473 5.9920 5.7624 3.3400 3.3595 5.3546 4.9322 5.1666 3.6916 -%! 4.6293 3.3815 6.0848 5.4157 3.3742 3.3693 5.0274 5.2838 5.0567 3.6525 -%! 4.2679 3.4206 5.9407 4.9615 3.5207 3.3986 4.8638 5.5280 5.0030 3.8259 -%! 4.0115 3.4132 5.8039 4.5952 3.7136 3.5793 4.7612 5.7405 5.0982 4.2240 -%! 3.8503 3.4523 5.7917 4.3314 3.7576 3.9480 4.5707 5.8748 5.3253 4.4242 -%! 3.7112 3.6355 5.6037 4.2972 3.7795 4.4120 4.3681 5.9554 5.5671 4.4291 -%! 3.5695 4.0384 5.2643 4.5829 3.6965 4.5854 4.3974 5.9920 5.4670 4.3192 -%! 3.5182 4.3754 4.9468 4.8613 3.7771 4.5146 4.5732 5.8455 5.2521 4.1385 -%! 3.6525 4.7270 4.6196 5.1739 3.8870 4.3436 4.8418 5.5280 4.9468 3.9651 -%! 3.8186 5.0567 4.5146 5.1666 3.9041 4.1556 5.2032 5.0616 4.8809 3.8870 -%! 3.8626 5.2985 4.4340 4.9199 3.8503 3.9847 5.4523 4.7344 4.9810 3.8015 -%! 4.0115 5.5329 4.2850 4.6074 3.9651 4.0433 5.6525 4.5341 5.2252 3.7014 -%! 4.3534 5.4670 4.1214 4.3705 4.2826 4.3070 5.8552 4.5341 5.4596 3.6403 -%! 4.7050 5.1959 3.9456 4.1825 4.5219 4.4218 5.9065 4.6977 5.7234 3.7673 -%! 5.0836 4.8858 3.9847 4.0384 4.7148 4.3534 5.9529 4.7441 5.7917 4.1507 -%! 5.3449 4.7637 4.2191 4.1458 4.9712 4.2240 5.8284 4.6196 5.9065 4.6489 -%! 5.2740 4.8760 4.5463 4.4315 5.2203 4.0530 5.7917 4.6440 5.9920 4.9908 -%! 5.1275 5.0420 4.8735 4.5561 5.5329 3.9407 5.7991 4.8320 5.8357 5.0884 -%! 4.7612 5.2838 5.1544 4.4804 5.6525 3.8381 5.8137 5.1324 5.5280 5.0225 -%! 4.4511 5.4914 5.3888 4.3754 5.7820 3.7307 5.8772 5.4108 5.1422 4.7832 -%! 4.2215 5.5964 5.6135 4.3705 5.9554 3.6525 5.9554 5.6257 4.7759 4.6855 -%! 4.0457 5.6721 5.8357 4.5585 6.0359 3.6110 5.7820 5.6037 4.4902 4.6660 -%! 3.8748 5.7722 5.8845 4.8589 6.1190 3.5646 5.5182 5.3155 4.2362 4.7075 -%! 3.7307 5.8308 5.9554 4.8955 6.1336 3.4963 5.1275 4.9615 4.0237 4.9126 -%! 3.6623 5.9334 5.7624 4.7417 6.1532 3.4621 4.7637 4.6196 3.8870 5.1959 -%! 3.5768 5.8992 5.4596 4.7441 6.1922 3.4547 4.4926 4.3583 3.7527 5.4157 -%! 3.5427 5.9358 5.0616 4.8760 6.1434 3.4254 4.2337 4.1556 3.6818 5.6232 -%! 3.4792 5.8943 4.7075 5.1055 6.1678 3.3790 4.0115 4.0335 3.8064 5.7405 -%! 3.4547 5.9187 4.4584 5.2398 5.9920 3.4328 3.8552 3.8870 4.1458 5.8992 -%! 3.3595 5.9944 4.2679 5.5182 5.6525 3.6232 3.6916 3.7722 4.6000 5.9285 -%! 3.2985 5.9578 4.0530 5.6525 5.4596 3.9749 3.6355 3.6403 5.0030 6.0506 -%! 3.2252 6.0311 3.9431 5.7234 5.4376 4.3803 3.8186 3.5329 5.3033 6.1532 -%! 3.2008 6.0628 3.8259 5.8552 5.3400 4.7148 4.1556 3.4352 5.5524 5.9651 -%! 3.2252 6.0408 3.9676 5.9627 5.0982 5.0738 4.5903 3.4279 5.6159 5.5866 -%! 3.2276 6.0970 4.2801 5.9847 4.7856 5.3693 4.9883 3.4230 5.5231 5.3815 -%! 3.2740 6.1239 4.4804 5.9847 4.4926 5.6037 5.0762 3.3986 5.6110 5.3717 -%! 3.4572 6.1629 4.4926 6.0555 4.2362 5.7453 4.9077 3.6037 5.7136 5.4865 -%! 3.8674 6.0408 4.3900 6.0628 4.0677 5.6525 4.6489 4.0237 5.8455 5.5671 -%! 4.3217 5.8455 4.1971 6.0555 3.9334 5.4010 4.3778 4.4511 5.8992 5.8210 -%! 4.4926 5.7722 4.1116 6.0701 3.8235 5.0152 4.2166 4.7930 5.9944 5.9138 -%! 4.4315 5.7991 3.9822 5.7844 3.7307 4.7099 4.2875 4.9029 6.0921 5.9944 -%! 4.2435 5.9236 3.8674 5.4401 3.6110 4.4169 4.5903 4.7808 6.0921 6.0115 -%! 4.0506 5.9285 3.7673 5.0567 3.5646 4.2362 4.8467 4.5903 6.1434 5.9993 -%! 3.8577 6.0018 3.8723 4.9419 3.5500 4.2362 5.1397 4.3363 6.1532 6.0188 -%! 3.7307 6.0018 4.2362 5.0103 3.5573 4.2484 5.3888 4.1458 6.2337 5.8210 -%! 3.7917 6.0604 4.6635 5.1348 3.5134 4.2215 5.6892 4.2166 6.1873 5.7282 -%! 3.9212 5.8821 4.9712 5.3131 3.5158 4.2972 5.8845 4.4340 6.0140 5.7405 -%! 3.9554 5.5109 5.0665 5.4792 3.6941 4.5903 6.0433 4.7148 5.8357 5.7649 -%! 3.8479 5.3229 4.9029 5.6232 4.0726 4.8931 6.1703 5.0982 5.7746 5.8821 -%! 3.7258 5.3717 4.6757 5.5622 4.4804 5.1348 6.2118 5.3595 5.6867 5.9260 -%! 3.6110 5.4547 4.3925 5.3302 4.7050 5.4279 6.2508 5.5695 5.5378 5.7502 -%! 3.7160 5.4376 4.0994 5.0103 4.6123 5.3790 6.2093 5.7722 5.3278 5.4157 -%! 4.0921 5.1593 4.1141 4.6660 4.3851 5.3644 6.0140 5.9212 5.0543 4.9956 -%! 4.4804 4.9029 4.3265 4.4145 4.2020 5.4523 5.7014 6.0555 4.7002 4.8613 -%! 4.8149 4.5878 4.6440 4.2020 4.0262 5.5671 5.4694 5.9627 4.3949 4.9029 -%! 5.0543 4.5024 4.9712 4.0482 3.9041 5.6721 5.4792 5.6428 4.1800 5.1031 -%! 5.3033 4.5952 5.1593 4.0799 3.7746 5.7698 5.5573 5.4352 4.0433 5.3644 -%! 5.4865 4.8247 5.3888 4.1898 3.6916 5.8308 5.7282 5.3888 3.8772 5.5964 -%! 5.6721 5.0640 5.5768 4.1312 3.8455 5.9236 5.8821 5.5378 3.7527 5.7527 -%! 5.7795 5.2716 5.6525 4.0042 4.2020 5.9651 5.9847 5.6818 3.7282 5.8455 -%! 5.7991 5.4670 5.8039 3.9163 4.5854 6.0579 5.9016 5.7014 3.8699 5.9285 -%! 5.6648 5.6159 5.9138 3.9602 4.9029 6.0506 5.5817 5.6159 4.2069 6.0066 -%! 5.2911 5.5280 5.8870 4.1996 5.2569 6.0726 5.3717 5.6672 4.3558 5.8406 -%! 4.8809 5.2545 5.7991 4.6245 5.5109 6.1116 5.4181 5.7405 4.4267 5.5182 -%! 4.5585 4.8833 5.7307 4.8833 5.6403 6.0701 5.5109 5.8039 4.4535 5.1739 -%! 4.1849 4.5170 5.7624 5.1373 5.8430 5.8967 5.6672 5.8821 4.5219 4.7392 -%! 3.8894 4.1971 5.8137 5.3790 5.9749 5.7551 5.7917 5.9505 4.3925 4.4584 -%! 3.7087 4.0018 5.8210 5.6232 5.9358 5.7185 5.6989 6.0726 4.1556 4.4267 -%! 3.6232 3.8064 5.9285 5.7624 5.8210 5.8210 5.4840 6.1483 3.9651 4.6025 -%! 3.5695 3.9041 6.0140 5.8333 5.5280 6.0018 5.1544 6.1165 3.8772 4.8223 -%! 3.7185 3.9236 5.7649 5.6867 5.1715 6.0018 4.9810 6.1776 3.9700 5.1837 -%! 4.0335 3.8699 5.4132 5.3668 4.8101 5.9016 5.0616 6.2020 4.2582 5.4303 -%! 4.4120 3.8064 5.0982 5.2252 4.4535 5.5573 5.1959 6.2069 4.4218 5.6525 -%! 4.6293 3.7209 4.6782 5.2398 4.3803 5.1739 5.3595 5.9920 4.3363 5.8210 -%! 4.5585 3.8186 4.3729 5.3546 4.5659 4.8003 5.6159 5.5646 4.2997 5.7063 -%! 4.3949 4.1409 4.3925 5.5085 4.8052 4.4315 5.7624 5.1788 4.3925 5.3693 -%! 4.1800 4.5292 4.5903 5.5964 5.1251 4.1947 5.8577 4.9981 4.6757 5.0274 -%! 4.1971 4.8052 4.9199 5.7527 5.3546 4.0066 5.9480 5.0518 4.7612 4.7050 -%! 4.4315 5.0860 5.0176 5.8748 5.5891 3.8503 5.8357 5.2325 4.6587 4.4145 -%! 4.7148 5.3400 4.8589 5.9065 5.7649 3.7478 5.7063 5.4840 4.4902 4.1458 -%! 4.9615 5.5329 4.6757 5.8943 5.9236 3.6428 5.4987 5.6867 4.3070 3.9651 -%! 5.3009 5.5768 4.6196 5.7429 5.9407 3.5915 5.1886 5.8992 4.1263 4.0335 -%! 5.5671 5.6672 4.8345 5.4474 5.8577 3.5695 5.1177 5.8699 3.9724 4.3729 -%! 5.6818 5.7917 5.0909 5.0250 5.6941 3.5280 5.1910 5.9773 4.0775 4.6831 ](:); -%! -%! -%! -%! U = [ 6.4100 3.4100 6.4100 6.4100 3.4100 3.4100 3.4100 6.4100 6.4100 3.4100 -%! 3.4100 3.4100 3.4100 6.4100 3.4100 3.4100 3.4100 3.4100 6.4100 3.4100 -%! 6.4100 3.4100 3.4100 6.4100 3.4100 3.4100 3.4100 3.4100 6.4100 3.4100 -%! 6.4100 3.4100 3.4100 6.4100 3.4100 3.4100 3.4100 3.4100 6.4100 3.4100 -%! 6.4100 3.4100 6.4100 6.4100 3.4100 3.4100 3.4100 6.4100 3.4100 6.4100 -%! 6.4100 3.4100 6.4100 6.4100 3.4100 3.4100 6.4100 3.4100 3.4100 6.4100 -%! 6.4100 3.4100 6.4100 6.4100 3.4100 3.4100 6.4100 3.4100 3.4100 3.4100 -%! 6.4100 3.4100 6.4100 3.4100 3.4100 3.4100 6.4100 3.4100 3.4100 3.4100 -%! 6.4100 3.4100 6.4100 6.4100 3.4100 3.4100 6.4100 6.4100 3.4100 3.4100 -%! 6.4100 3.4100 6.4100 6.4100 3.4100 3.4100 6.4100 3.4100 6.4100 3.4100 -%! 6.4100 3.4100 6.4100 6.4100 3.4100 3.4100 6.4100 3.4100 6.4100 3.4100 -%! 3.4100 3.4100 6.4100 6.4100 3.4100 3.4100 6.4100 6.4100 6.4100 3.4100 -%! 3.4100 3.4100 6.4100 6.4100 3.4100 3.4100 3.4100 6.4100 6.4100 3.4100 -%! 3.4100 3.4100 6.4100 3.4100 3.4100 3.4100 3.4100 6.4100 3.4100 3.4100 -%! 3.4100 3.4100 6.4100 3.4100 3.4100 3.4100 3.4100 6.4100 3.4100 3.4100 -%! 3.4100 3.4100 3.4100 3.4100 6.4100 3.4100 6.4100 6.4100 6.4100 6.4100 -%! 3.4100 3.4100 6.4100 3.4100 3.4100 6.4100 3.4100 6.4100 6.4100 6.4100 -%! 3.4100 3.4100 6.4100 3.4100 3.4100 6.4100 3.4100 6.4100 6.4100 3.4100 -%! 3.4100 6.4100 3.4100 6.4100 3.4100 6.4100 3.4100 6.4100 6.4100 3.4100 -%! 3.4100 6.4100 3.4100 6.4100 3.4100 3.4100 6.4100 6.4100 3.4100 3.4100 -%! 3.4100 6.4100 3.4100 6.4100 6.4100 3.4100 6.4100 3.4100 3.4100 3.4100 -%! 6.4100 6.4100 3.4100 6.4100 3.4100 3.4100 6.4100 3.4100 3.4100 3.4100 -%! 3.4100 6.4100 6.4100 3.4100 3.4100 3.4100 6.4100 3.4100 6.4100 3.4100 -%! 3.4100 6.4100 3.4100 3.4100 3.4100 3.4100 6.4100 3.4100 6.4100 3.4100 -%! 6.4100 6.4100 3.4100 3.4100 6.4100 6.4100 6.4100 3.4100 6.4100 3.4100 -%! 6.4100 3.4100 3.4100 3.4100 6.4100 6.4100 6.4100 6.4100 6.4100 3.4100 -%! 6.4100 3.4100 3.4100 3.4100 3.4100 3.4100 6.4100 6.4100 6.4100 6.4100 -%! 6.4100 3.4100 6.4100 3.4100 6.4100 3.4100 6.4100 3.4100 6.4100 6.4100 -%! 6.4100 6.4100 6.4100 6.4100 6.4100 3.4100 3.4100 3.4100 6.4100 6.4100 -%! 3.4100 6.4100 6.4100 6.4100 6.4100 3.4100 6.4100 6.4100 6.4100 6.4100 -%! 3.4100 6.4100 6.4100 3.4100 6.4100 3.4100 6.4100 6.4100 3.4100 3.4100 -%! 3.4100 6.4100 6.4100 3.4100 6.4100 3.4100 6.4100 6.4100 3.4100 3.4100 -%! 3.4100 6.4100 6.4100 3.4100 6.4100 3.4100 6.4100 6.4100 3.4100 3.4100 -%! 3.4100 6.4100 6.4100 6.4100 6.4100 3.4100 6.4100 6.4100 3.4100 6.4100 -%! 3.4100 6.4100 6.4100 6.4100 6.4100 3.4100 3.4100 3.4100 3.4100 3.4100 -%! 3.4100 6.4100 6.4100 6.4100 6.4100 3.4100 3.4100 3.4100 3.4100 6.4100 -%! 3.4100 6.4100 6.4100 3.4100 6.4100 3.4100 3.4100 3.4100 3.4100 6.4100 -%! 3.4100 6.4100 3.4100 3.4100 6.4100 3.4100 3.4100 3.4100 3.4100 6.4100 -%! 3.4100 6.4100 3.4100 6.4100 6.4100 3.4100 3.4100 3.4100 3.4100 6.4100 -%! 3.4100 6.4100 3.4100 6.4100 6.4100 3.4100 3.4100 3.4100 3.4100 6.4100 -%! 3.4100 6.4100 3.4100 6.4100 6.4100 3.4100 3.4100 3.4100 6.4100 6.4100 -%! 3.4100 6.4100 3.4100 6.4100 3.4100 3.4100 3.4100 3.4100 6.4100 6.4100 -%! 3.4100 6.4100 3.4100 6.4100 3.4100 6.4100 3.4100 3.4100 6.4100 6.4100 -%! 3.4100 6.4100 3.4100 6.4100 6.4100 6.4100 3.4100 3.4100 6.4100 6.4100 -%! 3.4100 6.4100 3.4100 6.4100 6.4100 6.4100 6.4100 3.4100 6.4100 6.4100 -%! 3.4100 6.4100 3.4100 6.4100 3.4100 6.4100 6.4100 3.4100 6.4100 3.4100 -%! 3.4100 6.4100 6.4100 6.4100 3.4100 6.4100 6.4100 3.4100 3.4100 3.4100 -%! 3.4100 6.4100 6.4100 6.4100 3.4100 6.4100 6.4100 3.4100 6.4100 6.4100 -%! 3.4100 6.4100 3.4100 6.4100 3.4100 6.4100 3.4100 3.4100 6.4100 6.4100 -%! 6.4100 6.4100 3.4100 6.4100 3.4100 6.4100 3.4100 6.4100 6.4100 6.4100 -%! 6.4100 3.4100 3.4100 6.4100 3.4100 3.4100 3.4100 6.4100 6.4100 6.4100 -%! 6.4100 6.4100 3.4100 6.4100 3.4100 3.4100 3.4100 6.4100 6.4100 6.4100 -%! 3.4100 6.4100 3.4100 6.4100 3.4100 3.4100 3.4100 6.4100 6.4100 6.4100 -%! 3.4100 6.4100 3.4100 3.4100 3.4100 3.4100 6.4100 3.4100 6.4100 6.4100 -%! 3.4100 6.4100 3.4100 3.4100 3.4100 3.4100 6.4100 3.4100 6.4100 6.4100 -%! 3.4100 6.4100 3.4100 3.4100 3.4100 3.4100 6.4100 3.4100 6.4100 6.4100 -%! 3.4100 6.4100 6.4100 6.4100 3.4100 6.4100 6.4100 3.4100 6.4100 6.4100 -%! 3.4100 6.4100 6.4100 6.4100 3.4100 3.4100 6.4100 3.4100 6.4100 3.4100 -%! 6.4100 6.4100 6.4100 6.4100 3.4100 3.4100 6.4100 6.4100 6.4100 6.4100 -%! 3.4100 3.4100 6.4100 6.4100 3.4100 6.4100 6.4100 6.4100 3.4100 6.4100 -%! 3.4100 3.4100 3.4100 6.4100 6.4100 6.4100 6.4100 6.4100 6.4100 6.4100 -%! 3.4100 6.4100 3.4100 6.4100 6.4100 6.4100 6.4100 6.4100 6.4100 6.4100 -%! 3.4100 6.4100 3.4100 3.4100 6.4100 6.4100 6.4100 6.4100 3.4100 6.4100 -%! 3.4100 6.4100 3.4100 3.4100 3.4100 6.4100 6.4100 6.4100 6.4100 3.4100 -%! 6.4100 3.4100 3.4100 3.4100 3.4100 3.4100 6.4100 6.4100 3.4100 3.4100 -%! 6.4100 3.4100 6.4100 3.4100 3.4100 6.4100 3.4100 6.4100 3.4100 3.4100 -%! 6.4100 3.4100 6.4100 3.4100 3.4100 6.4100 3.4100 6.4100 3.4100 6.4100 -%! 6.4100 3.4100 6.4100 3.4100 3.4100 6.4100 6.4100 3.4100 3.4100 6.4100 -%! 6.4100 6.4100 6.4100 3.4100 3.4100 6.4100 6.4100 3.4100 3.4100 6.4100 -%! 6.4100 6.4100 6.4100 6.4100 3.4100 6.4100 6.4100 6.4100 3.4100 6.4100 -%! 6.4100 6.4100 6.4100 3.4100 3.4100 6.4100 6.4100 6.4100 3.4100 6.4100 -%! 6.4100 6.4100 6.4100 3.4100 6.4100 6.4100 6.4100 6.4100 3.4100 6.4100 -%! 6.4100 6.4100 6.4100 3.4100 6.4100 6.4100 6.4100 6.4100 3.4100 6.4100 -%! 6.4100 6.4100 6.4100 3.4100 6.4100 6.4100 3.4100 3.4100 6.4100 6.4100 -%! 3.4100 6.4100 6.4100 6.4100 6.4100 6.4100 3.4100 6.4100 6.4100 6.4100 -%! 3.4100 3.4100 6.4100 6.4100 6.4100 6.4100 6.4100 6.4100 3.4100 3.4100 -%! 3.4100 3.4100 3.4100 6.4100 6.4100 6.4100 6.4100 6.4100 3.4100 3.4100 -%! 3.4100 3.4100 6.4100 6.4100 6.4100 6.4100 6.4100 6.4100 6.4100 3.4100 -%! 3.4100 3.4100 6.4100 6.4100 6.4100 3.4100 6.4100 6.4100 3.4100 3.4100 -%! 3.4100 3.4100 6.4100 6.4100 6.4100 6.4100 6.4100 6.4100 3.4100 3.4100 -%! 3.4100 3.4100 6.4100 6.4100 6.4100 6.4100 3.4100 6.4100 3.4100 6.4100 -%! 3.4100 3.4100 6.4100 6.4100 3.4100 6.4100 3.4100 6.4100 3.4100 6.4100 -%! 3.4100 6.4100 6.4100 6.4100 3.4100 6.4100 3.4100 6.4100 3.4100 6.4100 -%! 6.4100 3.4100 3.4100 3.4100 3.4100 6.4100 6.4100 6.4100 6.4100 6.4100 -%! 6.4100 3.4100 3.4100 3.4100 3.4100 3.4100 6.4100 6.4100 6.4100 6.4100 -%! 6.4100 3.4100 3.4100 6.4100 3.4100 3.4100 6.4100 6.4100 3.4100 6.4100 -%! 3.4100 3.4100 3.4100 6.4100 6.4100 3.4100 6.4100 3.4100 3.4100 6.4100 -%! 3.4100 6.4100 3.4100 6.4100 6.4100 3.4100 6.4100 3.4100 3.4100 3.4100 -%! 3.4100 6.4100 6.4100 6.4100 6.4100 3.4100 6.4100 3.4100 6.4100 3.4100 -%! 3.4100 6.4100 6.4100 6.4100 6.4100 3.4100 6.4100 6.4100 6.4100 3.4100 -%! 6.4100 6.4100 6.4100 6.4100 6.4100 3.4100 6.4100 6.4100 3.4100 3.4100 -%! 6.4100 6.4100 3.4100 6.4100 6.4100 3.4100 3.4100 6.4100 3.4100 3.4100 -%! 6.4100 6.4100 3.4100 6.4100 6.4100 3.4100 6.4100 6.4100 3.4100 3.4100 -%! 6.4100 6.4100 3.4100 6.4100 6.4100 3.4100 3.4100 6.4100 3.4100 3.4100 -%! 6.4100 6.4100 6.4100 3.4100 6.4100 3.4100 3.4100 6.4100 3.4100 6.4100 -%! 6.4100 6.4100 6.4100 3.4100 3.4100 3.4100 6.4100 6.4100 3.4100 6.4100 -%! 6.4100 6.4100 6.4100 3.4100 6.4100 3.4100 6.4100 6.4100 6.4100 6.4100 -%! 3.4100 6.4100 6.4100 6.4100 3.4100 3.4100 6.4100 6.4100 6.4100 6.4100 -%! 3.4100 6.4100 6.4100 6.4100 3.4100 3.4100 6.4100 6.4100 6.4100 6.4100 -%! 3.4100 6.4100 6.4100 3.4100 3.4100 3.4100 3.4100 6.4100 6.4100 6.4100 ](:); -%! -%! -%! DAT = iddata (Y, U); -%! -%! [SYS, X0, INFO] = moen4 (DAT, "s", 15, "rcond", 0.0, "tol", -1.0, "confirm", false); -%! -%! Ae = [ 0.8924 0.3887 0.1285 0.1716 -%! -0.0837 0.6186 -0.6273 -0.4582 -%! 0.0052 0.1307 0.6685 -0.6755 -%! 0.0055 0.0734 -0.2148 0.4788 ]; -%! -%! Ce = [ -0.4442 0.6663 0.3961 0.4102 ]; -%! -%! Be = [ -0.2142 -%! -0.1968 -%! 0.0525 -%! 0.0361 ]; -%! -%! De = [ -0.0041 ]; -%! -%! Ke = [ -1.9513 -%! -0.1867 -%! 0.6348 -%! -0.3486 ]; -%! -%! Qe = [ 0.0052 0.0005 -0.0017 0.0009 -%! 0.0005 0.0000 -0.0002 0.0001 -%! -0.0017 -0.0002 0.0006 -0.0003 -%! 0.0009 0.0001 -0.0003 0.0002 ]; -%! -%! Rye = [ 0.0012 ]; -%! -%! Se = [ -0.0025 -%! -0.0002 -%! 0.0008 -%! -0.0005 ]; -%! -%! X0e = [ -11.496422 -%! -0.718576 -%! -0.014211 -%! 0.500073 ]; # X0e is not from SLICOT -%! -%! ## The SLICOT test for IB01CD uses COMUSE=C, not COMUSE=U. -%! ## This means that they don't use the matrices B and D -%! ## computed by IB01BD. They use only A and C from IB01BD, -%! ## while B and D are from SLICOT routine IB01CD. -%! ## Therefore they get slightly different matrices B and D -%! ## and finally a different initial state vector X0. -%! -%!assert (SYS.A, Ae, 1e-4); -%!assert (SYS.B, Be, 1e-4); -%!assert (SYS.C, Ce, 1e-4); -%!assert (SYS.D, De, 1e-4); -%!assert (INFO.K, Ke, 1e-4); -%!assert (INFO.Q, Qe, 1e-4); -%!assert (INFO.Ry, Rye, 1e-4); -%!assert (INFO.S, Se, 1e-4); -%!assert (X0, X0e, 1e-4); - - -## [96-003] Data of a 120 MW power plant (Pont-sur-Sambre, France) -%!shared SYS, Ae, Be, Ce, De -%! U = [ -811 -592 421 -680 -681 -%! -812 -619 477 -685 -651 -%! -817 -565 538 -678 -677 -%! -695 -725 536 -674 -702 -%! -697 -571 531 -676 -685 -%! -697 -618 533 -681 -721 -%! -702 -579 549 -677 -699 -%! -703 -487 575 -677 -694 -%! -705 -449 561 -679 -678 -%! -705 -431 563 -680 -692 -%! -707 -502 561 -679 -686 -%! -707 -583 530 -676 -751 -%! -710 -458 540 -677 -700 -%! -713 -469 543 -679 -731 -%! -715 -506 549 -684 -635 -%! -713 -590 532 -681 -715 -%! -714 -582 528 -676 -696 -%! -713 -575 538 -679 -690 -%! -716 -382 557 -682 -701 -%! -716 -476 558 -679 -690 -%! -718 -425 565 -678 -686 -%! -719 -409 562 -679 -615 -%! -719 -508 523 -677 -737 -%! -721 -569 523 -679 -722 -%! -723 -434 542 -681 -735 -%! -723 -395 544 -676 -704 -%! -723 -428 542 -677 -729 -%! -722 -402 537 -677 -706 -%! -725 -380 534 -681 -696 -%! -726 -324 549 -676 -701 -%! -726 -211 578 -675 -614 -%! -727 -113 569 -677 -738 -%! -727 -208 554 -676 -737 -%! -727 -320 523 -684 -697 -%! -727 944 605 -680 -587 -%! -729 396 654 -681 -708 -%! -729 754 637 -682 -685 -%! -727 419 522 -677 -715 -%! -729 378 494 -668 -703 -%! -728 363 493 -669 -682 -%! -729 390 496 -665 -713 -%! -729 106 483 -664 -711 -%! -729 32 495 -661 -718 -%! -729 517 585 -661 -641 -%! -729 455 625 -659 -703 -%! -730 521 649 -687 -669 -%! -730 540 627 -689 -705 -%! -731 514 605 -694 -682 -%! -585 525 558 -685 -611 -%! -586 534 520 -680 -668 -%! -586 539 531 -681 -679 -%! -585 519 507 -682 -663 -%! -588 513 505 -667 -668 -%! -587 509 539 -680 -616 -%! -587 512 535 -668 -628 -%! -588 514 557 -667 -648 -%! -588 553 563 -676 -613 -%! -589 519 559 -684 -638 -%! -589 521 563 -682 -652 -%! -588 518 547 -678 -597 -%! -589 552 549 -688 -630 -%! -589 520 535 -685 -623 -%! -589 547 542 -678 -619 -%! -589 549 531 -684 -524 -%! -588 544 522 -1540 -580 -%! -588 564 555 -1538 -584 -%! -588 684 545 -1541 -564 -%! -590 558 546 -1541 -609 -%! -589 552 537 -1550 -601 -%! -591 532 526 -1548 -580 -%! -590 544 524 -1542 -565 -%! -591 559 535 -1538 -604 -%! -592 555 542 -1548 -629 -%! -591 577 532 -1549 -587 -%! -593 581 530 -1543 -585 -%! -592 562 540 -1548 -583 -%! -591 568 546 -1536 -587 -%! -593 550 557 -1533 -569 -%! -592 550 537 -1518 -527 -%! -593 568 551 -1533 -582 -%! -590 528 540 -1529 -492 -%! -590 542 532 -1525 -585 -%! -590 556 535 -1522 -606 -%! -591 637 535 -1516 -571 -%! -591 608 539 -1512 -582 -%! -591 545 527 -1510 -577 -%! ... [truncated message content] |
From: <par...@us...> - 2012-08-14 19:32:06
|
Revision: 10864 http://octave.svn.sourceforge.net/octave/?rev=10864&view=rev Author: paramaniac Date: 2012-08-14 19:32:00 +0000 (Tue, 14 Aug 2012) Log Message: ----------- control-devel: rename key Modified Paths: -------------- trunk/octave-forge/extra/control-devel/inst/__slicot_identification__.m trunk/octave-forge/extra/control-devel/inst/moen4.m trunk/octave-forge/extra/control-devel/inst/moesp.m trunk/octave-forge/extra/control-devel/inst/n4sid.m Modified: trunk/octave-forge/extra/control-devel/inst/__slicot_identification__.m =================================================================== --- trunk/octave-forge/extra/control-devel/inst/__slicot_identification__.m 2012-08-14 18:55:38 UTC (rev 10863) +++ trunk/octave-forge/extra/control-devel/inst/__slicot_identification__.m 2012-08-14 19:32:00 UTC (rev 10864) @@ -115,8 +115,7 @@ rcond = val; case "confirm" conf = logical (val); - case "noise" - ## FIXME: find a more speaking name than 'noise' for this option + case {"input", "inputs"} noise = val; otherwise warning ("%s: invalid property name '%s' ignored", method, key); Modified: trunk/octave-forge/extra/control-devel/inst/moen4.m =================================================================== --- trunk/octave-forge/extra/control-devel/inst/moen4.m 2012-08-14 18:55:38 UTC (rev 10863) +++ trunk/octave-forge/extra/control-devel/inst/moen4.m 2012-08-14 19:32:00 UTC (rev 10864) @@ -129,7 +129,7 @@ ## No confirmation. Default value. ## @end table ## -## @item 'noise' +## @item 'input' ## The desired type of noise input channels. ## @table @var ## @item 'n' Modified: trunk/octave-forge/extra/control-devel/inst/moesp.m =================================================================== --- trunk/octave-forge/extra/control-devel/inst/moesp.m 2012-08-14 18:55:38 UTC (rev 10863) +++ trunk/octave-forge/extra/control-devel/inst/moesp.m 2012-08-14 19:32:00 UTC (rev 10864) @@ -128,7 +128,7 @@ ## No confirmation. Default value. ## @end table ## -## @item 'noise' +## @item 'input' ## The desired type of noise input channels. ## @table @var ## @item 'n' Modified: trunk/octave-forge/extra/control-devel/inst/n4sid.m =================================================================== --- trunk/octave-forge/extra/control-devel/inst/n4sid.m 2012-08-14 18:55:38 UTC (rev 10863) +++ trunk/octave-forge/extra/control-devel/inst/n4sid.m 2012-08-14 19:32:00 UTC (rev 10864) @@ -128,7 +128,7 @@ ## No confirmation. Default value. ## @end table ## -## @item 'noise' +## @item 'input' ## The desired type of noise input channels. ## @table @var ## @item 'n' This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2012-08-14 18:55:45
|
Revision: 10863 http://octave.svn.sourceforge.net/octave/?rev=10863&view=rev Author: benjf5 Date: 2012-08-14 18:55:38 +0000 (Tue, 14 Aug 2012) Log Message: ----------- Removed looped lsreal, lscomplex; detabified fastlsreal.cc, cleaned up spaces in fastlscomplex. Modified Paths: -------------- trunk/octave-forge/extra/lssa/src/fastlscomplex.cc trunk/octave-forge/extra/lssa/src/fastlsreal.cc Removed Paths: ------------- trunk/octave-forge/extra/lssa/inst/lscomplex.m.old trunk/octave-forge/extra/lssa/inst/lsreal.m.old Deleted: trunk/octave-forge/extra/lssa/inst/lscomplex.m.old =================================================================== --- trunk/octave-forge/extra/lssa/inst/lscomplex.m.old 2012-08-14 16:51:37 UTC (rev 10862) +++ trunk/octave-forge/extra/lssa/inst/lscomplex.m.old 2012-08-14 18:55:38 UTC (rev 10863) @@ -1,68 +0,0 @@ -## 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 = 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); Deleted: trunk/octave-forge/extra/lssa/inst/lsreal.m.old =================================================================== --- trunk/octave-forge/extra/lssa/inst/lsreal.m.old 2012-08-14 16:51:37 UTC (rev 10862) +++ trunk/octave-forge/extra/lssa/inst/lsreal.m.old 2012-08-14 18:55:38 UTC (rev 10863) @@ -1,79 +0,0 @@ -## 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 <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {@var{transform} =} lsreal (@var{time}, @var{mag}, @var{maxfreq}, @var{numcoeff}, @var{numoctaves}) -## -## Return the real least-squares transform of the time series -## defined, based on the maximal frequency @var{maxfreq}, the -## number of coefficients @var{numcoeff}, and the number of -## octaves @var{numoctaves}. Each complex-valued result is the -## pair (c_o, s_o) defining the coefficients which best fit the -## function y = c_o * cos(ot) + s_o * sin(ot) to the (@var{time}, @var{mag}) data. -## -## @seealso{lscomplex} -## @end deftypefn - -function transform = lsreal (t, x, omegamax, ncoeff, noctave) - - ## FIXME : THIS IS VECTOR-ONLY. I'd need to add another bit of code to - ## make it array-safe, and that's not knowing right now what else - ## will be necessary. - k = n = length (t); - - transform = zeros (1, (noctave * ncoeff)); - - od = 2 ^ (- 1 / ncoeff); - o = omegamax; - n1 = 1 / n; - - ncoeffp = ncoeff * noctave; - - for iter = 1:ncoeffp - ## This method is an application of Eq. 8 on - ## page 6 of the text, as well as Eq. 7 - ot = o .* t; - - zeta = n1 * sum ((cos (ot) - i * sin (ot)) .* x); - - ot *= 2; - - iota = n1 * sum (cos (ot) - i * sin (ot)); - - - transform(iter) = (2 * (conj (zeta) - (conj (iota) * zeta)) / - (1 - (real (iota) ^ 2) - (imag (iota) ^ 2))); - - o *= od; - endfor - -endfunction - -%!test -%! 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 ) ); -%! # In the assert here, I've got an error bound large enough to catch -%! # individual system errors which would present no real issue. -%! assert (lsreal (t,x,maxfreq,2,2), -%! [(-1.68275915310663 + 4.70126183846743i), ... -%! (1.93821553170889 + 4.95660209883437i), ... -%! (4.38145452686697 + 2.14403733658600i), ... -%! (5.27425332281147 - 0.73933440226597i)], -%! 5e-10) Modified: trunk/octave-forge/extra/lssa/src/fastlscomplex.cc =================================================================== --- trunk/octave-forge/extra/lssa/src/fastlscomplex.cc 2012-08-14 16:51:37 UTC (rev 10862) +++ trunk/octave-forge/extra/lssa/src/fastlscomplex.cc 2012-08-14 18:55:38 UTC (rev 10863) @@ -43,12 +43,12 @@ \n\ @seealso{lscomplex, fastlsreal}\n\ \n\ -@end deftypefn") +@end deftypefn") { - octave_value_list retval; + octave_value_list retval; - if (args.length() != 5) + if (args.length() != 5) print_usage(); else { @@ -60,38 +60,37 @@ int ncoeff = args(4).int_value (); if (tvals.numel () != xvals.numel ()) - if (tvals.numel () > xvals.numel ()) + if (tvals.numel () > xvals.numel ()) error ("fastlscomplex: More time values than magnitude values"); - else + else error ("fastlscomplex: More magnitude values than time values"); - - if (ncoeff == 0) + if (ncoeff == 0) error ("fastlscomplex: No coefficients to compute"); - if (noctaves == 0) + if (noctaves == 0) error ("fastlscomplex: No octaves to compute over"); - if (omegamax == 0) + if (omegamax == 0) error ("fastlscomplex: No difference between minimal and maximal frequency"); - if (! error_state) + if (! error_state) { ComplexRowVector results; if (flscomplex (tvals, xvals, omegamax, noctaves, ncoeff, results)) retval(0) = octave_value (results); else error ("fastlscomplex: error in the underlying flscomplex function"); - } - + } + } return retval; } bool flscomplex (const RowVector & tvec, const ComplexRowVector & xvec, - double maxfreq, int octaves, int coefficients, - ComplexRowVector & results) + double maxfreq, int octaves, int coefficients, + ComplexRowVector & results) { - - struct Precomputation_Record + + struct Precomputation_Record { Precomputation_Record *next; std::complex<double> power_series[12]; // I'm using 12 as a matter of compatibility, only. @@ -112,19 +111,19 @@ int octave_iter, coeff_iter; - std::complex<double> zeta, zz, z_accumulator, exp_term, exp_multiplier, - alpha, h, *tpra, *temp_ptr_alpha, temp_alpha[12], *tprb, *temp_ptr_beta, + std::complex<double> zeta, zz, z_accumulator, exp_term, exp_multiplier, + alpha, h, *tpra, *temp_ptr_alpha, temp_alpha[12], *tprb, *temp_ptr_beta, temp_beta[12], temp_array[12], *p, x; octave_idx_type n = tvec.numel (); - for (int array_iter = 0; array_iter < 12; array_iter++) + for (int array_iter = 0; array_iter < 12; array_iter++) temp_array[array_iter] = std::complex<double> (0 , 0); - + int factorial_array[12]; factorial_array[0] = 1; - for (int i = 1; i < 12; i++) + for (int i = 1; i < 12; i++) factorial_array[i] = factorial_array[i-1] * i; n_1 = n_inv = 1.0 / n; @@ -244,7 +243,7 @@ record_current->stored_data = true; } - if (k >= n) + if (k >= n) break; tau_h = te + delta_tau; @@ -257,7 +256,7 @@ record_tail = record_current; record_current = precomp_records_head; record_tail->next = 0; - + /* Summation of coefficients for each frequency. As we have ncoeffs * noctaves elements, * it makes sense to work from the top down, as we have omega_max by default (maxfreq) */ @@ -267,18 +266,18 @@ octavemax = maxfreq; loop_tau_0 = tau_0; loop_delta_tau = delta_tau; - + octave_idx_type iter = 0; - + // Loops need to first travel over octaves, then coefficients; - for (octave_iter = octaves; ; + for (octave_iter = octaves; ; omega_oct *= 0.5, octavemax *= 0.5, loop_tau_0 += loop_delta_tau, loop_delta_tau *= 2) { o = omega_oct; omega_working = octavemax; - for (coeff_iter = 0; - coeff_iter < coefficients; - coeff_iter++, o *= omega_multiplier, + for (coeff_iter = 0; + coeff_iter < coefficients; + coeff_iter++, o *= omega_multiplier, omega_working *= omega_multiplier) { exp_term = std::complex<double> (cos (- omega_working * loop_tau_0), @@ -287,14 +286,14 @@ exp_multiplier = std::complex<double> (cos (- 2 * omega_working * loop_delta_tau) , sin (- 2 * omega_working * loop_delta_tau)); - for (zeta = 0, record_current = precomp_records_head; + for (zeta = 0, record_current = precomp_records_head; record_current; record_current = record_current->next, exp_term *= exp_multiplier ) { - if (record_current->stored_data) + if (record_current->stored_data) { int p; - for (zz = 0, p = 0, on_1 = n_1; p < 12; p++) + for (zz = 0, p = 0, on_1 = n_1; p < 12; p++) { zz += record_current->power_series[p] * on_1; on_1 *= o; @@ -302,40 +301,39 @@ zeta += exp_term * zz; } } - results(iter) = std::complex<double> (zeta); iter++; } - if (! (--octave_iter)) + if (! (--octave_iter)) break; - + /* If we've already reached the lowest value, stop. * Otherwise, merge with the next computation range. */ double *exp_pse_ptr, *exp_ptr, exp_power_series_elements[12]; exp_power_series_elements[0] = 1; exp_pse_ptr = exp_ptr = exp_power_series_elements; - - for (int r_iter = 1; r_iter < 12; r_iter++) + + for (int r_iter = 1; r_iter < 12; r_iter++) exp_power_series_elements[r_iter] = exp_power_series_elements[r_iter-1] * (mu * loop_delta_tau) * (1.0 / ((double) r_iter)); - + try - { - for (record_current = precomp_records_head; + { + for (record_current = precomp_records_head; record_current; - record_current = record_current->next) + record_current = record_current->next) { - if (! (record_ref = record_current->next ) - || ! record_ref->stored_data ) + if (! (record_ref = record_current->next ) + || ! record_ref->stored_data ) { // In this case, there is no next record, but this record has data. - if (record_current->stored_data) + if (record_current->stored_data) { int p = 0; for (exp_pse_ptr = exp_power_series_elements + 1, temp_ptr_alpha = temp_alpha; - p < 12; - p++ , exp_pse_ptr++) + p < 12; + p++ , exp_pse_ptr++) { tpra = temp_ptr_alpha; *(temp_ptr_alpha++) = std::complex<double>(record_current->power_series[p]); @@ -348,29 +346,29 @@ * actually be accessed for the first iterations, it's easier. */ - if (++exp_ptr >= exp_pse_ptr) + if (++exp_ptr >= exp_pse_ptr) break; --tpra; h = *tpra * *exp_ptr; record_current->power_series[p].real() -= h.imag(); record_current->power_series[p].imag() += h.real(); - - if (++exp_ptr >= exp_pse_ptr ) + + if (++exp_ptr >= exp_pse_ptr ) break; --tpra; record_current->power_series[p] -= *tpra * *exp_ptr; - if (++exp_ptr >= exp_pse_ptr) + if (++exp_ptr >= exp_pse_ptr) break; --tpra; h = -*tpra * *exp_ptr; record_current->power_series[p].real() -= h.imag(); record_current->power_series[p].imag() += h.real(); - - if (++exp_ptr >= exp_pse_ptr) + + if (++exp_ptr >= exp_pse_ptr) break; --tpra; @@ -378,112 +376,112 @@ } } - if ( ! record_ref ) + if ( ! record_ref ) break; // Last record was reached - } - else + } + else { record_next = record_ref; - if ( record_current->stored_data ) + if ( record_current->stored_data ) { int p = 0, q = 0; for (exp_pse_ptr = exp_power_series_elements + 1, temp_ptr_alpha = temp_alpha, temp_ptr_beta = temp_beta; - p < 12; p++, q++, exp_pse_ptr++) + p < 12; p++, q++, exp_pse_ptr++) { tpra = temp_ptr_alpha; *temp_ptr_alpha++ = record_current->power_series[p] + record_next->power_series[q]; *temp_ptr_beta++ = record_current->power_series[p] - record_next->power_series[1]; tprb = temp_ptr_beta; - + for (exp_ptr = exp_power_series_elements, record_current->power_series[p] = *tpra * *exp_ptr; ;) { - if (++exp_ptr >= exp_pse_ptr ) + if (++exp_ptr >= exp_pse_ptr ) break; - + tprb -= 2; h = *tprb * *exp_ptr; record_current->power_series[p].real() -= h.imag(); record_current->power_series[p].imag() += h.real(); - - if ( ++exp_ptr >= exp_pse_ptr ) + + if ( ++exp_ptr >= exp_pse_ptr ) break; - + tpra -= 2; record_current->power_series[p] -= *tpra * *exp_ptr; - - if (++exp_ptr >= exp_pse_ptr) + + if (++exp_ptr >= exp_pse_ptr) break; - + tprb -= 2; h = - *tprb * *exp_ptr; record_current->power_series[p].real() -= h.imag(); record_current->power_series[p].imag() += h.real(); - - if (++exp_ptr >= exp_pse_ptr) + + if (++exp_ptr >= exp_pse_ptr) break; - + tpra -= 2; record_current->power_series[p] += *tpra * *exp_ptr; } } - } + } else { int q = 0; - for (exp_pse_ptr = exp_power_series_elements + 1, - temp_ptr_alpha = temp_alpha, - temp_ptr_beta = temp_beta; - q < 12; - q++, exp_pse_ptr++) + for (exp_pse_ptr = exp_power_series_elements + 1, + temp_ptr_alpha = temp_alpha, + temp_ptr_beta = temp_beta; + q < 12; + q++, exp_pse_ptr++) { tpra = temp_ptr_alpha; *temp_ptr_alpha++ = std::complex<double>(record_next->power_series[q]); - - for (exp_ptr = exp_power_series_elements, + + for (exp_ptr = exp_power_series_elements, record_next->power_series[q] = *tpra * *exp_ptr; ;) { - if (++exp_ptr >= exp_pse_ptr) + if (++exp_ptr >= exp_pse_ptr) break; - + --tpra; h = *tpra * *exp_ptr; record_next->power_series[q].real() -= h.imag(); record_next->power_series[q].imag() += h.real(); - - if (++exp_ptr >= exp_pse_ptr) + + if (++exp_ptr >= exp_pse_ptr) break; - + --tpra; record_next->power_series[q] -= *tpra * *exp_ptr; - - if ( ++exp_ptr >= exp_pse_ptr ) + + if ( ++exp_ptr >= exp_pse_ptr ) break; - + --tpra; h = -*tpra * *exp_ptr; record_next->power_series[q].real() -= h.imag(); record_next->power_series[q].imag() += h.real(); - - if (++exp_ptr >= exp_pse_ptr) + + if (++exp_ptr >= exp_pse_ptr) break; - + --tpra; record_next->power_series[q] += *tpra * *exp_ptr; } } } - + record_current->stored_data = true; record_ref = record_next; record_current->next = record_ref->next; delete record_ref; - + } } } - } - catch (std::exception & e) + } + catch (std::exception & e) {//This section was part of my debugging, and may be removed. std::cout << "Exception thrown: " << e.what() << std::endl; return (false); Modified: trunk/octave-forge/extra/lssa/src/fastlsreal.cc =================================================================== --- trunk/octave-forge/extra/lssa/src/fastlsreal.cc 2012-08-14 16:51:37 UTC (rev 10862) +++ trunk/octave-forge/extra/lssa/src/fastlsreal.cc 2012-08-14 18:55:38 UTC (rev 10863) @@ -25,11 +25,11 @@ #include <exception> ComplexRowVector flsreal( RowVector tvec , ComplexRowVector xvec , - double maxfreq , int octaves , int coefficients); + double maxfreq , int octaves , int coefficients); DEFUN_DLD(fastlsreal,args,nargout, - "-*- texinfo -*-\n\ + "-*- texinfo -*-\n\ @deftypefn {Function File} { C = } fastlsreal(@var{time},@var{magnitude},@var{maximum_frequency},@var{octaves},@var{coefficients})\n\ \n\ Return the real least-sqaures spectral fit to the (@var{time},@var{magnitude})\n\ @@ -68,7 +68,7 @@ } ComplexRowVector flsreal( RowVector tvec , RowVector xvec , - double maxfreq, int octaves, int coefficients ) { + double maxfreq, int octaves, int coefficients ) { struct XTElem { double x, t; }; @@ -169,55 +169,55 @@ for(k++; ( k < n ) && tvec(k) < te ; k++ ) { x = xvec(k); { - double t = mu*(tvec(k)-tau_h), tt; - p = record_current->power_series; - // p = 0 - p->x += x; - (p++)->t += 1; - // p = 1 - tt = -t; - p->x += x * tt; - (p++)->t += tt; - // p = 2 - tt *= t*(1.0/2.0); - p->x += x * tt; - (p++)->t += tt; - // p = 3 - tt *= t*(-1.0/3.0); - p->x += x * tt; - (p++)->t += tt; - // p = 4 - tt *= t*(1.0/4.0); - p->x += x * tt; - (p++)->t += tt; - // p = 5 - tt *= t*(-1.0/5.0); - p->x += x * tt; - (p++)->t += tt; - // p = 6 - tt *= t*(1.0/6.0); - p->x += x * tt; - (p++)->t += tt; - // p = 7 - tt *= t*(-1.0/7.0); - p->x += x * tt; - (p++)->t += tt; - // p = 8 - tt *= t*(1.0/8.0); - p->x += x * tt; - (p++)->t += tt; - // p = 9 - tt *= t*(-1.0/9.0); - p->x += x * tt; - (p++)->t += tt; - // p = 10 - tt *= t*(1.0/10.0); - p->x += x * tt; - (p++)->t += tt; - // p = 11 - tt *= t*(-1.0/11.0); - p->x += x * tt; - (p++)->t += tt; + double t = mu*(tvec(k)-tau_h), tt; + p = record_current->power_series; + // p = 0 + p->x += x; + (p++)->t += 1; + // p = 1 + tt = -t; + p->x += x * tt; + (p++)->t += tt; + // p = 2 + tt *= t*(1.0/2.0); + p->x += x * tt; + (p++)->t += tt; + // p = 3 + tt *= t*(-1.0/3.0); + p->x += x * tt; + (p++)->t += tt; + // p = 4 + tt *= t*(1.0/4.0); + p->x += x * tt; + (p++)->t += tt; + // p = 5 + tt *= t*(-1.0/5.0); + p->x += x * tt; + (p++)->t += tt; + // p = 6 + tt *= t*(1.0/6.0); + p->x += x * tt; + (p++)->t += tt; + // p = 7 + tt *= t*(-1.0/7.0); + p->x += x * tt; + (p++)->t += tt; + // p = 8 + tt *= t*(1.0/8.0); + p->x += x * tt; + (p++)->t += tt; + // p = 9 + tt *= t*(-1.0/9.0); + p->x += x * tt; + (p++)->t += tt; + // p = 10 + tt *= t*(1.0/10.0); + p->x += x * tt; + (p++)->t += tt; + // p = 11 + tt *= t*(-1.0/11.0); + p->x += x * tt; + (p++)->t += tt; } record_current->stored_data = true; } @@ -250,33 +250,33 @@ omega_working = octavemax; for ( coeff_iter = 0 ; coeff_iter < coefficients ; coeff_iter++, o *= omega_multiplier, omega_working *= omega_multiplier){ exp_term = std::complex<double> ( cos( - omega_working * loop_tau_0 ) , - sin ( - omega_working * loop_tau_0 ) ); + sin ( - omega_working * loop_tau_0 ) ); exp_squared = exp_term * exp_term; exp_multiplier = std::complex<double> ( cos ( - 2 * omega_working * loop_delta_tau ) , - sin ( - 2 * omega_working * loop_delta_tau ) ); + sin ( - 2 * omega_working * loop_delta_tau ) ); exp_squared_multiplier = exp_multiplier * exp_multiplier; for ( zeta = iota = 0, record_current = precomp_records_head ; record_current ; - record_current = record_current->next, exp_term *= exp_multiplier, + record_current = record_current->next, exp_term *= exp_multiplier, exp_squared *= exp_squared_multiplier ) { - if ( record_current->stored_data ) { - int p; - for ( zz = ii = 0 , p = 0, on_1 = n_1 ; p < 12 ; ) { - zz.real() += record_current->power_series[p]->x * on_1; - ii.real() += record_current->power_series[p++]-> t * o2n_1; - on_1 *= o; - o2n_1 *= o2; - zz.imag() += record_current->power_series[p]->x * on_1; - ii.imag() += record_current->power_series[p++]-> t * o2n_1; - on_1 *= o; - o2n_1 *= o2; - } - zeta += exp_term * zz; - iota += exp_squared * ii; - } + if ( record_current->stored_data ) { + int p; + for ( zz = ii = 0 , p = 0, on_1 = n_1 ; p < 12 ; ) { + zz.real() += record_current->power_series[p]->x * on_1; + ii.real() += record_current->power_series[p++]-> t * o2n_1; + on_1 *= o; + o2n_1 *= o2; + zz.imag() += record_current->power_series[p]->x * on_1; + ii.imag() += record_current->power_series[p++]-> t * o2n_1; + on_1 *= o; + o2n_1 *= o2; + } + zeta += exp_term * zz; + iota += exp_squared * ii; + } } results(iter) = 2 / ( 1 - ( iota.real() * iota.real() ) - (iota.imag() * - iota.imag() ) - * ( conj(zeta) - conj(iota) * zeta ); + iota.imag() ) + * ( conj(zeta) - conj(iota) * zeta ); iter++; } if ( !(--octave_iter) ) break; @@ -288,104 +288,104 @@ exp_pse_ptr = exp_ptr = exp_power_series_elements; for ( int r_iter = 1 ; r_iter < 12 ; r_iter++ ) { exp_power_series_elements[r_iter] = exp_power_series_elements[r_iter-1] - * ( mu * loop_delta_tau) * ( 1.0 / ( (double) r_iter ) ); + * ( mu * loop_delta_tau) * ( 1.0 / ( (double) r_iter ) ); } try{ for ( record_current = precomp_records_head ; record_current ; - record_current = record_current->next ) { - if ( ! ( record_ref = record_current->next ) || ! record_ref->stored_data ) { - // In this case, there is no next record, but this record has data. - if ( record_current->stored_data ) { - int p = 0; - for( exp_pse_ptr = exp_power_series_elements , temp_ptr_alpha = temp_alpha ; ; ) { - tpra = temp_ptr_alpha; - temp_ptr_alpha->x = record_current->power_series[p]->x; - (temp_ptr_alpha++)->t = record_current->power_series[p]->t; - temp_ptr_beta->x = -record_current->power_series[p]->x; - (temp_ptr_beta++)->t = -record_current->power_series[p]->t; - for( exp_ptr = exp_pse_ptr++, record_current->power_series[p]->x = tpra->x * *exp_ptr, record_current->power_series[p]->t = tpra->t * *exp_ptr ; ; ) { - /* This next block is from Mathias' code, and it does a few - * ... unsavoury things. First off, it uses conditionals with - * break in order to avoid potentially accessing null regions - * of memory, and then it does ... painful things with a few - * numbers. However, remembering that most of these will not - * actually be accessed for the first iterations, it's easier. - */ - if ( --exp_ptr < exp_power_series_elements ) break; - ++tpra; - record_current->power_series[p]->x -= tpra->x * *exp_ptr; - record_current->power_series[p]->t -= tpra->t * *exp_ptr; - if ( --exp_ptr < exp_power_series_elements ) break; - ++tpra; - record_current->power_series[p]->x += tpra->x * *exp_ptr; - record_current->power_series[p]->t += tpra->x * *exp_ptr; - } - if ( ++p >= 12 ) break; - temp_ptr_alpha->x = -record_current->power_series[p]->x; - (temp_ptr_alpha++)->t = -record_current->power_series[p]->t; - temp_ptr_beta->x = record_current->power_series[p]->x; - (temp_ptr_beta++)->t = record_current->power_series[p]->t; - for( tprb = temp_beta, exp_ptr = exp_pse_ptr++, record_current->power_series[p]->t = tprb->t * *exp_ptr; exp_ptr > exp_power_series_elements ; ) { - ++tprb; - --exp_ptr; - record_current->power_series[p]->t += tprb->t * *exp_ptr; - } - if ( ++p >= 12 ) break; - } - } - if ( ! record_ref ) break; // Last record was reached - } - else { - record_next = record_ref; - if ( record_current->stored_data ) { - int p = 0; - for( exp_pse_ptr = exp_power_series_elements, temp_ptr_alpha = temp_alpha, temp_ptr_beta = temp_beta; ; ) { - temp_ptr_alpha->x = record_current->power_series[p]->x + record_next->power_series[p]->x; - (temp_ptr_alpha++)->t = record_current->power_series[p]->t + record_next->power_series[p]->t; - temp_ptr_beta->x = record_ref->power_series[p]->x - record_current->power_series[p]->x; - (temp_ptr_beta++)->t = record_ref->power_series[p]->t - record_current->power_series[p]->t; - for( tpra = temp_alpha, exp_ptr = exp_pse_ptr++, record_current->power_series[p]->x = tpra->x * *exp_ptr, record_current->power_series[p]->t = tpra->x * *exp_ptr; ; ) { - if ( --exp_ptr < exp_pse_ptr ) break; - ++tpra; - record_current->power_series[p]->x -= tpra->x * *exp_ptr; - record_current->power_series[p]->t -= tpra->t * *exp_ptr; - if ( --exp_ptr < exp_pse_ptr ) break; - ++tpra; - record_current->power_series[p]->x += tpra->x * *exp_ptr; - record_current->power_series[p]->t += tpra->t * *exp_ptr; - } - if ( ++p >= 12 ) break; - temp_ptr_alpha->x = record_next->power_series[p]->x - record_current->power_series[p]->x; - (temp_ptr_alpha++)->t = record_next->power_series[p]->t - record_current->power_series[p]->t; - temp_ptr_beta->x = record_current->power_series[p]->x + record_next->power_series[p]->x; - (temp_ptr_beta++)->t = record_current->power_series[p]->t + record_next->power_series[p]->t; - for(tprb = temp_beta, exp_ptr = exp_pse_ptr++, record_current->power_series[p]->x = tprb->x * *exp_ptr, record_current->power_series[p]->t = tprb->x * *exp_ptr; exp_ptr > exp_power_series_elements; ) { - ++tprb; - --exp_ptr; - record_current->power_series[p]->x += tprb->x * *exp_ptr; - record_current->power_series[p]->t += tprb->t * *exp_ptr; - } - if ( ++p >= 12 ) break; - } - } else { - int q = 0; - for( exp_pse_ptr = exp_power_series_elements, temp_ptr_alpha = temp_alpha, temp_ptr_beta = temp_beta; ; ) { - temp_ptr_alpha->x = record_next->power_series[q]->x; - temp_ptr_alpha->t = record_next->power_series[q]->t; - for(tpra = temp_alpha, exp_ptr = exp_pse_ptr++, record_next->power_series[q]->x = tpra->x * *exp_ptr, record_next->power_series[q]->t = tpra->t * *exp_ptr; exp_ptr > exp_power_series_elements; ) { - ++tpra; - --exp_ptr; - record_next->power_series[q]->x += tpra->x * *exp_ptr; - record_next->power_series[q]->t += tpra->t * *exp_ptr; - } - if ( ++q >= 12 ) break; - } - record_current->stored_data = true; - record_ref = record_next; - record_current->next = record_ref->next; - record_next = 0; - delete record_ref; - } + record_current = record_current->next ) { + if ( ! ( record_ref = record_current->next ) || ! record_ref->stored_data ) { + // In this case, there is no next record, but this record has data. + if ( record_current->stored_data ) { + int p = 0; + for( exp_pse_ptr = exp_power_series_elements , temp_ptr_alpha = temp_alpha ; ; ) { + tpra = temp_ptr_alpha; + temp_ptr_alpha->x = record_current->power_series[p]->x; + (temp_ptr_alpha++)->t = record_current->power_series[p]->t; + temp_ptr_beta->x = -record_current->power_series[p]->x; + (temp_ptr_beta++)->t = -record_current->power_series[p]->t; + for( exp_ptr = exp_pse_ptr++, record_current->power_series[p]->x = tpra->x * *exp_ptr, record_current->power_series[p]->t = tpra->t * *exp_ptr ; ; ) { + /* This next block is from Mathias' code, and it does a few + * ... unsavoury things. First off, it uses conditionals with + * break in order to avoid potentially accessing null regions + * of memory, and then it does ... painful things with a few + * numbers. However, remembering that most of these will not + * actually be accessed for the first iterations, it's easier. + */ + if ( --exp_ptr < exp_power_series_elements ) break; + ++tpra; + record_current->power_series[p]->x -= tpra->x * *exp_ptr; + record_current->power_series[p]->t -= tpra->t * *exp_ptr; + if ( --exp_ptr < exp_power_series_elements ) break; + ++tpra; + record_current->power_series[p]->x += tpra->x * *exp_ptr; + record_current->power_series[p]->t += tpra->x * *exp_ptr; + } + if ( ++p >= 12 ) break; + temp_ptr_alpha->x = -record_current->power_series[p]->x; + (temp_ptr_alpha++)->t = -record_current->power_series[p]->t; + temp_ptr_beta->x = record_current->power_series[p]->x; + (temp_ptr_beta++)->t = record_current->power_series[p]->t; + for( tprb = temp_beta, exp_ptr = exp_pse_ptr++, record_current->power_series[p]->t = tprb->t * *exp_ptr; exp_ptr > exp_power_series_elements ; ) { + ++tprb; + --exp_ptr; + record_current->power_series[p]->t += tprb->t * *exp_ptr; + } + if ( ++p >= 12 ) break; + } + } + if ( ! record_ref ) break; // Last record was reached + } + else { + record_next = record_ref; + if ( record_current->stored_data ) { + int p = 0; + for( exp_pse_ptr = exp_power_series_elements, temp_ptr_alpha = temp_alpha, temp_ptr_beta = temp_beta; ; ) { + temp_ptr_alpha->x = record_current->power_series[p]->x + record_next->power_series[p]->x; + (temp_ptr_alpha++)->t = record_current->power_series[p]->t + record_next->power_series[p]->t; + temp_ptr_beta->x = record_ref->power_series[p]->x - record_current->power_series[p]->x; + (temp_ptr_beta++)->t = record_ref->power_series[p]->t - record_current->power_series[p]->t; + for( tpra = temp_alpha, exp_ptr = exp_pse_ptr++, record_current->power_series[p]->x = tpra->x * *exp_ptr, record_current->power_series[p]->t = tpra->x * *exp_ptr; ; ) { + if ( --exp_ptr < exp_pse_ptr ) break; + ++tpra; + record_current->power_series[p]->x -= tpra->x * *exp_ptr; + record_current->power_series[p]->t -= tpra->t * *exp_ptr; + if ( --exp_ptr < exp_pse_ptr ) break; + ++tpra; + record_current->power_series[p]->x += tpra->x * *exp_ptr; + record_current->power_series[p]->t += tpra->t * *exp_ptr; + } + if ( ++p >= 12 ) break; + temp_ptr_alpha->x = record_next->power_series[p]->x - record_current->power_series[p]->x; + (temp_ptr_alpha++)->t = record_next->power_series[p]->t - record_current->power_series[p]->t; + temp_ptr_beta->x = record_current->power_series[p]->x + record_next->power_series[p]->x; + (temp_ptr_beta++)->t = record_current->power_series[p]->t + record_next->power_series[p]->t; + for(tprb = temp_beta, exp_ptr = exp_pse_ptr++, record_current->power_series[p]->x = tprb->x * *exp_ptr, record_current->power_series[p]->t = tprb->x * *exp_ptr; exp_ptr > exp_power_series_elements; ) { + ++tprb; + --exp_ptr; + record_current->power_series[p]->x += tprb->x * *exp_ptr; + record_current->power_series[p]->t += tprb->t * *exp_ptr; + } + if ( ++p >= 12 ) break; + } + } else { + int q = 0; + for( exp_pse_ptr = exp_power_series_elements, temp_ptr_alpha = temp_alpha, temp_ptr_beta = temp_beta; ; ) { + temp_ptr_alpha->x = record_next->power_series[q]->x; + temp_ptr_alpha->t = record_next->power_series[q]->t; + for(tpra = temp_alpha, exp_ptr = exp_pse_ptr++, record_next->power_series[q]->x = tpra->x * *exp_ptr, record_next->power_series[q]->t = tpra->t * *exp_ptr; exp_ptr > exp_power_series_elements; ) { + ++tpra; + --exp_ptr; + record_next->power_series[q]->x += tpra->x * *exp_ptr; + record_next->power_series[q]->t += tpra->t * *exp_ptr; + } + if ( ++q >= 12 ) break; + } + record_current->stored_data = true; + record_ref = record_next; + record_current->next = record_ref->next; + record_next = 0; + delete record_ref; + } } } return results; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2012-08-14 16:51:44
|
Revision: 10862 http://octave.svn.sourceforge.net/octave/?rev=10862&view=rev Author: benjf5 Date: 2012-08-14 16:51:37 +0000 (Tue, 14 Aug 2012) Log Message: ----------- Fixed help string that wouldn't have a proper first line in lssa. Modified Paths: -------------- trunk/octave-forge/extra/lssa/inst/lscorrcoeff.m Modified: trunk/octave-forge/extra/lssa/inst/lscorrcoeff.m =================================================================== --- trunk/octave-forge/extra/lssa/inst/lscorrcoeff.m 2012-08-14 16:27:34 UTC (rev 10861) +++ trunk/octave-forge/extra/lssa/inst/lscorrcoeff.m 2012-08-14 16:51:37 UTC (rev 10862) @@ -18,14 +18,15 @@ ## @deftypefnx {Function File} {@var{c} =} lscorrcoeff (@var{time1}, @var{mag1}, @var{time2}, @var{mag2}, @var{time}, @var{freq}, @var{window} = @var{cubicwgt}) ## @deftypefnx {Function File} {@var{c} =} lscorrcoeff (@var{time1}, @var{mag1}, @var{time2}, @var{mag2}, @var{time}, @var{freq}, @var{window} = @var{cubicwgt}, @var{winradius} = 1) ## -## Return the coefficient of the wavelet correlation of two complex-valued time -## series at a given time and frequency. The windowing function applied by -## default is cubicwgt, this can be changed by passing a different function -## handle to @var{window}, while the radius applied is set by @var{winradius}. -## Note that this will be most effective when both series have had their mean -## value (if it is not zero) subtracted (and stored separately); this reduces -## the constant-offset error further, and allows the functions to be compared on -## their periodic features rather than their constant features. +## Return the coefficient of the wavelet correlation of two complex time +## series. The correlation is only effective at a given time and frequency. +## The windowing function applied by default is cubicwgt, this can be changed by +## passing a different function handle to @var{window}, while the radius applied +## is set by @var{winradius}. Note that this will be most effective when both +## series have had their mean value (if it is not zero) subtracted (and stored +## separately); this reduces the constant-offset error further, and allows the +## functions to be compared on their periodic features rather than their +## constant features. ## ## @seealso{lswaveletcoeff, lscomplexwavelet, lsrealwavelet} ## This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2012-08-14 16:27:42
|
Revision: 10861 http://octave.svn.sourceforge.net/octave/?rev=10861&view=rev Author: benjf5 Date: 2012-08-14 16:27:34 +0000 (Tue, 14 Aug 2012) Log Message: ----------- DESCRIPTION update for lssa due to broadcasting, other miscellaneous help string changes. Modified Paths: -------------- trunk/octave-forge/extra/lssa/DESCRIPTION trunk/octave-forge/extra/lssa/inst/lscomplexwavelet.m trunk/octave-forge/extra/lssa/src/fastlscomplex.cc Modified: trunk/octave-forge/extra/lssa/DESCRIPTION =================================================================== --- trunk/octave-forge/extra/lssa/DESCRIPTION 2012-08-14 13:42:51 UTC (rev 10860) +++ trunk/octave-forge/extra/lssa/DESCRIPTION 2012-08-14 16:27:34 UTC (rev 10861) @@ -10,6 +10,6 @@ URLs). Url: http://www.jstatsoft.org/v11/i02 Problems: fast implementations, wavelet functions are currently not functional. -Depends: octave (>= 3.4.3) +Depends: octave (>= 3.6.0) Autoload: no License: GPLv3+ Modified: trunk/octave-forge/extra/lssa/inst/lscomplexwavelet.m =================================================================== --- trunk/octave-forge/extra/lssa/inst/lscomplexwavelet.m 2012-08-14 13:42:51 UTC (rev 10860) +++ trunk/octave-forge/extra/lssa/inst/lscomplexwavelet.m 2012-08-14 16:27:34 UTC (rev 10861) @@ -13,8 +13,11 @@ ## 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} =} lscomplexwavelet (@var{time}, +##@var{mag}, @var{maxfreq}, @var{numcoeff}, @var{numoctave}, - function transform = lscomplexwavelet( T, X, omegamax, ncoeff, noctave, tmin, tmax, tstep, sigma = 0.05) ## This is a transform based entirely on the simplified complex-valued transform Modified: trunk/octave-forge/extra/lssa/src/fastlscomplex.cc =================================================================== --- trunk/octave-forge/extra/lssa/src/fastlscomplex.cc 2012-08-14 13:42:51 UTC (rev 10860) +++ trunk/octave-forge/extra/lssa/src/fastlscomplex.cc 2012-08-14 16:27:34 UTC (rev 10861) @@ -25,16 +25,22 @@ #include <exception> bool flscomplex (const RowVector & tvec, const ComplexRowVector & xvec, - double maxfreq, int octaves, int coefficients, ComplexRowVector & result); + double maxfreq, int coefficients, int octaves, ComplexRowVector & result); DEFUN_DLD(fastlscomplex,args,nargout, "-*- texinfo -*-\n\ @deftypefn {Function File} { C = } fastlscomplex \ -(@var{time},@var{magnitude},@var{maximum_frequency},@var{octaves},@var{coefficients})\n \ +(@var{time},@var{magnitude},@var{maxfreq},@var{ncoeff},@var{noctave})\n \ \n\ -Return the complex least squares transform of the (@var{time},@var{magnitude}) series\n\ -supplied, using the fast algorithm.\n\ +Return a series of least-squares transforms of a complex time series via a divide and\n\ +conquer algorithm. Each transform is minimized independently at each frequency,\n\ +starting from @var{maxfreq} and descending over @var{ncoeff} frequencies for\n\ +each of @var{noctave} octaves.\n\ \n\ +For each result, the complex result for a given frequency o defines the real and\n\ +imaginary sinusoids which have the least distance to the data set: for a + bi,\n\ +the matching sinusoids are a cos (ot) + b i sin (ot).\n\ +\n\ @seealso{lscomplex, fastlsreal}\n\ \n\ @end deftypefn") This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2012-08-14 13:42:59
|
Revision: 10860 http://octave.svn.sourceforge.net/octave/?rev=10860&view=rev Author: benjf5 Date: 2012-08-14 13:42:51 +0000 (Tue, 14 Aug 2012) Log Message: ----------- Moved to loopless LS transforms, rewrote and improved help strings for all functions in lssa. Modified Paths: -------------- trunk/octave-forge/extra/lssa/inst/cubicwgt.m trunk/octave-forge/extra/lssa/inst/lombcoeff.m trunk/octave-forge/extra/lssa/inst/lombnormcoeff.m trunk/octave-forge/extra/lssa/inst/lscorrcoeff.m trunk/octave-forge/extra/lssa/inst/lswaveletcoeff.m Added Paths: ----------- trunk/octave-forge/extra/lssa/inst/lscomplex.m trunk/octave-forge/extra/lssa/inst/lscomplex.m.old trunk/octave-forge/extra/lssa/inst/lsreal.m trunk/octave-forge/extra/lssa/inst/lsreal.m.old Removed Paths: ------------- trunk/octave-forge/extra/lssa/inst/fastlscomplex.m trunk/octave-forge/extra/lssa/inst/lscomplex.m trunk/octave-forge/extra/lssa/inst/lsreal.m Modified: trunk/octave-forge/extra/lssa/inst/cubicwgt.m =================================================================== --- trunk/octave-forge/extra/lssa/inst/cubicwgt.m 2012-08-13 02:06:19 UTC (rev 10859) +++ trunk/octave-forge/extra/lssa/inst/cubicwgt.m 2012-08-14 13:42:51 UTC (rev 10860) @@ -15,11 +15,19 @@ ## -*- texinfo -*- ## @deftypefn {Function File} {@var{a} =} cubicwgt (@var{series}) -## Return @var{series} as windowed by a cubic polynomial, -## 1 + ( x ^ 2 * ( 2 x - 3 ) ), assuming x is in [-1,1]. +## +## Returns the input series, windowed by a polynomial similar to a Hanning +## window. To window an arbitrary section of the series, subtract or add an +## offset to it to adjust the centre of the window; for an offset of k, the call +## would be cubicwgt (@var{s} - k). Similarly, the radius of the window is 1; +## if an arbitrary radius r is desired, dividing the series by the radius after +## centering is the best way to adjust to fit the window: cubicwgt ((@var{s} - +## k) / r). +## +## The windowing function itself is: +## w = 1 + ( x ^ 2 * ( 2 x - 3 ) ), x in [-1,1], else w = 0. ## This function implements the windowing function on page 10 of the paper. -## if t is in [-1,1] then the windowed term is a = 1 + ( |t|^2 * ( 2|t| - 3 ) -## else the windowed term is 0. +## ## @end deftypefn function a = cubicwgt (s) Deleted: trunk/octave-forge/extra/lssa/inst/fastlscomplex.m =================================================================== --- trunk/octave-forge/extra/lssa/inst/fastlscomplex.m 2012-08-13 02:06:19 UTC (rev 10859) +++ trunk/octave-forge/extra/lssa/inst/fastlscomplex.m 2012-08-14 13:42:51 UTC (rev 10860) @@ -1,55 +0,0 @@ -## 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); Modified: trunk/octave-forge/extra/lssa/inst/lombcoeff.m =================================================================== --- trunk/octave-forge/extra/lssa/inst/lombcoeff.m 2012-08-13 02:06:19 UTC (rev 10859) +++ trunk/octave-forge/extra/lssa/inst/lombcoeff.m 2012-08-14 13:42:51 UTC (rev 10860) @@ -16,8 +16,7 @@ ## -*- texinfo -*- ## @deftypefn {Function File} {@var{c} =} lombcoeff (@var{time}, @var{mag}, @var{freq}) ## -## Return the coefficient of the Lomb periodogram (unnormalized) for the -## (@var{time},@var{mag}) series for the @var{freq} provided. +## Return the Lomb Periodogram value at one frequency for a time series. ## ## @seealso{lombnormcoeff} ## @end deftypefn Modified: trunk/octave-forge/extra/lssa/inst/lombnormcoeff.m =================================================================== --- trunk/octave-forge/extra/lssa/inst/lombnormcoeff.m 2012-08-13 02:06:19 UTC (rev 10859) +++ trunk/octave-forge/extra/lssa/inst/lombnormcoeff.m 2012-08-14 13:42:51 UTC (rev 10860) @@ -16,10 +16,11 @@ ## -*- texinfo -*- ## @deftypefn {Function File} {@var{c} =} lombnormcoeff (@var{time}, @var{mag}, @var{freq}) ## -## Return the coefficient of the Lomb Normalised Periodogram at the -## specified @var{frequency} of the periodogram applied to the -## (@var{time}, @var{mag}) series. +## Return the normalized Lomb Periodogram value at one frequency for a time +## series. ## +## @seealso{lombcoeff} +## ## @end deftypefn Deleted: trunk/octave-forge/extra/lssa/inst/lscomplex.m =================================================================== --- trunk/octave-forge/extra/lssa/inst/lscomplex.m 2012-08-13 02:06:19 UTC (rev 10859) +++ trunk/octave-forge/extra/lssa/inst/lscomplex.m 2012-08-14 13:42:51 UTC (rev 10860) @@ -1,68 +0,0 @@ -## 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 = 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); Copied: trunk/octave-forge/extra/lssa/inst/lscomplex.m (from rev 10856, trunk/octave-forge/extra/lssa/inst/fastlscomplex.m) =================================================================== --- trunk/octave-forge/extra/lssa/inst/lscomplex.m (rev 0) +++ trunk/octave-forge/extra/lssa/inst/lscomplex.m 2012-08-14 13:42:51 UTC (rev 10860) @@ -0,0 +1,61 @@ +## 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 a series of least-squares transforms of a complex-valued time series. +## Each transform is minimized independently at each frequency. @var{numcoeff} +## frequencies are tested for each of @var{numoctaves} octaves, starting from +## @var{maxfreq}. +## +## Each result (a + bi) at a given frequency, o, defines the real and imaginary +## coefficients for a sum of cosine and sine functions: a cos(ot) + b i +## sin(ot). The specific frequency can be determined by its index in @var{t}, +## @var{ind}, as @var{maxfreq} * 2 ^ (- (@var{ind} - 1) / @var{numcoeff}). +## +## @seealso{lsreal} +## @end deftypefn + + +function transform = lscomplex (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); Copied: trunk/octave-forge/extra/lssa/inst/lscomplex.m.old (from rev 10856, trunk/octave-forge/extra/lssa/inst/lscomplex.m) =================================================================== --- trunk/octave-forge/extra/lssa/inst/lscomplex.m.old (rev 0) +++ trunk/octave-forge/extra/lssa/inst/lscomplex.m.old 2012-08-14 13:42:51 UTC (rev 10860) @@ -0,0 +1,68 @@ +## 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 = 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); Modified: trunk/octave-forge/extra/lssa/inst/lscorrcoeff.m =================================================================== --- trunk/octave-forge/extra/lssa/inst/lscorrcoeff.m 2012-08-13 02:06:19 UTC (rev 10859) +++ trunk/octave-forge/extra/lssa/inst/lscorrcoeff.m 2012-08-14 13:42:51 UTC (rev 10860) @@ -15,24 +15,22 @@ ## -*- texinfo -*- ## @deftypefn {Function File} {@var{c} =} lscorrcoeff (@var{time1}, @var{mag1}, @var{time2}, @var{mag2}, @var{time}, @var{freq}) -## @deftypefnx {Function File} {@var{c} =} lscorrcoeff (@var{time1}, @var{mag1}, -## @var{time2}, @var{mag2}, @var{time}, @var{freq}, @var{window} = @var{cubicwgt}) -## @deftypefnx {Function File} {@var{c} =} lscorrcoeff (@var{time1}, @var{mag1}, -## @var{time2}, @var{mag2}, @var{time}, @var{freq}, @var{window} = -## @var{cubicwgt}, @var{winradius} = 1) +## @deftypefnx {Function File} {@var{c} =} lscorrcoeff (@var{time1}, @var{mag1}, @var{time2}, @var{mag2}, @var{time}, @var{freq}, @var{window} = @var{cubicwgt}) +## @deftypefnx {Function File} {@var{c} =} lscorrcoeff (@var{time1}, @var{mag1}, @var{time2}, @var{mag2}, @var{time}, @var{freq}, @var{window} = @var{cubicwgt}, @var{winradius} = 1) ## -## Return the coefficient of the wavelet correlation of time -## series (@var{time1}, @var{mag1}) and (@var{time2}, @var{mag2}). -## @var{window} is used to apply a windowing function, its -## default is cubicwgt if left blank, and its radius is 1, -## as defined as the default for @var{winradius}. +## Return the coefficient of the wavelet correlation of two complex-valued time +## series at a given time and frequency. The windowing function applied by +## default is cubicwgt, this can be changed by passing a different function +## handle to @var{window}, while the radius applied is set by @var{winradius}. +## Note that this will be most effective when both series have had their mean +## value (if it is not zero) subtracted (and stored separately); this reduces +## the constant-offset error further, and allows the functions to be compared on +## their periodic features rather than their constant features. ## ## @seealso{lswaveletcoeff, lscomplexwavelet, lsrealwavelet} ## ## @end deftypefn -## nucorrcoeff, computes a coefficient of the wavelet correlation of two time series - function coeff = lscorrcoeff (x1, y1, x2, y2, t, o, wgt = @cubicwgt, wgtrad = 1) so = 0.05 * o; Deleted: trunk/octave-forge/extra/lssa/inst/lsreal.m =================================================================== --- trunk/octave-forge/extra/lssa/inst/lsreal.m 2012-08-13 02:06:19 UTC (rev 10859) +++ trunk/octave-forge/extra/lssa/inst/lsreal.m 2012-08-14 13:42:51 UTC (rev 10860) @@ -1,79 +0,0 @@ -## 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 <http://www.gnu.org/licenses/>. - -## -*- texinfo -*- -## @deftypefn {Function File} {@var{transform} =} lsreal (@var{time}, @var{mag}, @var{maxfreq}, @var{numcoeff}, @var{numoctaves}) -## -## Return the real least-squares transform of the time series -## defined, based on the maximal frequency @var{maxfreq}, the -## number of coefficients @var{numcoeff}, and the number of -## octaves @var{numoctaves}. Each complex-valued result is the -## pair (c_o, s_o) defining the coefficients which best fit the -## function y = c_o * cos(ot) + s_o * sin(ot) to the (@var{time}, @var{mag}) data. -## -## @seealso{lscomplex} -## @end deftypefn - -function transform = lsreal (t, x, omegamax, ncoeff, noctave) - - ## FIXME : THIS IS VECTOR-ONLY. I'd need to add another bit of code to - ## make it array-safe, and that's not knowing right now what else - ## will be necessary. - k = n = length (t); - - transform = zeros (1, (noctave * ncoeff)); - - od = 2 ^ (- 1 / ncoeff); - o = omegamax; - n1 = 1 / n; - - ncoeffp = ncoeff * noctave; - - for iter = 1:ncoeffp - ## This method is an application of Eq. 8 on - ## page 6 of the text, as well as Eq. 7 - ot = o .* t; - - zeta = n1 * sum ((cos (ot) - i * sin (ot)) .* x); - - ot *= 2; - - iota = n1 * sum (cos (ot) - i * sin (ot)); - - - transform(iter) = (2 * (conj (zeta) - (conj (iota) * zeta)) / - (1 - (real (iota) ^ 2) - (imag (iota) ^ 2))); - - o *= od; - endfor - -endfunction - -%!test -%! 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 ) ); -%! # In the assert here, I've got an error bound large enough to catch -%! # individual system errors which would present no real issue. -%! assert (lsreal (t,x,maxfreq,2,2), -%! [(-1.68275915310663 + 4.70126183846743i), ... -%! (1.93821553170889 + 4.95660209883437i), ... -%! (4.38145452686697 + 2.14403733658600i), ... -%! (5.27425332281147 - 0.73933440226597i)], -%! 5e-10) Added: trunk/octave-forge/extra/lssa/inst/lsreal.m =================================================================== --- trunk/octave-forge/extra/lssa/inst/lsreal.m (rev 0) +++ trunk/octave-forge/extra/lssa/inst/lsreal.m 2012-08-14 13:42:51 UTC (rev 10860) @@ -0,0 +1,73 @@ +## 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} =} lsreal (@var{time}, @var{mag}, @var{maxfreq}, @var{numcoeff}, @var{numoctaves}) +## +## Return a series of least-squares transforms of a real-valued time series. +## Each transform is minimized independently for each frequency. The method +## used is a Lomb-Scargle transform of the real-valued (@var{time}, @var{mag}) +## series, starting from frequency @var{maxfreq} and descending @var{numoctaves} +## octaves with @var{numcoeff} coefficients per octave. +## +## The result of the transform for each frequency is the coefficient of a sum of +## sine and cosine functions modified by that frequency, in the form of a +## complex number—where the cosine coefficient is encoded in the real term, and +## the sine coefficient is encoded in the imaginary term. Each frequency is fit +## independently from the others, and to minimize very low frequency error, +## consider storing the mean of a dataset with a constant or near-constant +## offset separately, and subtracting it from the dataset. +## +## @seealso{lscomplex} +## @end deftypefn + + + +function transform = lsreal (t, x, omegamax, ncoeff, noctave) + + n = numel (t); + + iter = 0 : (ncoeff * noctave - 1); + omul = (2 .^ (- iter / ncoeff)); + + ## For a given frequency, the iota term is taken at twice the frequency of the + ## zeta term. + ot = t(:) * (omul * omegamax); + oit = t(:) * (omul * omegamax * 2); + + zeta = sum ((cos (ot) - (sin (ot) .* i)) .* x(:), 1) / n; + iota = sum ((cos (oit) - (sin (oit) .* i)), 1) / n; + + transform = 2 .* (conj (zeta) - conj (iota) .* zeta) ./ (1 - abs (iota) .^ 2); + +endfunction + +%!test +%! 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 ) ); +%! # In the assert here, I've got an error bound large enough to catch +%! # individual system errors which would present no real issue. +%! assert (lsreal (t,x,maxfreq,2,2), +%! [(-1.68275915310663 + 4.70126183846743i), ... +%! (1.93821553170889 + 4.95660209883437i), ... +%! (4.38145452686697 + 2.14403733658600i), ... +%! (5.27425332281147 - 0.73933440226597i)], +%! 5e-10) + Copied: trunk/octave-forge/extra/lssa/inst/lsreal.m.old (from rev 10856, trunk/octave-forge/extra/lssa/inst/lsreal.m) =================================================================== --- trunk/octave-forge/extra/lssa/inst/lsreal.m.old (rev 0) +++ trunk/octave-forge/extra/lssa/inst/lsreal.m.old 2012-08-14 13:42:51 UTC (rev 10860) @@ -0,0 +1,79 @@ +## 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 <http://www.gnu.org/licenses/>. + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{transform} =} lsreal (@var{time}, @var{mag}, @var{maxfreq}, @var{numcoeff}, @var{numoctaves}) +## +## Return the real least-squares transform of the time series +## defined, based on the maximal frequency @var{maxfreq}, the +## number of coefficients @var{numcoeff}, and the number of +## octaves @var{numoctaves}. Each complex-valued result is the +## pair (c_o, s_o) defining the coefficients which best fit the +## function y = c_o * cos(ot) + s_o * sin(ot) to the (@var{time}, @var{mag}) data. +## +## @seealso{lscomplex} +## @end deftypefn + +function transform = lsreal (t, x, omegamax, ncoeff, noctave) + + ## FIXME : THIS IS VECTOR-ONLY. I'd need to add another bit of code to + ## make it array-safe, and that's not knowing right now what else + ## will be necessary. + k = n = length (t); + + transform = zeros (1, (noctave * ncoeff)); + + od = 2 ^ (- 1 / ncoeff); + o = omegamax; + n1 = 1 / n; + + ncoeffp = ncoeff * noctave; + + for iter = 1:ncoeffp + ## This method is an application of Eq. 8 on + ## page 6 of the text, as well as Eq. 7 + ot = o .* t; + + zeta = n1 * sum ((cos (ot) - i * sin (ot)) .* x); + + ot *= 2; + + iota = n1 * sum (cos (ot) - i * sin (ot)); + + + transform(iter) = (2 * (conj (zeta) - (conj (iota) * zeta)) / + (1 - (real (iota) ^ 2) - (imag (iota) ^ 2))); + + o *= od; + endfor + +endfunction + +%!test +%! 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 ) ); +%! # In the assert here, I've got an error bound large enough to catch +%! # individual system errors which would present no real issue. +%! assert (lsreal (t,x,maxfreq,2,2), +%! [(-1.68275915310663 + 4.70126183846743i), ... +%! (1.93821553170889 + 4.95660209883437i), ... +%! (4.38145452686697 + 2.14403733658600i), ... +%! (5.27425332281147 - 0.73933440226597i)], +%! 5e-10) Modified: trunk/octave-forge/extra/lssa/inst/lswaveletcoeff.m =================================================================== --- trunk/octave-forge/extra/lssa/inst/lswaveletcoeff.m 2012-08-13 02:06:19 UTC (rev 10859) +++ trunk/octave-forge/extra/lssa/inst/lswaveletcoeff.m 2012-08-14 13:42:51 UTC (rev 10860) @@ -18,13 +18,17 @@ ## @deftypefnx {Function File} {@var{c} =} lswaveletcoeff (@var{t}, @var{x}, @var{time}, @var{freq}, @var{window}=cubicwgt) ## @deftypefnx {Function File} {@var{c} =} lswaveletcoeff (@var{t}, @var{x}, @var{time}, @var{freq}, @var{window}=cubicwgt, @var{winradius}=1) ## -## Return the coefficient of the wavelet transform of the -## complex time series (@var{t}, @var{x}) at time @var{time} -## and frequency @var{freq}; optional variable @var{window} -## provides a windowing function and defaults to cubicwgt, -## while @var{winradius} is the windowing radius, and defaults -## to 1 (the radius of cubicwgt.) +## Return the wavelet transform of a complex time series in a given window. The +## transform takes a complex time series (@var{t}, @var{x}) at time @var{time} +## and frequency @var{freq}, then applies a windowing function to it; the +## default is cubicwgt, however by providing a function handle for the optional +## variable @var{window}, the user may select their own function; to determine +## the radius of the interval around the @var{time} selected, set +## @var{winradius} to some value other than 1. ## +## This transform operates identically to the transform at the heart of +## lscomplexwavelet, however for one window only. +## ## @seealso{lscorrcoeff, lscomplexwavelet, lsrealwavelet} ## ## @end deftypefn This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ean...@us...> - 2012-08-13 02:06:26
|
Revision: 10859 http://octave.svn.sourceforge.net/octave/?rev=10859&view=rev Author: eandrius Date: 2012-08-13 02:06:19 +0000 (Mon, 13 Aug 2012) Log Message: ----------- serial: implemented srl_timeout Modified Paths: -------------- trunk/octave-forge/main/serial/INDEX trunk/octave-forge/main/serial/NEWS trunk/octave-forge/main/serial/src/Makefile trunk/octave-forge/main/serial/src/serial.cc trunk/octave-forge/main/serial/src/serial.h trunk/octave-forge/main/serial/src/srl_flush.cc trunk/octave-forge/main/serial/src/srl_read.cc Added Paths: ----------- trunk/octave-forge/main/serial/src/srl_timeout.cc Modified: trunk/octave-forge/main/serial/INDEX =================================================================== --- trunk/octave-forge/main/serial/INDEX 2012-08-13 00:54:33 UTC (rev 10858) +++ trunk/octave-forge/main/serial/INDEX 2012-08-13 02:06:19 UTC (rev 10859) @@ -8,4 +8,5 @@ srl_parity srl_stopbits srl_close - srl_read \ No newline at end of file + srl_read + srl_timeout Modified: trunk/octave-forge/main/serial/NEWS =================================================================== --- trunk/octave-forge/main/serial/NEWS 2012-08-13 00:54:33 UTC (rev 10858) +++ trunk/octave-forge/main/serial/NEWS 2012-08-13 02:06:19 UTC (rev 10859) @@ -13,3 +13,4 @@ srl_stopbits srl_close srl_read + srl_timeout Modified: trunk/octave-forge/main/serial/src/Makefile =================================================================== --- trunk/octave-forge/main/serial/src/Makefile 2012-08-13 00:54:33 UTC (rev 10858) +++ trunk/octave-forge/main/serial/src/Makefile 2012-08-13 02:06:19 UTC (rev 10859) @@ -1,5 +1,6 @@ OCT = serial.oct -OBJ := serial.o srl_baudrate.o srl_bytesize.o srl_flush.o srl_parity.o srl_stopbits.o srl_write.o srl_close.o srl_read.o +OBJ := serial.o srl_baudrate.o srl_timeout.o srl_bytesize.o srl_flush.o \ + srl_parity.o srl_stopbits.o srl_write.o srl_close.o srl_read.o MKOCTFILE ?= mkoctfile @@ -14,4 +15,5 @@ clean: rm -f *.oct *.o + .PHONY: all clean Modified: trunk/octave-forge/main/serial/src/serial.cc =================================================================== --- trunk/octave-forge/main/serial/src/serial.cc 2012-08-13 00:54:33 UTC (rev 10858) +++ trunk/octave-forge/main/serial/src/serial.cc 2012-08-13 02:06:19 UTC (rev 10859) @@ -13,9 +13,11 @@ // You should have received a copy of the GNU General Public License // along with this program; if not, see <http://www.gnu.org/licenses/>. -// TODO: Include more detailed error messages +// TODO: Include more detailed error messages (perror?) // TODO: Implement Flow Control +// TODO: Implement H/W handshaking // TODO: Implement read timeout +// TODO: Check if interface is opened first #include <octave/oct.h> #include <octave/ov-int32.h> @@ -53,6 +55,7 @@ { this->fd = open(path.c_str(), flags, 0); tcgetattr(this->fd, &this->config); + this->blocking_read = true; } octave_serial::~octave_serial() @@ -67,8 +70,8 @@ void octave_serial::print (std::ostream& os, bool pr_as_read_syntax ) const { - print_raw (os, pr_as_read_syntax); - newline (os); + print_raw(os, pr_as_read_syntax); + newline(os); } void octave_serial::print_raw (std::ostream& os, bool pr_as_read_syntax) const @@ -97,6 +100,8 @@ // Default values string path("/dev/ttyUSB0"); unsigned int baud_rate = 115200; + short timeout = -1; + unsigned short bytesize = 8; string parity("N"); unsigned short stopbits = 1; @@ -143,11 +148,11 @@ { if (args(2).is_integer_type() || args(2).is_float_type()) { - oflags = args(2).int_value(); + timeout = args(2).int_value(); } else { - error("serial: 3rd argument must be an interface flags of type integer..."); + error("serial: 3rd argument must be an timeout of type integer..."); return octave_value(); } } @@ -162,9 +167,14 @@ } retval->srl_baudrate(baud_rate); + + if (timeout >= 0) { + retval->srl_timeout(timeout); + } + retval->srl_parity(parity); retval->srl_bytesize(bytesize); retval->srl_stopbits(stopbits); - + return octave_value(retval); } Modified: trunk/octave-forge/main/serial/src/serial.h =================================================================== --- trunk/octave-forge/main/serial/src/serial.h 2012-08-13 00:54:33 UTC (rev 10858) +++ trunk/octave-forge/main/serial/src/serial.h 2012-08-13 02:06:19 UTC (rev 10859) @@ -49,6 +49,7 @@ int srl_flush(unsigned short); + int srl_timeout(short); int srl_baudrate(unsigned int); int srl_bytesize(unsigned short); int srl_parity(string); @@ -77,6 +78,8 @@ private: int fd; struct termios config; + + bool blocking_read; DECLARE_OCTAVE_ALLOCATOR DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA Modified: trunk/octave-forge/main/serial/src/srl_flush.cc =================================================================== --- trunk/octave-forge/main/serial/src/srl_flush.cc 2012-08-13 00:54:33 UTC (rev 10858) +++ trunk/octave-forge/main/serial/src/srl_flush.cc 2012-08-13 02:06:19 UTC (rev 10859) @@ -38,19 +38,19 @@ // PKG_ADD: autoload ("srl_flush", "serial.oct"); int octave_serial::srl_flush(unsigned short queue_selector) { + /* + * TCIOFLUSH Flush both pending input and untransmitted output. + * TCOFLUSH Flush untransmitted output. + * TCIFLUSH Flush pending input. + */ - // TCIFLUSH Flush pending input. - // TCIOFLUSH Flush both pending input and untransmitted output. - // TCOFLUSH Flush untransmitted output. - - int flag; switch (queue_selector) { - case 0: flag = TCIFLUSH; break; - case 1: flag = TCIOFLUSH; break; - case 2: flag = TCOFLUSH; break; + case 0: flag = TCOFLUSH; break; + case 1: flag = TCIFLUSH; break; + case 2: flag = TCIOFLUSH; break; default: error("srl_flush: only [0..2] values are accepted..."); return false; @@ -62,7 +62,7 @@ // PKG_ADD: autoload ("srl_flush", "serial.oct"); DEFUN_DLD (srl_flush, args, nargout, "Hello World Help String") { - int queue_selector = 1; + int queue_selector = 2; // Input and Output if (args.length() < 1 || args.length() > 2) { Modified: trunk/octave-forge/main/serial/src/srl_read.cc =================================================================== --- trunk/octave-forge/main/serial/src/srl_read.cc 2012-08-13 00:54:33 UTC (rev 10858) +++ trunk/octave-forge/main/serial/src/srl_read.cc 2012-08-13 02:06:19 UTC (rev 10859) @@ -78,26 +78,26 @@ const octave_base_value& rep = args(0).get_rep(); serial = &((octave_serial &)rep); - int retval = 0; + int buffer_read = 0, read_retval = -1; - while (retval < buffer_len) + // While buffer not full and not timeout + while (buffer_read < buffer_len && read_retval != 0) { - retval += serial->srl_read(buffer + retval, buffer_len - retval); + read_retval = serial->srl_read(buffer + buffer_read, buffer_len - buffer_read); + buffer_read += read_retval; } - - //buffer[retval] = '\0'; - + octave_value_list return_list; uint8NDArray data; - data.resize(retval); + data.resize(buffer_read); // TODO: clean this up - for (int i = 0; i < retval; i++) + for (int i = 0; i < buffer_read; i++) { data(i) = buffer[i]; } - return_list(1) = retval; + return_list(1) = buffer_read; return_list(0) = data; delete[] buffer; Added: trunk/octave-forge/main/serial/src/srl_timeout.cc =================================================================== --- trunk/octave-forge/main/serial/src/srl_timeout.cc (rev 0) +++ trunk/octave-forge/main/serial/src/srl_timeout.cc 2012-08-13 02:06:19 UTC (rev 10859) @@ -0,0 +1,110 @@ +// Copyright (C) 2012 Andrius Sutas <and...@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/>. + +#include <octave/oct.h> +#include <octave/ov-int32.h> +//#include <octave/ops.h> +//#include <octave/ov-typeinfo.h> + +#include <iostream> +#include <string> +#include <algorithm> + +#ifndef __WIN32__ +#include <stdio.h> +#include <string.h> +#include <fcntl.h> +#include <errno.h> +#include <termios.h> +#include <unistd.h> +#endif + +using std::string; + +#include "serial.h" + +// PKG_ADD: autoload ("srl_timeout", "serial.oct"); +DEFUN_DLD (srl_timeout, args, nargout, "Hello World Help String") +{ + if (args.length() < 1 || args.length() > 2) + { + error("srl_timeout: expecting one or two arguments..."); + return octave_value(-1); + } + + if (args(0).type_id() != octave_serial::static_type_id()) + { + error("srl_timeout: expecting first argument of type octave_serial..."); + return octave_value(-1); + } + + // Setting new timeout + if (args.length() > 1) + { + if ( !(args(1).is_integer_type() || args(1).is_float_type()) ) + { + error("srl_timeout: expecting second argument of type integer..."); + return octave_value(-1); + } + + octave_serial* serial = NULL; + + const octave_base_value& rep = args(0).get_rep(); + serial = &((octave_serial &)rep); + + serial->srl_timeout(args(1).int_value()); + + return octave_value(); + } + + // Returning current timeout + + // TODO: return current timeout + + return octave_value(0); +} + +int octave_serial::srl_timeout(short timeout) +{ + if (timeout < 0 || timeout > 255) + { + error("srl_timeout: timeout value must be between [0..255]..."); + return false; + } + + /* + // Disable timeout, enable blocking read + if (timeout < 0) + { + this->blocking_read = true; + BITMASK_SET(this->config.c_lflag, ICANON); // Set canonical mode + this->config.c_cc[VMIN] = 1; + this->config.c_cc[VTIME] = 0; + } + */ + + // Enable timeout, disable blocking read + this->blocking_read = false; + BITMASK_CLEAR(this->config.c_lflag, ICANON); // Set non-canonical mode + this->config.c_cc[VMIN] = 0; + this->config.c_cc[VTIME] = (unsigned) timeout; // Set timeout of 'timeout * 10' seconds + + if (tcsetattr(this->srl_get_fd(), TCSANOW, &this->config) < 0) { + error("srl_timeout: error setting stop bits..."); + return false; + } + + return true; +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <car...@us...> - 2012-08-13 00:54:41
|
Revision: 10858 http://octave.svn.sourceforge.net/octave/?rev=10858&view=rev Author: carandraug Date: 2012-08-13 00:54:33 +0000 (Mon, 13 Aug 2012) Log Message: ----------- fpl: fix date format Modified Paths: -------------- trunk/octave-forge/extra/fpl/DESCRIPTION Modified: trunk/octave-forge/extra/fpl/DESCRIPTION =================================================================== --- trunk/octave-forge/extra/fpl/DESCRIPTION 2012-08-11 17:25:08 UTC (rev 10857) +++ trunk/octave-forge/extra/fpl/DESCRIPTION 2012-08-13 00:54:33 UTC (rev 10858) @@ -1,6 +1,6 @@ Name: fpl Version: 1.3.1 -Date: 2012-10-08 +Date: 2012-08-10 Author: Carlo de Falco, Massimiliano Culpo and others Maintainer: Carlo de Falco, Massimiliano Culpo Title: Fem PLotting This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cd...@us...> - 2012-08-11 17:25:14
|
Revision: 10857 http://octave.svn.sourceforge.net/octave/?rev=10857&view=rev Author: cdf Date: 2012-08-11 17:25:08 +0000 (Sat, 11 Aug 2012) Log Message: ----------- fix incorrect call to fallback function Modified Paths: -------------- trunk/octave-forge/extra/fpl/inst/fpl_vtk_b64_write_field.m Modified: trunk/octave-forge/extra/fpl/inst/fpl_vtk_b64_write_field.m =================================================================== --- trunk/octave-forge/extra/fpl/inst/fpl_vtk_b64_write_field.m 2012-08-10 15:46:14 UTC (rev 10856) +++ trunk/octave-forge/extra/fpl/inst/fpl_vtk_b64_write_field.m 2012-08-11 17:25:08 UTC (rev 10857) @@ -59,7 +59,7 @@ ## ## @end deftypefn -function fpl_vtk_b64_write_field (basename, mesh, nodedata, celldata, endfile) +function fpl_vtk_b64_write_field (basename, mesh, nodedata, celldata) ## Check input if (nargin != 4) @@ -76,7 +76,7 @@ if (! exist ("base64_encode", "builtin")) warning ("fpl_vtk_b64_write_field: Octave >= 3.7 is required to save in binary format, your data will be saved as ascii"); - fpl_vtk_write_field (basename, mesh, nodedata, celldata, endfile, true); + fpl_vtk_write_field (basename, mesh, nodedata, celldata, true); return; endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cd...@us...> - 2012-08-10 15:46:20
|
Revision: 10856 http://octave.svn.sourceforge.net/octave/?rev=10856&view=rev Author: cdf Date: 2012-08-10 15:46:14 +0000 (Fri, 10 Aug 2012) Log Message: ----------- faster access to vector data Modified Paths: -------------- trunk/octave-forge/extra/lssa/src/fastlscomplex.cc Modified: trunk/octave-forge/extra/lssa/src/fastlscomplex.cc =================================================================== --- trunk/octave-forge/extra/lssa/src/fastlscomplex.cc 2012-08-10 15:10:54 UTC (rev 10855) +++ trunk/octave-forge/extra/lssa/src/fastlscomplex.cc 2012-08-10 15:46:14 UTC (rev 10856) @@ -25,7 +25,7 @@ #include <exception> bool flscomplex (const RowVector & tvec, const ComplexRowVector & xvec, - double maxfreq, int octaves, int coefficients, ComplexRowVector & result) + double maxfreq, int octaves, int coefficients, ComplexRowVector & result); DEFUN_DLD(fastlscomplex,args,nargout, "-*- texinfo -*-\n\ @@ -72,7 +72,7 @@ if (flscomplex (tvals, xvals, omegamax, noctaves, ncoeff, results)) retval(0) = octave_value (results); else - error ("fastlscomplex: error in the underlying flscomplex function") + error ("fastlscomplex: error in the underlying flscomplex function"); } } @@ -84,6 +84,7 @@ double maxfreq, int octaves, int coefficients, ComplexRowVector & results) { + struct Precomputation_Record { Precomputation_Record *next; @@ -91,13 +92,17 @@ bool stored_data; }; + const std::complex<double> *xvec_ptr = xvec.data (); + const double *tvec_ptr = tvec.data (); + results.resize (coefficients * octaves); + const std::complex<double> *results_ptr = results.fortran_vec (); double tau, delta_tau, tau_0, tau_h, n_inv, mu, te, omega_oct, omega_multiplier, octavemax, omega_working, loop_tau_0, loop_delta_tau, on_1, n_1, o; - double length = tvec(tvec.numel () - 1) - tvec(0); + double length = tvec_ptr[tvec.numel () - 1] - tvec_ptr[0]; int octave_iter, coeff_iter; @@ -123,7 +128,7 @@ */ delta_tau = M_PI / (2 * maxfreq); - tau_0 = tvec(0) + delta_tau; + tau_0 = tvec_ptr[0] + delta_tau; tau_h = tau_0; te = tau_h + delta_tau; @@ -132,32 +137,32 @@ Precomputation_Record * precomp_records_head, *record_current, *record_tail, *record_ref, *record_next; record_current = precomp_records_head = new Precomputation_Record; - for (te = tvec(k) + (2 * delta_tau) ; ;) + for (te = tvec_ptr[k] + (2 * delta_tau) ; ;) { - x = std::complex<double>(xvec(k)); + x = xvec_ptr[k]; { - double t = mu*(tvec(k)-tau_h), tt; + double t = mu *(tvec_ptr[k] - tau_h), tt; p = record_current->power_series; // p = 0 - *p++ = std::complex<double>(x); + *p++ = x; // p = 1 tt = -t; h = x * tt; - *p++ = std::complex<double>(-h.imag(),h.real()); + *p++ = std::complex<double> (-h.imag (), h.real ()); // p = 2 tt *= t*(1.0/2.0); *p++ = x*tt; // p = 3 tt *= t*(-1.0/3.0); h = x * tt; - *p++ = std::complex<double>(-h.imag(),h.real()); + *p++ = std::complex<double> (-h.imag (), h.real ()); // p = 4 tt *= t*(1.0/4.0); *p++ = x*tt; // p = 5 tt *= t*(-1.0/5.0); h = x * tt; - *p++ = std::complex<double>(-h.imag(),h.real()); + *p++ = std::complex<double>(-h.imag () ,h.real ()); // p = 6 tt *= t*(1.0/6.0); *p++ = x*tt; @@ -182,11 +187,11 @@ } record_current->stored_data = true; - for(k++; k < n && tvec(k) < te; k++) + for(k++; k < n && tvec_ptr[k] < te; k++) { - x = std::complex<double> (xvec(k)); + x = std::complex<double> (xvec_ptr[k]); { - double t = mu*(tvec(k)-tau_h), tt; + double t = mu * (tvec_ptr[k] - tau_h), tt; p = record_current->power_series; // p = 0 *p++ += std::complex<double>(x); @@ -267,9 +272,10 @@ omega_working = octavemax; for (coeff_iter = 0; coeff_iter < coefficients; - coeff_iter++, o *= omega_multiplier, omega_working *= omega_multiplier) + coeff_iter++, o *= omega_multiplier, + omega_working *= omega_multiplier) { - exp_term = std::complex<double> (cos (- omega_working * loop_tau_0) , + exp_term = std::complex<double> (cos (- omega_working * loop_tau_0), sin (- omega_working * loop_tau_0)); exp_multiplier = std::complex<double> (cos (- 2 * omega_working * loop_delta_tau) , @@ -471,14 +477,28 @@ } } } - catch (std::exception& e) + catch (std::exception & e) {//This section was part of my debugging, and may be removed. std::cout << "Exception thrown: " << e.what() << std::endl; - ComplexRowVector exception_result (1); - exception_result(0) = false; - return exception_result; + return (false); } } return true; } + +/* +%!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. |
From: <cd...@us...> - 2012-08-10 15:11:02
|
Revision: 10855 http://octave.svn.sourceforge.net/octave/?rev=10855&view=rev Author: cdf Date: 2012-08-10 15:10:54 +0000 (Fri, 10 Aug 2012) Log Message: ----------- more code revision Modified Paths: -------------- trunk/octave-forge/extra/lssa/inst/lswaveletcoeff.m trunk/octave-forge/extra/lssa/src/fastlscomplex.cc Modified: trunk/octave-forge/extra/lssa/inst/lswaveletcoeff.m =================================================================== --- trunk/octave-forge/extra/lssa/inst/lswaveletcoeff.m 2012-08-10 13:17:33 UTC (rev 10854) +++ trunk/octave-forge/extra/lssa/inst/lswaveletcoeff.m 2012-08-10 15:10:54 UTC (rev 10855) @@ -29,33 +29,31 @@ ## ## @end deftypefn -%!demo -%! x = 1:10; -%! y = sin(x); -%! xt = x'; -%! yt = y'; -%! a = lswaveletcoeff(x,y,0.5,0.9) -%! b = lswaveletcoeff(xt,yt,0.5,0.9) -%! ## Generates the wavelet transform coefficient for time 0.5 and circ. freq. 0.9, for row & column vectors. +function coeff = lswaveletcoeff (x, y, t, o, wgt = @cubicwgt, wgtrad = 1) -function coeff = lswaveletcoeff( x , y , t , o , wgt = @cubicwgt , wgtrad = 1 ) so = 0.05 .* o; - if ( ( ndims(x) == 2 ) && ! ( rows(x) == 1 ) ) - x = reshape(x,1,length(x)); - y = reshape(y,1,length(y)); + + if ((ndims (x) == 2) && ! (rows (x) == 1)) + x = reshape (x, 1, length (x)); + y = reshape (y, 1, length (y)); endif - mask = find( abs( x - t ) * so < wgtrad ); + + mask = (abs (x - t) * so < wgtrad); rx = x(mask); ry = y(mask); + ## Going by the R code, this can use the same mask. - s = sum( wgt( ( x - t ) .* so ) ); - coeff = ifelse( s != 0 , sum( wgt( ( rx - t ) .* so) .* exp( i .* o .* ( rx - t ) ) .* ry ) ./ s , 0 ); + s = sum (wgt ((x - t) .* so)); + coeff = ifelse (s != 0, + sum (wgt ((rx - t) .* so) .* + exp (i .* o .* (rx - t)) .* ry) ./ s, + 0); endfunction -%!test -%!shared t, p, x, y, z, o, maxfreq + +%!shared t, p, x, y, maxfreq %! maxfreq = 4 / (2 * pi); %! t = linspace (0, 8); %! x = (2 .* sin (maxfreq .* t) + @@ -65,13 +63,18 @@ %! cos ((1/4) * maxfreq .* t)); %! y = - x; %! p = linspace (0, 8, 500); -%! z = (2 .* sin (maxfreq .* p) + -%! 3 .* sin ((3/4) * maxfreq .* p) - -%! 0.5 .* sin ((1/4) * maxfreq .* p) - -%! 0.2 .* cos (maxfreq .* p) + -%! cos ((1/4) * maxfreq .* p)); -%! o = [maxfreq , (3/4 * maxfreq) , (1/4 * maxfreq)]; -%!assert (lswaveletcoeff (t, x, 0.5, maxfreq), 0.383340407638780 + -%! 2.385251997545446i , 5e-10); -%!assert (lswaveletcoeff (t, y, 3.3, 3/4 * maxfreq), -2.35465091096084 + -%! 1.01892561714824i, 5e-10); +%!assert (lswaveletcoeff (t, x, 0.5, maxfreq), +%! 0.383340407638780 + 2.385251997545446i, 5e-10); +%!assert (lswaveletcoeff (t, y, 3.3, 3/4 * maxfreq), +%! -2.35465091096084 + 1.01892561714824i, 5e-10); + + +%!demo +%! ## Generates the wavelet transform coefficient for time 0.5 and circ. freq. 0.9, for row & column vectors. +%! x = 1:10; +%! y = sin (x); +%! xt = x'; +%! yt = y'; +%! a = lswaveletcoeff (x, y, 0.5, 0.9) +%! b = lswaveletcoeff (xt, yt, 0.5, 0.9) + Modified: trunk/octave-forge/extra/lssa/src/fastlscomplex.cc =================================================================== --- trunk/octave-forge/extra/lssa/src/fastlscomplex.cc 2012-08-10 13:17:33 UTC (rev 10854) +++ trunk/octave-forge/extra/lssa/src/fastlscomplex.cc 2012-08-10 15:10:54 UTC (rev 10855) @@ -24,195 +24,225 @@ #include <iostream> #include <exception> +bool flscomplex (const RowVector & tvec, const ComplexRowVector & xvec, + double maxfreq, int octaves, int coefficients, ComplexRowVector & result) +DEFUN_DLD(fastlscomplex,args,nargout, +"-*- texinfo -*-\n\ +@deftypefn {Function File} { C = } fastlscomplex \ +(@var{time},@var{magnitude},@var{maximum_frequency},@var{octaves},@var{coefficients})\n \ +\n\ +Return the complex least squares transform of the (@var{time},@var{magnitude}) series\n\ +supplied, using the fast algorithm.\n\ +\n\ +@seealso{lscomplex, fastlsreal}\n\ +\n\ +@end deftypefn") +{ -ComplexRowVector flscomplex( RowVector tvec , ComplexRowVector xvec , - double maxfreq , int octaves , int coefficients); + octave_value_list retval; + if (args.length() != 5) + print_usage(); + else + { -DEFUN_DLD(fastlscomplex,args,nargout, - "-*- texinfo -*-\n" -"@deftypefn {Function File} { C = } fastlscomplex" - "(@var{time},@var{magnitude},@var{maximum_frequency},@var{octaves},@var{coefficients})\n" -"\n" -"Return the complex least squares transform of the (@var{time},@var{magnitude}) series\n\ -supplied, using the fast algorithm.\n" -"\n" -"@seealso{lscomplex, fastlsreal}\n" -"\n" -"@end deftypefn") { - if ( args.length() != 5 ) { - print_usage(); - return octave_value_list (); - } - RowVector tvals = args(0).row_vector_value(); - ComplexRowVector xvals = args(1).complex_row_vector_value(); - double omegamax = args(2).double_value(); - int noctaves = args(3).int_value(); - int ncoeff = args(4).int_value(); - if ( tvals.numel() != xvals.numel() ){ - if ( tvals.numel() > xvals.numel() ) { - error("More time values than magnitude values."); - } else { - error("More magnitude values than time values."); + RowVector tvals = args(0).row_vector_value (); + ComplexRowVector xvals = args(1).complex_row_vector_value (); + double omegamax = args(2).double_value (); + int noctaves = args(3).int_value (); + int ncoeff = args(4).int_value (); + + if (tvals.numel () != xvals.numel ()) + if (tvals.numel () > xvals.numel ()) + error ("fastlscomplex: More time values than magnitude values"); + else + error ("fastlscomplex: More magnitude values than time values"); + + if (ncoeff == 0) + error ("fastlscomplex: No coefficients to compute"); + if (noctaves == 0) + error ("fastlscomplex: No octaves to compute over"); + if (omegamax == 0) + error ("fastlscomplex: No difference between minimal and maximal frequency"); + + if (! error_state) + { + ComplexRowVector results; + if (flscomplex (tvals, xvals, omegamax, noctaves, ncoeff, results)) + retval(0) = octave_value (results); + else + error ("fastlscomplex: error in the underlying flscomplex function") + } + } - } - if ( ncoeff == 0 ) error("No coefficients to compute."); - if ( noctaves == 0 ) error("No octaves to compute over."); - if ( omegamax == 0 ) error("No difference between minimal and maximal frequency."); - octave_value_list retval; - if ( !error_state) { - ComplexRowVector results = flscomplex(tvals,xvals,omegamax,noctaves,ncoeff); - retval(0) = octave_value(results); - } else { - return octave_value_list (); - } + return retval; - } -ComplexRowVector flscomplex( RowVector tvec , ComplexRowVector xvec , - double maxfreq, int octaves, int coefficients ) { - struct Precomputation_Record { +bool flscomplex (const RowVector & tvec, const ComplexRowVector & xvec, + double maxfreq, int octaves, int coefficients, + ComplexRowVector & results) +{ + struct Precomputation_Record + { Precomputation_Record *next; std::complex<double> power_series[12]; // I'm using 12 as a matter of compatibility, only. bool stored_data; }; - ComplexRowVector results = ComplexRowVector (coefficients * octaves ); + results.resize (coefficients * octaves); double tau, delta_tau, tau_0, tau_h, n_inv, mu, te, omega_oct, omega_multiplier, octavemax, omega_working, loop_tau_0, loop_delta_tau, on_1, n_1, o; - double length = ( tvec((tvec.numel()-1)) - tvec( octave_idx_type (0))); + + double length = tvec(tvec.numel () - 1) - tvec(0); + int octave_iter, coeff_iter; - std::complex<double> zeta, zz, z_accumulator, exp_term, exp_multiplier, alpha, h, *tpra, *temp_ptr_alpha, temp_alpha[12], *tprb, *temp_ptr_beta, temp_beta[12], temp_array[12], *p, x; - octave_idx_type n = tvec.numel(); - for ( int array_iter = 0 ; array_iter < 12 ; array_iter++ ) { - temp_array[array_iter] = std::complex<double> ( 0 , 0 ); - } + + std::complex<double> zeta, zz, z_accumulator, exp_term, exp_multiplier, + alpha, h, *tpra, *temp_ptr_alpha, temp_alpha[12], *tprb, *temp_ptr_beta, + temp_beta[12], temp_array[12], *p, x; + + octave_idx_type n = tvec.numel (); + + for (int array_iter = 0; array_iter < 12; array_iter++) + temp_array[array_iter] = std::complex<double> (0 , 0); + int factorial_array[12]; factorial_array[0] = 1; - for ( int i = 1 ; i < 12 ; i++ ) { + + for (int i = 1; i < 12; i++) factorial_array[i] = factorial_array[i-1] * i; - } + n_1 = n_inv = 1.0 / n; - mu = (0.5 * M_PI)/length; // Per the article; this is in place to improve numerical accuracy if desired. + mu = (0.5 * M_PI) / length; // Per the article; this is in place to improve numerical accuracy if desired. /* Viz. the paper, in which Dtau = c / omega_max, and c is stated as pi/2 for floating point processors, * In the case of this computation, I'll go by the recommendation. */ - delta_tau = M_PI / ( 2 * maxfreq ); + + delta_tau = M_PI / (2 * maxfreq); tau_0 = tvec(0) + delta_tau; tau_h = tau_0; te = tau_h + delta_tau; - octave_idx_type k ( 0 ); // Iterator for accessing xvec, tvec. + octave_idx_type k = 0; // Iterator for accessing xvec, tvec. Precomputation_Record * precomp_records_head, *record_current, *record_tail, *record_ref, *record_next; record_current = precomp_records_head = new Precomputation_Record; - for ( te = tvec(k) + (2 * delta_tau) ; ; ) { - x = std::complex<double>(xvec(k)); + + for (te = tvec(k) + (2 * delta_tau) ; ;) { - double t = mu*(tvec(k)-tau_h), tt; - p = record_current->power_series; - // p = 0 - *p++ = std::complex<double>(x); - // p = 1 - tt = -t; - h = x * tt; - *p++ = std::complex<double>(-h.imag(),h.real()); - // p = 2 - tt *= t*(1.0/2.0); - *p++ = x*tt; - // p = 3 - tt *= t*(-1.0/3.0); - h = x * tt; - *p++ = std::complex<double>(-h.imag(),h.real()); - // p = 4 - tt *= t*(1.0/4.0); - *p++ = x*tt; - // p = 5 - tt *= t*(-1.0/5.0); - h = x * tt; - *p++ = std::complex<double>(-h.imag(),h.real()); - // p = 6 - tt *= t*(1.0/6.0); - *p++ = x*tt; - // p = 7 - tt *= t*(-1.0/7.0); - h = x * tt; - *p++ = std::complex<double>(-h.imag(),h.real()); - // p = 8 - tt *= t*(1.0/8.0); - *p++ = x*tt; - // p = 9 - tt *= t*(-1.0/9.0); - h = x * tt; - *p++ = std::complex<double>(-h.imag(),h.real()); - // p = 10 - tt *= t*(1.0/10.0); - *p++ = x*tt; - // p = 11 - tt *= t*(-1.0/11.0); - h = x * tt; - *p++ = std::complex<double>(-h.imag(),h.real()); - } - record_current->stored_data = true; - for(k++; ( k < n ) && tvec(k) < te ; k++ ) { x = std::complex<double>(xvec(k)); { - double t = mu*(tvec(k)-tau_h), tt; - p = record_current->power_series; - // p = 0 - *p++ += std::complex<double>(x); - // p = 1 - tt = -t; - h = x * tt; - *p++ += std::complex<double>(- h.imag(), h.real()); - // p = 2 - tt *= t*(1.0/2.0); - *p++ += x*tt; - // p = 3 - tt *= t*(-1.0/3.0); - h = x * tt; - *p++ += std::complex<double>(-h.imag(),h.real()); - // p = 4 - tt *= t*(1.0/4.0); - *p++ += x*tt; - // p = 5 - tt *= t*(-1.0/5.0); - h = x * tt; - *p++ += std::complex<double>(-h.imag(),h.real()); - // p = 6 - tt *= t*(1.0/6.0); - *p++ += x*tt; - // p = 7 - tt *= t*(-1.0/7.0); - h = x * tt; - *p++ += std::complex<double>(-h.imag(),h.real()); - // p = 8 - tt *= t*(1.0/8.0); - *p++ += x*tt; - // p = 9 - tt *= t*(-1.0/9.0); - h = x * tt; - *p++ += std::complex<double>(-h.imag(),h.real()); - // p = 10 - tt *= t*(1.0/10.0); - *p++ += x*tt; - // p = 11 - tt *= t*(-1.0/11.0); - h = x * tt; - *p++ += std::complex<double>(-h.imag(),h.real()); + double t = mu*(tvec(k)-tau_h), tt; + p = record_current->power_series; + // p = 0 + *p++ = std::complex<double>(x); + // p = 1 + tt = -t; + h = x * tt; + *p++ = std::complex<double>(-h.imag(),h.real()); + // p = 2 + tt *= t*(1.0/2.0); + *p++ = x*tt; + // p = 3 + tt *= t*(-1.0/3.0); + h = x * tt; + *p++ = std::complex<double>(-h.imag(),h.real()); + // p = 4 + tt *= t*(1.0/4.0); + *p++ = x*tt; + // p = 5 + tt *= t*(-1.0/5.0); + h = x * tt; + *p++ = std::complex<double>(-h.imag(),h.real()); + // p = 6 + tt *= t*(1.0/6.0); + *p++ = x*tt; + // p = 7 + tt *= t*(-1.0/7.0); + h = x * tt; + *p++ = std::complex<double>(-h.imag(),h.real()); + // p = 8 + tt *= t*(1.0/8.0); + *p++ = x*tt; + // p = 9 + tt *= t*(-1.0/9.0); + h = x * tt; + *p++ = std::complex<double>(-h.imag(),h.real()); + // p = 10 + tt *= t*(1.0/10.0); + *p++ = x*tt; + // p = 11 + tt *= t*(-1.0/11.0); + h = x * tt; + *p++ = std::complex<double>(-h.imag(),h.real()); } + record_current->stored_data = true; - } - if( k >= n ) break; - tau_h = te + delta_tau; - te = tau_h + delta_tau; - record_current->next = new Precomputation_Record; - record_current = record_current->next; + for(k++; k < n && tvec(k) < te; k++) + { + x = std::complex<double> (xvec(k)); + { + double t = mu*(tvec(k)-tau_h), tt; + p = record_current->power_series; + // p = 0 + *p++ += std::complex<double>(x); + // p = 1 + tt = -t; + h = x * tt; + *p++ += std::complex<double>(- h.imag(), h.real()); + // p = 2 + tt *= t*(1.0/2.0); + *p++ += x*tt; + // p = 3 + tt *= t*(-1.0/3.0); + h = x * tt; + *p++ += std::complex<double>(-h.imag(),h.real()); + // p = 4 + tt *= t*(1.0/4.0); + *p++ += x*tt; + // p = 5 + tt *= t*(-1.0/5.0); + h = x * tt; + *p++ += std::complex<double>(-h.imag(),h.real()); + // p = 6 + tt *= t*(1.0/6.0); + *p++ += x*tt; + // p = 7 + tt *= t*(-1.0/7.0); + h = x * tt; + *p++ += std::complex<double>(-h.imag(),h.real()); + // p = 8 + tt *= t*(1.0/8.0); + *p++ += x*tt; + // p = 9 + tt *= t*(-1.0/9.0); + h = x * tt; + *p++ += std::complex<double>(-h.imag(),h.real()); + // p = 10 + tt *= t*(1.0/10.0); + *p++ += x*tt; + // p = 11 + tt *= t*(-1.0/11.0); + h = x * tt; + *p++ += std::complex<double>(-h.imag(),h.real()); + } + record_current->stored_data = true; + } + + if (k >= n) + break; + + tau_h = te + delta_tau; + te = tau_h + delta_tau; + + record_current->next = new Precomputation_Record; + record_current = record_current->next; } + record_tail = record_current; record_current = precomp_records_head; record_tail->next = 0; @@ -222,152 +252,233 @@ */ omega_oct = maxfreq / mu; - omega_multiplier = exp(-log(2)/coefficients); + omega_multiplier = exp (-log(2) / coefficients); octavemax = maxfreq; loop_tau_0 = tau_0; loop_delta_tau = delta_tau; - octave_idx_type iter ( 0 ); + octave_idx_type iter = 0; // Loops need to first travel over octaves, then coefficients; - - for ( octave_iter = octaves ; ; omega_oct *= 0.5 , octavemax *= 0.5 , loop_tau_0 += loop_delta_tau , loop_delta_tau *= 2 ) { - o = omega_oct; - omega_working = octavemax; - for ( coeff_iter = 0 ; coeff_iter < coefficients ; coeff_iter++, o *= omega_multiplier, omega_working *= omega_multiplier){ - exp_term = std::complex<double> ( cos( - omega_working * loop_tau_0 ) , - sin ( - omega_working * loop_tau_0 ) ); - exp_multiplier = std::complex<double> ( cos ( - 2 * omega_working * loop_delta_tau ) , - sin ( - 2 * omega_working * loop_delta_tau ) ); - for ( zeta = 0, record_current = precomp_records_head ; record_current ; - record_current = record_current->next, exp_term *= exp_multiplier ) { - if ( record_current->stored_data ) { - int p; - for ( zz = 0 , p = 0, on_1 = n_1 ; p < 12 ; p++ ) { - zz += record_current->power_series[p] * on_1 ; - on_1 *= o; - } - zeta += exp_term * zz; - } - } - results(iter) = std::complex<double> (zeta); - iter++; + for (octave_iter = octaves; ; + omega_oct *= 0.5, octavemax *= 0.5, loop_tau_0 += loop_delta_tau, loop_delta_tau *= 2) + { + o = omega_oct; + omega_working = octavemax; + for (coeff_iter = 0; + coeff_iter < coefficients; + coeff_iter++, o *= omega_multiplier, omega_working *= omega_multiplier) + { + exp_term = std::complex<double> (cos (- omega_working * loop_tau_0) , + sin (- omega_working * loop_tau_0)); + + exp_multiplier = std::complex<double> (cos (- 2 * omega_working * loop_delta_tau) , + sin (- 2 * omega_working * loop_delta_tau)); + + for (zeta = 0, record_current = precomp_records_head; + record_current; + record_current = record_current->next, exp_term *= exp_multiplier ) + { + if (record_current->stored_data) + { + int p; + for (zz = 0, p = 0, on_1 = n_1; p < 12; p++) + { + zz += record_current->power_series[p] * on_1; + on_1 *= o; + } + zeta += exp_term * zz; + } + } + + results(iter) = std::complex<double> (zeta); + iter++; + } + if (! (--octave_iter)) + break; + + /* If we've already reached the lowest value, stop. + * Otherwise, merge with the next computation range. + */ + double *exp_pse_ptr, *exp_ptr, exp_power_series_elements[12]; + exp_power_series_elements[0] = 1; + exp_pse_ptr = exp_ptr = exp_power_series_elements; + + for (int r_iter = 1; r_iter < 12; r_iter++) + exp_power_series_elements[r_iter] = exp_power_series_elements[r_iter-1] * + (mu * loop_delta_tau) * (1.0 / ((double) r_iter)); + + try + { + for (record_current = precomp_records_head; + record_current; + record_current = record_current->next) + { + if (! (record_ref = record_current->next ) + || ! record_ref->stored_data ) + { + // In this case, there is no next record, but this record has data. + if (record_current->stored_data) + { + int p = 0; + for (exp_pse_ptr = exp_power_series_elements + 1, temp_ptr_alpha = temp_alpha; + p < 12; + p++ , exp_pse_ptr++) + { + tpra = temp_ptr_alpha; + *(temp_ptr_alpha++) = std::complex<double>(record_current->power_series[p]); + for( exp_ptr = exp_power_series_elements, record_current->power_series[p] = *temp_ptr_alpha * *exp_ptr; ; ) { + /* This next block is from Mathias' code, and it does a few + * ... unsavoury things. First off, it uses conditionals with + * break in order to avoid potentially accessing null regions + * of memory, and then it does ... painful things with a few + * numbers. However, remembering that most of these will not + * actually be accessed for the first iterations, it's easier. + */ + + if (++exp_ptr >= exp_pse_ptr) + break; + + --tpra; + h = *tpra * *exp_ptr; + record_current->power_series[p].real() -= h.imag(); + record_current->power_series[p].imag() += h.real(); + + if (++exp_ptr >= exp_pse_ptr ) + break; + + --tpra; + record_current->power_series[p] -= *tpra * *exp_ptr; + + if (++exp_ptr >= exp_pse_ptr) + break; + + --tpra; + h = -*tpra * *exp_ptr; + record_current->power_series[p].real() -= h.imag(); + record_current->power_series[p].imag() += h.real(); + + if (++exp_ptr >= exp_pse_ptr) + break; + + --tpra; + record_current->power_series[p] += *tpra * *exp_ptr; + } + } + + if ( ! record_ref ) + break; // Last record was reached + + } + else + { + record_next = record_ref; + if ( record_current->stored_data ) + { + int p = 0, q = 0; + for (exp_pse_ptr = exp_power_series_elements + 1, temp_ptr_alpha = temp_alpha, temp_ptr_beta = temp_beta; + p < 12; p++, q++, exp_pse_ptr++) + { + tpra = temp_ptr_alpha; + *temp_ptr_alpha++ = record_current->power_series[p] + record_next->power_series[q]; + *temp_ptr_beta++ = record_current->power_series[p] - record_next->power_series[1]; + tprb = temp_ptr_beta; + + for (exp_ptr = exp_power_series_elements, record_current->power_series[p] = *tpra * *exp_ptr; ;) + { + if (++exp_ptr >= exp_pse_ptr ) + break; + + tprb -= 2; + h = *tprb * *exp_ptr; + record_current->power_series[p].real() -= h.imag(); + record_current->power_series[p].imag() += h.real(); + + if ( ++exp_ptr >= exp_pse_ptr ) + break; + + tpra -= 2; + record_current->power_series[p] -= *tpra * *exp_ptr; + + if (++exp_ptr >= exp_pse_ptr) + break; + + tprb -= 2; + h = - *tprb * *exp_ptr; + record_current->power_series[p].real() -= h.imag(); + record_current->power_series[p].imag() += h.real(); + + if (++exp_ptr >= exp_pse_ptr) + break; + + tpra -= 2; + record_current->power_series[p] += *tpra * *exp_ptr; + } + } + } + else + { + int q = 0; + for (exp_pse_ptr = exp_power_series_elements + 1, + temp_ptr_alpha = temp_alpha, + temp_ptr_beta = temp_beta; + q < 12; + q++, exp_pse_ptr++) + { + tpra = temp_ptr_alpha; + *temp_ptr_alpha++ = std::complex<double>(record_next->power_series[q]); + + for (exp_ptr = exp_power_series_elements, + record_next->power_series[q] = *tpra * *exp_ptr; ;) + { + if (++exp_ptr >= exp_pse_ptr) + break; + + --tpra; + h = *tpra * *exp_ptr; + record_next->power_series[q].real() -= h.imag(); + record_next->power_series[q].imag() += h.real(); + + if (++exp_ptr >= exp_pse_ptr) + break; + + --tpra; + record_next->power_series[q] -= *tpra * *exp_ptr; + + if ( ++exp_ptr >= exp_pse_ptr ) + break; + + --tpra; + h = -*tpra * *exp_ptr; + record_next->power_series[q].real() -= h.imag(); + record_next->power_series[q].imag() += h.real(); + + if (++exp_ptr >= exp_pse_ptr) + break; + + --tpra; + record_next->power_series[q] += *tpra * *exp_ptr; + } + } + } + + record_current->stored_data = true; + record_ref = record_next; + record_current->next = record_ref->next; + delete record_ref; + + } + } + } + } + catch (std::exception& e) + {//This section was part of my debugging, and may be removed. + std::cout << "Exception thrown: " << e.what() << std::endl; + ComplexRowVector exception_result (1); + exception_result(0) = false; + return exception_result; + } } - if ( !(--octave_iter) ) break; - /* If we've already reached the lowest value, stop. - * Otherwise, merge with the next computation range. - */ - double *exp_pse_ptr, *exp_ptr, exp_power_series_elements[12]; - exp_power_series_elements[0] = 1; - exp_pse_ptr = exp_ptr = exp_power_series_elements; - for ( int r_iter = 1 ; r_iter < 12 ; r_iter++ ) { - exp_power_series_elements[r_iter] = exp_power_series_elements[r_iter-1] - * ( mu * loop_delta_tau) * ( 1.0 / ( (double) r_iter ) ); - } - try{ - for ( record_current = precomp_records_head ; record_current ; - record_current = record_current->next ) { - if ( ! ( record_ref = record_current->next ) || ! record_ref->stored_data ) { - // In this case, there is no next record, but this record has data. - if ( record_current->stored_data ) { - int p = 0; - for( exp_pse_ptr = exp_power_series_elements + 1 , temp_ptr_alpha = temp_alpha ; p < 12 ; p++ , exp_pse_ptr++ ) { - tpra = temp_ptr_alpha; - *(temp_ptr_alpha++) = std::complex<double>(record_current->power_series[p]); - for( exp_ptr = exp_power_series_elements, record_current->power_series[p] = *temp_ptr_alpha * *exp_ptr; ; ) { - /* This next block is from Mathias' code, and it does a few - * ... unsavoury things. First off, it uses conditionals with - * break in order to avoid potentially accessing null regions - * of memory, and then it does ... painful things with a few - * numbers. However, remembering that most of these will not - * actually be accessed for the first iterations, it's easier. - */ - if ( ++exp_ptr >= exp_pse_ptr ) break; - --tpra; - h = *tpra * *exp_ptr; - record_current->power_series[p].real() -= h.imag(); - record_current->power_series[p].imag() += h.real(); - if ( ++exp_ptr >= exp_pse_ptr ) break; - --tpra; - record_current->power_series[p] -= *tpra * *exp_ptr; - if ( ++exp_ptr >= exp_pse_ptr ) break; - --tpra; - h = -*tpra * *exp_ptr; - record_current->power_series[p].real() -= h.imag(); - record_current->power_series[p].imag() += h.real(); - if ( ++exp_ptr >= exp_pse_ptr ) break; - --tpra; - record_current->power_series[p] += *tpra * *exp_ptr; - } - } - if ( ! record_ref ) break; // Last record was reached - } - else { - record_next = record_ref; - if ( record_current->stored_data ) { - int p = 0, q = 0; - for( exp_pse_ptr = exp_power_series_elements + 1, temp_ptr_alpha = temp_alpha, temp_ptr_beta = temp_beta; p < 12 ; p++, q++, exp_pse_ptr++ ) { - tpra = temp_ptr_alpha; - *temp_ptr_alpha++ = record_current->power_series[p] + record_next->power_series[q]; - *temp_ptr_beta++ = record_current->power_series[p] - record_next->power_series[1]; - tprb = temp_ptr_beta; - for( exp_ptr = exp_power_series_elements, record_current->power_series[p] = *tpra * *exp_ptr; ; ) { - if ( ++exp_ptr >= exp_pse_ptr ) break; - tprb -= 2; - h = *tprb * *exp_ptr; - record_current->power_series[p].real() -= h.imag(); - record_current->power_series[p].imag() += h.real(); - if ( ++exp_ptr >= exp_pse_ptr ) break; - tpra -= 2; - record_current->power_series[p] -= *tpra * *exp_ptr; - if ( ++exp_ptr >= exp_pse_ptr ) break; - tprb -= 2; - h = - *tprb * *exp_ptr; - record_current->power_series[p].real() -= h.imag(); - record_current->power_series[p].imag() += h.real(); - if ( ++exp_ptr >= exp_pse_ptr ) break; - tpra -= 2; - record_current->power_series[p] += *tpra * *exp_ptr; - } - } - } else { - int q = 0; - for( exp_pse_ptr = exp_power_series_elements + 1, temp_ptr_alpha = temp_alpha, temp_ptr_beta = temp_beta; q < 12; q++, exp_pse_ptr++ ) { - tpra = temp_ptr_alpha; - *temp_ptr_alpha++ = std::complex<double>(record_next->power_series[q]); - for ( exp_ptr = exp_power_series_elements, record_next->power_series[q] = *tpra * *exp_ptr; ; ) { - if ( ++exp_ptr >= exp_pse_ptr ) break; - --tpra; - h = *tpra * *exp_ptr; - record_next->power_series[q].real() -= h.imag(); - record_next->power_series[q].imag() += h.real(); - if ( ++exp_ptr >= exp_pse_ptr ) break; - --tpra; - record_next->power_series[q] -= *tpra * *exp_ptr; - if ( ++exp_ptr >= exp_pse_ptr ) break; - --tpra; - h = -*tpra * *exp_ptr; - record_next->power_series[q].real() -= h.imag(); - record_next->power_series[q].imag() += h.real(); - if ( ++exp_ptr >= exp_pse_ptr ) break; - --tpra; - record_next->power_series[q] += *tpra * *exp_ptr; - } - } - } - record_current->stored_data = true; - record_ref = record_next; - record_current->next = record_ref->next; - delete record_ref; - } - } - } - } catch (std::exception& e) { //This section was part of my debugging, and may be removed. - std::cout << "Exception thrown: " << e.what() << std::endl; - ComplexRowVector exception_result (1); - exception_result(0) = std::complex<double> ( 0,0); - return exception_result; - } - } - return results; + + return true; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
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. |
From: <cd...@us...> - 2012-08-10 12:42:53
|
Revision: 10853 http://octave.svn.sourceforge.net/octave/?rev=10853&view=rev Author: cdf Date: 2012-08-10 12:42:46 +0000 (Fri, 10 Aug 2012) Log Message: ----------- prepare for release 1.3.1 Modified Paths: -------------- trunk/octave-forge/extra/fpl/DESCRIPTION trunk/octave-forge/extra/fpl/NEWS trunk/octave-forge/extra/fpl/inst/fpl_vtk_b64_write_field.m trunk/octave-forge/extra/fpl/inst/fpl_vtk_raw_write_field.m trunk/octave-forge/extra/fpl/src/Makefile Added Paths: ----------- trunk/octave-forge/extra/fpl/src/__array_to_uint8__.cc Removed Paths: ------------- trunk/octave-forge/extra/fpl/src/array_to_uint8.cc Modified: trunk/octave-forge/extra/fpl/DESCRIPTION =================================================================== --- trunk/octave-forge/extra/fpl/DESCRIPTION 2012-08-10 09:30:12 UTC (rev 10852) +++ trunk/octave-forge/extra/fpl/DESCRIPTION 2012-08-10 12:42:46 UTC (rev 10853) @@ -1,11 +1,11 @@ Name: fpl -Version: 1.3.0 -Date: 2012-08-08 +Version: 1.3.1 +Date: 2012-10-08 Author: Carlo de Falco, Massimiliano Culpo and others Maintainer: Carlo de Falco, Massimiliano Culpo Title: Fem PLotting Description: Collection of routines to export data produced by Finite Elements or Finite Volume Simulations in formats used by some visualization programs. Categories: Graphics -Depends: octave ( >= 3.0.0 ) +Depends: octave ( >= 3.4.2 ) License: GPLv3+ Modified: trunk/octave-forge/extra/fpl/NEWS =================================================================== --- trunk/octave-forge/extra/fpl/NEWS 2012-08-10 09:30:12 UTC (rev 10852) +++ trunk/octave-forge/extra/fpl/NEWS 2012-08-10 12:42:46 UTC (rev 10853) @@ -1,3 +1,8 @@ +Summary of important user-visible changes for dataframe 1.3.1: +------------------------------------------------------------------- + + * 1.3.1 is just a bugfix release to fix some issues in 1.3.0 + Summary of important user-visible changes for dataframe 1.3.0: ------------------------------------------------------------------- @@ -6,12 +11,13 @@ * ASCII VTK Unstructured Grid (VTU) exporter has been speeded up via code vectorization -* A new function to write raw binary VTU files has been added. - A new function to write base64-encoded binary VTU files has been added - (requires Octave >= 3.7, will fall back to ASCII mode otherwise). - As a rule of thumbs, ascii files are about 50% larger than base64 which - are 30% larger than raw files. base64 files are faster to write (about 30% faster - than raw on my machine for large meshes), ASCII files are more portable. + * A new function to write raw binary VTU files has been added. + A new function to write base64-encoded binary VTU files has been added + (requires Octave >= 3.7, will fall back to ASCII mode otherwise). + As a rule of thumbs, ascii files are about 50% larger than base64 which + are 30% larger than raw files. base64 files are faster to write (about 30% faster + than raw on my machine for large meshes), ASCII files are more portable. -* New functions to write ASCII structured grid VTK files have been added + * New functions to write ASCII structured grid VTK files have been added + Modified: trunk/octave-forge/extra/fpl/inst/fpl_vtk_b64_write_field.m =================================================================== --- trunk/octave-forge/extra/fpl/inst/fpl_vtk_b64_write_field.m 2012-08-10 09:30:12 UTC (rev 10852) +++ trunk/octave-forge/extra/fpl/inst/fpl_vtk_b64_write_field.m 2012-08-10 12:42:46 UTC (rev 10853) @@ -156,8 +156,8 @@ ## VTK-Points (mesh nodes) fprintf (fid, " <Points>\n"); fprintf (fid, " <DataArray type=""Float64"" Name=""Array"" NumberOfComponents=""3"" format=""appended"" offset=""%d"" />\n", offset); - newdata = array_to_uint8(p)(:); - data = [data, base64_encode([array_to_uint8(int32 (numel (newdata)))(:); newdata])]; + newdata = __array_to_uint8__(p)(:); + data = [data, base64_encode([__array_to_uint8__(int32 (numel (newdata)))(:); newdata])]; offset = numel (data); fprintf (fid, " </Points>\n"); @@ -165,20 +165,20 @@ ## VTK-Cells (mesh elements) fprintf (fid, " <Cells>\n"); fprintf (fid, " <DataArray type=""Int32"" Name=""connectivity"" format=""appended"" offset=""%d"" />\n", offset); - newdata = array_to_uint8(int32 (t))(:); - data = [data, base64_encode([array_to_uint8(int32 (numel (newdata)))(:); newdata])]; + newdata = __array_to_uint8__(int32 (t))(:); + data = [data, base64_encode([__array_to_uint8__(int32 (numel (newdata)))(:); newdata])]; offset = numel (data); fprintf (fid, " <DataArray type=""Int32"" Name=""offsets"" format=""appended"" offset=""%d"" />\n", offset); tmp = (dim+1):(dim+1):((dim+1)*nelems); - newdata = array_to_uint8(int32 (tmp))(:); - data = [data, base64_encode([array_to_uint8(int32 (numel (newdata)))(:); newdata])]; + newdata = __array_to_uint8__(int32 (tmp))(:); + data = [data, base64_encode([__array_to_uint8__(int32 (numel (newdata)))(:); newdata])]; offset = numel (data); fprintf (fid, " <DataArray type=""UInt8"" Name=""types"" format=""appended"" offset=""%d"" />\n", offset); tmp = eltype*ones(nelems,1); - newdata = array_to_uint8(uint8 (tmp))(:); - data = [data, base64_encode([array_to_uint8(int32 (numel (newdata)))(:); newdata])]; + newdata = __array_to_uint8__(uint8 (tmp))(:); + data = [data, base64_encode([__array_to_uint8__(int32 (numel (newdata)))(:); newdata])]; offset = numel (data); fprintf (fid, " </Cells>\n"); @@ -204,8 +204,8 @@ endif fprintf (fid, " <DataArray type=""Float64"" Name=""%s"" ", ndataname); fprintf (fid, "NumberOfComponents=""%d"" format=""appended"" offset=""%d"" />\n", ncomp, offset); - newdata = array_to_uint8(ndata.')(:); - data = [data, base64_encode([array_to_uint8(int32 (numel (newdata)))(:); newdata])]; + newdata = __array_to_uint8__(ndata.')(:); + data = [data, base64_encode([__array_to_uint8__(int32 (numel (newdata)))(:); newdata])]; offset = numel (data); endfor fprintf (fid, " </PointData>\n"); @@ -231,8 +231,8 @@ endif fprintf (fid, " <DataArray type=""Float64"" Name=""%s"" ", cdataname); fprintf (fid, "NumberOfComponents=""%d"" format=""appended"" offset=""%d"" />\n", ncomp, offset); - newdata = array_to_uint8(cdata.')(:); - data = [data, base64_encode([array_to_uint8(int32 (numel (newdata)))(:); newdata])]; + newdata = __array_to_uint8__(cdata.')(:); + data = [data, base64_encode([__array_to_uint8__(int32 (numel (newdata)))(:); newdata])]; offset = numel (data); endfor fprintf (fid, " </CellData>\n"); Modified: trunk/octave-forge/extra/fpl/inst/fpl_vtk_raw_write_field.m =================================================================== --- trunk/octave-forge/extra/fpl/inst/fpl_vtk_raw_write_field.m 2012-08-10 09:30:12 UTC (rev 10852) +++ trunk/octave-forge/extra/fpl/inst/fpl_vtk_raw_write_field.m 2012-08-10 12:42:46 UTC (rev 10853) @@ -151,8 +151,8 @@ ## VTK-Points (mesh nodes) fprintf (fid, " <Points>\n"); fprintf (fid, " <DataArray type=""Float64"" Name=""Array"" NumberOfComponents=""3"" format=""appended"" offset=""%d"" />\n", offset); - newdata = array_to_uint8 (p); - data = [data, array_to_uint8(int32 (numel (newdata))), newdata]; + newdata = __array_to_uint8__ (p); + data = [data, __array_to_uint8__(int32 (numel (newdata))), newdata]; offset = numel (data); fprintf (fid, " </Points>\n"); @@ -160,20 +160,20 @@ ## VTK-Cells (mesh elements) fprintf (fid, " <Cells>\n"); fprintf (fid, " <DataArray type=""Int32"" Name=""connectivity"" format=""appended"" offset=""%d"" />\n", offset); - newdata = array_to_uint8 (int32 (t)); - data = [data, array_to_uint8(int32 (numel (newdata))), newdata]; + newdata = __array_to_uint8__ (int32 (t)); + data = [data, __array_to_uint8__(int32 (numel (newdata))), newdata]; offset = numel (data); fprintf (fid, " <DataArray type=""Int32"" Name=""offsets"" format=""appended"" offset=""%d"" />\n", offset); tmp = (dim+1):(dim+1):((dim+1)*nelems); - newdata = array_to_uint8 (int32 (tmp)); - data = [data, array_to_uint8(int32 (numel (newdata))), newdata]; + newdata = __array_to_uint8__ (int32 (tmp)); + data = [data, __array_to_uint8__(int32 (numel (newdata))), newdata]; offset = numel (data); fprintf (fid, " <DataArray type=""UInt8"" Name=""types"" format=""appended"" offset=""%d"" />\n", offset); tmp = eltype*ones(nelems,1); - newdata = array_to_uint8 (uint8 (tmp)); - data = [data, array_to_uint8(int32 (numel (newdata))), newdata]; + newdata = __array_to_uint8__ (uint8 (tmp)); + data = [data, __array_to_uint8__(int32 (numel (newdata))), newdata]; offset = numel (data); fprintf (fid, " </Cells>\n"); @@ -199,8 +199,8 @@ endif fprintf (fid, " <DataArray type=""Float64"" Name=""%s"" ", ndataname); fprintf (fid, "NumberOfComponents=""%d"" format=""appended"" offset=""%d"" />\n", ncomp, offset); - newdata = array_to_uint8 (ndata.'); - data = [data, array_to_uint8(int32 (numel (newdata))), newdata]; + newdata = __array_to_uint8__ (ndata.'); + data = [data, __array_to_uint8__(int32 (numel (newdata))), newdata]; offset = numel (data); endfor fprintf (fid, " </PointData>\n"); @@ -226,8 +226,8 @@ endif fprintf (fid, " <DataArray type=""Float64"" Name=""%s"" ", cdataname); fprintf (fid, "NumberOfComponents=""%d"" format=""appended"" offset=""%d"" />\n", ncomp, offset); - newdata = array_to_uint8 (cdata.'); - data = [data, array_to_uint8(int32 (numel (newdata))), newdata]; + newdata = __array_to_uint8__ (cdata.'); + data = [data, __array_to_uint8__(int32 (numel (newdata))), newdata]; offset = numel (data); endfor fprintf (fid, " </CellData>\n"); Modified: trunk/octave-forge/extra/fpl/src/Makefile =================================================================== --- trunk/octave-forge/extra/fpl/src/Makefile 2012-08-10 09:30:12 UTC (rev 10852) +++ trunk/octave-forge/extra/fpl/src/Makefile 2012-08-10 12:42:46 UTC (rev 10853) @@ -1,9 +1,9 @@ -OCTFILES := array_to_uint8.oct - +OCTFILES := __array_to_uint8__.oct +MKOCTFILE ?= mkoctfile all: $(OCTFILES) %.oct: %.cc - mkoctfile $< + $(MKOCTFILE) $< clean: -rm -f *.o core octave-core *.oct *~ Copied: trunk/octave-forge/extra/fpl/src/__array_to_uint8__.cc (from rev 10831, trunk/octave-forge/extra/fpl/src/array_to_uint8.cc) =================================================================== --- trunk/octave-forge/extra/fpl/src/__array_to_uint8__.cc (rev 0) +++ trunk/octave-forge/extra/fpl/src/__array_to_uint8__.cc 2012-08-10 12:42:46 UTC (rev 10853) @@ -0,0 +1,112 @@ +/* +Copyright (C) 2012 Carlo de Falco + +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 Octave; see the file COPYING. If not, see +<http://www.gnu.org/licenses/>. + +Author: Carlo de Falco <carlo@guglielmo.local> +Created: 2012-08-04 + +*/ + +#include <octave/oct.h> + +DEFUN_DLD(__array_to_uint8__,args,nargout,"\ +-*- texinfo -*-\n\ +@deftypefn {Function File} [@var{out}] = __array_to_uint8__ (@var{in})\n\ +UNDOCUMENTED INTERNAL FUNCTION.\n\ +@end deftypefn") +{ + octave_value_list retval; + int nargin = args.length (); + + if (nargin != 1) + print_usage (); + else + { + uint8NDArray out; + + if (! args(0).is_numeric_type ()) + error ("array_to_uint8: encoding is supported only for numeric arrays"); + else if (args(0).is_complex_type () + || args(0).is_sparse_type ()) + error ("array_to_uint8: encoding complex or sparse data is not supported"); + else if (args(0).is_integer_type ()) + { + +#define MAKE_INT_BRANCH(X) \ + if (args(0).is_ ## X ## _type ()) \ + { \ + const X##NDArray in = \ + args(0). X## _array_value (); \ + octave_idx_type len = \ + in.numel () * sizeof (X## _t) / sizeof (uint8_t); \ + if (! error_state) \ + { \ + out.resize1 (len); \ + std::copy ((uint8_t*) in.data(), \ + ((uint8_t*) in.data()) + len, \ + out.fortran_vec ()); \ + retval(0) = octave_value (out); \ + } \ + } + + MAKE_INT_BRANCH(int8) + else MAKE_INT_BRANCH(int16) + else MAKE_INT_BRANCH(int32) + else MAKE_INT_BRANCH(int64) + else MAKE_INT_BRANCH(uint8) + else MAKE_INT_BRANCH(uint16) + else MAKE_INT_BRANCH(uint32) + else MAKE_INT_BRANCH(uint64) + +#undef MAKE_INT_BRANCH + + else + panic_impossible (); + } + else if (args(0).is_single_type ()) + { + const FloatNDArray in = + args(0).float_array_value (); + octave_idx_type len = + in.numel () * sizeof (float) / sizeof (uint8_t); + if (! error_state) + { + out.resize1 (len); + std::copy ((uint8_t*) in.data(), + ((uint8_t*) in.data()) + len, + out.fortran_vec ()); + retval(0) = octave_value (out); + } + } + else + { + const Array<double> in = args(0).array_value (); + + octave_idx_type len = + in.numel () * sizeof (double) / sizeof (uint8_t); + + if (! error_state) + { + out.resize1 (len); + std::copy ((uint8_t*) in.data(), + ((uint8_t*) in.data()) + len, + out.fortran_vec ()); + retval(0) = octave_value (out); + } + } + } + return retval; +} Deleted: trunk/octave-forge/extra/fpl/src/array_to_uint8.cc =================================================================== --- trunk/octave-forge/extra/fpl/src/array_to_uint8.cc 2012-08-10 09:30:12 UTC (rev 10852) +++ trunk/octave-forge/extra/fpl/src/array_to_uint8.cc 2012-08-10 12:42:46 UTC (rev 10853) @@ -1,112 +0,0 @@ -/* -Copyright (C) 2012 Carlo de Falco - -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 Octave; see the file COPYING. If not, see -<http://www.gnu.org/licenses/>. - -Author: Carlo de Falco <carlo@guglielmo.local> -Created: 2012-08-04 - -*/ - -#include <octave/oct.h> - -DEFUN_DLD(array_to_uint8,args,nargout,"\ --*- texinfo -*-\n\ -@deftypefn {Function File} [@var{out}] = array_to_uint8 (@var{in})\n\ -UNDOCUMENTED INTERNAL FUNCTION.\n\ -@end deftypefn") -{ - octave_value_list retval; - int nargin = args.length (); - - if (nargin != 1) - print_usage (); - else - { - uint8NDArray out; - - if (! args(0).is_numeric_type ()) - error ("array_to_uint8: encoding is supported only for numeric arrays"); - else if (args(0).is_complex_type () - || args(0).is_sparse_type ()) - error ("array_to_uint8: encoding complex or sparse data is not supported"); - else if (args(0).is_integer_type ()) - { - -#define MAKE_INT_BRANCH(X) \ - if (args(0).is_ ## X ## _type ()) \ - { \ - const X##NDArray in = \ - args(0). X## _array_value (); \ - octave_idx_type len = \ - in.numel () * sizeof (X## _t) / sizeof (uint8_t); \ - if (! error_state) \ - { \ - out.resize1 (len); \ - std::copy ((uint8_t*) in.data(), \ - ((uint8_t*) in.data()) + len, \ - out.fortran_vec ()); \ - retval(0) = octave_value (out); \ - } \ - } - - MAKE_INT_BRANCH(int8) - else MAKE_INT_BRANCH(int16) - else MAKE_INT_BRANCH(int32) - else MAKE_INT_BRANCH(int64) - else MAKE_INT_BRANCH(uint8) - else MAKE_INT_BRANCH(uint16) - else MAKE_INT_BRANCH(uint32) - else MAKE_INT_BRANCH(uint64) - -#undef MAKE_INT_BRANCH - - else - panic_impossible (); - } - else if (args(0).is_single_type ()) - { - const FloatNDArray in = - args(0).float_array_value (); - octave_idx_type len = - in.numel () * sizeof (float) / sizeof (uint8_t); - if (! error_state) - { - out.resize1 (len); - std::copy ((uint8_t*) in.data(), - ((uint8_t*) in.data()) + len, - out.fortran_vec ()); - retval(0) = octave_value (out); - } - } - else - { - const Array<double> in = args(0).array_value (); - - octave_idx_type len = - in.numel () * sizeof (double) / sizeof (uint8_t); - - if (! error_state) - { - out.resize1 (len); - std::copy ((uint8_t*) in.data(), - ((uint8_t*) in.data()) + len, - out.fortran_vec ()); - retval(0) = octave_value (out); - } - } - } - return retval; -} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cd...@us...> - 2012-08-10 09:30:20
|
Revision: 10852 http://octave.svn.sourceforge.net/octave/?rev=10852&view=rev Author: cdf Date: 2012-08-10 09:30:12 +0000 (Fri, 10 Aug 2012) Log Message: ----------- code review part 1 Modified Paths: -------------- trunk/octave-forge/extra/lssa/inst/cubicwgt.m trunk/octave-forge/extra/lssa/inst/lscomplex.m trunk/octave-forge/extra/lssa/inst/lscorrcoeff.m trunk/octave-forge/extra/lssa/inst/lsreal.m Modified: trunk/octave-forge/extra/lssa/inst/cubicwgt.m =================================================================== --- trunk/octave-forge/extra/lssa/inst/cubicwgt.m 2012-08-09 23:49:21 UTC (rev 10851) +++ trunk/octave-forge/extra/lssa/inst/cubicwgt.m 2012-08-10 09:30:12 UTC (rev 10852) @@ -13,27 +13,29 @@ ## 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{a} =} cubicwgt (@var{series}) +## -*- texinfo -*- +## @deftypefn {Function File} {@var{a} =} cubicwgt (@var{series}) ## Return @var{series} as windowed by a cubic polynomial, ## 1 + ( x ^ 2 * ( 2 x - 3 ) ), assuming x is in [-1,1]. -## @end deftypefn - ## This function implements the windowing function on page 10 of the paper. ## if t is in [-1,1] then the windowed term is a = 1 + ( |t|^2 * ( 2|t| - 3 ) ## else the windowed term is 0. -function a = cubicwgt(s) ## where s is the value to be windowed - a = abs(s); - a = ifelse( ( a < 1 ), 1 + ( ( a .^ 2 ) .* ( 2 .* a - 3 ) ), a = 0); +## @end deftypefn + +function a = cubicwgt (s) + ## s is the value to be windowed + a = abs (s); + a = ifelse ((a < 1), 1 + ((a .^ 2) .* (2 .* a - 3)), 0); endfunction -%!test + %!shared h, m, k %! h = 2; %! m = 0.01; -%! k = [ 0 , 3 , 1.5, -1, -0.5, -0.25, 0.75 ]; -%!assert( cubicwgt(h), 0 ); -%!assert( cubicwgt(m), 1 + m ^ 2 * ( 2 * m - 3 )); -%!assert( cubicwgt(k), [ 1.00000, 0.00000, 0.00000, 0.00000, 0.50000, 0.84375, 0.15625], 1e-6); +%! k = [0, 3, 1.5, -1, -0.5, -0.25, 0.75]; +%!assert (cubicwgt (h), 0 ); +%!assert (cubicwgt (m), 1 + m ^ 2 * (2 * m - 3)); +%!assert (cubicwgt (k), [1.00000, 0.00000, 0.00000, 0.00000, ... +%! 0.50000, 0.84375, 0.15625], 1e-6); %! ## Tests cubicwgt on two scalars and two vectors; cubicwgt will work %! ## on any array input. Modified: trunk/octave-forge/extra/lssa/inst/lscomplex.m =================================================================== --- trunk/octave-forge/extra/lssa/inst/lscomplex.m 2012-08-09 23:49:21 UTC (rev 10851) +++ trunk/octave-forge/extra/lssa/inst/lscomplex.m 2012-08-10 09:30:12 UTC (rev 10852) @@ -24,39 +24,45 @@ ## @end deftypefn -function transform = lscomplex( t , x , omegamax , ncoeff , noctave ) +function transform = lscomplex (t, x, omegamax, ncoeff, noctave) - n = length(t); ## VECTOR ONLY, and since t and x have the same number of + ## 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); + transform = zeros (1, ncoeff * noctave); o = omegamax; omul = 2 ^ (- 1 / ncoeff); - for iter = 1:ncoeff*noctave + for iter = 1:ncoeff * noctave ot = o .* t; - transform(iter) = sum ((cos (ot) - (sin (ot) .* i)) .* x) / n; ## See the - ## paper for the expression + ## See the paper for the expression below + transform(iter) = sum ((cos (ot) - (sin (ot) .* i)) .* x) / n; + - o *= omul; ## To advance the transform to the next coefficient in the octave + ## Advance the transform to the next coefficient in the octave + o *= omul; endfor endfunction %!test -%!shared t, x, o, maxfreq %! 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)); +%! 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 ); +%! 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); Modified: trunk/octave-forge/extra/lssa/inst/lscorrcoeff.m =================================================================== --- trunk/octave-forge/extra/lssa/inst/lscorrcoeff.m 2012-08-09 23:49:21 UTC (rev 10851) +++ trunk/octave-forge/extra/lssa/inst/lscorrcoeff.m 2012-08-10 09:30:12 UTC (rev 10852) @@ -31,47 +31,51 @@ ## ## @end deftypefn -## Demo with sin, cos as Nir suggested. -%!demo -%! x = 1:10; -%! y = sin(x); -%! z = cos(x); -%! a = lscorrcoeff(x,y,x,z,0.5,0.9) -%! ## This generates the correlation coefficient at time 0.5 and circular freq. 0.9 +## nucorrcoeff, computes a coefficient of the wavelet correlation of two time series +function coeff = lscorrcoeff (x1, y1, x2, y2, t, o, wgt = @cubicwgt, wgtrad = 1) -## nucorrcoeff, computes a coefficient of the wavelet correlation of two time series + so = 0.05 * o; -function coeff = lscorrcoeff(x1, y1, x2, y2, t, o, wgt = @cubicwgt, wgtrad = 1) - so = 0.05 * o; - ## This code can only, as of currently, work on vectors; I haven't figured out a way to make it work on a matrix. - if( ( ndims(x1) == 2 ) && ! ( rows(x1) == 1 ) ) - x1 = reshape(x1,1,length(x1)); - y1 = reshape(y1,1,length(y1)); - x2 = reshape(x2,1,length(x2)); - y2 = reshape(y2,1,length(y2)); + ## This code can only, as of currently, work on vectors; + ## I haven't figured out a way to make it work on a matrix. + if ((ndims (x1) == 2) && !(rows (x1) == 1)) + x1 = reshape (x1, 1, length (x1)); + y1 = reshape (y1, 1, length (y1)); + x2 = reshape (x2, 1, length (x2)); + y2 = reshape (y2, 1, length (y2)); endif - ## The first solution that comes to mind is admittedly slightly ugly and has a data footprint of O(2n) - ## but it is vectorised. - mask = find( ( abs( x1 - t ) * so ) < wgtrad ); - rx1 = x1(mask); ## I've kept the variable names from the R function here - ry1 = y1(mask); ## Needs to have a noisy error if length(y1) != length(x1) -- add this! - mask = find( ( abs( x2 - t ) * so ) < wgtrad ); + + ## The first solution that comes to mind is admittedly slightly + ## ugly and has a data footprint of O(2n) but it is vectorised. + mask = (abs (x1 - t) * so) < wgtrad; + ## I've kept the variable names from the R function here + rx1 = x1(mask); + ## FIXME : Needs to have a noisy error if length(y1) != length(x1) -- add this! + ry1 = y1(mask); + + ## I've used the same mask for all of these as it's an + ## otherwise unimportant variable ... can this leak memory? + mask = (abs (x2 - t) * so ) < wgtrad; rx2 = x2(mask); ry2 = y2(mask); - ## I've used the same mask for all of these as it's an otherwise unimportant variable ... can this leak memory? - length(rx1) ##printing this length is probably used as a warning if 0 is returned; I included it + + ## printing this length is probably used as a warning if 0 is returned; + ## I included it + length (rx1) + ## in particular to maintain an exact duplicate of the R function. - s = sum ( wgt ( ( rx1 - t ) .* so ) ) * sum ( wgt ( ( rx2 - t ) .* so ) ); - if s != 0 - coeff = sum ( wgt ((rx1-t).*so).*exp(i*o.*rx1).*ry1) * sum(wgt((rx2-t).*so).*exp(i*o.*rx2).*conj(ry2)) / s; + s = sum (wgt ((rx1 - t) .* so)) * sum (wgt ((rx2 - t ) .* so )); + if (s != 0) + coeff = sum (wgt ((rx1 - t) .* so) .* exp (i * o .* rx1) .* ry1) * ... + sum (wgt ((rx2 - t) .* so) .* exp (i * o .* rx2) .* conj (ry2)) / s; else coeff = 0; endif endfunction -%!test + %!shared t, p, x, y, z, o, maxfreq %! maxfreq = 4 / (2 * pi); %! t = linspace (0, 8); @@ -88,12 +92,18 @@ %! 0.2 .* cos (maxfreq .* p) + %! cos ((1/4) * maxfreq .* p)); %! o = [maxfreq , (3/4 * maxfreq) , (1/4 * maxfreq)]; -%!assert (lscorrcoeff (t, x, t, x, 0.5, maxfreq), -5.54390340863576 - -%! 1.82439880893383i, 5e-10); -%!assert (lscorrcoeff (t, x, t, y, 0.5, maxfreq), 5.54390340863576 + -%! 1.82439880893383i, 5e-10); -%!assert (lscorrcoeff (t, x, p, z, 0.5, maxfreq), -5.55636741054624 - -%! 1.82803733863170i, 5e-10); +%!assert (lscorrcoeff (t, x, t, x, 0.5, maxfreq), +%! -5.54390340863576 - 1.82439880893383i, 5e-10); +%!assert (lscorrcoeff (t, x, t, y, 0.5, maxfreq), +%! 5.54390340863576 + 1.82439880893383i, 5e-10); +%!assert (lscorrcoeff (t, x, p, z, 0.5, maxfreq), +%! -5.55636741054624 - 1.82803733863170i, 5e-10); +## Demo with sin, cos as Nir suggested. +%!demo +%! ## This generates the correlation coefficient at time 0.5 and circular freq. 0.9 +%! x = 1:10; +%! y = sin (x); +%! z = cos (x); +%! a = lscorrcoeff (x, y, x, z, 0.5, 0.9) - Modified: trunk/octave-forge/extra/lssa/inst/lsreal.m =================================================================== --- trunk/octave-forge/extra/lssa/inst/lsreal.m 2012-08-09 23:49:21 UTC (rev 10851) +++ trunk/octave-forge/extra/lssa/inst/lsreal.m 2012-08-10 09:30:12 UTC (rev 10852) @@ -28,44 +28,40 @@ function transform = lsreal (t, x, omegamax, ncoeff, noctave) - k = n = length(t); ## THIS IS VECTOR-ONLY. I'd need to add another bit of code to - ## make it array-safe, and that's not knowing right now what else will be necessary. - transform = zeros(1,(noctave * ncoeff)); + ## FIXME : THIS IS VECTOR-ONLY. I'd need to add another bit of code to + ## make it array-safe, and that's not knowing right now what else + ## will be necessary. + k = n = length (t); - od = 2 ^ (- 1 / ncoeff); + transform = zeros (1, (noctave * ncoeff)); + od = 2 ^ (- 1 / ncoeff); o = omegamax; - n1 = 1 / n; - ncoeffp = ncoeff; + ncoeffp = ncoeff * noctave; - ncoeffp *= noctave; - for iter = 1:ncoeffp - ## This method is an application of Eq. 8 on page 6 of the text, as well as Eq. 7 + ## This method is an application of Eq. 8 on + ## page 6 of the text, as well as Eq. 7 ot = o .* t; - zeta = sum ((cos (ot) .* x) - - (sin (ot) .* x .* i)); + zeta = n1 * sum ((cos (ot) - i * sin (ot)) .* x); - ot = ot .* 2; + ot *= 2; - iota = sum (cos (ot) - - (sin (ot) .* i)); + iota = n1 * sum (cos (ot) - i * sin (ot)); - zeta = zeta .* n1; - iota = iota .* n1; + transform(iter) = (2 * (conj (zeta) - (conj (iota) * zeta)) / + (1 - (real (iota) ^ 2) - (imag (iota) ^ 2))); - transform(iter) = (2 / (1 -(real (iota) ^ 2) - (imag(iota) ^ 2)) * (conj(zeta) - (conj(iota) * zeta))); - o = o .* od; + o *= od; endfor endfunction %!test -%!shared t, x, o, maxfreq %! maxfreq = 4 / ( 2 * pi ); %! t = linspace(0,8); %! x = ( 2 .* sin ( maxfreq .* t ) + @@ -73,8 +69,11 @@ %! 0.5 .* sin ( (1/4) * maxfreq .* t ) - %! 0.2 .* cos ( maxfreq .* t ) + %! cos ( (1/4) * maxfreq .* t ) ); -%!assert (lsreal (t,x,maxfreq,2,2), -%! [-1.68275915310663 + 4.70126183846743i, 1.93821553170889 + 4.95660209883437i, 4.38145452686697 + 2.14403733658600i, 5.27425332281147 - 0.73933440226597i ], -%! 5e-10) %! # In the assert here, I've got an error bound large enough to catch %! # individual system errors which would present no real issue. +%! assert (lsreal (t,x,maxfreq,2,2), +%! [(-1.68275915310663 + 4.70126183846743i), ... +%! (1.93821553170889 + 4.95660209883437i), ... +%! (4.38145452686697 + 2.14403733658600i), ... +%! (5.27425332281147 - 0.73933440226597i)], +%! 5e-10) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2012-08-09 23:49:28
|
Revision: 10851 http://octave.svn.sourceforge.net/octave/?rev=10851&view=rev Author: benjf5 Date: 2012-08-09 23:49:21 +0000 (Thu, 09 Aug 2012) Log Message: ----------- Fixed INDEX, NEWS for lssa 0.1.1 release. Also updated formatting. Modified Paths: -------------- trunk/octave-forge/extra/lssa/DESCRIPTION trunk/octave-forge/extra/lssa/INDEX trunk/octave-forge/extra/lssa/NEWS trunk/octave-forge/extra/lssa/inst/cubicwgt.m trunk/octave-forge/extra/lssa/inst/lombcoeff.m trunk/octave-forge/extra/lssa/inst/lombnormcoeff.m trunk/octave-forge/extra/lssa/inst/lscomplex.m trunk/octave-forge/extra/lssa/inst/lscorrcoeff.m trunk/octave-forge/extra/lssa/inst/lsreal.m trunk/octave-forge/extra/lssa/inst/lswaveletcoeff.m Modified: trunk/octave-forge/extra/lssa/DESCRIPTION =================================================================== --- trunk/octave-forge/extra/lssa/DESCRIPTION 2012-08-09 16:45:30 UTC (rev 10850) +++ trunk/octave-forge/extra/lssa/DESCRIPTION 2012-08-09 23:49:21 UTC (rev 10851) @@ -5,9 +5,9 @@ Maintainer: Ben Lewis <be...@gm...> Title: Least squares spectral analysis Description: A package implementing tools to compute spectral decompositions of -irregularly-spaced time series. Currently includes functions based off the -Lomb-Scargle periodogram and Adolf Mathias' implementation for R and C (see -URLs). + irregularly-spaced time series. Currently includes functions based off the + Lomb-Scargle periodogram and Adolf Mathias' implementation for R and C (see + URLs). Url: http://www.jstatsoft.org/v11/i02 Problems: fast implementations, wavelet functions are currently not functional. Depends: octave (>= 3.4.3) Modified: trunk/octave-forge/extra/lssa/INDEX =================================================================== --- trunk/octave-forge/extra/lssa/INDEX 2012-08-09 16:45:30 UTC (rev 10850) +++ trunk/octave-forge/extra/lssa/INDEX 2012-08-09 23:49:21 UTC (rev 10851) @@ -1,10 +1,19 @@ -cubicwgt -fastlscomplex -lombcoeff -lombnormcoeff -lscomplex -lscomplexwavelet -lscorrcoeff -lsreal -lsrealwavelet -lswaveletcoeff \ No newline at end of file +lssa >> Least Squares Spectral Analysis +Windowing + cubicwgt +Periodogram + lombcoeff lombnormcoeff +Accelerated time-series functions + fastlscomplex +Complex time-series functions + lscomplex fastlscomplex lswaveletcoeff +# lscomplexwavelet +Real time-series functions + lsreal +# lsrealwavelet +Correlation + lscorrcoeff +Wavelet Transform + lswaveletcoeff +# lscomplexwavelet lsrealwavelet +## The wavelet functions are unavailable until I can get them working. Modified: trunk/octave-forge/extra/lssa/NEWS =================================================================== --- trunk/octave-forge/extra/lssa/NEWS 2012-08-09 16:45:30 UTC (rev 10850) +++ trunk/octave-forge/extra/lssa/NEWS 2012-08-09 23:49:21 UTC (rev 10851) @@ -14,9 +14,13 @@ author's reasoning. Its generated results are relevant to any given data set, but it does not appear to be normalized to any great extent. - ** lsrealwavelet and lscomplexwavelet are not currently correct or even really - functional; this is an ongoing struggle for me, and if anyone can suggest - what I might do to improve them, please! By all means, send me an email. + ** There are two wavelet functions under development, but they are not included + in this release as they are currently not functional. For all your wavelet + needs, the specific transformation used is available in the lswaveletcoeff + function, and will generate a single cosine/sine magnitude pair (as a + complex number) for a complex-valued series (this function may be joined by + a companion for real-valued series) and can be looped to simulate a full + wavelet transform. ** For all the working functions, tests have been written and formatted to Octave coding standards. These tests should pass on any given architecture Modified: trunk/octave-forge/extra/lssa/inst/cubicwgt.m =================================================================== --- trunk/octave-forge/extra/lssa/inst/cubicwgt.m 2012-08-09 16:45:30 UTC (rev 10850) +++ trunk/octave-forge/extra/lssa/inst/cubicwgt.m 2012-08-09 23:49:21 UTC (rev 10851) @@ -14,8 +14,8 @@ ## this program; if not, see <http://www.gnu.org/licenses/>. ## -*-texinfo-*- -## @deftypefn {Function File} {a =} cubicwgt {series} -## Return the series as windowed by a cubic polynomial, +## @deftypefn {Function File} {@var{a} =} cubicwgt (@var{series}) +## Return @var{series} as windowed by a cubic polynomial, ## 1 + ( x ^ 2 * ( 2 x - 3 ) ), assuming x is in [-1,1]. ## @end deftypefn @@ -36,4 +36,4 @@ %!assert( cubicwgt(m), 1 + m ^ 2 * ( 2 * m - 3 )); %!assert( cubicwgt(k), [ 1.00000, 0.00000, 0.00000, 0.00000, 0.50000, 0.84375, 0.15625], 1e-6); %! ## Tests cubicwgt on two scalars and two vectors; cubicwgt will work -%! ## on any array input. \ No newline at end of file +%! ## on any array input. Modified: trunk/octave-forge/extra/lssa/inst/lombcoeff.m =================================================================== --- trunk/octave-forge/extra/lssa/inst/lombcoeff.m 2012-08-09 16:45:30 UTC (rev 10850) +++ trunk/octave-forge/extra/lssa/inst/lombcoeff.m 2012-08-09 23:49:21 UTC (rev 10851) @@ -14,7 +14,7 @@ ## this program; if not, see <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {Function File} {c =} lombcoeff (time, mag, freq) +## @deftypefn {Function File} {@var{c} =} lombcoeff (@var{time}, @var{mag}, @var{freq}) ## ## Return the coefficient of the Lomb periodogram (unnormalized) for the ## (@var{time},@var{mag}) series for the @var{freq} provided. Modified: trunk/octave-forge/extra/lssa/inst/lombnormcoeff.m =================================================================== --- trunk/octave-forge/extra/lssa/inst/lombnormcoeff.m 2012-08-09 16:45:30 UTC (rev 10850) +++ trunk/octave-forge/extra/lssa/inst/lombnormcoeff.m 2012-08-09 23:49:21 UTC (rev 10851) @@ -14,7 +14,7 @@ ## this program; if not, see <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {Function File} {c =} lombnormcoeff (time, mag, freq) +## @deftypefn {Function File} {@var{c} =} lombnormcoeff (@var{time}, @var{mag}, @var{freq}) ## ## Return the coefficient of the Lomb Normalised Periodogram at the ## specified @var{frequency} of the periodogram applied to the @@ -25,11 +25,17 @@ function coeff = lombnormcoeff (T, X, omega) -tau = atan2 (sum (sin (2 .* omega .*T)), sum (cos (2 .* omega .* T))) / 2; -coeff = ((sum (X .* cos (omega .* T - tau)) .^ 2 / sum (cos (omega .* T - tau) .^ 2) + - sum (X .* sin (omega .* T - tau)) .^ 2 / sum (sin (omega .* T - tau) .^ 2 )) / - (2 * var(X))); + xmean = mean (X); + theta = atan2 (sum (sin (2 .* omega .*T)), + sum (cos (2 .* omega .* T))) / (2*omega); + + coeff = ((sum ((X-xmean) .* cos (omega .* T - theta)) .^ 2 / + sum (cos (omega .* T - theta) .^ 2) + + sum ((X-xmean) .* sin (omega .* T - theta)) .^ 2 / + sum (sin (omega .* T - theta) .^ 2 )) / + (2 * var(X))); + endfunction %!shared t, x, o, maxfreq @@ -41,6 +47,6 @@ %! 0.2 .* cos (maxfreq .* t) + %! cos ((1/4) * maxfreq .*t)); %! o = [maxfreq , (3/4 * maxfreq) , (1/4 * maxfreq)]; -%!assert (lombnormcoeff (t,x,o(1)), 63.3294946603949, 5e-10); -%!assert (lombnormcoeff (t,x,o(2)), 73.2601360674868, 5e-10); -%!assert (lombnormcoeff (t,x,o(3)), 53.0799752083903, 5e-10); +%!assert (lombnormcoeff (t,x,o(1)), 44.7068607258824, 5e-10); +%!assert (lombnormcoeff (t,x,o(2)), 35.7769955188467, 5e-10); +%!assert (lombnormcoeff (t,x,o(3)), 20.7577786183241, 5e-10); Modified: trunk/octave-forge/extra/lssa/inst/lscomplex.m =================================================================== --- trunk/octave-forge/extra/lssa/inst/lscomplex.m 2012-08-09 16:45:30 UTC (rev 10850) +++ trunk/octave-forge/extra/lssa/inst/lscomplex.m 2012-08-09 23:49:21 UTC (rev 10851) @@ -14,7 +14,7 @@ ## this program; if not, see <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {Function File} {t =} lscomplex ( time, mag, maxfreq, numcoeff, numoctaves) +## @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} @@ -25,14 +25,25 @@ function transform = lscomplex( t , x , omegamax , ncoeff , noctave ) - n = length(t); ## VECTOR ONLY, and since t and x have the same number of entries, there's no problem. + + n = length(t); ## VECTOR ONLY, and since t and x have the same number of + ## entries, there's no problem. + transform = zeros(1,ncoeff*noctave); + o = omegamax; - omul = 2 ^ ( - 1 / ncoeff ); + + omul = 2 ^ (- 1 / ncoeff); + for iter = 1:ncoeff*noctave + ot = o .* t; - transform(iter) = sum( ( cos(ot) - ( sin(ot) .* i ) ) .* x ) / n; ## See the paper for the expression + + transform(iter) = sum ((cos (ot) - (sin (ot) .* i)) .* x) / n; ## See the + ## paper for the expression + o *= omul; ## To advance the transform to the next coefficient in the octave + endfor endfunction @@ -48,4 +59,4 @@ %! 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 ); \ No newline at end of file +%! [-0.400924546169395 - 2.371555305867469i, 1.218065147708429 - 2.256125004156890i, 1.935428592212907 - 1.539488163739336i, 2.136692292751917 - 0.980532175174563i ], 5e-10 ); Modified: trunk/octave-forge/extra/lssa/inst/lscorrcoeff.m =================================================================== --- trunk/octave-forge/extra/lssa/inst/lscorrcoeff.m 2012-08-09 16:45:30 UTC (rev 10850) +++ trunk/octave-forge/extra/lssa/inst/lscorrcoeff.m 2012-08-09 23:49:21 UTC (rev 10851) @@ -14,12 +14,15 @@ ## this program; if not, see <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {Function File} {c =} lscorrcoeff (abc1, ord1, abc2, ord2, time, freq) -## @deftypefnx {Function File} {c =} lscorrcoeff (abc1, ord1, abc2, ord2, time, freq, window) -## @deftypefnx {Function File} {c =} lscorrcoeff (abc1, ord1, abc2, ord2, time, freq, window, winradius) +## @deftypefn {Function File} {@var{c} =} lscorrcoeff (@var{time1}, @var{mag1}, @var{time2}, @var{mag2}, @var{time}, @var{freq}) +## @deftypefnx {Function File} {@var{c} =} lscorrcoeff (@var{time1}, @var{mag1}, +## @var{time2}, @var{mag2}, @var{time}, @var{freq}, @var{window} = @var{cubicwgt}) +## @deftypefnx {Function File} {@var{c} =} lscorrcoeff (@var{time1}, @var{mag1}, +## @var{time2}, @var{mag2}, @var{time}, @var{freq}, @var{window} = +## @var{cubicwgt}, @var{winradius} = 1) ## ## Return the coefficient of the wavelet correlation of time -## series (@var{abc1}, @var{ord1}) and (@var{abc2}, @var{ord2}). +## series (@var{time1}, @var{mag1}) and (@var{time2}, @var{mag2}). ## @var{window} is used to apply a windowing function, its ## default is cubicwgt if left blank, and its radius is 1, ## as defined as the default for @var{winradius}. Modified: trunk/octave-forge/extra/lssa/inst/lsreal.m =================================================================== --- trunk/octave-forge/extra/lssa/inst/lsreal.m 2012-08-09 16:45:30 UTC (rev 10850) +++ trunk/octave-forge/extra/lssa/inst/lsreal.m 2012-08-09 23:49:21 UTC (rev 10851) @@ -14,7 +14,7 @@ ## this program; if not, see <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {Function File} {transform =} lsreal ( time, mag, maxfreq, numcoeff, numoctaves) +## @deftypefn {Function File} {@var{transform} =} lsreal (@var{time}, @var{mag}, @var{maxfreq}, @var{numcoeff}, @var{numoctaves}) ## ## Return the real least-squares transform of the time series ## defined, based on the maximal frequency @var{maxfreq}, the @@ -26,35 +26,39 @@ ## @seealso{lscomplex} ## @end deftypefn -function transform = lsreal( t, x, omegamax, ncoeff, noctave) - ## the R function runs the following command: - ## nureal( double X, double Y, int min(X,Y), int ncoeff, int noctave, double omegamax, complex rp) - ## this means that in the C, *tptr is X and *xptr is Y. Yes, I know. I think I'll rename them. - ## n is the min of X and Y ... (as is k) and ncoeff is ... ncoeff, while noctave is noctave and - ## o is omegamax. - ## where rp = complex(noctave*ncoeff) so ... I can just store that as noctave*ncoeff and have no - ## problems, I guess. - ## Possibly throw an error if ncoeff <= 0. +function transform = lsreal (t, x, omegamax, ncoeff, noctave) + k = n = length(t); ## THIS IS VECTOR-ONLY. I'd need to add another bit of code to ## make it array-safe, and that's not knowing right now what else will be necessary. - transform = zeros(1,(noctave * ncoeff)); ## In the C code, this is rendered as a Complex, but Octave doesn't care. - od = 2 ^ ( - 1 / ncoeff ); ## this will cause a crash if ncoeff=0; prefer error & quit? + transform = zeros(1,(noctave * ncoeff)); + + od = 2 ^ (- 1 / ncoeff); + o = omegamax; - ## ot is just defined as a Real here, I'm leaving it until it needs to be called. - n1 = 1 / n; ## written n_1 in the C, but I'd prefer to not get into underscores here. - ## zeta and iota are defined as Complex here, leaving them until they need to be defined. - ## I'm not convinced I won't want ncoeff again, so ... + + n1 = 1 / n; + ncoeffp = ncoeff; + ncoeffp *= noctave; + for iter = 1:ncoeffp ## This method is an application of Eq. 8 on page 6 of the text, as well as Eq. 7 ot = o .* t; - zeta = sum( ( cos(ot) .* x ) - ( sin(ot) .* x .* i ) ); + + zeta = sum ((cos (ot) .* x) - + (sin (ot) .* x .* i)); + ot = ot .* 2; - iota = sum( cos(ot) - ( sin(ot) .* i ) ); + + iota = sum (cos (ot) - + (sin (ot) .* i)); + zeta = zeta .* n1; + iota = iota .* n1; - transform(iter) = 2 / ( 1 - ( real(iota) ^ 2 ) - ( imag(iota) ^ 2 ) ) * ( conj(zeta) - (conj(iota) * zeta )); + + transform(iter) = (2 / (1 -(real (iota) ^ 2) - (imag(iota) ^ 2)) * (conj(zeta) - (conj(iota) * zeta))); o = o .* od; endfor @@ -73,4 +77,4 @@ %! [-1.68275915310663 + 4.70126183846743i, 1.93821553170889 + 4.95660209883437i, 4.38145452686697 + 2.14403733658600i, 5.27425332281147 - 0.73933440226597i ], %! 5e-10) %! # In the assert here, I've got an error bound large enough to catch -%! # individual system errors which would present no real issue. \ No newline at end of file +%! # individual system errors which would present no real issue. Modified: trunk/octave-forge/extra/lssa/inst/lswaveletcoeff.m =================================================================== --- trunk/octave-forge/extra/lssa/inst/lswaveletcoeff.m 2012-08-09 16:45:30 UTC (rev 10850) +++ trunk/octave-forge/extra/lssa/inst/lswaveletcoeff.m 2012-08-09 23:49:21 UTC (rev 10851) @@ -14,12 +14,12 @@ ## this program; if not, see <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {Function File} {c =} lswaveletcoeff (abc, ord, time, freq) -## @deftypefnx {Function File} {c =} lswaveletcoeff (abc, ord, time, freq, window) -## @deftypefnx {Function File} {c =} lswaveletcoeff (abc, ord, time, freq, window, winradius) +## @deftypefn {Function File} {@var{c} =} lswaveletcoeff (@var{t}, @var{x}, @var{time}, @var{freq}) +## @deftypefnx {Function File} {@var{c} =} lswaveletcoeff (@var{t}, @var{x}, @var{time}, @var{freq}, @var{window}=cubicwgt) +## @deftypefnx {Function File} {@var{c} =} lswaveletcoeff (@var{t}, @var{x}, @var{time}, @var{freq}, @var{window}=cubicwgt, @var{winradius}=1) ## ## Return the coefficient of the wavelet transform of the -## complex time series (@var{abc}, @var{ord}) at time @var{time} +## complex time series (@var{t}, @var{x}) at time @var{time} ## and frequency @var{freq}; optional variable @var{window} ## provides a windowing function and defaults to cubicwgt, ## while @var{winradius} is the windowing radius, and defaults @@ -74,4 +74,4 @@ %!assert (lswaveletcoeff (t, x, 0.5, maxfreq), 0.383340407638780 + %! 2.385251997545446i , 5e-10); %!assert (lswaveletcoeff (t, y, 3.3, 3/4 * maxfreq), -2.35465091096084 + -%! 1.01892561714824i, 5e-10); \ No newline at end of file +%! 1.01892561714824i, 5e-10); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2012-08-09 16:45:39
|
Revision: 10850 http://octave.svn.sourceforge.net/octave/?rev=10850&view=rev Author: benjf5 Date: 2012-08-09 16:45:30 +0000 (Thu, 09 Aug 2012) Log Message: ----------- Really the last commit for lssa release 0.1.1. Modified Paths: -------------- trunk/octave-forge/extra/lssa/inst/cubicwgt.m trunk/octave-forge/extra/lssa/inst/lscomplex.m trunk/octave-forge/extra/lssa/inst/lscomplexwavelet.m trunk/octave-forge/extra/lssa/inst/lsreal.m Modified: trunk/octave-forge/extra/lssa/inst/cubicwgt.m =================================================================== --- trunk/octave-forge/extra/lssa/inst/cubicwgt.m 2012-08-09 16:08:18 UTC (rev 10849) +++ trunk/octave-forge/extra/lssa/inst/cubicwgt.m 2012-08-09 16:45:30 UTC (rev 10850) @@ -34,7 +34,6 @@ %! k = [ 0 , 3 , 1.5, -1, -0.5, -0.25, 0.75 ]; %!assert( cubicwgt(h), 0 ); %!assert( cubicwgt(m), 1 + m ^ 2 * ( 2 * m - 3 )); -%!assert( cubicwgt(k), [ 1.00000, 0.00000, 0.00000, 0.00000, 0.50000, -%! 0.84375, 0.15625], 1e-6); +%!assert( cubicwgt(k), [ 1.00000, 0.00000, 0.00000, 0.00000, 0.50000, 0.84375, 0.15625], 1e-6); %! ## Tests cubicwgt on two scalars and two vectors; cubicwgt will work %! ## on any array input. \ No newline at end of file Modified: trunk/octave-forge/extra/lssa/inst/lscomplex.m =================================================================== --- trunk/octave-forge/extra/lssa/inst/lscomplex.m 2012-08-09 16:08:18 UTC (rev 10849) +++ trunk/octave-forge/extra/lssa/inst/lscomplex.m 2012-08-09 16:45:30 UTC (rev 10850) @@ -48,7 +48,4 @@ %! 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 ); \ No newline at end of file +%! [-0.400924546169395 - 2.371555305867469i, 1.218065147708429 - 2.256125004156890i, 1.935428592212907 - 1.539488163739336i, 2.136692292751917 - 0.980532175174563i ], 5e-10 ); \ No newline at end of file Modified: trunk/octave-forge/extra/lssa/inst/lscomplexwavelet.m =================================================================== --- trunk/octave-forge/extra/lssa/inst/lscomplexwavelet.m 2012-08-09 16:08:18 UTC (rev 10849) +++ trunk/octave-forge/extra/lssa/inst/lscomplexwavelet.m 2012-08-09 16:45:30 UTC (rev 10850) @@ -15,7 +15,7 @@ -function transform = lscomplexwavelet( t , x, omegamax, ncoeff, noctave, tmin, tmax, tstep, sigma = 0.05) +function transform = lscomplexwavelet( T, X, omegamax, ncoeff, noctave, tmin, tmax, tstep, sigma = 0.05) ## This is a transform based entirely on the simplified complex-valued transform ## in the Mathias paper, page 10. My problem with the code as it stands is, it @@ -42,8 +42,8 @@ current_iteration = (octave_iter-1)*ncoeff+coeff_iter; window_radius = pi / ( sigma * omegamax * ( 2 ^ ( current_iteration - 1 ) ) ); - window_count = 2 * ceil ( ( tmax - tmin ) / window_step ) - 1; - omega = current_frequency = maxfreq * 2 ^ ( - octave_iter*coeff_iter / ncoeff ); + window_count = 2 * ceil ( ( tmax - tmin ) / window_radius ) - 1; + omega = current_frequency = omegamax * 2 ^ ( - octave_iter*coeff_iter / ncoeff ); Modified: trunk/octave-forge/extra/lssa/inst/lsreal.m =================================================================== --- trunk/octave-forge/extra/lssa/inst/lsreal.m 2012-08-09 16:08:18 UTC (rev 10849) +++ trunk/octave-forge/extra/lssa/inst/lsreal.m 2012-08-09 16:45:30 UTC (rev 10850) @@ -70,10 +70,7 @@ %! 0.2 .* cos ( maxfreq .* t ) + %! cos ( (1/4) * maxfreq .* t ) ); %!assert (lsreal (t,x,maxfreq,2,2), -%! [-1.68275915310663 + 4.70126183846743i, -%! 1.93821553170889 + 4.95660209883437i, -%! 4.38145452686697 + 2.14403733658600i, -%! 5.27425332281147 - 0.73933440226597i ], +%! [-1.68275915310663 + 4.70126183846743i, 1.93821553170889 + 4.95660209883437i, 4.38145452686697 + 2.14403733658600i, 5.27425332281147 - 0.73933440226597i ], %! 5e-10) %! # In the assert here, I've got an error bound large enough to catch %! # individual system errors which would present no real issue. \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <be...@us...> - 2012-08-09 16:08:25
|
Revision: 10849 http://octave.svn.sourceforge.net/octave/?rev=10849&view=rev Author: benjf5 Date: 2012-08-09 16:08:18 +0000 (Thu, 09 Aug 2012) Log Message: ----------- Updated tests, DESCRIPTION, etc. for lssa release. Modified Paths: -------------- trunk/octave-forge/extra/lssa/DESCRIPTION trunk/octave-forge/extra/lssa/NEWS trunk/octave-forge/extra/lssa/inst/cubicwgt.m trunk/octave-forge/extra/lssa/inst/lombcoeff.m trunk/octave-forge/extra/lssa/inst/lscomplex.m trunk/octave-forge/extra/lssa/inst/lscorrcoeff.m trunk/octave-forge/extra/lssa/inst/lsreal.m trunk/octave-forge/extra/lssa/inst/lswaveletcoeff.m Modified: trunk/octave-forge/extra/lssa/DESCRIPTION =================================================================== --- trunk/octave-forge/extra/lssa/DESCRIPTION 2012-08-09 12:58:55 UTC (rev 10848) +++ trunk/octave-forge/extra/lssa/DESCRIPTION 2012-08-09 16:08:18 UTC (rev 10849) @@ -1,6 +1,6 @@ Name: lssa -Version: 0.1.0 -Date: 2012-07-28 +Version: 0.1.1 +Date: 2012-08-09 Author: Ben Lewis <be...@gm...> Maintainer: Ben Lewis <be...@gm...> Title: Least squares spectral analysis Modified: trunk/octave-forge/extra/lssa/NEWS =================================================================== --- trunk/octave-forge/extra/lssa/NEWS 2012-08-09 12:58:55 UTC (rev 10848) +++ trunk/octave-forge/extra/lssa/NEWS 2012-08-09 16:08:18 UTC (rev 10849) @@ -1,4 +1,4 @@ -Welcome to the first release of lssa, 0.1.0 +Welcome to the first release of lssa, 0.1.1 Current status: @@ -18,3 +18,7 @@ functional; this is an ongoing struggle for me, and if anyone can suggest what I might do to improve them, please! By all means, send me an email. + ** For all the working functions, tests have been written and formatted to + Octave coding standards. These tests should pass on any given architecture + (there was some question about that previously) and often provide examples + of how the function operates. For a few functions, there are demo scripts. Modified: trunk/octave-forge/extra/lssa/inst/cubicwgt.m =================================================================== --- trunk/octave-forge/extra/lssa/inst/cubicwgt.m 2012-08-09 12:58:55 UTC (rev 10848) +++ trunk/octave-forge/extra/lssa/inst/cubicwgt.m 2012-08-09 16:08:18 UTC (rev 10849) @@ -19,19 +19,22 @@ ## 1 + ( x ^ 2 * ( 2 x - 3 ) ), assuming x is in [-1,1]. ## @end deftypefn -%!shared h, m, k -%! h = 2; m = 0.01; -%! k = [ 0 , 3 , 1.5, -1, -0.5, -0.25, 0.75 ]; -%!assert( cubicwgt(h), 0 ); -%!assert( cubicwgt(m), 1 + m ^ 2 * ( 2 * m - 3 )); -%!assert( cubicwgt(k), [ 1.00000 0.00000 0.00000 0.00000 0.50000 0.84375 0.15625], 1E-6); -%! ## Tests cubicwgt on two scalars and two vectors; cubicwgt will work on any array input. - - -## This function implements the windowing function on page 10 of the doc. +## This function implements the windowing function on page 10 of the paper. ## if t is in [-1,1] then the windowed term is a = 1 + ( |t|^2 * ( 2|t| - 3 ) ## else the windowed term is 0. function a = cubicwgt(s) ## where s is the value to be windowed a = abs(s); a = ifelse( ( a < 1 ), 1 + ( ( a .^ 2 ) .* ( 2 .* a - 3 ) ), a = 0); endfunction + +%!test +%!shared h, m, k +%! h = 2; +%! m = 0.01; +%! k = [ 0 , 3 , 1.5, -1, -0.5, -0.25, 0.75 ]; +%!assert( cubicwgt(h), 0 ); +%!assert( cubicwgt(m), 1 + m ^ 2 * ( 2 * m - 3 )); +%!assert( cubicwgt(k), [ 1.00000, 0.00000, 0.00000, 0.00000, 0.50000, +%! 0.84375, 0.15625], 1e-6); +%! ## Tests cubicwgt on two scalars and two vectors; cubicwgt will work +%! ## on any array input. \ No newline at end of file Modified: trunk/octave-forge/extra/lssa/inst/lombcoeff.m =================================================================== --- trunk/octave-forge/extra/lssa/inst/lombcoeff.m 2012-08-09 12:58:55 UTC (rev 10848) +++ trunk/octave-forge/extra/lssa/inst/lombcoeff.m 2012-08-09 16:08:18 UTC (rev 10849) @@ -47,6 +47,6 @@ %! 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); +%!assert (lombcoeff (t, x, maxfreq), 1076.77574184435, 5e-10); +%!assert (lombcoeff (t, x, 3/4*maxfreq), 1226.53572492183, 5e-10); +%!assert (lombcoeff (t, x, 1/4*maxfreq), 1341.63962181896, 5e-10); Modified: trunk/octave-forge/extra/lssa/inst/lscomplex.m =================================================================== --- trunk/octave-forge/extra/lssa/inst/lscomplex.m 2012-08-09 12:58:55 UTC (rev 10848) +++ trunk/octave-forge/extra/lssa/inst/lscomplex.m 2012-08-09 16:08:18 UTC (rev 10849) @@ -23,16 +23,7 @@ ## @seealso{lsreal} ## @end deftypefn -%!test -%!shared t, x, o, maxfreq -%! 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.400754376933531 - 2.366871097665244i, 1.226663545950135 - 2.243899314661490i, 1.936433327880238 - 1.515538553198501i, 2.125045509991203 - 0.954100898917708i ], 6e-14 ); - - function transform = lscomplex( t , x , omegamax , ncoeff , noctave ) n = length(t); ## VECTOR ONLY, and since t and x have the same number of entries, there's no problem. transform = zeros(1,ncoeff*noctave); @@ -45,3 +36,19 @@ endfor endfunction + +%!test +%!shared t, x, o, maxfreq +%! 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 ); \ No newline at end of file Modified: trunk/octave-forge/extra/lssa/inst/lscorrcoeff.m =================================================================== --- trunk/octave-forge/extra/lssa/inst/lscorrcoeff.m 2012-08-09 12:58:55 UTC (rev 10848) +++ trunk/octave-forge/extra/lssa/inst/lscorrcoeff.m 2012-08-09 16:08:18 UTC (rev 10849) @@ -68,7 +68,7 @@ endfunction - +%!test %!shared t, p, x, y, z, o, maxfreq %! maxfreq = 4 / (2 * pi); %! t = linspace (0, 8); Modified: trunk/octave-forge/extra/lssa/inst/lsreal.m =================================================================== --- trunk/octave-forge/extra/lssa/inst/lsreal.m 2012-08-09 12:58:55 UTC (rev 10848) +++ trunk/octave-forge/extra/lssa/inst/lsreal.m 2012-08-09 16:08:18 UTC (rev 10849) @@ -26,13 +26,6 @@ ## @seealso{lscomplex} ## @end deftypefn -%!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)); -%!assert(lsreal(t,x,maxfreq,2,2),[-1.68275915310663 + 4.70126183846743i, 1.93821553170889 + 4.95660209883437i, 4.38145452686697 + 2.14403733658600i, 5.27425332281147 - 0.73933440226597i],6e-14) -%! #In the assert here, I've got an error bound large enough to catch individual system errors which would present no real issue. - function transform = lsreal( t, x, omegamax, ncoeff, noctave) ## the R function runs the following command: ## nureal( double X, double Y, int min(X,Y), int ncoeff, int noctave, double omegamax, complex rp) @@ -65,6 +58,22 @@ o = o .* od; endfor - ## transform = rp; +endfunction -endfunction +%!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 ) ); +%!assert (lsreal (t,x,maxfreq,2,2), +%! [-1.68275915310663 + 4.70126183846743i, +%! 1.93821553170889 + 4.95660209883437i, +%! 4.38145452686697 + 2.14403733658600i, +%! 5.27425332281147 - 0.73933440226597i ], +%! 5e-10) +%! # In the assert here, I've got an error bound large enough to catch +%! # individual system errors which would present no real issue. \ No newline at end of file Modified: trunk/octave-forge/extra/lssa/inst/lswaveletcoeff.m =================================================================== --- trunk/octave-forge/extra/lssa/inst/lswaveletcoeff.m 2012-08-09 12:58:55 UTC (rev 10848) +++ trunk/octave-forge/extra/lssa/inst/lswaveletcoeff.m 2012-08-09 16:08:18 UTC (rev 10849) @@ -53,3 +53,25 @@ coeff = ifelse( s != 0 , sum( wgt( ( rx - t ) .* so) .* exp( i .* o .* ( rx - t ) ) .* ry ) ./ s , 0 ); endfunction + +%!test +%!shared t, p, x, y, z, 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)); +%! y = - x; +%! p = linspace (0, 8, 500); +%! z = (2 .* sin (maxfreq .* p) + +%! 3 .* sin ((3/4) * maxfreq .* p) - +%! 0.5 .* sin ((1/4) * maxfreq .* p) - +%! 0.2 .* cos (maxfreq .* p) + +%! cos ((1/4) * maxfreq .* p)); +%! o = [maxfreq , (3/4 * maxfreq) , (1/4 * maxfreq)]; +%!assert (lswaveletcoeff (t, x, 0.5, maxfreq), 0.383340407638780 + +%! 2.385251997545446i , 5e-10); +%!assert (lswaveletcoeff (t, y, 3.3, 3/4 * maxfreq), -2.35465091096084 + +%! 1.01892561714824i, 5e-10); \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |