annotate _beattracker/get_dfs.m @ 9:4ea6619cb3f5 tip

removed log files
author matthiasm
date Fri, 11 Apr 2014 15:55:11 +0100
parents b5b38998ef3b
children
rev   line source
matthiasm@8 1 function df = get_dfs(x,p)
matthiasm@8 2
matthiasm@8 3 % function to calculate the following onset detection functions
matthiasm@8 4 % df{1} = complex spectral difference
matthiasm@8 5 % df{2} = spectral difference
matthiasm@8 6 % df{3} = phase deviation
matthiasm@8 7 x = mean(x,2);
matthiasm@8 8
matthiasm@8 9 % onset analysis step increment
matthiasm@8 10 o_step = p.winlen*2; % should be 1024
matthiasm@8 11 % onset analysis winlen
matthiasm@8 12 o_winlen = o_step*2; % should be 2048
matthiasm@8 13
matthiasm@8 14 hlfwin = o_winlen/2; % will be half fft size
matthiasm@8 15
matthiasm@8 16 % formulate hanningz window function
matthiasm@8 17 win = hanningz(o_winlen);
matthiasm@8 18 % win = tukeywin(o_winlen,0.5);
matthiasm@8 19
matthiasm@8 20 % loop parameters
matthiasm@8 21 N = length(x);
matthiasm@8 22 pin = 0;
matthiasm@8 23 pend = N - o_winlen;
matthiasm@8 24
matthiasm@8 25 % vectors to store phase and magnitude calculations
matthiasm@8 26 theta1 = zeros(hlfwin,1);
matthiasm@8 27 theta2 = zeros(hlfwin,1);
matthiasm@8 28 oldmag = zeros(hlfwin,1);
matthiasm@8 29
matthiasm@8 30 % output onset detection functions
matthiasm@8 31 df = {};
matthiasm@8 32
matthiasm@8 33 % df sample number
matthiasm@8 34 k = 0;
matthiasm@8 35 while pin<pend
matthiasm@8 36
matthiasm@8 37 k=k+1;
matthiasm@8 38 % calculate windowed fft frame
matthiasm@8 39 segment = x(pin+1:pin+o_winlen);
matthiasm@8 40 X = fft(fftshift(win.*segment));
matthiasm@8 41 %X = X.*fftshift(hanningz(length(X)));
matthiasm@8 42 X = X(floor(length(X)/2)+1:length(X),:);
matthiasm@8 43 % X = X.*[length(X):-1:1]';
matthiasm@8 44 % separate into magnitude
matthiasm@8 45 mag = (abs(X));
matthiasm@8 46
matthiasm@8 47 % mag = [0 abs(diff(log(eps+mag)))']';
matthiasm@8 48 % and phase
matthiasm@8 49 theta = angle(X);
matthiasm@8 50
matthiasm@8 51 % complexsd part
matthiasm@8 52 dev=princarg(theta-2*theta1+theta2);
matthiasm@8 53 % keyboard
matthiasm@8 54 meas=oldmag - (mag.*exp(i.*dev));
matthiasm@8 55 df{1}(k) = sum(sqrt((real(meas)).^2+(imag(meas)).^2));
matthiasm@8 56
matthiasm@8 57 % % spectral difference part
matthiasm@8 58 % dev2=sqrt(mag.^2-oldmag.^2);
matthiasm@8 59 % df{2}(k) = sum(abs(dev2(mag>0.1)));
matthiasm@8 60 %
matthiasm@8 61 %
matthiasm@8 62 % % phase deviation part
matthiasm@8 63 % df{3}(k) = sum(abs(dev((mag>0.1))));
matthiasm@8 64 % % df{3}(k) = sum(abs(dev(end-5:end)));
matthiasm@8 65 %
matthiasm@8 66 % % energy part
matthiasm@8 67 % df{4}(k) = sum(abs(segment));
matthiasm@8 68 %
matthiasm@8 69 % % hfc part
matthiasm@8 70 % df{5}(k) = sum(mag.*(length(mag):-1:1)');
matthiasm@8 71 % % df{5}(k) = sum(mag.*rand(hlfwin,1));
matthiasm@8 72 %
matthiasm@8 73 % update vectors
matthiasm@8 74 theta2 = theta1;
matthiasm@8 75 theta1 = theta;
matthiasm@8 76 oldmag = mag;
matthiasm@8 77 pin = pin+o_step;
matthiasm@8 78 end
matthiasm@8 79
matthiasm@8 80 % now interpolate each detection function by a factor of 2,
matthiasm@8 81 % to get resolution of 11.6ms
matthiasm@8 82
matthiasm@8 83 for j=1:1,%5
matthiasm@8 84 df{j} = interp(df{j},2);
matthiasm@8 85 % also check there are no negative elements
matthiasm@8 86 df{j}(df{j}<0) = 0;
matthiasm@8 87 % and scale to sum to unity
matthiasm@8 88 % df{j} = (df{j}+eps)/sum(df{j}+eps);
matthiasm@8 89 end
matthiasm@8 90