Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am trying gaussian fitting using matlab. I have received a function to obtain

ID: 3348579 • Letter: I

Question

I am trying gaussian fitting using matlab.
I have received a function to obtain the parameters needed for gaussian fitting elsewhere. Through this, I succeeded in obtaining parameters p1, p2, p3, p4 in case 2.
Now we want to overlay the gaussian functions fitted with these parameters over the original signal. However, in this process, one of the parameters mu1 and mu2 is fixed to 1 and 999. How do I fix the code?

clear all; close all; clc;
%% data load
load('SPR0051_base_waves_allPEAKS.mat');
%%
cnt=51;

PPG=DATA.WAVE(:,2);
PT=DATA.LPEAK(:,1);
PTI=round(PT*300);
L=length(PTI);

x=PTI(cnt):PTI(cnt+1);
y=PPG(x);
x = x-PTI(cnt);

norm_y=((y-min(y)) / (max(y)-min(y)));
re_PPG=interpol3(x,norm_y,x(end));
n=[1:1:1000];

plot(re_PPG,'color',[0.1 0.1 0.1],'LineWidth',1);
title(['segment ',num2str(cnt)])
xlabel('Number of samples')
ylabel('Norm a.u.')
axis tight

p= segGaussFit(n, re_PPG, 2, 1)

dn=length(n);

for step = 1:(dn-1)
for initmu = 0:dn
mu1 = initmu+1;
mu2 = mu1 + step;

if (mu1 + step >= dn) || (mu2 >= dn)
break;
end
mu = [mu1 mu2];
end
end
gaumd1 = (p(1).* exp(-(((n-mu(1)).^2)/(2*p(2)^2))))+ ...
(p(3).* exp(-(((n-mu(2)).^2)/(2*p(4)^2))));  

hold on;
plot(gaumd1);

DATA 1x1 global struct 5? ?? ?? ?? ? WAVE 126600x2 double 406x2 double 406x2 double 406x2 double 126600x1 double ?QRS ?UPEAK LPEAK TIME

Explanation / Answer

clear all; close all; clc;
%% data load
load('SPR0051_base_waves_allPEAKS.mat');
%%
cnt=51;

PPG=DATA.WAVE(:,2);
PT=DATA.LPEAK(:,1);
PTI=round(PT*300);
L=length(PTI);

x=PTI(cnt):PTI(cnt+1);
y=PPG(x);
x = x-PTI(cnt);

norm_y=((y-min(y)) / (max(y)-min(y)));
re_PPG=interpol3(x,norm_y,x(end));
n=[1:1:1000];

plot(re_PPG,'color',[0.1 0.1 0.1],'LineWidth',1);
title(['segment ',num2str(cnt)])
xlabel('Number of samples')
ylabel('Norm a.u.')
axis tight

p= segGaussFit(n, re_PPG, 2, 1)

dn=length(n);

for step = 1:(dn-1)
for initmu = 0:dn
mu1 = initmu+1;
mu2 = mu1 + step;

if (mu1 + step >= dn) || (mu2 >= dn)
break;
end
mu = [mu1 mu2];
end
end
gaumd1 = (p(1).* exp(-(((n-mu(1)).^2)/(2*p(2)^2))))+ ...
(p(3).* exp(-(((n-mu(2)).^2)/(2*p(4)^2))));  

hold on;
plot(gaumd1);

clc [1] - clears the command window and nothing else. This command is like removing written things from a whiteboard using a duster.

After using clc, you cannot use the scroll bar to see the history of functions, but you still can use the up arrow key, ?, to recall statements from the command history.

clear all [2] clears variables, but it also clears a lot of other things from memory, such as breakpoints, persistent variables and cached memory.

We rarely need to use clear all - most of the time a simple clear will be enough.

close all [3] deletes all the figures whose handles are not hidden.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote