Pattern recognition based on episodes and DTW