【发布时间】:2021-03-05 13:32:36
【问题描述】:
我尝试生成频率随时间变化的正弦波信号。频率是通过在[0.5, 2] 范围内生成一些随机值并在它们之间插入点来随机定义的。
预期的输出信号是一个幅度不变但频率变化的正弦波。
但是有一些较小的颠簸,信号不是“平滑”的正弦波。例如。 x = 200 的句点应该大于x = 10 的句点,但情况正好相反。
有谁知道,这里发生了什么?
import numpy as np
from scipy.interpolate import interp1d
import matplotlib.pyplot as plt
x_samples = np.arange(-100, 3100, 50)
freq_samples = np.random.random(x_samples.shape) * 1.5 + 0.5
x = np.arange(0, 3000, 0.1)
interpolation = interp1d(x_samples, freq_samples, kind='quadratic')
freq = interpolation(x)
y = np.sin(freq * x)
plt.plot(x, y, label="sin(freq(x) * x)")
plt.plot(x, freq, label="freq(x)")
plt.legend()
plt.show()
【问题讨论】:
标签: numpy trigonometry