Home > NoiseTools > EXAMPLE > example3.m

# example3

## PURPOSE

Find linear combination of LFPs that maximizes selectivity to stimulus

## SYNOPSIS

This is a script file.

## DESCRIPTION

     Find linear combination of LFPs that maximizes selectivity to stimulus
     frequency.  Data are from a 16-channel electrode array in guinea pig
     auditory cortex. Stimuli are tone pips with frequencies from 0.56 to 36
     kHz in 6% steps (97 frequencies), each presented 8 times in pseudorandom
     order.

     Uses nt_dss0().

## CROSS-REFERENCE INFORMATION

This function calls:

This function is called by:

## SOURCE CODE

    0001 % Find linear combination of LFPs that maximizes selectivity to stimulus
    0002 % frequency.  Data are from a 16-channel electrode array in guinea pig
    0003 % auditory cortex. Stimuli are tone pips with frequencies from 0.56 to 36
    0004 % kHz in 6% steps (97 frequencies), each presented 8 times in pseudorandom
    0005 % order.
    0006 %
    0007 % Uses nt_dss0().
    0008
    0009 clear;
    0010 disp(mfilename);
    0011 help(mfilename)
    0012
    0013 FNAME=[fileparts(which('nt_version')), '/DATA/Fichier_1815_lfp.mat'];
    0014 if ~exist(FNAME);
    0015     disp(['file ',FNAME,' not found, get it at http://cognition.ens.fr/Audition/adc/NoiseTools/DATA/']);
    0016     return
    0017 end
    0018
    0019 load (FNAME);   % loads LFPSampleRate, frequencies, xx
    0020 x=xx; clear xx
    0021 sr=LFPSampleRate;
    0022 [nsample,nchan,ntrial,nfreq]=size(x);
    0023 t=(0:nsample-1)'/sr;
    0024
    0025 % average over repeats, trim to first 100 ms
    0026 x=squeeze(mean(x,3)); % --> time * channels * frequency
    0027 x=x(find(t<=0.1),:,:,:);
    0028 nsample=size(x,1);
    0029 x=nt_demean(x);
    0030
    0031
    0032 % Component analysis:
    0033 % For each frequency, find the matrix that defines the linear combination of channels that
    0034 % maximizes response at that frequency relative to all others
    0035 to_otc=zeros(nchan,nfreq);
    0036 c0=nt_cov(x);
    0037 for iBias=1:nfreq
    0038     c1=nt_cov(x(:,:,iBias));
    0039     [todss]=nt_dss0(c0,c1);
    0040     todss=todss(:,1); % keep best
    0041     to_otc(:,iBias)=todss;
    0042 end
    0043
    0044 % apply that matrix to get components
    0045 otc=zeros(nsample,nfreq,nfreq);
    0046 for iBias=1:nfreq
    0047     z=nt_mmat(x,to_otc(:,iBias));
    0048     otc(:,iBias,:)=z; % optimally tuned component (time*bias*freq)
    0049 end
    0050
    0051 % for convenience, flip signs so all components are similar
    0052 a=nt_unfold(otc);
    0053 aa=nt_pca(a);
    0054 for iBias=1:nfreq
    0055     if aa(:,1)'*a(:,iBias)<0
    0056         otc(:,iBias,:)=-otc(:,iBias,:);
    0057         to_otc(:,iBias)=-to_otc(:,iBias);
    0058     end
    0059 end
    0060
    0061
    0062
    0063 % Display results.
    0064
    0065 % Tuning curves for electrodes and components
    0066
    0067 % RMS over time --> stim bias freq * stim freq
    0068 zz=squeeze(sqrt(mean(otc.^2,1)));
    0069 zz=nt_normcol(zz);
    0070
    0071 % same for electrode signals --> stim freq * electrodes
    0072 xx=squeeze(sqrt(mean(x.^2)))';
    0073 xx=nt_normcol(xx);
    0074
    0075 figure(1); clf
    0076 subplot 211
    0077 nt_imagescc(xx'); title('electrode tuning curves');
    0078 xlabel('stim freq (.56 - 36 kHz)');
    0079 ylabel('electrode');
    0080
    0081 subplot 212
    0082 nt_imagescc(zz); title('optimally tuned components');
    0083 xlabel('stim freq (.56 - 36 kHz)');
    0084 ylabel('bias freq (.56 - 36 kHz)');
    0085
    0086
    0087 figure(2); clf
    0088 plot([xx(:,11), zz(:,70)]);
    0089 xlabel('stim freq (.56 - 36 kHz)');
    0090 nt_linecolors([],[1 3]);
    0091 legend('electrode #11','component #70', 'location', 'northwest'); legend boxoff
    0092 title('example tuning curves');
    0093
    0094 figure(3); clf
    0095 subplot 121;
    0096 nt_imagescc(squeeze(x(:,11,:)))
    0097 xlabel('stim freq (.56 - 36 kHz)');
    0098 ylabel('time (0-100ms)');
    0099 title('electrode 11');
    0100 subplot 122;
    0101 nt_imagescc(squeeze(otc(:,72,:)))
    0102 xlabel('stim freq (.56 - 36 kHz)');
    0103 ylabel('time (0-100ms)');
    0104 title('component 72');
    0105
    0106 figure(4); clf
    0107 nt_imagescc(to_otc)
    0108 xlabel('bias freq (.56 - 36 kHz)');
    0109 ylabel('electrode');
    0110 title('weights for each component');
    0111