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

% PURPOSE: This function generates the time series of the simulation exercises.

% INPUT VARIABLES:
%    numberExercise: Number of the simulation exercise.
%    class: Number of the population.
%    sampleSize: Number of elements to be generated.
%    T: Length of the processes/series to be generated.
%    paramVector: Vector with the parameters of the model.
%    contamType: Optional variable with the type of contamination.

% OUTPUT VARIABLES:
%    series: Matrix of size 'sampleSize by T' with the generated time series as rows.

% COMMENTS:
%   (1) The correct model is generated when it is called without 'contamType', while
%       the contaminating series are generated when this argument is determined.
%   (2) In the first exercise, processes are stationary; in the second, two-piece 
%       piecewise stationary; in the third, nowhere stationary.
%   (3) The user can easily add new models of stochastic processes.

function series = dataExercisesTS(numberExercise, class, sampleSize, T, paramVector, contamType)

switch numberExercise
  case 1
    if exist('contamType','var')  % Generating contaminants only
      switch contamType
        case 'A'
          series = funcARMApq(paramVector(2), paramVector(1), sampleSize, T);
        case 'B'
          series = funcARMApq(-0.9, paramVector(2), sampleSize, T);
        case 'C'
          series = funcARMApq(0.9, paramVector(2), sampleSize, T);
      end
    else  % Generating time series without contamination
      series = funcARMApq(paramVector(1), paramVector(2), sampleSize, T);
    end
  case 2  % T must be an even number
    if exist('contamType','var')  % Generating contaminants only
      switch contamType
        case 'A'
          series = funcARMApq(paramVector(2), paramVector(1), sampleSize, T/2);
        case 'B'
          series = funcARMApq(-0.9, paramVector(2), sampleSize, T/2);
        case 'C'
          series = funcARMApq(0.9, paramVector(2), sampleSize, T/2);
      end
    else  % Generating time series without contamination
      series = funcARMApq(paramVector(1), paramVector(2), sampleSize, T/2);
    end
    % Adding white noise
    series = [normrnd(0,1,sampleSize,T/2) series];
  case 3
    if exist('contamType','var')  % Generating contaminants only
      switch contamType
        case 'A'
          series = funcAR2tv([paramVector(1) 0.2 paramVector(3)], sampleSize, T);
        case 'B'
          series = funcAR2tv([paramVector(1) -0.9 paramVector(3)], sampleSize, T);
        case 'C'
          series = funcAR2tv([paramVector(1) 0.9 paramVector(3)], sampleSize, T);
      end
    else  % Generating time series without contamination
      series = funcAR2tv(paramVector, sampleSize, T);
    end
end

end
