% method of class @
% function newsig=squeeze(sig,factor) 
%   INPUT VALUES:
%  		sig: orginal @signal
%		factor: factor, by which the signal is squeezed
%   RETURN VALUE:
%		newsig: squeezed signal
% 
% reduces the length of the signal by scaling it in time
%
% (c) 2003-2008, University of Cambridge, Medical Research Council 
% Maintained by Tom Walters (tcw24@cam.ac.uk), written by Stefan Bleeck (stefan@bleeck.de)
% http://www.pdn.cam.ac.uk/cnbh/aim2006
% $Date: 2008-06-10 18:00:16 +0100 (Tue, 10 Jun 2008) $
% $Revision: 585 $

function newsig=squeeze(sig,factor)


%%%%%%%%%%%%%%%
% if squeezed it becomes shorter
if factor < 1
    len=getlength(sig);
    newlen=len*factor;
    sr=sig.samplerate;
    newsr=sr;   % dont change the sr
    if newlen < newsr
        newlen=newsr;
    end
    newsig=signal(newlen,newsr);
    nr_points=getnrpoints(newsig);
    new_vals=zeros(nr_points,1);
    for i=1:nr_points
        whichstart=(i-1)*newsr/factor;
        whichstop=i*newsr/factor;
        
        if whichstop>len
            whichstop=len;
        end
        new_vals(i)=average(sig,whichstart,whichstop);    
    end
    newsig=setvalues(newsig,new_vals);
    return
end

newsig=sig;


