If you want to double the frequency and obtain a square wave, you can do it simply using an XOR gate. If you feed your 20KHz square wave directly into one input and via a resistor/capacitor integrator (to delay it) to the other input you will get a pulse out every time the input waveform changes polarity, ie. at twice the input frequency.
You need a delay of 12.5uS to equal mark/space at 40KHz, so feed through a resistor of 18K0 to the second gate and then a 1nF from gate to ground.