2/10/2017

Fit T2 distribution with 2 gaussian distributions

Today, I successfully fitted T2 distribution with 2 gaussian distributions.

Summary:

%% fit T2 with gaussian distribution
% b(1) is scale, b(2) is sigma, b(3) is miu.
modelfun1=@(b,x)(b(1)*(1/(b(2)*sqrt(2 * pi))) * exp(-(x - b(3)).^2 ./ (2 * b(2)^2)));
x1=(1:40);
y1=T2row1(:,(1:40));
x2=(40:64);
y2=T2row1(:,(40:64));
beta10=[0.01;1;10];
beta20=[0.01;1;50];
beta1=nlinfit(x1,y1,modelfun1,beta10);
beta2=nlinfit(x2,y2,modelfun1,beta20);
[beta1,R1,J1,CovB1,MSE1,ErrorModelInfo1]=nlinfit(x1,y1,modelfun1,beta10);
[beta2,R2,J2,CovB2,MSE2,ErrorModelInfo2]=nlinfit(x2,y2,modelfun1,beta20);
fun1=beta1(1,:)*(1/(beta1(2,:)*sqrt(2 * pi))) * exp(-(x1 - beta1(3,:)).^2 ./ (2 * beta1(2,:)^2));
fun2=beta2(1,:)*(1/(beta2(2,:)*sqrt(2 * pi))) * exp(-(x2 - beta2(3,:)).^2 ./ (2 * beta2(2,:)^2));

%% plot
hold off;
plot(T2row1)
hold on;
plot(x1,fun1, 'r-');
plot(x2,fun2, 'r-');
title('T2 distribution fitting');
rsq1=1-sum(R1.^2)/sum((y1-mean(y1)).^2)
rsq2=1-sum(R2.^2)/sum((y2-mean(y2)).^2)


Result:

beta1 =

    0.0426
    6.5562
   19.3092

beta2 =

    0.0042
    2.6393
   49.9026

The first is the scale to adjust gaussian distribution, the second is standard deviation, the third is mean value. I calculated that the r square for the first gaussian distribution is 0.9695 and  the r square for the second gaussian distribution is 0.9907. Both of them are good enough for fitting.

Next week, I will try to apply the method to all the depth of T2 distribution.

4 comments:

  1. looks good... now try your best to get accurate and high quality results for the match...

    once you have the six Gaussian parameters for each depth... you can develop their predictions...

    ReplyDelete
    Replies
    1. Ok, the problem now is how to apply them to all depth because every depth is different.

      Delete
  2. you need to record error in the match for each peak... this should also be used to improve your prediction...

    ReplyDelete