circ_vmpdf.m 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. function [p alpha] = circ_vmpdf(alpha, thetahat, kappa)
  2. % [p alpha] = circ_vmpdf(alpha, w, p)
  3. % Computes the circular von Mises pdf with preferred direction thetahat
  4. % and concentration kappa at each of the angles in alpha
  5. %
  6. % The vmpdf is given by f(phi) =
  7. % (1/(2pi*I0(kappa))*exp(kappa*cos(phi-thetahat)
  8. %
  9. % Input:
  10. % alpha angles to evaluate pdf at, if empty alphas are chosen to
  11. % 100 uniformly spaced points around the circle
  12. % [thetahat preferred direction, default is 0]
  13. % [kappa concentration parameter, default is 1]
  14. %
  15. % Output:
  16. % p von Mises pdf evaluated at alpha
  17. % alpha angles at which pdf was evaluated
  18. %
  19. %
  20. % References:
  21. % Statistical analysis of circular data, Fisher
  22. %
  23. % Circular Statistics Toolbox for Matlab
  24. % By Philipp Berens and Marc J. Velasco, 2009
  25. % velasco@ccs.fau.edu
  26. % if no angles are supplied, 100 evenly spaced points around the circle are
  27. % chosen
  28. if nargin < 1 || isempty(alpha)
  29. alpha = linspace(0, 2*pi, 101)';
  30. alpha = alpha(1:end-1);
  31. end
  32. if nargin < 3
  33. kappa = 1;
  34. end
  35. if nargin < 2
  36. thetahat = 0;
  37. end
  38. alpha = alpha(:);
  39. % evaluate pdf
  40. C = 1./(2*pi*besseli(0,kappa));
  41. p = C .* exp(kappa.*cos(alpha-thetahat));