SLP DATA 처리용 M파일

clear all;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%parameter%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% use mks unit

R=1000;
C_e=1.602*10^(-19);
m_e=9.107*10^(-31);               %% cgs -> 9.107*10^(-28)
k = 1.380622*10^(-23);             %% J/K
M_i=6.6423*10^(-26);                %Ar의 질량
%M_i=6.6423*10^(-27);               %He의 질량
R_probe=0.00015;                    %% 150um
L_probe=0.008;                      %% 8mm
A_probe=2*pi*R_probe*L_probe;
alpha_0=0.61; %% cylindrical tip - comp coeff
%alpha_0=0.5; %% planar tip
epsilon_0 = 8.854*10^(-12);       %% F/m
mu_argon = 40;

quant_step = 1000;



linearfit_offset = 10;
linearfit_sample = 50;
%% 이온 전류를 피팅할 때 V_f 로부터 몇번째 뒤의 지점까지 삭제할 것인지 결정한다.
I_fit_offset = 70;

%% 몇번째 미분 0 지점을 V_p로 선택할지 결정한다.
V_p_candidate = 1;

%% 계산시 생성되는 모든 그림과 데이타를 얻고 싶으면 1로 한다.
%% 데이타 필요 없이, 단순히 빠른 계산을 원하면 0으로 한다.
print_all       = 1;
 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%data읽어들이기%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
folder='F:/meeting/20110916_slp/1mTorr/pt1/1000W/0W/';
i1a = strcat(folder,'0.csv');
i1b = strcat(folder,'1.csv');

I_1a=dlmread(i1a,',',5,0);
I_1b=dlmread(i1b,',',5,0);

V_raw1=I_1a(:,2);
V_raw2=I_1b(:,2);

clear I_1a;
clear I_1b;

V__raw = smooth(V_raw1);
V_raw2 = smooth(V_raw2);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%  raw I-V 커브 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

I__raw=(V__raw - V_raw2)/R;

%plot(V__raw,I__raw);

clear V_raw1;
clear V_raw2;

maxval = max(V__raw) - 5;
minval = min(V__raw) + 5;

V__quant = linspace(minval,maxval,quant_step);
I__val = zeros(quant_step,1);
I__quant_count = zeros(quant_step,1);

for(i = 1:1:length(V__raw)-1)
    for(j = 1:1:quant_step)
        if(V__raw(i) < (minval-quant_step) || V__raw(i) > (maxval)) continue;
        end
        
        if(V__raw(i) <= V__quant(j))
            I__val(j) = I__val(j) + I__raw(i);
            I__quant_count(j) = I__quant_count(j) + 1;
            break;
        end
    end
end

clear I__raw;
clear V__raw;

for(i = 1:1:quant_step)
    I__val(i) = I__val(i) / I__quant_count(i);
end

clear I__quant_count;


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 그래프를 1차, 2차 미분하고 smooth 한다.

smooth_temp = smooth(V__quant,I__val,50,'sgolay');
I__val_smooth = smooth(V__quant,smooth_temp,'lowess');

if(print_all == 1)
    outfile = strcat(folder,'iv.csv');
    fout = fopen(outfile,'w');
    for(j = 1:1:length(V__quant))
    fprintf(fout,'%f,%f\r\n',V__quant(j),I__val_smooth(j));
    end
    fclose(fout);
end
clear smooth_temp;

I_1st_diff = diff(I__val_smooth);
smooth_temp = smooth(V__quant(1:(end-1)),I_1st_diff,50,'sgolay');
I_1st_diff_smooth = smooth(V__quant(1:(end-1)),smooth_temp,'lowess');

if(print_all == 1)
    outfile = strcat(folder,'1st_diff_iv.csv');
    fout = fopen(outfile,'w');
    for(j = 1:1:length(V__quant)-1)
    fprintf(fout,'%f,%f\r\n',V__quant(j),I_1st_diff_smooth(j));
    end
    fclose(fout);
end
clear smooth_temp;

I_2nd_diff = diff(I_1st_diff_smooth);

smooth_temp = smooth(V__quant(1:(end-2)),I_2nd_diff,50,'sgolay');
I_2nd_diff_smooth = smooth(V__quant(1:(end-2)),smooth_temp,'lowess');

if(print_all == 1)
    outfile = strcat(folder,'2nd_diff_iv.csv');
    fout = fopen(outfile,'w');
    for(j = 1:1:length(V__quant)-2)
    fprintf(fout,'%f,%f\r\n',V__quant(j),I_2nd_diff_smooth(j));
    end
    fclose(fout);
end
clear smooth_temp;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

plot(V__quant,I__val,V__quant,I__val_smooth);
title('SLP I- V curves');
xlabel('voltage(V)');
ylabel('current(I)');
outfile = strcat(folder,'IV_curve.tiff');
print('-dtiff',outfile);

clear I__val;

if(print_all == 1)
    plot(V__quant(1:(end-1)),I_1st_diff,V__quant(1:(end-1)),I_1st_diff_smooth);
    title('SLP 1st diff of I- V curves');
    xlabel('voltage(V)');
    ylabel('dI/dV');
    outfile = strcat(folder,'I_1st_diff.tiff');
    print('-dtiff',outfile);
end

clear I_1st_diff;

if(print_all == 1)
    plot(V__quant(1:(end-2)),I_2nd_diff,V__quant(1:(end-2)),I_2nd_diff_smooth);
    title('SLP 2nd diff of I- V curves');
    xlabel('voltage(V)');
    ylabel('d2I/dV2');
    outfile = strcat(folder,'I_2nd_diff.tiff');
    print('-dtiff',outfile);
end

clear I_2nd_diff;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% V_f 를 구한다. (I=0 이 되는 V 값)
%% V_f 는 fast primanry 전자가 있거나 rf 보정이 안될수록 작게 나타난다.

for(j = 1:1:length(V__quant)-1)
    if(I__val_smooth(j) <= 0 && (I__val_smooth(j+1) > 0)) 
        V_f = V__quant(j);
        V_f_num = j;
        break;
    end
end

if(j == length(V__quant)-1)
    fprintf('Error -- There is no V_f..\n');
else
    fprintf('V_f is %f\r\n',V_f);
end


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% V_p의 candidate들을 를 구한다 (플라즈마 포텐셜)
%% V_p 는 반드시 V_f 보다 커야한다!!
%% 이 값을 이용하여 T_ev 값을 구한다
fprintf('V_p (approximated) candidate:\n');
k = 0;
for(j = V_f_num:1:length(V__quant) - 3)
    if(I_2nd_diff_smooth(j) <= 0 && I_2nd_diff_smooth(j+1) > 0)
        k = k+1;
        if(k == V_p_candidate) %% 대부분의 Vp는 첫번째 미분 0 점에서 나타난다.!!
            V_p = V__quant(j); 
            V_p_num = j;
        end
        fprintf('%dth candidate : Vp( %f ), Tev(~ %f )\n',k,V__quant(j),(V__quant(j) - V_f) / log(2 * M_i / pi / m_e)/ alpha_0);
    end
end
fprintf('Selected V_p : %f\r\n',V_p);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 대략적인 Tev를 구한다. Ie 커브만을 이용해야 하나 지금 단계에서는 Iion 도 같이 들어있다.(대략적)
%% Tev를 구하기 위해서 적당히 잘라낸다. 시작점은 Vf 이다.

ln_I__e = log(I__val_smooth);

for(j = 1:1:linearfit_sample+linearfit_offset)
    V_e(j) = V__quant(j + V_f_num);
    ln_I_e(j) = ln_I__e(j + V_f_num);
end

pp = polyfit(V_e(linearfit_offset :end),ln_I_e(linearfit_offset:end),1);
Tev_fit = polyval(pp,V_e);

plot(V__quant,ln_I__e,V_e,Tev_fit);

title('Electron saturation current');
xlabel('Voltage');
ylabel('Current(ln)');
outfile = strcat(folder,'Tev_fiting.tiff');
print('-dtiff',outfile);
Tev_1 = 1/pp(1);
fprintf('Approximated Tev is ~%f\r\n',Tev_1);

clear V_e;
clear Tev_fit;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 밀도를 대략적으로 측정한다
%% I_B = alpha * n * e * A * sqrt(k * Te / M)
%% 플라즈마 포텐셜에서의 이온 전류는 0 으로 근사하여, Ie(Vp) ~ I(Vp) 로 가정하자
%% alpha ~ 0.5      planar tip
%% alpha ~ 0.61     cylindrical tip

density_1 = I__val_smooth(V_p_num) / C_e / A_probe / sqrt(Tev_1 * C_e / 2 / pi / m_e);

fprintf('Density from I(Vp) ~ Ie(Vp) : %e (cm-3)\r\n',density_1/1000000);       %% c=> m-3

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 디바이 거리 등 여러 플라즈마 변수를 측정한다.

debye_len = sqrt(epsilon_0 * Tev_1 / density_1 / C_e);
Xi = R_probe / debye_len;
eta_f = -(V_f - V_p) / Tev_1;
sheath_len = 1/3*sqrt(2 / alpha_0) * (2 * eta_f) ^ (3/4) * debye_len;
Cs = sqrt(Tev_1 * C_e / M_i);                                           %% bohm velocity

fprintf('Debye length is ~%f (m)\r\n',debye_len);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 밀도를 정확하게 측정한다
%% Orbit Motion Limit(OML) theory 를 이용한다.
%% sheath 가 probe 보다 훨씬 커야 한다. (밀도가 낮아야 한다)

I_val_square = I__val_smooth(1:V_f_num).^2;

coef_pf1 = polyfit(V__quant(1:V_f_num-I_fit_offset),transpose(I_val_square(1:V_f_num-I_fit_offset)),1);
pf1 = polyval(coef_pf1,V__quant(1:V_f_num));

plot(V__quant(1:V_f_num),I_val_square,V__quant(1:V_f_num),pf1);
title('Extrapolation of I^2 curve');
xlabel('Voltage');
ylabel('I^2');
outfile = strcat(folder,'Ion_fiting_2.tiff');
print('-dtiff',outfile);

I_ion_f = sqrt(pf1(V_f_num));
density_2 = I_ion_f / A_probe / C_e / sqrt( 2* abs(C_e * V_f) / M_i) * pi;

fprintf('Density from OML method : %e (cm-3) \n',density_2/1000000);


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% 밀도를 정확하게 측정한다
%% Moderate density rf plasmas 방법을 이용한다.
%% ICP 플라즈마의 경우에 맞는다 밀도가 10^10 ~ 10^12 사이일 때에..
I_val_43 = I__val_smooth(1:V_f_num).^4;
I_val_43 =  I_val_43.^(1/3);

coef_pf2 = polyfit(V__quant(1:V_f_num-I_fit_offset),transpose(I_val_43(1:V_f_num-I_fit_offset)),1);
pf2 = polyval(coef_pf2,V__quant(1:V_f_num));

plot(V__quant(1:V_f_num),I_val_43,V__quant(1:V_f_num),pf2);
title('Extrapolation of I^(4/3) curve');
xlabel('Voltage');
ylabel('I^(4/3)');
outfile = strcat(folder,'Ion_fiting_43.tiff');
print('-dtiff',outfile);

I_ion_f = pf2(V_f_num) ^ (3/4);
density_3 =  I_ion_f / 2 / pi / (R_probe + sheath_len) / C_e / L_probe / alpha_0 / Cs;

fprintf('Density from FP method(work well at ICP plasma) : %e (cm-3) \n',density_3/1000000);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% EEDF 를 구한다.
for(j = 1:1:200);
    V_EEDF(j) = V_p - V__quant(V_p_num - j);
    EEDF(j) = -I_2nd_diff_smooth(V_p_num - j);
end

norm(EEDF);

plot(V_EEDF,EEDF);
title('EEDF');
xlabel('eV');
ylabel('EEDF');
outfile = strcat(folder,'eedf.tiff');
print('-dtiff',outfile);


%% END OF PROGRAM