3 views (last 30 days)

Hello,

I am working on ECG signal and I want to determine the HR.

How to compute the moving average of a signal with 6-hour window length and shifted 15 min at a time?

Sampling frequency is 200.

Thank you

Dimitris Kalogiros
on 22 Sep 2019

Hi Mohanad

Bellow, you will find an example, where a moving average corresponding to a 6h window, is applied upon a signal taken within an interval of 24h with Fsampling=200Hz

clearvars; close all; clc;

%% input data

Fs = 200; % 200 Hz sampling frequency

time = 0:(1/Fs):(24*3600-1); % data collected within 24 hours

data = sin(2*pi*(1/2E5).*time)+0.2*randn(size(time)); % an example of input data: a sine with some noise

%% averanging

Kstep = (15*60)*Fs; % step of 15 minutes

Kwindow = (6*3600)*Fs; % aneranging window is 6 hours

meanData=[]; meanTime=[];

for k=1:Kstep:length(data)-Kwindow

dataWindow=data(1:k+Kwindow);

meanData=[meanData mean(dataWindow)];

meanTime=[meanTime time(k+floor(Kwindow/2))];

end

figure;

%mean values are depocted at the middle of their corresponding 6h window

plot(time, data); hold on;

plot(meanTime, meanData, '-*'); zoom on; grid on;

xlabel('time'); ylabel('data values');

Steven Lord
on 22 Sep 2019

Sign in to answer this question.

Opportunities for recent engineering grads.

Apply Today
## 2 Comments

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/481528-how-to-compute-the-moving-average-of-a-signal-with-6-hour-window-length-and-shifted-15-min-at-a-time#comment_748619

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/481528-how-to-compute-the-moving-average-of-a-signal-with-6-hour-window-length-and-shifted-15-min-at-a-time#comment_748619

## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/481528-how-to-compute-the-moving-average-of-a-signal-with-6-hour-window-length-and-shifted-15-min-at-a-time#comment_748621

⋮## Direct link to this comment

https://au.mathworks.com/matlabcentral/answers/481528-how-to-compute-the-moving-average-of-a-signal-with-6-hour-window-length-and-shifted-15-min-at-a-time#comment_748621

Sign in to comment.