-
Notifications
You must be signed in to change notification settings - Fork 0
/
autoSomaticTEMP.m
105 lines (70 loc) · 2.29 KB
/
autoSomaticTEMP.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
% Extract waveforms
% Raw spike data
tempSpkData = double(CElectrode1);
% Sampling Frequency
sampFreq = mer.sampFreqHz; % THIS NEEDS to CHANGE
handles.params = set_parameters_AS(sampFreq);
[thrOut] = SpikeThresholdCreate(tempSpkData, handles, 'Min9sig');
filtSpkData = thrOut.Filtered;
threshold = thrOut.AveThresh;
[jat_Struct] = SpikeTimeExtract(filtSpkData, threshold, handles);
%%
plot(jat_Struct.spkWaveforms','k')
%%
% Extract Features
features = struct;
% Reduce dimensions and extract Waveforms of interest
tempWaves = jat_Struct.spkWaveforms;
% Waveform Structure
WaveIndex = tempWaves;
% Peak
features.Peak = max(tempWaves,[],2);
% Valley
features.Valley = min(tempWaves,[],2);
% Energy
features.Energy = trapz(abs(tempWaves),2);
% Combine for WavePCA analysis
featsForPCA = horzcat(features.Peak,...
features.Valley,...
features.Energy);
% WavePC1
[~,pcScores,~] =...
princomp(featsForPCA);
features.WavePC1 = pcScores(:,1);
features.FSDE_Values =...
FSDE_Method(tempWaves);
%%
% Derive Gaussian fit parameters for positive and negative
% component of waveform (Felsen and Thompson method)
[features.WaveFitParams] = WaveFormFit_AS(tempWaves, size(tempWaves,2));
%%
plot(jat_Struct.spkWaveforms(features.WaveFitParams.noise,:)','k')
hold on
plot(jat_Struct.spkWaveforms(~features.WaveFitParams.noise,:)','r')
% normalize features
X = [features.Peak , features.Valley ,...
features.Energy , features.WavePC1 ,...
features.FSDE_Values.FDmin , features.FSDE_Values.SDmax ,...
features.FSDE_Values.SDmin , features.WaveFitParams.gauss_fit_neg_width ,...
features.WaveFitParams.gauss_fit_pos_width];
%% HOW TO DETERMINe THE best number of clusters
X1 = X(:,1:3);
eva = evalclusters(X1,'kmeans','DaviesBouldin','KList',1:7);
numClusts = eva.OptimalK;
%%
% c = clusterdata(X1,'mahalanobis','linkage','ward','maxclust',3);
c = clusterdata(X1,'distance','chebychev','linkage','ward','maxclust',numClusts);
% Plot the data with each cluster shown in a different color.
figure
scatter3(X1(:,1),X1(:,2),X1(:,3),10,c)
%%
filtWave = jat_Struct.spkWaveforms(~features.WaveFitParams.noise,:);
cfilt = c(~features.WaveFitParams.noise);
%%
figure;
subplot(1,2,1);
plot(filtWave(cfilt==1,:)','r')
ylim([-6000 6000]);
subplot(1,2,2);
plot(filtWave(cfilt==2,:)','g')
ylim([-6000 6000]);