将不同的sin函数进行叠加———用python仿真

闲来无事,想起之前看来关于傅里叶分析的文章,进行一个简单的仿真;

具体的文章的地址如下:


https://blog.csdn.net/u013921430/article/details/79683853


python实现的代码如下:

'''
author : sunyan
'''

from matplotlib import pyplot as plt
import numpy as np
import math

plt.figure(figsize = (10, 10))

three_d_flg = True      #3D开启标志位
all_pit_flg = True      #是否要绘制所有图形
f = 2                   #正弦函数的频率
te_100 = 0              #由于range方法不能生成小数,所以先放大,实际时间再缩小
re_sin = 0
acc_end = 1000          #放大倍数,如果想要提高采样精度,放大此值
fu_n = 23               #叠加正弦函数的次数(fu_n - 2)

re_add = [0] * acc_end  #所有正弦函数结果的叠加
time = []               #x轴----->>>>时间
result = []             #每一个正弦函数的结果
z_dex = []              #z轴

if three_d_flg:
    plt.gca(projection='3d')

plt.xlim(0, 1.2)        # 设置x轴范围
plt.ylim(-1.5, 1.5)     # 设置y轴范围
plt.grid(True)

for ide in range(1, fu_n, 2):
    time = []
    result = []
    z_dex = []
    for index in range(0, acc_end, 1):
        te_100 = index / acc_end
        time.append(te_100)
        re_sin = (1 / (ide * math.pi)) * math.sin(2 * math.pi * ide * f * te_100)
        re_add[index] = re_add[index] + re_sin
        result.append(re_sin)
        z_dex.append(ide / 10)
    if all_pit_flg:
        plt.plot(time, result, z_dex)

plt.plot(time, re_add)

plt.show()

放一张绘制的图片:

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值