comparison src/matlab/ifptrack.m @ 0:c52bc3e8d3ad tip

user: boblsturm branch 'default' added README.md added assets/.DS_Store added assets/playButton.jpg added assets/stopButton.png added assets/swapButton.jpg added data/.DS_Store added data/fiveoctaves.mp3 added data/glock2.wav added data/sinScale.mp3 added data/speech_female.mp3 added data/sweep.wav added nimfks.m.lnk added src/.DS_Store added src/matlab/.DS_Store added src/matlab/AnalysisCache.m added src/matlab/CSS.m added src/matlab/DataHash.m added src/matlab/ExistsInCache.m added src/matlab/KLDivCost.m added src/matlab/LoadFromCache.m added src/matlab/SA_B_NMF.m added src/matlab/SaveInCache.m added src/matlab/Sound.m added src/matlab/SynthesisCache.m added src/matlab/chromagram_E.m added src/matlab/chromagram_IF.m added src/matlab/chromagram_P.m added src/matlab/chromsynth.m added src/matlab/computeSTFTFeat.m added src/matlab/controller.m added src/matlab/decibelSliderReleaseCallback.m added src/matlab/drawClickCallBack.m added src/matlab/fft2chromamx.m added src/matlab/hz2octs.m added src/matlab/ifgram.m added src/matlab/ifptrack.m added src/matlab/istft.m added src/matlab/nimfks.fig added src/matlab/nimfks.m added src/matlab/nmfFn.m added src/matlab/nmf_beta.m added src/matlab/nmf_divergence.m added src/matlab/nmf_euclidean.m added src/matlab/prune_corpus.m added src/matlab/rot_kernel.m added src/matlab/templateAdditionResynth.m added src/matlab/templateDelCb.m added src/matlab/templateScrollCb.m
author boblsturm
date Sun, 18 Jun 2017 06:26:13 -0400
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:c52bc3e8d3ad
1 function [p,m,S] = ifptrack(d,w,sr,fminl,fminu,fmaxl,fmaxu)
2 % [p,m,S] = ifptrack(d,w,sr,fminl,fminu,fmaxl,fmaxu)
3 % Pitch track based on inst freq.
4 % Look for adjacent bins with same inst freq.
5 % d is the input waveform. sr is its sample rate
6 % w is the basic STFT DFT length (window is half, hop is 1/4)
7 % S returns the underlying complex STFT.
8 % fmin,fmax define ramps at edge of sensitivity
9 % 2006-05-03 dpwe@ee.columbia.edu
10
11 % Copyright (c) 2006 Columbia University.
12 %
13 % This file is part of LabROSA-coversongID
14 %
15 % LabROSA-coversongID is free software; you can redistribute it and/or modify
16 % it under the terms of the GNU General Public License version 2 as
17 % published by the Free Software Foundation.
18 %
19 % LabROSA-coversongID is distributed in the hope that it will be useful, but
20 % WITHOUT ANY WARRANTY; without even the implied warranty of
21 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 % General Public License for more details.
23 %
24 % You should have received a copy of the GNU General Public License
25 % along with LabROSA-coversongID; if not, write to the Free Software
26 % Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
27 % 02110-1301 USA
28 %
29 % See the file "COPYING" for the text of the license.
30
31 % downweight fundamentals below here
32 if nargin < 4; fminl = 150; end
33 if nargin < 5; fminu = 300; end
34 % highest frequency we look to
35 if nargin < 6; fmaxl = 2000; end
36 if nargin < 7; fmaxu = 4000; end
37
38
39 % Calculate the inst freq gram
40 [I,S] = ifgram(d,w,w/2,w/4,sr);
41
42 % Only look at bins up to 2 kHz
43 maxbin = round(fmaxu * (w/sr) );
44 %maxbin = size(I,1)
45 minbin = round(fminl * (w/sr) );
46
47 % Find plateaus in ifgram - stretches where delta IF is < thr
48 ddif = [I(2:maxbin, :);I(maxbin,:)] - [I(1,:);I(1:(maxbin-1),:)];
49
50 % expected increment per bin = sr/w, threshold at 3/4 that
51 dgood = abs(ddif) < .75*sr/w;
52
53 % delete any single bins (both above and below are zero);
54 dgood = dgood .* ([dgood(2:maxbin,:);dgood(maxbin,:)] > 0 | [dgood(1,:);dgood(1:(maxbin-1),:)] > 0);
55
56 % check it out
57 %p = dgood;
58
59 % reconstruct just pitchy cells?
60 %r = istft(p.*S,w,w/2,w/4);
61
62 p = 0*dgood;
63 m = 0*dgood;
64
65 % For each frame, extract all harmonic freqs & magnitudes
66 for t = 1:size(I,2)
67 ds = dgood(:,t)';
68 lds = length(ds);
69 % find nonzero regions in this vector
70 st = find(([0,ds(1:(lds-1))]==0) & (ds > 0));
71 en = find((ds > 0) & ([ds(2:lds),0] == 0));
72 npks = length(st);
73 frqs = zeros(1,npks);
74 mags = zeros(1,npks);
75 for i = 1:length(st)
76 bump = abs(S(st(i):en(i),t));
77 frqs(i) = (bump'*I(st(i):en(i),t))/(sum(bump)+(sum(bump)==0));
78 mags(i) = sum(bump);
79 if frqs(i) > fmaxu
80 mags(i) = 0;
81 frqs(i) = 0;
82 elseif frqs(i) > fmaxl
83 mags(i) = mags(i) * max(0, (fmaxu - frqs(i))/(fmaxu-fmaxl));
84 end
85 % downweight magnitudes below? 200 Hz
86 if frqs(i) < fminl
87 mags(i) = 0;
88 frqs(i) = 0;
89 elseif frqs(i) < fminu
90 % 1 octave fade-out
91 mags(i) = mags(i) * (frqs(i) - fminl)/(fminu-fminl);
92 end
93 if frqs(i) < 0
94 mags(i) = 0;
95 frqs(i) = 0;
96 end
97
98 end
99
100 % then just keep the largest at each frame (for now)
101 % [v,ix] = max(mags);
102 % p(t) = frqs(ix);
103 % m(t) = mags(ix);
104 % No, keep them all
105 %bin = st;
106 bin = round((st+en)/2);
107 p(bin,t) = frqs;
108 m(bin,t) = mags;
109 end
110
111 %% Pull out the max in each column
112 %[mm,ix] = max(m);
113 %% idiom to retrieve different element from each column
114 %[nr,nc] = size(p);
115 %pp = p((nr*[0:(nc-1)])+ix);
116 %mm = m((nr*[0:(nc-1)])+ix);
117 % r = synthtrax(pp,mm,sr,w/4);
118
119 %p = pp;
120 %m = mm;
121