Flexible Algorithm for Frequency Tone Detection