# 傅立葉轉換（一）

``````import numpy as np
import matplotlib.pyplot as plt

freq = 10         # 頻率
stop = .25        # 取樣範圍為 0 ~ stop
sample_rate = 800 # 取樣率，單位 x 取樣幾次

x = np.linspace(0, stop, int(stop * sample_rate), endpoint = False)
y = np.sin(freq * 2 * np.pi * x)

plt.plot(x, y)
plt.show()
``````

``````import numpy as np
import matplotlib.pyplot as plt

freq = 10         # 頻率
stop = .25        # 取樣範圍為 0 ~ stop
sample_rate = 800 # 取樣率，單位 x 取樣幾次

x = np.linspace(0, stop, int(stop * sample_rate), endpoint = False)
y1 = np.sin(freq * 2 * np.pi * x)
y2 = np.sin(3 * freq * 2 * np.pi * x) / 3

plt.plot(x, y1)
plt.plot(x, y2)
plt.plot(x, y1 + y2)
plt.show()

plt.plot(x, y)
plt.show()
``````

``````import numpy as np
import matplotlib.pyplot as plt

freq = 10         # 頻率
stop = .25        # 取樣範圍為 0 ~ stop
sample_rate = 800 # 取樣率，單位 x 取樣幾次

x = np.linspace(0, stop, int(stop * sample_rate), endpoint = False)
y1 = np.sin(freq * 2 * np.pi * x)
y2 = np.sin(3 * freq * 2 * np.pi * x) / 3
y3 = np.sin(5 * freq * 2 * np.pi * x) / 5

plt.plot(x, y1 + y2 + y3)
plt.show()
``````

``````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()
``````

``````import numpy as np
import matplotlib.pyplot as plt

freq = 10         # 頻率
stop = .25        # 取樣範圍為 0 ~ stop
sample_rate = 800 # 取樣率，單位 x 取樣幾次

x = np.linspace(0, stop, int(stop * sample_rate), endpoint = False)

z1 = np.sin(freq * 2 * np.pi * x)          # 頻率 10
z2 = np.sin(3 * freq * 2 * np.pi * x) / 2  # 頻率 30
z3 = np.sin(4 * freq * 2 * np.pi * x) / 5  # 頻率 40
z4 = np.sin(8 * freq * 2 * np.pi * x) / 3  # 頻率 80
zero = np.zeros(z1.size)

ax = plt.axes(projection='3d')

ax.plot(x, zero, z1 + z2 + z3 + z4)

ax.plot(x, (zero + freq), z1)
ax.plot(x, (zero + 3 * freq), z2)
ax.plot(x, (zero + 4 * freq), z3)
ax.plot(x, (zero + 8 * freq), z4)

plt.show()
``````

`x` 代表著時間，一段時間內的聲音波形，是隨著時間而變化的，然而就分解後的弦波來看，有四種頻率的波，無論時間再怎麼變化，這四個頻率的值是不變的，若這四個波以頻率為 x 軸，振幅為 y 軸，畫出來的圖會是：