SciPy提供啁啾功能,以生成逐渐改变频率的信号。如何生成其中一个以某个频率停止并继续该频率的信号?
我尝试使用以下内容执行此操作,但唧唧声似乎超过了f1
限制,并且它创建了一个波动过渡到最终f1
解决方案
import numpy as np
from scipy.io import wavfile
samplerate = 44100
length = 5
chirplength = 3
f0 = 440
f1 = 880
signal = np.arange(chirplength*samplerate)/(chirplength*samplerate)
signal = np.interp(signal, [0, 1], [f0, f1])
signal = np.append(signal, np.repeat(f1, (length-chirplength)*samplerate))
signal = np.sin(signal * 2 * np.pi * np.arange(length*samplerate)/samplerate)
signal = np.float32(signal)
wavfile.write("audio.wav", samplerate, signal)
答案 0 :(得分:3)
你试图通过乘以显然不会起作用的斜坡进行整合。
尝试替换
signal = np.sin(signal * 2 * np.pi * np.arange(length*samplerate)/samplerate)
与
signal = np.sin(signal.cumsum() * 2 * np.pi / samplerate)