我试图从单音、频率中产生(音频)信号,这种信号会随着时间而变化。
我的音调为1d numpy阵列: 频率=[100102103100115113,…,430]
每个值对应N个(例如100个)样本。我知道如何确保它匹配每个模式(N=1)。(它可以在这段时间内生长和下降)
现在我需要把这个频率“曲线”转换成正弦信号。
我知道 scipy.signal.sweep_poly (和类似的)函数,但我不能将频率描述为多项式。
请问,你们能帮我吗,我怎样才能从频率表中生成信号?
非常感谢!
我不确定我百分之百理解你想要什么,但是:
freqs = np.random.uniform(100, 400, (20,)) times = np.cumsum(np.random.uniform(0.01, 0.02, (20,))) # or np.arange(20) / sample_freq if evenly sampled grid, dt = np.linspace(0, times[-1], 10000, retstep=True) signal = np.sin(2*np.pi*dt*np.cumsum(np.interp(grid, times, freqs)))
这在采样时间点之间使用线性插值。其他方法在 scipy.interpolate
scipy.interpolate