function I_ph_AWGN = TS_ph(MC_run,AWGN_Fading_indicator)
K = 8;
%full CSI
H = zeros(1,K);
%H(1) = B_0, H(2) = H_1, H(3) = H_2, and etc.
%H_K is not used (casuality of harvasting energy.)
I_avg = zeros(MC_run,8);
SNR = 20;

tic
for itr = 1:MC_run
    %AWGN
    T_opt = zeros(1,K);
    S = [];
    loop = 0;
    for K_ind = 1:K %SNR = 0:20 db
        loop = loop+1;
        SNR_rms = 10^((1/10)*SNR); %convert dB to rms 
        K_num = 2^(K_ind-1);
        if AWGN_Fading_indicator == 1 %%AWGN
            r = SNR_rms*ones(1,K_num);
        elseif AWGN_Fading_indicator == 2 %%Fading
            r = exprnd(SNR_rms,[1,K_num]);
        end
        H = zeros(1,K_num);
        for k_i = 1:K_num
            flc = rand(1); %flip the coin
            if flc <=1/3
                H(1,k_i) = 0.5;
            elseif flc<=2/3
                H(1,k_i) = 1;
            elseif flc<=1
                H(1,k_i) = 0;
            end
        end
        B = 0;
        T = zeros(1,K_num);
        for i = 1:K_num
            B = H(i)+B;
            if i== K_num
                T(i) = B;
                break
            end
            T(i) = B/2;
            B = B/2;
                
        end
        I  = log2(1+T.*r);
        I_avg(itr,loop)= sum(I)/K_num;

    end
end
toc
I_ph_AWGN = mean(I_avg,1);


