Dynamic pattern generation and recognition