SCM

Forum: help

Monitor Forum | Start New Thread Start New Thread
RE: create & analyse & export 5 minute intervals from 24h recordings [ Reply ]
By: Constantino Antonio on 2016-11-02 17:32
[forum:43604]
Dear Marc,

I am very sorry for the reply. Somehow i missed your message in the forum.

The problem with the script is that it only creates a Tag ("5min"), which covers the whole series. CreateTimeAnalysisByEpisode analyzes both the RR intervals within a Tag and outside the Tag. Since the "outside Tag" does not contain any beat, it fails. I would create a different Tag for each 5
minute window and then apply the function:

begin = seq(0, tail(hd$Beat$Time, 1), by = 300)
n = length(begin)
hd = AddEpisodes(hd,
InitTimes =begin,
Durations = rep(300, n),
Tags = 1:n, # Create a different Tag for each window
Values = rep("1", n))
PlotNIHR(hd, Tag="all")

#debugonce(CreateTimeAnalysisByEpisodes)
results = CreateTimeAnalysisByEpisodes(hd, Tag="1")
results = CreateTimeAnalysisByEpisodes(hd, Tag="2")
results = CreateTimeAnalysisByEpisodes(hd, Tag="3")

I hope this helps.
Kind regards!

RE: create & analyse & export 5 minute intervals from 24h recordings [ Reply ]
By: Marc Jarczok on 2016-09-28 12:56
[forum:43533]

test_episodeR.R (13) downloads
Dear Constantino,
thats great, thank you for your help! I had to modify the code a bit to add the episodes:

#episode data

begin = seq(0, tail(hrv.data$Beat$Time, 1), by = 300)
n = length(begin)
hrv.data = AddEpisodes(hrv.data,
InitTimes =begin,
Durations = rep(300, n),
Tags = rep("5min,", n),
Values = rep("1", n))
PlotNIHR(hrv.data, Tag="all")

unfortunately the CreateTimeAnalysisByEpisodes command returns the following error:

##################################################################
> results = CreateTimeAnalysisByEpisodes(hrv.data, Tag="5min")
Using episodes with tag: 5min
** Splitting heart rate signal using episodes **
Using episodes with tag: 5min
Number of episodes: 4
Show Traceback

Rerun with Debug
Error in seq.default(from = lowhist, by = interval, length.out = longhist) :
'from' cannot be NA, NaN or infinite In addition: Warning messages:
1: In min(rr) : no non-missing arguments to min; returning Inf
2: In max(rr) : no non-missing arguments to max; returning -Inf
3: In min(rr) : no non-missing arguments to min; returning Inf
4: In max(rr) : no non-missing arguments to max; returning -Inf
##################################################################

i´ve attached the full code to this post.
The EDF file can be downloaded here:
https://heibox.uni-heidelberg.de/f/7708c7a822/?raw=1

Thanks for helping!
Marc

RE: create & analyse & export 5 minute intervals from 24h recordings [ Reply ]
By: Constantino Antonio on 2016-09-26 07:35
[forum:43530]
Dear Mr. Jarczok,

The wavelet method returns a vector with the same length of the original time series with the instantaneous energy in each frequency band. In order to compute the energy in intervals of 5 minutes you can split this wavelet-vector in chunks of size 1200 ( 300 seconds * 4 samples / seconds) and compute the mean (you may want to use the rollapply function from the zoo package).

On the other hand, there is no need to add one episode at a time. You may use:

hrv_data = HRVProcessedData
beg = seq(0, tail(hrv_data$Beat$Time, 1), by = 300)
n = length(beg)
hrv_data = AddEpisodes(hrv_data,
InitTimes = beg,
Durations = rep(300, n),
Tags = 1:n,
Values = rep("", n))
PlotNIHR(hrv_data, Tags = "all")

which creates chunks of 5 minutes using episodes. Then you may want to use the Time analysis function by episodes discussed here https://r-forge.r-project.org/forum/forum.php?thread_id=29689&forum_id=2952&group_id=919 .

Note that the CreateTimeAnalysis only applies to the whole recording, and that the window parameter is only used to compute some of the time parameters (e.g. the SDANN).

Kind regards

create & analyse & export 5 minute intervals from 24h recordings [ Reply ]
By: Marc Jarczok on 2016-09-21 08:42
[forum:43516]
Hi,

i need to do the following:
1) split up a 24h recording in 5 minute intervals e.g. 1-288
2) run time & frequency analysis on each of the 288 intervals
3) create datasets containing the results of the time or freq analysis for each interval that i can use in another program

I´m having trouble with step 1 & 2.

addEpisodes seem not the right function in step one (unless i would create the 288 epochs by hand).

i firstly thought, CreateTimeAnalysis would work, but despite the size=300 second option it returns the results for the complete 24h
hrv.data = CreateTimeAnalysis(hrv.data, size = 300, interval = 7.8125)


similar, CalculatePowerBand seem to "ignore" the size = 300 option
hrv.data = CalculatePowerBand(hrv.data , indexFreqAnalysis = 1,
type = "wavelet" , wavelet = "la8",
size = 300 ,
bandtolerance = 0.01, relative = FALSE,
ULFmin= 0 , ULFmax = 0.03,
VLFmin = 0.03, VLFmax = 0.05,
LFmin = 0.05, LFmax= 0.15,
HFmin = 0.14, HFmax= 0.4)


instead i receive from a 15 minute recording containing 1076beats and 3583 points a total of 3583 power density results per freqband.
So what is the basis of these 3583 points? how can i gain the result per 5 minute interval?
The example EDF recording is attached and below i pasted my current R code.

i appreciate your help!
Marc



library("foreign", lib.loc="/Library/Frameworks/R.framework/Versions/3.3/Resources/library")
library("RHRV", lib.loc="/Library/Frameworks/R.framework/Versions/3.3/Resources/library")
setwd("/Users/")

#prepare HRV dataset
hrv.data = CreateHRVData()
hrv.data = SetVerbose(hrv.data, TRUE )

hrv.data = LoadBeatEDFPlus(hrv.data, RecordName = "reduced15min_editedonset.edf",
RecordPath = "/Users/",
annotationType ="R-onset")
hrv.data = BuildNIHR(hrv.data)
hrv.data = FilterNIHR(hrv.data, minbpm=30, maxbpm=190)
hrv.data = InterpolateNIHR (hrv.data, freqhr = 4)


hrv.data = CreateTimeAnalysis(hrv.data, size = 300, interval = 7.8125)

#export time results
timedata <- as.data.frame(hrv.data$TimeAnalysis)
write.dta(timedata, "time.dta")


#Frequency domain analysis
hrv.data = CreateFreqAnalysis(hrv.data)
hrv.data = CalculatePowerBand(hrv.data , indexFreqAnalysis = 1,
type = "wavelet" , wavelet = "la8",
size = 300 ,
bandtolerance = 0.01, relative = FALSE,
ULFmin= 0 , ULFmax = 0.03,
VLFmin = 0.03, VLFmax = 0.05,
LFmin = 0.05, LFmax= 0.15,
HFmin = 0.14, HFmax= 0.4)

PlotPowerBand(hrv.data, indexFreqAnalysis = 1, ymax = 200, ymaxratio = 50)

#export freq results
frequdata <- as.data.frame(hrv.data$FreqAnalysis)
write.dta(frequdata, "frequ.dta")


Thanks to:
Vienna University of Economics and Business Powered By FusionForge