% method of class @signal
% function sig=generatesweep(sig,fre1,fre2,amplitude,phase)
%   INPUT VALUES:
%       sig: original @signal with length and samplerate 
%       fre1: start frequency (Hz)
%       fre2: stop frequency (Hz)
%       amplitude: [1]
%       phase: startphase [0]
%       phases must be in degrees!
%   RETURN VALUE:
%       sig:  @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=generatesweep(sig,fre1,fre2,amplitude,phase)

if nargin < 5
    phase=0;
end
if nargin < 4
    amplitude=1;
end

if nargin <3 
    disp('GenerateSweep: Error: usage: sig=generatesweep(sig,fre1,fre2[,amplitude,phase])')
end

nr_points=getnrpoints(sig);
sr=getsr(sig);
length=getlength(sig);

from=0+phase;

fre_space=linspace(fre1,fre2,nr_points);    % the change of frequency
t_space=linspace(0,length,nr_points);    % a linear function of time
val=2*pi*t_space.*fre_space;

val=val + phase;

data=sin(val);

data=data*amplitude;

sig=signal(data);
sig=setsr(sig,sr);
sig=setname(sig,sprintf('Sweep from %4.2f kHz to %4.2f kHz',fre1/1000,fre2/1000));