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

History | View | Annotate | Download (2.16 KB)

1
function df = get_dfs(x,p)
2

    
3
% function to calculate the following onset detection functions
4
% df{1} = complex spectral difference
5
% df{2} = spectral difference
6
% df{3} = phase deviation
7
x = mean(x,2);
8

    
9
% onset analysis step increment
10
o_step = p.winlen*2; % should be 1024
11
% onset analysis winlen
12
o_winlen = o_step*2; % should be 2048
13

    
14
hlfwin = o_winlen/2; % will be half fft size
15

    
16
% formulate hanningz window function
17
win = hanningz(o_winlen);
18
%  win = tukeywin(o_winlen,0.5);
19

    
20
% loop parameters
21
N = length(x);
22
pin = 0;
23
pend = N - o_winlen;
24

    
25
% vectors to store phase and magnitude calculations
26
theta1 = zeros(hlfwin,1);
27
theta2 = zeros(hlfwin,1);
28
oldmag = zeros(hlfwin,1);
29

    
30
% output onset detection functions
31
df = {};
32

    
33
% df sample number
34
k = 0;
35
while pin<pend
36
    
37
    k=k+1;
38
    % calculate windowed fft frame
39
    segment = x(pin+1:pin+o_winlen);
40
    X = fft(fftshift(win.*segment));
41
    %X = X.*fftshift(hanningz(length(X)));
42
    X = X(floor(length(X)/2)+1:length(X),:);
43
  %  X = X.*[length(X):-1:1]';
44
    % separate into magnitude
45
    mag = (abs(X));
46
	
47
%  	mag = [0 abs(diff(log(eps+mag)))']';
48
    % and phase
49
    theta = angle(X);
50
    
51
    % complexsd part
52
        dev=princarg(theta-2*theta1+theta2);
53
%  		keyboard
54
        meas=oldmag - (mag.*exp(i.*dev));
55
        df{1}(k) = sum(sqrt((real(meas)).^2+(imag(meas)).^2));
56
        
57
%      % spectral difference part    
58
%          dev2=sqrt(mag.^2-oldmag.^2);
59
%          df{2}(k) = sum(abs(dev2(mag>0.1)));
60
%      
61
%      
62
%      % phase deviation part
63
%          df{3}(k) = sum(abs(dev((mag>0.1))));
64
%  %        df{3}(k) = sum(abs(dev(end-5:end)));
65
%          
66
%      % energy part
67
%          df{4}(k) = sum(abs(segment));
68
%          
69
%      % hfc part    
70
%          df{5}(k) = sum(mag.*(length(mag):-1:1)');
71
%      %    df{5}(k) = sum(mag.*rand(hlfwin,1));
72
%          
73
    % update vectors
74
    theta2 = theta1;
75
    theta1 = theta;
76
    oldmag = mag;
77
    pin = pin+o_step;
78
end
79

    
80
% now interpolate each detection function by a factor of 2,
81
% to get resolution of 11.6ms
82

    
83
for j=1:1,%5
84
    df{j} = interp(df{j},2);
85
    % also check there are no negative elements
86
    df{j}(df{j}<0) = 0;
87
    % and scale to sum to unity
88
%    df{j} = (df{j}+eps)/sum(df{j}+eps);
89
end
90