a b/Analysis/.ipynb_checkpoints/jpca_nusim-checkpoint.m
1
clc
2
clear all
3
close all
4
5
%Make sure that usim test_data folder is included in the MATLAB path
6
%test_data folder is where the jpca is saved during usim test
7
8
%Parameters
9
%Sampling rate in ms
10
sampling_rate = 10;   %Sampling rate in ms; we do jpca at 10ms sampling rate as done previously in original jpca implementation
11
numPCs = 4;   % Number of PCs for jpca
12
end_tpoint= 620;   %timepoints to do the jpca
13
%Select the cycle for each condition to do the jpca
14
cycle = [3, 3, 3, 3, 3, 3];
15
16
load('Data_jpca.mat')
17
load('n_fixedsteps_jpca.mat')
18
load('condition_tpoints_jpca.mat')
19
%%
20
%iterate through the Data object and format
21
for i= 1:size(Data, 2)
22
    
23
    Data(i).A = double(Data(i).A.A);
24
    Data(i).times = double(Data(i).times.times');
25
26
end
27
28
%%
29
30
31
min_tpoints_cond = inf;
32
for i= 1:size(Data, 2)
33
    
34
    Data(i).A = Data(i).A(n_fsteps(i) + cycle(i) * cond_tpoints(i): n_fsteps(i) + (cycle(i)+1) * cond_tpoints(i), :);
35
    
36
    Data(i).times = Data(i).times(n_fsteps(i) + cycle(i) * cond_tpoints(i): n_fsteps(i) + (cycle(i)+1) * cond_tpoints(i), :);
37
    Data(i).times = Data(i).times - Data(i).times(1);
38
    
39
    %Now sample the data at the required sampling rate
40
    Data(i).A = Data(i).A(1:sampling_rate:length(Data(i).A), :);
41
    Data(i).times = Data(i).times(1:sampling_rate:length(Data(i).times), :);
42
    
43
    if min_tpoints_cond > size(Data(i).A, 1)
44
        
45
        min_tpoints_cond = size(Data(i).A, 1);
46
    
47
    end
48
    
49
end
50
51
%Now select the min_tpoints for all the conditions for jpca analysis
52
for i=1:size(Data, 2)
53
    
54
    Data(i).A = Data(i).A(1:min_tpoints_cond, :);
55
    Data(i).times = Data(i).times(1:min_tpoints_cond, :);
56
57
end
58
%%
59
60
%Now the data array has been created. Apply the jPCA to obtain the
61
%corresponding plot
62
63
64
%%-------------------------------------------------------------------------
65
66
% these will be used for everything below
67
jPCA_params.softenNorm = 1;  % how each neuron's rate is normized, see below
68
jPCA_params.suppressBWrosettes = true;  % these are useful sanity plots, but lets ignore them for now
69
jPCA_params.suppressHistograms = false;  % these are useful sanity plots, but lets ignore them for now
70
jPCA_params.meanSubtract = false;
71
72
%% EX1: FIRST PLANE
73
times = 0:sampling_rate:end_tpoint;  % 0 ms before 'movement onset' until 150 ms after
74
jPCA_params.numPCs = 4;  % default anyway, but best to be specific
75
[Projection, Summary] = jPCA_4(Data, times, jPCA_params);
76
77
phaseSpace(Projection, Summary);  % makes the plot
78
79
printFigs(gcf, './jpca_plo;t', '-dpdf', 'jPCA_Plot');  % prints in the current directory as a PDF