Last active
May 17, 2021 03:06
-
-
Save JustinSDK/901f850ff4988a86e055370a0bc6e30f to your computer and use it in GitHub Desktop.
弦波疊加
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
freq = 10 # 頻率 | |
stop = .25 # 取樣範圍為 0 ~ stop | |
sample_rate = 800 # 取樣率,單位 x 取樣幾次 | |
n = 1000 # 疊加的波數 | |
x = np.linspace(0, stop, int(stop * sample_rate), endpoint = False) | |
i = np.arange(1, 2 * n, 2).reshape((n, 1)) | |
y = (np.sin(i * freq * 2 * np.pi * x) / i).sum(axis = 0) | |
plt.plot(x, y) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment