satt2=movstd(emgdata{sub,trials(t)}(1,:),125);%125 sample windows, you can play around with this parameter and check in the loop above
satt=std(emgdata{sub,trials(t)}(1,:));%STD for right(1) channel
c=find(satt2>(t_emg_*satt));% first exceed thresh STD
%including button press rigth hand
if~isempty(c)
c1_all(1,t)=c(1);% BP sample
end
%indices without button press
% right hand
if~isempty(c)&&c(1)<size(emgdata{sub,trials(t)}(1,:),2)-t_BP_ms*(cfg.EMG.srate/1000)%<- threshold to account for the button press (750 ms), check if index is lower so that movement is not derived from button press
c1(1,t)=c(1);% position where movavg exceeds std
end
%left hand // only when no movement in rigth hand
ifisempty(c)
satt3=movstd(emgdata{sub,trials(t)}(2,:),125);
satt4=std(emgdata{sub,trials(t)}(2,:));
cca=find(satt3>(satt4));
if~isempty(cca)
c2_all(1,t)=cca(1);% left hand only
end
if~isempty(cca)&&cca(1)<size(emgdata{sub,trials(t)}(2,:),2)-t_BP_ms*(cfg.EMG.srate/1000)%left hand without BP