-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmutual_inf_filt_meanHIST_2sigs.m
87 lines (87 loc) · 3.59 KB
/
mutual_inf_filt_meanHIST_2sigs.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
80
81
82
83
84
85
86
87
format long
oo=1; oo2=3; c_signal_name=cell(1,1);
c_signal_name{1}='Lozeron130919';
c_signal_name{2}='Lozeron08092016';
c_signal_name{3}='Milani08092106';
c_signal_name{4}='Milani150916';
signal_name_1=c_signal_name{oo};
[st_Header1, m_SignalsMat1] = edfread([signal_name_1,'.edf']); % a=rand(1,10000); b=filtfilt(SOS, G, a); figure;plot(b)
signal_name_2=c_signal_name{oo2};
[st_Header2, m_SignalsMat2] = edfread([signal_name_2,'.edf']); % a=rand(1,10000); b=filtfilt(SOS, G, a); figure;plot(b)
str_MI=struct;
v_delay=0:60;
for kk=1:6%%%%%%%%%%%%%%%%%%%%%%
mean_hist_1=zeros(1,length(v_delay));
mean_hist_2=zeros(1,length(v_delay));
time_mean=zeros(1,length(v_delay));
k_1 = kk; %signal EEG
k_2 = 8; %signal EMG
Fs = st_Header1.samples(k_1);
t = 0:1/Fs:1-1/Fs; %Time
load('G.mat'), load('SOS.mat')
x_raw = m_SignalsMat1(k_1,:);
x = filtfilt(SOS, G, x_raw);
y_raw = m_SignalsMat2(k_2,:);
y = filtfilt(SOS, G, y_raw);
load([signal_name_1,'.mat']);
v_TimeStartEvts1=v_TimeStartEvts;
load([signal_name_2,'.mat']);
v_TimeStartEvts2=v_TimeStartEvts;
lab=st_Header1.label(kk);
MI=cell(1,1);
MI_hist=cell(1,1);
% figure(kk),
% k=1;
% subplot(121),plot(x),
% hold on, subplot(121),plot(v_TimeStartEvts(k)*Fs,x(v_TimeStartEvts(k)*Fs),'r*')
% hold on , subplot(121), grid
% subplot(122),plot(y),
% hold on, subplot(122),plot(v_TimeStartEvts(k)*Fs,y(v_TimeStartEvts(k)*Fs),'r*')
% hold on , subplot(122), grid
for kkk=1:length(v_delay)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% for k=1:length(v_TimeStartEvts)
% t1=(v_TimeStartEvts(k)*Fs)-(Fs*2)+(v_delay(kkk)*25);
% t2=t1+Fs*1.5;
% t3=(v_TimeStartEvts(k)*Fs)-(Fs*2)+(v_delay(kkk)*25);
% t4=t3+Fs*1.5;
% hold on,
% subplot(221),plot(t1,x(t1),'go')
% subplot(221),plot(t2,x(t2),'ko')
% subplot(222),plot(t3,y(t3),'co')
% subplot(222),plot(t4,y(t4),'mx')
% end
% subplot(221), title(['Muscular contraction. Signal ',num2str(kk),' ',lab{1},' MH']),xlabel('Time (s)'),grid
% subplot(222), title(['Muscular contraction. Signal ',num2str(k_2),' EMG MH']),xlabel('Time (s)'),grid
% figure
if length(v_TimeStartEvts1)<length(v_TimeStartEvts2), n_events=length(v_TimeStartEvts1); else, n_events=length(v_TimeStartEvts2); end
mi_CM=zeros(1, n_events);
for k=1:n_events
t1=(v_TimeStartEvts1(k)*Fs)-(Fs*2);%+(v_delay(kkk)*25);
t2=t1+Fs*1.5;
t3=(v_TimeStartEvts2(k)*Fs)-(Fs*2)+(v_delay(kkk)*25);
t4=t3+Fs*1.5;
mi_CM(k) = mutualinfo(x(t1:t2),y(t3:t4)); %Mutual information from MI folder
end
MI{kkk}=mi_CM;
h1=histogram(mi_CM,20);
MI_hist{kkk}=h1;
mean_hist_1(kkk)=mean(h1.BinEdges);
time_mean(kkk)=v_delay(kkk)*25/256;
mean_hist_2(kkk)=mean(mi_CM);
% hold on,
% subplot(223),plot(mi_CM) %Plot of the Coherence vs. the frequencies (in hertz) at which Cxy is estimated
% hold on,
% subplot(223),title('MH Mutual information')
% hold on,
% subplot(224),histogram(mi_CM,20),title('MH Histogram on Mutual Information')
% pause
end
str_MI(kk).name=lab{1};
str_MI(kk).MI=MI;
str_MI(kk).MI_hists=MI_hist;
str_MI(kk).mean_hists_1=mean_hist_1;
str_MI(kk).mean_hists_2=mean_hist_2;
str_MI(kk).time_means=time_mean;
str_MI(kk).static='EEG';
end
save(['./seminario5_MI/hists_2sigs/',signal_name_1,signal_name_2,'_MI_signal',num2str(k_2),'_1-',num2str(kk),'.mat'], 'str_MI')