MLLS stands for multiple linear least squares fitting, which is the common strategy for the solving EELS edge overlapping and which is also built-in the GMS software.
The target spectrum Y and the reference spectrum X
Y = A * X
Assuming Y is 1*256 matrix and we have three reference spectrums, ie, X is 3*256 matrix. So A is 1*3 matrix.
The target is to solve A.
If Y and X are n*n matrices, we can use the simple formula Y * inv(X) = A * X * inv(X), ie., A = Y * inv(X). However, Y and X are not n*n matrices, it is necessary to have some trick to solve it. We can multiply the transpose matrix to produce n*n matrix.
Y * X' = A * X * X' (ps X' means the transpose matrix of X)
so
A = Y * X' * inv(X * X')
Here is the Matlab code:
=========
% create target spectrum
x=0:256;
c=[90,120,155];
sig=[5,10,8];
int=[5,10,8];
xn=zeros(size(x));
ref=zeros(length(c),length(x));
factor=rand(size(c))';
for i=1:length(c)
xn=xn+int(i)*exp(-1*(x-c(i)).^2/(2*sig(i))^2);
ref(i,:)=int(i)*exp(-1*(x-c(i)).^2/(2*sig(i))^2)*factor(i);
end
xn=xn+0.5*rand(size(xn))-0.3;
figure(1);
subplot(4,1,1);plot(xn)
axis([0,length(x),0,max(xn)+1]);
title('Experimental Data');
subplot(4,1,2);plot(ref(1,:))
axis([0,length(x),0,max(xn)+1]);
title(['Ref-1, foctor= ',num2str(factor(1))]);
subplot(4,1,3);plot(ref(2,:))
axis([0,length(x),0,max(xn)+1]);
title(['Ref-2, foctor= ',num2str(factor(2))]);
subplot(4,1,4);plot(ref(3,:))
axis([0,length(x),0,max(xn)+1]);
title(['Ref-3, foctor= ',num2str(factor(3))]);
% Do MLLS
sol= xn*ref'*inv(ref*ref');
fit_sp=zeros(size(xn));
for i=1:length(sol)
fit_sp=fit_sp+sol(i)*ref(i,:);
end
r=sqrt(mean((fit_sp-xn).^2));
figure(2)
plot(xn);
hold on;
plot(fit_sp);
hold off;
legend('Experimental Data','MLLS fitting');
axis([0,length(x),0,max(xn)+1]);
title(['Fitted sp, Residual=',num2str(r)]);
The target spectrum Y and the reference spectrum X
Y = A * X
Assuming Y is 1*256 matrix and we have three reference spectrums, ie, X is 3*256 matrix. So A is 1*3 matrix.
The target is to solve A.
If Y and X are n*n matrices, we can use the simple formula Y * inv(X) = A * X * inv(X), ie., A = Y * inv(X). However, Y and X are not n*n matrices, it is necessary to have some trick to solve it. We can multiply the transpose matrix to produce n*n matrix.
Y * X' = A * X * X' (ps X' means the transpose matrix of X)
so
A = Y * X' * inv(X * X')
Here is the Matlab code:
=========
% create target spectrum
x=0:256;
c=[90,120,155];
sig=[5,10,8];
int=[5,10,8];
xn=zeros(size(x));
ref=zeros(length(c),length(x));
factor=rand(size(c))';
for i=1:length(c)
xn=xn+int(i)*exp(-1*(x-c(i)).^2/(2*sig(i))^2);
ref(i,:)=int(i)*exp(-1*(x-c(i)).^2/(2*sig(i))^2)*factor(i);
end
xn=xn+0.5*rand(size(xn))-0.3;
figure(1);
subplot(4,1,1);plot(xn)
axis([0,length(x),0,max(xn)+1]);
title('Experimental Data');
subplot(4,1,2);plot(ref(1,:))
axis([0,length(x),0,max(xn)+1]);
title(['Ref-1, foctor= ',num2str(factor(1))]);
subplot(4,1,3);plot(ref(2,:))
axis([0,length(x),0,max(xn)+1]);
title(['Ref-2, foctor= ',num2str(factor(2))]);
subplot(4,1,4);plot(ref(3,:))
axis([0,length(x),0,max(xn)+1]);
title(['Ref-3, foctor= ',num2str(factor(3))]);
% Do MLLS
sol= xn*ref'*inv(ref*ref');
fit_sp=zeros(size(xn));
for i=1:length(sol)
fit_sp=fit_sp+sol(i)*ref(i,:);
end
r=sqrt(mean((fit_sp-xn).^2));
figure(2)
plot(xn);
hold on;
plot(fit_sp);
hold off;
legend('Experimental Data','MLLS fitting');
axis([0,length(x),0,max(xn)+1]);
title(['Fitted sp, Residual=',num2str(r)]);
======
Ref
Comments
Post a Comment