我试图制造类型的罪恶波
f(x) = A*sin(2*pi*f*x + phi)
其中A是幅度,f是频率,phi是相位角。我知道这样绘制简单的sin曲线:
def plot(self):
Amplitude = 1.5
Frequency = 0.5
Phase = 2.6
ax = self.figure.add_subplot(111)
X = np.linspace(-np.pi, np.pi, 256,endpoint=True)
S = np.sin(X)
ax.hold(True)
ax.plot(X, S, color="blue", linewidth=1.0, linestyle="-")
xlim(0.0,2.0)
xticks(np.linspace(0,2,5,endpoint=True))
ylim(-1.5,1.5)
yticks(np.linspace(-1.5,1.5,7,endpoint=True))
self.canvas.draw()
我使用QtGui绘制它。请帮我找到正确的方法来绘制正弦波。
我知道我需要修改这两行:
X = np.linspace(-np.pi, np.pi, 256,endpoint=True)
S = np.sin(X)
我的尝试:
def plot(self):
Amplitude = 1.5
Frequency = 0.5
Phase = 2.6
fs = 44100
T = np.arange(-0.002, .002, 1.0/fs)
ax = self.figure.add_subplot(111)
X = Amplitude*np.sin(2*np.pi*Frequency*T + Phase)
ax.hold(True)
ax.plot(T, X, color="blue", linewidth=1.0, linestyle="-")
xlim(0.0,2.0)
xticks(np.linspace(0,2,5,endpoint=True))
ylim(-1.5,1.5)
yticks(np.linspace(-1.5,1.5,7,endpoint=True))
self.canvas.draw()
但现在没有任何东西显示为正弦波。请帮我找错。
沿X轴,它位于0到2之间,如0,0.5,1.0,1.5,2.0
沿Y轴,它从-1.5到1.5,如-1.5,-1.0,-0.5,0.0,0.5,1.0,1.5