annotate aim-mat/tools/@signal/getoneperiod.m @ 4:537f939baef0 tip

various bug fixes and changed copyright message
author Stefan Bleeck <bleeck@gmail.com>
date Tue, 16 Aug 2011 14:37:17 +0100
parents 20ada0af3d7d
children
rev   line source
tomwalters@0 1 % method of class @signal
tomwalters@0 2 %
tomwalters@0 3 % INPUT VALUES:
tomwalters@0 4 %
tomwalters@0 5 % RETURN VALUE:
tomwalters@0 6 %
bleeck@3 7 % This external file is included as part of the 'aim-mat' distribution package
bleeck@3 8 % (c) 2011, University of Southampton
bleeck@3 9 % Maintained by Stefan Bleeck (bleeck@gmail.com)
bleeck@3 10 % download of current version is on the soundsoftware site:
bleeck@3 11 % http://code.soundsoftware.ac.uk/projects/aimmat
bleeck@3 12 % documentation and everything is on http://www.acousticscale.org
bleeck@3 13
tomwalters@0 14
tomwalters@0 15 function per=getoneperiod(signal,risetime)
tomwalters@0 16 % returns one period of the signal
tomwalters@0 17 % to find out about periodicy, the maxima are searched
tomwalters@0 18 % from risetime s after the beginning (because of the rise time)
tomwalters@0 19
tomwalters@0 20 if nargin < 2
tomwalters@0 21 risetime=0.01; % default: 10 ms
tomwalters@0 22 end
tomwalters@0 23
tomwalters@0 24 % the maxima are received by the hilbert envelope
tomwalters@0 25 h=hilbertenvelope(signal);
tomwalters@0 26 maxsi=max(h);
tomwalters@0 27 % to get good maxima, we need to define some threshold, when a maximum is a real maximum
tomwalters@0 28 % lets take 10 percent...
tomwalters@0 29
tomwalters@0 30 % [lmax,tmax]=getlocalmaxima(h,maxsi/1000000); %returns all the local maxima and the corresponding times
tomwalters@0 31 [lmax,tmax]=getlocalmaxima(h,maxsi/10); %returns all the local maxima and the corresponding times
tomwalters@0 32 % tmax=getzerocrossings(h,maxsi/100); %returns all the local maxima and the corresponding times
tomwalters@0 33
tomwalters@0 34 % zweite Möglichkeit: mache die FFT der Hilberteinhüllenden und schaue nach dem höchsten peak
tomwalters@0 35 % geht nicht, da die Auflösung viel zu schlecht ist (96kHz->10 Hz Auflösungsvermögen)
tomwalters@0 36
tomwalters@0 37 nrmax=size(tmax,2);
tomwalters@0 38 if nrmax < 2 % keine Periodizität
tomwalters@0 39 per=0;
tomwalters@0 40 return;
tomwalters@0 41 end
tomwalters@0 42
tomwalters@0 43 i=1;
tomwalters@0 44 % suche in einer Schleife die ersten beiden Maxima hinter der Anstiegszeit
tomwalters@0 45 while i < nrmax
tomwalters@0 46 if tmax(i) > risetime % hinter der Anstiegszeit
tomwalters@0 47 if i<nrmax
tomwalters@0 48 t1=tmax(i); % der erste Hügel
tomwalters@0 49 t2=tmax(i+1); % der zweite Hügel -> dazwischen ist die Periode
tomwalters@0 50 break;
tomwalters@0 51 end
tomwalters@0 52 end
tomwalters@0 53 i=i+1;
tomwalters@0 54 end
tomwalters@0 55
tomwalters@0 56 dauer=t2-t1; % das ist die Dauer einer Periode
tomwalters@0 57 %ich will die Perioden aber nicht über die Maxima haben, weil das doof aussieht, sondern über die Minima
tomwalters@0 58 % also muss ich zwischen den zweien den tiefsten Punkt suchen
tomwalters@0 59
tomwalters@0 60 sr=getSR(signal);
tomwalters@0 61 x1=time2bin(signal,t1);
tomwalters@0 62 x2=time2bin(signal,t2);
tomwalters@0 63 a=1000000;
tomwalters@0 64 b=1231231;
tomwalters@0 65 werte=getdata(h);
tomwalters@0 66 tmin=0;
tomwalters@0 67 for i=x1:x2
tomwalters@0 68 c=werte(i);
tomwalters@0 69 if a >= b & b < c
tomwalters@0 70 tmin=bin2time(signal,i);
tomwalters@0 71 break; % das erste reicht uns vollkommen
tomwalters@0 72 end
tomwalters@0 73 a=b;
tomwalters@0 74 b=c;
tomwalters@0 75 end
tomwalters@0 76
tomwalters@0 77 per=getpart(signal,tmin,tmin+dauer);
tomwalters@0 78 per=setname(per,sprintf('One Period of Signal \n%s\n Periodlength: %5.2f ms',signal.name,getlength(per)*1000));