% Listing 15.1 of the book for ML estimates of mean and variance
% "Principles of System Identification: Theory and Practice"

% Arun K. Tangirala
% September 04, 2015
% Freely distributed under no warranty

% Requires Statistics toolbox
% Generate time-series
yk = randn(200,1);

% Estimate mean and variance using ML
[p_hat,p_ci] = mle(yk,'distribution','normal'); % Or mle('data')

% Compute standard errors
cov_phat = mlecov(p_hat,yk,'pdf',@normpdf);
err_phat = sqrt(diag(cov_phat));