Home > NoiseTools > EXAMPLE > example2.m

example2

PURPOSE ^

Same as example1, but the data now include multiple conditions.

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

 Same as example1, but the data now include multiple conditions.
 We look for the linear combination that maximizes repeatability jointly
 for all conditions.  Data are in a cell array of matrices of dimensions 
 time*channels*trials

 Uses nt_dss0().

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % Same as example1, but the data now include multiple conditions.
0002 % We look for the linear combination that maximizes repeatability jointly
0003 % for all conditions.  Data are in a cell array of matrices of dimensions
0004 % time*channels*trials
0005 %
0006 % Uses nt_dss0().
0007 
0008 clear;
0009 disp(mfilename);
0010 help(mfilename)
0011 
0012 % create synthetic data
0013 nsamples=100*3;
0014 nchans=30;
0015 ntrials=100;
0016 noise_dim=20; % dimensionality of noise
0017 freqs=[1 2];
0018 mix1=randn(1,nchans);
0019 mix2=randn(noise_dim,nchans);
0020 for iCondition=1:2
0021     source{iCondition}=[zeros(nsamples/3,1);sin(2*pi*freqs(iCondition)*(1:nsamples/3)/(nsamples/3))';zeros(nsamples/3,1)]; 
0022     s=source{iCondition}*mix1;
0023     s=repmat(s,[1,1,100]); % evoked
0024     SNR=0.1;
0025     noise=nt_mmat(randn(nsamples,noise_dim,ntrials), mix2);
0026     data{iCondition}=noise/rms(noise(:))+SNR*s/nt_rms(s(:));
0027 end
0028 
0029 % apply DSS to clean them
0030 c0=zeros(nchans); c1=zeros(nchans);
0031 for iCondition=1:2
0032     c0=c0+nt_cov(data{iCondition});
0033     c1=c1+nt_cov(mean(data{iCondition},3));
0034 end
0035 [todss,pwr0,pwr1]=nt_dss0(c0,c1);
0036 for iCondition=1:2
0037     z{iCondition}=nt_mmat(data{iCondition},todss);
0038 end
0039 
0040 % plot results
0041 figure(1); clf
0042 subplot 231; 
0043 plot(source{1}); title('source, condition 1'); 
0044 subplot 232;
0045 plot(mean(data{1},3)); title('data');
0046 subplot 233;
0047 nt_bsplot(z{1}(:,1,:)); title('recovered'); 
0048 subplot 234; 
0049 plot(source{2}); title('source, condition 2'); 
0050 subplot 235;
0051 plot(mean(data{2},3)); title('data');
0052 subplot 236;
0053 nt_bsplot(z{2}(:,1,:)); title('recovered'); 
0054

Generated on Mon 30-Jan-2017 18:59:11 by m2html © 2005