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

clear, close all;

path   = '~/matlab_workspace/Data_Fermilab2/';

data1 = reshape(csvread([path 'DATA00.S1'],5,0,[5,0,401*9+4,0]),9,[])';
data2 = reshape(csvread([path 'DATA01.S1'],5,0,[5,0,401*9+4,0]),9,[])';
data3 = reshape(csvread([path 'DATA02.S1'],5,0,[5,0,401*9+4,0]),9,[])';
data4 = reshape(csvread([path 'DATA03.S1'],5,0,[5,0,401*9+4,0]),9,[])';
data5 = reshape(csvread([path 'DATA04.S1'],5,0,[5,0,401*9+4,0]),9,[])';
data6 = reshape(csvread([path 'DATA05.S1'],5,0,[5,0,401*9+4,0]),9,[])';

time=linspace(0,5e-9,401)';
%% Data1

figure('Name','Data1','NumberTitle','off')
subplot(2,1,1)
plot(data1(:,1),data1(:,2),'-x','Color',[1,0,0]         ,'LineWidth',2);
grid on
xlabel('Time (S)')
ylabel('Amplitude (V)')
title('TDR of tester board with the chip');
subplot(2,1,2)
plot(data1(:,1),data1(:,4),'-x','Color',[0.21,0.78,0.21],'LineWidth',2);
grid on
xlabel('Time (S)')
ylabel('Amplitude (V)')
title('TDR of sampling chip + 50ohms');
xlabel('Time (S)')
ylabel('Amplitude (V)')
title('TDR of tester board without chip');

%% Data2

figure('Name','Data2','NumberTitle','off')
subplot(2,1,1)
plot(data2(:,1),data2(:,2),'-x','Color',[1,0,0]         ,'LineWidth',2);
grid on
xlabel('Time (S)')
ylabel('Amplitude (V)')
title('TDR of tester board with the chip');
subplot(2,1,2)
plot(data2(:,1),data2(:,4),'-x','Color',[0.21,0.78,0.21],'LineWidth',2);
grid on
xlabel('Time (S)')
ylabel('Amplitude (V)')
title('TDR of sampling chip + 50ohms');
xlabel('Time (S)')
ylabel('Amplitude (V)')
title('TDR of tester board without chip');

%% Data3

figure('Name','Data3','NumberTitle','off')
subplot(2,1,1)
plot(data3(:,1),data3(:,2),'-x','Color',[1,0,0]         ,'LineWidth',2);
grid on
xlabel('Time (S)')
ylabel('Amplitude (V)')
title('TDR of tester board with the chip');
subplot(2,1,2)
plot(data3(:,1),data3(:,4),'-x','Color',[0.21,0.78,0.21],'LineWidth',2);
grid on
xlabel('Time (S)')
ylabel('Amplitude (V)')
title('TDR of sampling chip + 50ohms');
xlabel('Time (S)')
ylabel('Amplitude (V)')
title('TDR of tester board without chip');

%% Data4

figure('Name','Data4','NumberTitle','off')
subplot(2,1,1)
plot(data4(:,1),data4(:,2),'-x','Color',[1,0,0]         ,'LineWidth',2);
grid on
xlabel('Time (S)')
ylabel('Amplitude (V)')
title('TDR of tester board with the chip');
subplot(2,1,2)
plot(data4(:,1),data4(:,4),'-x','Color',[0.21,0.78,0.21],'LineWidth',2);
grid on
xlabel('Time (S)')
ylabel('Amplitude (V)')
title('TDR of sampling chip + 50ohms');
xlabel('Time (S)')
ylabel('Amplitude (V)')
title('TDR of tester board without chip');

%% Data5

figure('Name','Data5','NumberTitle','off')
subplot(2,1,1)
plot(data5(:,1),data5(:,2),'-x','Color',[1,0,0]         ,'LineWidth',2);
grid on
xlabel('Time (S)')
ylabel('Amplitude (V)')
title('TDR of tester board with the chip');
subplot(2,1,2)
plot(data5(:,1),data5(:,4),'-x','Color',[0.21,0.78,0.21],'LineWidth',2);
grid on
xlabel('Time (S)')
ylabel('Amplitude (V)')
title('TDR of sampling chip + 50ohms');
xlabel('Time (S)')
ylabel('Amplitude (V)')
title('TDR of tester board without chip');

%% Data6

figure('Name','Data6','NumberTitle','off')
subplot(2,1,1)
plot(data6(:,1),data6(:,2),'-x','Color',[1,0,0]         ,'LineWidth',2);
grid on
xlabel('Time (S)')
ylabel('Amplitude (V)')
title('TDR of tester board with the chip');
subplot(2,1,2)
plot(data6(:,1),data6(:,4),'-x','Color',[0.21,0.78,0.21],'LineWidth',2);
grid on
xlabel('Time (S)')
ylabel('Amplitude (V)')
title('TDR of sampling chip + 50ohms');
xlabel('Time (S)')
ylabel('Amplitude (V)')
title('TDR of tester board without chip');
