-
Notifications
You must be signed in to change notification settings - Fork 3
/
makePeakPlot.m
65 lines (46 loc) · 1.59 KB
/
makePeakPlot.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
function makePeakPlot(data,peakIdxGroup,toPlot,xRange)
%makes peak plot (data, with lines, colored differently for different
%templates)
%Inputs:
%data -> 1-D sounds trace
%peakIdxGroup -> L x 1 cell array of peak values outputted from
% createTemplates.m
%toPlot -> 1-D array of the templates to plot (i.e. [1 3 4 5])
%xRange -> minimum and maximum points (in units of data points)
if nargin < 3 || isempty(toPlot)
toPlot = 1:length(peakIdxGroup);
end
if nargin < 4
xRange = [];
else
if length(xRange) == 2
xRange = xRange(1):xRange(2);
end
end
cs = 'r--k--g--m--c--r-.k-.g-.m-.c-.r-*k-*g-*m--c-*r-^k-^g-^m-^c-^';
highVal = ceil(max(data)*2)/2;
lowVal = floor(min(data)*2)/2;
L = length(toPlot);
if nargin >= 4 && ~isempty(xRange) && length(xRange) > 1
q = 1:length(data);
idx = q >= xRange(1) & q <= max(xRange);
data = data(idx);
xRange = q(idx);
for j=1:L
peakIdxGroup{j} = peakIdxGroup{j}(peakIdxGroup{j} >= ...
xRange(1) & peakIdxGroup{j} <= max(xRange));
end
end
if isempty(xRange) || length(xRange) ~= length(data)
plot(data,'b-');
else
plot(xRange,data);
end
hold on
for i=1:L
j = toPlot(i);
for k=1:length(peakIdxGroup{j})
plot([peakIdxGroup{j}(k) peakIdxGroup{j}(k)],[lowVal highVal],cs(3*i-2:3*i))
end
end
hold off