% I/V-curve for a Langmuir probe
% Initial version: Magnus Billvik, Swedish Institute of Space Physics,
%Uppsala, June 2005

% Physical quantities and constants
Ap=4*pi*0.025^2;
Ap_proj=pi*0.025^2;
Ap_proj=Ap_proj/2;

ne=2.5e6;       % [electrons/m3]
ni=7e6;         % [protons/m3]
Te=15e4;        % [K]
Ti=10e4;        % [K]
me=9.109e-31;   % [kg]
mi=1.673e-27;   % [kg]
qe=-1.602e-19;  % [C]
qi=1.602e-19;   % [C]
kB=1.381e-23;   % [J/K]
Vp=-50:0.1:25;  % [V]

index_neg=find(Vp<0);
index_pos=find(Vp>=0);

% random current
Ie0=-Ap*ne*qe*sqrt(kB*Te/(2*pi*me));
Ii0=-Ap*ni*qi*sqrt(kB*Ti/(2*pi*mi));

% probe currents
Ie_pos=Ie0.*(1-qe*Vp./(kB*Te));
Ii_pos=Ii0.*exp(-qi*Vp./(kB*Ti));
Ie_neg=Ie0.*exp(-qe*Vp./(kB*Te));
Ii_neg=Ii0*(1-qi*Vp./(kB*Ti));

% photo current
Iph(index_neg)=-ones(1,length(index_neg))*Ap_proj*80e-6;
Iph(index_pos)=-Ap_proj*(80.*exp(-Vp(index_pos)/2)+3.*exp(-Vp(index_pos)/7.5))*1e-6;


% calculate the I/V-curve
Ie(index_neg)=Ie_neg(index_neg);
Ie(index_pos)=Ie_pos(index_pos);
Ii(index_neg)=Ii_neg(index_neg);
Ii(index_pos)=Ii_pos(index_pos);

figure(5)
%set(gca,'YDir','reverse');
plot(Vp,Ie*1e9,'r--', Vp,Ii*1e9,'b-.');
hold on;
plot(Vp,(Ie+Ii)*1e9,'k', 'LineWidth' ,2);

grid;
xlabel('Vp [V]');
ylabel('I [nA]');
title('I/V sweep curve for a LAP without photo current');
legend('electron current', 'proton current', 'probe current');
%set(gca,'YDir','reverse');


figure(6)
%set(gca,'YDir','reverse');
plot(Vp,Ie*1e9,'r--', Vp,Ii*1e9,'b-.', Vp,Iph*1e9,'y-');
hold on;
plot(Vp,(Ie+Ii+Iph)*1e9,'k', 'LineWidth' ,2);
grid on;
xlabel('Vp [V]');
ylabel('I [nA]');
title('I/V sweep curve for a sunlit LAP with a photo current');
legend('electron current', 'proton current', 'photo current', 'probe current');
%set(gca,'YDir','reverse');
