[422372]: / functions / studyfunc / std_readspecgram.m

Download this file

139 lines (128 with data), 5.0 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
% STD_READSPECGRAM - returns the stored mean power spectrogram for an ICA component
% or a data channel in a specified dataset. The spectrogram is
% assumed to have been saved in a Matlab file,
% "[dataset_name].datspecgram", in the same
% directory as the dataset file. If this file doesn't exist,
% use STD_SPECGRAM to create it.
% Usage:
% >> [spec, times, freqs] = std_readspecgram(ALLEEG, setindx, component, timerange, freqrange);
%
% Inputs:
% ALLEEG - a vector of dataset EEG structures (may also be one dataset).
% Must contain the dataset of interest (the 'setindx' below).
% setindx - [integer] an index of an EEG dataset in the ALLEEG
% structure for which to read a component spectrum.
% component - [integer] index of the component in the selected EEG dataset
% for which to return the spectrum
% freqrange - [min max in Hz] frequency range to return
%
%
% Outputs:
% spec - the log-power spectrum of the requested ICA component in the
% specified dataset (in dB)
% freqs - vector of spectral frequencies (in Hz)
%
% See also STD_SPEC, POP_PRECLUST, STD_PRECLUST
%
% Authors: Arnaud Delorme, SCCN, INC, UCSD, February, 2008
% Copyright (C) Hilit Serby, SCCN, INC, UCSD, October 11, 2004, hilit@sccn.ucsd.edu
%
% This file is part of EEGLAB, see http://www.eeglab.org
% for the documentation and details.
%
% Redistribution and use in source and binary forms, with or without
% modification, are permitted provided that the following conditions are met:
%
% 1. Redistributions of source code must retain the above copyright notice,
% this list of conditions and the following disclaimer.
%
% 2. Redistributions in binary form must reproduce the above copyright notice,
% this list of conditions and the following disclaimer in the documentation
% and/or other materials provided with the distribution.
%
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
% AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
% IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
% ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
% LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
% CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
% SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
% INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
% CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
% ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
% THE POSSIBILITY OF SUCH DAMAGE.
function [X, t, f] = std_readspecgram(ALLEEG, abset, comp, timerange, freqrange, rmsubjmean);
if nargin < 4
timerange = [];
end
if nargin < 5
freqrange = [];
end
X = [];
if iscell(comp)
% find channel indices list
% -------------------------
chanind = [];
tmpchanlocs = ALLEEG(abset).chanlocs;
chanlabs = lower({ tmpchanlocs.labels });
for index = 1:length(comp)
tmp = strmatch(lower(comp{index}), chanlabs, 'exact');
if isempty(tmp)
error([ 'Channel ''' comp{index} ''' not found in dataset ' int2str(abset)]);
else
chanind = [ chanind tmp ];
end
end
filename = fullfile( ALLEEG(abset).filepath,[ ALLEEG(abset).filename(1:end-3) 'datspecgram']);
prefix = 'chan';
inds = chanind;
elseif comp(1) < 0
filename = fullfile( ALLEEG(abset).filepath,[ ALLEEG(abset).filename(1:end-3) 'datspecgram']);
prefix = 'chan';
inds = -comp;
else
filename = fullfile( ALLEEG(abset).filepath,[ ALLEEG(abset).filename(1:end-3) 'icaspecgram']);
prefix = 'comp';
inds = comp;
end
for k=1:length(inds)
try,
warning backtrace off;
erpstruct = load( '-mat', filename, [ prefix int2str(inds(k)) ], 'freqs', 'times');
warning backtrace on;
catch
error( [ 'Cannot read file ''' filename '''' ]);
end
tmpdat = getfield(erpstruct, [ prefix int2str(inds(k)) ]);
if k == 1
X = zeros([size(tmpdat) length(comp)]);
end
X(:,:,k) = tmpdat;
f = getfield(erpstruct, 'freqs');
t = getfield(erpstruct, 'times');
end
% select frequency range of interest
% ----------------------------------
if ~isempty(freqrange)
maxind = max(find(f <= freqrange(end)));
minind = min(find(f >= freqrange(1)));
else
%if not, use whole spectrum
maxind = length(f);
minind = 1;
end
f = f(minind:maxind);
X = X(minind:maxind,:,:);
% select time range of interest
% -----------------------------
if ~isempty(timerange)
maxind = max(find(t <= timerange(end)));
minind = min(find(t >= timerange(1)));
else
%if not, use whole spectrum
maxind = length(t);
minind = 1;
end
t = t(minind:maxind);
X = X(:,minind:maxind,:);
return;