problems calculating phase propagation (in C) I'm coding a phase vocoder in C for time-stretching audio signals. The only piece that is currently not working is the phase propagation.


I take overlapping frames from an input signal, apply a window function, and perform FFT.
Then i calculate the phase propagation (the one I'm stuck with)
Finally I perform iFFT and overlap-add the output frames with a different hop size.


If I skip step 2, the phase propagation, the output sound is correctly time-stretched but I can hear a phaser effect. My assumption is that the missing piece will correct this. However when I apply my current implementation the sound is terribly distorted.

I appreciate if anyone can give some good pointers on how the phase correction can be implemented.

It might be too much to ask, but this is my current implementation should you see something weird.

// _prevPhaseX[] = FFT phases from previous frame (n-1) (propagation input)
// _prevPhaseY[] = FFT phases from previous frame (n-1) (propagation output)
// _phase[] has the FFT phase information from current frame
static int first = 1;
if (first)
{
    first = 0;
    for (int k=0; k&lt;half; k++)          // half = window length/2 = number of bins
    {
        _prevPhaseX[k] = _phase[k];
        _prevPhaseY[k] = _phase[k];
    }
}
else
{
    // int length = window length - e.g. 1024 
    // float Ra = analysis hop size - e.g. 256
    // float Rs = synthesis hop size - e.g. 512
    // float PI = PI
    // float DPI = 2*PI
    for (int k=1; k&lt;half; k++)
    {
        // compute Delta Phi(k)
        float phase = _phase[k];
        float omega = DPI*(float)k/(float)length;  // length vs length/2?
        float phasediff = phase - _prevPhaseX[k] - Ra*omega;
        _prevPhaseX[k] = phase;   // Save value for next frame

        // get principal argument
        while (phasediff&gt;PI) phasediff -=DPI;
        while (phasediff&lt;-PI) phasediff +=DPI;

        float freq = omega + (phasediff)/Ra;
        _phase[k] = _prevPhaseY[k] + Rs*freq;
        _prevPhaseY[k] = _phase[k];   // Save value for next frame
    }
} 
// the _phase[] vector (and magnitude[]) goes to IFFT (after conv. to rectangluar)


Thanks!
you don't wanna do this on a bin-by-bin basis.  here's a paper by Miller Puckette that is seminal regarding this issue.  what you want to do is identify specific frequency components (perhaps each lobe in the spectrum would be a specific frequency component) and multiply that entire $n$th lobe by $e^{j \phi_n}$  where $\phi_n = \omega_n \ T_n$  and  $\omega_n$ is the frequency of the $n$th component and $T_n$ is the time adjustment to that component to match its phase to the corresponding component in the previous frame.

each bin gets multiplied by $e^{j \phi_n}$, but for most bins that factor is the same as for an adjacent bin.