def HeterodynWithF0Track(x, tf0, f0, sr=1,
nwind=1024, nhop=512,
windfunc=np.blackman):
'''
Calculates the amplitude near frequency f0 in x
(f0 is time-varying, values given at tf0
nwind should be at least 3 periods if the signal
is periodic.
'''
valid_idx = np.logical_not(np.isnan(f0))
tx = np.arange(len(x))/float(sr)
f0s = np.interp(tx, tf0[valid_idx], f0[valid_idx])
phs = np.cumsum(2*np.pi*f0s/sr)
sinsig = np.exp(1j*phs)
hamp, t = FuncWind(np.sum, x*sinsig, power=1, sr=sr,
nwind=nwind, nhop=nhop,
windfunc=windfunc)
return np.array(hamp)*2, np.array(t)
评论列表
文章目录