No BSD License  

Highlights from
Generic Signal Class

from Generic Signal Class by Stefan Bleeck
A generic class that allows easy signal (data in time) managment

per=getoneperiod(signal,risetime)
% method of class @signal
% 
%   INPUT VALUES:
%  
%   RETURN VALUE:
%
% 
% (c) 2003, University of Cambridge, Medical Research Council 
% Stefan Bleeck (stefan@bleeck.de)
% http://www.mrc-cbu.cam.ac.uk/cnbh/aimmanual
% $Date: 2003/01/17 16:57:43 $
% $Revision: 1.3 $

function per=getoneperiod(signal,risetime)
% returns one period of the signal
% to find out about periodicy, the maxima are searched
% from risetime s after the beginning (because of the rise time)

if nargin < 2
    risetime=0.01;   % default: 10 ms
end

% the maxima are received by the hilbert envelope
h=hilbertenvelope(signal);
maxsi=max(h);
% to get good maxima, we need to define some threshold, when a maximum is a real maximum
% lets take 10 percent...

% [lmax,tmax]=getlocalmaxima(h,maxsi/1000000);    %returns all the local maxima and the corresponding times
[lmax,tmax]=getlocalmaxima(h,maxsi/10);    %returns all the local maxima and the corresponding times
% tmax=getzerocrossings(h,maxsi/100);    %returns all the local maxima and the corresponding times

% zweite Mglichkeit: mache die FFT der Hilberteinhllenden und schaue nach dem hchsten peak
% geht nicht, da die Auflsung viel zu schlecht ist (96kHz->10 Hz Auflsungsvermgen)

nrmax=size(tmax,2);
if  nrmax < 2   % keine Periodizitt
    per=0;
    return;
end

i=1;
% suche in einer Schleife die ersten beiden Maxima hinter der Anstiegszeit
while i < nrmax 
    if tmax(i) > risetime % hinter der Anstiegszeit
        if i<nrmax 
            t1=tmax(i); % der erste Hgel
            t2=tmax(i+1); % der zweite Hgel -> dazwischen ist die Periode
            break;
        end
    end
    i=i+1;
end

dauer=t2-t1; % das ist die Dauer einer Periode
%ich will die Perioden aber nicht ber die Maxima haben, weil das doof aussieht, sondern ber die Minima
% also muss ich zwischen den zweien den tiefsten Punkt suchen

sr=getSR(signal);
x1=time2bin(signal,t1);
x2=time2bin(signal,t2);
a=1000000;
b=1231231;
werte=getdata(h);
tmin=0;
for i=x1:x2
    c=werte(i);
    if a >= b & b < c
        tmin=bin2time(signal,i);
        break; % das erste reicht uns vollkommen
    end
    a=b;
    b=c;
end

per=getpart(signal,tmin,tmin+dauer);
per=setname(per,sprintf('One Period of Signal \n%s\n Periodlength: %5.2f ms',signal.name,getlength(per)*1000));

Contact us at files@mathworks.com