I need to form a new sequence of numbers by replacing every data value, starting with the 4th entry and ending with the 4th from the last entry, with a weighted average of the seven points around it, using the following formula:
(y[i-3] + 2y[i-2] + 3y[i-1] + 3y[i] + 3y[i+1] + 2y[i+2] + y[i+3]) // 15
(NOTE. The i- or i+ some number is a subscript in case that wasn't apparent.)
Here is the code I have which produces a raw graph, but I need to smooth a new graph with the above formula. The data file produces an array of integers set up as [-24, 4, -4, -12, -52...]
. I am not even sure where to begin with the formula any help would be appreciated.
from matplotlib import pyplot as plt
with open('2_Record2308.dat', 'r') as f:
data = [int(x) for x in f]
graph = data
fig, ax = plt.subplots()
ax.plot(graph)
ax.legend()
ax.set_ylabel('Raw')
plt.tight_layout()
plt.show()