Home > chronux_0.5 > testscript.m

testscript

PURPOSE ^

function testscript(pname,direction,movingwin,segave,params,fscorr)

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

 function testscript(pname,direction,movingwin,segave,params,fscorr)

 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 variable dlfp, spikes from two
 neurons are in in a struct array dsp, and event information is in
 the following set of variables:

 trialtimes - start times of trials
 fixon - fixation light comes on
 fixacq - fixation acquired
 targon - target light on
 targoff - target light off
 fixoff - fixation off
 saccade - saccade

 Note that spikes and event times are in seconds and the sampling
 frequency for the LFP in this experiment was 1kHz.

 the script takes the following input argument - 
 pname - path name on your computer where the data file LIPdata is stored.
 direction - target direction to be analysed (0-7)

 The remaining parameters control various computations and are discussed
 in chronux.m - type Help chronux.m for more information.
 
 if nargin < 4;
     error('Need 6 input parameters - see help');
 end;
 if nargin < 5 | isempty(params);
    [tapers,pad,Fs,fpass,err,trialave,params]=getparams(params);
 end;
 if nargin < 6 | isempty(fscorr);
     fscorr=1;
 end;

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 % function testscript(pname,direction,movingwin,segave,params,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 variable dlfp, spikes from two
0008 % neurons are in in a struct array dsp, and event information is in
0009 % the following set of variables:
0010 %
0011 % trialtimes - start times of trials
0012 % fixon - fixation light comes on
0013 % fixacq - fixation acquired
0014 % targon - target light on
0015 % targoff - target light off
0016 % fixoff - fixation off
0017 % saccade - saccade
0018 %
0019 % Note that spikes and event times are in seconds and the sampling
0020 % frequency for the LFP in this experiment was 1kHz.
0021 %
0022 % the script takes the following input argument -
0023 % pname - path name on your computer where the data file LIPdata is stored.
0024 % direction - target direction to be analysed (0-7)
0025 %
0026 % The remaining parameters control various computations and are discussed
0027 % in chronux.m - type Help chronux.m for more information.
0028 %
0029 % if nargin < 4;
0030 %     error('Need 6 input parameters - see help');
0031 % end;
0032 % if nargin < 5 | isempty(params);
0033 %    [tapers,pad,Fs,fpass,err,trialave,params]=getparams(params);
0034 % end;
0035 % if nargin < 6 | isempty(fscorr);
0036 %     fscorr=1;
0037 % end;
0038 pname='C:\home\matlab\chronux_code\data';
0039 params.Fs=1000; % sampling frequency
0040 params.fpass=[10 100]; % band of frequencies to be kept
0041 params. tapers=[3 5]; % taper parameters
0042 params.pad=2; % pad factor for fft
0043 params.err=[2 0.05];
0044 params.trialave=1;
0045 movingwin=[0.5 0.1];
0046 segave=1;
0047 direction=5;
0048 
0049 wintrig=[5*movingwin(1) 5*movingwin(1)];
0050 winseg=2*movingwin(1);
0051 %
0052 % Load data
0053 %
0054 eval(['load ' pname '\LIPdata.mat']);
0055 % %
0056 % % Create rearranged data blocks for further analysis: We are going to
0057 % % extract segments of data centered on the target off times from the first channel of LFP data and the from one of the two spike trains
0058 % %
0059 % %
0060 % indx1=find(targets==5);indx2=find(targets==1); % trials to preferred and antipreferred direction
0061 % E1=targon(indx1); E2=targon(indx2); % target on times trials to preferred adn anti-preferred directions
0062 % dlfp1=createdatamatc(dlfp(:,1),E1,Fs,wintrig);dlfp2=createdatamatc(dlfp(:,1),E2,Fs,wintrig); % extract event triggered segments of the first LFP channel
0063 % dsp1=createdatamatpt(dsp(1),E1,wintrig); dsp2=createdatamatpt(dsp(1),E2,wintrig); % the same for one of the spike trains
0064 
0065 % compute spectrum of the first few seconds of LFP channels 1-2
0066 NT=round(10*movingwin(1));
0067 data=dlfp(1:NT,:); data1=data(:,1:2);
0068 [S,f,Serr]=mtspectrumc(data1,params);
0069 figure;
0070 plot(f,10*log10(S),f,10*log10(Serr(1,:)),f,10*log10(Serr(2,:))); xlabel('Frequency Hz'); ylabel('Spectrum');
0071 pause
0072 
0073 % compute derivative of the spectrum for the same data
0074 phi=[0 pi/2];
0075 [dS,f]=mtdspectrumc(data1,phi,params);
0076 figure;
0077 plot(f,dS(1,:),f,dS(2,:)); xlabel('frequency Hz'); ylabel('Derivatives'); legend('Time','Frequency');
0078 pause
0079 
0080 % compute coherency between  channels 1-2 and  3-4
0081 data1=data(:,1:2);data2=data(:,3:4);
0082 [C,phi,S12,S1,S2,f,confC,phierr,Cerr]=coherencyc(data1,data2,params); 
0083 figure;plot(f,C,f,Cerr(1,:),f,Cerr(2,:));xlabel('frequency'); ylabel('Coherency');
0084 pause
0085 
0086 % coherency matrix of data1
0087 [C,phi,S12,f,confC,phierr,Cerr]=cohmatrixc(data1,params);
0088 
0089 % compute spectrogram for 1-2
0090 [S,t,f,Serr]=mtspecgramc(data1,movingwin,params);
0091 figure;imagesc(t,f,10*log10(S)'); axis xy; colorbar
0092 pause
0093 
0094 % compute time-frequency derivative of the spectrogram for 1-2
0095 phi=[0 pi/2];
0096 [dS,t,f]=mtdspecgramc(data1,movingwin,phi,params);
0097 figure;subplot(211);imagesc(t,f,squeeze(dS(1,:,:))'); axis xy; colorbar;
0098 subplot(212);imagesc(t,f,squeeze(dS(2,:,:))'); axis xy; colorbar;
0099 pause
0100 
0101 % compute coherogram between 1-2 and 3-4
0102 NT=round(movingwin(1)*Fs);
0103 [C,phi,S12,S1,S2,t,f,confC,phierr,Cerr]=cohgramc(data1,data2,movingwin,params);
0104 figure;imagesc(t,f,C'); axis xy; colorbar;
0105 pause
0106 
0107 % compute segmented spectrum of 1
0108 NT=10*round(winseg*Fs);
0109 data1=dlfp(1:NT,1);
0110 [S,f,varS,C,Serr]=mtspectrumsegc(data1,winseg,params,segave);
0111 figure; subplot(211);plot(f,10*log(S)); varS
0112 imagesc(f,f,C); axis xy;colorbar;
0113 pause
0114 
0115 % compute segmented coherency between 1 and 2
0116 NT=10*round(winseg*Fs);
0117 data1=dlfp(1:NT,1); data2=dlfp(1:NT,2);
0118 [C,phi,S12,S1,S2,f,confC,phierr,Cerr]=coherencysegc(data1,data2,winseg,params);
0119 figure; subplot(311); plot(f,C);subplot(312); plot(f,10*log10(S1)); subplot(313);plot(f,10*log10(S2))
0120 pause
0121 
0122 % compute spectrum of channel 1 triggered to events E
0123 E1=targon(find(targets==direction)); 
0124 data1=dlfp(:,1); 
0125 [S,f,Serr]=mtspectrumtrigc(data1,E,wintrig,params);
0126 figure;plot(f,10*log10(S)'); axis xy; colorbar;
0127 pause
0128 
0129 % compute spectrogram of channel 1 triggered to events E
0130 E1=targon(find(targets==direction)); 
0131 data1=dlfp(:,1); 
0132 [S,t,f,Serr]=mtspecgramtrigc(data1,E,wintrig,movingwin,params);
0133 figure; imagesc(t,f,10*log10(S)'); axis xy; colorbar;
0134 pause
0135 
0136 %
0137 % Analysis - point process stored as times
0138 %
0139 
0140 % dsp contains 2 channels of spikes
0141 
0142 data=extractdatapt(dsp,[20 30]); % extract spikes occurring between 20 and 30 seconds and compute their spectrum
0143 [S,f,R,Serr]=mtspectrumpt(data,params);
0144 figure; plot(f,10*log10(S),f,10*log10(Serr(1,:)),f,10*log10(Serr(2,:)));line(get(gca,'xlim'),[10*log10(R) 10*log10(R)]);
0145 pause
0146 
0147 %
0148 % Compute the derivative of the spectrum
0149 %
0150 phi=[0 pi/2];
0151 [dS,f]=mtdspectrumpt(data,phi,params);
0152 figure; plot(f,dS);
0153 pause
0154 
0155 %
0156 % Compute the derivative of the time-frequency spectrum
0157 %
0158 data=extractdatapt(dsp,[20 30]);
0159 data1=data(1); data2=data(2);fscorr=[];t=[];
0160 [C,phi,S12,S1,S2,f,zerosp,confC,phierr,Cerr]=coherencypt(data1,data2,params);
0161 figure; plot(f,C);
0162 pause
0163 
0164 %
0165 % Compute event triggered average spectrum for one of the directions
0166 %
0167 E1=targon(find(targets==direction));
0168 data=dsp(1); 
0169 [S,f,R,Serr]=mtspectrumtrigpt(data,E1,wintrig,params);
0170 figure;plot(f,10*log10(S),f,10*log10(Serr(1,:)),f,10*log10(Serr(2,:))); line(get(gca,'xlim'),[10*log10(R) 10*log10(R)]); 
0171 pause
0172 
0173 %
0174 % Compute the matrix of coherencies
0175 %
0176 data=extractdatapt(dsp,[20 30]);
0177 [C,phi,S12,f,zerosp,confC,phierr,Cerr]=cohmatrixpt(data,params,fscorr);
0178 
0179 %
0180 % Event triggered spectrogram - first way way
0181 %
0182 data=createdatamatpt(dsp(1),E1,wintrig);
0183 [S,t,f,R,Serr]=mtspecgrampt(data,movingwin,params);
0184 figure;imagesc(t,f,10*log10(S)'); axis xy; colorbar;
0185 pause
0186 
0187 %
0188 % Derivative of the time-frequency spectrum
0189 %
0190 data=createdatamatpt(dsp(1),E1,wintrig);
0191 phi=[0 pi/2];
0192 [dS,t,f]=mtdspecgrampt(data,movingwin,phi,params);
0193 figure; subplot(211); imagesc(t,f,squeeze(dS(1,:,:))'); axis xy; colorbar;
0194 subplot(212); imagesc(t,f,squeeze(dS(2,:,:))'); axis xy; colorbar;
0195 
0196 %
0197 % Coherogram between the two spike trains
0198 %
0199 data1=createdatamatpt(dsp(1),E1,wintrig);
0200 data2=createdatamatpt(dsp(2),E1,wintrig);
0201 [C,phi,S12,S1,S2,t,f,zerosp,confC,phierr,Cerr]=cohgrampt(data1,data2,movingwin,params,fscorr);
0202 figure;imagesc(t,f,C');axis xy; colorbar
0203 pause
0204 
0205 %
0206 % Event Triggered spectrogram another way
0207 %
0208 data=dsp(1);
0209 [S,t,f,R,Serr]=mtspecgramtrigpt(data,E1,wintrig,movingwin,params);
0210 imagesc(t,f,10*log10(S)'); axis xy; colorbar
0211 %
0212 % Segmented spectrum
0213 %
0214 data=extractdatapt(dsp,[20 30]);
0215 data=data(1);
0216 [S,f,R,varS]=mtspectrumsegpt(data,winseg,params);
0217 plot(f,10*log10(S)); line(get(gca,'xlim'),[10*log10(R) 10*log10(R)]);
0218 %
0219 % Segmented coherency
0220 %
0221 data=extractdatapt(dsp,[20 30]);
0222 data1=data(1);data2=data(2);
0223 [C,phi,S12,S1,S2,f,zerosp,confC,phierr,Cerr]=coherencysegpt(data1,data2,winseg,params);
0224 figure; subplot(311); plot(f,C);subplot(312); plot(f,10*log10(S1));subplot(313); plot(f,10*log10(S2))
0225 %
0226 % Analysis - hybrid: one continous and one point process stored as times
0227 %
0228 data1=dlfp(20000:30000,1); data2=extractdatapt(dsp,[20 30],offset);data2=data2(1).times;
0229 [C,phi,S12,S1,S2,f,zerosp,confC,phierr,Cerr]=coherencycpt(data1,data2,params);
0230 figure; subplot(311); plot(f,C);subplot(312); plot(f,10*log10(S1));subplot(313); plot(f,10*log10(S2))
0231 
0232 
0233 data1=dlfp(20000:30000,1); data2=extractdatapt(dsp,[20 30],offset);data2=data2(1).times;
0234 [C,phi,S12,S1,S2,f,zerosp,confC,phierr,Cerr]=coherencysegcpt(data1,data2,winseg,params,segave,fscorr);
0235 figure; subplot(311); plot(f,C);subplot(312); plot(f,10*log10(S1));subplot(313); plot(f,10*log10(S2))
0236 
0237 
0238 data1=dlfp(20000:30000,1); data2=extractdatapt(dsp,[20 30],offset);data2=data2(1).times;
0239 [C,phi,S12,S1,S2,t,f,zerosp,confC,phierr,Cerr]=cohgramcpt(data1,data2,movingwin,params,fscorr);
0240 figure; subplot(311); imagesc(t,f,C');axis xy; colorbar; subplot(312);imagesc(t,f,10*log10(S1)');axis xy; colorbar; subplot(313); imagesc(t,f,10*log10(S2)');axis xy; colorbar
0241 
0242 
0243 %  Analysis: Binned spike counts
0244 
0245 [dN,t]=binspikes(dsp,params.Fs,[20 30]); % extract spikes occurring between 20 and 30 seconds
0246 
0247 data=dN;
0248 [S,f,R,Serr]=mtspectrumpb(data,params);
0249 plot(f,10*log10(S),f,10*log10(Serr(1,:)), f,10*log10(Serr(2,:))); line(get(gca,'xlim'),[10*log10(R) 10*log10(R)]);
0250 
0251 data=dN;
0252 phi=[0 pi/2];
0253 [dS,f]=mtdspectrumpb(data,phi,params);
0254 figure; plot(f,dS); 
0255 
0256 data=dN;
0257 data1=data(:,1); data2=data(:,2);fscorr=[];t=[];
0258 [C,phi,S12,S1,S2,f,zerosp,confC,phierr,Cerr]=coherencypb(data1,data2,params);
0259 figure; subplot(311); plot(f,C);subplot(312); plot(f,10*log10(S1)); subplot(313); plot(f,10*log10(S2));
0260 
0261 E=targon(find(targets==direction)); E=E(find(E>20 & E<450)); [dN,t]=binspikes(dsp,params.Fs,[20 500]);data=dN(:,1);
0262 [S,f,R,Serr]=mtspectrumtrigpb(data,E,wintrig,params);
0263 plot(f,10*log10(S),f,10*log10(Serr(1,:)),f,10*log10(Serr(2,:)));
0264 
0265 [dN,t]=binspikes(dsp,params.Fs,[20 30]); % extract spikes occurring between 20 and 30 seconds
0266 data=dN;
0267 [C,phi,S12,f,zerosp,confC,phierr,Cerr]=cohmatrixpb(data,params,fscorr);
0268 
0269 [dN,t]=binspikes(dsp,params.Fs,[20 30]); % extract spikes occurring between 20 and 30 seconds
0270 data=dN;
0271 [S,t,f,R,Serr]=mtspecgrampb(data,movingwin,params);
0272 imagesc(t,f,10*log10(S)'); axis xy; colorbar
0273 
0274 [dN,t]=binspikes(dsp,params.Fs,[20 30]); % extract spikes occurring between 20 and 30 seconds
0275 data=dN;
0276 [dS,t,f]=mtdspecgrampb(data,movingwin,phi,params);
0277 
0278 
0279 [dN,t]=binspikes(dsp,params.Fs,[20 30]); % extract spikes occurring between 20 and 30 seconds
0280 data=dN;
0281 data1=data(:,1); data2=data(:,2);
0282 [C,phi,S12,S1,S2,t,f,zerosp,confC,phierr,Cerr]=cohgrampb(data1,data2,movingwin,params,fscorr);
0283 
0284 [dN,t]=binspikes(dsp,params.Fs); % extract spikes
0285 dN=dN(:,1);
0286 E=E(1:9);
0287 data=dN;
0288 [S,t,f,R,Serr]=mtspecgramtrigpb(data,E,wintrig,movingwin,params);
0289 figure;imagesc(t,f,10*log10(S)'); axis xy; colorbar
0290 
0291 [dN,t]=binspikes(dsp,params.Fs,[20 30]); % extract spikes occurring between 20 and 30 seconds
0292 data=dN;
0293 data=data(:,1);
0294 [S,f,R,varS]=mtspectrumsegpb(data,winseg,params,segave,fscorr);
0295 
0296 
0297 [dN,t]=binspikes(dsp,params.Fs,[20 30]); % extract spikes occurring between 20 and 30 seconds
0298 data=dN;
0299 data1=data(:,1);data2=data(:,2);
0300 [C,phi,S12,S1,S2,f,zerosp,confC,phierr,Cerr]=coherencysegpb(data1,data2,winseg,params);
0301 
0302 %
0303 % Analysis - hybrid: one continous and one point process stored as counts
0304 %
0305 data1=dlfp(20000:30000,:);data1=data1(:,1:2); [dN,t]=binspikes(dsp,params.Fs,[20 30]); % extract spikes occurring between 20 and 30 seconds
0306 data2=dN; data2=data2(1:end-1,:);
0307 [C,phi,S12,S1,S2,f,zerosp,confC,phierr,Cerr]=coherencycpb(data1,data2,params);
0308 
0309 data1=data1(:,1); data2=data2(:,1);
0310 [C,phi,S12,S1,S2,f,zerosp,confC,phierr,Cerr]=coherencysegcpb(data1,data2,winseg,params,segave,fscorr);
0311 
0312 
0313 data1=dlfp(20000:30000,:); data1=data1(:,1:2);
0314 [dN,t]=binspikes(dsp,params.Fs,[20 30]); % extract spikes occurring between 20 and 30 seconds
0315 data2=dN;
0316 [C,phi,S12,S1,S2,t,f,zerosp,confC,phierr,Cerr]=cohgramcpb(data1,data2,movingwin,params,fscorr);
0317

Generated on Tue 16-Aug-2005 21:33:45 by m2html © 2003