Loop over a time window (10 sec.) in a time series to calculate indices of synchronization. Help needed. See comments for details as well.
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Dear all,
in my time series of tow people walking side by side I calculate a synchronization index over the whole time series. Now I would like to calculate the index over time (time window 10 seconds). Here is my code so far:
%% compute GSI to quantify gait snychronization according to Tass et al. (1998)
bin_size = 100; % NOTE: bin size effects GSI;
%% condition together
for i = 1:numel(data_trimmed_al)
phi12 = data_trimmed_al(i).phase_angle_difference; % phase difference over time
% bring phase difference into interval of [-pi, pi]
phi12(phi12 < -pi) = phi12(phi12 < -pi) + 2*pi;
phi12(phi12 > pi) = phi12(phi12 > pi) - 2*pi;
% categorize phase angle difference into bin_size equally distanced bins
bin_edges = linspace(-pi,pi,bin_size); % create equally distanced bins
Y = histcounts(phi12,bin_edges); % count number of data in each bin
p = Y/sum(Y); % normalize bin counts to get probability for each phi12 to be in bin x
% Shannon entropy calculation (rho).
S_max = log(bin_size);
S = - sum(p.*log(p));
rho = (S_max - S)/S_max;
data_trimmed_al(i).GSI_together = rho; % indices of all participants as a mean score of complete time series. I put it in a structure.
end
for synchronization over time:
% compute GSI over time for pair#1
synchTS_GSI = zeros (1, pnts); % time series of synchronization time points
pair_1_GSI = data_trimmed_al(1).phase_angle_difference; % use phase angle difference of pair#1
timevec_1 = (0:pnts-1/srate);
tidx = 1:2860; % time window
if pair_1_GSI
for ti = 1:pnts
phi12 = pair_1_GSI;
phi12(phi12 < -pi) = phi12(phi12 < -pi) + 2*pi;
phi12(phi12 > pi) = phi12(phi12 > pi) - 2*pi;
bin_edges = linspace(-pi,pi,bin_size);
Y = histcounts(phi12,bin_edges);
p = Y/sum(Y);
S_max = log(bin_size);
S = - sum(p.*log(p));
synchTS_GSI(ti) = (S_max-S)/S_max(tidx); Time % this part is cricial and I don't get iz how to loop over time window tidx!
end
end
Help is welcome and appreciated.
Jonas
10 comentarios
Jon
el 6 de Oct. de 2023
No sorry it is not clear.
The problem is that the original code you show is part of a very complex program with many variables and functions that I have no idea about what they are or what they do. So I can't really understand in terms of that code what you are trying to accomplish and why you can't. I was hoping you could provide a simple, runnable example which captures the essence of what it is you are trying to do, and where your problem with accomplishing this is.
It is good that you provided an example, but unfortunately it is an example of something that you know how to do without problems. What I need is a simple example showing what you are actually trying to do, and pointing out exactly where you are stuck and what it is that you don't know how to do.
Maybe someone else can understand from your description, what it is you are trying to do, and provide help for you. Otherwise, unless you can provide a better example of what you are trying to do, and where you are stuck I guess we should give up, so you don't just get frustrated with my lack of understanding.
Respuestas (0)
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!