annotate cell2sparse.m @ 1:3ea8ed09af0f tip

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