# Zero phase in IFFT

I'm trying to synthesise a sine waveform and I'm noticing that if I perform the IFFT with the Sine aligned to a bin frequency the phase is zeroed, however if I tune the sine off of the bin frequency the phase is no longer zeroed even if I start the waveform at -90.

What gives? how do I compensate for this. I've tried to minus the delta (frequency - binFrequency) but this doesn't seem to work. I accept it could be my calculation is incorrect but I'm hoping someone can explain how I zero phase this sine?

• Can you provide an example? Jul 24 '15 at 11:40
• Hi Jason, basically I'm trying to synthesise waveforms per Hal Chamberlins book "Musical Applications of Microprocessors". I am successfully doing this but I am noticing an advance in phase when I tune the waveform in the frequency domain to a non bin aligned frequency. I hope this clarifies. Jul 24 '15 at 22:31

The cosine and sine components, or the real and imaginary components of a complex DFT, can also be thought of as the even and odd decomposition of a waveform. For a waveform to have pure sine components (no added phase due to a non-zero cosine components), the waveform must be purely odd, thus has to be anti-symmetric around the center of the DFT/FFT window. And only a sine wave with a phase of zero or pi at the center of a window is a purely anti-symmetric sinusoid in that window for any frequency.

So to create your sine wave with a DFT phase of pi/2, you need to start your sine wave with a phase of zero or pi at the center (N/2) of your vector of N=1024, not zero or pi or pi/2 at the left end. This guarantees that it is anti-symmetric for any frequency (not just DFT/FFT bin-center frequencies).

Note that pure sinusoids that are not exactly integer periodic in aperture will have a discontinuity between the left and right ends of the vector or DFT window (as well as have a non-zero magnitude in multiple DFT result bins). That's why you can't start arbitrary frequency sinusoidal synthesis with a phase of zero or +-pi/2 at either end if you want a guaranteed DFT phase of +-pi/2.

• Thanks for the response hotpaw2. WRT paragraph 2. Do you mean in the time domain? Is there a way to calculate this in the frequency domain? Jul 24 '15 at 22:27
• I think I've figured it out on paper. basically in the frequency domain I am working from a know start phase SP. The calculation to zero centre this in the frequency domain would be to calculate the phase at N/2 based on the startphase (SP). this represents the delta of the phase required to centre it so subtract that from the start phase. ? so SP = (SP - delta) + 2pif/fs is this reasonable? Jul 24 '15 at 22:48
• oops sorry should be SP = (SP - delta) + 2pif/N Jul 24 '15 at 22:50
• Thanks for that description hotpaw2. it enabled me to visualise what I had to do. I'm not that great with mathematic notation. Jul 24 '15 at 23:16
• sorry for the post 'noise'. the calculation i came up with to zero centre a sine wave is 1. Calculate the radian increment (2 × PI()× freq) ÷ samplerate then 2. wind it back from the N/2 (radianincrement × halfFFTSize × −1).. This results in 0 phase at the middle of the frame or N/2. Thanks again hotpaw2 Jul 25 '15 at 7:07

Mathematically the FFT is a flavor of the Discrete Fourier Series (DFS) sometimes also called Discrete Time Fourier Transform (which is not a great name for it)

Both domains (time & frequency) are discretized over a finite interval, N. A time vector of N=1024 points will give a frequency vector of 1024 frequencies. It you sample it in one domain, you automatically imply that it's periodic with N in the other domain. That's the way the math works.

A sine wave that aligns with an FFT bin has a period that is an integer fraction of N. If you periodically repeat this time vector, it stays a sign wave. You could say it has the "same phase" at the beginning and the end of the time vector.

A sine wave that's not aligned, that's not the case. The phase is different at both ends and if you periodically repeat this you don't get a sine wave, but sine wave segments that are sliced together with a discontinuity every N samples. Such a signal contains multiple frequencies each with its own phase and it doesn't make sense to assign a single phase value to it.

• Hi Hilmar, and thanks for the explanation. My understanding is that you can create non bin aligned sine waves but you must overlap and add them to smooth out these discontinuities. I'm synthesising waveforms per Hal Chamberlins book "Musical Applications of Microprocessors" and while I'm successfully synthesising Sine waves a various frequencies I'm noticing the phase of the synthesised waveform doesn't always start at 0. This is having an adverse effect when I try and synthesise more complex fourier series waveforms such as sawtooth. Jul 24 '15 at 22:37