Optimization of parameters in template matching
3 views (last 30 days)
Show older comments
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 Comment
Vinayak
on 18 Apr 2024
Hi Jarl, it might be more helpful if we have some data to reproduce on our end.
Answers (1)
See Also
Categories
Find more on Get Started with Optimization Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!