The recent discussion on DTMF decoding made me think about a project I had been considering for a while. I did some simulations to verify my math was right and look at filter time constants and the like. You can see the result at http://www.embedinc.com/temp/dtmf.gif. The input is bursts of the DTMF tones 697, 770, and 853 Hz. Each burst and the gaps between the bursts are 50mS long, which is the time you are supposed to be able to detect a DTMF tone within. The blue trace is the square of the magnitude of the detected tone. The algorithm was set up to detect 770Hz, which is the frequency of the center burst. As you can see, this worked very well. The blue trace would have eventually reached 1.0 if the center burst persisted. But clearly the center burst was well detected and the other two were not, even though the frequencies between adjacent tones differ by less than 11%. Below is the core code of the simulation. The complete code contains too many distractions to show here, like CSV file writing and other logistics. for sampn := 0 to nsamp do begin {once for each input sample} t := sampn * sampdt; {make time of this sample} samp := getsamp (t); {get input sample} r := t * freq; {make reference frequency phase} ii := trunc(r); r := r - ii; r := r * pi2; prods := samp * sin(r); {mix by ref freq sine and cosine} prodc := samp * cos(r); filter (filts, prods); {low pass filter mixer results} filter (filtc, prodc); magsq := sqr(filts.val) + sqr(filtc.val); {make square of magnitude} magsq := magsq * 4.0; {normalize} Obviously you wouldn't normalize the result in the PIC, you'd adjust the detection threshold instead. The FILTER subroutine does a two pole low pass filter. Each pole has a filter fraction of 1/128, which means it can be realized inside a PIC with a right shift of 7 bits. The input was sampled and processed every 100uS. ******************************************************************** Embed Inc, Littleton Massachusetts, http://www.embedinc.com/products (978) 742-9014. Gold level PIC consultants since 2000. -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist