function [x, HistoBasis, Ostar, fstar, Mth] = func_emissionProjection_Histo(m, Qstar, param, kast, lawtype)
% Computes fstar and its projection on the histogram basis.

% Stationary law.
pistar = func_stationaryLaw(Qstar);

% True emission laws and their projection onto Sm
meshlength = 10000;
x=linspace(0,1,meshlength);

% Density of the emission laws.
fstar = func_emissionDensities(x,param,kast,lawtype);

% Histogram basis
HistoBasis=zeros(m,meshlength);
for j=1:m
    HistoBasis(j,:)=(x>(j-1)/m).*(x<=j/m);
end
HistoBasis=sqrt(m)*HistoBasis;
% HistoBasis(j,x) = 0 if x isn't in the j-th interval (open to the
% left, closed to the right), else sqrt(m).

% True law of the observations
Ostar = zeros(m,kast);
Ostar = (1/meshlength).*HistoBasis*(fstar');

Mth = zeros(m,m,m);
for b=1:m
    Mth(:,b,:) = Ostar * diag(pistar) * Qstar * diag(Ostar(b,:)) * Qstar * Ostar';
end
