Converting beat-by-beat data into second average

Hi,
I have a 30-minute recording of heart rate measured beat-by-beat (2003 samples), however i would like to have this dataset as averages of each second (1800 samples). I believe an interpolation of the data may be required but unsure how to acheive this.
Any help would be greatly appreciated!
Thanks.

回答 (2 件)

Mathieu NOE
Mathieu NOE 2022 年 10 月 26 日

1 投票

hello
you can use smoothdata to smooth / average your curve then you do the interpolation to resample at dt = 1 second
nota that your original sample rate (0.8985 second) and the target one (1 second) are very close, so there are not many samples of data in a 1 second long buffer. I supposed that it was rather a matter of smoothing (but maybe I'm wrong)
t = TimeHR.Time;
y = TimeHR.HR;
dt = mean(diff(t)); % original rate
% smoothing using 'samples' length window
samples = 5;
ys = smoothdata(y,'gaussian',samples);
% interpolate to get 1 s time increment data
new_t = t(1):1:t(end);
new_ys = interp1(t,ys,new_t,'linear');
figure
plot(t,y,new_t,new_ys)

2 件のコメント

Jason
Jason 2022 年 10 月 28 日
Thank you for you help!
Mathieu NOE
Mathieu NOE 2022 年 10 月 28 日
My pleasure !

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

William Rose
William Rose 2022 年 10 月 26 日

0 投票

I have done this in Labview before but not Matlab.
Make a time series of HR versus time, where HR is computed as 1/(R-R interval), and the time of each HR esitmate is the midpoint time between the two RR intervals. Now you have two vectors of equal length : t_raw (unevenly sampled) and HR. Then make a time vector with the values t=(0,1,2,...), and use interp1() to interpolate the HR to the 1-second time vector.

3 件のコメント

William Rose
William Rose 2022 年 10 月 26 日
編集済み: William Rose 2022 年 10 月 26 日
[edit: fix typos in text, no change to code] I'm sorry I had not opened your .mat file when I answered your question. Therefore my answer was based on the supposition that you were starting with a list of the R-wave times, derived from the EKG. Now I see that you have a time vector (uneven sampling rate, as expected) and a vector of HR values. So, as before, I recommend you create a time vector with equal sampling at 1 second intervals, and use interp1() to interpolate:
data=importdata('Beat-by-beat HR.mat'); %import the data
traw=data.Time; %raw time
hrraw=data.HR; %raw HR
t=0:floor(max(traw)); %vector of whole-second times
hr=interp1(traw,hrraw,t); %interpolated HR
plot(traw,hrraw,'-b.',t,hr,'rx') %plot results
xlim([0 30]) %plot first 30 seconds
legend('raw','interpolated'); grid on; %make plot pretty
xlabel('Time (s)'); ylabel('HR (bpm)');
Try that.
Jason
Jason 2022 年 10 月 28 日
That's great, thanks for your help!
William Rose
William Rose 2022 年 10 月 28 日
Jason, you’re welcome. Good luck with your work.

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

カテゴリ

製品

リリース

R2022b

質問済み:

2022 年 10 月 26 日

コメント済み:

2022 年 10 月 28 日

Community Treasure Hunt

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

Start Hunting!

Translated by