summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChandra Pratap2024-08-07 17:54:45 +0530
committerChandra Pratap2024-08-07 17:54:45 +0530
commit2d44554c3f4070fc447a6db3da204f7b7e9554d7 (patch)
tree461c32db659cd10117986a9a5ca5b0e0cc9d5c07
parent12f72c647026be2fc8e28a04ad0130fb20154e7e (diff)
downloadFOSSEE-Signal-Processing-Toolbox-2d44554c3f4070fc447a6db3da204f7b7e9554d7.tar.gz
FOSSEE-Signal-Processing-Toolbox-2d44554c3f4070fc447a6db3da204f7b7e9554d7.tar.bz2
FOSSEE-Signal-Processing-Toolbox-2d44554c3f4070fc447a6db3da204f7b7e9554d7.zip
Implement spencer.sci in Scilab
-rw-r--r--macros/spencer.sci50
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));