Skip to content

Instantly share code, notes, and snippets.

@rysk-t
Created October 8, 2015 18:32
Show Gist options
  • Select an option

  • Save rysk-t/7c61de13b990d4f5014f to your computer and use it in GitHub Desktop.

Select an option

Save rysk-t/7c61de13b990d4f5014f to your computer and use it in GitHub Desktop.
vonmises distribution fit with matlab
twopeakVonmises = @(v, x) ...
v(1) + v(2)*exp(-1* ((x*pi/180) - v(3)).^2 * (1/(2*v(4)^2))) ...
+ v(5)*exp(-1* ((x*pi/180) - v(3)+v(6)).^2 * (1/(2*v(4)^2)));
options = optimoptions('fmincon', 'MaxIter', 100000,'GradObj','off');
for i = 1:size(stimResp.meanVal, 1)
tmp = (stimResp.meanVal(i,1:end-1)-1);
fcn = @(v) sum(abs((twopeakVonmises(v,ORvar) - tmp)));
v(1) = min(tmp); % baseline
[v(2), maxidx] = max(tmp); % amplitude
v(3) = ORvar(maxidx)*pi/180; % peak 1
v(4) = pi/4; % width
v(5) = v(2); % amplitude 2
if v(3) > pi
v(6) = pi; % peak val
else
v(6) = -pi; % peak val
end
[s,f(i),flag(i),lamb(i)] = fmincon(fcn, [v(1); v(2); v(3); v(4); v(5); v(6)], ...
[],[],[],[],[],[],[],options);
figure;
subplot(121)
plot(ORvar, tmp, 'o'); hold on;
plot(x, twopeakVonmises(s,x), '-r')
subplot(122)
polar([ORvar 360]*pi/180, [tmp tmp(1)])
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment