function [Mhat, Phat, Nhat, lhat] = func_empiricalEstimators_Trigo(m, Y)
% Computes the empirical estimators of the spectral method for the trigonometric basis.

disp('Computing empirical estimators.');
tic;

temp = size(Y);

Mhat=zeros(m,m,m);
Phat=zeros(m,m);
Nhat=zeros(m,m);
lhat=zeros(m,1);
for a=1:m
    coefa = sqrt(2)+(1-sqrt(2)).*(a==1);
    vecta = coefa .* (cos(pi.*(a-1).*Y(:,1:end-2)));
            lhat(a) = mean(vecta);
    for b=1:m
        coefb = sqrt(2)+(1-sqrt(2)).*(b==1);
        vectb = coefb .* (cos(pi.*(b-1).*Y(:,2:end-1)));
            Nhat(a,b) = mean(vecta .* vectb);
            Phat(a,b) = mean(...
                vecta .*...
                coefb .* (cos(pi.*(b-1).*Y(:,3:end))) );
        for c=1:m
            coefc = sqrt(2)+(1-sqrt(2)).*(c==1);
            vectc = coefc .* (cos(pi.*(c-1).*Y(:,3:end)));           
            Mhat(a,b,c) = mean(vecta .* vectb .* vectc); 
        end
    end
end

elapsedTime = toc;
disp([' ... finished in ' num2str(elapsedTime) ' seconds.']);
