Repository navigation
Expand file tree
/
Copy pathplot_TextGrid.m
More file actions
executable file
·73 lines (62 loc) · 2.45 KB
/
Copy pathplot_TextGrid.m
File metadata and controls
executable file
·73 lines (62 loc) · 2.45 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
function [] = plot_TextGrid(filenameTG, filenameW, label, binsiz, timestart)
% plot activity versus time for the label input
% example:
% plot_TextGrid('~/Documents/Students/Ben_Reed/MOKO1_20140925_180000.TextGrid','~/Documents/bioacoustics/recordings/Burgess_Sept2014/Plot1/MOKO1_20140925_180000.wav','diving_petrel',60,'25/09/2014 18:00:00');
% plot_TextGrid('~/Documents/Students/Ben_Reed/MOKO1_20140926_004553.TextGrid','~/Documents/bioacoustics/recordings/Burgess_Sept2014/Plot1/MOKO1_20140926_004553.wav','diving_petrel',60,'26/09/2014 00:45:53');
% binsiz: size of windows in seconds
if nargin<5
timestart = 0;
if nargin<4
% choose bin size in seconds
binsiz = 60 ;
if nargin<3
label = 'diving_petrel' ;
end
end
else
timestart = datenum(timestart,'dd/mm/yyyy HH:MM:SS') ;
end
% get the Fs
%tmp = regexprep(filename(end:-1:1),'dirGtxeT.','vaw.','once');
%tmp = tmp(end:-1:1);
%fprintf(1,tmp);% allows to replace just once, the last one
%ainfo = audioinfo(filenameW) ; % not implemented in Octave
%Fs = ainfo.SampleRate ;
%length1 = ainfo.TotalSamples ;
[y, Fs] = wavread(filenameW,1);
length1 = wavread(filenameW, "size");
tmp = regexprep(filenameTG(end:-1:1),'dirGtxeT.','flm.','once');
tmp = tmp(end:-1:1); % allows to replace just once, the last one
textGrid2mlf( filenameTG, tmp ) ;
song = mlf2song( tmp, [], 3, 0, 0, 0, 0, Fs) ;
% create tables
syltable = song2table(song) ;
[countlab, uniklabel] = syltable_bins(syltable,binsiz,Fs,length1(1)) ;
% find column of countlab that match the required label
colnum = find(uniklabel==sum(double(label))) ;
% plot the column activity as percentage time labelled "label" during each time bin
activity = countlab(:,colnum) ./ sum(countlab, 2) ;
% plotting
figure('Position', [0, 0, 1200, 400]);
timeaxsec = cumsum(sum(countlab,2)) ;
timeax = zeros(numel(timeaxsec),1);
for i=1:numel(timeaxsec)
timeax(i) = addtodate(timestart,timeaxsec(i),'second') ;
end
plot( timeax, activity, '-o') ;
ylim([0 1]);
datetick('x','HH:MM:SS') ;
xlabel(datestr(timestart)) ;
set(gcf, 'papersize', [10, 3]);
set(gcf,'paperposition', [0,0,[10 4]]);
orient landscape;
%print([filenameW '.pdf'],'-dpdf');
print([filenameW '.eps'],'-deps');
% save to csv
datatable = horzcat(timeaxsec,activity);
fid = fopen([filenameW '.csv'],'w+');
fprintf(fid,'%s,%s\n','Second',['Percentage_' label]);
for n=1:size(datatable,1)
fprintf(fid,'%s,%s\n',num2str(datatable(n,1)),num2str(datatable(n,2)));
end
fclose(fid);