Mean absolute value for ecg signal

I have an ecg signal of total length 2500 samples with 250Hz sampling frequency. Now i need to find the Mean absolute value for the signal with 8s analysis window using the formula MAV =1/N summation ( 0 to N-1) of x(n). Can anyone help me with the code.
N=length(xrec); %xrec is my ecg signal
A=N/8;
Y=0;
for i=1:A
Y=Y+max(abs(xrec(i)));
end
MAV=(1/A)*Y;

Answers (1)

Your code is okay with exception of the length. If you have a sampling rate of 250 Hz (or, in another way of expression, values per second) you need to multiply it by the number of seconds you want to obtain the signal length. Fixing your code look like this (also, repare in the lower implementation for a more efficient way to do it with matlab):
xrec = randn(2500,1);
Fs = 250;
N=length(xrec); %xrec is my ecg signal
A= 8*Fs; % 8 seconds times Fs
Y=0;
for i=1:A
Y=Y+max(abs(xrec(i)));
end
MAV=(1/A)*Y;
% more efficient way
MAV = mean(abs(xrec(1:A)));

5 Comments

Thankyou sir. will this code work for the above.
Fs=360;
window = 8*Fs; %8seconds
MAV_buf=[];
i=1;
while(i<2.77)
start = ((i-1)*(window/2))+1;
last = ((window*i) - ((i-1)*(window/2)));
segment = f1(start:last);
max_val = max(segment);
segment = segment/max_val;
sumi = 0;
for j=1:length(segment)
sumi = sumi + abs(segment(j));
end
mav = 1/length(segment)*sumi;
MAV_buf = [MAV_buf mav];
i = i + 1;
end
What you want to do? A normalized moving mean? If so you need to check how many blocks your signal has. 2.77 is not a value that you put in a while/for loop that should give integer indexes. Correcting the index of the while loop should be fine, although I strongely recommend to do it with vectors, as I showed in the answer.
  1. choose a smaller segment x(n) from the ECG signal of 8s-second duration . If the sampling frequency of the ECG signal is Fs samples/s, then the total sample within this segment (N) is 8*Fs
  2. Next, divide the smaller segment x(n) by the maximum absolute value found in that segment.
  3. Calculate the MAV using the formula.
These are the steps i need to follow sir. Please kindly help me to solve this
The only thing missing from my first answer and your command is the normalization (step 2):
xrec = randn(2500,1); % replace for your signal and Fs
Fs = 250;
N=length(xrec); %xrec is my ecg signal
A= 8*Fs; % step 1
seg = xrec(1:A);
seg = seg/max(abs(seg)); % step 2
% Step 3
Y=0;
for i=1:A
Y=Y+max(abs(seg(i)));
end
MAV=(1/A)*Y;
% more efficient Step 3
MAV = mean(abs(seg(1:A)));
Little Flower
Little Flower on 25 Aug 2022
Edited: Little Flower on 25 Aug 2022
How to calculate Mean absolute value slope (MAVS) of a signal? It was given as the difference between the adjacent segments of mean absolute value (MAV). What does it mean ? Thanks in advance

Sign in to comment.

Asked:

on 10 May 2020

Edited:

on 25 Aug 2022

Community Treasure Hunt

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

Start Hunting!