//discretized normal distribution simulator
//distribution of means as a function of averaging width

numavg=[1:10,10:10:100]; //number of samples to average
numst=1000; //number of random trials for distribution of means
ssig=10; //sigma of incoming signal in LSBs
boffs=0; //center of distribution, with bit boundaries at integers (round down) and bit values are at half-integers
stdm=zeros(1,length(numavg));//zeros(1,length(numavg));
mnm=stdm;
mi=1;
for ni=1:length(numavg)
    sr=grand(numavg(ni),numst,'nor',boffs(mi),ssig); //generate random signal centered on 0
    sdr=floor(sr)+0.5; //discretize to half-integers
    sdm=mean(sdr,1); //take averages
    stdm(ni)=stdev(sdm); //standard deviation of the means
    mnm(ni)=mean(sdm); //mean of means
end
plot(numavg, stdm);
title(string(ssig));
xlabel('Number of samples averaged')
ylabel('Standard deviation of mean')

//the effect is: sigma of mean is reduced by 1/sqrt(N) even for ssig=1 or 0.5 or 0.2, by 0.1 it drops to zero (below observation limit)