# Find reappearing pattern in the signal

I am working with a signal that describes energy consumption in some house as a function of time and I am trying to find time intervals that correspond to some particular type of dish washer.

1. It has 4 heating pulses.
2. Each pulse has amplitude around 2000 and lasts for at least 120 seconds.
3. Heating pulses are not periodic.
4. If there is such a dish washer it was used at least twice in a given period of time.

Question that I am trying to answer:

1. Was such a dish washer used in this house during given time interval?
2. If yes, I would like to identify all time intervals when this happened.

Example:

csv with whole signal

Let's say I identified one occurrence of this dish washer, like on this figure and trying to find if there are other similar intervals. At the moment I am doing convolution of the whole signal with this dish washer signal and pick time intervals that give high convolution score. Problem is that signal is additive and if person is using other appliances at the same time I may get high score when there is no dish washer there and low score when it is.

• I suggest the book "adaptive filtering and change detection_gustafsson" for excellent examples for this kind of detection problems Commented Dec 18, 2015 at 0:31

Vladimir: You're trying to detect a certain sample pattern (a certain sequence of sample values) within a longer discrete sequence of input samples. This sounds liked a "matched filter" problem to me. If the pattern of samples you're trying to detect is the samples in the red shaded region of your diagram then performing convolution seems like a smart thing to try first before you explore more exotic signal detection algorithms. By convolution I mean an implementation where you pass your long input sequence of values through a tapped-delay line FIR filter. But be careful! You must make sure that the coefficients of the tapped-delay line filter are a "flipped in time" (reversed in time order) version of the sequence you're trying to detect.

Assumptions

You know the total duration of the whole washing cycle (or at least you have a good estimation). By this I mean you know that the four pulses have to appear within a certain amount of time, e.g. 2 hours. Let's call this window the acceptance window.

Suggested Solution

Before applying complicated math, why not try something simple and straight forward, such as a simple counting approach? In situations like this, it is very often fruitful to do an exemplary analysis by hand on paper and then think carefully about what you just did.

Here is an idea:

1. Differentiate the signal and do not detect the pulses via a threshold. This eliminates the problem of additivity.

2. Check for a rising edge (start of the heating period). Save the current start time. Check then if there is a falling edge (end of the heating period) after 120 s or more, that is within the acceptance window.

2a. By the same method repeat the edge-based pulse detection three times. Check if the next pulses found are also within the acceptance window that started with the first heating pulse.

3. If you have found four pulses within an acceptance window, mark the period in your signal as a candidate segment and analyze the rest of the signal the same way.

4. You can now go on and check that the amplitudes are above 2000 or so, just to be sure...

You can also experiment with doing the analysis backwards and check whether the found candidate segments overlap in the original and reversed analysis. This might help, if there are other signal sources that also produce pulses like the ones you expect...