Remove noise spikes from an event data stream

This flow filters out short noise spikes from a regularly spaced stream of data points.

This arose from the need to reliably identify an "appliance on" event in a stream of electricity usage numbers coming from a #CurrentCost energy monitor, published over #MQTT.

A data point arrives roughly every 6 seconds. An individual appliance monitor (IAM) sends out 0 when the appliance is off, and the watts it's consuming, when it's on (100 in this example).

Occasionally you get a noisy sample - a single non-zero value which can be mistaken for the appliance turning on, if you're looking for the "rising edge".

Sample data: 0 0 0 80 0 0 0 100 100 100 100 100 ... The "80" is the noise sample that could easily be mistaken for the appliance turning on, which actually happens 4 samples later.

The flow uses two features of the trigger node to ignore the single sample spike. First, on arrival of a message, do nothing for a guard period before you pass it on. That period should be at least the interval between readings (6 sec in this case), or more if you want to be "really sure" the appliance is on. Second, if during the guard time, the signal returns to 0, we use the reset function of the node to ensure that nothing gets propagated to the next node.

This effectively filters the noise glitches out of the signal.

[{"id":"cc0ee793.910238","type":"inject","z":"dab4790.2f8c008","name":"go","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"x":110,"y":60,"wires":[["d3fd1b78.24af88"]]},{"id":"d3fd1b78.24af88","type":"function","z":"dab4790.2f8c008","name":"signal","func":"var signal = [0,0,0,100,0,0,0,100,100,100,100,100];\n\nfor (var i in signal)\n{\n    node.send({payload:signal[i]})\n}\n","outputs":1,"noerr":0,"x":250,"y":60,"wires":[["54adc2e9.0bd9cc"]]},{"id":"54adc2e9.0bd9cc","type":"delay","z":"dab4790.2f8c008","name":"","pauseType":"rate","timeout":"5","timeoutUnits":"seconds","rate":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":410,"y":60,"wires":[["effd0e01.18427"]]},{"id":"effd0e01.18427","type":"trigger","z":"dab4790.2f8c008","op1":"1","op2":"0","op1type":"nul","op2type":"pay","duration":"2","extend":false,"units":"s","reset":"0","name":"","x":580,"y":60,"wires":[["b9678c91.7aef18"]]},{"id":"b9678c91.7aef18","type":"debug","z":"dab4790.2f8c008","name":"","active":true,"console":"false","complete":"false","x":750,"y":60,"wires":[]}]
andysc

Flow Info

created 1 year, 3 months ago

Node Types

Core
  • debug (x1)
  • delay (x1)
  • function (x1)
  • inject (x1)
  • trigger (x1)

Tags

  • #IoT
  • #CurrentCost
  • signal
  • spike
  • glitch
Copy this flow JSON to your clipboard and then import into Node-RED using the Import From > Clipboard (Ctrl-I) menu option