Пример #1
0
def sig_f1():
    def f1(t, t0):
        return (t > 0) * t

    qi, mo = -10, 10  # 坐标轴的起始位置
    num = 1000  # 样本数量
    x = np.linspace(qi, mo)
    image_list = []
    t1 = 6
    t0 = 4

    for i in range(0, t0 + 1):
        plt.title('点动,函数不变', fontsize=24)
        plt.xlim(qi, mo)
        x1 = t1 - i
        y1 = f1(x1, 0)
        plt.plot(x, f1(x, 0), lw=2, label="y=r(t)")
        plt.legend()
        plt.plot(x1, y1, 'bo')
        if (i == t0):
            plt.annotate('y值为%d' % y1,
                         xy=(x1, y1),
                         xytext=(x1 - 3, y1 + 1),
                         arrowprops=dict(facecolor='red', shrink=0.1))

        plt.annotate('(%d,%d)' % (x1, y1),
                     xy=(x1 + 2, y1),
                     xytext=(x1, y1 + 0.4))
        plt.savefig('single1.png')
        plt.close()  # 这样会清楚旧图
        image_list.append(imageio.imread('single1.png'))
        img = cv2.imread('single1.png')
        deputy.read("single1.png")
    imageio.mimsave('single1.gif', image_list, duration=1)
    return image_list
Пример #2
0
def step_rope(spe=1):
    # 画dirac
    ge = 0.5
    x = np.arange(-10, 10, ge)
    image_list = []
    make_rope_func(0)
    for i in range(5):
        image_list.append(imageio.imread('step.png'))

    for i in range(len(x)):
        title = "阶跃函数" + r"$\Rightarrow$" + "斜坡函数"
        plt.title(title, c="c", fontsize=20)
        plt.text(-9,
                 5,
                 r"$ r(t)=\int_{-∞}^{∞}\delta(t)\,dx$",
                 c="c",
                 fontsize=18,
                 alpha=0.6)
        plt.axhline(y=0, ls="-", color="c", alpha=0.3)  # 添加垂直直线
        if x[i] < 0: continue
        plt.xlim(-10, 10)
        plt.ylim(0, 10)
        for d in range(40):
            if x[i] >= ge * d:
                plt.vlines(ge * d, 0, ge * d, linestyles='-', colors="c")
            if d * ge > x[i]: break
        plt.plot()
        name = "step_rope"
        plt.savefig(name + ".png")
        deputy.read(name + ".png", -1)
        plt.close()
        image_list.append(imageio.imread(name + '.png'))
    for i in range(5):
        image_list.append(imageio.imread('rope.png'))
    imageio.mimsave('step_rope.gif', image_list, duration=0.5)
Пример #3
0
def dirac_step():
    # 画dirac
    ge = 0.5
    x = np.arange(-10, 10, ge)
    image_list = []
    make_step_func(0)
    for i in range(5):
        image_list.append(imageio.imread('dirac.png'))

    for i in range(len(x)):
        title = "冲激函数" + r"$\Rightarrow$" + "阶跃函数"
        plt.title(title, c="b", fontsize=18)
        plt.text(-9,
                 0.8,
                 r"$\delta(t)=\int_{-∞}^{∞} \varepsilon(t) \, dx$",
                 c="b",
                 fontsize=18,
                 alpha=0.6)
        plt.axhline(y=0, ls="-", color="b", alpha=0.3)  # 添加垂直直线
        if x[i] < 0: continue
        plt.xlim(-10, 10)
        for d in range(40):
            if x[i] >= ge * d:
                plt.vlines(ge * d, 0, 1, linestyles='-', colors="b")
            if d * ge > x[i]: break
        plt.plot()
        plt.savefig("dirac_step.png")
        deputy.read("dirac_step.png", -1)
        plt.close()
        image_list.append(imageio.imread('dirac_step.png'))
    for i in range(5):
        image_list.append(imageio.imread('step.png'))

    imageio.mimsave('dirac_step.gif', image_list, duration=0.5)
Пример #4
0
def make_rope_func(spe=1):
    qi = -10  # 坐标轴的起始位置
    mo = -qi
    num = 1000  # 样本数量

    x = np.linspace(qi, mo, num)
    y = (x > 0) * x
    plt.title("斜坡函数", fontdict={"size": "xx-large", "color": "deepskyblue"})
    plt.plot(x, y, lw=2, label="r(t)", c="deepskyblue")
    plt.legend()
    plt.savefig("rope.png")
    if spe == 1: deputy.read("rope.png", 3)
    plt.show()
Пример #5
0
def make_step_func(spe=1):
    qi = -10  # 坐标轴的起始位置
    mo = -qi
    num = 1000  # 样本数量

    x = np.linspace(qi, mo, num)
    y = x > 0
    plt.title("画阶跃函数", fontdict={"size": "xx-large", "color": "c"})
    plt.plot(x, y, lw=2, label=r"$\varepsilon(t)$", c="c")
    plt.legend()
    plt.savefig("step.png")
    if spe == 1: deputy.read("step.png", 3)
    plt.show()
Пример #6
0
def make_dirac():
    # 画dirac
    scope = 0.01  #冲激范围
    xie = 100
    x = np.arange(-10, 10, 0.01, np.float)
    y = np.zeros(x.shape, np.float32)
    for i in range(len(x)):
        if x[i] > scope: break
        if x[i] < -scope: continue

        if x[i] >= 0:
            y[i] = (x[i] - scope) * (-xie)
        elif x[i] < 0:
            y[i] = (x[i] + scope) * xie
    plt.text(0.2, 0.6, "(1)", weight="bold", color="b")
    plt.title("画冲激函数", fontdict={"size": "xx-large", "color": "b"})
    plt.plot(x, y, lw=2, label=r"$\delta(t)$", c="b")
    plt.legend()
    plt.savefig("dirac.png")
    deputy.read("dirac.png", 3)
    plt.show()
Пример #7
0
def sig_f2():
    def f1(t, t0):
        t = t - t0
        return (t > 0) * t

    qi, mo = -10, 10  # 坐标轴的起始位置
    num = 1000  # 样本数量
    x = np.linspace(qi, mo)
    image_list = []
    t1 = 6
    t0 = 4

    for i in range(0, t0 + 1):
        plt.title('函数右移,点不变', fontsize=24)
        plt.xlim(qi, mo)
        plt.ylim(-2, 10)
        x1 = t1
        y1 = f1(x1, i)
        plt.plot(x, f1(x, i), lw=2, label="y=u(t-%d)" % i)
        plt.legend(loc=2)
        plt.plot(x1, y1, 'bo')
        if (i == t0):
            plt.annotate('y值为%d!' % y1,
                         xy=(x1, y1),
                         xytext=(x1 - 3, y1 + 1),
                         arrowprops=dict(facecolor='red', shrink=0.1))

        plt.annotate('(%d,%d)' % (x1, y1),
                     xy=(x1 + 0.3, y1),
                     xytext=(x1, y1 + 0.4))

        plt.savefig('single2.png')
        plt.close()  # 这样会清楚旧图
        image_list.append(imageio.imread('single2.png'))
        deputy.read("single2.png")  #把这个照片存储到视频里去

    imageio.mimsave('single2.gif', image_list, duration=1)
Пример #8
0
def func1(t=3):
    image_list = []
    ge = 0.1  #time的时间间隔,不能取1
    time = np.arange(-0.5, 3.5, ge)
    tt = 0
    x = np.arange(-6, 10, ge)
    data_list = np.zeros(len(time))

    yes = np.zeros(6)
    print(yes)
    for i in range(len(time)):
        # plt.text(0,0,"hello",fontsize=20,color="gray",alpha=0.5)
        plt.title("hello")
        y1 = h(x)
        y2 = f(x, time[i])
        y_int = np.sum(y1 * y2) * ge
        t = np.arange(-5, time[i], ge)

        data_list[i] = y_int
        # print(time[i],":",y_int)
        ax1 = plt.subplot(121)
        ax1.plot(x, y1, lw=2)  #函数曲线)
        ax1.plot(x, y2, lw=2)
        ax1.fill(x, y1, 'r', alpha=0.5, label='y1')
        ax1.fill(x, y2, 'b', alpha=0.5, label='y2')
        ax1.legend(loc=("upper left"))
        plt.title("卷积过程")
        ax2 = plt.subplot(122)
        plt.title("h(t)*f(t)")
        #画分隔线
        if time[i] >= 1.00:
            plt.axvline(x=1, ls="--", c="dimgray", alpha=0.3)  # 添加垂直直线
        if time[i] >= 2.00:
            plt.axvline(x=2, ls="--", c="dimgray", alpha=0.4)  # 添加垂直直线

        # 画分段函数

        ### 画各个阶段的函数式
        plt.text(-4.7, 0.9, "0<t:y=0", weight="bold", color="b", alpha=0.8)
        if time[i] > 0:
            plt.text(-4.7,
                     0.8,
                     r"$0\leq t\leq 1:y=\frac{1}{4}t^2$",
                     weight="bold",
                     color="b",
                     alpha=0.8)
        if time[i] > 1:
            plt.text(-4.7,
                     0.7,
                     r"$1<t\leq2:y=\frac{1}{2}t-\frac{1}{4}$",
                     weight="bold",
                     color="b",
                     alpha=0.8)
        if time[i] > 2:
            plt.text(-4.7,
                     0.6,
                     r"$2<t\leq3:$",
                     weight="bold",
                     color="b",
                     alpha=0.8)
            plt.text(-4.7,
                     0.5,
                     r"$y=\frac{1}{4}t^2+\frac{1}{2}t+\frac{3}{4}$",
                     weight="bold",
                     color="b",
                     alpha=0.8)
        if time[i] > 3:
            plt.text(-4.7,
                     0.4,
                     "$3<t:y=0$",
                     weight="bold",
                     color="b",
                     alpha=0.8)

        ###
        x_major_locator = MultipleLocator(1)
        ax = plt.gca()
        # ax为两条坐标轴的实例
        ax.xaxis.set_major_locator(x_major_locator)

        ax2.plot(time, data_list, 'b')
        plt.suptitle("卷积演示", fontsize=25)

        plt.xlim(-5, 5)
        plt.ylim(0, 1)
        # plt.plot(y1,y3)
        # plt.show()
        plt.savefig('tem.png')

        image_list.append((imageio.imread('tem.png')))
        plt.close()
        deputy.read("tem.png")

        image_list.append(imageio.imread('tem.png'))

    imageio.mimsave('卷积.gif', image_list, duration=1)
Пример #9
0
def combin1():
    name="对比图1"
    def x0(t,i=0):
        t=t
        t=t-i
        return t
        #表示激励

    #原函數为y=u(-t)
    def f1(t,i):
        return x0(t,i)

    qi,mo=-10,10  # 坐标轴的起始位置
    ylim_min,ylim_max=-4,200     #y轴的范围
    num = 1000  # 样本数量
    image_list = []
    t1 = 6
    t0 = 5

    x = np.linspace(qi, mo)

    for i in range(0, t0 + 1):
        plt.title("hello")
        #picture 1
        x1=t1-i  # 点动
        ax1=plt.subplot(1,2,1)
        ax1.set_title('函数不变,t变')
        ax1.plot(x, f1(x,0), lw=2, label="y(t)")

        ax1.legend()
        ax1.set(ylim=(-10,15))
        plt.plot(x1, f1(x1,0), 'bo')       #标出移动的点
        ax1.annotate('(%d,%d)' % (x1,f1(x1,0)), xy=(x1 ,f1(x1,0)))

        if (i == t0):
            y1=f1(x1,0)
            ax1.annotate("y值为%lf"%y1, xy=(x1-2, y1+2), xytext=(x1-3, y1 + 1),color='b')

        ax1.annotate('y=f(t)', xy=(1,1),xytext=(t1-5, t1-7))    #曲线的注释

        #picture 2
        x2=t1     #点不动
        y2 = f1(x2, i)
        ax2 = plt.subplot(1,2,2)
        ax2.set_title('函数变,t不变')
        ax2.plot(x, f1(x, i), lw=2, label="y=y(t-t0)",color="darkviolet")  #函数曲线
        ax2.legend()    #显示图标
        plt.annotate('y=f(t-%d)' % i, xy=(1,1),xytext=(t1-3, t1-7)) #给函数图像做注释
        ax2.set(ylim=(-10,15))
        ax2.plot(x2, y2, 'p',color="purple")  # 标出移动的点
        ax2.annotate('(%d,%d)' % (x2,y2), xy=(x2, y2))


        if i == t0:
            ax2.annotate('y值为%lf'%(y2), xy=(x2-1, y2-1), xytext=(x2-5, y2 + 1),color='darkorchid')


        plt.savefig('comb1.png')
        plt.close()  # 这样会清楚旧图
        image_list.append(imageio.imread('comb1.png'))
        deputy.read("comb1.png",1)
    imageio.mimsave('对比图1.gif', image_list, duration=1)