how to make fft ignore phase shift when only interested in magnitude

I have a signal that consists of a sine wave, on which I apply a rectangular window and then an FFT. I'm only interested in the magnitude of the sine wave, and I want it to stay the same even if the signal shifts a few samples to the right relative to the window (of course assuming the sine wave has the same amplitude from top to bottom). Is this possible and how can this be done best? The application is a kind of pitch detector where I have to detect a small group of different pitches.

• Pitch detection algorithms (cepstrum, YAAPT, RAPT, harmonic product, weighted autocorrelation, etc.,) usually don't require exact magnitudes independent of phase. – hotpaw2 Jan 15 '14 at 9:06

The absolute magnitude of the DFT result will be independent of the phase shift. Each DFT bin will give you a complex number of the form $A \ e^{j \ \theta}$. Circularly shifting your tone will only affect $\theta$. If you take the absolute magnitude, you will end up with $|A|$, all the while ignoring the phase.