I just found that i generated the random number wrongly, should be:
x=mu + sigma.*randn(n,1);
and not:
x=sigma + mu.*randn(n,1);
but i still can't find obtain reasonable estimate of mu and sigma. they are closer to a truncated normal distribution (which only consider the observed value).
the revised code is as followed:
-----------------------------------------------------------------------------------
%%Sampling from a normal distribution
mu=0.5; sigma=0.8;
%%No.of samples to generate
n=50;
x=mu + sigma.*randn(n,1);
%%Censoring data below this point (treating them as unobserved)
DL=0.01;
%%Tagging samples which are observed (above DL) and unobserved (below DL)
cens_id=(find(x<DL));
obs_id= (find(x>DL));
%%Applying negative log-likelihood to fit the data
nloglik= @(p) -sum(log(normcdf(x(cens_id), p(1),p(2))))...
-sum(log(normpdf(x(obs_id),p(1),p(2))));
[y]=fminsearch(nloglik,[0.5,0.5],optimset('MaxFunEvals',10000,'MaxIter',1000));
% y is [mu_hat, sigma_hat]
% mu_hat and sigma_hat should be really close to mu=0.5 and sigma=0.8 using Tobit regression
Thanks, Keah