Home > FMAToolbox > Analyses > FindSubcycles.m

FindSubcycles

PURPOSE ^

FindSubcycles - Find timestamps for subcycles of an oscillating signal.

SYNOPSIS ^

function [intervals,subcycle,cycle] = FindSubcycles(angles,nSubcycles)

DESCRIPTION ^

FindSubcycles - Find timestamps for subcycles of an oscillating signal.

  USAGE

    [intervals,subcycle,cycle] = FindSubcycles(angles,nSubcycles)

    angles         phase <a href="matlab:help samples">samples</a>
    nSubcycles     number of subcycles

  EXAMPLE

    % Split theta cycles in six (i.e. subcycles of size pi/3)
    angles = Phase(FilterLFP(lfp,'passband','theta'));
    [intervals,subcycle] = FindSubcycles(angles,6);

  SEE

    See also Phase.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [intervals,subcycle,cycle] = FindSubcycles(angles,nSubcycles)
0002 
0003 %FindSubcycles - Find timestamps for subcycles of an oscillating signal.
0004 %
0005 %  USAGE
0006 %
0007 %    [intervals,subcycle,cycle] = FindSubcycles(angles,nSubcycles)
0008 %
0009 %    angles         phase <a href="matlab:help samples">samples</a>
0010 %    nSubcycles     number of subcycles
0011 %
0012 %  EXAMPLE
0013 %
0014 %    % Split theta cycles in six (i.e. subcycles of size pi/3)
0015 %    angles = Phase(FilterLFP(lfp,'passband','theta'));
0016 %    [intervals,subcycle] = FindSubcycles(angles,6);
0017 %
0018 %  SEE
0019 %
0020 %    See also Phase.
0021 
0022 % Copyright (C) 2016-2017 by Ralitsa Todorova, Micha??l Zugaro
0023 %
0024 % This program is free software; you can redistribute it and/or modify
0025 % it under the terms of the GNU General Public License as published by
0026 % the Free Software Foundation; either version 3 of the License, or
0027 % (at your option) any later version.
0028 
0029 % Make sure angles are unwrapped
0030 if range(angles) < 2 * pi + 1,
0031     angles = unwrap(angles);
0032 end
0033 
0034 % Window size
0035 window = 2*pi/nSubcycles;
0036 
0037 % Start at cycle number 0
0038 angles(:,2) = angles(:,2) - floor(angles(1,2)/(2*pi))*2*pi;
0039 
0040 % Find unwrapped phases corresponding to subcycle boundaries
0041 startPhase = ceil(angles(1,2)/(2*pi))*2*pi;
0042 stopPhase = floor(angles(end,2)/(2*pi))*2*pi;
0043 intervals = (startPhase:window:stopPhase)';
0044 intervals = [intervals(1:end-1) intervals(2:end)];
0045 
0046 % Compute cycle and subcycle IDs
0047 n = size(intervals,1);
0048 cycle = ceil(nanmean(intervals,2)/(2*pi));
0049 subcycle = CumSum(ones(n,1),[false;diff(cycle)~=0]);
0050 
0051 % Convert boundaries from phases to time
0052 % (ignore aberrant non-unique values = identical unwrapped phases for two timestamps)
0053 [~,ok] = unique(angles(:,2));
0054 angles = angles(ok,:);
0055 intervals = interp1(angles(:,2),angles(:,1),intervals);

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