# Best algorithm for classifying time series motor data

I am working on a machine control project. We can measure the motor's current during operation. Sample data from two motors performing an operation successfully is below. The red trace shows the current from one motor, the blue trace the current from another. I'd like to try and come up with an algorithm for identifying problems with machine behavior. Problems could be excessively high motor current, near zero motor current, current increasing at the end of the operation, a shorter time series than normal, anything in general which doesn't look like a typical operation below. Can anyone suggest a good algorithm for achieving this? The only one I'm familiar with is a neural network. I have put an Excel file of actual data at motor currents

## migrated from stackoverflow.comSep 26 '11 at 7:36

This question came from our site for professional and enthusiast programmers.

• Probably more appropriate for the statistics SE site, as this involves anomaly detection and statistical modeling of a time series. Survival analysis may play a role, though it's not clear from the question. – Iterator Sep 25 '11 at 23:59
• Could you post an image of a "problem"? One idea would be to calculate the distance between an "ideal operation" (like the red line) and the "actual operation" (the blue line). If any point is too far from the "ideal operation" flag it as a problem. – Zach Sep 26 '11 at 14:42
• +1 This is a key idea: use application-specific knowledge to characterize the behavior. It will be far more pertinent and powerful than any purely statistical technique possibly can be. Statistics can then offer ways to compare the data to the "baseline" or ideal series. – whuber Sep 26 '11 at 16:14
• This idea of using a theoretical or ideal can easily be incorporated as a predictor/cause/right-hand side support series in a Transfer Function model which will then yield the change point detection information I described in my answer. – IrishStat Sep 26 '11 at 22:44
• @Irish I think it's not that simple. There is a characteristic shape to the current consumption: an initial rapid spike, a slower (exponential?) decline, a long region of (hopefully) stable current, followed by the final drop-off (which assumes a characteristic shape) at the end. Details will vary, but distinguishing normal variation from "bad" variation is key. Of concern are things like the relative height of the initial spike and the time taken to level off. Remember, the objective is to identify problems and some of those may be subtler than standard analyses will show. – whuber Sep 27 '11 at 15:00

## 3 Answers

My approach is to form an ARIMA Model for the data and then to employ various "change-point detection schemes" in order to provide early warning about unexpected "things". These schemes would include

1. detecting the presence/onset of Pulses/Level Shifts/Local Time Trends i.e. changes in the mean of the errors over time
2. detecting the presence/onset of changes in parameters over time
3. detecting the presence/onset of changes in variance of residuals over time

If you wish to actually post one of your series we could actually show you this kind of analysis which can "push out" the idea that things are changing or have changed significantly.

Hidden Markov Model

One of the best approaches to modeling time series data is a Hidden Markov Model (HMM). You can either make a single model of your know non-problem state, separate models of each of your known problem states or, if you have sufficient data, a single composite model of all of your known problem states. A good open source library is the Hidden Markov Model Toolbox for Matlab.

http://www.cs.ubc.ca/~murphyk/Software/HMM/hmm.html

Kalman Filter

Another approach that is a little more involved is a Kalman Filter. This approach is especially useful if your data has a lot of noise. A good open source library is the Kalman Filter Toolbox for Matlab.

http://www.cs.ubc.ca/~murphyk/Software/Kalman/kalman.html

Bayesian Models

Both of these approaches are considered Bayesian Models. A good open source library is the Bayes Net Toolbox for Matlab.

http://code.google.com/p/bnt

I hope this works for you.

I would suggest you this link that deals with time series classification: http://www.r-bloggers.com/time-series-analysis-and-mining-with-r/.