% method of class @signal
% function sig=changesr(sig,sr_neu)
% changes the sample rate of the signal to the new samplerate. 
% the number of points of the signal change!
% new values are interpolated
%
%   INPUT VALUES:
%       sig1:       first @signal
%       sr_new: new samplerate
%
%   RETURN VALUE:
%       sigresult:  @signal `
%
% (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 sig=changesr(a,sr_neu)

sr_alt=a.samplerate;
if fround(sr_alt,5)==fround(sr_neu,5)   %nichts zu tun
    sig=a;
    return;
end


if sr_neu > sr_alt
    r=round(sr_neu/sr_alt);
%     r=sr_neu/sr_alt;
%     y = interp(a.werte,r);
    x_val_new = a.start_time+1/sr_neu:1/sr_neu:getlength(a);
    x_val_old = a.start_time+1/sr_alt:1/sr_alt:getlength(a);
    y = interp1(x_val_old, a.werte, x_val_new, 'cubic');
else
    p=sr_neu;
    q=sr_alt;
    y = resample(a.werte,p,q);
end

sig=signal(y);
sig.samplerate=sr_neu;
sig.name=a.name;
sig.unit_x=a.unit_x;
sig.unit_y=a.unit_y;
sig.start_time=a.start_time;
sig.nr_x_ticks=a.nr_x_ticks;
sig.x_tick_labels=a.x_tick_labels;