Matching patterns in time series