% curve.m
%
% A Matlab script for exploring "exponential" and "logarithmic"
% amplitude envelopes.
%
% by Gary Scavone
% McGill University, 2004.

% We use an algorithm of the form:
%
%   y(t) = m*t^b
%
% We assume the user specifies the time duration, amplitude
% change, and curve parameter b ( > 0 ).

b = 1.5;

y = [4 2];    % y1 and y2 values
t = [-1 3];   % t1 and t2 values
tinc = 0.01;

m = diff( y ) / diff( t )^b;
tvals = t(1):tinc:t(2);
plot( tvals, y(1)+m*(tvals-t(1)).^b )
xlabel('Time');
ylabel('Amplitude');

disp('pause')
pause

% Now do iteratively.

yvals = zeros( size(tvals) );
yvals(1) = y(1);
tn = t(1);
tn = 0;

for n = 2:length(tvals),
  tn = tn + tinc;
  yvals(n) = y(1) + m*tn^b;
end

plot( tvals, yvals )
xlabel('Time');
ylabel('Amplitude');