-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathptCut.m
More file actions
87 lines (77 loc) · 1.79 KB
/
Copy pathptCut.m
File metadata and controls
87 lines (77 loc) · 1.79 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
function ptNew = ptCut(pt, tStart, tEnd)
% function ptNew = ptCut(pt, tStart, tEnd)
%
% Cut the specified interval from the PitchTier and preserve time
%
% pt ... PitchTier object
% tStart ... [optional] beginning time of interval to be cut (default -Inf = cut from the tmin of the PitchTier)
% tEnd ... [optional] final time of interval to be cut (default Inf = cut to the tmax of the PitchTier)
%
% v1.0, Tomas Boril, borilt@gmail.com
%
% Example
% pt = ptRead('demo/H.PitchTier');
% pt2 = ptCut(pt, 3);
% pt2_0 = ptCut0(pt, 3);
% pt3 = ptCut(pt, 2, 3);
% pt3_0 = ptCut0(pt, 2, 3);
% pt4 = ptCut(pt, -Inf, 1);
% pt4_0 = ptCut0(pt, -Inf, 1);
% pt5 = ptCut(pt, -1, 1);
% pt5_0 = ptCut0(pt, -1, 1);
% subplot(3,1,1)
% ptPlot(pt)
% subplot(3,1,2)
% ptPlot(pt2)
% subplot(3,1,3)
% ptPlot(pt2_0)
% figure
% subplot(2,3,1)
% ptPlot(pt3)
% subplot(2,3,4)
% ptPlot(pt3_0)
% subplot(2,3,2)
% ptPlot(pt4)
% subplot(2,3,5)
% ptPlot(pt4_0)
% subplot(2,3,3)
% ptPlot(pt5)
% subplot(2,3,6)
% ptPlot(pt5_0)
if nargin < 1 || nargin > 3
error('Wrong number of arguments.')
end
if nargin == 1
tStart = -Inf;
tEnd = Inf;
elseif nargin == 2
tEnd = Inf;
end
if isinf(tStart) && tStart>0
error('infinite tStart can be negative only')
end
if isinf(tEnd) && tEnd<0
error('infinite tEnd can be positive only')
end
if isnan(tStart)
error('tStart must be a number')
end
if isnan(tEnd)
error('tEnd must be a number')
end
if tEnd < tStart
error('tEnd must be >= tStart')
end
ptNew = pt;
ptNew.t = pt.t(pt.t >= tStart & pt.t <= tEnd);
ptNew.f = pt.f(pt.t >= tStart & pt.t <= tEnd);
if isinf(tStart)
ptNew.tmin = pt.tmin;
else
ptNew.tmin = tStart;
end
if isinf(tEnd)
ptNew.tmax = pt.tmax;
else
ptNew.tmax = tEnd;
end