close all
clear all

TestName = '100 micron test on 7/24/17';

K = 17.633;  %Pulses per Liter
PsiPerVolt = .5;  %Nominal.

%No Filter

LegStr{1} = 'No Filter';
FlowRate{1} = [0 7.7 18.5 35 58 70 80 ];  %Hz
PressureDrop{1} = [-.017 0 .080 .275 .78 1.1 1.5]; %V

%100 micron filter
LegStr{2} = '100 Micron Filter';
FlowRate{2} = [0 3.5 10 20 34 44 59 70 78 78 70 63 53 42 32 19 5 0];  %Hz
PressureDrop{2} = [-.010 0  .040 .145 .410 .720 1.3 1.7 2.09 2.08 1.7 1.46 1.08 .66 .42 .16 0.05 -.013]; %V


%50 micron filter 
LegStr{3} = '50 Micron Filter';
FlowRate{3} = [0 6.8 15 25 36 56 64 72 65 58 44 29 14.5 0]  %Hz
PressureDrop{3} = [-.018 .067 .19 .43 .76 1.65 2.11 2.66 2.11 1.71 1.1 .55 .19 -.018]; %V

%20 micron filter 
LegStr{4} = '20 Micron Filter';
FlowRate{4} = [0 19.85]*K/60  %Hz  (Measured with Bucket and converted to Hz since paddlwheel was out of the flow.
PressureDrop{4} = [-.018 8.45 ]; %V


for i = 1:length(FlowRate)
   PressureDrop{i} = PressureDrop{i}-PressureDrop{i}(1)*ones(size(PressureDrop{i}));

FlowRate{i} = FlowRate{i}*60/K;  %LitersPerMin
PressureDrop{i} = PressureDrop{i}*PsiPerVolt;
        
p{i} = polyfit(FlowRate{i},PressureDrop{i},2);
end
 

figure

x = 0:300;
for i = 1:length(FlowRate)
y = polyval(p{i},x);   
plot(x,y);
hold all;
end
legend(LegStr);%,'Location','NorthWest');

for i = 1:length(FlowRate)
plot(FlowRate{i},PressureDrop{i},'kx');

end

ylim([0 5]);


xlabel('Flow Rate (LPM)');
ylabel('Pressure Drop (psi)');
grid on


% 
% 
% x = 0:300;
% y = polyval(p,x);
% 
% hold all
% plot(x,y);
% plot(x,1.2*p(1)*x.*x,'-k');
% 
% legend('Data','2nd Order Polynomial Fit to Data','Quadratic Fit to Data','Location','NorthWest');
% title(TestName);
% grid on;
% print('-dpdf','PressureDropTest2.pdf');