Quick Change Detection Algorithm

I register the temperature in the room, storing them in a database. I would like to receive a warning when the temperature suddenly rises. I can’t set fixed values ​​because 18 ° C is acceptable in winter and 25 ° C in summer. But if it jumps from 20 ° C to 25 ° C during, say, 30 minutes and stays the same for 5 minutes (to exclude false testimony), I would like information.

My current idea is to read the samples from the last 30 minutes (A) and the samples from the last 5 minutes (B), calculate the median A and B and check if the difference between them is different than my desired threshold.

Is this the right way to solve this problem or is there a better algorithm? I was looking for a specific one, but most of them seem complicated.

Thanks!

+5
source share
2 answers

Detecting changes in a time series is a well-studied subject, and hundreds, if not thousands, of articles have been written on this subject. As you have seen, many methods are quite advanced, but have proven to be very useful for many use cases. Whichever method you choose, you must evaluate it against real simulated data and optimize its parameters for your use case.

As you need, let me suggest a very simple method, which in many cases turns out to be quite good and very similar to the one you considered.

Basically, you have two problems:

  • Detection of monotonic variation of a sample noise signal
  • Ignoring false readings

First, note that medians are not commonly used to detect trends. For the series (1,2,3,30,35,3,2,1) the medians of 5 consecutive members are (3, 3, 3, 3). Most commonly used averages.

One common trick is to throw out the extreme values ​​before averaging (for example, for each 7 values ​​on average only the average 5). If you expect a lot of false readings - try to take measurements at a faster pace and throw out more extreme values ​​(for example, for each 13 values ​​the average is 9).

In addition, you must throw away the impracticable values ​​and replace them with the last measured value (impracticable means out of range or unphysical rate of change).

Your idea of ​​comparing a short-period measure with a long-period measure is a good idea, and indeed it is usually used (for example, in econometrics).

A quote from Financial Econometric Models — Some Contributions to the Field [Nicolau, 2007]:

Buy and sell signals are generated by two moving average price levels: average average and average average periods. A typical moving average trading rule prescribes to buy (sell) when a short-term moving average crosses a long-period moving average from the bottom (top) (i.e. when the initial time series rises (falls) relatively quickly).

0
source

When you say "suddenly rising," mathematically you are talking about the magnitude of the derivative of the temperature signal.

There is a good algorithm for simultaneously smoothing the signal and calculating its derivative, called the Savitsky-Golay filter. This is explained by examples on Wikipedia, or you can use Matlab to help you generate the required convolution coefficients. When you have the odds, the calculation is very simple.

0
source

Source: https://habr.com/ru/post/1270062/


All Articles