From 4d154e1d5d4d503d1c23be9e0b5a7fe170658bcf Mon Sep 17 00:00:00 2001 From: Nathan Perkins Date: Sat, 29 Apr 2017 09:24:07 -0400 Subject: [PATCH] Fix sliding window indices Previously, sliding window indices excluded some final indices. New approach ensures all indices are returned, but an extra clipping step is necessary to prevent reading beyond the end of the feature matrix. Closes #1. --- find_audio.m | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/find_audio.m b/find_audio.m index 1dca4ac..bf3180f 100644 --- a/find_audio.m +++ b/find_audio.m @@ -224,7 +224,18 @@ function idx = sliding_window_indices(length, win_length, win_step) win = 0:(win_length - 1); - idx = bsxfun(@plus, 1:win_step:(length - win_length + 1), win'); + + % length - win_length + 1 provides all valid indices (but misses + % some at the end of the length) + + % length - win_step + 1 provides all indices (as well as a few past + % the end of length; as result, clip indices past length) + + idx = bsxfun(@plus, 1:win_step:(length - win_step + 1), win'); + + if idx(end) > length + idx(idx > length) = length; + end end function [match_starts, match_ends, match_scores] = match_via_dtw(feat_template, feat_audio, thresh_score)