data_st = plot_desmtx_spectra(DesMtx,params) flist - List of SPM.mat files whose design matrices we want to plot spectra for. Parameters can be passed in for any spectral calculation method via a field in the params structure, where that field is named for the method, e.g. params.pwelch
0001 function [data_st] = plot_spm_desmtx_spectra(flist,params) 0002 % data_st = plot_desmtx_spectra(DesMtx,params) 0003 % 0004 % flist - List of SPM.mat files whose design matrices we want to plot 0005 % spectra for. 0006 % 0007 % Parameters can be passed in for any spectral calculation method via a 0008 % field in the params structure, where that field is named for the method, 0009 % e.g. params.pwelch 0010 0011 0012 % Make sure flist is a cellstr 0013 if ~iscell(flist) 0014 flist = cellstr(flist); 0015 end 0016 0017 % Loop over the SPM.mat files 0018 nfiles = length(flist); 0019 for ifile = 1:nfiles 0020 % Clear out any existing SPM structures 0021 clear SPM 0022 0023 % Load the file 0024 fprintf('Working on file: %s\n', flist{ifile}); 0025 load(flist{ifile}) 0026 0027 % Get the design matrix 0028 X = SPM.xX.X; 0029 0030 % Get the column names 0031 col_names = SPM.xX.name; 0032 0033 % Figure out which columns we are using 0034 try 0035 use_cols = ismember(col_names, params.use_regress_names); 0036 catch 0037 use_cols = 1:length(col_names); 0038 end 0039 0040 % calculate the power spectrum 0041 nrows = size(X,1); 0042 P = abs(fft(X(:,use_cols))).^2; 0043 0044 % normalize by total power 0045 P = P./repmat(sum(P),size(P,1),1); 0046 0047 data_st = P; 0048 end % for ifile= 0049