source: misclib/filter_fmri_data.m @ 80

Last change on this file since 80 was 80, checked in by tjniskan, 10 years ago
  • Changed the historical "an2_" prefix to "aedes_" in all files. NOTE:

Any script or function relying to Aedes functions will be broken
because of this. Just do a search/replace from "an2_" to "aedes_" in
your files and all should be well...

  • Changed the name of an2_readtab.m to a more informative

aedes_readphasetable.m

File size: 1.4 KB
Line 
1function filter_fmri_data()
2
3if nargin==0
4  % Prompt for the input file
5  [fname,fpath,findex] = uigetfile({'*.nii','4D NIfTI Files (*.nii)';...
6        '*.*','All Files (*.*)'},'Select 4D NIfTI file');
7  if isequal(fname,0)
8        % Canceled
9        return
10  end
11  infile = fullfile(fpath,fname);
12end
13
14if nargin==0
15  % Prompt for the output file
16  [fn,fp] = uiputfile({'*.nii','NIfTI files (*.nii)';...
17        '*.*','All Files (*.*)'},'Select output file',...
18        '4D_nifti.nii');
19  if isequal(fn,0)
20        % Canceled
21        return
22  end
23  outfile = fullfile(fp,fn);
24end
25
26% Read the data
27data = aedes_read_nifti(infile);
28if length(size(data.FTDATA))<4
29  error('Input data has to be 4D data!')
30end
31
32% High-pass cutoff
33hp_co = 0.009;
34lp_co = 0.085;
35TR = 1.7;
36
37% High pass filter
38[B_hi,A_hi]=butter(8,hp_co/((1/TR)/2),'high');
39
40% Low-pass filter
41[B_lo,A_lo]=butter(15,lp_co/((1/TR)/2),'low');
42
43% Waitbar
44wbh=aedes_wbar(0,'Filtering image data...');
45
46counter=1;
47sz=size(data.FTDATA);
48nVox = prod(sz(1:3));
49for ii=1:size(data.FTDATA,1)
50  for kk=1:size(data.FTDATA,2)
51        for zz=1:size(data.FTDATA,3)
52          tmp = squeeze(double(data.FTDATA(ii,kk,zz,:)));
53          data.FTDATA(ii,kk,zz,:) = filtfilt(B_lo,A_lo,filtfilt(B_hi,A_hi,tmp))+mean(tmp);
54          aedes_wbar(counter/nVox,wbh)
55          counter=counter+1;
56        end
57  end
58end
59close(wbh)
60
61
62% Write new 4D NIfTI  image
63cwh = aedes_calc_wait(sprintf('Writing 4D NIfTI file:\n%s',outfile));
64aedes_write_nifti(data,outfile);
65delete(cwh)
66
67
Note: See TracBrowser for help on using the repository browser.

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