-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextractWaveforms_Clz_v06.m
More file actions
114 lines (76 loc) · 2.6 KB
/
extractWaveforms_Clz_v06.m
File metadata and controls
114 lines (76 loc) · 2.6 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
function [ expData ] = extractWaveforms_Clz_v06(spikeData, spkThresh, noisThresh, minDist, Fs , pnFlag)
%UNTITLED Summary of this function goes here
% Detailed explanation goes here
% Initial Vars
sampLen = round(Fs/1000);
% boundary = sampLen*2;
% Positive waves
[pWavesLocs , ~] = peakseek(spikeData , minDist , spkThresh);
% Negative waves
ridP = spikeData;
ridP(ridP > 0) = 0;
[nWavesLocs , ~] = peakseek(abs(ridP) , minDist , spkThresh);
% Positive Noise
if sum(spikeData > noisThresh) == 0
pNoiseLocs = [];
else
[pNoiseLocs , ~] = peakseek(spikeData , 1 , noisThresh);
end
pNoiseInds = ~ismember(pWavesLocs,pNoiseLocs);
pWavesLocs = pWavesLocs(pNoiseInds);
pWavesLocs = pWavesLocs(pWavesLocs > sampLen);
% Negative Noise
if sum(abs(ridP) > noisThresh) == 0
nNoiseLocs = [];
else
[nNoiseLocs , ~] = peakseek(spikeData , 1 , noisThresh);
end
nNoiseInds = ~ismember(nWavesLocs,nNoiseLocs);
nWavesLocs = nWavesLocs(nNoiseInds);
nWavesLocs = nWavesLocs(nWavesLocs > sampLen);
[posWaves , posWpost] = computeWaves(1,spikeData,pWavesLocs,sampLen);
[negWaves , negWpost] = computeWaves(1,spikeData,nWavesLocs,sampLen);
% allWaves = [negWaves , posWaves];
if pnFlag == 1
allWaves = posWaves;
allLocs = pWavesLocs;
expData.posWaveInfo.waves = posWaves;
expData.posWaveInfo.positions = posWpost;
expData.posWaveInfo.numWaves = size(posWaves,2);
expData.posWaveInfo.posLocs = pWavesLocs;
else
allWaves = negWaves;
allLocs = nWavesLocs;
expData.negWaveInfo.waves = negWaves;
expData.negWaveInfo.positions = negWpost;
expData.negWaveInfo.numWaves = size(negWaves,2);
expData.negWaveInfo.neglocs = nWavesLocs;
end
expData.waveAnylsInfo.spkThresh = spkThresh;
expData.waveAnylsInfo.noiseThresh = noisThresh;
expData.allWaves.waves = allWaves;
expData.allWavesInfo.numWaves = size(allWaves,2);
expData.allWavesInfo.alllocs = allLocs;
end
% Subfunction
function [WavesOut , PositionOut] = computeWaves(nOp,spkData,waves,sampLen)
totLen = length(1 - (sampLen/2):1 + (round(sampLen*0.8)-1));
WavesOut = zeros(totLen, length(waves));
PositionOut = zeros(totLen, length(waves));
for ai = 1:length(waves)
locP = waves(ai);
if nOp == -1
sampPeriod = locP - (round(sampLen*0.8)-1):locP + (sampLen/2);
elseif nOp == 1
sampPeriod = locP - (sampLen/2):locP + (round(sampLen*0.8)-1);
end
if any(sampPeriod > length(spkData))
WavesOut(:,ai) = [];
PositionOut(:,ai) = [];
break
else
WavesOut(:,ai) = spkData(sampPeriod);
PositionOut(:,ai) = sampPeriod;
end
end
end