
% fn = 'C:\Users\radar\Documents\Travel\Antarctica_2011\antenna_ground_meas\kuband_antennas.s2p';
% fn = 'C:\Users\radar\Documents\Travel\Antarctica_2011\kuband_20111006_sparam\thru without antennas.s2p';
% fn = 'C:\Users\radar\Documents\Travel\Antarctica_2011\kuband_20111006_sparam\p3-1.s2p';
% fn = 'C:\Users\radar\Documents\Travel\Antarctica_2011\kuband_20111006_sparam\p3-2.s2p';
% fn = 'C:\Users\radar\Documents\Travel\Antarctica_2011\fmcw_sparams_20111007\snow_new_cables.s2p';
% fn = 'C:\Users\radar\Documents\Travel\Antarctica_2011\fmcw_sparams_20111007\kuband_new_cables.s2p';
% fn = 'C:\Users\radar\Documents\Travel\Antarctica_2011\fmcw_sparams_20111007\original_cables_on_kuband.s2p';
% fn = 'C:\Users\radar\Documents\Travel\Antarctica_2011\delay_line_meas\2011_10_05_Delay_A_B.s2p';
% fn = 'C:\Users\radar\Documents\Travel\Antarctica_2011\delay_line_meas\2011_10_05_Delay_B_C.s2p';
fn = 'C:\Users\radar\Documents\Travel\Antarctica_2011\snow_radar_delay_line_meas\delay_line_2.95su.s2p';
% fn = 'C:\Users\radar\Documents\Travel\Antarctica_2011\snow_radar_delay_line_meas\snow_cables.s2p';


[freq, data, freq_noise, data_noise, Zo] = SXPParse(fn);

% freq_range = [12e9 18e9];
% % freq_range = [2e9 8e9];
% good_idx = find(freq>=freq_range(1) & freq <= freq_range(end));
% freq = freq(good_idx);
% data = data(:,:,good_idx);

figure(1); clf;
plot(freq/1e9, lp(squeeze(data(1,1,:)),2));
xlabel('frequency (GHz)');
ylabel('S_1_1 (dB)');
grid on;

figure(2); clf;
plot(freq/1e9, lp(squeeze(data(2,2,:)),2));
xlabel('frequency (GHz)');
ylabel('S_2_2 (dB)');
grid on;

figure(5); clf;
plot(freq/1e6, lp(squeeze(data(2,1,:)),2));
xlabel('frequency (MHz)');
ylabel('S_2_1 (dB)');
grid on;
fig_pos = get(5,'Position');
set(5,'Position',[fig_pos(1:2) 827 362]);

window_func = @hanning;
window_func = @boxcar;
Mt = 10;
df = freq(2)-freq(1);
Nt = length(freq) * Mt;
BW = df*Nt;
dt = 1/BW;
time = dt*(0:Nt-1).';
physical_constants;
VF = 0.8;
range = time * c/2 * VF;

figure(3); clf;
plot(range*100/2.54/12, lp(ifft(squeeze(data(1,1,:))*Mt,length(freq)*Mt),2));
grid on;
hold on;
plot(range*100/2.54/12, lp(ifft(squeeze(data(2,2,:))*Mt,length(freq)*Mt),2),'r');
hold off;
xlabel('range (ft)');
ylabel('relative power (dB)');
legend('S_1_1','S_2_2');

figure(4); clf;
plot(time*1e6, lp(ifft(squeeze(data(2,1,:)) .* window_func(size(data,3)) * Mt,length(freq)*Mt),2));
%plot(range*100/2.54/12, lp(ifft(squeeze(data(2,1,:)) .* window_func(size(data,3)) * Mt,length(freq)*Mt),2));
% xlabel('range (ft)');
title(sprintf('%s window', func2str(window_func)));
xlabel('time (us)');
ylabel('S_2_1 (dB)');
grid on;
fig_pos = get(4,'Position');
set(4,'Position',[fig_pos(1:2) 827 362]);
