Commit 0f9a6aec authored by Jesse Heckman's avatar Jesse Heckman

added a bunch

parent 8da48606
This diff is collapsed.
This diff is collapsed.
......@@ -16,7 +16,7 @@ spheretrial2complete(); % creates 2 .sphere files: calibration "0000" block, and
%% Prep Calibration data
[fname,~] = pb_getfile('dir',cdir);
[fname,~] = pb_getfile('dir',cd);
sphere2hoopdat(fname); % calibration
sphere2hoopcsv(fname);
......@@ -24,7 +24,7 @@ sphere2hoopcsv(fname);
%% Calibrate experiment data
[fname,~] = pb_getfile('dir',cdir);
[fname,~] = pb_getfile('dir',cd);
sphere2hoopdat(fname); % data
sphere2hoopcsv(fname);
......@@ -53,8 +53,8 @@ pa_sac2mat(); % MANUALLY select! input: *.hv / output: *.mat
%%
load(strrep(fname,'.sphere','')) % load 'XX-0001-YY-MM-DD-000n.mat --> create: Sac, Stim
clear fn fname s;
S = pb_stim2MSstim(Stim);
[M] = pa_supersac(Sac,S);
%S = pb_stim2MSstim(Stim);
[M] = pa_supersac(Sac,Stim);
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
......
function [slowphase,quickphase,VOR,stats] = pb_segmentVOR(eye,tsEye,head,tsHead,varargin)
% PB_SEGMENTVOR()
%
% PB_SEGMENTVOR() ...
%
% See also ...
% PBToolbox (2019): JJH: j.heckman@donders.ru.nl
%% Init
v = varargin;
disp = pb_keyval('disp',v,1);
range = pb_keyval('range',v,1:length(eye));
fsPup = 121.37;
fsSH = 51.71;
%% Preprocess
% Select data
% eye = eye(:);
% head = head(:);
eye_vel = gradient(eye) * fsPup;
head_vel = gradient(head) * fsSH;
if disp
figure;
hold on;
plot(tsEye, eye_vel);
plot(tsHead, head);
pb_nicegraph;
end
% Input data format % velocity profile of vc
head_vel = interp1(tsHead,head_vel,tsEye,'pchip');
kInput = eye_vel .* sign(head_vel);
%% Cluster
%% Postprocess
%% Checkout
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2019) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
function [nsnippets] = pb_vocsegment(fn,varargin)
% PB_VOCSEGMENT()
%
% PB_VOCSEGMENT() ...
%
% See also ...
% PBToolbox (2019): JJH: j.heckman@donders.ru.nl
% Varargins
v = varargin;
sniplen = pb_keyval('length',v,5); % Snippet length in time (s).
storedir = pb_keyval('cdir',v,'snippets');
% Read sound
[audioT,Fs] = audioread(fn);
audiolen = length(audioT);
nSamples = sniplen * Fs;
[rem,rep] = pb_mod(audiolen,nSamples);
% Storing
ind = strfind(fn,filesep);
p = fn(1:ind(end));
fnSnip = [p 'snippets' filesep 'R_voc_s'];
for iRep = 1:rep+1
% Segmentate
start = (iRep-1) * nSamples + 1;
stop = iRep * nSamples;
if iRep > rep
stop = start + rem;
end
audio = audioT(start:stop);
save([fnSnip num2str(iRep,'%04.f')],'audio','Fs');
end
nsnippets = iRep;
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2019) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
function pb_flipsubplot(varargin)
% PB_FLIPSUBPLOT()
%
% PB_FLIPSUBPLOT() ...
%
% See also ...
% PBToolbox (2019): JJH: j.heckman@donders.ru.nl
v = varargin;
fig = pb_keyval('fig',v,gcf);
square = pb_keyval('axis',v,1);
nicegr = pb_keyval('nicegraph',v,1);
h = pb_fobj(fig,'Type','Axes');
axesPos = get(h, 'Position');
hl = length(h);
% Get Orientation
col = [];
row = [];
for iAx = 1:hl
col = [col axesPos{iAx}(1)];
row = [row axesPos{iAx}(2)];
end
nrow = length(unique(col));
ncol = length(unique(row));
% Swoop em
tmp = figure('Position',[0 1 1 1]);
for iRepos = 1:hl
hSub(iRepos) = subplot(nrow,ncol,iRepos);
h(iRepos).Position = hSub(iRepos).Position;
end
close(tmp);
% Set extra's
if square
for iAx = 1:length(h)
h(iAx).PlotBoxAspectRatio = [1 1 1];
h(iAx).PlotBoxAspectRatioMode = 'manual';
end
end
if nicegr
pb_nicegraph;
end
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2019) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
function cfn = pb_cfn(varargin)
% PB_CFN
%
% PB_CFN returns current figure number
%
% See also pb_newfig
% PBToolbox (2019): JJH: j.heckman@donders.ru.nl
g = groot;
if isempty(g.CurrentFigure)
cfn = 0;
else
cfn = g.CurrentFigure.Number;
end
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2019) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
function pb_clean(varargin)
function cfn = pb_clean(varargin)
% PB_CLEAN(varargin)
%
% PB_CLEAN(varargin) cleans up your matlab. Closes all open figures,
......@@ -12,7 +12,8 @@ function pb_clean(varargin)
empty = pb_keyval('clc',varargin,true);
clr = pb_keyval('clr',varargin,true);
if fig; close all; end
if fig; close all hidden; end
if nargout; cfn = 0; end
if empty; clc; end
if islogical(clr)
if clr; pb_clear(); end
......
......@@ -13,7 +13,7 @@ function [fname, path] = pb_getfile(varargin)
ext = pb_keyval('ext',varargin,'*.*');
title = pb_keyval('title',varargin,'Open file...'); % titles have been removed from matlab ui's in OS X - El capitain
cd(cdir);
if flag; cd(cdir); end
[fname, path] = uigetfile(ext,title);
fpath = [path fname];
......
......@@ -9,7 +9,7 @@ function [cfn,f] = pb_newfig(cfn, varargin)
if nargin == 0 ; cfn = 0; end
if isempty(cfn); cfn = 0; end
units = pb_keyval('units',varargin,'centimeters');
ws = pb_keyval('ws',varargin,'docked'); % normal
rsz = pb_keyval('resize',varargin,'on');
......
function h = pb_puzzlegrid(h,sz,varargin)
% PB_PUZZLEGRID()
%
% PB_PUZZLEGRID() ...
%
% See also ...
% PBToolbox (2019): JJH: j.heckman@donders.ru.nl
for i = length(h)
h(i).Box = 'on';
h(i).XTickLabel = {[]};
h(i).YTickLabel = {[]};
h(i).XGrid = 'on';
h(i).YGrid = 'on';
h(i).XLim = [1 sz(2)+1];
h(i).YLim = [1 sz(1)+1];
axis square;
end
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2019) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
function [par,fun] = pb_sinefit(x,y,varargin)
% PB_SINEFIT()
%
% PB_SINEFIT() ...
%
% See also ...
% PBToolbox (2019): JJH: j.heckman@donders.ru.nl
% Get Varargin
v = varargin;
frequency = pb_keyval('f',v);
offset = pb_keyval('offset',v,mean(y));
amplitude = pb_keyval('amplitude',v,0);
phase = pb_keyval('phase',v,0);
disp = pb_keyval('display',v,false);
par = zeros(1,4);
% Obtain main freq
nsamples = length(x);
T = x(2)-x(1);
NyFreq = 1/(2*T); % Nyquist frequency
y_m = y-offset; % FFT much better without offset
n = 128*2^nextpow2(nsamples); % Heavy zero padding
Y = fft(y_m,n); % Y(f)
n2 = floor(n/2);
P2 = abs(Y/nsamples);
P1 = P2(1:n2+1);
P1(2:end-1) = 2*P1(2:end-1);
fs = (0:n2)/n/T; % frequency scale
% %FFT parameters at peak
[maxFFT,maxFFTindx] = max(P1); % Peak magnitude and location
fpeak = fs(maxFFTindx); % f at peak
Phip = angle(Y(maxFFTindx))+pi/2; % Phi-Peak is for cos, sin(90°+alpha)=cos(betta), alpha=-betta
Phip = Phip-x(1)*fpeak*2*pi; % shift for phi at x=0
%Better estimate for offset:
omega = 2*pi*fpeak;
offset = offset - maxFFT*(cos(omega*x(1)+Phip)-cos(omega*x(end)+Phip))/(omega*(x(end)-x(1)));
% Knowit all mode
if isempty(frequency)
frequency = fpeak;
end
% Set parameters
par(1) = offset;
par(2) = amplitude;
par(3) = frequency;
par(4) = phase;
% Fake parameters
par(1) = -8;
par(2) = 24.2;
par(4) = -.28;
if disp
graphFit(x,y,par)
end
end
function graphFit(x,y,par)
% Create fits
t = x;
f = par(1) + par(2) * sin(2*pi*par(3)*t +par(4));
% Plot
cfn = pb_newfig(pb_cfn);
hold on;
raw = plot(x,y,'.'); % Rawdata
fit = plot(t,f); % Fit
pb_nicegraph;
fit.LineWidth = 2;
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2019) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
......@@ -19,7 +19,7 @@ function pb_initialize()
% Run generic commands
cd(INIT_DIR);
INIT_FILES = dir('*.m');
for n = 1:size(INIT_FILES);
for n = 1:size(INIT_FILES)
[~,INIT_CMD,~] = fileparts(INIT_FILES(n).name);
eval(INIT_CMD);
end
......@@ -27,7 +27,7 @@ function pb_initialize()
% Run architecture specficic commands
cd(INIT_ARCH_DIR);
INIT_FILES = dir('*.m');
for n = 1:size(INIT_FILES);
for n = 1:size(INIT_FILES)
[~,INIT_CMD,~]=fileparts(INIT_FILES(n).name);
eval(INIT_CMD);
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment