Normalize transofrm now as class
This commit is contained in:
parent
f8782fb258
commit
e1ba44127e
@ -94,16 +94,24 @@ def calc_peaks(peaks):
|
|||||||
return vpeaks
|
return vpeaks
|
||||||
|
|
||||||
|
|
||||||
def normalize(a):
|
class Normalize:
|
||||||
"""
|
"""
|
||||||
normalize so that all values are between 0 and 1
|
normalize so that all values are between low and high
|
||||||
"""
|
"""
|
||||||
min_ = np.min(a)
|
def __init__(self, low=0, high=1):
|
||||||
a = a - min_
|
assert(low < high)
|
||||||
max_ = np.max(a)
|
self.low = low
|
||||||
if max_ != 0:
|
self.high = high
|
||||||
a = a / max_
|
def __call__(self, array):
|
||||||
return a
|
min_ = np.min(array)
|
||||||
|
a = a - min_
|
||||||
|
max_ = np.max(array)
|
||||||
|
if max_ != 0:
|
||||||
|
a = (a / max_)
|
||||||
|
# now normalized between 0 and 1
|
||||||
|
a *= (self.high - self.low)
|
||||||
|
a -= self.low
|
||||||
|
return a
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
"""
|
"""
|
||||||
@ -112,7 +120,7 @@ if __name__ == "__main__":
|
|||||||
"""
|
"""
|
||||||
df = load_dataframe(file)
|
df = load_dataframe(file)
|
||||||
a = df.to_numpy()
|
a = df.to_numpy()
|
||||||
vdata = normalize(a[:,2])
|
vdata = Normalize(0, 1)(a[:,2])
|
||||||
plt.ion()
|
plt.ion()
|
||||||
# vpeaks[0] is the list of the peaks
|
# vpeaks[0] is the list of the peaks
|
||||||
vpeaks = signal.find_peaks(vdata)[0]
|
vpeaks = signal.find_peaks(vdata)[0]
|
||||||
|
Loading…
Reference in New Issue
Block a user