def rectdraw(length_sec=1000):
rect = []
for time in range(0, 3000, 1):
if time > 1000 and time < 2000:
rect.append(1.2)
else:
rect.append(0)
plt.figure()
plt.plot(rect)
plt.show()
def rectdraw(a=1, freq=0.005, ph=0, length_sec=1000):
rect = []
for time in range(0, 3000, 1):
if time > 1000 and time < 2000:
rect.append(1.2+(a*np.sin(2*np.pi*freq*time + ph)))
else:
rect.append(0)
plt.figure()
plt.plot(rect)
plt.show()
正弦函数如下所示:
因此,在使用正弦函数时,需要定义振幅、频率和相位。所以,我稍微改变了你的函数,它接受了另外三个参数:
a
(1为默认值)freq
(默认值为0.005)李>ph
(0作为默认值)运行上一个函数会生成以下图形:
相关问题 更多 >
编程相关推荐