# CalcCurvature

## PURPOSE

CALCCURVATURE

## SYNOPSIS

function kappa = CalcCurvature(v, vtheta, indx, dt)

## DESCRIPTION

    CALCCURVATURE
       Usage:  kappa = CalcCurvature(v,theta,indx,dt)

     This function calculates the curvature of the path that the fly took
     while walking in the frames indexed by indx.  The inputs are the speed v
     , the angle of the velocity vector vtheta,the index of walking frames,and the time resolution
     (1/sampling rate) dt. I am convinced that this function can be
     simplified, but haven't had the time or energy to find a more efficient way.

## CROSS-REFERENCE INFORMATION

This function calls:

This function is called by:

- FAnalyze FANALYZE

## SOURCE CODE

    0001 function kappa = CalcCurvature(v, vtheta, indx, dt)
    0002
    0003 %CALCCURVATURE
    0004 %   Usage:  kappa = CalcCurvature(v,theta,indx,dt)
    0005 %
    0006 % This function calculates the curvature of the path that the fly took
    0007 % while walking in the frames indexed by indx.  The inputs are the speed v
    0008 % , the angle of the velocity vector vtheta,the index of walking frames,and the time resolution
    0009 % (1/sampling rate) dt. I am convinced that this function can be
    0010 % simplified, but haven't had the time or energy to find a more efficient way.
    0011
    0012 %Written by Dan Valente
    0013 %September 2007
    0014
    0015 list = [];
    0016 phi = [];
    0017 kappa = [];
    0018 indx(end+1)=-1;
    0019 for i = 1:length(indx)-1
    0020     if (indx(i)+1 == indx(i+1))
    0021         list = [list indx(i)];
    0022     else
    0023         list = [list indx(i)];
    0024         temp = vtheta(list)';
    0025         if (length(temp)~= 1)
    0026             for j = 1:length(temp)-1
    0027                 d = temp(j+1)-temp(j);
    0028                 if abs(d) >= pi
    0029                     if (temp(j+1) < 0)
    0030                         d = (temp(j+1)+2*pi)-temp(j);
    0031                     elseif (temp(j+1) >= 0)
    0032                         d = (temp(j+1)-2*pi)-temp(j);
    0033                     end
    0034                 end
    0035                 phi(j) = d/dt;
    0036             end
    0037
    0038             phi2 = phi./v(list(1:end-1))'; %transpose for FAnalyze;
    0039             kappa = [kappa phi2];
    0040         end
    0041         list = [];
    0042         phi = [];
    0043     end
    0044 end
    0045
    0046 return;