Robust phase extraction of STFT bins
like hotpaw, unless you know something prior about the signal (like it's periodic with period $P$), i'm thinking that you're windowing in the neighborhood of samples $m \le n &lt; m+N$.

STFT: $$ X_m[k] \triangleq  (-1)^k \, e^{-j\pi k/N} \ \sum\limits_{n=0}^{N-1} x[n+m] w[n] \, e^{-j2\pi nk/N} $$

$w[n]$ is a decent window centered about $n \approx \tfrac{N-1}{2}$, specifically $$w[n]=w[N-1-n] \ .$$

if $x[n]$ and $w[n]$ are both real, then $X[k]$ is Hermitian symmetric: $X[N-k]=\overline{X[k]}$.  and $X[0]$ must be real.  so the complex angle of $X[0]$ is either $0$ or $\pm \pi$ depending on if $X[0]$ is positive or negative.

$$ \arg\{ X[0] \} = \begin{cases}
0       &amp; \text{for } \Re\{X[0]\} \ge 0 \\
\pm \pi &amp; \text{for } \Re\{X[0]\} &lt; 0 \\
\end{cases}$$

because $ \Im\{ X[0] \} = 0 $.

then you can calculate phase increments:

$$\begin{align}
 \arg\{ X[k] \} -  \arg\{ X[k-1] \}  &amp;= \arg\left\{ \frac{X[k]}{X[k-1]} \right\} \\ 
\\
                                     &amp;= \arg\left\{ \frac{X[k]\overline{X[k-1]}}{\Big|X[k-1]\Big|^2} \right\} \\
\\
                                     &amp;= \arg\left\{ X[k]\overline{X[k-1]} \right\} \\
\\
                                     &amp;= \arg\left\{ \big(\Re\{X[k]\}+j\Im\{X[k]\}\big)\big(\Re\{X[k-1]\}-j\Im\{X[k-1]\}\big) \right\} \\
\\
                                     &amp;= \arg\left\{ \Re\{X[k]\} \Re\{X[k-1]\} + \Im\{X[k]\} \Im\{X[k-1]\} + j\big( \Im\{X[k]\} \Re\{X[k-1]\} - \Re\{X[k]\} \Im\{X[k-1]\} \big) \right\} \\
\\
                                     &amp;= \arctan\left(\frac{ \Im\{X[k]\} \Re\{X[k-1]\} - \Re\{X[k]\} \Im\{X[k-1]\}} {\Re\{X[k]\} \Re\{X[k-1]\} + \Im\{X[k]\} \Im\{X[k-1]\}} \right) \\
\end{align}$$

or recursively

$$ \arg\{ X[k] \} = \arg\{ X[k-1] \} + \arctan\left(\tfrac{ \Im\{X[k]\} \Re\{X[k-1]\} - \Re\{X[k]\} \Im\{X[k-1]\}} {\Re\{X[k]\} \Re\{X[k-1]\} + \Im\{X[k]\} \Im\{X[k-1]\}} \right) $$

for $ 1 \le k \le \tfrac{N}{2} $.

this is assuming that every little phase increment is smaller in magnitude than $\tfrac{\pi}{2}$.  this is how you deal with unwrapping phase naturally.