Optimization of parameters in template matching

조회 수: 3 (최근 30일)
Jarl Bredal
Jarl Bredal 2024년 4월 5일
답변: Catalytic 2024년 4월 19일
I have a signal that looks like this:, and a template like this: . I want to optimize the parameters of my template function so that it fits well with the peak in the original signal. Right now I am using a function "correlationfitting" to try finding the place where the template and signal is most similar, and fmincon in order to optimize the parameters. The first three parameters are parameters of the template function, p is an offset parameter, and minID is where the function correlationfitting finds the highest similarity.
It does not work however, and I would greatly appreciate any tips or help.
Apologies for long or unclear question, thanks in advance!
x0 = [alpha lambda mu p minID];
A = -eye(5);
b = [0 0 0 0 0];
y = fmincon(@(x)costfunc(sensornr, bolusnr, x),x0,A,b);
alpha_opt = y(1);
lambda_opt = y(2);
mu_opt = y(3);
p_opt = y(4);
t_opt = y(5);
function sim_value = similarity(vec1, vec2)
sim_value = sum(vec1.*vec2)/(norm(vec2)*(norm(vec1)));
end
function sim_values = correlationfitting(raw_data,template_data)
sim_values = zeros(length(raw_data),1);
for i=1:(length(raw_data)-length(template_data)+1)
raw_chunk = raw_data(i:i+length(template_data)-1);
sim_values(i) = similarity(raw_chunk,template_data);
end
end
function cost = costfunc(sensor_values, bolustime, x)
alpha = x(1);
lambda = x(2);
mu = x(3);
p = x(4);
t_min = x(5);
t = 1:1:61;
template = alpha.*exp(lambda)/mu.*(lambda.*mu./(2.*pi.*t)).^(1/2).*exp(-lambda./2.*(t./mu+mu./t));
raw_data = read_raw(sensor_values, bolustime);
raw_dataadjusted = raw_data -p;
simvals = correlationfitting(raw_dataadjusted, template');
cost = -simvals(round(t_min));
end
  댓글 수: 1
Vinayak
Vinayak 2024년 4월 18일
Hi Jarl, it might be more helpful if we have some data to reproduce on our end.

댓글을 달려면 로그인하십시오.

답변 (1개)

Catalytic
Catalytic 2024년 4월 19일
cost = interp1( -simvals, t_min,'cubic');

카테고리

Help CenterFile Exchange에서 Get Started with Optimization Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by