MHz Speed Analog Reading + High Quality 40kHz Square Wave

I need a clean 40khz square wave to power the "sender" transducer. I had just assumed that I could do this by basically "blinking" one of my output pins at this frequency--but I realized earlier today that that didn't work at all. It looks like this might work: Arduino Playground - Timer1 but I still need to try it.

I noticed that some other people were suggested somehow getting the PWM to do this. Regardless, I assume this is a pretty trivial task compared to the high speed analog reading, so what I'm really trying to get a pulse on here is whether there is some reasonable technique I can use to sample an input at that frequency.

The three orders of magnitude I was referring to was from 10kHZ (the fastest stock analog read speed of the Arduino) to ~3MHz (the speed I need to sample my signal at). I guess that's technically closer to two orders of magnitude, to be precise.