diff options
Diffstat (limited to 'macros/spencer.sci')
-rw-r--r-- | macros/spencer.sci | 50 |
1 files changed, 33 insertions, 17 deletions
diff --git a/macros/spencer.sci b/macros/spencer.sci index 63a1b83..1b0f377 100644 --- a/macros/spencer.sci +++ b/macros/spencer.sci @@ -1,21 +1,37 @@ -function y= spencer(x) -//Return Spencer's 15 point moving average of each column of X. -//Calling Sequence -//spencer(X) -//Parameters -//X: Real scalar or vector -//Description -//Return Spencer's 15 point moving average of each column of X. -funcprot(0); +function savg = spencer (x) +//Returns Spencer's 15 point moving average of each column of x. +//Calling Sequence: +//spencer(x) +//Parameters: +//X: Real vector or matrix +//Description: +//Returns Spencer's 15 point moving average of each column of x. -rhs= argn(2); + funcprot(0); + if (nargin() ~= 1) + error("Wrong number of input arguments."); + end + [xr, xc] = size (x); -if(rhs <1 | rhs >1) -error("Wrong number of input arguments"); -end + n = xr; + c = xc; + + if (isvector (x)) + n = length (x); + c = 1; + x = matrix(x, n, 1); + end + + end + w = [-3, -6, -5, 3, 21, 46, 67, 74, 67, 46, 21, 3, -5, -6, -3] / 320; + savg = filter (w, 1, x); + savg = [zeros(7,c); savg(15:n,:); zeros(7,c);]; + savg = matrix(savg, xr, xc); -select(rhs) - case 1 then - y = callOctave("spencer",x); -end endfunction + +//tests: +//assert_checkerror("spencer()", "Wrong number of input arguments."); +//assert_checkerror("spencer(1, 2)", "Wrong number of input arguments."); +//assert_checkequal(spencer(linspace(1, 14, 14)'), zeros(14, 1)); +//assert_checkequal(spencer(linspace(-1, -10, 14)), zeros(1, 14)); |