Created
October 24, 2018 08:52
-
-
Save kanedo/06d19d18f77e8a1fa691c892ad585c21 to your computer and use it in GitHub Desktop.
triangle smoothing filter in python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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