How to sum two data sets to get a best match of another data set?

3 visualizaciones (últimos 30 días)
I have three spectrum, which essentially shares the same wavelength (x-axis). I would like to add the first two spectrum (i.e. column y1 & y2) is such a way as describes below to match the 3rd spectrum:
Ideally: y3 = a*y1 + b*y2
But in reality, I would like to find coefficients a & b with minimised y3 - (a*y1 + b*y2)
All x-axis, y1, y2, and y3 are columns of 608X1
The problem I am facing is that I don't know how to optimise the coefficients a & b to achive what I want.
Thank you !

Respuesta aceptada

Mathieu NOE
Mathieu NOE el 3 de Mayo de 2021
hello
see demo below :
I added some noise on y3 to see the robustness of fminsearch
got the results :
a = 3.0379
b = 5.0149
which is pretty close to the input equation coefficients
y1 = rand(1,20);
y2 = 3*rand(1,20);
noise = 0.1*rand(1,20);
y3 = 3*y1+5*y2+noise;
% equation to minimize : y3-(a*y1+b*y2) %a = x(1), b=x(2)
% fminsearch optimization loop
fun = @(x)norm(y3-(x(1)*y1+x(2)*y2)); %a = x(1), b=x(2)
x0 = [0, 0];
X = fminsearch(fun,x0);
a = X(1)
b = X(2)
  3 comentarios
Mathieu NOE
Mathieu NOE el 4 de Mayo de 2021
hello
I believe there is a variant of fminsearch with bounds available on the FEX , but I just dsicover it , never usd it yet :

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Mathematics en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by