function [h] = mcmch(AMP,freq,phase,h,mmax,H,k) counterh = 0; while counterh == 0 hnew = abs(round(h+randn)); if (hnew<=mmax) counterh = 1; end end Hnew = vectamp(hnew,mmax); oldprob = probabilityphi(AMP.*H,freq,phase)/(2*pi*2*pi*(0.08-0.01)*(8-1))^h; newprob = probabilityphi(AMP.*Hnew,freq,phase)/(2*pi*2*pi*(0.08-0.01)*(8-1))^hnew; if (newprob-oldprob) >= 0 h = hnew; elseif ((k>25000)& ((newprob/oldprob)>=rand)) h = hnew; end