-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathcreateSurrogates.m
34 lines (30 loc) · 1013 Bytes
/
createSurrogates.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
function [Surrogates] = createSurrogates(opts,Data,nsur)
% Create the surrogate data for statistical testing
%
% ----------- Inputs -----------
% opts...
%
% ---------- Outputs -----------
% Surrogates = the surrogate data
%
% ------------------------------
Surrogates = NaN(size(Data,1),size(Data,2),nsur);
if opts.SurrogateMethod == 2
% Randomly shuffle data (leaving NaNs where they are)
for i = 1:size(Data,2)
ni = ~isnan(Data(:,i));
for ti = 1:nsur
Surrogates(ni,i,ti) = randsample(Data(ni,i),sum(ni));
end
end
elseif opts.SurrogateMethod == 3
% Create Iterated Amplitude Adjusted Fourier Transform surrogates
if sum(isnan(Data(:))) == 0
for i = 1:size(Data,2)
Surrogates(:,i,:) = IAAFTsur(Data(:,i),nsur);
end
else
% IAAFT surrogates requires gap-free data
logwrite('Warning: Surrogates set to NaN. Use of IAAFT method requires gap-free data.',1);
end
end