tomwalters@0: % method of class @signal tomwalters@0: % tomwalters@0: % INPUT VALUES: tomwalters@0: % tomwalters@0: % RETURN VALUE: tomwalters@0: % bleeck@3: % This external file is included as part of the 'aim-mat' distribution package bleeck@3: % (c) 2011, University of Southampton bleeck@3: % Maintained by Stefan Bleeck (bleeck@gmail.com) bleeck@3: % download of current version is on the soundsoftware site: bleeck@3: % http://code.soundsoftware.ac.uk/projects/aimmat bleeck@3: % documentation and everything is on http://www.acousticscale.org bleeck@3: tomwalters@0: tomwalters@0: function per=getoneperiod(signal,risetime) tomwalters@0: % returns one period of the signal tomwalters@0: % to find out about periodicy, the maxima are searched tomwalters@0: % from risetime s after the beginning (because of the rise time) tomwalters@0: tomwalters@0: if nargin < 2 tomwalters@0: risetime=0.01; % default: 10 ms tomwalters@0: end tomwalters@0: tomwalters@0: % the maxima are received by the hilbert envelope tomwalters@0: h=hilbertenvelope(signal); tomwalters@0: maxsi=max(h); tomwalters@0: % to get good maxima, we need to define some threshold, when a maximum is a real maximum tomwalters@0: % lets take 10 percent... tomwalters@0: tomwalters@0: % [lmax,tmax]=getlocalmaxima(h,maxsi/1000000); %returns all the local maxima and the corresponding times tomwalters@0: [lmax,tmax]=getlocalmaxima(h,maxsi/10); %returns all the local maxima and the corresponding times tomwalters@0: % tmax=getzerocrossings(h,maxsi/100); %returns all the local maxima and the corresponding times tomwalters@0: tomwalters@0: % zweite Möglichkeit: mache die FFT der Hilberteinhüllenden und schaue nach dem höchsten peak tomwalters@0: % geht nicht, da die Auflösung viel zu schlecht ist (96kHz->10 Hz Auflösungsvermögen) tomwalters@0: tomwalters@0: nrmax=size(tmax,2); tomwalters@0: if nrmax < 2 % keine Periodizität tomwalters@0: per=0; tomwalters@0: return; tomwalters@0: end tomwalters@0: tomwalters@0: i=1; tomwalters@0: % suche in einer Schleife die ersten beiden Maxima hinter der Anstiegszeit tomwalters@0: while i < nrmax tomwalters@0: if tmax(i) > risetime % hinter der Anstiegszeit tomwalters@0: if i dazwischen ist die Periode tomwalters@0: break; tomwalters@0: end tomwalters@0: end tomwalters@0: i=i+1; tomwalters@0: end tomwalters@0: tomwalters@0: dauer=t2-t1; % das ist die Dauer einer Periode tomwalters@0: %ich will die Perioden aber nicht über die Maxima haben, weil das doof aussieht, sondern über die Minima tomwalters@0: % also muss ich zwischen den zweien den tiefsten Punkt suchen tomwalters@0: tomwalters@0: sr=getSR(signal); tomwalters@0: x1=time2bin(signal,t1); tomwalters@0: x2=time2bin(signal,t2); tomwalters@0: a=1000000; tomwalters@0: b=1231231; tomwalters@0: werte=getdata(h); tomwalters@0: tmin=0; tomwalters@0: for i=x1:x2 tomwalters@0: c=werte(i); tomwalters@0: if a >= b & b < c tomwalters@0: tmin=bin2time(signal,i); tomwalters@0: break; % das erste reicht uns vollkommen tomwalters@0: end tomwalters@0: a=b; tomwalters@0: b=c; tomwalters@0: end tomwalters@0: tomwalters@0: per=getpart(signal,tmin,tmin+dauer); tomwalters@0: per=setname(per,sprintf('One Period of Signal \n%s\n Periodlength: %5.2f ms',signal.name,getlength(per)*1000));