-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFilter_Delays.m
More file actions
146 lines (119 loc) · 4.17 KB
/
Filter_Delays.m
File metadata and controls
146 lines (119 loc) · 4.17 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
% -------------------------------------------------------------------------
% Delay of the filter BW
% -------------------------------------------------------------------------
clear all;
close all;
filter_case = 'CC2'; % 'BWLab' or 'BWProp' or 'CC2'
switch filter_case
case 'BWLab'
load('D:\SWS_Chord_PN\data\comp_filters\BWLab\BWLab.mat')
case 'BWProp'
load('D:\SWS_Chord_PN\data\comp_filters\BWProp\BWProp.mat')
case 'CC2'
load('D:\SWS_Chord_PN\data\comp_filters\CC2\CC2.mat')
end
%grpdelay(Hd_but1)
% -------------------------------------------------------------------------
% Slow Wave extraction
% -------------------------------------------------------------------------
% SWs from raw EEG extracted with filtfilt
x=find(sw_detect==0);
raw_samp_SW=raw_samp;
raw_samp_SW(x)=0;
% SWs from filt EEG extracted with filt
x=find(sw_detect_filt==0);
raw_samp_filt_SW=raw_samp_filt;
raw_samp_filt_SW(x)=0;
% SWs from filtfilt EEG extracted with filtfilt
x=find(sw_detect==0);
raw_samp_filtfilt_SW=raw_samp_filtfilt;
raw_samp_filtfilt_SW(x)=0;
%% Plot data with trigger_offline_filt
% -------------------------------------------------------------------------
% plot triggers and SW borders
figure
plot(raw_samp_filtfilt_SW)
hold on
plot(trigger_offline_filt,raw_samp_filtfilt_SW(trigger_offline_filt),'*')
hold on
plot(raw_samp_filt_SW,'r')
hold on
plot(trigger_offline_filt,raw_samp_filt_SW(trigger_offline_filt),'*r')
legend('filtfilt EEG','triggers with filt','filt EEG','triggers with filt')
hold on
for idx = 1 : length(sw)
plot([sw(idx) sw(idx)], [min(raw_samp_filtfilt_SW) max(raw_samp_filtfilt_SW)]);
end
hold on
for idx = 1 : length(sw_filt)
plot([sw_filt(idx) sw_filt(idx)], [min(raw_samp_filt_SW) max(raw_samp_filt_SW)],'r');
end
h=refline(0);
g=refline([0 30]);
set(h,'color','k')
set(g,'color','k')
xlabel('Samples')
ylabel('Amplitude')
title(['Filt and Filtfilt SWs with triggers from filt - ',filter_case])
%% Phase extraction
% -------------------------------------------------------------------------
hilb = hilbert(raw_samp_filt');
sigphase_filt = angle(hilb);
sigphase_degree_filt=(sigphase_filt+pi)./pi.*180;
clear hilb
hilb = hilbert(raw_samp_filtfilt');
sigphase_filtfilt = angle(hilb);
sigphase_degree_filtfilt=(sigphase_filtfilt+pi)./pi.*180;
clear hilb
sample_SW_hit=trigger_offline_filt(find(raw_samp_filtfilt_SW(trigger_offline_filt)));
phase_filt=sigphase_degree_filt(sample_SW_hit);
phase_filtfilt=sigphase_degree_filtfilt(sample_SW_hit);
% -------------------------------------------------------------------------
% polar histogram of phase hit at common detected SWs
figure
h1=rose(sigphase_filt(sample_SW_hit)+pi,12);
hold on
h=rose(sigphase_filtfilt(sample_SW_hit)+pi,12);
t=title(['Phase analyis on SWs detected both by filt and filtfilt - ',filter_case]);
set(t,'FontSize',18)
% x1 = get(h1, 'XData') ;
% y1 = get(h1, 'YData') ;
% p1 = patch(x1, y1,'b') ;
%
% x = get(h, 'XData') ;
% y = get(h, 'YData') ;
% p = patch(x, y, 'g') ;
set(h1,'LineWidth',2.5)
set(h,'LineWidth',2.5,'Color','g')
l=legend('phase of filt EEG','phase of filtfilt EEG');
%set(l,'FontSize',18,'Position',[0.5 0.75 0.67 0.15])
get(l,'Position')
% -------------------------------------------------------------------------
% polar histogram of
% plot triggers and SW borders
figure
plot(raw_samp_filtfilt)
hold on
plot(trigger_offline_filt,raw_samp_filtfilt(trigger_offline_filt),'*')
hold on
plot(raw_samp_filt,'r')
hold on
plot(trigger_offline_filt,raw_samp_filt(trigger_offline_filt),'*r')
legend('filtfilt EEG','triggers with filt','filt EEG','triggers with filt')
hold on
for idx = 1 : length(sw)
plot([sw(idx) sw(idx)], [min(raw_samp_filtfilt) max(raw_samp_filtfilt)]);
end
hold on
for idx = 1 : length(sw_filt)
plot([sw_filt(idx) sw_filt(idx)], [min(raw_samp_filt) max(raw_samp_filt)],'r');
end
hold on
plot(raw_samp,'g')
h=refline(0);
g=refline([0 30]);
set(h,'color','k')
set(g,'color','k')
xlabel('Samples')
ylabel('Amplitude')
title(['Filt and Filtfilt SWs with triggers from filt - ',filter_case])