-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathpsr_lfp_combine_freq.m
68 lines (59 loc) · 1.77 KB
/
psr_lfp_combine_freq.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
function timefreq = psr_lfp_combine_freq(timefreq_array)
% PSR_LFP_COMBINE_FREQ - Combine multiple power spectrum structures into one
%
% Syntax: timefreq = psr_lfp_combine_freq(timefreq_array)
%
% Inputs:
% timefreq_array - Cell array of output structures from PSR_LFP_TFA
%
% Outputs:
% timefreq - Single data structure containing the data from each element
% of the input cell array
%
% See also: PSR_LFP_TFA
% PASER: Processing and Analysis Schemes for Extracellular Recordings
% https://github.com/tbrouns/paser
% Author: Terence Brouns
% Radboud University, Neurophysiology Dept.
% E-mail address: [email protected]
% Date: 2018
%------------- BEGIN CODE --------------
nBlocks = length(timefreq_array);
timefreq = timefreq_array{1};
if (isempty(timefreq)); return; end
nDims = ndims(timefreq.powspctrm);
% Initialize
sz = zeros(1,nDims);
sz(1) = length(timefreq_array);
for iBlock = 1:nBlocks
for iDim = 2:nDims
if (isfield(timefreq_array{iBlock},'powspctrm'))
n = size(timefreq_array{iBlock}.powspctrm,iDim);
if (n > sz(iDim)); sz(iDim) = n; end
end
end
end
timefreq.powspctrm = NaN(sz);
% Insert data
itr = 1;
for iBlock = 1:nBlocks
if (isfield(timefreq_array{iBlock},'powspctrm'))
x = timefreq_array{iBlock}.powspctrm;
sz1 = size(x, 1);
sz2 = size(x,nDims);
I = itr : itr + sz1 - 1;
if (nDims == 4); timefreq.powspctrm(I,:,:,1:sz2) = x;
else, timefreq.powspctrm(I,:, 1:sz2) = x;
end
itr = itr + sz1;
end
end
% Change time vector
if (isfield(timefreq,'time'))
T = timefreq.time;
dt = mean(diff(mean(T,1)));
n = size(timefreq.powspctrm,nDims);
t = T(1):dt:(n-1)*dt+T(1);
timefreq.time = t;
end
end