Skip to content

Commit

Permalink
Update coupling2.m
Browse files Browse the repository at this point in the history
  • Loading branch information
Mac Shine authored Aug 15, 2017
1 parent 127d1c4 commit bdfeaa5
Showing 1 changed file with 15 additions and 38 deletions.
53 changes: 15 additions & 38 deletions coupling2.m
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@



function mtd = coupling2(data,window,direction,trim)
%COUPLING2 Time-resolved connectivity
function mtd = coupling(data,window,direction,trim)
%COUPLING Time-resolved connectivity
%
% MTD = coupling2(data,window);
% MTD = coupling2(data,window,direction);
% MTD = coupling2(data,window,direction,trim);
% MTD = coupling(data,window);
% MTD = coupling(data,window,direction);
% MTD = coupling(data,window,direction,trim);
%
% Creates a functional coupling metric from an input matrix 'data'
% data: should be organized in 'time x nodes' matrix
Expand All @@ -28,90 +28,67 @@
% Outputs:
% MTD,
% time-varying connectivity matrix
%
%
%
%
%



if isempty(direction)
% check inputs and define variables

if nargin==2
direction=0; trim=0;
elseif nargin==2
trim=0;
end

if isempty(trim)
trim=0;
end

%define variables
[ts,nodes] = size(data);

%calculate temporal derivative
td = diff(data);


%standardize data
data_std = std(td);


for i = 1:nodes

td(:,i) = td(:,i) / data_std(1,i);

td(:,i) = td(:,i) / data_std(1,i);
end


% [...] = zscore(X,FLAG,DIM) standardizes X by working along the dimension
% DIM of X. Pass in FLAG==0 to use the default normalization by N-1, or 1
% to use N.
% DIM of X. Pass in FLAG==0 to use the default normalization by N-1, or 1 to use N.


%functional coupling score

fc = bsxfun(@times,permute(td,[1,3,2]),permute(td,[1,2,3]));



%temporal smoothing (credit: T. C. O'Haver, 2008.)

mtd_temp = zeros(nodes,nodes,ts-1);



for j = 1:nodes
for k = 1:nodes
mtd_temp(j,k,:) = smooth(squeeze(fc(:,j,k)),window);
end
end


%window type
%window type (0 = middle; 1 = forward facing)

mtd = zeros(nodes,nodes,ts);

if direction == 1

mtd(:,:,1:ts-round(window/2+1)) = mtd_temp(:,:,round(window/2+1):end);

elseif direction == 0

mtd(:,:,1:ts-1) = mtd_temp;

end



%trim ends?
%trim ends (0 = no; 1 = yes)?

if trim == 1 && direction == 0

mtd(:,:,ts-round(window/2):end) = [];
mtd(:,:,1:round(window/2)) = [];

elseif trim == 1 && direction == 1

mtd(:,:,(ts-window):end) = [];

end

end
Expand Down

0 comments on commit bdfeaa5

Please sign in to comment.