Calculate number of sprints based on sprint and time data

2 Ansichten (letzte 30 Tage)
Lotte Korblet
Lotte Korblet am 22 Feb. 2024
Kommentiert: Aquatris am 23 Feb. 2024
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? :)

Akzeptierte Antwort

Aquatris
Aquatris am 22 Feb. 2024
Bearbeitet: Aquatris am 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 Kommentare
Lotte Korblet
Lotte Korblet am 23 Feb. 2024
It worked! Thank you so much!
Aquatris
Aquatris am 23 Feb. 2024
Glad it worked. Good luck with your work. Sounds interesting :)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Programming finden Sie in Help Center und File Exchange

Produkte


Version

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by