我已经使用Weierstrass变换制作了一个python代码来平滑给定信号,这基本上是归一化高斯与信号的卷积.
代码如下:
#Importing relevant libraries
from __future__ import division
from scipy.signal import fftconvolve
import numpy as np
def smooth_func(sig, x, t= 0.002):
N = len(x)
x1 = x[-1]
x0 = x[0]
# defining a new array y which is symmetric around zero, to make the gaussian symmetric.
y = np.linspace(-(x1-x0)/2, (x1-x0)/2, N)
#gaussian centered around zero.
gaus = np.exp(-y**(2)/t)
#using fftconvolve to speed up the convolution; gaus.sum() is the normalization constant.
return fftconvolve(sig, gaus/gaus.sum(), mode='same')
Run Code Online (Sandbox Code Playgroud)
如果我运行此代码来表示阶梯函数,它会使角落变得平滑,但是在边界处它会解释另一个角落并使其平滑,从而在边界处产生不必要的行为.我用下面链接中的数字解释这个.
边界效应
如果我们直接整合以找到卷积,则不会出现此问题.因此问题不在于Weierstrass变换,因此问题在于scipy的fftconvolve函数.
要理解为什么会出现这个问题,我们首先需要了解fftconvolve在scipy中的工作原理.
fftconvolve函数基本上使用卷积定理来加速计算. …