Mercurial > hg > silvet
comparison mirex2012-matlab/cell2sparse.m @ 2:8017dd4a650d
Add MIREX 2012 code
author | Chris Cannam |
---|---|
date | Wed, 19 Mar 2014 09:09:23 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
1:662b0a8b17b9 | 2:8017dd4a650d |
---|---|
1 function spCQT = cell2sparse(Xcq,octaves,bins,firstcenter,atomHOP,atomNr) | |
2 %Generates a sparse matrix containing the CQT coefficients (rasterized). | |
3 % | |
4 %The sparse matrix representation of the CQT coefficients contains all | |
5 %computed coefficients at the corresponding time-frequency location | |
6 %(similar to a spectrogram). For lower frequencies this means, that | |
7 %each coefficient is followed by zeros stemming from the fact, that the time | |
8 %resolution for lower frequencies decreases as the frequency resolution | |
9 %increases. Due to the design of the CQT kernel, however, the coefficients | |
10 %of different octaves are synchronised, meaning that for the second highest | |
11 %octave each coefficient is followed by one zero, for the next octave down | |
12 %two zeros are inserted, for the next octave four zeros are inserted and so | |
13 %on. | |
14 % | |
15 %INPUT: | |
16 % Xcq ... Cell array consisting of all coefficients for all octaves | |
17 % octaves ... Number of octaves processed | |
18 % bins ... Number of bins per octave | |
19 % firstcenter ... Location of the leftmost atom-stack in the temporal | |
20 % kernel | |
21 % atomHOP ... Spacing of two consecutive atom stacks | |
22 % atomNr ... Number of atoms per bin within the kernel | |
23 % | |
24 %Christian Schörkhuber, Anssi Klapuri 2010-06 | |
25 | |
26 if 0 | |
27 %% this version has big memory consumption but is very fast | |
28 emptyHops = firstcenter/atomHOP; | |
29 drop = emptyHops*2^(octaves-1)-emptyHops; %distance between first value in highest octave and first value in lowest octave | |
30 spCQT = zeros(bins*octaves,size(Xcq{1},2)*atomNr-drop); | |
31 | |
32 for i=1:octaves | |
33 drop = emptyHops*2^(octaves-i)-emptyHops; %first coefficients of all octaves have to be in synchrony | |
34 X = Xcq{i}; | |
35 if atomNr > 1 %more than one atom per bin --> reshape | |
36 Xoct = zeros(bins,atomNr*size(X,2)-drop); | |
37 for u=1:bins %reshape to continous windows for each bin (for the case of several wins per frame) | |
38 octX_bin = X((u-1)*atomNr+1:u*atomNr,:); | |
39 Xcont = reshape(octX_bin,1,size(octX_bin,1)*size(octX_bin,2)); | |
40 Xoct(u,:) = Xcont(1+drop:end); | |
41 end | |
42 X = Xoct; | |
43 else | |
44 X = X(:,1+drop:end); | |
45 end | |
46 binVec = bins*octaves-bins*i+1:bins*octaves-bins*(i-1); | |
47 spCQT(binVec,1:2^(i-1):size(X,2)*2^(i-1)) = X; | |
48 | |
49 end | |
50 spCQT = sparse(spCQT); %storing as sparse matrix at the end is the fastest way. Big memory consumption though! | |
51 | |
52 else | |
53 %% this version uses less memory but is noticable slower | |
54 emptyHops = firstcenter/atomHOP; | |
55 drops = emptyHops*2.^(octaves-(1:octaves))-emptyHops; | |
56 len = max(((atomNr*cellfun('size',Xcq,2)-drops).*2.^(0:octaves-1))); %number of columns of output matrix | |
57 spCQT = []; | |
58 | |
59 for i=octaves:-1:1 | |
60 drop = emptyHops*2^(octaves-i)-emptyHops; %first coefficients of all octaves have to be in synchrony | |
61 X = Xcq{i}; | |
62 if atomNr > 1 %more than one atom per bin --> reshape | |
63 Xoct = zeros(bins,atomNr*size(X,2)-drop); | |
64 for u=1:bins %reshape to continous windows for each bin (for the case of several wins per frame) | |
65 octX_bin = X((u-1)*atomNr+1:u*atomNr,:); | |
66 Xcont = reshape(octX_bin,1,size(octX_bin,1)*size(octX_bin,2)); | |
67 Xoct(u,:) = Xcont(1+drop:end); | |
68 end | |
69 X = Xoct; | |
70 else | |
71 X = X(:,1+drop:end); | |
72 end | |
73 X = upsample(X.',2^(i-1)).'; | |
74 X = [X zeros(bins,len-size(X,2))]; | |
75 spCQT = sparse([spCQT; X]); | |
76 end | |
77 | |
78 end |