FieldShift - Estimate firing field shifts between two conditions. For each place cell, the absolute field shift between the two conditions is estimated as the mode of the spatial cross-correlogram between the respective firing fields. This value is then divided by the average field size across conditions, yielding a relative shift. This measures by how much the field moves between the two conditions, in proportion to the field size. Current implementation is only for 1D environments. USAGE [relativeShift,absoluteShift,xc] = FieldShift(control,test,<options>) control firing fields in control condition (MxN: M fields, N bins) test firing fields in test condition <options> optional list of property-value pairs (see table below) ========================================================================= Properties Values ------------------------------------------------------------------------- 'type' 'linear' for linear tracks (default), 'circular' otherwise 'show' plot results (default = 'off') =========================================================================
0001 function [relativeShift,absoluteShift,xc] = FieldShift(control,test,varargin) 0002 0003 %FieldShift - Estimate firing field shifts between two conditions. 0004 % 0005 % For each place cell, the absolute field shift between the two conditions is 0006 % estimated as the mode of the spatial cross-correlogram between the 0007 % respective firing fields. 0008 % 0009 % This value is then divided by the average field size across conditions, 0010 % yielding a relative shift. This measures by how much the field moves between 0011 % the two conditions, in proportion to the field size. 0012 % 0013 % Current implementation is only for 1D environments. 0014 % 0015 % USAGE 0016 % 0017 % [relativeShift,absoluteShift,xc] = FieldShift(control,test,<options>) 0018 % 0019 % control firing fields in control condition (MxN: M fields, N bins) 0020 % test firing fields in test condition 0021 % <options> optional list of property-value pairs (see table below) 0022 % 0023 % ========================================================================= 0024 % Properties Values 0025 % ------------------------------------------------------------------------- 0026 % 'type' 'linear' for linear tracks (default), 'circular' otherwise 0027 % 'show' plot results (default = 'off') 0028 % ========================================================================= 0029 % 0030 0031 % Copyright (C) 2012 by Michaƫl Zugaro 0032 % 0033 % This program is free software; you can redistribute it and/or modify 0034 % it under the terms of the GNU General Public License as published by 0035 % the Free Software Foundation; either version 3 of the License, or 0036 % (at your option) any later version. 0037 0038 % Defaults 0039 type = 'linear'; 0040 show = 'off'; 0041 0042 % Check number of parameters 0043 if nargin < 3 | mod(length(varargin),2) ~= 0, 0044 error('Incorrect number of parameters (type ''help <a href="matlab:help FieldShift">FieldShift</a>'' for details).'); 0045 end 0046 0047 % Check parameter sizes 0048 if ~isdmatrix(control) || ~isdmatrix(test), 0049 error('Both sets of firing fields should be MxN matrices (type ''help <a href="matlab:help FieldShift">FieldShift</a>'' for details).'); 0050 end 0051 if ~all(size(control)==size(test)), 0052 error('Both sets of firing fields should have the same sizes (type ''help <a href="matlab:help FieldShift">FieldShift</a>'' for details).'); 0053 end 0054 0055 % Parse parameter list 0056 for i = 1:2:length(varargin), 0057 if ~ischar(varargin{i}), 0058 error(['Parameter ' num2str(i+2) ' is not a property (type ''help <a href="matlab:help FieldShift">FieldShift</a>'' for details).']); 0059 end 0060 switch(lower(varargin{i})), 0061 case 'type', 0062 type = varargin{i+1}; 0063 if ~isastring(type,'linear','circular'), 0064 error('Incorrect value for property ''type'' (type ''help <a href="matlab:help FieldShift">FieldShift</a>'' for details).'); 0065 end 0066 case 'show', 0067 show = varargin{i+1}; 0068 if ~isastring(show,'on','off'), 0069 error('Incorrect value for property ''show'' (type ''help <a href="matlab:help FieldShift">FieldShift</a>'' for details).'); 0070 end 0071 otherwise, 0072 error(['Unknown property ''' num2str(varargin{i}) ''' (type ''help <a href="matlab:help FieldShift">FieldShift</a>'' for details).']); 0073 end 0074 end 0075 0076 % Compute cross-correlations between fields 0077 [m,n] = size(control); 0078 [xc,mode] = XCorr1(test,control,'type',type); % test vs control yields xc>0 for rightward shift 0079 0080 % Compute mean field sizes across control and repeat, and across control and test 0081 fieldSize = mean([sum(control>0,2) sum(test>0,2)],2)/n; 0082 % Compute field shift as the distance relative to size 0083 relativeShift = mode ./ fieldSize; 0084 absoluteShift = mode; 0085 0086 % Find peak positions (optimized code, uneasy to read) 0087 [y,x] = find(control==repmat(max(control,[],2),1,n)); 0088 peakControl = Accumulate(y,x)./Accumulate(y,1)/n; 0089 [y,x] = find(test==repmat(max(test,[],2),1,n)); 0090 peakTest = Accumulate(y,x)./Accumulate(y,1)/n; 0091 0092 if strcmp(show,'on'), 0093 0094 % Plot cross-correlograms 0095 figure;subplot(1,2,1);hold on; 0096 PlotColorCurves(xc,[-1 1],0,'w--',mode,'.k'); 0097 0098 % Plot field modes in control vs test (density plot) 0099 subplot(1,2,2);hold on; 0100 nBins = 100; 0101 range = [0 1]; 0102 c = Bin(peakControl,range,nBins); 0103 t = Bin(peakTest,range,nBins); 0104 z = Accumulate([c t],1,[nBins nBins]); 0105 z = Smooth([z z;z z],3)'/n; 0106 PlotColorMap(z,'x',linspace(range(1),2*range(2),2*n),'y',linspace(range(1),2*range(2),2*n)); 0107 xlabel('Control Peak Position'); 0108 ylabel('Test Peak Position'); 0109 clim([0 0.3*max(z(:))]); 0110 [beta,R2] = CircularRegression(peakControl*2*pi,peakTest*2*pi,'slope',1); 0111 hold on; 0112 PlotSlope(1,1,beta(1),2,'w--'); 0113 0114 end