annotate 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
rev   line source
boblsturm@0 1 function Y = chromagram_IF(d,sr,fftlen,nbin,f_ctr,f_sd)
boblsturm@0 2 % Y = chromagram_IF(d,sr,fftlen,nbin,f_ctr,f_sd)
boblsturm@0 3 % Calculate a "chromagram" of the sound in d (at sampling rate sr)
boblsturm@0 4 % Use windows of fftlen points, hopped by ffthop points
boblsturm@0 5 % Divide the octave into nbin steps
boblsturm@0 6 % Weight with center frequency f_ctr (in Hz) and gaussian SD f_sd
boblsturm@0 7 % (in octaves)
boblsturm@0 8 % Use instantaneous frequency to keep only real harmonics.
boblsturm@0 9 % 2006-09-26 dpwe@ee.columbia.edu
boblsturm@0 10
boblsturm@0 11 % Copyright (c) 2006 Columbia University.
boblsturm@0 12 %
boblsturm@0 13 % This file is part of LabROSA-coversongID
boblsturm@0 14 %
boblsturm@0 15 % LabROSA-coversongID is free software; you can redistribute it and/or modify
boblsturm@0 16 % it under the terms of the GNU General Public License version 2 as
boblsturm@0 17 % published by the Free Software Foundation.
boblsturm@0 18 %
boblsturm@0 19 % LabROSA-coversongID is distributed in the hope that it will be useful, but
boblsturm@0 20 % WITHOUT ANY WARRANTY; without even the implied warranty of
boblsturm@0 21 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
boblsturm@0 22 % General Public License for more details.
boblsturm@0 23 %
boblsturm@0 24 % You should have received a copy of the GNU General Public License
boblsturm@0 25 % along with LabROSA-coversongID; if not, write to the Free Software
boblsturm@0 26 % Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
boblsturm@0 27 % 02110-1301 USA
boblsturm@0 28 %
boblsturm@0 29 % See the file "COPYING" for the text of the license.
boblsturm@0 30
boblsturm@0 31 if nargin < 3; fftlen = 2048; end
boblsturm@0 32 if nargin < 4; nbin = 12; end
boblsturm@0 33 if nargin < 5; f_ctr = 1000; end
boblsturm@0 34 if nargin < 6; f_sd = 1; end
boblsturm@0 35
boblsturm@0 36 A0 = 27.5; % Hz
boblsturm@0 37 A440 = 440; % Hz
boblsturm@0 38 f_ctr_log = log(f_ctr/A0) / log(2);
boblsturm@0 39
boblsturm@0 40 fminl = octs2hz(hz2octs(f_ctr)-2*f_sd);
boblsturm@0 41 fminu = octs2hz(hz2octs(f_ctr)-f_sd);
boblsturm@0 42 fmaxl = octs2hz(hz2octs(f_ctr)+f_sd);
boblsturm@0 43 fmaxu = octs2hz(hz2octs(f_ctr)+2*f_sd);
boblsturm@0 44
boblsturm@0 45 ffthop = fftlen/4;
boblsturm@0 46 nchr = 12;
boblsturm@0 47
boblsturm@0 48 % Calculate spectrogram and IF gram pitch tracks...
boblsturm@0 49 [p,m]=ifptrack(d,fftlen,sr,fminl,fminu,fmaxl,fmaxu);
boblsturm@0 50
boblsturm@0 51 [nbins,ncols] = size(p);
boblsturm@0 52
boblsturm@0 53 %disp(['ncols = ',num2str(ncols)]);
boblsturm@0 54
boblsturm@0 55 % chroma-quantized IF sinusoids
boblsturm@0 56 Pocts = hz2octs(p+(p==0));
boblsturm@0 57 Pocts(p(:)==0) = 0;
boblsturm@0 58 % Figure best tuning alignment
boblsturm@0 59 nzp = find(p(:)>0);
boblsturm@0 60 %hist(nchr*Pmapo(nzp)-round(nchr*Pmapo(nzp)),100)
boblsturm@0 61 [hn,hx] = hist(nchr*Pocts(nzp)-round(nchr*Pocts(nzp)),100);
boblsturm@0 62 centsoff = hx(find(hn == max(hn)));
boblsturm@0 63 % Adjust tunings to align better with chroma
boblsturm@0 64 Pocts(nzp) = Pocts(nzp) - centsoff(1)/nchr;
boblsturm@0 65
boblsturm@0 66 % Quantize to chroma bins
boblsturm@0 67 PoctsQ = Pocts;
boblsturm@0 68 PoctsQ(nzp) = round(nchr*Pocts(nzp))/nchr;
boblsturm@0 69
boblsturm@0 70 % map IF pitches to chroma bins
boblsturm@0 71 Pmapc = round(nchr*(PoctsQ - floor(PoctsQ)));
boblsturm@0 72 Pmapc(p(:) == 0) = -1;
boblsturm@0 73 Pmapc(Pmapc(:) == nchr) = 0;
boblsturm@0 74
boblsturm@0 75 Y = zeros(nchr,ncols);
boblsturm@0 76 for t = 1:ncols;
boblsturm@0 77 Y(:,t)=(repmat([0:(nchr-1)]',1,size(Pmapc,1))==repmat(Pmapc(:,t)',nchr,1))*m(:,t);
boblsturm@0 78 end