Home > FMAToolbox > Analyses > NormalizeFields.m

NormalizeFields

PURPOSE ^

NormalizeFields - Normalize one or more firing fields in space and rate.

SYNOPSIS ^

function normalized = NormalizeFields(fields,varargin)

DESCRIPTION ^

NormalizeFields - Normalize one or more firing fields in space and rate.

  For each field, interpolate space in [0..1] and normalize z values
  (typically, firing rates for place fields). Z values outside the fields
  should be set to zero (see example below).

  Current implementation is only for 1D environments.

  USAGE

    normalized = NormalizeFields(fields,<options>)

    fields         firing fields (MxN: M fields, N bins)
    <options>      optional list of property-value pairs (see table below)

    =========================================================================
     Properties    Values
    -------------------------------------------------------------------------
     'rate'        'off' to disable rate normalization (default = 'on')
    =========================================================================

  EXAMPLE

    [c1,s1] = FiringCurve(positions,spikes1);
    c1.rate(~c1.field) = 0;
    c2 = FiringCurve(positions,spikes2);
    c2.rate(~c2.field) = 0;
    n = NormalizeFields([c1.rate;c2.rate]);
    average = mean(n);
    error = std(n);

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function normalized = NormalizeFields(fields,varargin)
0002 
0003 %NormalizeFields - Normalize one or more firing fields in space and rate.
0004 %
0005 %  For each field, interpolate space in [0..1] and normalize z values
0006 %  (typically, firing rates for place fields). Z values outside the fields
0007 %  should be set to zero (see example below).
0008 %
0009 %  Current implementation is only for 1D environments.
0010 %
0011 %  USAGE
0012 %
0013 %    normalized = NormalizeFields(fields,<options>)
0014 %
0015 %    fields         firing fields (MxN: M fields, N bins)
0016 %    <options>      optional list of property-value pairs (see table below)
0017 %
0018 %    =========================================================================
0019 %     Properties    Values
0020 %    -------------------------------------------------------------------------
0021 %     'rate'        'off' to disable rate normalization (default = 'on')
0022 %    =========================================================================
0023 %
0024 %  EXAMPLE
0025 %
0026 %    [c1,s1] = FiringCurve(positions,spikes1);
0027 %    c1.rate(~c1.field) = 0;
0028 %    c2 = FiringCurve(positions,spikes2);
0029 %    c2.rate(~c2.field) = 0;
0030 %    n = NormalizeFields([c1.rate;c2.rate]);
0031 %    average = mean(n);
0032 %    error = std(n);
0033 
0034 % Copyright (C) 2012-2013 by Michaƫl Zugaro
0035 %
0036 % This program is free software; you can redistribute it and/or modify
0037 % it under the terms of the GNU General Public License as published by
0038 % the Free Software Foundation; either version 3 of the License, or
0039 % (at your option) any later version.
0040 
0041 % Defaults
0042 rate = 'on';
0043 
0044 % Check number of parameters
0045 if nargin < 1 | mod(length(varargin),2) ~= 0,
0046   error('Incorrect number of parameters (type ''help <a href="matlab:help NormalizeFields">NormalizeFields</a>'' for details).');
0047 end
0048 
0049 % Check parameter sizes
0050 if ~isdmatrix(fields),
0051     error('Firing fields should be MxN matrices (type ''help <a href="matlab:help NormalizeFields">NormalizeFields</a>'' for details).');
0052 end
0053 
0054 % Parse parameter list
0055 for i = 1:2:length(varargin),
0056     if ~ischar(varargin{i}),
0057         error(['Parameter ' num2str(i+2) ' is not a property (type ''help <a href="matlab:help NormalizeFields">NormalizeFields</a>'' for details).']);
0058     end
0059     switch(lower(varargin{i})),
0060         case 'rate',
0061             rate = varargin{i+1};
0062             if ~isastring(rate,'on','off'),
0063                 error('Incorrect value for property ''rate'' (type ''help <a href="matlab:help NormalizeFields">NormalizeFields</a>'' for details).');
0064             end
0065         otherwise,
0066             error(['Unknown property ''' num2str(varargin{i}) ''' (type ''help <a href="matlab:help NormalizeFields">NormalizeFields</a>'' for details).']);
0067     end
0068 end
0069 
0070 [m,n] = size(fields);
0071 
0072 % First, align fields to first bin
0073 
0074 % For each field, find start index, i.e. transition from 0 to 1 (0: outside field, 1: inside)
0075 f = logical(fields);
0076 transitions = [zeros(m,1) diff(f,1,2)];
0077 [i,j] = find(transitions==1);
0078 start = ones(m,1);
0079 start(i) = j;
0080 % Shift to align left
0081 aligned = CircularShift(fields,-(start-1));
0082 
0083 % Second, 'spread' fields across all bins
0084 
0085 % For each field, find stop index, i.e. transition from 1 to 0
0086 f = logical(aligned);
0087 transitions = [zeros(m,1) diff(f,1,2)];
0088 [i,j] = find(transitions==-1);
0089 stop = n*ones(m,1);
0090 stop(i) = j-1;
0091 % Interpolate
0092 normalized = zeros(m,n);
0093 for i = 1:m,
0094     normalized(i,:) = interp1(aligned(i,1:stop(i)),linspace(1,stop(i),n));
0095 end
0096 
0097 % Third, normalize z values
0098 if strcmp(rate,'on'),
0099     M = max(normalized,[],2);
0100     normalized = normalized ./ repmat(M,1,n);
0101 end

Generated on Fri 16-Mar-2018 13:00:20 by m2html © 2005