
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%  Title: StatisCLAS: A Package of Classification Methods   %%%%
%%%%  Author: David Casado de Lucas                            %%%%
%%%%  Version: 29th May 2013                                   %%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% PURPOSE: This function generates a deterministic differentiable curve with
%          a peak in the middle position.

% INPUT VARIABLES:
%    t: Grid of points of the independent variable.
%    peakType: Type of peak.
%    peakParam: Parameter of the peak.
%    peakHeight: Final height of the peak (maximum.

% OUTPUT VARIABLES:
%    peak: Points of the curve with the peak

% COMMENTS:
%   (1) The width can be modified through 'peakParam'.
%   (2) Once the maximum of the peak is normalized, the final height of the peak
%       is the corresponding value included in 'peakHeight'. This value should
%       depend on the range of values of the function f(t); for example, the mean
%       of {f(t_i)} can be computed, and the height of the peak can be 1.25 times
%       this quantity; the user can select the relative extreme value of the peak.
%       These values can be be negative or null.

function peak = generatePeak(t, peakType, peakParam, peakHeight)

t = t-t(end)/2;

switch peakType
  case 'Agnesi'
    peak = (peakParam.^3)./(peakParam.^2 + t.^2);
    peak = peak/peakParam;
  case 'Gauss'
    peak = normpdf(t,0,peakParam);  % Or, directly:
    % peak = 1./(sqrt(2*pi)*peakParam*exp((t.^2)/(2*peakParam^2)));
    peak = peak/normpdf(0,0,peakParam);
  case 'Dirichlet'
    peak = sin((peakParam+0.5)*t)./sin(0.5*t);
    peak = peak/(2*peakParam+1);
  case 'Fejer'
    peak = (sin(0.5*peakParam*t)./sin(0.5*t)).^2;
    peak = peak/(peakParam^2);
end

peak = peakHeight*peak;

end
