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 / _beattracker / chromaframe.m @ 8:b5b38998ef3b

History | View | Annotate | Download (2.78 KB)

1
function [spec] = chromaframe(x,spark);
2
%  function [spec,mfcc,cq,hpcp,chroma] = chromaframe(x,spark);
3

    
4
% function to return spectrogram, constq, hpcp and chromagram
5
% for one single frame of arbitrary length
6
% with the possible inclusion of an adaptive thresholding stage.
7

    
8
fmin = 110; 
9
fmax = 880;
10

    
11
if nargin<2
12
    spark = sparsekernel(fmin, fmax, 36, 44100/16, 0.054);
13
    spark(1025:end,:) = [];
14
end
15

    
16

    
17
% make x a row vector
18
x = x(:)';
19
x2 = x;
20
fs = 44100;
21
% downsample by a factor of 16.
22
%x = x(1:16:end);
23
% x = resample(x,11025,44100);
24
 x = resample(x,2756,11024);
25
%  x = resample(x,11024,44096);
26

    
27
len = length(x);
28

    
29

    
30
% make windowing function
31
w = hanningz(len);
32
w = w(:)';
33
%  w = ones(1,length(x)); % or no windowing... shouldn't be better..
34
% take fft
35
spec = abs(fft(w.*x,2048));
36
spec = adapt_thresh(spec(1:1024),16,15);
37

    
38
%  %spec = spec(1:1024);
39
%  
40
%  %cq = adapt_thresh(abs(spec*spark));   
41
%  cq = abs(spec*spark);
42
%  hpcp = zeros(1,36);
43
%  
44
%  for k=1:36 
45
%      hpcp(k) =  sum(abs(cq(k:36:end)));
46
%  end
47
%  
48
%  %hpcp = adapt_thresh(hpcp,2,3);
49
%  
50
%  % for k=1:round(abs(log2(fmax/fmin))),
51
%  %     l(k) = sum(hpcp(k:3:end));
52
%  % end
53
%  % 
54
%  % [val,ind] = max(l);
55
%  % 
56
%  % chroma = hpcp(ind:3:end);
57
%  % 
58
%  for i=1:12 % sum bins.. 
59
%      chroma(i) = sum(hpcp((i-1)*3+1:3*i));
60
%  end
61

    
62

    
63
%chroma = adapt_thresh(chroma,3,2);
64

    
65
%  % modulated complex lapped transform
66
%  % spec = abs(fmclt(x',1024)');
67
%  % spec = adapt_thresh(spec);
68
%  
69
%  % % try to treat everything as gaussians
70
%  % n = 1:length(cq);
71
%  % mu = sum(n.*cq)/sum(cq);
72
%  % sigma = sqrt(sum((n-mu).^2)/sum(cq));
73
%  % cq = exp(-0.5 * ((n - mu)./sigma).^2) ./ (sqrt(2*pi) .* sigma);
74
%  % 
75
%  % n = 1:length(hpcp);
76
%  % mu = sum(n.*hpcp)/sum(hpcp);
77
%  % sigma = sqrt(sum((n-mu).^2)/sum(hpcp));
78
%  % hpcp = exp(-0.5 * ((n - mu)./sigma).^2) ./ (sqrt(2*pi) .* sigma);
79
%  % 
80
%  % n = 1:length(chroma);
81
%  % mu = sum(n.*chroma)/sum(chroma);
82
%  % sigma = sqrt(sum((n-mu).^2)/sum(chroma));
83
%  % chroma = exp(-0.5 * ((n - mu)./sigma).^2) ./ (sqrt(2*pi) .* sigma);
84
%  % 
85
%  % n = 1:length(spec);
86
%  % mu = sum(n.*spec)/sum(spec);
87
%  % sigma = sqrt(sum((n-mu).^2)/sum(spec));
88
%  % spec = exp(-0.5 * ((n - mu)./sigma).^2) ./ (sqrt(2*pi) .* sigma);
89
%  
90
%  %x2 = resample(x2,8000,44100);
91
%  %spec = mfcc(x',8000,100);
92
%  %spec = abs(sum(spec'))';
93
%  
94
% x2 = x2(1:4:end);
95
% spec2 = abs(fft(hanning(length(x2))'.*x2,2048));
96
% spec2 = spec2(1:1024);
97
%  mlmx = fft2melmx(1024,round(44100/16),40);
98
% [size(mlmx) size(spec2)];
99
%  mfcc = 20*log10(1+spec*mlmx');
100
%  spec = 20*log10(1+spec*mlmx');
101

    
102
%  spec = adapt_thresh(mfcc,2,3);
103
%  x2 = resample(x2,1378,44096);
104
%  len = length(x2);
105
%  w = hanningz(len);
106
%  w = w(:)';
107
%  % take fft
108
%  spec = abs(fft(w.*x2,1024));
109
%  spec = adapt_thresh(spec(1:512),16,15);
110
  spec = spec(1:512);
111
%  mlmx = fft2melmx(512,round(44100),40);
112
%  spec = spec*mlmx';