In [1]:
from bregman.suite import *

In [2]:
sr=48000.
n=128
f0=sr/n
k=4
x1 = sinusoid(f0=f0*(k), num_points=sr, sr=sr) # A sine wave
x2 = sinusoid(f0=f0*(k+10+.25), num_points=sr, sr=sr) # A sine wave
x = (x1 + x2) / sqrt(2)

In [3]:
F = LinearFrequencySpectrum(x, nfft=n, wfft=n, nhop=n, sample_rate=sr) # Congruent STFT analysis
F.feature_plot()



In [4]:
U = array(F._phase_map())
plot(F.X[k-1:k+2,:10].T)
grid()
legend(['k-1','k','k+1'],loc=4)
ylabel('abs(STFT)'); xlabel('Frame Index (hop=%d)'%F.nhop)
title('Magnitude either side of non-zero magnitude channel')
figure()
plot(U[k-1:k+2,:10].T/pi)
grid()
legend(['k-1','k','k+1'],loc=4)
ylabel('angle(STFT) / PI'); xlabel('Frame Index (hop=%d)'%F.nhop)
title('Phase either side of non-zero magnitude channel')


Out[4]:
<matplotlib.text.Text at 0xaf4e4c4c>

Relative Differential Phase

$$d\phi/dt \implies d\phi/dt$$


In [5]:
plot(F.dphi)


Out[5]:
[<matplotlib.lines.Line2D at 0xaf65fa0c>]

In [6]:
F.dphi[-1] - round(F.dphi[-3]/(2*pi))*2*pi


Out[6]:
12.566370614359187

In [7]:
print F.dphi[k]
plot(diff(unwrap(angle(F.STFT[k,:]))))
plot(diff(unwrap(angle(F.STFT[k+10,:]))))
ax = array(axis())
ax[2]=-pi
ax[3]=pi
ax = axis(ax)


25.1327412287

In [7]:


In [ ]: