Mercurial > hg > nimfks
comparison src/matlab/chromagram_IF.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 Y = chromagram_IF(d,sr,fftlen,nbin,f_ctr,f_sd) | |
2 % Y = chromagram_IF(d,sr,fftlen,nbin,f_ctr,f_sd) | |
3 % Calculate a "chromagram" of the sound in d (at sampling rate sr) | |
4 % Use windows of fftlen points, hopped by ffthop points | |
5 % Divide the octave into nbin steps | |
6 % Weight with center frequency f_ctr (in Hz) and gaussian SD f_sd | |
7 % (in octaves) | |
8 % Use instantaneous frequency to keep only real harmonics. | |
9 % 2006-09-26 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 if nargin < 3; fftlen = 2048; end | |
32 if nargin < 4; nbin = 12; end | |
33 if nargin < 5; f_ctr = 1000; end | |
34 if nargin < 6; f_sd = 1; end | |
35 | |
36 A0 = 27.5; % Hz | |
37 A440 = 440; % Hz | |
38 f_ctr_log = log(f_ctr/A0) / log(2); | |
39 | |
40 fminl = octs2hz(hz2octs(f_ctr)-2*f_sd); | |
41 fminu = octs2hz(hz2octs(f_ctr)-f_sd); | |
42 fmaxl = octs2hz(hz2octs(f_ctr)+f_sd); | |
43 fmaxu = octs2hz(hz2octs(f_ctr)+2*f_sd); | |
44 | |
45 ffthop = fftlen/4; | |
46 nchr = 12; | |
47 | |
48 % Calculate spectrogram and IF gram pitch tracks... | |
49 [p,m]=ifptrack(d,fftlen,sr,fminl,fminu,fmaxl,fmaxu); | |
50 | |
51 [nbins,ncols] = size(p); | |
52 | |
53 %disp(['ncols = ',num2str(ncols)]); | |
54 | |
55 % chroma-quantized IF sinusoids | |
56 Pocts = hz2octs(p+(p==0)); | |
57 Pocts(p(:)==0) = 0; | |
58 % Figure best tuning alignment | |
59 nzp = find(p(:)>0); | |
60 %hist(nchr*Pmapo(nzp)-round(nchr*Pmapo(nzp)),100) | |
61 [hn,hx] = hist(nchr*Pocts(nzp)-round(nchr*Pocts(nzp)),100); | |
62 centsoff = hx(find(hn == max(hn))); | |
63 % Adjust tunings to align better with chroma | |
64 Pocts(nzp) = Pocts(nzp) - centsoff(1)/nchr; | |
65 | |
66 % Quantize to chroma bins | |
67 PoctsQ = Pocts; | |
68 PoctsQ(nzp) = round(nchr*Pocts(nzp))/nchr; | |
69 | |
70 % map IF pitches to chroma bins | |
71 Pmapc = round(nchr*(PoctsQ - floor(PoctsQ))); | |
72 Pmapc(p(:) == 0) = -1; | |
73 Pmapc(Pmapc(:) == nchr) = 0; | |
74 | |
75 Y = zeros(nchr,ncols); | |
76 for t = 1:ncols; | |
77 Y(:,t)=(repmat([0:(nchr-1)]',1,size(Pmapc,1))==repmat(Pmapc(:,t)',nchr,1))*m(:,t); | |
78 end |