Skip to content

Commit

Permalink
복잡한 신호가 단순한 여러 파형으로 구성되었다는 것을 보여주는 그림
Browse files Browse the repository at this point in the history
  • Loading branch information
rhaos68 committed Oct 5, 2020
1 parent ea0fac3 commit 076d9bb
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions draw_sum_of_wave.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import numpy as np
from matplotlib import pyplot as plt

def draw_sum_of_wave(a0, coeffi, w):
t = np.linspace(0.0, 1.0, 1000) # 1ms 단위. ~1초
n = range(1,len(coeffi)+1) # 1,2,3,...len(coeffi)

y_a0 = a0 * np.ones(len(t))

sin_val = [ab[0] * np.sin(i*w*t) for ab,i in zip(coeffi,n)] #an*sin(nwt)
cos_val = [ab[1] * np.cos(i*w*t) for ab,i in zip(coeffi,n)] #bn*cos(nwt)
yn = [(a0 + s + c) for s,c in zip(sin_val,cos_val)]

y_sum = yn[0]
for y in yn[1:]: y_sum += y

plt.subplot(5,1,1)
plt.plot(t, y_sum)
plt.title(r"$y(t)=a_0 + \sum _{n=0}^{\infty}{a_n \sin n\omega t + b_n \cos n\omega t}$")

plt.subplot(5,1, 2)
plt.plot(t, y_a0)
plt.title("$y(t)=a_0$")

plt.subplot(5, 2, 5)
plt.plot(t, sin_val[0])
plt.title(r"$y(t)=a_1 \sin \omega t$")

plt.subplot(5, 2, 6)
plt.plot(t, cos_val[0])
plt.title(r"$y(t)=b_1 \cos \omega t$")

plt.subplot(5, 2, 7)
plt.plot(t, sin_val[1])
plt.title(r"$y(t)=a_2 \sin \omega t$")

plt.subplot(5, 2, 8)
plt.plot(t, cos_val[1])
plt.title(r"$y(t)=b_2 \cos \omega t$")

plt.subplot(5, 2, 9)
plt.plot(t, sin_val[2])
plt.title(r"$y(t)=a_3 \sin \omega t$")

plt.subplot(5, 2, 10)
plt.plot(t, cos_val[2])
plt.title(r"$y(t)=b_3 \cos \omega t$")

# plt.tight_layout()
plt.show()

a0 = 0.4
coeffi = (
(0.3,0.5), (0.2,0.5), (0.2,0.3), (0.7,0.6),(1.2,0.3), (0.3,0.6),(0.2,0.3), (2.3,0.6),(1.5,1.5),(0.2,0.5),(2.3,0.6),(1.5,1.5),(0.2,0.5)
)
w = 2*np.pi*4

draw_sum_of_wave(a0, coeffi, w )

0 comments on commit 076d9bb

Please sign in to comment.