comparison src/matlab/fft2chromamx.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 wts = fft2chromamx(nfft,nbins,sr,A440,ctroct,octwidth)
2 % wts = fft2chromamx(nfft,nbins,sr,A440,ctroct,octwidth)
3 % Create a wts matrix to convert FFT to Chroma
4 % A440 is optional ref frq for A
5 % ctroct, octwidth specify a dominance window - Gaussian
6 % weighting centered on ctroct (in octs, re A0 = 27.5Hz) and
7 % with a gaussian half-width of octwidth. Defaults to
8 % halfwidth = inf i.e. flat.
9 % 2006-06-29 dpwe@ee.columbia.edu
10
11 if nargin < 2; nbins = 12; end
12 if nargin < 3; sr = 22050; end
13 if nargin < 4; A440 = 440; end
14 if nargin < 5; ctroct = 5; end
15 if nargin < 6; octwidth = 0; end
16
17 wts = zeros(nbins, nfft);
18
19 fftfrqbins = nbins*hz2octs([1:(nfft-1)]/nfft*sr,A440);
20
21 % make up a value for the 0 Hz bin = 1.5 octaves below bin 1
22 % (so chroma is 50% rotated from bin 1, and bin width is broad)
23 fftfrqbins = [fftfrqbins(1)-1.5*nbins,fftfrqbins];
24
25 binwidthbins = [max(1, fftfrqbins(2:nfft) - fftfrqbins(1:(nfft-1))), 1];
26
27 D = repmat(fftfrqbins,nbins,1) - repmat([0:(nbins-1)]',1,nfft);
28
29 nbins2 = round(nbins/2);
30
31 % Project into range -nbins/2 .. nbins/2
32 % add on fixed offset of 10*nbins to ensure all values passed to rem are +ve
33 D = rem(D + nbins2 + 10*nbins, nbins) - nbins2;
34
35 % Gaussian bumps - 2*D to make them narrower
36 wts = exp(-0.5*(2*D./repmat(binwidthbins,nbins,1)).^2);
37
38 % normalize each column
39 wts = wts./repmat(sqrt(sum(wts.^2)),nbins,1);
40
41 % remove aliasing columns
42 wts(:,[(nfft/2+2):nfft]) = 0;
43
44 % Maybe apply scaling for fft bins
45 if octwidth > 0
46 wts = wts.*repmat(exp(-0.5*(((fftfrqbins/nbins - ctroct)/octwidth).^2)), nbins, 1);
47 end
48
49 %wts = binwidthbins;
50 %wts = fftfrqbins;
51
52 function octs = hz2octs(freq, A440)
53 % octs = hz2octs(freq, A440)
54 % Convert a frequency in Hz into a real number counting
55 % the octaves above A0. So hz2octs(440) = 4.0
56 % Optional A440 specifies the Hz to be treated as middle A (default 440).
57 % 2006-06-29 dpwe@ee.columbia.edu for fft2chromamx
58
59 %if nargin < 2; A440 = 440; end
60
61 % A4 = A440 = 440 Hz, so A0 = 440/16 Hz
62 octs = log(freq./(A440/16))./log(2);
63
64