Can anyone please help me to understand the below mentioned code?
Show older comments
function [pwav]=p_wav(x,a_pwav,d_pwav,t_pwav,li)
l=li;
a=a_pwav;
x=x+t_pwav;
b=(2*l)/d_pwav;
n=100;
p1=1/l;
p2=0;
for i = 1:n
harm1=(((sin((pi/(2*b))*(b-(2*i))))/(b-(2*i))+(sin((pi/(2*b))*(b+(2*i))))/(b+(2*i)))*(2/pi))*cos((i*pi*x)/l);
function [qwav]=q_wav(x,a_qwav,d_qwav,t_qwav,li)
l=li;
x=x+t_qwav;
a=a_qwav;
b=(2*l)/d_qwav;
n=100;
q1=(a/(2*b))*(2-b);
q2=0;
for i = 1:n
harm5=(((2*b*a)/(i*i*pi*pi))*(1-cos((i*pi)/b)))*cos((i*pi*x)/l);
q2=q2+harm5;
end
qwav=-1*(q1+q2);
function [qrswav]=qrs_wav(x,a_qrswav,d_qrswav,li)
l=li;
a=a_qrswav;
b=(2*l)/d_qrswav;
n=100;
qrs1=(a/(2*b))*(2-b);
qrs2=0;
for i = 1:n
harm=(((2*b*a)/(i*i*pi*pi))*(1-cos((i*pi)/b)))*cos((i*pi*x)/l);
qrs2=qrs2+harm;
end
function [swav]=s_wav(x,a_swav,d_swav,t_swav,li)
l=li;
x=x-t_swav;
a=a_swav;
b=(2*l)/d_swav;
n=100;
s1=(a/(2*b))*(2-b);
s2=0;
for i = 1:n
harm3=(((2*b*a)/(i*i*pi*pi))*(1-cos((i*pi)/b)))*cos((i*pi*x)/l);
s2=s2+harm3;
end
swav=-1*(s1+s2);
function [twav]=t_wav(x,a_twav,d_twav,t_twav,li)
l=li;
a=a_twav;
x=x-t_twav-0.045;
b=(2*l)/d_twav;
n=100;
t1=1/l;
t2=0;
for i = 1:n
harm2=(((sin((pi/(2*b))*(b-(2*i))))/(b-(2*i))+(sin((pi/(2*b))*(b+(2*i))))/(b+(2*i)))*(2/pi))*cos((i*pi*x)/l);
t2=t2+harm2;
end
twav1=t1+t2;
twav=a*twav1;
qrswav=qrs1+qrs2;
function [uwav]=u_wav(x,a_uwav,d_uwav,t_uwav,li)
l=li;
a=a_uwav
x=x-t_uwav;
b=(2*l)/d_uwav;
n=100;
u1=1/l
u2=0
for i = 1:n
harm4=(((sin((pi/(2*b))*(b-(2*i))))/(b-(2*i))+(sin((pi/(2*b))*(b+(2*i))))/(b+(2*i)))*(2/pi))*cos((i*pi*x)/l);
u2=u2+harm4;
end
uwav1=u1+u2;
uwav=a*uwav1;
12 Comments
James Tursa
on 16 Sep 2016
You need to format this to make it readable. But even then, it looks like there is too much going on for us to discern what the purpose of the code is without the help of any comments.
Steven Lord
on 16 Sep 2016
Your best hope is probably going to be to ask the person from whom you obtained that code to explain it. [And ask them to add comments the next time they write code!]
John D'Errico
on 16 Sep 2016
It is virtually impossible to understand what undocumented code is intended to do. We don't even know that it works as it should have. We have no indication of what the inputs are, nor what context the code is to be used under.
Contact the author. And tell them to write better code next time, AFTER they explain what it does.
Meha Gadkari
on 18 Sep 2016
Meha Gadkari
on 18 Sep 2016
Edited: Walter Roberson
on 18 Sep 2016
Meha Gadkari
on 18 Sep 2016
Edited: Walter Roberson
on 18 Sep 2016
Meha Gadkari
on 18 Sep 2016
Edited: Walter Roberson
on 18 Sep 2016
Meha Gadkari
on 18 Sep 2016
Edited: Walter Roberson
on 18 Sep 2016
Meha Gadkari
on 18 Sep 2016
Edited: Walter Roberson
on 18 Sep 2016
Meha Gadkari
on 18 Sep 2016
Edited: Walter Roberson
on 18 Sep 2016
Meha Gadkari
on 18 Sep 2016
John D'Errico
on 18 Sep 2016
Contact the author.
Answers (1)
Walter Roberson
on 18 Sep 2016
0 votes
You need to read the documentation that was provided as part of that File Exchange Submission as unfortunately there is no useful comments in the source.
The contribution includes files ECG.doc and ECG.pdf which describe the mathematics involved.
Categories
Find more on Pulsed Waveforms in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!