testscript

PURPOSE ^

SYNOPSIS ^

function testscript(pname,winlocdetrend,pftest,wintrig,movingwin,tapers,pad,fpass,err,fscorr)

DESCRIPTION ^

 This script runs a sequence of analysis steps using the test
 data contained in data. The data consists of a single tetrode
 recording from macaque area LIP during a memory saccade experiment
 a la Pesaran et al (2002). The data is already separated into
 spikes and LFPs. LFPs are contained in the file *.ds.au, the spikes
 are contained in *_ev.mat and the behavioural information is in
 *.bev.mat. The sampling frequency of the LFP data is 1kHz
 Inputs:
 pname: path name for test data
 winlocdetrend: moving window for local detrending.
             Default [2 1] secs.
 pftest: p value for ftest. Default-0.001.
 wintrig: window of data to be used for event triggered spectrogram. 
      Default [1.5 1.5] a window starting 1.5 sec before and ending 1.5
      sec after event
          after the events.
 movingwin: moving window used to compute spectrograms. 
             Default [0.5 0.05] secs. 
 tapers: parameters for calculating prolates [NW K] with K<2NW-1 
         Default [3 5].
 pad: pad factor for fft used to calculate spectra. Use low integer 2,3
 etc. Default pad=2 i.e. for data with length 500 calculate fft using 2048
 points, for data with length 1000 calculate fft using 4096 points.
 fpass: band of frequencies for which spectral quantities are estimated.
        Default: [0 100] Hz.
 err: parameters for error calculation [0] - no error; 
      [1 p] - Theoretical confidence intervals, where p is a p value
      [2 p] - Jackknife confidence intervals, where p is a p value
      Default - [1 0.05]
 fscorr: whether or not to include finite size corrections for the 
         spikes (0-no corrections; 1 include corrections). Default 1.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function testscript(pname,winlocdetrend,pftest,wintrig,movingwin,tapers,pad,fpass,err,fscorr)
0002 %
0003 % This script runs a sequence of analysis steps using the test
0004 % data contained in data. The data consists of a single tetrode
0005 % recording from macaque area LIP during a memory saccade experiment
0006 % a la Pesaran et al (2002). The data is already separated into
0007 % spikes and LFPs. LFPs are contained in the file *.ds.au, the spikes
0008 % are contained in *_ev.mat and the behavioural information is in
0009 % *.bev.mat. The sampling frequency of the LFP data is 1kHz
0010 % Inputs:
0011 % pname: path name for test data
0012 % winlocdetrend: moving window for local detrending.
0013 %             Default [2 1] secs.
0014 % pftest: p value for ftest. Default-0.001.
0015 % wintrig: window of data to be used for event triggered spectrogram.
0016 %      Default [1.5 1.5] a window starting 1.5 sec before and ending 1.5
0017 %      sec after event
0018 %          after the events.
0019 % movingwin: moving window used to compute spectrograms.
0020 %             Default [0.5 0.05] secs.
0021 % tapers: parameters for calculating prolates [NW K] with K<2NW-1
0022 %         Default [3 5].
0023 % pad: pad factor for fft used to calculate spectra. Use low integer 2,3
0024 % etc. Default pad=2 i.e. for data with length 500 calculate fft using 2048
0025 % points, for data with length 1000 calculate fft using 4096 points.
0026 % fpass: band of frequencies for which spectral quantities are estimated.
0027 %        Default: [0 100] Hz.
0028 % err: parameters for error calculation [0] - no error;
0029 %      [1 p] - Theoretical confidence intervals, where p is a p value
0030 %      [2 p] - Jackknife confidence intervals, where p is a p value
0031 %      Default - [1 0.05]
0032 % fscorr: whether or not to include finite size corrections for the
0033 %         spikes (0-no corrections; 1 include corrections). Default 1.
0034 if nargin < 1;
0035     error('Need path name for data');
0036 end;
0037 if nargin < 2;
0038     winlocdetrend=[2 1];
0039 end;
0040 if nargin < 3;
0041     pftest=0.001;
0042 end;
0043 if nargin < 4;
0044     wintrig=[1.5 1.5];
0045 end;
0046 if nargin < 5;
0047     movingwin=[0.5 0.05];
0048 end;
0049 if nargin < 6;
0050     tapers=[5 9];
0051 end;
0052 if nargin < 7;
0053     pad=2;
0054 end;
0055 if nargin < 8;
0056     fpass=[0 100];
0057 end;
0058 if nargin < 9;
0059     err=[1 0.05];
0060 end;
0061 if nargin < 10;
0062     fscorr=0;
0063 end;
0064 %
0065 % Load data
0066 %
0067 [dc,Fs]=auread([pname 'lmem5321.lp200.ds.au']);
0068 [NT,C]=size(dc);
0069 eval(['load ' pname '\lmem5321_ev.mat']);
0070 eval(['load ' pname 'lmem5321.bev.mat']);
0071 cueon=tr_times+vt1;
0072 indx=find(status==1 & targ==5); % successful trials to the preferred direction
0073 E1=cueon(indx);
0074 indx=find(status==1 & targ==1); % successful trials to the anti-preferred direction
0075 E2=cueon(indx);
0076 % Note that these times are in seconds
0077 
0078 %
0079 % Performing local detrending
0080 %
0081 display('Performing local detrending');
0082 dcld=locdetrend(dc(1:10000,:),Fs,winlocdetrend);
0083 figure;
0084 subplot(211);plot(dc(1:10000,1)); title('Original data'); ylim([-1 1]);hold on;
0085 subplot(212);plot(dcld(1:10000,1),'r'); ylim([-1 1]);title('Detrended data');
0086 dc=detrend(dc);
0087 pause
0088 
0089 display('Performing Ftest for lines');
0090 figure;
0091 for c=1:C;
0092     figure(1);
0093     subplot(C,1,c);
0094     dtmp=dc(1:1000,c)+0.05*sin(2*pi*60*[1:1000]'/1000); % Putting in a 60 Hz oscillation
0095     ftestc(dtmp,tapers,Fs,fpass,pad,pftest);
0096     dtmplr=rmlinesc(dtmp,tapers, Fs, fpass, pad, pftest);
0097     [S1,f]=mtspectrumc(dtmp,tapers,pad,Fs,fpass);
0098     [S2,f]=mtspectrumc(dtmplr,tapers,pad,Fs,fpass);
0099     figure(2); 
0100     subplot(C,1,c);
0101     plot(f,10*log10(S1),f,10*log10(S2));
0102     legend('original spectrum','spectrum with line removed');
0103 end;
0104 pause
0105 
0106 %
0107 % Analysis of LFP
0108 %
0109 dctr1=createdatamatc(dc(:,1),E1(1:end-1),Fs,wintrig);
0110 dctr2=createdatamatc(dc(:,1),E2(1:end-1),Fs,wintrig);
0111 figure;
0112 subplot(211);
0113 [V1,t,Err] = evoked(dctr1,Fs,[],0.005); title('Preferred');
0114 subplot(212);
0115 [V2,t,Err] = evoked(dctr2,Fs,[],0.005); title('Anti-preferred');
0116 pause
0117 
0118 trialave=1;
0119 display('Calculating triggered LFP spectra for preferred and anti-preferred directions');
0120 [S1,f,Serr1]=mtspectrumtrigc(dc(:,1),E1,wintrig,tapers,pad,Fs,fpass,err,trialave);
0121 [S2,f,Serr2]=mtspectrumtrigc(dc(:,1),E2,wintrig,tapers,pad,Fs,fpass,err,trialave);
0122 figure;
0123 plotsigdiff(S1',Serr1,S2',Serr2,'l',1,f);
0124 pause;
0125 
0126 [S1,t,f,Serr1]=mtspecgramtrigc(detrend(dc(:,1)),E1,wintrig,movingwin,tapers,pad,Fs,fpass,err,trialave);
0127 [S2,t,f,Serr2]=mtspecgramtrigc(detrend(dc(:,1)),E2,wintrig,movingwin,tapers,pad,Fs,fpass,err,trialave);
0128 indx=find(f>15);
0129 figure;
0130 plotsigdiff(S1(:,indx),Serr1(:,:,indx),S2(:,indx),Serr2(:,:,indx),'l',t,f(indx));
0131 pause
0132 
0133 display('Calculating coherence between LFP channels');
0134 dctr11=createdatamatc(dc(:,2),E1(1:end-1),Fs,wintrig);
0135 [C,phi,f,confC,phierr]=coherencyc(dctr1,dctr11,tapers,pad,Fs,fpass,err,trialave);
0136 figure; 
0137 plotsig(C',confC,1,f); title('Coherence between two LFP channels where significant');pause
0138 display('Done with LFP analyses');
0139 
0140 display('Starting analysis of spiking activity');
0141 %
0142 % Creating a structural array of spike times');
0143 %
0144 spnum=unique(ev(:,3));
0145 dsp(1:length(spnum))=struct('times',[]);
0146 maxtime=0;
0147 for n=1:length(spnum);
0148     sp=spnum(n);
0149     indx=find(ev(:,3)==sp);
0150     dsp(n).times=[dsp(n).times; ev(indx,4)];
0151     maxtime=max(maxtime, max(dsp(n).times));
0152 end;
0153 t=[0:1/Fs:maxtime];
0154 %
0155 % Binning spikes and creating event triggered data matrices (structures)
0156 %
0157 [dN,tt]=binspikes(dsp,Fs,t);
0158 %
0159 % Plotting the psth
0160 %
0161 figure;
0162 for m=1:length(spnum);
0163     dsptr=createdatamatpt(dsp(m),E1,Fs,wintrig);
0164     subplot(length(spnum),2,2*m-1);
0165     [R,t,E]=psth(dsptr);
0166     pause
0167     dsptr=createdatamatpt(dsp(m),E2,Fs,wintrig);
0168     subplot(length(spnum),2,2*m); 
0169     [R,t,E] = psth(dsptr);
0170     pause
0171 end;
0172 %
0173 % Input which cell to analyse
0174 %
0175 n=input('Give me a cell number to analyse\n');
0176 
0177 display(['Calculating triggered spectra for cell ' num2str(n)]);
0178 
0179 dsptr1=createdatamatpt(dsp(n),E1(1:end-1),Fs,wintrig); % data triggered to events
0180 dNtr1=createdatamatpb(dN(:,n),E1(1:end-1),Fs,wintrig,tt); % data triggered to events
0181 dsptr2=createdatamatpt(dsp(n),E2(1:end-1),Fs,wintrig); % data triggered to events
0182 dNtr2=createdatamatpb(dN(:,n),E2(1:end-1),Fs,wintrig,tt); % data triggered to events
0183 %
0184 % Spectra
0185 %
0186 [S1,f,R1,Serr1]=mtspectrumtrigpt(dsp(n),E1,wintrig,tapers,pad,Fs,fpass,err,trialave);
0187 [S2,f,R2,Serr2]=mtspectrumtrigpt(dsp(n),E2,wintrig,tapers,pad,Fs,fpass,err,trialave);
0188 [S3,f3,R3]=mtspectrumtrigpb(dN(:,n),E1,wintrig,tapers,pad,Fs,fpass,[],trialave);
0189 [S4,f4,R4]=mtspectrumtrigpb(dN(:,n),E2,wintrig,tapers,pad,Fs,fpass,[],trialave);
0190 figure;
0191 plotsigdiff(S1',Serr1,S2',Serr2,'l',1,f);
0192 subplot(311);hold on; line(get(gca,'xlim'),10*log10(R1),'Color','r');
0193 plot(f3,10*log10(S3),'k-.');
0194 subplot(312);hold on;line(get(gca,'xlim'),10*log10(R2),'Color','r');
0195 plot(f4,10*log10(S4),'k-.');
0196 pause
0197 
0198 [S1,t,f,R1,Serr1]=mtspecgramtrigpt(dsp(n),E1,wintrig,movingwin,tapers,pad,Fs,fpass,err,trialave);
0199 [S2,t,f,R2,Serr2]=mtspecgramtrigpt(dsp(n),E2,wintrig,movingwin,tapers,pad,Fs,fpass,err,trialave);
0200 figure;
0201 subplot(211); imagesc(t,f,10*log10(S1)'); axis xy; colorbar;xlabel('Time s'); ylabel('Frequency Hz'); title('spikes: preferred direction');
0202 subplot(212); imagesc(t,f,10*log10(S2)'); axis xy; colorbar;xlabel('Time s'); ylabel('Frequency Hz'); title('spikes:anti-Preferred');
0203 pause
0204 
0205 % [S1,t,f,R1,Serr1]=mtspecgramtrigpb(dN(:,n),E1,wintrig,movingwin,tapers,pad,Fs,fpass,err);
0206 % [S2,t,f,R2,Serr2]=mtspecgramtrigpb(dN(:,n),E2,wintrig,movingwin,tapers,pad,Fs,fpass,err);
0207 % figure;
0208 % subplot(211); imagesc(t,f,10*log10(S1)'); axis xy; colorbar;xlabel('Time s'); ylabel('Frequency Hz'); title('Preferred');
0209 % title('spikes: preferred from binned counts');
0210 % subplot(212); imagesc(t,f,10*log10(S2)'); axis xy; colorbar;xlabel('Time s'); ylabel('Frequency Hz'); title('Anti-Preferred');
0211 % title('spikes: antipreferred from binned counts');
0212 display('Done with spike analyses');
0213 pause;
0214 
0215 display('Calculating spike-field coherence');
0216 [Cp,phi,f,confCp,phierr]=coherencycpt(dctr1,dsptr1,tapers,pad,Fs,fpass,err,trialave);
0217 [Ca,phi,f,confCa,phierr]=coherencycpt(dctr2,dsptr2,tapers,pad,Fs,fpass,err,trialave);
0218 subplot(211);plot(f,Cp);line(get(gca,'xlim'),[confCp,confCp],'Color','r');xlabel('Frequency Hz'); ylabel('|C|');
0219 title('Preferred direction trials');
0220 subplot(212);plot(f,Ca);line(get(gca,'xlim'),[confCa,confCa],'Color','r');xlabel('Frequency Hz'); ylabel('|C|');
0221 title('Anti-Preferred direction trials');
0222 
0223 [Cp,phi,t,f,confCp,phierr]=cohgramcpt(dctr1,dsptr1,movingwin,tapers,pad,Fs,fpass,err,trialave);
0224 [Ca,phi,t,f,confCa,phierr]=cohgramcpt(dctr2,dsptr2,movingwin,tapers,pad,Fs,fpass,err,trialave);
0225 % subplot(211);plotsig(Cp,confCp,t,p);xlabel('t'); ylabel('f');
0226 % title('Preferred direction trials');
0227 % subplot(212);plot(f,Ca);line(get(gca,'xlim'),[confCa,confCa],'Color','r');xlabel('Frequency Hz'); ylabel('|C|');
0228 % title('Anti-Preferred direction trials');
0229 
0230 
0231 % [Cp,phi,f,confCp,phierr]=coherencycpb(dctr1,dNtr1,tapers,pad,Fs,fpass,err,trialave);
0232 % [Ca,phi,f,confCa,phierr]=coherencycpb(dctr2,dNtr2,tapers,pad,Fs,fpass,err,trialave);
0233 % figure;
0234 % subplot(211);plot(f,Cp);line(get(gca,'xlim'),[confCp,confCp],'Color','r');xlabel('Frequency Hz'); ylabel('|C|');
0235 % title('Preferred direction trials');
0236 % subplot(212);plot(f,Ca);line(get(gca,'xlim'),[confCa,confCa],'Color','r');xlabel('Frequency Hz'); ylabel('|C|');
0237 % title('Anti-Preferred direction trials');

Generated on Tue 24-Aug-2004 15:55:33 by m2html © 2003