An analog option would use a comparator for a high/low output, send that to the RESET pin (4) of a LM555 timer set up for your 20khz and a whole different set-up for your 50hz.

Mike