0001 function status = make_meg_coherence(csdmfname,coherencefname,obs_labels,noise_flag);
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 if nargin < 3
0014 error('not enough input arguments');
0015 end;
0016
0017 if nargin == 3
0018 noise_flag = 'yes';
0019 end;
0020
0021 if isempty(obs_labels)
0022 obs_labels = csdmfname;
0023 end;
0024 all_bad_chan = zeros(size(csdmfname,1),100);
0025 for i = 1:size(csdmfname,1)
0026 [version, NChan_file,NMeg(i),NReference(i),NEeg(i),NAnalog(i),NBad_chan(i),bad_chan,NEpoch(i),Epoch(i),nfreq(i)] = rd_meg_csdm_hdr(csdmfname(i,:));
0027 all_bad_chan(i,1:NBad_chan(i)) = bad_chan;
0028 all_NChan(i) = 148+NReference(i)+NEeg(i) +NAnalog(i);
0029 end;
0030
0031 pfid = fopen(coherencefname,'wb');
0032 pversion = -3;
0033 nfile = size(csdmfname,1);
0034 status = wt_meg_anal_hdr(pfid,pversion,nfile,all_NChan,NMeg,NReference,NEeg,NAnalog,NBad_chan,all_bad_chan,NEpoch,Epoch,nfreq,obs_labels);
0035
0036
0037 for i = 1:nfile
0038 [ravgcsdm,iavgcsdm] = rd_meg_csdm(csdmfname(i,:));
0039 coherence_data = meg_coherence(ravgcsdm,iavgcsdm,all_NChan(i),all_bad_chan(i,1:NBad_chan(i)),NReference(i),noise_flag);
0040 fwrite(pfid,coherence_data','real*4');
0041 end;
0042
0043 fclose('all')
0044 status = 1;
0045
0046
0047
0048
0049