function fstar = func_emissionDensities(x,param,kast,lawtype)
% Calculates the value of the emission densities on x.
% x:  1*meshlength  points on which the densities are evaluated
% param:  k*.  parameters of the emission densities
% kast: true order
% lawtype: cell of k strings containing the type of emission law

meshlength = size(x);
meshlength = meshlength(2);

fstar=zeros(kast,meshlength);
for j=1:kast
    if strcmp(lawtype(j), 'beta')
		% The emission law is a beta law.
        fstar(j,:)=betapdf(x,param(j,1),param(j,2));
    elseif strcmp(lawtype(j), 'hist')
		% The emission density is piecewise constant function.
        piecesNumber = size(param);
        piecesNumber = piecesNumber(2)/3; % Get number of pieces to check.

        for piece=1:piecesNumber
            fstar(j,:) = fstar(j,:) + (x > param(j,3*piece-2)) .* (x <= param(j,3*piece-1)) * param(j,3*piece);
        end
    end
end
