% Jon Newman 
% 2012 03 23
% 
% I measured the optical conversion functions for both blue and yellow
% light on the optoclamp rig

%% Blue LED
area = 6.2; % Area of spot at culture (during this measurement)

% The blue power density at the culture
pow = [0
    0
    0
    12.52
    23
    29.80
    36.43
    43.6
    50.73
    57.1
    62.2
    67.4
    73.2]/area;

% Current through LED
iLED = ([0 0 0:100:1000])'/1000; % amps
    
close all
figure

hold on
plot(iLED,pow,'k-o','LineWidth',1.5);
ylabel('Power Density @ cells (mW/mm^2)')
xlabel('I_{LED} (A)')
set(gca,'TickDir','out','TickLength',[0.01 0.025])
axis square

% Create conversion functions

iLED2pow.p_blu = polyfit(iLED,pow,2);
iLED2pow.info = 'Second order polynomail coefficients for the conversion from LED current (amps) to power density at the cutlture (mW/mm^2)'; 

itest = 0:0.01:1;

plot(itest,polyval(iLED2pow.p_blu,itest),'b-','LineWidth',1.5);
ymax = get(gca,'YTick');
ylim([0 ymax(end)])


%% Yellow LED
area = 6.2; % Area of spot at culture (during this measurement)

% The blue power density at the culture
pow = [0
    0
    0
    6.81
    15.15
    22.7
    29.3
    37.6
    44.2
    50.8
    55.7
    62.1
    66.0]/area;

% Current through LED
iLED = ([0 0 0:100:1000])'/1000; % amps
    
plot(iLED,pow,'k-o','LineWidth',1.5);
ylabel('Power Density @ cells (mW/mm^2)')
xlabel('I_{LED} (A)')
set(gca,'TickDir','out','TickLength',[0.01 0.025])
axis square

% Create conversion functions

iLED2pow.p_yel = polyfit(iLED,pow,2);
iLED2pow.info = 'Second order polynomail coefficients for the conversion from LED current (amps) to power density at the cutlture (mW/mm^2)'; 

itest = 0:0.01:1;

plot(itest,polyval(iLED2pow.p_yel,itest),'y-','LineWidth',1.5);
ymax = get(gca,'YTick');
ylim([0 ymax(end)])


legend('457 nm','590 nm','Location','NorthWest')
%% Save
% Figure
export_fig 2012_03_23_trans-stimulator_measurment-conversion -pdf -transparent

% Save the conversions as polynomial coeffs
save('iLED2pow','iLED2pow');

