%% demo test

clear all;
Nt = 64;
Nr = 64;
M_h = 16; M_v = 16; M = M_h*M_v;

Ns = 4;

BS_loc = [2,0,10];
RIS_loc = [0,148,10];
UE_loc = [5,150,1.8];
K_factor = 1;
Rx_dBi = 0;
Tx_dBi = 24.5;



path_G = 7;
path_R = 7;

Nt_RF = 6;
Nr_RF = 6;

trans_Pt = 1e-3*10^(30/10); % 30dBm


sigma2 = 1e-3*10^(-90/10);  % -90dBm




%% generate channel
        [R,G,gain_G_path,AoD_G,AoA_G,AR_G_irs,AT_G_bs,...
    AR_R_re,gain_R_path,AT_R_irs,AoA_R,AoD_R] = gen_Chan_dBi_mis(Nr,Nt,M_h,M_v,...
    BS_loc,RIS_loc,UE_loc,K_factor,path_R,path_G,Rx_dBi,Tx_dBi);  % % Tx-antenn gain BS
% % estimated mismatch error channel 
% beta = 0.5*pi/180;
%        [est_R,est_G,err_AoD_G,err_AoA_G,est_AR_G_irs,est_AT_G_bs,...
%             est_AR_R_re,est_AT_R_irs]= gen_Chan_mismatch(Nr,Nt,M_h,M_v,...
%             path_R,path_G,Rx_dBi,Tx_dBi,gain_G_path,AoD_G,AoA_G,gain_R_path,AoA_R,AoD_R,beta);

%% our method
[H_man,v_man] =  test_Mani_0714( R,G,M, Ns,AR_G_irs,gain_G_path,gain_R_path,AT_R_irs,trans_Pt,sigma2);

%% hybrid precoding
mode2 = 2;snr = trans_Pt/sigma2/Ns;

[Cap_opt_man, Cap_hyb_man] = Cap_Approx_pow(H_man,Nt_RF,Nr_RF,Ns,Nt,Nr,snr,mode2);

Condi_man = Cal_condi(H_man,Ns);