annotate _beattracker/adapt_thresh.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 [dfout,m] = adapt_thresh(df,pre,post);
matthiasm@8 2
matthiasm@8 3
matthiasm@8 4
matthiasm@8 5
matthiasm@8 6 df = df(:)';
matthiasm@8 7 % uses juan's adaptive median threshold
matthiasm@8 8
matthiasm@8 9 alpha = 9;
matthiasm@8 10 thresh=0.033;
matthiasm@8 11 fn = @mean;
matthiasm@8 12
matthiasm@8 13 if(nargin<2)
matthiasm@8 14 pre = 8;
matthiasm@8 15 post = 7;
matthiasm@8 16 end
matthiasm@8 17
matthiasm@8 18 %df = df-min(df);
matthiasm@8 19 %alpha norm
matthiasm@8 20 %df = df/real(mean(abs(df+eps).^alpha).^(1/alpha));
matthiasm@8 21
matthiasm@8 22
matthiasm@8 23
matthiasm@8 24
matthiasm@8 25 % low pass filtering
matthiasm@8 26
matthiasm@8 27 %[b,a]=butter(2,0.28);
matthiasm@8 28
matthiasm@8 29 %b = [0.1600 0.3200 0.1600];
matthiasm@8 30 %a = [1.0000 -0.5949 0.2348];
matthiasm@8 31
matthiasm@8 32
matthiasm@8 33 %df=filtfilt(b,a,df);
matthiasm@8 34
matthiasm@8 35
matthiasm@8 36 % median threshold
matthiasm@8 37
matthiasm@8 38 N=length(df);
matthiasm@8 39
matthiasm@8 40 for i=1:min(post,N)
matthiasm@8 41 k=min(i+pre,N);
matthiasm@8 42 m(i)=feval(fn,df(1:k));
matthiasm@8 43 % m2(i) = feval(@mean,df(1:k));
matthiasm@8 44 end
matthiasm@8 45
matthiasm@8 46 if N>(post+pre)
matthiasm@8 47 m=[m feval(fn,buffer(df,post+pre+1,post+pre,'nodelay'))];
matthiasm@8 48 end
matthiasm@8 49
matthiasm@8 50 % if N>(post+pre)
matthiasm@8 51 % m2=[m2 feval(@mean,buffer(df,post+pre+1,post+pre,'nodelay'))];
matthiasm@8 52 % end
matthiasm@8 53
matthiasm@8 54 for i=N+(1-pre:0)
matthiasm@8 55 j=max(i-post,1);
matthiasm@8 56 m(i)=feval(fn,df(j:end));
matthiasm@8 57 % m2(i)=feval(@mean,df(j:end));
matthiasm@8 58 end
matthiasm@8 59
matthiasm@8 60 %df = (df- m*thresh);
matthiasm@8 61 df = df-m;
matthiasm@8 62
matthiasm@8 63 dfout = (df>0).*df;
matthiasm@8 64 %dfout = df;