%matplotlib inline import matplotlib.pyplot as plt import numpy as np import cmp import math #ここから↑は消さないで下さい # None を数値に置き換えて下さい # 円周率は math.pi です w1=None # 基本角周波数 C0=None # C[0] = 直流成分 # 複素フーリエ係数 C[k] のパラメータをセットしてください # C[-k]のパラメータは自動でセットされます C1_a=None # C[1]の絶対値 C1_phi=None # C[1]の偏角 C2_a=None # C[2]の絶対値 C2_phi=None # C[2]の偏角 C3_a=None # C[3]の絶対値 C3_phi=None # C[3]の偏角 C4_a=None # C[4]の絶対値 C4_phi=None # C[4]の偏角 ########### ここから↓は消さないで下さい t = np.linspace(0, 8, 100) y = C0+2*C1_a*np.cos(1*w1*t+C1_phi)+2*C2_a*np.cos(2*w1*t+C2_phi)+2*C3_a*np.cos(3*w1*t+C3_phi)+2*C4_a*np.cos(4*w1*t+C4_phi) plt.plot(t, y, label="f(t)") plt.show() cmp.init( shape=(9,2), hsize=4.5, axs=( ('t',r'$f_0(t)$',(0,0),1,2), ('c',r'$z_1(t)=C[1]e^{jw_1t}$',(1,0),1,1), ('c',r'$z_{-1}(t)=C[-1]e^{-jw_1t}$',(1,1),1,1), ('t',r'$f_1(t)$',(2,0),1,2), ('c',r'$z_2(t)=C[2]e^{j2w_1t}$',(3,0),1,1), ('c',r'$z_{-2}(t)=C[-2]e^{-j2w_1t}$',(3,1),1,1), ('t',r'$f_2(t)$',(4,0),1,2), ('c',r'$z_3(t)=C[3]e^{j3w_1t}$',(5,0),1,1), ('c',r'$z_{-3}(t)=C[-3]e^{-j3w_1t}$',(5,1),1,1), ('t',r'$f_3(t)$',(6,0),1,2), ('c',r'$z_4(t)=C[4]e^{j4w_1t}$',(7,0),1,1), ('c',r'$z_{-4}(t)=C[-4]e^{-j4w_1t}$',(7,1),1,1), ('t',r'$f_4(t)$',(8,0),1,2), ), cgrid=False, cxlim=(-2.5,2.5), cylim=(-2.5,2.5), tgrid=True, txlim=(-0.1,8.1), tylim=(-4.1,4.1) ) if w1 is None: w1=0 if C1_phi is None: C1_phi = 0 if C2_phi is None: C2_phi = 0 if C3_phi is None: C3_phi = 0 if C4_phi is None: C4_phi = 0 cmp.plot_tsignal('f',lambda t: C0, 8, axno=0) cmp.plot_csin('z1',C1_a,C1_phi,1*w1,axno=1) cmp.plot_csin('z-1',C1_a,-C1_phi,-1*w1,axno=2) cmp.plot_synth( 'f1', ((C1_a,C1_phi,1*w1),(C1_a,-C1_phi,-1*w1)), sec=8, imag=False, axno=3) cmp.plot_csin('z2',C2_a,C2_phi,2*w1,axno=4) cmp.plot_csin('z-2',C2_a,-C2_phi,-2*w1,axno=5) cmp.plot_synth( 'f2', ((C2_a,C2_phi,2*w1),(C2_a,-C2_phi,-2*w1)), sec=8, imag=False, axno=6) cmp.plot_csin('z3',C3_a,C3_phi,3*w1,axno=7) cmp.plot_csin('z-3',C3_a,-C3_phi,-3*w1,axno=8) cmp.plot_synth( 'f3', ((C3_a,C3_phi,3*w1),(C3_a,-C3_phi,-3*w1)), sec=8, imag=False, axno=9) cmp.plot_csin('z4',C4_a,C4_phi,4*w1,axno=10) cmp.plot_csin('z-4',C4_a,-C4_phi,-4*w1,axno=11) cmp.plot_synth( 'f4', ((C4_a,C4_phi,4*w1),(C4_a,-C4_phi,-4*w1)), sec=8, imag=False, axno=12) cmp.savefig("result.png")