How to remove a glitch...

Recommended Posts

I'm reading ambient temperature via ModBus once a second via a channel called ambientTemp. The channel does a conversion to Fahrenheit and has a persistence length of 86400 so that I can do statistics on it once a day (min, max, and average).

It turns out I've got a glitch where every couple of days it reads a negative temperature for one reading. So, when I do my daily stats once a day, the minimum temperature shows up as something like -25.

So, I was trying to figure out how to easily fix it. I tried to check the just read temperature and if it was below a set temperature like 40 degrees, replace it with the previously read temperature with code like this:

if (ambientTemp[0] < 40)
	ambientTemp[0] = ambientTemp[1]

But that didn't work.

Do you have an idea how I can easily eliminate a single bad reading that occurs once every couple of days?

Link to comment
Share on other sites

I'm not a fan of removing data under any circumstances. I believe I explain it a little in one of the blog posts. The story I like to tell is of the guys watching ozone at south pole in the early 80's. One group had been watching it for years. Another group came down, observed for a few years and published a paper discovering the ozone hole, making their careers. The first group couldn't understand what had happened so they looked at their acquisition technique and realized they had programmed the system to throw out any value < 50ppb to save disk space. Of course values below 50ppm describe the ozone hole, so they basically threw out all this real data and ended up missing the scientific discovery of their lifetime in that field.

Anyhow, its much better to massage the data post-acquisition, that way you can always go back and look at the raw readings. You can do it with simple boolean math. For example, try this at the command / alert window:

global x = {1,2,3,4}

? min(x)

? min(x + (x < 2) * nan())

You'll see that the first min() yields 1, but the second one yields 2 because the 1 is made into nan (not a number) which isn't used in min/max calcs.

Link to comment
Share on other sites


This topic is now archived and is closed to further replies.