读取波形文件后,我试图绘制选定数量的样本。我编写了以下代码来实现这一目标:
import numpy as np
import matplotlib.pyplot as plt
from scipy.io.wavfile import read
(fs, x) = read('/home/sk_he/sounds/sample.wav')
M = 501
start_time = 0.2
start_sample = int(start_time * fs)
stop_sample = int(start_time * fs) + M
x1 = x[start_sample:stop_sample]
stop_time = float(stop_sample/fs)
tx1 = np.linspace(start_time, stop_time, M)
plt.plot(tx1, x1)
尽管这很好,但我打算指出从0.2秒到M
采样结束的时间。我还正确地将start
和stop
的值赋予了linspace
。但是该图的第一个值仍为0.0
,而不是0.2
。如何使它从0.2
而不是0.0
开始?