I've been trying to detect defrost cycles using refrigeration data. I have a sensor within the fridge which simulates a product and measures the temperature every 15 minutes. Usually, based on the data, a defrost cycle occurs every 4 hours and lasts about 1:30 hours. I want to be able to detect when a defrost cycle starts and when it ends without losing any data on the way.
What I tried so far:
- Scale the data.
- Find the peaks using a threshold.
- Find the distance between two consecutive peaks.
- Calculate the median between 2 peaks.
- Find the start and the end by comparing the current value to the median, i.e. if the current value is smaller than the median but the next one is bigger, a peak starts. The opposite is valid for the end, if the current value is higher than the median but the next one is smaller, it's the end.
The algorithm works quite good if the data is not noisy. However, using the algorithm for different data sets is not an option in this case. Here is a picture of a sample data:
As you can see, there are some small peaks and valleys which are being detected as false positives and I would like to avoid that. I am looking for an approach which will eliminate the need of a threshold and does not require smoothing the data as I am interested in the data between the cycles. Here is a sample of the data:
c(3.73709, 3.74075, 3.73709, 3.73709, 4.06058, 4.48783, 5.00664,
4.48173, 4.2742, 4.05814, 4.06424, 3.72854, 3.73709, 3.74075,
3.73709, 3.73709, 3.73709, 3.73709, 3.73709, 3.73709, 3.73709,
4.2742, 4.69535, 4.2742, 4.06058, 4.06424, 3.73709, 3.73709,
3.73709, 3.72488, 3.73709, 3.74075, 3.73709, 3.73465, 3.73709,
3.73709, 4.05814, 4.48173, 5.00664, 4.48783, 4.2742, 4.06058,
4.06424, 3.73465, 3.73709, 3.73709, 3.73709, 3.73465, 3.73465,
3.73709, 3.73709, 3.73709, 4.06058, 5.0042, 5.42779, 4.90288,
4.38163, 4.2742, 4.06058, 4.06058, 3.73709, 3.73709, 3.73709,
3.73709, 3.73709, 3.73709, 3.74075, 3.73709, 4.06058, 4.48783,
5.00664, 4.48173, 4.28031, 4.06058, 4.06424, 3.73709, 3.73709,
3.74075, 3.73709, 3.73709, 3.73709, 3.73709, 3.73709, 4.06058,
4.2742, 4.69535, 5.22393, 4.69535, 4.38163, 4.27176, 4.28031,
4.06058, 4.05814, 4.06058, 4.06058, 4.06424, 4.06058, 4.06058,
4.06058, 4.06058, 4.06058, 4.38163, 4.90288, 4.38407, 4.2742,
4.2742, 4.06424, 4.06058, 4.06424, 4.05814, 4.06058, 4.05203,
4.06058, 4.06424, 4.06424, 4.06058, 4.06424, 4.48783, 5.00664,
4.48173, 4.2742, 4.28031, 4.28031, 4.06424, 4.06424, 4.06424,
4.06058, 4.06424, 3.73709, 4.06058, 3.74075, 3.73709, 4.06424,
4.69535, 5.22393, 4.48173, 4.37797, 4.2742, 4.06424, 4.06424,
4.06424, 4.2742, 4.06058, 4.06424, 4.06424, 4.06424, 4.06424,
4.06058, 4.28031, 4.48783, 5.0042, 4.69902, 4.48173, 4.2742,
4.28397, 4.2742, 4.2742, 4.06424, 4.06058, 4.06424, 4.2742, 4.06058,
4.06058, 4.06424, 4.2742, 4.69535, 5.22393, 4.69535, 4.38163,
4.28031, 4.2742, 4.06424, 4.06058, 4.06058, 4.06424, 4.06058,
4.06424, 4.06424, 4.06058, 4.06058, 4.06058, 4.48783, 5.0042,
4.48173, 4.38163, 4.28031, 4.05814, 4.06058, 4.06058, 4.06058,
4.06058, 4.06424, 3.73465, 4.06058, 3.73465, 4.06058, 4.05814,
4.48173, 5.0042, 4.48173, 4.27176, 4.06058, 4.06058, 4.06058,
4.05814, 4.05814, 4.05814, 3.73709, 3.73709, 3.73465, 3.73709,
3.73709, 3.73465, 4.27176, 4.69291, 4.2742, 4.06058, 4.06058,
4.06058, 3.73465, 4.06058, 3.74075, 4.06058, 3.73709, 3.73709,
3.73709, 3.73465, 3.73709, 3.73465, 4.2681, 4.48173, 4.48173,
4.2742, 4.2742, 4.27176, 4.26566, 4.06058, 4.06058, 4.06058,
4.06058, 4.06058, 4.06058, 4.06424, 4.06058, 4.06058, 4.48173,
5.00664, 4.47929, 4.37797, 4.2742, 4.2742, 4.2742, 4.06058, 4.06058,
4.06058, 4.06058, 4.06058, 4.06058, 4.06058, 3.73465, 4.06058,
4.38163, 4.90043, 4.38163, 4.27176, 4.06058, 4.06058, 4.05814,
4.06058, 3.73709, 3.73709, 3.73465, 3.73465, 3.73709, 3.73709,
3.73709, 3.73709, 4.28031, 4.69535, 4.38163, 4.2742, 4.06424,
4.06424, 3.73709, 3.73465, 3.73709, 3.73709, 3.73709)
I read quite a bit of questions here but I am still confused which approach to take. Any kind of suggestions, papers, packages or approaches would be highly appreciated. Thank you very much in advance!
Kind Regards, Boris