Skip to content

Instantly share code, notes, and snippets.

@kanedo
Created October 24, 2018 08:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kanedo/06d19d18f77e8a1fa691c892ad585c21 to your computer and use it in GitHub Desktop.
Save kanedo/06d19d18f77e8a1fa691c892ad585c21 to your computer and use it in GitHub Desktop.
triangle smoothing filter in python
def triangle_filter(self, n):
f = np.zeros((1+2*n))
for i in range(n):
f[i] = i+1
f[-i-1] = i+1
f[n] = n + 1
return f / np.sum(f)
filter = triangle_filter(smoothing_factor)
tmp = np.pad(data, smoothing, mode='edge')
res = np.convolve(tmp, filter, mode='valid')
data = res
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment