-
Notifications
You must be signed in to change notification settings - Fork 0
/
eegplugin_PAA.m
81 lines (75 loc) · 3.35 KB
/
eegplugin_PAA.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
function vers = eegplugin_PAA(fig, trystrs, catchstrs)
% eegplugin_PAA() - EEGLAB plugin for period amplitude analysis
%
% Usage:
% >> eegplugin_PAA(fig, trystrs, catchstrs)
%
% Inputs:
% fig - [integer] EEGLAB figure.
% trystrs - [struct] "try" strings for menu callbacks.
% catchstrs - [struct] "catch" strings for menu callbacks.
%
% See also:
% PAA, pop_PAA, eeglab
%
% June 24, 2020 Version 1.0
% Aug 27, 2020 Revised 1.1 Critical bug fixes: ch order, polarity, channel
% labels
% Sept 13, 2020 Revised 1.2 included sleep stages in output and SW events,
% fixed bug for SW inclusion criteria, optimised code
% Sept 16, 2020 Revised 1.3 negative slope calculation bug fixed. Improved
% detection criteria to include any adjacent HWs
% Sept 23, 2020 Revised 1.4 major fix for starting issue with polarity and
% table creation for multiple files.
% Sept 24, 2020 Revised 1.5 fixed conflict with identical latency events
% Sept 28, 2020 Revised 1.6 adjusted filtering parameters and functions to
% improve filter response - AG
% Jun 1, 2021 Revised 1.7 (incorporated updates from AG):
% 1. updates to HW threshold process. The peak-to-peak amplitude is now
% calculated by finding the difference between the maximum absolute peak
% of each HW and it's oppositely valanced HW neighbours. As before, the
% length of each HW and it's neighbour is also checked to ensure it falls
% within the correct frequency range. Only HWs that meet both criteria
% are included in future analyses.
% 2. added feature to save each subjects data as separate .csv files in
% addition to concatinated .csv for all subjects
% 3. minor fix to correct mismatch between filename and setname in output
% table - SF
% 4. added half wave amplitude threshold in addition to p2p amplitude
% threshold. - AG
% 5. added functionality to remove unwanted SW during sleepstages of
% non-interest - SF
% Jun 21, 2021 Revised 1.8: added feature to remove SW events outside
% Lights OFF/ON tags.
% May 26, 2022 Revised 1.9: corrected bug in calculation on integrated
% amplitude - SF
% Aug 30, 2022 Revised 2.0: new SW parameters added to event structure.
% Dec 18, 2022 Revised 2.01: better handling of GUI input with multiple channels.
% Dec 28, 2022 Revised 2.02: modified menu layout
% Jan 21, 2023 Revised 2.1: batch uses GUI
% Feb 12, 2023 Revised 2.1.1: added progress bars
% Feb 15, 2023 Revised 2.1.2: handle multiple bad data markers
% Nov 15, 2023 Revised 2.1.3: include error catch if channel labels include
% whitespaces
% Sept 4, 2024 Revised 2.1.4: handled issues with orphaned events at end of
% recording, outside sleep scoring.
% Sept 4, 2024 Revised 2.1.5: added catch for when no events detected.
%
% Copyright, Sleep Well. https://www.sleepwellpsg.com
%
vers = '2.1.5';
if nargin < 3
error('eegplugin_PAA requires 3 arguments');
end
% add plugin folder to path
if exist('pop_PAA.m','file')
p = which('eegplugin_PAA');
p = p(1:findstr(p,'eegplugin_PAA.m')-1);
addpath(p);
end
% find tools menu
menu = findobj(fig, 'tag', 'tools');
% menu callbacks
PAA_cback = [ trystrs.no_check '[EEG,LASTCOM] = pop_PAA(EEG);' catchstrs.add_to_hist trystrs.no_check '[ALLEEG EEG CURRENTSET] = pop_newset(ALLEEG, EEG, CURRENTSET);eeglab redraw;' catchstrs.add_to_hist ];
% create menu
uimenu(menu, 'Label', 'Period Amplitude Analysis', 'CallBack', PAA_cback);