以下是示例代码(Python)来实现上述步骤:
- import numpy as np
- import matplotlib.pyplot as plt
- # 生成标准的正弦波
- x = np.linspace(0, 2*np.pi, 1000) # 0到2π之间生成1000个点
- y = np.sin(x)
- # 缩放波形
- y_scaled = 2 * y
- # 平移波形
- y_shifted = y_scaled + 1
- # 取反
- y_negative = -y_shifted
- # 绘制波形
- plt.plot(x, y_shifted, label='Positive Sin Wave')
- plt.plot(x, y_negative, label='Negative Sin Wave')
- plt.xlabel('x')
- plt.ylabel('Amplitude')
- plt.title('Positive and Negative Sin Wave')
- plt.legend()
- plt.grid(True)
- plt.show()
|