source: misclib/fmri_corr.m @ 73

Last change on this file since 73 was 73, checked in by tjniskan, 11 years ago
  • Fixed a bug in aedes.m when viewing "voxel time-series" from generic

matrix input

  • Fixed a small issue with some arrayed experiments in an2_readfid.m

and hopefully did not break anything this time

  • Few minor corrections and changes here and there...

M misclib/fmri_filter.m
M misclib/fmri_corr.m
M an2_revision.m
M an2_fitmaps.m
M aedes.m
M plugins/resting_state_fc.m
M an2_readfid.m

File size: 1.9 KB
Line 
1function corrmap = fmri_corr(data,seed)
2
3corrmap = [];
4
5if ischar(data)
6  data=an2_data_read(data);
7  data = data.FTDATA;
8elseif isstruct(data)
9  data=data.FTDATA;
10end
11
12% Get mean time-series from seed ROIs
13seed_struct = l_Roi2seed(data,seed);
14
15
16% Calculate Pearson correlation coefficients -------------
17data_sz = ones(1,4);
18data_sz(1:ndims(data)) = size(data);
19
20for kk = 1:length(seed_struct)
21 
22  % Allocate space for ccc
23  ccc = zeros(data_sz(1:3));
24 
25  T = length(seed_struct(kk).data);
26  std_seed = std(seed_struct(kk).data,1);
27  norm_seed = seed_struct(kk).data-mean(seed_struct(kk).data);
28  seed_plane = reshape(reshape(repmat(norm_seed,...
29        [data_sz(1),data_sz(2)]),data_sz(1)*T,[]).',...
30        data_sz(1),data_sz(2),[]);
31 
32  % Loop over in-plane slices
33  for ii=1:data_sz(3)
34        tmp_data = double(squeeze(data(:,:,ii,:)));
35       
36        std_data = std(tmp_data,1,3);
37       
38        ccc(:,:,ii) = ((1/T)*sum(seed_plane.*tmp_data,3))./(std_data.*std_seed);
39  end
40 
41  % Make sure that there are no Infs or nans ...
42  ccc(find(isnan(ccc))) = 0;
43  ccc(find(isinf(ccc))) = 0;
44 
45  % Fisher's z-transform to make values normally distributed
46  zf = ccc;
47  zf = 0.5*log((1+ccc)./(1-ccc));
48 
49  % Calculate Z-scores
50  zscore = zf./(1/sqrt(T-3));
51 
52  % Construct output structure
53  corrmap(kk).ccc = ccc;
54  corrmap(kk).zf = zf;
55  corrmap(kk).zscore = zscore;
56  corrmap(kk).label = seed_struct(kk).label;
57end
58
59% Subfunctions -----------------------------------
60function seed_struct = l_Roi2seed(data,ROI)
61% Thus subfunction extracts mean seed time-series from ROI voxels
62%
63
64seed_struct = [];
65
66if isstruct(ROI)
67  for ii=1:length(ROI)
68    ind = repmat(ROI(ii).voxels{1}(:,:,:,1),[1 1 1 size(data,4)]);
69    seed_struct(ii).data = mean(reshape(double(data(ind)),[],size(data,4)));
70    seed_struct(ii).label = ROI(ii).label;
71  end
72else
73  tmp = ROI(:).';
74  seed_struct(1).data = double(tmp);
75  seed_struct(1).label = 'custom seed';
76end
77
78
79
Note: See TracBrowser for help on using the repository browser.

Powered by Trac 1.0.9.Copyright © Juha-Pekka Niskanen 2008