Add Standard Deviation calculation to smooth node

This commit is contained in:
Dave Conway-Jones 2015-10-11 17:47:08 +01:00
parent 5316ff715c
commit 5d4a255876
4 changed files with 34 additions and 10 deletions

View File

@ -20,7 +20,8 @@
<select id="node-input-action" style="width:60%; margin-right:5px;">
<option value="max">Return the maximum value seen</option>
<option value="min">Return the minimum value seen</option>
<option value="mean">Return the mean value seen</option>
<option value="mean">Return the mean value</option>
<option value="sd">Return the standard deviation</option>
<option value="low">Perform low pass filter</option>
<option value="high">Perform high pass filter</option>
</select>

View File

@ -25,6 +25,7 @@ module.exports = function(RED) {
var node = this;
var a = [];
var tot = 0;
var tot2 = 0;
var pop = 0;
var old = null;
@ -51,6 +52,14 @@ module.exports = function(RED) {
tot = tot + n - pop;
msg.payload = tot / a.length;
}
if (node.action === "sd") {
tot = tot + n - pop;
tot2 = tot2 + (n*n) - (pop * pop);
if (a.length > 1) {
msg.payload = Math.sqrt((a.length * tot2 - tot * tot)/(a.length * (a.length - 1)));
}
else { msg.payload = 0; }
}
}
if (node.round) { msg.payload = Math.round(msg.payload); }
node.send(msg);

View File

@ -1,12 +1,21 @@
node-red-node-smooth
====================
A <a href="http://nodered.org" target="_new">Node-RED</a> node that provides several simple smoothing algorithms for incoming data values.
A <a href="http://nodered.org" target="_new">Node-RED</a> node that provides
several simple smoothing algorithms for incoming data values. These include
- Minimum
- Maximum
- Mean
- Standard Deviation
- High Pass Smoothing
- Loww Pass Smoothing
Install
-------
Run the following command in the root directory of your Node-RED install
Run the following command in the root directory of your Node-RED install. This
is normally `~/.node-red`
npm install node-red-node-smooth
@ -14,11 +23,16 @@ Run the following command in the root directory of your Node-RED install
Usage
-----
A simple node to provide various functions across several previous values, including max, min, mean, high and low pass filters.
A simple node to provide various functions across several previous values,
including max, min, mean, standard deviation, high and low pass filters.
Max, Min and Mean work over a specified number of previous values.
Max, Min, Mean and Standard Deviation work over a rolling window, based on a
specified number of previous values.
The High and Low pass filters use a smoothing factor. The higher the number the more the smoothing. E.g. a value of 10 is similar to an &alpha; of 0.1. It is analogous to an RC time constant - but there is no time component to this as the code is based on events arriving.
The High and Low pass filters use a smoothing factor. The higher the number
the more the smoothing. E.g. a value of 10 is similar to an &alpha; of 0.1.
It is analogous to an RC time constant - but there is no time component to
this as the code is based on events arriving.
**Note:** This only operates on **numbers**. Anything else will try to be made into a number and rejected if that fails.
**Note:** This node only operates on **numbers**. Anything else will try to be
made into a number and rejected if that fails.

View File

@ -1,6 +1,6 @@
{
"name" : "node-red-node-smooth",
"version" : "0.0.4",
"version" : "0.0.5",
"description" : "A Node-RED node that provides several simple smoothing algorithms for incoming data values.",
"dependencies" : {
},
@ -9,7 +9,7 @@
"url":"https://github.com/node-red/node-red-nodes/tree/master/analysis/smooth"
},
"license": "Apache-2.0",
"keywords": [ "node-red", "smooth", "average" ],
"keywords": [ "node-red", "smooth", "average", "standard deviation" ],
"node-red" : {
"nodes" : {
"smooth": "17-smooth.js"