Calculate number of sprints based on sprint and time data

4 views (last 30 days)
Hi everyone,
I am analyzing soccer-related data. I have a big file containing x & y coordinates, speed (km/h) and acceleration for each point in time (frequency was 1000 Hz but I transformed the samples into time in seconds). So, for each variable, I have its value for a lot of time-points.
I want to calculate the number of sprints performed during the match. Somehting is considered as a sprint if:
  • speed > 17 km/h AND
  • duration (t) > 1 sec (so speed needs to be higher than 17 km/h for an interval of minimal 1 second)
I think I need to do something with a for loop and the 'diff' function, but I'm struggling a lot... Can someone help me out? :)

Accepted Answer

Aquatris
Aquatris on 22 Feb 2024
Edited: Aquatris on 22 Feb 2024
Based on another answer here, find below a solution:
clear ,clc
Fs = 1e3; % sampling rate
dt = 1/Fs;
t = 0:dt:100; % time vector
x = sin(t)*20; % signal
threshold = 17; % signal threshold to look for
threshold_duration = 1; % min duration
threshold_number_samples = ceil(threshold_duration * Fs); % duration in samples
%% exact copy of the solution from the link
mask = x(:).' >= threshold; % find parts of the signal that is above threshold
% create pattern of [0 1 1 1 ... 1] that defines 1s for threshold_number_samples
mask2 = true(1, threshold_number_samples);
% search for the start points for the mask2 pattern in mask to identify
% the occurences of signal being larger than threshold for at least some duration
starts = strfind([false, mask], [false, mask2]);
% search for the stop points
stops = strfind([mask, false], [mask2, false]);
% get index of signal that is larger than threshold for at least threshold_duration
idx = [];
for i = 1:length(starts)
idx = [idx,starts(i):stops(i),stops(i)+(1:threshold_number_samples)];
end
% plot data and identified part of the signal that is greater than the
% threshold for at least 1 sec
plot(t,x,t(idx),x(idx),'.')
  4 Comments
Aquatris
Aquatris on 23 Feb 2024
Glad it worked. Good luck with your work. Sounds interesting :)

Sign in to comment.

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!