1 | % directory where the WAV-files of the birds are stored: |
---|
2 | dpath = fullfile(mildatapath,'birds'); |
---|
3 | |
---|
4 | fname = 'PC13_20090531_050000_0.wav'; |
---|
5 | %fname = 'PC8_20090531_050000_99.wav'; |
---|
6 | [signal,fs] = wavread(fullfile(dpath,'wavs',fname)); |
---|
7 | |
---|
8 | [S,f,t] = spectrogram(signal,512,256,[],fs); |
---|
9 | fmax = 256;%Defined in paper |
---|
10 | |
---|
11 | figure(2); clf; showspec(S,f,t); |
---|
12 | [S,f,t] = spectrogram(signal,512,256,fmax,fs); |
---|
13 | |
---|
14 | figure(2); imagesc(t,f,abs(S)); |
---|
15 | axis xy; xlabel('time (s)'); ylabel('freq.'); |
---|
16 | |
---|
17 | figure(3); clf; showspec(imag(S), f,t); |
---|
18 | |
---|
19 | %% |
---|
20 | % smooth and threshold the spectrogram? |
---|
21 | G = fspecial('gaussian',[5 5],2); % window 5x5, sigma=2 |
---|
22 | I = imfilter(abs(S),G,'same'); |
---|
23 | t = dd_threshold(I(:),0.8); |
---|
24 | mask = (I>t); |
---|
25 | mask(f<2000,:) = 0; |
---|
26 | |
---|
27 | figure(4); clf; imagesc(mask); axis xy; |
---|
28 | % measure something: |
---|
29 | x = regionprops(bwlabel(mask),abs(S)); |
---|
30 | y1 = x([x.Area]>10) |
---|
31 | |
---|
32 | |
---|
33 | |
---|
34 | %% |
---|
35 | s2 = specwhiten(S,fmax); |
---|
36 | %figure(5); imagesc(t,f,s2); |
---|
37 | %axis xy; xlabel('time (s)'); ylabel('freq.'); |
---|
38 | |
---|
39 | % do the same smoothing but change the threshold |
---|
40 | G = fspecial('gaussian',[5 5],2); |
---|
41 | I = imfilter(abs(s2),G,'same'); |
---|
42 | t = dd_threshold(I(:),0.95); |
---|
43 | mask = (I>t); |
---|
44 | mask(f<2000,:) = 0; |
---|
45 | |
---|
46 | figure(6); clf; imagesc(mask); axis xy; %Looks pretty similar, but less small blobs |
---|
47 | |
---|
48 | labeledx = bwlabel(mask); |
---|
49 | Nseg = max(unique(labeledx)); %Segment labels, segment 0 is background |
---|
50 | |
---|
51 | absim = abs(S); |
---|
52 | realim = real(S); |
---|
53 | imagim = imag(S); |
---|
54 | |
---|
55 | |
---|
56 | maskfeats = nan(Nseg,3); |
---|
57 | absfeats = nan(Nseg, 7); |
---|
58 | |
---|
59 | |
---|
60 | for i=1:Nseg |
---|
61 | |
---|
62 | ix = (labeledx == i); |
---|
63 | |
---|
64 | pixtotal = sum(sum(ix)); |
---|
65 | pixheight = max(sum(ix,1)); |
---|
66 | pixwidth = max(sum(ix,2)); |
---|
67 | |
---|
68 | maskfeats(i,:) = [pixtotal pixheight pixwidth]; |
---|
69 | |
---|
70 | |
---|
71 | seg = absim(ix); |
---|
72 | absfeats(i,1) = mean(seg); |
---|
73 | absfeats(i,2) = std(seg); |
---|
74 | |
---|
75 | absfeats(i,3) = quantile(seg(:),0); |
---|
76 | absfeats(i,4) = quantile(seg(:),0.25); |
---|
77 | absfeats(i,5) = quantile(seg(:),0.5); |
---|
78 | absfeats(i,6) = quantile(seg(:),0.75); |
---|
79 | absfeats(i,7) = quantile(seg(:),1); |
---|
80 | |
---|
81 | end |
---|
82 | |
---|
83 | mildata = [maskfeats absfeats]; |
---|
84 | |
---|
85 | |
---|
86 | |
---|
87 | |
---|