Good method for keeping track of data variance

I'm coding an arduino relay controller for a refrigerator that keeps track of the temperature. Currently, I take a temperature measurement every 10 seconds, add them all up, and save an average every 15 minutes to EEPROM (after squashing the average temp to -27 to 100 degrees C, with 1 bit for half degrees). I can then press a button to dump the data stored in EEPROM to serial using a program that disables the DST signal when establishing a serial connection so it doesn't reset the counter of where in EEPROM it is.While testing this setup on a peltier cooler sitting over the temp sensor, I noticed that while the average was pretty close to my target temp (and this was taking a sample every minute instead of 10 seconds, and restricted to only changing the relay up to once every 10 minutes for compressor safety) but while reading the serial I noticed the temps varied wildly.

What I want to know is what method one might recommend to keep track of how much variance is in the data? Keep in mind that I don't want to write another byte to EEPROM every 15 minutes because it would cut down my time before data dumps to 5 days instead of 10, and also cut the life expectancy of the EEPROM in half (total number of writes being ~100,000). I'm thinking about maybe keeping the values in an array, calculate variance every 15 minutes and add that to a variance counter. Then when I do the data dump divide the variance counter by the number of data points. Only issue with this is that taking 1 reading every 10 seconds for 15 minutes is 90 floating point numbers (about 360B of memory).

Suggestions? I know I could buy more hardware for bigger space (an SD card shield would be nice or an android phone from craig's list to connect via serial) but I'm curious what I can do with my current setup.

A little algebra suggests to me that all you need to calculate the variance and average is the number of samples, the sum of the samples, and the sum of the squares of the samples. So you just need one more number to keep track of the running total of the sum of the squares of the samples.

Alternatively, I haven't used it myself, but according to the documentation you should be able to use the flash memory to store your data points using PROGMEM (PROGMEM - Arduino Reference).

Alternatively, I haven't used it myself, but according to the documentation you should be able to use the flash memory to store your data points using PROGMEM (http://www.arduino.cc/en/Reference/PROGMEM).

You'll notice the absence of a "write" method in the PROGMEM documentation.

It isn't absolutely impossible, but unless you're up to rewriting the bootloader, it isn't a task for a beginner.

Wow. That reference page is long and detailed, but it entirely fails to mention that PROGMEM variables are effectively static.

chrisribe:
A little algebra suggests to me that all you need to calculate the variance and average is the number of samples, the sum of the samples, and the sum of the squares of the samples. So you just need one more number to keep track of the running total of the sum of the squares of the samples.

See this just proves it has been far too long since I've coded or done any statistics. Should have known this, thanks :slight_smile:

but it entirely fails to mention that PROGMEM variables are effectively static

I suspect the PROGMEM qualifier is meant as something of a hint.

So here is the math I plan on doing. Since I don't know the average for the entire data set until the end, I'll use the expected value of what I set the fridge to (which is closer to what I want anyway).

Something like this:

float variance_counter=0

...

    currentTempFerm=sensors.getTempCByIndex(FERM_INDEX);
    variance_counter+=(currentTempFerm - FERM_TEMP)*(currentTempFerm - FERM_TEMP);
...
      if(digitalRead(SERIAL_DUMP_PIN)==HIGH){
        Serial.print("Data variance is ");
        Serial.print(variance_counter/(eepromAddress*90+i));
        // i is my counter in the for loop that does the measurements 90 times
        // eepromAddress is the next address to be written starting from 0
        Serial.print(" from ");
        Serial.println(FERM_TEMP);
        Serial.println("DUMPING DATA");