【问题标题】:How to segment a gaussian function to equal-volume parts如何将高斯函数分割为等体积部分
【发布时间】:2022-01-06 21:34:51
【问题描述】:

我正在尝试使用 Python 将高斯形曲线拆分为 K 个等体积段,以进行信号过滤。

我正在寻找伪代码、一般概念或执行它的库。 任何帮助将不胜感激。

谢谢!

例如在下图中:对于 K=6。卷 s1 = s2 = ... = s6:

【问题讨论】:

    标签: python statistics signal-processing gaussian


    【解决方案1】:

    您需要确定分布的百分位数。您可以使用这个scipy.stats.norm 类及其.ppf() 方法。

    import numpy as np
    import scipy.stats as sps
    import matplotlib.pyplot as plt
    
    mu = 25
    sigma = 4
    splits = 8
    
    # define the normal distribution and PDF
    dist = sps.norm(loc=mu, scale=sigma)
    x = np.linspace(dist.ppf(.001), dist.ppf(.999))
    y = dist.pdf(x)
    
    # calculate PPFs
    step = 1 / splits
    quantiles = np.arange(step, 1.0 - step / 2, step)
    ppfs = dist.ppf(quantiles)  # boundaries
    
    # plot results
    fig, ax = plt.subplots(figsize=(10, 4))
    ax.plot(x, y, color='k')
    for i, ppf in enumerate(ppfs):
        ax.axvline(ppf, color=f'C{i}', label=f'{quantiles[i]:.3f}: {ppf:.1f}')
    ax.legend()
    plt.show()
    

    这是基于this answer

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-12
      • 2023-03-19
      • 2012-02-20
      • 1970-01-01
      • 1970-01-01
      • 2013-04-17
      • 1970-01-01
      • 2022-12-04
      相关资源
      最近更新 更多