-
Notifications
You must be signed in to change notification settings - Fork 0
/
EMG_app.m
80 lines (77 loc) · 2.39 KB
/
EMG_app.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
%load data
load EMGRT.mat
N = length(rts);
%Getting sample trials
%One is selected to be relatively clean while the other is not
trials2plot = [4 29];
%plotting the figure
figure(1),clf
%Plot of Movement times
plot(rts,'s-','markerfacecolor','w');
xlabel('Trials'),ylabel('Movement time(ms)');
set(gca,'xlim',[0 N+1])
%Histogram of RTs
figure(2),clf
histogram(rts,40)
xlabel('Count'),ylabel('Movement Time(ms)')
figure(3),clf
for i = 1:2
subplot(2,1,i),hold on
plot(timevec,emg(trials2plot(i),:),'r','linew',1)
plot([1 1]*rts(trials2plot(i)),get(gca,'ylim'),'k--','linew',1)
xlabel('Time(ms)')
legend({'EMG';'Button Press'})
end
%detect EMG onsets
%define baseline time window for normalization
baseidx = dsearchn(timevec',[-500 0]');
%pick the z-threshold
zthresh = 100;
%intialization of outputs
emgonsets = zeros(N,1);
%initiate filtered signal
emgSelected = emg(29,:);
emgf = emgSelected;
%the loop implementation
for i = 2:length(emgSelected)-1
emgf(i) = emgSelected(i)^2 - (emgSelected(i-1)*emgSelected(i+1));
end
%Normalization because the filtered signal is not in the same scale as the
%original.For that we use the prezero section
emgZ = (emgSelected-mean(emgSelected(baseidx(1):baseidx(2))))/std(emgSelected(baseidx(1):baseidx(2)));
emgZf = (emgf-mean(emgf(baseidx(1):baseidx(2))))/std(emgf(baseidx(1):baseidx(2)));
%plotting the zscored
figure(4),clf,hold on
plot(timevec,emgSelected,'b','linew',2);
plot(timevec,emgZf,'m','linew',2);
xlabel('Time(ms)'),ylabel('Z score relative to prestimulus')
legend({'EMG'; 'EMG TKEO'});
for triali = 1:N
%convert to energy via TKEO
tkeo = emg(triali,2:end-1).^2-(emg(triali,1:end-2).*emg(triali,3:end));
tkeo = (tkeo-mean(tkeo(baseidx(1):baseidx(2))))./std(tkeo(baseidx(1):baseidx(2)));
tkeoThresh = tkeo > zthresh;
tkeoThresh(timevec<0) = 0;
tkeoPnts = find(tkeoThresh);
emgonsets(triali) = timevec(tkeoPnts(1)+1);
end
figure(5), clf
plot(rts,emgonsets,'bo','markerfacecolor','b','markersize',5)
xlabel('Button press time')
ylabel('EMG onset time')
axis square
%Get the correlation results
[R,P,RL,RU] = corrcoef(emgonsets,rts);
%Getting the stat parameters
minOnSet = min(emgonsets);
maxOnSet = max(emgonsets);
meanOnset = mean(emgonsets);
medianOnset = median(emgonsets);
stdOnset = std(emgonsets);
varOnset = stdOnset^2;
minMT = min(rts);
maxMT = max(rts);
meanMT = mean(rts);
medianMT = median(rts);
stdMT = std(rts);
varMT = stdMT^2;