-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathfirfiltsplit.m
More file actions
89 lines (79 loc) · 2.92 KB
/
firfiltsplit.m
File metadata and controls
89 lines (79 loc) · 2.92 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
% firfiltsplit() - Split data at discontinuities and forward to dc padded
% filter function
%
% Usage:
% >> EEG = firfiltsplit(EEG, b);
% >> EEG = firfiltsplit(EEG, b, causal);
% >> EEG = firfiltsplit(EEG, b, causal, usefftfilt);
%
% Inputs:
% EEG - EEGLAB EEG structure
% b - vector of filter coefficients
%
% Optional inputs:
% causal - scalar boolean perform causal filtering {default false}
% usefftfilt - scalar boolean use fftfilt frequency domain filtering
% {default false}
% chaninds - channel indices {default all}
%
% Outputs:
% EEG - EEGLAB EEG structure
%
% Note:
% This function is (in combination with fir_filterdcpadded) just a
% non-memory optimized version of the firfilt function allowing causal
% filtering. Will possibly replace firfilt in the future.
%
% Author: Andreas Widmann, University of Leipzig, 2013
%
% See also:
% fir_filterdcpadded, findboundaries
%123456789012345678901234567890123456789012345678901234567890123456789012
% Copyright (C) 2013 Andreas Widmann, University of Leipzig, widmann@uni-leipzig.de
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
function EEG = firfiltsplit(EEG, b, causal, usefftfilt, chaninds)
% Defaults
if nargin < 4 || isempty(usefftfilt)
usefftfilt = 0;
end
if nargin < 3 || isempty(causal)
causal = 0;
end
if nargin < 5 || isempty( chaninds )
chaninds = 1:size(EEG.data,1);
end
if nargin < 2
error('Not enough input arguments.');
end
% Find data discontinuities and reshape epoched data
if EEG.trials > 1 % Epoched data
EEG.data = reshape(EEG.data, [EEG.nbchan EEG.pnts * EEG.trials]);
dcArray = 1 : EEG.pnts : EEG.pnts * (EEG.trials + 1);
else % Continuous data
dcArray = findboundaries(EEG.event);
dcArray = dcArray( dcArray >= 1 & dcArray <= EEG.pnts ); % Assert DC offset events are within data range
dcArray = [ dcArray EEG.pnts + 1 ];
end
% Loop over continuous segments
for iDc = 1:(length(dcArray) - 1)
% Filter segment
EEG.data(chaninds, dcArray(iDc):dcArray(iDc + 1) - 1) = fir_filterdcpadded(b, 1, EEG.data(chaninds, dcArray(iDc):dcArray(iDc + 1) - 1)', causal, usefftfilt)';
end
% Reshape epoched data
if EEG.trials > 1
EEG.data = reshape(EEG.data, [EEG.nbchan EEG.pnts EEG.trials]);
end
end