A method and a device for selecting a function which is implemented at a terminal of the device. This environment makes significant use of context, prior information, domain knowledge, and user specific profile data to achieve a natural environment for one or more users making queries or commands in multiple domains. The end result enables the indexing of very large input strings and at the same time maintain a bounded working set size and a fixed memory footprint. The result of the minimization algorithm identifies the amplitude and frequency of a tone of the multi-tone signal with appreciable degree of accuracy.