Home > marsbar > @mardo > ui_ft_design_data.m

ui_ft_design_data

PURPOSE ^

method plots FT of design and data to graphics window

SYNOPSIS ^

function ui_ft_design_data(D, mY, e_s, opts)

DESCRIPTION ^

 method plots FT of design and data to graphics window
 FORMAT ui_ft_design_data(D, mY, e_s, opts)
 
 Inputs
 D           - design object
 mY          - marsy data object
 e_s         - event specification (session no, event no)
 opts        - struct containing optional fields
               'event_name' - name for the event
               'filter' - apply design filter
               'fig'    - figure handle to plot to

 $Id$

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function ui_ft_design_data(D, mY, e_s, opts)
0002 % method plots FT of design and data to graphics window
0003 % FORMAT ui_ft_design_data(D, mY, e_s, opts)
0004 %
0005 % Inputs
0006 % D           - design object
0007 % mY          - marsy data object
0008 % e_s         - event specification (session no, event no)
0009 % opts        - struct containing optional fields
0010 %               'event_name' - name for the event
0011 %               'filter' - apply design filter
0012 %               'fig'    - figure handle to plot to
0013 %
0014 % $Id$
0015   
0016 if ~is_fmri(D)
0017   disp('Need an FMRI design for design/data plot');
0018   return
0019 end
0020 if nargin < 2
0021   error('Need data to plot against');
0022 end
0023 mY = marsy(mY);
0024 if n_time_points(mY) ~= n_time_points(D)
0025   error('Design and data have different number of rows');
0026 end
0027 
0028 if nargin < 3, e_s = []; end
0029 if nargin < 4, opts = []; end
0030 
0031 e_n = 'Event';
0032 if isempty(e_s)
0033   % Setup input window
0034   [Finter,Fgraph,CmdLine] = spm('FnUIsetup','Design filter', 1);
0035   [e_s e_n] = ui_get_event(D);
0036 end
0037 if isfield(opts, 'fig')
0038   Fgraph = opts.fig; 
0039 else 
0040   Fgraph = spm_figure('GetWin');
0041 end
0042 e_n_tmp = mars_struct('getifthere', opts, 'event_name');
0043 if ~isempty(e_n_tmp)
0044   e_n = e_n_tmp;
0045 end
0046 
0047 s = e_s(1);
0048 e = e_s(2);
0049 
0050 % Get the regressors and data
0051 X         = design_matrix(D);
0052 R         = X(:, event_cols(D,e_s));
0053 Y         = summary_data(mY);
0054 r         = block_rows(D);
0055 r         = r{s};
0056 R         = R(r,:);
0057 Y         = Y(r,:);
0058 
0059 % Filter data if requested
0060 if isfield(opts, 'filter')
0061     R = apply_filter(D, R, struct('sessions', s));
0062     Y = apply_filter(D, Y, struct('sessions', s));
0063 end 
0064 
0065 TR        = tr(D);
0066 if isempty(TR)
0067   b_len = 1; 
0068   b_str   = 'cycles per time point';
0069 else
0070   b_len = TR; 
0071   b_str   = 'Hz';
0072 end
0073 q         = length(r);
0074 Hz        = [0:(q - 1)]/(q * b_len);
0075 q         = 2:fix(q/2);
0076 Hz        = Hz(q);
0077 
0078 figure(Fgraph)
0079 subplot(2,1,1);
0080 gX    = abs(fft(R)).^2;
0081 gX    = gX*diag(1./sum(gX));
0082 gX    = gX(q,:);
0083 plot(Hz, gX);
0084 xlabel(sprintf('Frequency (%s)', b_str))
0085 ylabel('Relative spectral density')
0086 t_str = sprintf('Regressors for %s: block %d', e_n, e_s(1));
0087 title(t_str, 'interpreter', 'none');
0088 axis tight
0089 
0090 subplot(2,1,2);
0091 gX    = abs(fft(spm_detrend(Y))).^2;
0092 gX    = gX*diag(1./sum(gX));
0093 gX    = gX(q,:);
0094 plot(Hz, gX);
0095 xlabel(sprintf('Frequency (%s)', b_str))
0096 ylabel('Relative spectral density')
0097 title('Region data');
0098 legend(region_name(mY));
0099 axis tight
0100

Generated on Sat 19-Nov-2011 16:12:40 by m2html © 2005