-
Notifications
You must be signed in to change notification settings - Fork 4
/
createPairs_adjustable.m
98 lines (73 loc) · 4.05 KB
/
createPairs_adjustable.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
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
function [f1 f2 delTPoints] = createPairs_adjustable(peaks,timeBinSec,fs)
%createPairs Pairs local peaks of a spectrogram matrix by treating each
%peak in the matrix as an anchor point, then pairing the anchor point with
%the first numPairsMax number of points within it's target zone. The target
%zone height and width are set below
%
%@param peaks Matrix of 0's and 1's representing location of local
% maxima of the spectrogram matrix
%@param timeBinSec The number of seconds per time bin
%@return f1 Vector containing anchor point frequency
%@return f2 Vector containing frequency point of a peak matched
% with anchor point from f1
%@return t1 Vector containing anchor point time
%@return deltaTpoints Vector containing time between anchor point and its
% paired local maxima
[rowSizeSpec, colSizeSpec] = size(peaks); %Gets size of the peaks matrix
[rowPeakLoc,colPeakLoc] = find(peaks); %Finds index of each peak in the matrix
numPeaks = length(rowPeakLoc); %Gets the total number of peaks
deltaT = 30; %Targetzone "width" in timebins; searches to the right of anchor point
deltaF = 15; %Targetzone search, searches up and down from the anchor point
deltaTInit = 5; %Target zone initial distance from anchor point
numPairsMax = 5; %Max limit on number of pairs an anchor point can have
%Play with this since too large will cost excessive storage, but too
%little and it will be difficult to match
%Initialize vectors that make up the hash
f1=[];
f2=[];
delTPoints=[];
for i=1:numPeaks %each peak is considered as an anchor point
%Gets index of current anchor point
anchorPtRow = rowPeakLoc(i);
anchorPtCol = colPeakLoc(i);
maxDistRight = anchorPtCol+deltaT+deltaTInit;%The farthest right of our target zone
maxDistLeft = anchorPtCol + deltaTInit;
if(maxDistRight > colSizeSpec) %Check target zone is within the spectrogram matrix
maxDistRight = colSizeSpec;
end
if(maxDistLeft > colSizeSpec) %Check target zone is within the spectrogram matrix
maxDistLeft = colSizeSpec;
end
%Find indicies of rows that will be searched up and down
maxDistUp = anchorPtRow+deltaF;
maxDistDown = anchorPtRow-deltaF;
%Check that the index is within bounds of spectrogram matrix
if(maxDistDown<1)
maxDistDown = 1;
end
if(maxDistUp>rowSizeSpec)
maxDistUp = rowSizeSpec;
end
counter=0; %Counter to keep track of how many pairings have been made for the current anchor point
%Go through target zone and check for peaks near anchor point
for j=maxDistDown:maxDistUp
for k=anchorPtCol:maxDistRight
if(counter<numPairsMax) %Check limit of pairings is not exceeded
for m=1:numPeaks %Go through all peaks and see if they are in the target zone
if( j==rowPeakLoc(m) && k==colPeakLoc(m) ) %Then we found a peak within the target zone
if(anchorPtRow == rowPeakLoc(m) && anchorPtCol == colPeakLoc(m) )
%Check the anchor point is not being paired
%to itself
else
%Add values to the vectors
f1 = [f1, fs(anchorPtRow)];
f2 = [f2, fs(rowPeakLoc(m))];
delTPoints = [delTPoints, timeBinSec(colPeakLoc(m)) - timeBinSec(anchorPtCol)];
end
counter = counter + 1; %Keep track of how many pairs have been made
end
end %end for
end %end if
end %end for
end %end for
end