%% Analysis of data taken at Fermilab the 3/17/2011

clear, close all;

path   = '~/matlab_workspace/DataFermilab14july/';

data1 = reshape(csvread([path 'DATA00.S1'],5,0,[5,0,401*9+4,0]),9,[])'; %S12 of Ceramic with adjacent non terminated
data2 = reshape(csvread([path 'DATA01.S1'],5,0,[5,0,401*9+4,0]),9,[])'; %S12 of Ceramic with adjacent terminated
data3 = reshape(csvread([path 'DATA02.S1'],5,0,[5,0,401*9+4,0]),9,[])'; %S13 of Ceramic far end
data4 = reshape(csvread([path 'DATA03.S1'],5,0,[5,0,401*9+4,0]),9,[])'; %S14 of Ceramic near end
data5 = reshape(csvread([path 'DATA04.S1'],5,0,[5,0,401*9+4,0]),9,[])'; %TDR pulse Start Stop 20ns
data6 = reshape(csvread([path 'DATA05.S1'],5,0,[5,0,401*9+4,0]),9,[])'; %S12 of Glass with adjacent terminated
data7 = reshape(csvread([path 'DATA06.S1'],5,0,[5,0,401*9+4,0]),9,[])'; %S13 of Glass far end
data8 = reshape(csvread([path 'DATA07.S1'],5,0,[5,0,401*9+4,0]),9,[])'; %S14 of Glass near end


figure('Name','Ceramic plate','NumberTitle','off')
hold on
plot(data2(:,1),data2(:,4),'Color',[1,0,0]         ,'LineWidth',2);
%plot(data2(:,1),data2(:,2),'Color',[0.21,0.78,0.21],'LineWidth',2);
plot(data3(:,1),data3(:,4),'Color',[0,0.4,1]       ,'LineWidth',2);
%plot(data4(:,1),data4(:,4),'Color',[.44,0.21,0.78] ,'LineWidth',2);
hold off
grid on
axis([0,2e10,-50,10])
legend('S12','S13 (far end)')
xlabel('Frequency in Hz')
ylabel('Gain in dB')
title('S Parameters of Ceramic plate')
set(gca,'xscale','log');

figure('Name','Glass plate','NumberTitle','off')
hold on
plot(data6(:,1),data6(:,4),'Color',[1,0,0]         ,'LineWidth',2);
%plot(data6(:,1),data6(:,2),'Color',[0.21,0.78,0.21],'LineWidth',2);
plot(data7(:,1),data7(:,4),'Color',[0,0.4,1]       ,'LineWidth',2);
%plot(data8(:,1),data8(:,4),'Color',[.44,0.21,0.78] ,'LineWidth',2);
hold off
grid on
axis([0,2e10,-50,10])
legend('S12','S13 (far end)')
xlabel('Frequency in Hz')
ylabel('Gain in dB')
title('S Parameters of Glass plate')
set(gca,'xscale','log');

figure('Name','Ceramic plate pulse','NumberTitle','off')
hold on
plot(linspace(-1e-9,4e-9,401),data5(:,4),'Color',[1,0,0]         ,'LineWidth',2);
plot(linspace(-1e-9,4e-9,401),data5(:,2),'Color',[0.21,0.78,0.21],'LineWidth',2);
hold off
grid on
