Pattern detector