

files = dir('*.TXT');

for n = 1:length(files)
data{n} = dlmread(files(n).name);
end

Angles = [104 130 151];
DIW = data{4}(:,3:5);
Blanks(1,:) = median(DIW);
AZ = data{1}(:,3:5);
D(1,:) = median(AZ);
Cheat = [data{2}(:,3:5);data{3}(:,3:5)];
D(2,:) = median(Cheat);
DRE_filt = data{5}(:,3:5);
DRE_filt([46 45],:) = [];
Blanks(2,:) = median(DRE_filt);
DRE = data{6}(:,3:5);
D(3,:) = median(DRE);
Plat = data{7}(:,3:5);
Plat([1 37],:) = [];
D(4,:) = median(Plat);

Corr = D-repmat(Blanks(2,:),4,1);

sf = [0.0000499315
0.0000513194
0.0000291279]';
final = Corr.*repmat(sf,4,1);
final_p = final.*repmat((2.*pi.*sin(deg2rad([104 130 151]))),4,1);

for n = 1:4
p = polyfit(deg2rad(Angles),final_p(n,:),3);
x = deg2rad(90:180);
y(n,:) = p(1)*x.^3+p(2)*x.^2+p(3)*x+p(4);
int = trapz(x,y(n,:));
bbp(n) = int*1.013;
end