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

2 ビュー (過去 30 日間)
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
  2 件のコメント
KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 9 月 22 日
編集済み: KALYAN ACHARJYA 2019 年 9 月 22 日
I am working on ECG signal and I want to determine the HR.
Is this here ?
Mohanad Alkhodari
Mohanad Alkhodari 2019 年 9 月 22 日
No this is not the same
am working on a different thing

サインインしてコメントする。

採用された回答

Dimitris Kalogiros
Dimitris Kalogiros 2019 年 9 月 22 日
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');
  1 件のコメント
Mohanad Alkhodari
Mohanad Alkhodari 2019 年 9 月 27 日
I tweaked this code and it worked perfectly.
Fs = 200; % 200 Hz sampling frequency
time = ((0:17280000)/Fs)'; %24 hours in seconds
Kstep = (15*60)*Fs; % step of 15 minutes
Kwindow = (6*3600)*Fs; % averaging window is 6 hours
meanData=[];
meanTime=[];
k_old = 1;
for k=1:Kstep:length(data)-1
dataWindow=data(k_old:k+Kstep);
meanData=[meanData mean(dataWindow)];
meanTime=[meanTime time(k+floor(Kstep/2))];
k_old = k+Kstep;
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');

サインインしてコメントする。

その他の回答 (1 件)

Steven Lord
Steven Lord 2019 年 9 月 22 日
Use movmean with a datetime or duration SamplePoints input. Specify the window using a duration array.
  1 件のコメント
Mohanad Alkhodari
Mohanad Alkhodari 2019 年 9 月 27 日
I did not get this.
The signal is in samples, I use movemean but it only provides the window length as inputs.
How to use SamplePoints for steps of 15 minutes each?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeSignal Generation and Preprocessing についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by