FindDeltaWaves - Find cortical delta waves (1-6Hz waves). USAGE delta = FindDeltaWaves(filtered,<options>) filtered delta-band filtered LFP <a href="matlab:help samples">samples</a> (one channel). This must be restricted to slow wave sleep periods for the algorithm to perform best. <options> optional list of property-value pairs (see table below) ========================================================================= Properties Values ------------------------------------------------------------------------- 'thresholds' thresholds for z-scored minimum peak and trough amplitudes (default = [1 2 0 1.5], see NOTE below) 'durations' min and max wave durations in ms (default = [150 500]) ========================================================================= OUTPUT delta for each delta wave, times and z-scored amplitudes of the beginning, peak and trough of the wave, in a Nx6 matrix [start_t peak_t end_t start_z peak_z end_z] NOTE To be selected, candidate delta waves must fulfill one of two amplitude conditions. The peak and trough must both exceed a threshold, but one can compensate for the other, i.e. a large peak requires a smaller trough and vice versa. More precisely, there are two thresholds for the peak, p and P (p<P), and two for the trough, t and T (t<T). The amplitude must fulfill one of the following conditions: peak > p and trough > T or peak > P and trough > t Thresholds are given in SDs, and the above conditions relate to absolute values. SEE See also FilterLFP, FindRipples.
0001 function delta = FindDeltaWaves(filtered,varargin) 0002 0003 %FindDeltaWaves - Find cortical delta waves (1-6Hz waves). 0004 % 0005 % USAGE 0006 % 0007 % delta = FindDeltaWaves(filtered,<options>) 0008 % 0009 % filtered delta-band filtered LFP <a href="matlab:help samples">samples</a> (one channel). This must 0010 % be restricted to slow wave sleep periods for the algorithm 0011 % to perform best. 0012 % <options> optional list of property-value pairs (see table below) 0013 % 0014 % ========================================================================= 0015 % Properties Values 0016 % ------------------------------------------------------------------------- 0017 % 'thresholds' thresholds for z-scored minimum peak and trough amplitudes 0018 % (default = [1 2 0 1.5], see NOTE below) 0019 % 'durations' min and max wave durations in ms (default = [150 500]) 0020 % ========================================================================= 0021 % 0022 % OUTPUT 0023 % 0024 % delta for each delta wave, times and z-scored amplitudes of 0025 % the beginning, peak and trough of the wave, in a Nx6 0026 % matrix [start_t peak_t end_t start_z peak_z end_z] 0027 % 0028 % NOTE 0029 % 0030 % To be selected, candidate delta waves must fulfill one of two amplitude 0031 % conditions. The peak and trough must both exceed a threshold, but one can 0032 % compensate for the other, i.e. a large peak requires a smaller trough and 0033 % vice versa. 0034 % 0035 % More precisely, there are two thresholds for the peak, p and P (p<P), and 0036 % two for the trough, t and T (t<T). The amplitude must fulfill one of the 0037 % following conditions: 0038 % 0039 % peak > p and trough > T 0040 % or peak > P and trough > t 0041 % 0042 % Thresholds are given in SDs, and the above conditions relate to absolute 0043 % values. 0044 % 0045 % SEE 0046 % 0047 % See also FilterLFP, FindRipples. 0048 0049 % Copyright (C) 2012-2017 Michaƫl Zugaro, 2012-2015 Nicolas Maingret, 0050 % 0051 % This program is free software; you can redistribute it and/or modify 0052 % it under the terms of the GNU General Public License as published by 0053 % the Free Software Foundation; either version 3 of the License, or 0054 % (at your option) any later version. 0055 0056 % Default values 0057 highPeak = 2 ; % Threshold for filtered signal (number of SDs) 0058 lowPeak = 1; 0059 highTrough = 1.5; 0060 lowTrough = 0; 0061 minDuration = 150; % min time between successive zero crossings (in ms) 0062 maxDuration = 450; % max time between successive zero crossings (in ms) 0063 0064 % Check number of parameters 0065 if nargin < 1 | mod(length(varargin),2) ~= 0, 0066 error('Incorrect number of parameters (type ''help <a href="matlab:help FindDeltaWaves">FindDeltaWaves</a>'' for details).'); 0067 end 0068 0069 % Check parameter sizes 0070 if ~isdmatrix(filtered,'@2'), 0071 error('Parameter ''filtered'' is not a Nx2 matrix (type ''help <a href="matlab:help FindDeltaWaves">FindDeltaWaves</a>'' for details).'); 0072 end 0073 0074 % Parse parameter list 0075 for i = 1:2:length(varargin), 0076 if ~ischar(varargin{i}), 0077 error(['Parameter ' num2str(i+2) ' is not a property (type ''help <a href="matlab:help FindDeltaWaves">FindDeltaWaves</a>'' for details).']); 0078 end 0079 switch(lower(varargin{i})), 0080 case {'thresholds','amplitudes'}, 0081 thresholds = varargin{i+1}; 0082 if ~isdvector(thresholds,'#4'), 0083 error('Incorrect value for property ''thresholds'' (type ''help <a href="matlab:help FindDeltaWaves">FindDeltaWaves</a>'' for details).'); 0084 end 0085 lowPeak = thresholds(1); 0086 highPeak = thresholds(2); 0087 lowTrough = thresholds(3); 0088 highTrough = thresholds(4); 0089 if lowPeak > highPeak || lowTrough > highTrough, 0090 error('Inconsistent amplitude thresholds (type ''help <a href="matlab:help FindDeltaWaves">FindDeltaWaves</a>'' for details).'); 0091 end 0092 case 'durations', 0093 durations = varargin{i+1}; 0094 if ~isdvector(durations,'#2','<','>0'), 0095 error('Incorrect value for property ''durations'' (type ''help <a href="matlab:help FindDeltaWaves">FindDeltaWaves</a>'' for details).'); 0096 end 0097 if durations(2) < 1, 0098 warning('Delta wave min and max durations are less than 1 ms, assuming seconds.'); 0099 durations = durations * 1000; 0100 end 0101 minDuration = durations(1); maxDuration = durations(2); 0102 otherwise, 0103 error(['Unknown property ''' num2str(varargin{i}) ''' (type ''help <a href="matlab:help FindDeltaWaves">FindDeltaWaves</a>'' for details).']); 0104 end 0105 end 0106 0107 % Find local minima and maxima corresponding to beginning, peak and end of delta waves 0108 % This is done by finding zero crossings of the (z-scored) derivative of the signal 0109 0110 % Differentiate, filter and z-score signal 0111 z = filtered; 0112 z(:,2) = [diff(filtered(:,2));0]; 0113 z = FilterLFP(z,'passband',[0 6],'order',8); 0114 z(:,2) = zscore(z(:,2)); 0115 0116 % Find positions (in # samples) of zero crossings 0117 [up,down] = ZeroCrossings(z); 0118 down = find(down); 0119 up = find(up); 0120 if down(1) < up(1), down(1) = []; end 0121 0122 % List positions (in # samples) of successive up,down,up crossings in an Nx3 matrix 0123 n = length(up); 0124 where = [up(1:n-1) down(1:n-1) up(2:n)]; 0125 0126 % List positions but also z-scored amplitudes in an Nx6 matrix (positions then amplitudes) 0127 z = filtered; 0128 z(:,2) = zscore(filtered(:,2)); 0129 delta = z(where,:); 0130 delta = reshape(delta,size(where,1),6); 0131 0132 % Discard waves that are too long or too short 0133 duration = delta(:,3) - delta(:,1); 0134 delta(duration<minDuration/1000|duration>maxDuration/1000,:) = []; 0135 0136 % Threshold z-scored peak and trough amplitudes 0137 peak = delta(:,5); 0138 trough = delta(:,6); 0139 case1 = peak > highPeak & trough <= -lowTrough; 0140 case2 = peak >= lowPeak & trough < -highTrough; 0141 delta = delta(case1|case2,:);