The answer i give is probably partly help full. What you can do is when you have a pre stored STD and MEAN(N samples long). While running the real time proces update the stored MEAN. Create an array of you mean value. During the loop add every cycle a sample to your array and remove the oldest one. You create a kind of circular pattern. After N samples your MEAN is only the MEAN from your data. Do the same with the STD. Maybe you can create a different MEAN and STD from different types of data so the error is less worse Good Luck