i just want to know what does Fun(y)=[R,S] , do in the matlab script. , and what does 'fun' do in general. Sampling_tim

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

i just want to know what does Fun(y)=[R,S] , do in the matlab script. , and what does 'fun' do in general. Sampling_tim

Post by answerhappygod »

i just want to know what does Fun(y)=[R,S] , do in the
matlab script. , and what does 'fun' do in general.
Sampling_time = 0.003;
disp("filename");
y = load('filename').val;
threshold = input('Enter the threshold value: ');
t = (1:21600)*Sampling_time;
[R,S] = Fun(y);
P_Width = zeros(1,length(R));
for p = 1:length(R)
c = 0;
d = 0;
while y(R(p) - c)>threshold && y(R(p) +
d)>threshold
if y(R(p) - c)>threshold
c = c+1;
end
if y(R(p) + d)>threshold
d = d+1;
end
end
P_Width(p) = c + d;
end
P_Width = P_Width*Sampling_time;
SSdiff = mean(diff(S))*Sampling_time;
disp("Number of S valleys: "+num2str(length(S)));
disp("Average time difference between two consecutive S-S valleys:
"+num2str(SSdiff)+"seconds");
disp("Width of each R peaks according to the threshold value
"+threshold+" :");
disp(P_Width);
figure
hold on
title('ECG signal from 208m.mat')
ylabel('Magnitude of signal')
plot(time,y)
xlabel('Time in seconds')
threshold = input('Please enter the threshold value: ');
disp("filename2");
y = load('filename2t').val(1,:);
[R,S] = Fun(y);
P_Width = zeros(1,length(R));
for p = 1:length(R)
c = 0;
d = 0;
while y(R(p) - c)>threshold && y(R(p) +
d)>threshold
if y(R(p) - c)>threshold
c = c+1;
end
if y(R(p) + d)>threshold
d = d+1;
end
end
P_Width(p) = c + d;
end
SSdiff = mean(diff(S))*Sampling_time;
P_Width = P_Width*Sampling_time;
disp("Width of each R peaks according to the threshold value
"+threshold+" :");
disp(P_Width);
disp("Number of S valleys: "+num2str(length(S)));
disp("Average time difference between two consecutive S-S valleys:
"+num2str(SSdiff)+"seconds");
figure
hold on
title('ECG signal from 100m.mat')
xlabel('Time(Seconds)')
ylabel('Magnitude of signal')
plot(time,y)
% Function used
function [M,N] = Fun(Y)
n = 1;
m = 1;
Peaks = zeros(1,length(Y));
Peak_LOCATION = zeros(1,length(Y));
Valleys = zeros(1,length(Y));
Valley_LOCATION = zeros(1,length(Y));
for i = 1:length(Y)-2
if (Y(i+1)-Y(i)>0) &&
(Y(i+2)-Y(i+1) <= 0)
Peaks(n)=Y(i+1);


Peak_LOCATION(n)=i+1;
n = n+1;
elseif (Y(i+1)-Y(i)<= 0) &&
(Y(i+2)-Y(i+1) > 0)
Valleys(m) =
Y(i+1);
Valley_LOCATION(m)
= i+1;
m = m+1;
end
end
Valleys = Valleys(1:m-1);
Valley_LOCATION = Valley_LOCATION(1:m-1);
Peaks = Peaks(1:n-1);
Peak_LOCATION = Peak_LOCATION(1:n-1);
M = zeros(1,length(Peaks));
N = zeros(1,length(Valleys));
l = 1;
for j=1:length(Peaks)
if (Peaks(j)-Valleys(j)) > 200

M(l) =
Peak_LOCATION(j);
N(l) =
Valley_LOCATION(j);
l=l+1;
end
end
M = M(1:l-1);
N = N(1:l-1);
end
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply