In [ ]:
x=1

In [ ]:
model_bp_proj_RaColony_20170921


Rotate original measurements 2 times
> In rbfcreate (line 142)
  In interp_bp (line 27)
  In shift_rotate_bp_composite (line 177)
  In model_bp_proj_RaColony_20170921 (line 111)
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND =  1.106667e-17.
File: rotate_all_click_2010308_36134_03_c08_rotated.mat
> In rbfcreate (line 142)
  In model_bp_proj_RaColony_20170921 (line 249)
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND =  2.834036e-23.
Rotate original measurements 1 times
File: rotate_all_click_2010308_36134_03_c09_rotated.mat
> In rbfcreate (line 142)
  In model_bp_proj_RaColony_20170921 (line 249)
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND =  8.469543e-22.
Rotate original measurements 2 times
File: rotate_all_click_2010308_36134_03_c10_rotated.mat
> In rbfcreate (line 142)
  In model_bp_proj_RaColony_20170921 (line 249)
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND =  8.263022e-22.
Rotate original measurements 3 times
File: rotate_all_click_2010308_36134_03_c11_rotated.mat
> In rbfcreate (line 142)
  In model_bp_proj_RaColony_20170921 (line 249)
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND =  5.022401e-22.
Rotate original measurements 1 times
File: rotate_all_click_2010308_36134_03_c12_rotated.mat
File: rotate_all_click_2010308_36134_03_c13_rotated.mat
> In rbfcreate (line 142)
  In model_bp_proj_RaColony_20170921 (line 249)
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND =  4.385064e-21.
Rotate original measurements 3 times
File: rotate_all_click_2010308_36134_03_c14_rotated.mat
> In rbfcreate (line 142)
  In model_bp_proj_RaColony_20170921 (line 249)
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND =  1.107534e-22.
Rotate original measurements 2 times
File: rotate_all_click_2010308_36134_03_c15_rotated.mat
> In rbfcreate (line 142)
  In model_bp_proj_RaColony_20170921 (line 249)
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND =  6.378800e-22.
Rotate original measurements 2 times
File: rotate_all_click_2010308_36134_03_c16_rotated.mat
> In rbfcreate (line 142)
  In model_bp_proj_RaColony_20170921 (line 249)
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND =  1.796415e-23.
Rotate original measurements 1 times
File: rotate_all_click_2010308_36134_03_c18_rotated.mat
> In rbfcreate (line 142)
  In model_bp_proj_RaColony_20170921 (line 249)
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND =  2.865204e-22.
Rotate original measurements 2 times
File: rotate_all_click_2010308_36134_03_c19_rotated.mat
> In rbfcreate (line 142)
  In model_bp_proj_RaColony_20170921 (line 249)
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND =  5.047741e-22.
Rotate original measurements 2 times
File: rotate_all_click_2010308_36134_03_c20_rotated.mat
> In rbfcreate (line 142)
  In model_bp_proj_RaColony_20170921 (line 249)
Warning: Matrix is close to singular or badly scaled. Results may be inaccurate. RCOND =  5.349488e-22.
Rotate original measurements 1 times

In [58]:
iB


iB =

    91


In [4]:
noise_mean = 0;  % added noise profile [dB]
noise_std = noise_std_all(iN);

In [5]:
script_name = 'model_bp_proj_RaColony_20170921'


script_name =

model_bp_proj_RaColony_20170921


In [6]:
script_name = sprintf('%s_std%2.1f',script_name,noise_std);
    save_path = fullfile(data_base_path,results_path,script_name);
    if ~exist(save_path,'dir')
        mkdir(save_path);
    end

In [7]:
save_path


save_path =

~/internal_2tb/Dropbox/Z_wjlee/projects/rousettus_bp/analysis_results_figs/model_bp_proj_RaColony_20170921_std1.0


In [8]:
S.param.noise_mean = noise_mean;
    S.param.noise_std = noise_std;

    % Model projection setup
    rotate_data = cell(length(rotate_data_file_all),1);
    flag_trial = 0;
    flag_count = 0;

In [10]:
length(rotate_data_file_all)


ans =

   300


In [20]:
iB=91


iB =

    91


In [56]:
[rotate_data_file_all(87:98).name]


ans =

rotate_all_click_2010308_36134_03_c08_rotated.matrotate_all_click_2010308_36134_03_c09_rotated.matrotate_all_click_2010308_36134_03_c10_rotated.matrotate_all_click_2010308_36134_03_c11_rotated.matrotate_all_click_2010308_36134_03_c12_rotated.matrotate_all_click_2010308_36134_03_c13_rotated.matrotate_all_click_2010308_36134_03_c14_rotated.matrotate_all_click_2010308_36134_03_c15_rotated.matrotate_all_click_2010308_36134_03_c16_rotated.matrotate_all_click_2010308_36134_03_c18_rotated.matrotate_all_click_2010308_36134_03_c19_rotated.matrotate_all_click_2010308_36134_03_c20_rotated.mat


In [24]:
ss = strsplit(bat_proc_file,'_');
save_fname = strjoin([script_name,ss(5:7)],'_');

if ~flag_trial
    t_name = strjoin(ss(5:6),'_');
    trial_file_all = dir(fullfile(data_base_path,...
                                  results_path,rotate_data_path,['*_',t_name,'_*.mat']));
    flag_trial = 1;
end

if flag_count<length(trial_file_all)
    flag_count = flag_count+1;
end

if plot_opt_all_click && flag_count==1
    numrow = ceil(length(trial_file_all)/4);
    fig_clicks = figure;
    set(fig_clicks,'Position',[100 100 1400 240*numrow]);
end

fprintf('File: %s\n',bat_proc_file);

% Get az/el from measurement
data = load(fullfile(data_base_path,results_path,rotate_data_path,bat_proc_file));


File: rotate_all_click_2010308_36134_03_c12_rotated.mat

In [29]:
% Beam center from measurements
% --- max beam energy point
xx = data.raw.vq_norm(:);
[~,mm_idx] = max(xx);
max_elq_loc = data.raw.elq(mm_idx);  % [deg]
max_azq_loc = data.raw.azq(mm_idx);
% --- averaged location of point >-1 dB normalized beam energy
xx(isnan(xx)) = -inf;
[~,sort_idx] = sort(xx,'descend');
ii = xx(sort_idx)>-1;
top_elq_loc = mean(data.raw.elq(sort_idx(ii)));  % [deg]
top_azq_loc = mean(data.raw.azq(sort_idx(ii)));
% --- fit ellipse
if E_max.x0<xy_lim(1) || E_max.x0>xy_lim(2) ||...
   E_max.y0<xy_lim(3) || E_max.y0>xy_lim(4)
else
   
end
[data.rot_max.E.x0,data.rot_max.E.y0]
%[el_ectr,az_ectr] = minvtran(mstruct,data.rot_max.E.x0,...
%                             data.rot_max.E.y0);  % inverse map projection
%[el_ectr_r,az_ectr_r] = rotatem(el_ectr,az_ectr,...  % [deg]
%                                [max_elq_loc,max_azq_loc],...
%                                'inverse','degrees');


ans =

    0.3945   -1.6071


In [33]:
[xxx,yyy] = mfwdtran(mstruct,[0,0,-90,90],[-180,180,0,0]);
xy_lim = [xxx(1:2), yyy(3:4)]


xy_lim =

   -2.6530    2.6530   -1.3265    1.3265


In [39]:
contourf(data.raw.azq,data.raw.elq,data.raw.vq_norm)
hold on
plot(max_azq_loc,max_elq_loc,'rx')
plot(top_azq_loc,top_elq_loc,'r^')



In [40]:
contourf(data.rot_max.azq,data.rot_max.elq,data.raw.vq_norm)



In [42]:
contourf(data.rot_max.xq,data.rot_max.yq,data.raw.vq_norm)
hold on
plot(data.rot_max.E.x0,data.rot_max.E.y0,'rx')



In [45]:
isempty(data.rot_elpctr)


ans =

  logical

   1


In [ ]:
% Model bp
if data.raw_meas.click_side==1  % right click --> no need to flip az
    azq_model = BP.azq;
    az_model = BP.az;
    max_azq_loc_model = BP.max_azq_loc;
    top_azq_loc_model = BP.top_azq_loc;
    az_ectr_r_model = BP.az_ectr_r;
else   % left click
    azq_model = -BP.azq;
    az_model = -BP.az;
    max_azq_loc_model = -BP.max_azq_loc;
    top_azq_loc_model = -BP.top_azq_loc;
    az_ectr_r_model = -BP.az_ectr_r;
end
elq_model = BP.elq;
el_model = BP.el;
max_elq_loc_model = max_elq_loc;
top_elq_loc_model = top_elq_loc;
el_ectr_r_model = el_ectr_r;

switch bpctr_opt
  case 'max'
    el_diff = max_elq_loc-max_elq_loc_model;
    az_diff = max_azq_loc-max_azq_loc_model;
  case 'top'
    el_diff = top_elq_loc-top_elq_loc_model;
    az_diff = top_azq_loc-top_azq_loc_model;
  case 'ectr'
    el_diff = el_ectr_r-el_ectr_r_model;
    az_diff = az_ectr_r-az_ectr_r_model;
end

S.data.max_elq_loc = max_elq_loc;
S.data.max_azq_loc = max_azq_loc;
S.data.top_elq_loc = top_elq_loc;
S.data.top_azq_loc = top_azq_loc;
S.data.el_ectr_r = el_ectr_r;
S.data.az_ectr_r = az_ectr_r;
S.data.el_diff = el_diff;
S.data.az_diff = az_diff;

% Rotate model bp according to max az/el
[elq_model_rot,azq_model_rot] = rotatem(elq_model,azq_model,...
                                        [el_diff,az_diff],'inverse','degrees');
[el_model_rot,az_model_rot] = rotatem(el_model,az_model,...
                                      [el_diff,az_diff],'inverse','degrees');

% Project model bp to mic loc
idxnotnan = ~isnan(BP.pp_plot);
vq_mic = rbfinterp([data.raw.az(:)';data.raw.el(:)'],...
                   rbfcreate([az_model_rot(idxnotnan)';el_model_rot(idxnotnan)'],...
                             BP.pp_plot(idxnotnan)',...
                             'RBFFunction','multiquadrics'));

% Add noise
vq_mic = vq_mic+randn(size(vq_mic))*noise_std+noise_mean;

% Fit ellipse
[click_side,raw,rot_max,rot_elpctr,rot_elpctr_tilt] = ...
    shift_rotate_bp(data.raw.az/180*pi,data.raw.el/180*pi,...
                    vq_mic,'eckert4',it_shift_th);

% if the best-fitting ellipse for shift_max is outside of globe
% then don't plot
if isempty(rot_elpctr) || isempty(rot_elpctr_tilt)
    flag_elps_fail = 1;
else
    flag_elps_fail = 0;
end

In [ ]:


In [ ]:
% Model bp
if data.raw_meas.click_side==1  % right click --> no need to flip az
    azq_model = BP.azq;
    az_model = BP.az;
    max_azq_loc_model = BP.max_azq_loc;
    top_azq_loc_model = BP.top_azq_loc;
    az_ectr_r_model = BP.az_ectr_r;
else   % left click
    azq_model = -BP.azq;
    az_model = -BP.az;
    max_azq_loc_model = -BP.max_azq_loc;
    top_azq_loc_model = -BP.top_azq_loc;
    az_ectr_r_model = -BP.az_ectr_r;
end
elq_model = BP.elq;
el_model = BP.el;
max_elq_loc_model = max_elq_loc;
top_elq_loc_model = top_elq_loc;
el_ectr_r_model = el_ectr_r;

switch bpctr_opt
  case 'max'
    el_diff = max_elq_loc-max_elq_loc_model;
    az_diff = max_azq_loc-max_azq_loc_model;
  case 'top'
    el_diff = top_elq_loc-top_elq_loc_model;
    az_diff = top_azq_loc-top_azq_loc_model;
  case 'ectr'
    el_diff = el_ectr_r-el_ectr_r_model;
    az_diff = az_ectr_r-az_ectr_r_model;
end

S.data.max_elq_loc = max_elq_loc;
S.data.max_azq_loc = max_azq_loc;
S.data.top_elq_loc = top_elq_loc;
S.data.top_azq_loc = top_azq_loc;
S.data.el_ectr_r = el_ectr_r;
S.data.az_ectr_r = az_ectr_r;
S.data.el_diff = el_diff;
S.data.az_diff = az_diff;

% Rotate model bp according to max az/el
[elq_model_rot,azq_model_rot] = rotatem(elq_model,azq_model,...
                                        [el_diff,az_diff],'inverse','degrees');
[el_model_rot,az_model_rot] = rotatem(el_model,az_model,...
                                      [el_diff,az_diff],'inverse','degrees');

% Project model bp to mic loc
idxnotnan = ~isnan(BP.pp_plot);
vq_mic = rbfinterp([data.raw.az(:)';data.raw.el(:)'],...
                   rbfcreate([az_model_rot(idxnotnan)';el_model_rot(idxnotnan)'],...
                             BP.pp_plot(idxnotnan)',...
                             'RBFFunction','multiquadrics'));

% Add noise
vq_mic = vq_mic+randn(size(vq_mic))*noise_std+noise_mean;

% Fit ellipse
[click_side,raw,rot_max,rot_elpctr,rot_elpctr_tilt] = ...
    shift_rotate_bp(data.raw.az/180*pi,data.raw.el/180*pi,...
                    vq_mic,'eckert4',it_shift_th);

% if the best-fitting ellipse for shift_max is outside of globe
% then don't plot
if isempty(rot_elpctr) || isempty(rot_elpctr_tilt)
    flag_elps_fail = 1;
else
    flag_elps_fail = 0;
end

In [17]:
Vpass.raw = raw;
            Vpass.rot_max = rot_max;
            Vpass.rot_elpctr = rot_elpctr;
            Vpass.rot_elpctr_tilt = rot_elpctr_tilt;
            
            % Movement of [az,el] of each mic
            fig_azel = plot_indiv_click_azel_movement(Vpass);
            title(regexprep(save_fname,'_','\\_'));



In [18]:
fig_fit = plot_indiv_click_rotate(Vpass,cvec,mstruct);
            suptitle(regexprep(save_fname,'_','\\_'));



In [19]:
% Rotated model output
        S.model_rot.click_side = click_side;
        S.model_rot.raw = raw;
        S.model_rot.rot_max = rot_max;
        S.model_rot.rot_elpctr = rot_elpctr;
        S.model_rot.rot_elpctr_tilt = rot_elpctr_tilt;

In [ ]: