Index: trunk/psLib/src/math/psVectorSmooth.c
===================================================================
--- trunk/psLib/src/math/psVectorSmooth.c	(revision 10999)
+++ trunk/psLib/src/math/psVectorSmooth.c	(revision 13918)
@@ -13,7 +13,8 @@
 #include "psLogMsg.h"
 #include "psVector.h"
+#include "psAssert.h"
+#include "psConstants.h"
+
 #include "psVectorSmooth.h"
-#include "psAssert.h"
-
 
 psVector *psVectorSmooth(psVector *output,
@@ -106,2 +107,54 @@
     return output;
 }
+
+
+
+psVector *psVectorBoxcar(psVector *output,
+                         const psVector *input,
+                         int size
+                        )
+{
+    PS_ASSERT_VECTOR_NON_NULL(input, NULL);
+    PS_ASSERT_INT_POSITIVE(size, NULL);
+
+    long num = input->n;                // Number of elements
+    output = psVectorRecycle(output, num, input->type.type);
+    psVector *nums = psVectorAlloc(num, PS_TYPE_U32); // Number of elements in each bin
+    psU32 *numsData = nums->data.U32;   // Dereferenced version
+
+    psVectorInit(output, 0.0);
+    psVectorInit(nums, 0);
+
+
+    #define VECTOR_BOXCAR_CASE(TYPE) \
+  case PS_TYPE_##TYPE: { \
+      /* Dereference data */ \
+      ps##TYPE *outputData = output->data.TYPE; \
+      ps##TYPE *inputData = input->data.TYPE; \
+      /* Smooth the vector */ \
+      for (long i = 0; i < num; i++) { \
+          for (long j = PS_MAX(0, i - size); j < PS_MIN(num, i + size + 1); j++) { \
+              outputData[j] += inputData[i]; \
+              numsData[j]++; \
+          } \
+      } \
+      /* Normalisation */ \
+      for (long i = 0; i < num; i++) { \
+          outputData[i] /= numsData[i]; \
+      } \
+  }
+
+    switch (input->type.type) {
+        VECTOR_BOXCAR_CASE(F32);
+        VECTOR_BOXCAR_CASE(F64);
+    default: {
+            char* typeStr;
+            PS_TYPE_NAME(typeStr, input->type.type);
+            psError(PS_ERR_BAD_PARAMETER_TYPE, true, "Type %s is not valid.", typeStr);
+            psFree(nums);
+            return NULL;
+        }
+    }
+    psFree(nums);
+    return output;
+}
