To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Revision:

root / _chroma / newdict.m @ 8:b5b38998ef3b

History | View | Annotate | Download (4.21 KB)

1
s = chunkspectrogram(filename,4096,4096*7/8,4096,inf);
2
a = abs(s);
3
T = size(s,2);
4
%%
5
zeroind = find(sum(a)==0 | sum(a)==-inf);
6
a(:,zeroind) = randn(size(a,1),length(zeroind)).^2;
7

    
8
wind_size = 6 * 3 + 1;
9
pad_size = (wind_size-1)/2;
10
wind = qnormalise(hamming(wind_size),1,1);
11

    
12
atransf = wm' * qnormalise(a,2,1);
13

    
14
nFbin = size(wm,2);
15

    
16

    
17

    
18

    
19
% CHANGED: this is an equivalent formulation in terms of phase.
20
fftr=fft(sum(atransf(3:end-2,:),2));
21
th = -angle(fftr((nFbin - 4)/3+1)) - 2*pi/3;
22
th(th < -pi) = th(th < -pi) + 2*pi;
23
disp(440*2.^(th/2/pi/12))
24

    
25
for iFrame = 1:T
26
    atransf(:,iFrame) = interp1(1:nFbin, atransf(:,iFrame), (1:nFbin) + th / (2 * pi) * 3,'spline',0);
27
end
28

    
29

    
30
%
31
nFbin = size(atransf,1);
32
T = size(atransf,2);
33

    
34
% calculate running mean
35
m = conv2(atransf,wind(:),'valid');
36
m = [repmat(m(1,:),pad_size,1); m ; repmat(m(end,:),pad_size,1)];
37

    
38
% calculate running standard deviation
39
stdev = sqrt(conv2((atransf-m).^2,wind(:),'valid'));
40
stdev = [repmat(stdev(1,:),pad_size,1); stdev ; repmat(stdev(end,:),pad_size,1)];
41

    
42
% loamp = logical(atransf < 1.5 * m);
43
% atransf(loamp) = atransf(loamp)/5;
44
atransf = (atransf - m)./stdev;
45
atransf(atransf<0) = 0;
46

    
47
% atransf = qnormalise(atransf,inf,2);
48
% atransf(isnan(atransf)) = 0;
49

    
50
%% generate dictionary
51
nSBin = 3;
52
fs = 11025;
53
blocksize = 4096;
54
minMidi = 20;
55
maxMidi = 105;
56
overs = 40;
57
midiFrequencies = midinote2frequency(minMidi:1/nSBin:maxMidi);
58

    
59

    
60

    
61
dx = fs/blocksize/overs;
62
x = dx:dx:fs/2;
63
nX = length(x);
64

    
65
nMidi = length(midiFrequencies);
66
% nFFT = length(fftFrequencies);
67

    
68
midiWarp = semitonedistance(midiFrequencies,nSBin);
69
% fftWarp = ones(size(x)) * fs / blocksize;
70

    
71
B = zeros(256, 7*12);
72

    
73
for iMidi = 1:7*12
74
    f0 = midiFrequencies(3*iMidi+1);
75
    f = f0;
76
    factor = 1;
77
    help = (log(f0) - log(midiFrequencies(1)))/log(midiFrequencies(end));
78
    factorred(iMidi) = 0.9 * (1 - help) + 0.9 * help;
79
    fprintf(1,'%3.2f %%\r',iMidi/nMidi*100*3)
80
    midiVector = cospuls_warped(midiFrequencies,f,midiWarp);
81
    while f < 11025/2;
82
        f = f + f0;
83
        factor = factor * factorred(iMidi);
84
        midiVector = midiVector + factor * cospuls_warped(midiFrequencies,f,midiWarp);    
85
    end
86
    B(:,iMidi) = midiVector;
87
end
88
% %%
89

    
90
%%
91
B = qnormalise(B,1,1);
92
% C = B(:,12:6*36+11)';
93
C=B;
94
% atransf(atransf<0) = atransf(atransf<0)/5;
95
% mys = mldivide(C,(atransf));
96

    
97
atransf = sparse(atransf);
98

    
99
for t = 1:T
100
    fprintf('%0.1f %%\n',t/T*100)
101
    mys(:,t) = lsqnonneg(C,atransf(:,t));
102
end
103

    
104
% mys =  qnormalise(mys,1,1);
105
% mys(mys<0)=0;
106
imagesc(mys.*(mys>0))
107
axis xy
108
%%
109

    
110
n = size(mys,1);
111

    
112
bt_spacing = 1/4.5;
113

    
114
basswindow = cospuls(1:n,n * bt_spacing +0.5,n * 2 * bt_spacing);
115
% treblewindow =  cospuls(1:n,2 * n * bt_spacing+0.5,n * 2 * bt_spacing) + cospuls(1:n,3*n * bt_spacing+0.5,n* 2 * bt_spacing);
116
treblewindow = cospuls(1:n,n * 0.5 + 0.5,n * 2 * 0.5);
117
% treblewindow = basswindow(12:6*36+11)/2 + treblewindow(12:6*36+11);
118
% basswindow = basswindow(12:6*36+11);
119

    
120
%%
121
thirtysix2twelve = zeros(12,36);
122
for iSemitone = 0:11
123
    thirtysix2twelve(iSemitone+1,iSemitone*3+(1:3)) = 1;
124
end
125
if n == 256
126
    toPC = repmat(eye(36),7,1);
127
    toPC = [toPC(end-1:end,:); toPC; toPC(1:2,:)];
128
    bass_chromagram = mys' * diag(basswindow) * toPC * thirtysix2twelve';
129
    treble_chromagram = mys' * diag(treblewindow) * toPC * thirtysix2twelve';
130
else
131
    toPC = repmat(eye(12),7,1);
132
    bass_chromagram = mys' * diag(basswindow) * toPC;
133
    treble_chromagram = mys' * diag(treblewindow) * toPC;
134
end
135
% chromagram = mys' * repmat(eye(36),6,1);
136
thr_l = 0.0;
137
thr_h = 3;
138
treble_chromagram(treble_chromagram<thr)=thr_l;
139
bass_chromagram(bass_chromagram<thr)=thr_l;
140

    
141
treble_chromagram = circshift(treble_chromagram,[0 -3]);
142
bass_chromagram = circshift(bass_chromagram,[0, -3]);
143

    
144
% treble_chromagram = treble_chromagram + bass_chromagram/4;
145

    
146
% bass_chromagram = medfilt1(bass_chromagram,10);
147
% treble_chromagram = medfilt1(treble_chromagram,10);
148

    
149
%%
150
some = 100 * 0;
151
% subplot(211)
152
imagesc(qnormalise([(bass_chromagram');(treble_chromagram')],2,1))
153
hold on
154
ax = axis;
155
plot(ax(1:2),[12.5 12.5],'color',[0.7 0.7 0.7])
156
axis xy
157
hold off
158
% xlim([0 800] + some)
159
% subplot(212)
160
% imagesc()
161
% xlim([0 800] + some)
162
% axis xy
163
%%
164
dlmwrite('/Users/matthiasmauch/temptreble.csv',treble_chromagram, 'delimiter','\t');
165
dlmwrite('/Users/matthiasmauch/tempbass.csv',bass_chromagram, 'delimiter','\t');