spkit.filter_smooth_mollifier

spkit.filter_smooth_mollifier(X, window_length=11, s=None, p=None, r=None, iterations=1, mode='same')

Smoothing filter using Mollifier kernel and 1d-ConvFB

Smoothing filter using Mollifier kernel and 1d-ConvFB

Mollifier: Kurt Otto Friedrichs

Generalized function

\[f(x) = exp(-s/(1-|x|**p)) for |x|<1, x \in [-r, r]\]

Convolving with a mollifier, signals’s sharp features are smoothed, while still remaining close to the original nonsmooth (generalized) signals.

Intuitively, given a function which is rather irregular, by convolving it with a mollifier the function gets “mollified”.

This function is infinitely differentiable, non analytic with vanishing derivative for |x| = 1, can be therefore used as mollifier as described in [1]. This is a positive and symmetric mollifier.[2]

Parameters:
Xarray,
  • input signal single channel (n,) or multi-channel, channel axis should be 1 shape ~ (n,ch)

window_length: int >1, length of kernel
s: scaler, s>0, default=None, which means; s =1,

Spread of the middle width, heigher the value of s, narrower the width

p: scaler, p>0, default=None, which means; p=2,

Order of flateness of the peak at the top, p=2, smoother, p=1, triangulare type Higher it is, more flat the peak.

r: float, 0<r<1, default=None, which means; r=0.999,

it is used to compute x = [-r, r] recommonded to keep it r=0.999

iterations: int, >=1, repeating gaussian smoothing iterations times
mode: convolution mode in {‘same’,’valid’,’full’}, ‘same make sense’
Returns:
Yarray
  • Mollified signal, of same shape as input X

See also

filter_smooth_sGolay

Smoothing signal using Savitzky-Golay filter

filter_smooth_gauss

Smoothing signal using Gaussian kernel

filter_with_kernel

filtering signal using custom kernel

filter_X

Spectral filtering

References

Examples

#sp.filter_smooth_mollifier
import numpy as np
import matplotlib.pyplot as plt
import spkit as sp
seed = 4
N = 10
fs = 100
x   = sp.create_signal_1d(n=2*fs,seed=seed,sg_polyorder=3, sg_winlen=11)
x_n = sp.create_signal_1d(n=2*fs,seed=seed,sg_polyorder=1, sg_winlen=11)
idx = np.arange(len(x))
np.random.seed(seed)
np.random.shuffle(idx)
x[idx[:N]] = x_n[idx[:N]]
#x[idx[:N]+1] = x_n[idx[:N]+1]
#x[idx[:N]+2] = x_n[idx[:N]+2]
t = np.arange(len(x))/fs
y = sp.filter_smooth_mollifier(x.copy(),window_length=11, s=1, p=1)
plt.figure(figsize=(12,4))
plt.plot(t,x,label='x: signal')
plt.plot(t,y,label='y: mollified')
plt.plot(t,x-y1-2,label='x-y:residual')
plt.xlim([t[0],t[-1]])
plt.xlabel('time (s)')
plt.title('Mollifier')
plt.yticks([0,-2],['x','x-y'])
plt.grid()
plt.legend(bbox_to_anchor=(1,1))
np.random.seed(None)
plt.show()