TimeToPhase - Resample signal as a function of unwrapped phase. LFP signals and spikes are recorded as a function of computer time, but one may instead wish to express them as a function of unwrapped LFP phase. This is necessary e.g. to align LFPs and spikes with reconstructed positions (see <a href="matlab:help ReconstructPosition">ReconstructPosition</a>), computing spike autocorrelograms in units of 'per-cycle' rather than Hz, estimating cross-frequency (amplitude-phase) coupling, etc. To better understand how this transformation acts on the signal, consider the following example. When plotting LFP traces as a function of time, unless the underlying rhythm (e.g. theta) is a pure sine wave, phases will increase in a non-linear way along the x axis, sometimes faster, sometimes slower. Resampling in phase space 'distorts' the signal and yields a different plot where phases increase linearly (but computer clock implicitly increases non-linearly). USAGE output = TimeToPhase(input,phases,varargin) input input <a href="matlab:help samples">samples</a> phases unwrapped phases (obtained e.g. using <a href="matlab:help Phase">Phase</a>) <options> optional list of property-value pairs (see table below) ========================================================================= Properties Values ------------------------------------------------------------------------- 'frequency' number of output samples per cycle (default = 150) =========================================================================
0001 function output = TimeToPhase(input,phases,varargin) 0002 0003 %TimeToPhase - Resample signal as a function of unwrapped phase. 0004 % 0005 % LFP signals and spikes are recorded as a function of computer time, but one 0006 % may instead wish to express them as a function of unwrapped LFP phase. This 0007 % is necessary e.g. to align LFPs and spikes with reconstructed positions 0008 % (see <a href="matlab:help ReconstructPosition">ReconstructPosition</a>), computing spike autocorrelograms in units of 0009 % 'per-cycle' rather than Hz, estimating cross-frequency (amplitude-phase) 0010 % coupling, etc. 0011 % 0012 % To better understand how this transformation acts on the signal, consider the 0013 % following example. When plotting LFP traces as a function of time, unless the 0014 % underlying rhythm (e.g. theta) is a pure sine wave, phases will increase in a 0015 % non-linear way along the x axis, sometimes faster, sometimes slower. Resampling 0016 % in phase space 'distorts' the signal and yields a different plot where phases 0017 % increase linearly (but computer clock implicitly increases non-linearly). 0018 % 0019 % 0020 % USAGE 0021 % 0022 % output = TimeToPhase(input,phases,varargin) 0023 % 0024 % input input <a href="matlab:help samples">samples</a> 0025 % phases unwrapped phases (obtained e.g. using <a href="matlab:help Phase">Phase</a>) 0026 % <options> optional list of property-value pairs (see table below) 0027 % 0028 % ========================================================================= 0029 % Properties Values 0030 % ------------------------------------------------------------------------- 0031 % 'frequency' number of output samples per cycle (default = 150) 0032 % ========================================================================= 0033 % 0034 0035 % Copyright (C) 2015 by Michaƫl Zugaro 0036 % 0037 % This program is free software; you can redistribute it and/or modify 0038 % it under the terms of the GNU General Public License as published by 0039 % the Free Software Foundation; either version 3 of the License, or 0040 % (at your option) any later version. 0041 0042 % Defaults 0043 frequency = 150; 0044 0045 % Check number of parameters 0046 if nargin < 2 || mod(length(varargin),2) ~= 0, 0047 error('Incorrect number of parameters (type ''help <a href="matlab:help TimeToPhase">TimeToPhase</a>'' for details).'); 0048 end 0049 0050 % Check parameters 0051 if ~issamples(input), 0052 error('Incorrect input samples (type ''help <a href="matlab:help TimeToPhase">TimeToPhase</a>'' for details).'); 0053 end 0054 0055 % Parse parameters 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 TimeToPhase">TimeToPhase</a>'' for details).']); 0059 end 0060 switch(lower(varargin{i})), 0061 case 'frequency', 0062 frequency = varargin{i+1}; 0063 if ~isdscalar(frequency), 0064 error('Incorrect value for property ''frequency'' (type ''help <a href="matlab:help TimeToPhase">TimeToPhase</a>'' for details).'); 0065 end 0066 otherwise, 0067 error(['Unknown property ''' num2str(varargin{i}) ''' (type ''help <a href="matlab:help TimeToPhase">TimeToPhase</a>'' for details).']); 0068 end 0069 end 0070 0071 if size(input,2) == 1, 0072 % Point process 0073 [~,~,output] = Phase(phase,input); 0074 else 0075 % Continuous data 0076 start = phases(1,2); 0077 stop = phases(end,2); 0078 nCycles = (stop-start)/(2*pi); 0079 output = Interpolate([phases(:,2) input(:,2)],linspace(start,stop,round(nCycles*frequency))); 0080 end 0081