From 076d9bb52950b53a9cfc2c70fd0becb5e252d955 Mon Sep 17 00:00:00 2001 From: Heejin Park Date: Mon, 5 Oct 2020 22:23:22 +0900 Subject: [PATCH] =?UTF-8?q?=EB=B3=B5=EC=9E=A1=ED=95=9C=20=EC=8B=A0?= =?UTF-8?q?=ED=98=B8=EA=B0=80=20=EB=8B=A8=EC=88=9C=ED=95=9C=20=EC=97=AC?= =?UTF-8?q?=EB=9F=AC=20=ED=8C=8C=ED=98=95=EC=9C=BC=EB=A1=9C=20=EA=B5=AC?= =?UTF-8?q?=EC=84=B1=EB=90=98=EC=97=88=EB=8B=A4=EB=8A=94=20=EA=B2=83?= =?UTF-8?q?=EC=9D=84=20=EB=B3=B4=EC=97=AC=EC=A3=BC=EB=8A=94=20=EA=B7=B8?= =?UTF-8?q?=EB=A6=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- draw_sum_of_wave.py | 58 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 draw_sum_of_wave.py diff --git a/draw_sum_of_wave.py b/draw_sum_of_wave.py new file mode 100644 index 0000000..4f2fd44 --- /dev/null +++ b/draw_sum_of_wave.py @@ -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 ) \ No newline at end of file