fns{1} = 'C:\Users\radar\Documents\Travel\Antarctica_2011\antenna_air_meas\2011_10_05_ANT_1234.s4p';
chans{1} = [1 2 3 4];
fns{2} = 'C:\Users\radar\Documents\Travel\Antarctica_2011\antenna_air_meas\2011_10_05_ANT_1235.s4p';
chans{2} = [1 2 3 5];
fns{3} = 'C:\Users\radar\Documents\Travel\Antarctica_2011\antenna_air_meas\2011_10_05_ANT_1245.s4p';
chans{3} = [1 2 4 5];

csv_fn = 'C:\Users\radar\Documents\Travel\Antarctica_2011\antenna_air_meas\paden_reformat_of_2009_data.csv';

data = {};
for fn_idx = 1:length(fns)
  [freq, data{fn_idx}] = SXPParse(fns{fn_idx});
end

% Plot return loss from each antenna
colors = {'k','r','g','b','m'};
figure(1);
fig_pos = get(1,'Position');
set(1,'Position',[fig_pos(1:2) 827 362]);
clf;
for chan = 1:5
  for fn_idx = 1:3
    meas_idx = find(chans{fn_idx} == chan);
    if ~isempty(meas_idx)
      break;
    end
  end
  plot(freq/1e6, lp(squeeze(data{fn_idx}(meas_idx,meas_idx,:))),colors{chan});
  hold on;
  legend_str{chan} = sprintf('S_%d_%d', chan, chan);
  xlabel('frequency (MHz)');
  ylabel('S_N_N (dB)');
  grid on;
end
hold off;
xlim([180 205]);
ylim([-25 0]);
legend(legend_str,'Location','SouthWest');

if 1
  C = csvread(csv_fn);
  hold on;
  for rx = 1:5
    plot(C(:,1),C(:,rx+1), [colors{rx} '.']);
  end
  hold off;
end
return;

% Plot mutual coupling for each antenna
for chan = 1:5
  figure(10+chan);
  fig_pos = get(10+chan,'Position');
  set(10+chan,'Position',[fig_pos(1:2) 827 362]);
  for couple_chan = 1:5
    for fn_idx = 1:3
      meas_idx = find(chans{fn_idx} == chan);
      cpl_idx = find(chans{fn_idx} == couple_chan);
      if ~isempty(meas_idx) & ~isempty(cpl_idx)
        break;
      end
    end
    plot(freq/1e6, lp(squeeze(data{fn_idx}(meas_idx,cpl_idx,:))),colors{couple_chan});
    hold on;
    legend_str{chan} = sprintf('S_%d_%d', chan, couple_chan);
    xlabel('frequency (MHz)');
    ylabel(sprintf('S_%d_N (dB)', chan));
    grid on;
  end
  hold off;
  xlim([180 205]);
  ylim([-50 -20]);
  legend(legend_str,'Location','NorthWest');
end


