Skip to content

Instantly share code, notes, and snippets.

@JustinSDK
Last active May 17, 2021 03:06
Show Gist options
  • Save JustinSDK/901f850ff4988a86e055370a0bc6e30f to your computer and use it in GitHub Desktop.
Save JustinSDK/901f850ff4988a86e055370a0bc6e30f to your computer and use it in GitHub Desktop.
弦波疊加
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