Commit 63460f3c authored by Jesse Heckman's avatar Jesse Heckman

update vPrime data analyses | added keystroke recognition ML analyses example

parent a237eb33
......@@ -4,16 +4,16 @@
pb_clean;
cfn = 0;
[fn,path] = pb_getfile('cdir',pb_datapath);
[fn,path] = pb_getfile('dir',pb_datapath);
fullname = [path fn];
blocknumber = 4;
blocknumber = 7;
load(fullname);
D = Data;
datl = length(D);
load(fullname);
changefonts; % set fonts to avenir next
%changefonts; % set fonts to avenir next
%% Convert 2 AzEl
% Take eye x, y, z traces and transform 2 azimuth and elevation
......@@ -57,7 +57,7 @@ end
%% Interpolate VC data (find lsl_ts for tsVC(1) = 0! )
% Read in Data, synchronize VC/SH, define tsVC(1) as 0 for all LSL streams
FsVC = 9.95;
FsVC = 9.98;
% Sensehat data
sensehat_posD = rad2deg(cumsum(D(blocknumber).Sensehat.gyro_y - D(blocknumber).Sensehat.gyro_y(1)))/-100;
......@@ -98,7 +98,7 @@ hold on;
plot(tsSense, sensehat_posD,'.');
plot(tsVestibularI, vestibular_posDI,'.');
pb_hline([45 -45]);
pb_hline([30 -30]);
title(['Cross-correlate VC and Sensehat signal (lag = ' num2str(lagDiff,'%.2f') ' s)'] );
legend('FusionPose','VC PV')
......
......@@ -22,7 +22,7 @@ function D = pb_convertdata(fn,varargin)
% Loop over pb_data
% temp variables
pup = dat(iSig).pupil_labs;
pup = dat(iSig).pupil_labs;u
pup.Data = lsl_pupil_convert2soa(pup);
opt = dat(iSig).optitrack;
......
......@@ -36,7 +36,6 @@ function fn = pb_zipblocks(cdir,varargin)
fn = [fn '.mat'];
save([cd filesep fn], 'Data');
disp(['<< Zip complete... (fn: ' fn ')']);
end
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
......@@ -46,7 +45,3 @@ end
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
%%
%% Initialize Machine Learning - Read Keyboard
% Clean and initialize
cfn = pb_clean;
%% Load data set
load([pb_userpath 'machine learning/analysis/clustering/keystroke recognition/data/keyrecognition.mat']);
%% Create data set
% Initalize
cfn = pb_clean;
% Create audio recording
fs = 44100;
recObj = audiorecorder(fs,24,2);
recObj.StartFcn = 'disp(''>> Recording started...'')';
recObj.StopFcn = 'disp(''>> Recording stopped...'')';
% Experimental parameters
trialsz = 3000;
% Create GUI
col = pb_selectcolor(3,2);
[~,h] = pb_newfig(999);
h.Color = [1 1 1];
a = axes('XColor',[1 1 1], ...
'YColor',[1 1 1], ...
'Color','none', ...
'XTick',[], ...
'YTick',[]);
ttl = sgtitle('Keystroke Classification (ML)','FontSize',20,'FontWeight','Bold');
txt(1) = text(0.40,0.65,'Current Keystroke:','FontSize',13);
txt(2) = text(0.46,0.5,'...','FontSize',50,'Color',col(1,:));
% Run experiment
recObj.record;
keystroke = repmat(' ',trialsz,1);
samples = zeros(1,trialsz);
for iTrial = 1:trialsz
% Get keystroke
k = waitforbuttonpress;
samples(iTrial) = recObj.CurrentSample;
value = get(gcf,'CurrentCharacter');
% Display Keystroke
txt(2).String = value;
pause(1);
txt(2).String = '.';
for i = 1:2
pause(0.05);
txt(2).String = [txt(2).String '.'];
end
pause(0.3);
txt(2).String = '';
% Store data
keystroke(iTrial) = value;
end
% Save audio
recObj.stop;
% Display
y = recObj.getaudiodata;
cfn = pb_newfig(cfn);
plot(y);
pb_vline(samples);
pb_nicegraph;
% Clear
recObj.delete;
%
samplesz = length(samples);
signals = zeros(samplesz,6615);
for iSig = 1:samplesz
ind(1) = (samples(iSig) - 1504);
ind(2) = (samples(iSig) + 5110);
signals(iSig,:) = y(ind(1):ind(2),1);
cfn = pb_newfig(cfn);
plot(signals(iSig,:))
pb_nicegraph;
end
%% Shuffle
% Shuffle data
seq = randperm(samplesz);
keystroke = keystroke(seq);
signals = signals(seq,:);
%% Convert data fft
for iFFT = 1:samplesz
Y = fft(signals(iFFT,:));
P2 = abs(Y/samplesz);
P1 = P2(1:samplesz/2+1);
P1(2:end-1) = 2*P1(2:end-1);
signalsfft(iFFT,:) = P1;
end
%% Train & Predict
% Make training- and testset
clc;
trainingind = 1:700;
testind = trainingind(end)+1:samplesz;
trainset = signalsfft(trainingind,:);
trainlbl = keystroke(trainingind);
testset = signalsfft(testind,:);
testlbl = keystroke(testind);
% Use discriminant analysis clasifier
mdl = fitcdiscr(trainset,trainlbl,...
'OptimizeHyperparameters','auto',...
'HyperparameterOptimizationOptions',...
struct('AcquisitionFunctionName','expected-improvement-plus'));
predictions = mdl.predict(testset);
iscorrect = predictions == testlbl;
accuracy = sum(iscorrect)/numel(iscorrect);
pb_newfig(999);
cm = confusionchart(testlbl, predictions, ...
'ColumnSummary','column-normalized', ...
'RowSummary','row-normalized');
title(['Confusion Chart: (' num2str(1-accuracy,3) ' misrate)']);
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
% %
% Part of Programmeer Beer Toolbox (PBToolbox) %
% Written by: Jesse J. Heckman (2020) %
% %
% % % % % % % % % % % % % % % % % % % % % % % % % % % % % % %
......@@ -11,8 +11,7 @@ function path = pb_datapath(path)
if isempty(path) || ~exist(path)
username = char(java.lang.System.getProperty('user.name'));
if ismac % MAC (personal // NO VC, NO TDT)
path = ['/Users/' username '/Documents/Data/Experiment'];
%path = '/Users/jjheckman/Documents/Data/PhD/Experiment/VC';
path = ['/Users/' username '/Documents/Data/PhD/Experiment'];
elseif isunix && ~ismac % LINUX (public // VC, NO TDT)
path = ['/home/' username '/Documents/Data'];
elseif ispc % WINDOWS (public // VC, TDT)
......
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