Skip to content

Commit 8b50b3a

Browse files
author
arch
committed
improve signal processing
1 parent 1d3154f commit 8b50b3a

File tree

1 file changed

+37
-15
lines changed

1 file changed

+37
-15
lines changed

funscript_editor/algorithms/signal.py

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -308,25 +308,47 @@ def get_local_min_max_points(self, signal: list, filter_len: int = 3) -> list:
308308
"""
309309
avg = Signal.moving_average(signal, w=round(self.fps * self.params.avg_sec_for_local_min_max_extraction))
310310
smothed_signal = Signal.moving_average(signal, w=filter_len)
311-
points, tmp_min_idx, tmp_max_idx = [], -1, -1
311+
points, tmp_min_start_idx, tmp_min_end_idx, tmp_max_start_idx, tmp_max_end_idx = [], -1, -1, -1, -1
312312
for pos in range(len(smothed_signal)):
313313
if smothed_signal[pos] < avg[pos]:
314-
if tmp_min_idx < 0:
315-
tmp_min_idx = pos
316-
elif smothed_signal[tmp_min_idx] >= smothed_signal[pos]:
317-
tmp_min_idx = pos
318-
elif tmp_min_idx >= 0:
319-
points.append(tmp_min_idx)
320-
tmp_min_idx = -1
314+
if tmp_min_start_idx < 0:
315+
tmp_min_start_idx = pos
316+
tmp_min_end_idx = pos
317+
elif smothed_signal[tmp_min_start_idx] == smothed_signal[pos]:
318+
tmp_min_end_idx = pos
319+
elif smothed_signal[tmp_min_start_idx] > smothed_signal[pos]:
320+
tmp_min_start_idx = pos
321+
tmp_min_end_idx = pos
322+
elif tmp_min_start_idx >= 0:
323+
if abs(smothed_signal[tmp_min_end_idx] - avg[tmp_min_end_idx]) > 2.0:
324+
# only add if ther is movement in the data
325+
if tmp_min_end_idx - tmp_min_start_idx > 3:
326+
points.append(tmp_min_start_idx)
327+
328+
points.append(tmp_min_end_idx)
329+
330+
tmp_min_start_idx = -1
331+
tmp_min_end_idx = -1
321332

322333
if smothed_signal[pos] > avg[pos]:
323-
if tmp_max_idx < 0:
324-
tmp_max_idx = pos
325-
elif smothed_signal[tmp_max_idx] <= smothed_signal[pos]:
326-
tmp_max_idx = pos
327-
elif tmp_max_idx >= 0:
328-
points.append(tmp_max_idx)
329-
tmp_max_idx = -1
334+
if tmp_max_start_idx < 0:
335+
tmp_max_start_idx = pos
336+
tmp_max_end_idx = pos
337+
elif smothed_signal[tmp_max_start_idx] == smothed_signal[pos]:
338+
tmp_max_end_idx = pos
339+
elif smothed_signal[tmp_max_start_idx] < smothed_signal[pos]:
340+
tmp_max_start_idx = pos
341+
tmp_max_end_idx = pos
342+
elif tmp_max_start_idx >= 0:
343+
if abs(smothed_signal[tmp_max_end_idx] - avg[tmp_max_end_idx]) > 2.0:
344+
# only add if ther is movement in the data
345+
if tmp_max_end_idx - tmp_max_start_idx > 3:
346+
points.append(tmp_max_start_idx)
347+
348+
points.append(tmp_max_end_idx)
349+
350+
tmp_max_start_idx = -1
351+
tmp_max_end_idx = -1
330352

331353
self.logger.info("Found %d local min max points", len(points))
332354
return points

0 commit comments

Comments
 (0)