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

## [Octave-cvsupdate] octave-forge/main/signal sgolay.m,1.1.1.1,1.2 sgolayfilt.m,1.1.1.1,1.2

 [Octave-cvsupdate] octave-forge/main/signal sgolay.m,1.1.1.1,1.2 sgolayfilt.m,1.1.1.1,1.2 From: Paul Kienzle - 2004-12-23 11:38:53 ```Update of /cvsroot/octave/octave-forge/main/signal In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21039 Modified Files: sgolay.m sgolayfilt.m Log Message: [for Pascal Dupuis] allow derivatives Index: sgolay.m =================================================================== RCS file: /cvsroot/octave/octave-forge/main/signal/sgolay.m,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- sgolay.m 10 Oct 2001 19:54:49 -0000 1.1.1.1 +++ sgolay.m 23 Dec 2004 11:38:43 -0000 1.2 @@ -14,9 +14,10 @@ ## along with this program; if not, write to the Free Software ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -## F = sgolay (p, n) +## F = sgolay (p, n [, m [, ts]]) ## Computes the filter coefficients for all Savitzsky-Golay smoothing -## filters of order p for length n (odd). +## filters of order p for length n (odd). m can be used in order to +## get directly the mth derivative. In this case, ts is a scaling factor. ## ## The early rows of F smooth based on future values and later rows ## smooth based on past values, with the middle row using half future @@ -36,30 +37,29 @@ ## ## See also: sgolayfilt +## 15 Dec 2004 modified by Pascal Dupuis ## Author: Paul Kienzle ## Based on smooth.m by E. Farhi -## TODO: Doesn't accept "weight vector" as fourth parameter since -## TODO: Should be able to estimate derivatives using second and -## TODO: subsequent columns of A, but they seem to have the wrong -## TODO: sign and the wrong scale, so I won't put that in. - -function F = sgolay (p, n) +function F = sgolay (p, n, m, ts) - if (nargin < 2 || nargin > 3) - usage ("F = sgolay (p, n)"); + if (nargin < 2 || nargin > 4) + usage ("F = sgolay (p, n [, m [, ts]])"); elseif rem(n,2) != 1 error ("sgolay needs an odd filter length n"); elseif p >= n error ("sgolay needs filter length n larger than polynomial order p"); else + if nargin < 3, m = 0; endif + if nargin < 4, ts = 1; endif + if length(m) > 1, error("weight vector unimplemented"); endif k = floor (n/2); F = zeros (n, n); for row = 1:k+1 A = pinv( ( [(1:n)-row]'*ones(1,p+1) ) .^ ( ones(n,1)*[0:p] ) ); - F(row,:) = A(1,:); + F(row,:) = A(1+m,:); end F(k+2:n,:) = F(k:-1:1,n:-1:1); endif - + if m > 1, F = F * ( factorial(m) / (ts^m) ); endif endfunction Index: sgolayfilt.m =================================================================== RCS file: /cvsroot/octave/octave-forge/main/signal/sgolayfilt.m,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- sgolayfilt.m 10 Oct 2001 19:54:49 -0000 1.1.1.1 +++ sgolayfilt.m 23 Dec 2004 11:38:43 -0000 1.2 @@ -14,7 +14,7 @@ ## along with this program; if not, write to the Free Software ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -## y = sgolayfilt (x, p, n) +## y = sgolayfilt (x, p, n [, m [, ts]]) ## Smooth the data in x with a Savitsky-Golay smoothing filter of ## polynomial order p and length n, n odd, n > p. By default, p=3 ## and n=p+2 or n=p+3 if p is even. @@ -36,20 +36,24 @@ ## ## See also: sgolay -## TODO: Doesn't accept "weight vector" as fourth parameter. +## 15 Dec 2004 modified by Pascal Dupuis +## Author: Paul Kienzle + ## TODO: Patch filter.cc so that it accepts matrix arguments -function y = sgolayfilt (x, p, n) +function y = sgolayfilt (x, p, n, m, ts) - if nargin < 1 || nargin > 3 - usage("y = sgolayfilt(x,p,n) or y = sgolayfilt(x,F)"); + if nargin < 1 || nargin > 5 + usage("y = sgolayfilt(x,p,n [, m [, ts]]) or y = sgolayfilt(x,F)"); endif if (nargin < 2) p = 3; endif - if (nargin == 3) - F = sgolay(p, n); + if nargin < 4, m = 0; endif + if nargin < 5, ts = 1; endif + if (nargin >= 3) + F = sgolay(p, n, m, ts); elseif (prod(size(p)) == 1) n = p+3-rem(p,2); F = sgolay(p, n); @@ -73,8 +77,12 @@ ## The last k rows of F are used to filter the last k points ## of the data set based on the last n points of the dataset. ## The remaining data is filtered using the central row of F. + ## As the filter coefficients are used in the reverse order of what + ## seems the logical notation, reverse F(k+1, :) so that antisymmetric + ## sequences are used with the right sign. + k = floor(n/2); - z = filter(F(k+1,:), 1, x); + z = filter(F(k+1,n:-1:1), 1, x); y = [ F(1:k,:)*x(1:n,:) ; z(n:len,:) ; F(k+2:n,:)*x(len-n+1:len,:) ]; if (transpose) y = y.'; endif ```

 [Octave-cvsupdate] octave-forge/main/signal sgolay.m,1.1.1.1,1.2 sgolayfilt.m,1.1.1.1,1.2 From: Paul Kienzle - 2004-12-23 11:38:53 ```Update of /cvsroot/octave/octave-forge/main/signal In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21039 Modified Files: sgolay.m sgolayfilt.m Log Message: [for Pascal Dupuis] allow derivatives Index: sgolay.m =================================================================== RCS file: /cvsroot/octave/octave-forge/main/signal/sgolay.m,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- sgolay.m 10 Oct 2001 19:54:49 -0000 1.1.1.1 +++ sgolay.m 23 Dec 2004 11:38:43 -0000 1.2 @@ -14,9 +14,10 @@ ## along with this program; if not, write to the Free Software ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -## F = sgolay (p, n) +## F = sgolay (p, n [, m [, ts]]) ## Computes the filter coefficients for all Savitzsky-Golay smoothing -## filters of order p for length n (odd). +## filters of order p for length n (odd). m can be used in order to +## get directly the mth derivative. In this case, ts is a scaling factor. ## ## The early rows of F smooth based on future values and later rows ## smooth based on past values, with the middle row using half future @@ -36,30 +37,29 @@ ## ## See also: sgolayfilt +## 15 Dec 2004 modified by Pascal Dupuis ## Author: Paul Kienzle ## Based on smooth.m by E. Farhi -## TODO: Doesn't accept "weight vector" as fourth parameter since -## TODO: Should be able to estimate derivatives using second and -## TODO: subsequent columns of A, but they seem to have the wrong -## TODO: sign and the wrong scale, so I won't put that in. - -function F = sgolay (p, n) +function F = sgolay (p, n, m, ts) - if (nargin < 2 || nargin > 3) - usage ("F = sgolay (p, n)"); + if (nargin < 2 || nargin > 4) + usage ("F = sgolay (p, n [, m [, ts]])"); elseif rem(n,2) != 1 error ("sgolay needs an odd filter length n"); elseif p >= n error ("sgolay needs filter length n larger than polynomial order p"); else + if nargin < 3, m = 0; endif + if nargin < 4, ts = 1; endif + if length(m) > 1, error("weight vector unimplemented"); endif k = floor (n/2); F = zeros (n, n); for row = 1:k+1 A = pinv( ( [(1:n)-row]'*ones(1,p+1) ) .^ ( ones(n,1)*[0:p] ) ); - F(row,:) = A(1,:); + F(row,:) = A(1+m,:); end F(k+2:n,:) = F(k:-1:1,n:-1:1); endif - + if m > 1, F = F * ( factorial(m) / (ts^m) ); endif endfunction Index: sgolayfilt.m =================================================================== RCS file: /cvsroot/octave/octave-forge/main/signal/sgolayfilt.m,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- sgolayfilt.m 10 Oct 2001 19:54:49 -0000 1.1.1.1 +++ sgolayfilt.m 23 Dec 2004 11:38:43 -0000 1.2 @@ -14,7 +14,7 @@ ## along with this program; if not, write to the Free Software ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -## y = sgolayfilt (x, p, n) +## y = sgolayfilt (x, p, n [, m [, ts]]) ## Smooth the data in x with a Savitsky-Golay smoothing filter of ## polynomial order p and length n, n odd, n > p. By default, p=3 ## and n=p+2 or n=p+3 if p is even. @@ -36,20 +36,24 @@ ## ## See also: sgolay -## TODO: Doesn't accept "weight vector" as fourth parameter. +## 15 Dec 2004 modified by Pascal Dupuis +## Author: Paul Kienzle + ## TODO: Patch filter.cc so that it accepts matrix arguments -function y = sgolayfilt (x, p, n) +function y = sgolayfilt (x, p, n, m, ts) - if nargin < 1 || nargin > 3 - usage("y = sgolayfilt(x,p,n) or y = sgolayfilt(x,F)"); + if nargin < 1 || nargin > 5 + usage("y = sgolayfilt(x,p,n [, m [, ts]]) or y = sgolayfilt(x,F)"); endif if (nargin < 2) p = 3; endif - if (nargin == 3) - F = sgolay(p, n); + if nargin < 4, m = 0; endif + if nargin < 5, ts = 1; endif + if (nargin >= 3) + F = sgolay(p, n, m, ts); elseif (prod(size(p)) == 1) n = p+3-rem(p,2); F = sgolay(p, n); @@ -73,8 +77,12 @@ ## The last k rows of F are used to filter the last k points ## of the data set based on the last n points of the dataset. ## The remaining data is filtered using the central row of F. + ## As the filter coefficients are used in the reverse order of what + ## seems the logical notation, reverse F(k+1, :) so that antisymmetric + ## sequences are used with the right sign. + k = floor(n/2); - z = filter(F(k+1,:), 1, x); + z = filter(F(k+1,n:-1:1), 1, x); y = [ F(1:k,:)*x(1:n,:) ; z(n:len,:) ; F(k+2:n,:)*x(len-n+1:len,:) ]; if (transpose) y = y.'; endif ```