├── DESCRIPTION ├── MD5 ├── NAMESPACE ├── R ├── AddEpisodes.R ├── AnalyzeHRbyEpisodes.R ├── AnalyzePowerBandsByEpisodes.R ├── AvgIntegralCorrelation.R ├── BoundModwpt.r ├── BuildNIHR.R ├── BuildNIHR2.R ├── BuildTakensVector.R ├── CalculateApEn.R ├── CalculateCorrelationDimension.R ├── CalculateFracDim.R ├── CalculateInfDim.R ├── CalculateLyapunov.R ├── CalculateNonLinearParameters.R ├── CalculatePowerBand.R ├── CalculateRfromCorrelation.R ├── CalculateSampleEntropy.R ├── CalculateSpectrogram.R ├── CreateFreqAnalysis.R ├── CreateHRVData.R ├── CreateNonLinearAnalysis.R ├── CreateTimeAnalysis.R ├── EditNIHR.R ├── ExtractTimeSegment.R ├── FilterNIHR.R ├── GenerateEpisodes.R ├── IntegralCorrelation.R ├── InterpolateNIHR.R ├── ListEpisodes.R ├── LoadApneaWFDB.R ├── LoadBeat.R ├── LoadBeatAmbit.R ├── LoadBeatAscii.R ├── LoadBeatEDFPlus.R ├── LoadBeatPolar.R ├── LoadBeatRR.R ├── LoadBeatSuunto.R ├── LoadBeatVector.R ├── LoadBeatWFDB.R ├── LoadEpisodesAscii.R ├── LoadHeaderWFDB.R ├── ModifyEpisodes.R ├── NonLinearNoiseReduction.R ├── NonlinearityTest.R ├── OverplotEpisodes.R ├── PlotHR.R ├── PlotNIHR.R ├── PlotPowerBand.R ├── PlotSpectrogram.R ├── RHRVEasy.R ├── RQA.R ├── ReadFromFile.R ├── RemoveEpisodes.R ├── SetVerbose.R ├── SplitHRbyEpisodes.R ├── SplitPowerBandByEpisodes.R ├── StationaryFrequencyAnalysis.R ├── Utils.R ├── WriteToFile.R ├── checkingStructure.R ├── dfa.R ├── easyFreqAnalysis.R ├── easyNonlinearAnalysis.R ├── easyScalingRegionEstimation.R ├── easyStatsFunctions.R ├── easyTimeAnalysis.R ├── getC.r ├── getError.r ├── getNodes.r ├── getNodesAux.r ├── getPower.r ├── intToCharacter.R ├── modwptAnalysis.r ├── poincarePlot.R ├── rhrv.filled.contour.R ├── rhrv_in.r ├── selectEpisodes.R ├── stringToIntList.R ├── stringToStringList.R └── zzz.R ├── build └── vignette.rds ├── data ├── HRVData.rda └── HRVProcessedData.rda ├── inst ├── COPYRIGHT └── doc │ ├── RHRV-quickstart.R │ ├── RHRV-quickstart.Rmd │ ├── RHRV-quickstart.html │ ├── RHRVEasy.R │ ├── RHRVEasy.Rmd │ ├── RHRVEasy.html │ └── rhrv.index.html ├── man ├── AddEpisodes.Rd ├── AnalyzeHRbyEpisodes.Rd ├── AnalyzePowerBandsByEpisodes.Rd ├── AvgIntegralCorrelation.Rd ├── BuildNIHR.Rd ├── BuildTakens.Rd ├── BuildTakensVector.Rd ├── CalculateApEn.Rd ├── CalculateCorrDim.Rd ├── CalculateDFA.Rd ├── CalculateEmbeddingDim.Rd ├── CalculateEnergyInPSDBands.Rd ├── CalculateFracDim.Rd ├── CalculateInfDim.Rd ├── CalculateMaxLyapunov.Rd ├── CalculatePSD.Rd ├── CalculatePowerBand.Rd ├── CalculateRfromCorrelation.Rd ├── CalculateSampleEntropy.Rd ├── CalculateSpectrogram.Rd ├── CalculateTimeLag.Rd ├── CreateFreqAnalysis.Rd ├── CreateHRVData.Rd ├── CreateNonLinearAnalysis.Rd ├── CreateTimeAnalysis.Rd ├── EditNIHR.Rd ├── EstimatePSDSlope.Rd ├── ExtractTimeSegment.Rd ├── FilterNIHR.Rd ├── GenerateEpisodes.Rd ├── HRVData.Rd ├── HRVProcessedData.Rd ├── IntegralCorrelation.Rd ├── InterpolateNIHR.Rd ├── ListEpisodes.Rd ├── LoadApneaWFDB.Rd ├── LoadBeat.Rd ├── LoadBeatAmbit.Rd ├── LoadBeatAscii.Rd ├── LoadBeatEDFPlus.Rd ├── LoadBeatPolar.Rd ├── LoadBeatRR.Rd ├── LoadBeatSuunto.Rd ├── LoadBeatVector.Rd ├── LoadBeatWFDB.Rd ├── LoadEpisodesAscii.Rd ├── LoadHeaderWFDB.Rd ├── ModifyEpisodes.Rd ├── NonlinearityTests.Rd ├── OverplotEpisodes.Rd ├── PlotHR.Rd ├── PlotNIHR.Rd ├── PlotPSD.Rd ├── PlotPowerBand.Rd ├── PlotSinglePowerBand.Rd ├── PlotSpectrogram.Rd ├── PoincarePlot.Rd ├── RHRV-package.Rd ├── RHRVEasy.Rd ├── RHRVEasyStats.Rd ├── RQA.Rd ├── ReadFromFile.Rd ├── RecurrencePlot.Rd ├── RemoveEpisodes.Rd ├── SaveHRVIndices.Rd ├── SetVerbose.Rd ├── SplitHRbyEpisodes.Rd ├── SplitPowerBandByEpisodes.Rd ├── SurrogateTest.Rd ├── Window.Rd ├── WriteToFile.Rd ├── getNormSpectralUnits.Rd └── nonLinearNoiseReduction.Rd ├── src ├── filterhr.c ├── pmodwpt.c └── rhrv_init.c └── vignettes ├── RHRV-quickstart.Rmd ├── RHRVEasy.Rmd ├── beatsFolder └── example.beats └── figures ├── basicHRVData.pdf └── basicHRVData.png /DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: RHRV 2 | Type: Package 3 | Title: Heart Rate Variability Analysis of ECG Data 4 | Version: 5.0.0 5 | Date: 2024-09-19 6 | Maintainer: Leandro Rodriguez-Linares 7 | Authors@R: c(person("Leandro", "Rodriguez-Linares", 8 | email = "leandro@uvigo.es", 9 | role = c("aut", "cre")), 10 | person("Xose", "Vila", role = "aut"), 11 | person("Maria Jose", "Lado", role = "aut"), 12 | person("Arturo", "Mendez", role = "aut"), 13 | person("Abraham", "Otero", role = "aut"), 14 | person("Constantino Antonio", "Garcia", 15 | role = "aut"), 16 | person("Matti", "Lassila", 17 | role = "ctb")) 18 | Encoding: UTF-8 19 | URL: http://rhrv.r-forge.r-project.org/ 20 | Description: Allows users to import data files containing heartbeat positions in the most broadly used formats, to remove outliers or points with unacceptable physiological values present in the time series, to plot HRV data, and to perform time domain, frequency domain and nonlinear HRV analysis. See Garcia et al. (2017) . 21 | License: GPL-2 22 | Copyright: Code for the wavelet transform is based on Brandon 23 | Whitcher's work. See file COPYRIGHT for details 24 | Depends: R (>= 3.0.0), waveslim(>= 1.6.4), nonlinearTseries (>= 0.3.0), 25 | lomb (>= 1.0) 26 | Imports: boot, broom, doParallel, foreach, iterators, parallel, 27 | plotrix, PMCMRplus, segmented, stats, tibble, tidyr, writexl 28 | Suggests: tcltk, tkrplot, knitr, rmarkdown 29 | VignetteBuilder: knitr 30 | RoxygenNote: 7.3.1 31 | NeedsCompilation: yes 32 | Packaged: 2024-09-30 10:05:20 UTC; leandro 33 | Author: Leandro Rodriguez-Linares [aut, cre], 34 | Xose Vila [aut], 35 | Maria Jose Lado [aut], 36 | Arturo Mendez [aut], 37 | Abraham Otero [aut], 38 | Constantino Antonio Garcia [aut], 39 | Matti Lassila [ctb] 40 | Repository: CRAN 41 | Date/Publication: 2024-09-30 19:30:02 UTC 42 | -------------------------------------------------------------------------------- /NAMESPACE: -------------------------------------------------------------------------------- 1 | useDynLib(RHRV, .registration = TRUE) 2 | 3 | 4 | export("AddEpisodes", "AnalyzeHRbyEpisodes","AnalyzePowerBandsByEpisodes", 5 | "AvgIntegralCorrelation", "BuildNIHR", "BuildTakensVector", "BuildTakens", 6 | "CalculateApEn", "CalculateFracDim", "CalculatePowerBand","CalculateSpectrogram", 7 | "CalculateRfromCorrelation", "CreateFreqAnalysis", "CreateHRVData", 8 | "CreateNonLinearAnalysis", "CreateTimeAnalysis", "EditNIHR", "FilterNIHR", 9 | "GenerateEpisodes", "IntegralCorrelation", "InterpolateNIHR", 10 | "LoadApneaWFDB", "LoadBeatAscii", "LoadBeatEDFPlus", "LoadBeatPolar", 11 | "LoadBeat", "LoadBeatAmbit", "LoadBeatRR", "LoadBeatSuunto", 12 | "LoadBeatWFDB", "LoadBeatVector", 13 | "LoadEpisodesAscii", "LoadHeaderWFDB", "PlotHR", "PlotNIHR", 14 | "PlotPowerBand","PlotSinglePowerBand", 15 | "CalculatePSD", "PlotPSD","CalculateEnergyInPSDBands", 16 | "getNormSpectralUnits", 17 | "PlotSpectrogram", "ReadFromFile", "SetVerbose", 18 | "SplitHRbyEpisodes", "SplitPowerBandByEpisodes", "WriteToFile", 19 | "CalculateEmbeddingDim","CalculateTimeLag", 20 | "CalculateCorrDim","EstimateCorrDim","PlotCorrDim","PoincarePlot", 21 | "CalculateSampleEntropy","EstimateSampleEntropy","PlotSampleEntropy", 22 | "CalculateMaxLyapunov","EstimateMaxLyapunov","PlotMaxLyapunov", 23 | "CalculateDFA","EstimateDFA","PlotDFA", 24 | "CalculateInfDim","EstimateInfDim","PlotInfDim", 25 | "RQA","RecurrencePlot","NonLinearNoiseReduction", 26 | "NonlinearityTests","SurrogateTest","OverplotEpisodes", 27 | "ExtractTimeSegment","Window","EstimatePSDSlope", 28 | "ListEpisodes", "RemoveEpisodes", "ModifyEpisodes", 29 | "RHRVEasy", "RHRVEasyStats", "SaveHRVIndices" 30 | ) 31 | 32 | S3method(estimateScalingRegion,corrDim) 33 | S3method(estimateScalingRegion,maxLyapunov) 34 | S3method(nltsFilter,corrDim) 35 | S3method(nltsFilter,maxLyapunov) 36 | S3method(print,RHRVEasyResult) 37 | 38 | # import(progress) 39 | importFrom("grDevices", "palette", "rainbow", "topo.colors") 40 | importFrom("graphics", ".filled.contour", "Axis", "abline", "arrows", 41 | "axis", "box", "grid", "hist", "layout", "lcm", "legend", 42 | "lines", "par", "plot", "plot.new", "plot.window", "points", 43 | "polygon", "rect", "text", "title") 44 | importFrom("stats", "IQR", "approxfun", "coef", "cov", "diffinv", 45 | "dist", "fft", "lm", "median", "na.fail", "qchisq", 46 | "quantile", "runif", "sd", "splinefun", "ts", "var", 47 | "aov", "formula", "kruskal.test", 48 | "ks.test", "ksmooth", "p.adjust", "pairwise.t.test", 49 | "rstandard", "shapiro.test", "t.test", "uniroot") 50 | importFrom("utils", "head", "read.table", "tail", "capture.output") 51 | importFrom("PMCMRplus","kwAllPairsDunnTest") 52 | importFrom("boot","boot", "boot.ci") 53 | importFrom("broom","tidy") 54 | importFrom("foreach","%do%", "%dopar%", "foreach") 55 | importFrom("iterators","iter") 56 | importFrom("parallel","detectCores", "makeCluster") 57 | importFrom("doParallel", "registerDoParallel") 58 | importFrom("plotrix","clean.args") 59 | importFrom("segmented","segmented") 60 | importFrom("tibble","as_tibble") 61 | importFrom("tidyr","all_of", "pivot_longer") 62 | importFrom("writexl","write_xlsx") 63 | 64 | # Import all packages listed as Imports or Depends 65 | import( 66 | waveslim, 67 | nonlinearTseries, 68 | lomb 69 | ) 70 | 71 | -------------------------------------------------------------------------------- /R/AddEpisodes.R: -------------------------------------------------------------------------------- 1 | AddEpisodes <- 2 | function(HRVData, InitTimes,Tags, Durations ,Values, verbose=NULL) { 3 | #------------------ 4 | # Adds new episodes 5 | #------------------ 6 | # InitTimes -> Vector containing initial times in seconds 7 | # Tags -> Vector containing types of episodes 8 | # Durations -> Vector containing durations in seconds 9 | # Values -> Vector containing numerical values for episodes 10 | 11 | HRVData = HandleVerboseArgument(HRVData, verbose) 12 | 13 | VerboseMessage(HRVData$Verbose, "Adding new episodes") 14 | 15 | NewEpisodes=data.frame(InitTime=InitTimes,Type=Tags,Duration=Durations,Value=Values) 16 | VerboseMessage(HRVData$Verbose, 17 | paste("Added", length(NewEpisodes$InitTime), "episodes from file")) 18 | 19 | HRVData$Episodes = rbind(HRVData$Episodes, NewEpisodes) 20 | HRVData$Episodes = HRVData$Episodes[order(HRVData$Episodes$InitTime), ] # Sort episodes by InitTime 21 | HRVData$Episodes = HRVData$Episodes[!duplicated(HRVData$Episodes), ] # Remove duplicated episodes 22 | 23 | VerboseMessage(HRVData$Verbose, 24 | paste("Number of episodes:", length(HRVData$Episodes$InitTime))) 25 | 26 | 27 | return(HRVData) 28 | } 29 | 30 | -------------------------------------------------------------------------------- /R/AnalyzeHRbyEpisodes.R: -------------------------------------------------------------------------------- 1 | AnalyzeHRbyEpisodes <- 2 | function(HRVData, Tag="", func, ..., verbose=NULL) { 3 | # ---------------------------------------------- 4 | # Analyzes Heart Rate using Episodes information 5 | # ---------------------------------------------- 6 | # Tag -> specifies tag of episodes 7 | # func -> function to apply 8 | # Returns a list with two objects result 9 | 10 | # Function func musts receive a vector and returns an object 11 | 12 | funcToApply = match.fun(func) 13 | nameFunc = deparse(substitute(func)) 14 | 15 | HRVData = HandleVerboseArgument(HRVData, verbose) 16 | VerboseMessage(HRVData$Verbose, 17 | paste("Applying function to heart rate signal using episodic information")) 18 | VerboseMessage(HRVData$Verbose, paste0("Function: ", nameFunc)) 19 | 20 | CheckEpisodes(HRVData) 21 | CheckInterpolation(HRVData) 22 | VerboseMessage(HRVData$Verbose, 23 | ifelse(Tag == "", "No tag was specified", 24 | paste("Using episodes with tag:", Tag)) 25 | ) 26 | 27 | vectors = SplitHRbyEpisodes(HRVData, Tag = Tag) 28 | result = list(resultIn = funcToApply(vectors$InEpisodes, ...), 29 | resultOut = funcToApply(vectors$OutEpisodes, ...)) 30 | return(result) 31 | } 32 | 33 | -------------------------------------------------------------------------------- /R/AnalyzePowerBandsByEpisodes.R: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | #' Analyze power band by episodes 3 | #' @description 4 | #' Analyzes the ULF, VLF, LF and HF bands from a given indexFreqAnalysis allowing 5 | #' to evaluate the application of a desired function inside and outside each episode. 6 | #' @param HRVData Data structure that stores the beats register and information related to it. 7 | #' @param indexFreqAnalysis Integer value denoting which frequency analysis is going to be analyzed using func. Default: 1 8 | #' @param Tag Type of episode 9 | #' @param verbose Deprecated argument maintained for compatibility, use SetVerbose() instead 10 | #' @param func Function to be applied to each power band inside and outside episodes 11 | #' @param ... Optional arguments for func. 12 | #' @return Returns a list with two objects, that is, the values of the application of the selected function 13 | #' inside ("resultIn") and outside ("resultOut") episodes in the given indexFreqAnalysis. Each of these 14 | #' list has another set of lists: the "ULF", "VLF", "LF" and "HF" lists. 15 | #' @examples 16 | #' \dontrun{ 17 | #' hrv.data = CreateHRVData() 18 | #' hrv.data = SetVerbose(hrv.data, TRUE) 19 | #' hrv.data = LoadBeat(hrv.data, fileType = "WFDB", "a03", RecordPath ="beatsFolder/", 20 | #' annotator = "qrs") 21 | #' hrv.data = LoadApneaWFDB(hrv.data, RecordName="a03",Tag="Apnea", 22 | #' RecordPath="beatsFolder/") 23 | #' hrv.data = BuildNIHR(hrv.data) 24 | #' hrv.data = InterpolateNIHR (hrv.data, freqhr = 4) 25 | #' hrv.data = CreateFreqAnalysis(hrv.data) 26 | #' hrv.data = CalculatePowerBand( hrv.data , indexFreqAnalysis= 1, 27 | #' type = "wavelet", wavelet = "la8", 28 | #' bandtolerance = 0.01, relative = FALSE) 29 | #' results = AnalyzePowerBandsByEpisodes(hrv.data,indexFreqAnalysis=1, 30 | #' Tag="Apnea",func=mean)} 31 | AnalyzePowerBandsByEpisodes = function(HRVData, indexFreqAnalysis = length(HRVData$FreqAnalysis), Tag="", verbose=NULL,func, ...) { 32 | # ---------------------------------------------- 33 | # Analyzes PowerBands using Episodes information 34 | # ---------------------------------------------- 35 | # indexFreqAnalysis -> which frequency analysis is going to be analyzed using func 36 | # Tag -> specifies tag of episodes 37 | # func -> function to apply 38 | # ... -> additional arguments for func 39 | # Returns a list with two objects result 40 | 41 | funcToApply = match.fun(func) 42 | nameFunc = deparse(substitute(func)) 43 | 44 | 45 | #check if indexFreqAnalysis exists 46 | CheckAnalysisIndex(indexFreqAnalysis, length(HRVData$FreqAnalysis), 47 | "frequency") 48 | HRVData = HandleVerboseArgument(HRVData, verbose) 49 | VerboseMessage(HRVData$Verbose, 50 | paste("Applying function to power bands in frequency analysis", 51 | indexFreqAnalysis,"using episodic information")) 52 | VerboseMessage(HRVData$Verbose, paste0("Function: ",nameFunc,"()")) 53 | 54 | 55 | CheckEpisodes(HRVData) 56 | 57 | VerboseMessage(HRVData$Verbose, 58 | ifelse(Tag == "", 59 | "No tag was specified", 60 | paste("Using episodes with tag:", Tag))) 61 | 62 | episodicInformation = SplitPowerBandByEpisodes(HRVData, 63 | indexFreqAnalysis = indexFreqAnalysis, 64 | Tag = Tag) 65 | 66 | bandNames = names(episodicInformation$InEpisodes) 67 | resultIn = list() 68 | resultOut = list() 69 | for (band in bandNames){ 70 | resultIn[[band]] = funcToApply(episodicInformation$InEpisodes[[band]], ...) 71 | resultOut[[band]] = funcToApply(episodicInformation$OutEpisodes[[band]], ...) 72 | } 73 | 74 | 75 | result=list(resultIn=resultIn,resultOut=resultOut) 76 | return(result) 77 | 78 | } 79 | -------------------------------------------------------------------------------- /R/AvgIntegralCorrelation.R: -------------------------------------------------------------------------------- 1 | AvgIntegralCorrelation <- 2 | function(HRVData, Data, m, tau, r) { 3 | # ------------------------------------- 4 | # Averages Integral Correlation 5 | # ------------------------------------- 6 | .Deprecated("CalculateSampleEntropy") 7 | Cmr = IntegralCorrelation(HRVData,Data,m=m,tau=tau,r=r) 8 | 9 | VerboseMessage(HRVData$Verbose, 10 | "Averaging Integral Correlation") 11 | 12 | Phi=log(sum(Cmr)/length(Cmr)) 13 | 14 | VerboseMessage(HRVData$Verbose, 15 | paste("Average Integral Correlation:", mean(Cmr))) 16 | 17 | return(Phi) 18 | } 19 | 20 | -------------------------------------------------------------------------------- /R/BoundModwpt.r: -------------------------------------------------------------------------------- 1 | BoundModwpt<- function(x, wf="la8", n.levels=4, oldtargets) 2 | { 3 | 4 | N <- length(x); storage.mode(N) <- "integer" 5 | J <- n.levels 6 | if(2^J > N) stop("Too many depth levels in the wavelet transform") 7 | 8 | dict <- wave.filter(wf) 9 | L <- dict$length 10 | storage.mode(L) <- "integer" 11 | ht <- dict$hpf/sqrt(2) 12 | storage.mode(ht) <- "double" 13 | gt <- dict$lpf/sqrt(2) 14 | storage.mode(gt) <- "double" 15 | 16 | targets=prepareTargets(oldtargets)#encoding targets using gray code 17 | 18 | y <- vector("list", sum(2^(1:J))) 19 | yn <- length(y) 20 | crystals1 <- rep(1:J, 2^(1:J)) 21 | crystals2 <- unlist(apply(as.matrix(2^(1:J) - 1), 1, seq, from=0)) 22 | names(y) <- paste("w", crystals1, ".", crystals2, sep="") 23 | 24 | W <- numeric(N);V<- numeric(N) 25 | storage.mode(W) <- "double"; storage.mode(V)<- "double" 26 | for(j in 1:J) { 27 | index <- 0 28 | jj <- min((1:yn)[crystals1 == j]) 29 | for(n in 0:(2^j / 2 - 1)) { 30 | index <- index + 1 31 | #should filter parent node j-1,n 32 | sc=shouldCompute(c(j-1,n),targets) 33 | if(sum(sc)>0){ 34 | if(j > 1) 35 | x <- y[[(1:yn)[crystals1 == j-1][index]]] 36 | if(n %% 2 == 0) { 37 | z <- .C("pmodwpt", as.double(x), N, as.integer(j),as.integer(2), L, ht, gt, 38 | W = W, V = V, PACKAGE="RHRV")[8:9] 39 | y[[jj + 2*n + 1]] <- z$W 40 | y[[jj + 2*n]] <- z$V 41 | } 42 | else { 43 | z <- .C("pmodwpt", as.double(x), N, as.integer(j),as.integer(2), L, ht, gt, 44 | W = W, V = V, PACKAGE="RHRV")[8:9] 45 | y[[jj + 2*n]] <- z$W 46 | y[[jj + 2*n + 1 ]] <- z$V 47 | } 48 | } 49 | 50 | } 51 | } 52 | 53 | return(y) 54 | } 55 | 56 | 57 | shouldCompute2intCode<-function(sc){ 58 | if (codeEquals(sc,c(1,0))){ intCode=0} 59 | if (codeEquals(sc,c(0,1))) { intCode=1} 60 | if (codeEquals(sc,c(1,1))){intCode=2} 61 | return (intCode) 62 | } 63 | 64 | prepareTargets <- function(targets){ 65 | newTargets=list() 66 | numberTargets=length(targets)/2; 67 | for (n in 1:numberTargets){ 68 | newTargets[[n]]=getC(targets[[2*n-1]],targets[[2*n]]) 69 | } 70 | return(newTargets) 71 | } 72 | 73 | shouldCompute <- function(node,targets){ 74 | 75 | #compute should be c(0,0)(none), c(1,0)(left),c(0,1)(right), c(1,1) (both) 76 | compute=c(0,0) 77 | # node c(0,0) must be computed 78 | if (nodeEquals(node,c(0,0))){ 79 | len=length(targets) 80 | for (j in 1:len){ 81 | if (targets[[j]][1]==0){ 82 | compute[[1]]=1; 83 | }else{ 84 | compute[[2]]=1; 85 | } 86 | if (codeEquals(compute,c(1,1))) break 87 | } 88 | 89 | }else{ 90 | len=length(targets) 91 | nodeCode=getC(node[[1]],node[[2]]) 92 | codeLen=length(nodeCode) 93 | compute=c(0,0) 94 | for (j in 1:len){ 95 | if (length(targets[[j]])>codeLen){ 96 | equals=codeEquals(nodeCode,targets[[j]][1:codeLen]) 97 | if (equals){ 98 | ntc=nodeToCompute(targets[[j]][[codeLen+1]]) 99 | compute=compute+ntc 100 | compute=compute/max(compute)## avoid (2,0) or (0,2) 101 | if (codeEquals(compute,c(1,1))) break 102 | 103 | } 104 | } 105 | } 106 | return (compute) 107 | } 108 | 109 | 110 | 111 | return(compute); 112 | } 113 | 114 | 115 | nodeToCompute<-function(number){ 116 | if (number==1){##high pass filter 117 | return (c(0,1)) 118 | }else{## low pass filter 119 | return (c(1,0)) 120 | } 121 | } 122 | 123 | codeEquals<-function(c1,c2){ 124 | if (length(c1)!=length(c2)) 125 | { 126 | return (FALSE) 127 | }else{ 128 | return (prod(c1==c2)==1) 129 | } 130 | } 131 | 132 | nodeEquals<-function(n1,n2){ 133 | return ((n1[1]==n2[1])&&(n1[2]==n2[2])); 134 | 135 | } 136 | -------------------------------------------------------------------------------- /R/BuildNIHR.R: -------------------------------------------------------------------------------- 1 | BuildNIHR <- 2 | function(HRVData, verbose=NULL) { 3 | #------------------------------------------------------ 4 | # Obtains instantaneous heart rate from beats positions 5 | #------------------------------------------------------ 6 | 7 | HRVData = HandleVerboseArgument(HRVData, verbose) 8 | 9 | VerboseMessage(HRVData$Verbose, "Calculating non-interpolated heart rate") 10 | 11 | # Check if some beats have been loaded 12 | CheckBeats(HRVData) 13 | 14 | NBeats = length(HRVData$Beat$Time) 15 | VerboseMessage(HRVData$Verbose, paste("Number of beats:",NBeats)) 16 | 17 | hr = c(0) 18 | hr[2:NBeats] = 60.0 / diff(HRVData$Beat$Time) 19 | hr[1] = hr[2] # Not a real data 20 | HRVData$Beat$niHR = hr 21 | 22 | rr = c(0) 23 | rr[2:NBeats] = 1000.0 * diff(HRVData$Beat$Time) 24 | rr[1] = rr[2] # Not a real data 25 | HRVData$Beat$RR = rr 26 | 27 | return(HRVData) 28 | } 29 | 30 | -------------------------------------------------------------------------------- /R/BuildNIHR2.R: -------------------------------------------------------------------------------- 1 | # source('/data/pulse/rhrv/pkg/R/BuildNIHR2.R', chdir = TRUE) 2 | BuildNIDHR <- 3 | function(HRVData, verbose=NULL) { 4 | #------------------------------------------------------ 5 | # Obtains instantaneous heart rate variation from beats positions 6 | # D for difference 7 | #------------------------------------------------------ 8 | if (!is.null(verbose)) { 9 | cat(" --- Warning: deprecated argument, using SetVerbose() instead ---\n --- See help for more information!! ---\n") 10 | SetVerbose(HRVData,verbose) 11 | } 12 | 13 | if (HRVData$Verbose) { 14 | cat("** Calculating non-interpolated heart rate differences **\n") 15 | } 16 | 17 | if (is.null(HRVData$Beat$Time)) { 18 | cat(" --- ERROR: Beats positions not present... Impossible to calculate Heart Rate!! ---\n") 19 | return(HRVData) 20 | } 21 | 22 | NBeats=length(HRVData$Beat$Time) 23 | if (HRVData$Verbose) { 24 | cat(" Number of beats:",NBeats,"\n"); 25 | } 26 | 27 | 28 | #using NA, not constant extrapolation as else in RHRV 29 | #drr=c(NA,NA,1000.0* diff(HRVData$Beat$Time, lag=1 , differences=2)) 30 | HRVData$Beat$dRR=c(NA, NA, 31 | 1000.0*diff(HRVData$Beat$Time, lag=1, differences=2)) 32 | 33 | HRVData$Beat$avRR=(c(NA,HRVData$Beat$RR[-1])+HRVData$Beat$RR)/2 34 | 35 | #relative variation. gs 2014-08-21 36 | HRVData$Beat$HRRV <- HRVData$Beat$dRR/HRVData$Beat$avRR 37 | 38 | return(HRVData) 39 | } 40 | 41 | -------------------------------------------------------------------------------- /R/BuildTakensVector.R: -------------------------------------------------------------------------------- 1 | BuildTakensVector <- 2 | function(HRVData, Data, m, tau) { 3 | # ------------------------------------- 4 | # Calculates Takens expanded vectors 5 | # ------------------------------------- 6 | .Deprecated("BuildTakens") 7 | 8 | VerboseMessage(HRVData$Verbose, paste("Creating Takens expanded vectors")) 9 | VerboseMessage(HRVData$Verbose, paste("m:", m, "Tau:", tau)) 10 | 11 | 12 | N = length(Data) 13 | jump = tau 14 | maxjump = (m-1)*jump 15 | jumpsvect = seq(0,maxjump,jump) 16 | numjumps = length(jumpsvect) 17 | numelem = N-maxjump 18 | DataExp = matrix(nrow=numelem,ncol=numjumps) 19 | 20 | for (i in 1:numelem) { 21 | DataExp[i,1:numjumps] = Data[jumpsvect+i] 22 | } 23 | 24 | return(DataExp) 25 | } 26 | 27 | 28 | #' Build the Takens' vectors 29 | #' @description 30 | #' This function builds the Takens' vectors of the Non Interpolated RR intervals. 31 | #' The set of Takens' vectors is the result of embedding the time series in 32 | #' a m-dimensional space. That is, the \eqn{n^{th}} Takens' vector is defined as 33 | #' \deqn{T[n]=\{niRR[n], niRR[n+ timeLag],..., niRR[n+m*timeLag]\}.} 34 | #' Taken's theorem states that we can then reconstruct an equivalent dynamical 35 | #' system to the original one (the 36 | #' dynamical system that generated the observed time series) by using the Takens' vectors. 37 | 38 | #' @param HRVData Data structure that stores the beats register and information related to it 39 | #' @param embeddingDim Integer denoting the dimension in which we shall embed the RR series. 40 | #' @param timeLag Integer denoting the number of time steps that will be use to construct the 41 | #' Takens' vectors. 42 | #' @return A matrix containing the Takens' vectors (one per row). 43 | #' @note This function is based on the \code{\link[nonlinearTseries]{buildTakens}} function from the 44 | #' nonlinearTseries package. 45 | #' @references H. Kantz and T. Schreiber: Nonlinear Time series Analysis (Cambridge university press) 46 | BuildTakens = function(HRVData, embeddingDim, timeLag){ 47 | CheckNIHR(HRVData) 48 | buildTakens(HRVData$Beat$RR,embedding.dim = embeddingDim,time.lag = timeLag) 49 | } 50 | -------------------------------------------------------------------------------- /R/CalculateApEn.R: -------------------------------------------------------------------------------- 1 | CalculateApEn <- 2 | function(HRVData, indexNonLinearAnalysis = length(HRVData$NonLinearAnalysis), m=2, tau=1, r=0.2, N=1000, verbose=NULL) { 3 | # ------------------------------------- 4 | # Calculates Approximate Entropy 5 | # ------------------------------------- 6 | .Deprecated("CalculateSampleEntropy") 7 | HRVData = HandleVerboseArgument(HRVData, verbose) 8 | 9 | npoints = length(HRVData$Beat$niHR) 10 | 11 | if (npoints > N) { 12 | DataInt = HRVData$Beat$niHR[(npoints / 2 - N / 2):(npoints / 2 + N / 2)] 13 | } 14 | else{ 15 | DataInt = HRVData$Beat$niHR 16 | } 17 | r = r*sd(DataInt) 18 | 19 | VerboseMessage(HRVData$Verbose, "Calculating Approximate Entropy") 20 | Phi1 = AvgIntegralCorrelation(HRVData,DataInt,m = m,tau = tau,r = r) 21 | Phi2 = AvgIntegralCorrelation(HRVData,DataInt,m = (m + 1),tau = tau,r = r) 22 | ApEn = Phi1 - Phi2 23 | VerboseMessage(HRVData$Verbose, paste("Approximate Entropy: ", ApEn)) 24 | 25 | HRVData$NonLinearAnalysis[[indexNonLinearAnalysis]]$ApEn=ApEn 26 | return(HRVData) 27 | } 28 | 29 | -------------------------------------------------------------------------------- /R/CalculateFracDim.R: -------------------------------------------------------------------------------- 1 | CalculateFracDim <- 2 | function(HRVData, indexNonLinearAnalysis = length(HRVData$NonLinearAnalysis), 3 | m=10, tau=3, Cra=0.005, Crb=0.75, N=1000, verbose=NULL) { 4 | # ------------------------------------- 5 | # Calculates Fractal Dimension 6 | # ------------------------------------- 7 | # Using paste in order to maintain the line format 8 | .Deprecated("CalculateCorrDim") 9 | 10 | HRVData = HandleVerboseArgument(HRVData, verbose) 11 | 12 | npoints = length(HRVData$Beat$niHR) 13 | if (npoints > N) { 14 | DataInt = HRVData$Beat$niHR[(npoints / 2 - N / 2):(npoints / 2 + N / 2)] 15 | } else{ 16 | DataInt = HRVData$Beat$niHR 17 | } 18 | 19 | randC = CalculateRfromCorrelation(HRVData, DataInt, m=m, tau=tau, Cra=Cra, Crb=Crb) 20 | ra = randC[1,1] 21 | rb = randC[1,2] 22 | Cmra = randC[2,1] 23 | Cmrb = randC[2,2] 24 | 25 | VerboseMessage(HRVData$Verbose, "Calculating Fractal Dimension") 26 | 27 | FracDim = (log(Cmrb) - log(Cmra)) / (log(rb) - log(ra)) 28 | VerboseMessage(HRVData$Verbose, paste("Fractal Dimension:", FracDim)) 29 | HRVData$NonLinearAnalysis[[indexNonLinearAnalysis]]$FracDim=FracDim 30 | 31 | return(HRVData) 32 | } 33 | 34 | -------------------------------------------------------------------------------- /R/CalculateRfromCorrelation.R: -------------------------------------------------------------------------------- 1 | CalculateRfromCorrelation <- 2 | function(HRVData, Data, m, tau, Cra, Crb) { 3 | # ------------------------------------- 4 | # Calculates ra and rb from Correlation 5 | # ------------------------------------- 6 | .Deprecated("CalculateCorrDim") 7 | randC = matrix(nrow=2, ncol=2) 8 | 9 | DataExp = BuildTakensVector(HRVData,Data,m=m,tau=tau) 10 | # numelem = nrow(DataExp) 11 | 12 | VerboseMessage(HRVData$Verbose, "Calculating R from Correlation") 13 | 14 | 15 | mutualDistance = dist(DataExp,method="maximum") 16 | 17 | numelem = length(mutualDistance) 18 | rs = quantile(mutualDistance, probs = c(0.005, 0.75)) 19 | ra = rs[1] 20 | rb = rs[2] 21 | 22 | Cmra = length(mutualDistance[mutualDistance <= ra]) / numelem 23 | Cmrb = length(mutualDistance[mutualDistance <= rb]) / numelem 24 | 25 | VerboseMessage(HRVData$Verbose, paste("ra =", rhrvFormat(ra))) 26 | VerboseMessage(HRVData$Verbose, paste("rb =", rhrvFormat(rb))) 27 | 28 | 29 | VerboseMessage(HRVData$Verbose, paste("Cmra =", rhrvFormat(Cmra * 100))) 30 | VerboseMessage(HRVData$Verbose, paste("Cmrb =", rhrvFormat(Cmrb * 100))) 31 | 32 | randC[1,1] = ra 33 | randC[1,2] = rb 34 | randC[2,1] = Cmra 35 | randC[2,2] = Cmrb 36 | 37 | return(randC) 38 | } 39 | 40 | -------------------------------------------------------------------------------- /R/CalculateSpectrogram.R: -------------------------------------------------------------------------------- 1 | CalculateSpectrogram <- 2 | function(HRVData, size, shift, sizesp=1024, verbose=NULL) { 3 | # --------------------------------------------------------------- 4 | # Calculates the spectrogram of an interpolated heart rate signal 5 | # --------------------------------------------------------------- 6 | # size, disp: size and displacement of window (sec.) 7 | # sizesp: points for calculating spectrogram (zero padding) 8 | # Used by PlotSpectrogram and CalculatePowerPerBand 9 | 10 | HRVData = HandleVerboseArgument(HRVData, verbose) 11 | 12 | 13 | VerboseMessage(HRVData$Verbose, 14 | "Calculating spectrogram") 15 | 16 | shift=shift*HRVData$Freq_HR 17 | size=floor(size*HRVData$Freq_HR) 18 | 19 | VerboseMessage(HRVData$Verbose, 20 | paste("Window:", size, "samples (shift:", shift, "samples)")) 21 | 22 | if (is.null(sizesp)){ 23 | sizesp = 2^ceiling(log2(size)) 24 | } 25 | if (sizesp <= size){ 26 | sizesp = size 27 | } 28 | 29 | sizezp=sizesp-size 30 | VerboseMessage(HRVData$Verbose, 31 | paste("Window size for calculation:", sizesp, 32 | " samples (zero padding:", sizezp," samples)")) 33 | 34 | 35 | signal=1000.0/(HRVData$HR/60.0) # msec. 36 | 37 | VerboseMessage(HRVData$Verbose, 38 | paste("Signal size:", length(signal), "samples")) 39 | 40 | hamming=0.54-0.46*cos(2*pi*(0:(size-1))/(size-1)) 41 | hammingfactor=1.586 42 | 43 | # Calculates the number of windows 44 | nw=1 45 | begnw=1 46 | repeat { 47 | begnw=begnw+shift 48 | if ((begnw+size-1)>=length(signal)) { 49 | break 50 | } 51 | nw=nw+1 52 | } 53 | 54 | VerboseMessage(HRVData$Verbose, 55 | paste("Windowing signal with", nw, "windows")) 56 | 57 | zp=matrix(nrow=nw,ncol=sizesp) 58 | for (i in 1:nw) { 59 | beg=1+(shift*(i-1)) 60 | windowedSignal = signal[beg:(beg + size - 1)] 61 | windowedSignal = windowedSignal - mean(windowedSignal) 62 | zp[i, ] = c(windowedSignal * hamming, rep(0, length = sizezp)) 63 | } 64 | 65 | z=matrix(nrow=nw,ncol=floor(sizesp/2)) 66 | for (i in 1:nw) { 67 | f= hammingfactor * abs(fft(zp[i,]))^2 68 | f = f/(2*(sizesp^2)) 69 | f=f[1:(length(f)/2)] 70 | z[i,]=f 71 | } 72 | 73 | VerboseMessage(HRVData$Verbose, 74 | paste("Spectrogram calculated")) 75 | 76 | return(z) 77 | } 78 | 79 | -------------------------------------------------------------------------------- /R/CreateFreqAnalysis.R: -------------------------------------------------------------------------------- 1 | CreateFreqAnalysis <- 2 | function(HRVData, verbose=NULL) { 3 | # --------------------------------------------------------- 4 | # Creates a frequency analysis associated to the data model 5 | # --------------------------------------------------------- 6 | 7 | HRVData = HandleVerboseArgument(HRVData, verbose) 8 | VerboseMessage(HRVData$Verbose, "Creating frequency analysis") 9 | num = length(HRVData$FreqAnalysis) 10 | HRVData$FreqAnalysis[[num + 1]] = list() 11 | VerboseMessage(HRVData$Verbose, 12 | paste("Data has now", num + 1, "frequency analysis")) 13 | return(HRVData) 14 | } 15 | 16 | -------------------------------------------------------------------------------- /R/CreateHRVData.R: -------------------------------------------------------------------------------- 1 | CreateHRVData <- 2 | function(Verbose=FALSE) { 3 | # ---------------------- 4 | # Creates the data model 5 | # ---------------------- 6 | # Verbose -> TRUE for Verbose mode 7 | 8 | VerboseMessage(Verbose, "Creating data model") 9 | 10 | HRVData <- list() 11 | HRVData$Beat=NULL 12 | # Beat annotations: dataframe containing: 13 | # Time -> sequence of beats (seconds) 14 | # niHR -> non interpolated instantaneous frequency (beats/min) 15 | # RR -> instantaneous period (mseg.) 16 | 17 | HRVData$Episodes=NULL 18 | # Episodes annotations: dataframe containing: 19 | # InitTime -> initial time for the episodes (seconds) 20 | # Type -> type of episodes 21 | # Duration -> duration of episodes 22 | # Value -> numerical value for episodes 23 | 24 | HRVData$Freq_HR=NULL # Heart Rate interpolation frequency (default: 4 Hz) 25 | 26 | HRVData$HR=NULL # Interpolated Heart Rate 27 | 28 | HRVData$Ext="hrv" # Extension for files 29 | 30 | HRVData$datetime=NULL # Date and time for the data 31 | 32 | HRVData$FreqAnalysis <- list() # Frequency analysis associated to the data 33 | 34 | HRVData$TimeAnalysis<-list() # Time analysis associated to the data 35 | 36 | HRVData$NonLinearAnalysis<-list() # Non Linear analysis associated to the data 37 | 38 | HRVData$Verbose = Verbose 39 | 40 | VerboseMessage(HRVData$Verbose, "Data model created") 41 | 42 | return(HRVData) 43 | } 44 | 45 | -------------------------------------------------------------------------------- /R/CreateNonLinearAnalysis.R: -------------------------------------------------------------------------------- 1 | CreateNonLinearAnalysis <- 2 | function(HRVData, verbose=NULL) { 3 | # ---------------------------------------------------------- 4 | # Creates a non linear analysis associated to the data model 5 | # ---------------------------------------------------------- 6 | HRVData = HandleVerboseArgument(HRVData, verbose) 7 | VerboseMessage(HRVData$Verbose, "Creating non linear analysis") 8 | 9 | num = length(HRVData$NonLinearAnalysis) 10 | HRVData$NonLinearAnalysis[[num + 1]] = list() 11 | 12 | VerboseMessage(HRVData$Verbose, paste("Data has now ",num + 1," nonlinear analysis")) 13 | 14 | return(HRVData) 15 | } 16 | 17 | -------------------------------------------------------------------------------- /R/FilterNIHR.R: -------------------------------------------------------------------------------- 1 | FilterNIHR <- 2 | function(HRVData, long=50, last=13, minbpm=25, maxbpm=200, mini=NULL, maxi=NULL, fixed=NULL, verbose=NULL) { 3 | # ---------------------------------------------------------------------------------------- 4 | # Filters non-interpolated heart rate 5 | # Filtering is based on comparisons with previous and last values and with an updated mean 6 | # ---------------------------------------------------------------------------------------- 7 | 8 | CheckDeprecatedArg(mini) 9 | CheckDeprecatedArg(maxi) 10 | CheckDeprecatedArg(fixed) 11 | 12 | HRVData = HandleVerboseArgument(HRVData, verbose) 13 | 14 | CheckBeats(HRVData) 15 | CheckNIHR(HRVData) 16 | 17 | VerboseMessage(HRVData$Verbose, "Filtering non-interpolated Heart Rate") 18 | VerboseMessage(HRVData$Verbose, 19 | paste("Number of original beats:",length(HRVData$Beat$niHR))) 20 | 21 | 22 | n=length(HRVData$Beat$niHR) 23 | ind=seq(from=0,to=0,length.out=n) 24 | # call C function to load the results in out 25 | out <-.C("filterhr",hr=as.double(HRVData$Beat$niHR),as.integer(n),as.integer(long),as.integer(last),as.integer(minbpm),as.integer(maxbpm),ind=as.integer(ind)) 26 | #copiei a maneira que implmentou Leandro para actualizar a estructura HRVData$Beat 27 | hr=HRVData$Beat$niHR[out$ind==1] 28 | beat=HRVData$Beat$Time[out$ind==1] 29 | rr=HRVData$Beat$RR[out$ind==1] 30 | 31 | VerboseMessage(HRVData$Verbose, 32 | paste("Number of accepted beats:", length(hr))) 33 | 34 | 35 | HRVData$Beat = data.frame (Time=beat, niHR=hr, RR=rr) 36 | return(HRVData) 37 | } 38 | 39 | -------------------------------------------------------------------------------- /R/GenerateEpisodes.R: -------------------------------------------------------------------------------- 1 | GenerateEpisodes <- 2 | function(HRVData, NewBegFrom = c("Beg", "End"), NewEndFrom = c("End", "Beg"), 3 | DispBeg, DispEnd, OldTag="", NewTag="", verbose=NULL) { 4 | #----------------------------------- 5 | # Creates new episodes from old ones 6 | #----------------------------------- 7 | # NewBegFrom, NewEndFrom -> source of new beginning and end of episodes ("Beg" for indicating the same beginning as that of the old episode, "End" for end) 8 | # DispBeg, DispEnd -> absolute displacements for new episodes in seconds 9 | # OldTag -> specifies tag of old episodes 10 | # NewTag -> specifies tag for new episodes (if empty, copies OldTag) 11 | 12 | # Example: arguments for creating episodes one minute before old ones 13 | # NewBegFrom="Beg", NewEndFrom="End", DispBeg=-60, DispEnd=-60 14 | 15 | # Example: arguments for creating episodes just after previous ones (length = 1 min.) 16 | # NewBegFrom="End", NewEndFrom="End", DispBeg=0, DispEnd=60 17 | 18 | HRVData = HandleVerboseArgument(HRVData, verbose) 19 | NewBegFrom = match.arg(NewBegFrom) 20 | NewEndFrom = match.arg(NewEndFrom) 21 | 22 | VerboseMessage(HRVData$Verbose, 23 | c("Creating new episodes from old ones\n", 24 | ifelse(OldTag == "", 25 | "No tag specified: using all old episodes\n", 26 | paste("Using episodes with tag:", OldTag, "\n")), 27 | ifelse(NewTag == "", 28 | "Duplicating old tags", 29 | paste("Creating episodes with tag:", NewTag))) 30 | ) 31 | 32 | if (OldTag == "") { 33 | NewEpisodes = HRVData$Episodes 34 | } else { 35 | NewEpisodes = subset(HRVData$Episodes, HRVData$Episodes$Type == OldTag) 36 | } 37 | 38 | if (NewBegFrom == "Beg") { 39 | BegInstants = NewEpisodes$InitTime + DispBeg 40 | } else { 41 | BegInstants = NewEpisodes$InitTime + NewEpisodes$Duration + DispBeg 42 | } 43 | 44 | if (NewEndFrom == "Beg") { 45 | EndInstants = NewEpisodes$InitTime + DispEnd 46 | } else { 47 | EndInstants = NewEpisodes$InitTime + NewEpisodes$Duration + DispEnd 48 | } 49 | 50 | NewEpisodes$InitTime = BegInstants 51 | NewEpisodes$Duration = EndInstants - BegInstants 52 | if (NewTag != "") { 53 | NewEpisodes$Type = NewTag 54 | } 55 | 56 | VerboseMessage(HRVData$Verbose, 57 | paste("Created", length(NewEpisodes$InitTime), 58 | "episodes from previous ones") 59 | ) 60 | 61 | HRVData$Episodes = rbind(HRVData$Episodes, NewEpisodes) 62 | HRVData$Episodes = HRVData$Episodes[order(HRVData$Episodes$InitTime), ] # Sorts episodes by InitTime 63 | HRVData$Episodes = HRVData$Episodes[!duplicated(HRVData$Episodes), ] # Removes duplicated episodes 64 | 65 | VerboseMessage(HRVData$Verbose, 66 | paste("Number of episodes:", length(HRVData$Episodes$InitTime)) 67 | ) 68 | 69 | return(HRVData) 70 | } 71 | 72 | -------------------------------------------------------------------------------- /R/IntegralCorrelation.R: -------------------------------------------------------------------------------- 1 | IntegralCorrelation <- 2 | function(HRVData, Data, m, tau, r) { 3 | # ------------------------------------- 4 | # Calculates Integral Correlation 5 | # ------------------------------------- 6 | .Deprecated("CalculateSampleEntropy") 7 | 8 | DataExp = BuildTakensVector(HRVData,Data,m=m,tau=tau) 9 | numelem = nrow(DataExp) 10 | 11 | VerboseMessage(HRVData$Verbose, "Calculating Integral Correlation") 12 | 13 | mutualDistance = as.matrix(dist(DataExp,method="maximum")) 14 | Cmr = array(1:numelem) 15 | 16 | 17 | for (i in 1:numelem) { 18 | iDistance = mutualDistance[i, 1:numelem] 19 | Cmr[i] = length(iDistance[iDistance <= r]) / numelem 20 | } 21 | 22 | VerboseMessage(HRVData$Verbose, paste("Integral Correlation:", rhrvFormat(sum(Cmr)))) 23 | return(Cmr) 24 | } 25 | 26 | -------------------------------------------------------------------------------- /R/InterpolateNIHR.R: -------------------------------------------------------------------------------- 1 | InterpolateNIHR <- 2 | function(HRVData, freqhr=4, method= c("linear", "spline"), 3 | verbose=NULL) { 4 | # ------------------------------------- 5 | # Interpolates instantaneous heart rate 6 | # ------------------------------------- 7 | # freqhr -> frequency for interpolating heart rate 8 | # method -> "linear" interpolation or "spline" monotone interpolation 9 | 10 | method = match.arg(method) 11 | HRVData = HandleVerboseArgument(HRVData, verbose) 12 | 13 | VerboseMessage(HRVData$Verbose, 14 | paste("Interpolating instantaneous heart rate")) 15 | VerboseMessage(HRVData$Verbose, 16 | paste("Frequency:", freqhr, "Hz")) 17 | 18 | HRVData$Freq_HR=freqhr 19 | 20 | first = head(HRVData$Beat$Time,1) 21 | last = tail(HRVData$Beat$Time,1) 22 | npoints=as.integer((last-first)*HRVData$Freq_HR+1) 23 | 24 | VerboseMessage(HRVData$Verbose, 25 | paste("Number of beats:", length(HRVData$Beat$niHR))) 26 | VerboseMessage(HRVData$Verbose, 27 | paste("Number of points:", npoints)) 28 | 29 | 30 | if (method == "linear") { 31 | fun = approxfun(HRVData$Beat$Time,HRVData$Beat$niHR, 32 | method = "linear", ties = "ordered") 33 | } else { 34 | fun = splinefun(HRVData$Beat$Time,HRVData$Beat$niHR, 35 | method = "monoH.FC", ties = "ordered") 36 | } 37 | 38 | vectorxint=seq(first,last,1/HRVData$Freq_HR) 39 | 40 | HRVData$HR=fun(vectorxint) 41 | 42 | # limit indicates the maximum width in seconds of an interval without beats 43 | limit = 30 # seconds 44 | # beg and end are the beginning and end of the interval without beats 45 | begindex = which(diff(HRVData$Beat$Time)>limit) 46 | beg = HRVData$Beat$Time[begindex] 47 | end = HRVData$Beat$Time[begindex+1] 48 | 49 | # the value of HR in these intervals is set to zero 50 | if (length(begindex) > 0) { 51 | for (i in 1:length(beg)) { 52 | HRVData$HR[vectorxint>beg[i] & vectorxint record containing beat positions 7 | # RecordPath -> path 8 | # Tag -> tag to include in episodes 9 | 10 | HRVData = HandleVerboseArgument(HRVData, verbose) 11 | 12 | 13 | VerboseMessage(HRVData$Verbose, 14 | paste("Loading apnea episodes for record:", RecordName)) 15 | 16 | 17 | dir=getwd() 18 | on.exit(setwd(dir)) 19 | 20 | VerboseMessage(HRVData$Verbose, paste("Path:", RecordPath)) 21 | 22 | setwd(RecordPath) 23 | 24 | # Reads header, verbose=FALSE 25 | if (is.null(HRVData$datetime)) { 26 | VerboseMessage(HRVData$Verbose, 27 | paste("Reading header info for:", RecordName)) 28 | HRVData = LoadHeaderWFDB(HRVData,RecordName,RecordPath) 29 | } else { 30 | VerboseMessage(HRVData$Verbose, 31 | paste("Header info already present for:",RecordName)) 32 | } 33 | 34 | auxHeader = readLines(paste(RecordName,".hea",sep=""),1) 35 | splitAuxHeader = strsplit(auxHeader," ") 36 | 37 | if(length(splitAuxHeader[[1]])>2) 38 | samplingFrequency = splitAuxHeader[[1]][3] 39 | else 40 | samplingFrequency = "250" 41 | 42 | samplingFrequency = as.numeric(samplingFrequency) 43 | 44 | VerboseMessage(HRVData$Verbose, 45 | paste("Sampling frequency for apnea annotations:", 46 | samplingFrequency)) 47 | 48 | inApnea = FALSE 49 | accumulator = 0 50 | initT = c() 51 | endT = c() 52 | con = file(paste(RecordName,".apn",sep=""),"rb") 53 | repeat { 54 | value = readBin(con,"integer",n=1,size=1,signed=FALSE)+256*readBin(con,"integer",n=1,size=1,signed=FALSE) 55 | 56 | #message(paste("value:",value)) 57 | 58 | code = bitwShiftR(value,10) 59 | #message(paste("code:",code)) 60 | 61 | time = value %% 1024 62 | 63 | #message(paste("time:",time)) 64 | 65 | if(code==0 && time==0) 66 | break 67 | 68 | if (code==8 && !inApnea) { 69 | #message(paste("Onset: ", accumulator)) 70 | inApnea = TRUE 71 | if (accumulator > 30) 72 | initT = c(initT,accumulator-30) 73 | else 74 | initT = c(initT, accumulator) 75 | } 76 | 77 | if (code==1 && inApnea) { 78 | #message(paste("End: ",accumulator)) 79 | inApnea = FALSE 80 | endT = c(endT,accumulator-30) 81 | } 82 | 83 | if (code==59) { 84 | interval = (readBin(con,"integer",n=1,size=1,signed=FALSE)+readBin(con,"integer",n=1,size=1,signed=FALSE)*256)*65536+(readBin(con,"integer",n=1,size=1,signed=FALSE)+readBin(con,"integer",n=1,size=1,signed=FALSE)*256) 85 | accumulator = accumulator + interval/samplingFrequency 86 | next 87 | } 88 | 89 | } 90 | 91 | if (inApnea) { 92 | endT = c(endT,accumulator) 93 | #message(paste("End: ",accumulator)) 94 | } 95 | 96 | close(con) 97 | 98 | if (length(initT) > 0) { 99 | HRVData = AddEpisodes( 100 | HRVData, 101 | InitTimes = initT, 102 | Tags = Tag, 103 | Durations = endT-initT, 104 | Values = 0 105 | ) 106 | } 107 | return(HRVData) 108 | } 109 | 110 | -------------------------------------------------------------------------------- /R/LoadBeat.R: -------------------------------------------------------------------------------- 1 | LoadBeat <- function(fileType, HRVData, Recordname, RecordPath = ".", annotator = "qrs", scale = 1, datetime = "1/1/1900 0:0:0", annotationType = "QRS", verbose = NULL) { 2 | #------------------------------- 3 | # Loads beats from a specific file 4 | #------------------------------- 5 | # fileType -> type of the file 6 | # RecordName -> record containing values 7 | # RecordPath -> path 8 | #------------------------------- 9 | 10 | toret="" 11 | if(fileType == "WFDB") 12 | { 13 | toret = LoadBeatWFDB(HRVData,Recordname,RecordPath,annotator,verbose) 14 | } 15 | else 16 | { 17 | if(fileType == "Ascii") 18 | { 19 | toret = LoadBeatAscii(HRVData, Recordname, RecordPath, scale, datetime, verbose) 20 | } 21 | else 22 | { 23 | if(fileType == "RR") 24 | { 25 | toret = LoadBeatRR(HRVData, Recordname, RecordPath, scale, datetime, verbose) 26 | } 27 | else 28 | { 29 | if(fileType == "Polar") 30 | { 31 | toret = LoadBeatPolar(HRVData, Recordname, RecordPath, verbose) 32 | } 33 | else 34 | { 35 | if(fileType == "Suunto") 36 | { 37 | toret = LoadBeatSuunto(HRVData, Recordname, RecordPath, verbose) 38 | } 39 | else 40 | { 41 | if(fileType == "EDFPlus") 42 | { 43 | toret = LoadBeatEDFPlus(HRVData, Recordname, RecordPath, annotationType, verbose) 44 | } 45 | else 46 | { 47 | if(fileType == "Ambit") 48 | { 49 | toret = LoadBeatAmbit(HRVData, Recordname, RecordPath, verbose) 50 | } 51 | else 52 | { 53 | stop("unknown file type") 54 | } 55 | } 56 | } 57 | } 58 | } 59 | } 60 | } 61 | return(toret) 62 | } 63 | -------------------------------------------------------------------------------- /R/LoadBeatAmbit.R: -------------------------------------------------------------------------------- 1 | LoadBeatAmbit <- function(HRVData, RecordName, RecordPath=".", verbose = NULL) { 2 | #------------------------------- 3 | # Loads beats from a Suunto Ambit XML file 4 | #------------------------------- 5 | # RecordName -> record containing RR values 6 | # RecordPath -> path 7 | #------------------------------- 8 | 9 | dir=getwd() 10 | 11 | HRVData = HandleVerboseArgument(HRVData, verbose) 12 | 13 | 14 | VerboseMessage(HRVData$Verbose, 15 | paste("Loading beats positions for record:", RecordName)) 16 | VerboseMessage(HRVData$Verbose, paste("Path:", RecordPath)) 17 | 18 | 19 | setwd(RecordPath) 20 | 21 | #Date and time information 22 | aux=scan(RecordName,what=character(0),strip.white=TRUE,quiet=TRUE) 23 | date=aux[grepl('DateTime',aux)] 24 | dateAux=substr(date,11,20) 25 | 26 | time <- substr(date,22,29) 27 | 28 | 29 | VerboseMessage(HRVData$Verbose, paste("Date: ", dateAux)) 30 | VerboseMessage(HRVData$Verbose, paste("Time: ", time)) 31 | 32 | datetimeinfo = paste(dateAux,time,sep = " ") 33 | HRVData$datetime=datetimeinfo 34 | 35 | BeatPosition=grep('IBI',aux) 36 | rawIBI=aux[BeatPosition[1]:BeatPosition[2]] 37 | rawIBI[1]=gsub('','',rawIBI[1]) 38 | rawIBI[length(rawIBI)]=gsub('','',rawIBI[length(rawIBI)]) 39 | HRVData$Beat$RR=as.numeric(rawIBI) 40 | 41 | HRVData$Beat$Time=cumsum(HRVData$Beat$RR)/1000 42 | VerboseMessage(HRVData$Verbose, 43 | paste("Number of beats:", length(HRVData$Beat$Time)) 44 | ) 45 | setwd(dir) 46 | return(HRVData) 47 | } 48 | -------------------------------------------------------------------------------- /R/LoadBeatAscii.R: -------------------------------------------------------------------------------- 1 | LoadBeatAscii <- function (HRVData, RecordName, RecordPath=".", scale = 1, starttime=NULL, endtime=NULL, datetime = "1/1/1900 0:0:0", verbose = NULL) { 2 | #------------------------------- 3 | # Loads beats from an ASCII file 4 | #------------------------------- 5 | # RecordName -> file containing values 6 | # RecordPath -> path 7 | #------------------------------- 8 | 9 | HRVData = HandleVerboseArgument(HRVData, verbose) 10 | 11 | VerboseMessage(HRVData$Verbose, 12 | paste("Loading beats positions for record:", RecordName)) 13 | 14 | 15 | if ( (!is.null(starttime) & is.null(endtime) ) | ( is.null(starttime) & !is.null(endtime) ) ) { 16 | stop("Bad specification of starttime and endtime") 17 | } 18 | 19 | if (!is.null(starttime) & !is.null(endtime)) { 20 | if ( (starttime<0) | (endtime<0) | (starttime > endtime) ) { 21 | stop("Bad specification of starttime and endtime") 22 | } 23 | } 24 | 25 | dir = getwd() 26 | on.exit(setwd(dir)) 27 | VerboseMessage(HRVData$Verbose, paste("Path:", RecordPath)) 28 | VerboseMessage(HRVData$Verbose, paste("Scale:", scale)) 29 | 30 | setwd(RecordPath) 31 | 32 | x = read.table(RecordName) 33 | beatsaux = x$V1 34 | beats = beatsaux[!duplicated(beatsaux)] 35 | if (length(beatsaux) != length(beats)) { 36 | VerboseMessage(HRVData$Verbose, 37 | paste("Removed", length(beatsaux) - length(beats), 38 | "duplicated beats") 39 | ) 40 | } 41 | 42 | if (!is.null(starttime)) { 43 | lastbeattime = tail(beats,n=1) 44 | if (endtime > lastbeattime) { 45 | stop("Endtime exceeds record length") 46 | } 47 | beats <- beats[beats>=starttime & beats<=endtime] 48 | VerboseMessage(HRVData$Verbose, paste("Init time:", starttime)) 49 | VerboseMessage(HRVData$Verbose, paste("End time:", endtime)) 50 | } 51 | 52 | datetimeaux = strptime(datetime, "%d/%m/%Y %H:%M:%S") 53 | if (is.na(datetimeaux)) { 54 | stop("Date/time format is dd/mm/yyyy HH:MM:SS") 55 | } 56 | VerboseMessage(HRVData$Verbose, 57 | c(paste("Date: ", 58 | sprintf("%02d", datetimeaux$mday), "/", 59 | sprintf("%02d", 1 + datetimeaux$mon), "/", 60 | 1900 + datetimeaux$year, "\n"), 61 | paste("Time: ", 62 | sprintf("%02d", datetimeaux$hour), ":", 63 | sprintf("%02d", datetimeaux$min), ":", 64 | sprintf("%02d", datetimeaux$sec)) 65 | ) 66 | ) 67 | 68 | HRVData$datetime = datetimeaux 69 | HRVData$Beat = data.frame(Time = beats * scale) 70 | VerboseMessage(HRVData$Verbose, 71 | paste("Number of beats:", length(HRVData$Beat$Time))) 72 | 73 | return(HRVData) 74 | } 75 | -------------------------------------------------------------------------------- /R/LoadBeatPolar.R: -------------------------------------------------------------------------------- 1 | LoadBeatPolar <- function(HRVData, RecordName, RecordPath=".", verbose = NULL) { 2 | #------------------------------- 3 | # Loads beats from an ascii file 4 | #------------------------------- 5 | # RecordName -> record containing RR values 6 | # RecordPath -> path 7 | #------------------------------- 8 | 9 | dir=getwd() 10 | on.exit(setwd(dir)) 11 | 12 | 13 | HRVData = HandleVerboseArgument(HRVData, verbose) 14 | 15 | VerboseMessage(HRVData$Verbose, 16 | paste("Loading beats positions for record:", RecordName)) 17 | VerboseMessage(HRVData$Verbose, paste("Path:", RecordPath)) 18 | 19 | 20 | setwd(RecordPath) 21 | 22 | # Extracts time and date information from file 23 | headerinfo=scan(RecordName,what=character(0),sep="=",skip=4,nlines=2,quiet=TRUE) 24 | 25 | regexpdate="[0-9]{4}[0-9]{2}[0-9]{2}" 26 | if (length(headerinfo[regexpr(regexpdate,headerinfo)==1])) { 27 | dateinfo=headerinfo[regexpr(regexpdate,headerinfo)==1] 28 | } else { 29 | dateinfo="19000101" 30 | } 31 | 32 | regexptime="[0-9]{2}:[0-9]{2}:[0-9]{2}.[0-9]{1}" 33 | if (length(headerinfo[regexpr(regexptime,headerinfo)==1])) { 34 | timeinfo=headerinfo[regexpr(regexptime,headerinfo)==1] 35 | } else { 36 | timeinfo="00:00:00.0" 37 | } 38 | 39 | datetimeinfo = paste(dateinfo,timeinfo) 40 | datetimeaux = strptime(datetimeinfo,"%Y%m%d %H:%M:%S") 41 | 42 | VerboseMessage(HRVData$Verbose, 43 | c(paste0("Date: ", sprintf("%02d", datetimeaux$mday),"/", 44 | sprintf("%02d", 1 + datetimeaux$mon),"/", 45 | 1900 + datetimeaux$year, "\n"), 46 | paste0("Time: ",sprintf("%02d", datetimeaux$hour), ":", 47 | sprintf("%02d", datetimeaux$min), ":", 48 | sprintf("%02.01f", datetimeaux$sec)) 49 | ) 50 | ) 51 | HRVData$datetime = datetimeaux 52 | 53 | aux=scan(RecordName,what=character(0),sep="=",skip=39,quiet=TRUE) 54 | HRVData$Beat$RR=as.numeric(aux[-(1:which(aux=="[HRData]"))]) 55 | 56 | HRVData$Beat$Time=cumsum(HRVData$Beat$RR)/1000 57 | VerboseMessage(HRVData$Verbose, 58 | paste("Number of beats:", length(HRVData$Beat$Time)) 59 | ) 60 | 61 | return(HRVData) 62 | } 63 | -------------------------------------------------------------------------------- /R/LoadBeatRR.R: -------------------------------------------------------------------------------- 1 | LoadBeatRR <- function (HRVData, RecordName, RecordPath=".", scale = 1, datetime = "1/1/1900 0:0:0", verbose = NULL) { 2 | #------------------------------- 3 | # Loads beats from a RR ASCII file 4 | #------------------------------- 5 | # RecordName -> file containing RR values 6 | # RecordPath -> path 7 | #------------------------------- 8 | 9 | HRVData = HandleVerboseArgument(HRVData, verbose) 10 | 11 | VerboseMessage(HRVData$Verbose, 12 | paste("Loading beats positions for record:", RecordName)) 13 | 14 | dir = getwd() 15 | on.exit(setwd(dir)) 16 | 17 | VerboseMessage(HRVData$Verbose, paste("Path:", RecordPath)) 18 | VerboseMessage(HRVData$Verbose, paste("Scale:", scale)) 19 | 20 | setwd(RecordPath) 21 | 22 | x = read.table(RecordName) 23 | beats=cumsum(c(0,x$V1)) 24 | 25 | datetimeaux = strptime(datetime, "%d/%m/%Y %H:%M:%S") 26 | if (is.na(datetimeaux)) { 27 | stop("Date/time format is dd/mm/yyyy HH:MM:SS") 28 | } 29 | VerboseMessage(HRVData$Verbose, 30 | c(paste0("Date: ", sprintf("%02d", datetimeaux$mday), "/", 31 | sprintf("%02d", 1 + datetimeaux$mon), "/", 1900 + 32 | datetimeaux$year, "\n"), 33 | paste0("Time: ", sprintf("%02d", datetimeaux$hour), ":", 34 | sprintf("%02d", datetimeaux$min), ":", 35 | sprintf("%02d", datetimeaux$sec)) 36 | )) 37 | HRVData$datetime = datetimeaux 38 | 39 | HRVData$Beat = data.frame(Time = beats * scale) 40 | VerboseMessage(HRVData$Verbose, 41 | paste("Number of beats:", length(HRVData$Beat$Time))) 42 | 43 | return(HRVData) 44 | } 45 | -------------------------------------------------------------------------------- /R/LoadBeatSuunto.R: -------------------------------------------------------------------------------- 1 | LoadBeatSuunto <- function(HRVData, RecordName, RecordPath=".", verbose = NULL) { 2 | #------------------------------- 3 | # Loads beats from an ascii file 4 | #------------------------------- 5 | # RecordName -> record containing RR values 6 | # RecordPath -> path 7 | #------------------------------- 8 | 9 | dir=getwd() 10 | 11 | HRVData = HandleVerboseArgument(HRVData, verbose) 12 | VerboseMessage(HRVData$Verbose, 13 | paste("Loading beats positions for record:", RecordName)) 14 | VerboseMessage(HRVData$Verbose, paste("Path:", RecordPath)) 15 | 16 | setwd(RecordPath) 17 | 18 | #Date and time information 19 | aux=scan(RecordName,what=character(0),sep="=",quiet=TRUE) 20 | date=aux[which(aux=="STARTTIME")+1] 21 | dateAux = substr(date,1,10) 22 | dateAux = gsub("\\.","-",dateAux) 23 | 24 | time = substr(date,12,19) 25 | time = gsub("\\.",":",time) 26 | 27 | 28 | VerboseMessage(HRVData$Verbose, paste("Date: ",dateAux)) 29 | VerboseMessage(HRVData$Verbose, paste("Time: ",time)) 30 | 31 | datetimeinfo = paste(dateAux,time,sep = " ") 32 | HRVData$datetime=datetimeinfo 33 | 34 | aux=scan(RecordName,what=character(0),sep="=",quiet=TRUE) 35 | HRVData$Beat$RR=as.numeric(aux[-(1:which(aux=="[CUSTOM1]"))]) 36 | 37 | HRVData$Beat$Time=cumsum(HRVData$Beat$RR)/1000 38 | VerboseMessage(HRVData$Verbose, 39 | paste("Number of beats:", length(HRVData$Beat$Time))) 40 | 41 | setwd(dir) 42 | return(HRVData) 43 | } 44 | -------------------------------------------------------------------------------- /R/LoadBeatVector.R: -------------------------------------------------------------------------------- 1 | #' Loads beats positions from an R vector 2 | #' @description Stores the beat positions from an R vector under the 3 | #' \emph{HRVData} data structure. 4 | #' @param HRVData Data structure that stores the beats recording and information 5 | #' related to it 6 | #' @param beatPositions Numeric vector with the heartbeats occurrence's times since 7 | #' the beginning of the recording. See \emph{scale} parameter to specify the 8 | #' units 9 | #' @param scale Numeric value identifying the temporal units in which 10 | #' the beat positions are specified: 1 if beat positions is specified in seconds, 11 | #' 0.001 if beat positions in milliseconds, etc. 12 | #' @param datetime Date and time (DD/MM/YYYY HH:MM:SS) of the beginning of the 13 | #' recording 14 | #' @examples 15 | #' \dontrun{ 16 | #' hd = CreateHRVData() 17 | #' hd = LoadBeatVector(hd, 18 | #' c(0.000, 0.328, 0.715, 0.124, 1.50,1.880, 2.268, 2.656)) 19 | #' hd = BuildNIHR(hd) 20 | #' # ... continue analyzing the recording 21 | #' } 22 | #' @return A \emph{HRVData} structure containing the heartbeat positions 23 | #' from the \emph{beatPositions} vector. 24 | LoadBeatVector <- function(HRVData, beatPositions, scale = 1, 25 | datetime = "1/1/1900 0:0:0"){ 26 | VerboseMessage(HRVData$Verbose, "Loading beats positions") 27 | dir = getwd() 28 | on.exit(setwd(dir)) 29 | VerboseMessage(HRVData$Verbose, paste("Scale:", scale)) 30 | 31 | beatsaux = beatPositions 32 | beatPositions = beatsaux[!duplicated(beatsaux)] 33 | if (length(beatsaux) != length(beatPositions)) { 34 | warning(paste("Removed", length(beatsaux) - length(beatPositions), 35 | "duplicated beat positions")) 36 | } 37 | datetimeaux = strptime(datetime, "%d/%m/%Y %H:%M:%S") 38 | if (is.na(datetimeaux)) { 39 | stop("Date/time format is dd/mm/yyyy HH:MM:SS") 40 | } 41 | VerboseMessage(HRVData$Verbose, 42 | paste("Date: ", sprintf("%02d", datetimeaux$mday), "/", 43 | sprintf("%02d", 1 + datetimeaux$mon), "/", 1900 + 44 | datetimeaux$year, sep = "")) 45 | VerboseMessage(HRVData$Verbose, 46 | paste("Time: ", sprintf("%02d", datetimeaux$hour), ":", 47 | sprintf("%02d", datetimeaux$min), ":", 48 | sprintf("%02d", datetimeaux$sec), sep = "")) 49 | 50 | HRVData$datetime = datetimeaux 51 | HRVData$Beat = data.frame(Time = beatPositions * scale) 52 | VerboseMessage(HRVData$Verbose, 53 | paste("Number of beats:", length(HRVData$Beat$Time))) 54 | 55 | return(HRVData) 56 | } -------------------------------------------------------------------------------- /R/LoadBeatWFDB.R: -------------------------------------------------------------------------------- 1 | LoadBeatWFDB <- function (HRVData, RecordName, RecordPath = ".", annotator = "qrs", verbose = NULL) { 2 | #------------------------------- 3 | # Loads beats from a WFDB file 4 | #------------------------------- 5 | # RecordName -> record containing values 6 | # RecordPath -> path 7 | # annotator -> type of file 8 | #------------------------------- 9 | 10 | samplingFrequency = "" 11 | 12 | HRVData = HandleVerboseArgument(HRVData, verbose) 13 | 14 | VerboseMessage(HRVData$Verbose, 15 | paste("Loading beats positions for record:", RecordName)) 16 | 17 | 18 | dir = getwd() 19 | setwd(RecordPath) 20 | 21 | auxHeader = readLines(paste(RecordName,".hea",sep=""),1) 22 | splitAuxHeader = strsplit(auxHeader," ") 23 | 24 | if(length(splitAuxHeader[[1]])>2) 25 | samplingFrequency = splitAuxHeader[[1]][3] 26 | else 27 | samplingFrequency = "250" 28 | 29 | samplingFrequency = as.numeric(samplingFrequency) 30 | 31 | 32 | #Read binary file 33 | con = file(paste(RecordName,".",annotator,sep=""),"rb") 34 | 35 | counter=1 36 | acumulator=0 37 | beats=c() 38 | repeat 39 | { 40 | value = readBin(con,"integer",n=1,size=2,signed=FALSE) 41 | 42 | code = bitwShiftR(value,10) 43 | time = value %% 1024 44 | 45 | if(code==0 && time==0) 46 | break 47 | else 48 | { 49 | if(code==1) 50 | { 51 | acumulator=acumulator+time 52 | timeInSeconds = acumulator/samplingFrequency 53 | beats=c(beats,timeInSeconds) 54 | counter=counter+1 55 | } 56 | else 57 | { 58 | if(code==63) 59 | { 60 | jump = time%/%2 + time%%2 61 | for(i in 1:jump) 62 | value = readBin(con,"integer",n=1,size=2,signed=FALSE) 63 | } 64 | else 65 | { 66 | if(code==59 && time==0) 67 | { 68 | tmp1 = readBin(con,"integer",n=1,size=2,signed=FALSE) 69 | tmp2 = readBin(con,"integer",n=1,size=2,signed=FALSE) 70 | time = tmp1*(2**16)+tmp2 71 | acumulator=acumulator+time 72 | } 73 | else 74 | if(code!=60 && code!=61 && code!=62 && code!=22 && code!=0) 75 | { 76 | acumulator=acumulator+time 77 | } 78 | } 79 | } 80 | } 81 | } 82 | 83 | beats = unique(beats) 84 | HRVData$Beat = data.frame(Time = beats) 85 | HRVData = LoadHeaderWFDB(HRVData, RecordName, RecordPath=".") 86 | VerboseMessage(HRVData$Verbose, paste("Number of beats:", length(beats))) 87 | 88 | 89 | close(con) 90 | setwd(dir) 91 | return(HRVData) 92 | } 93 | -------------------------------------------------------------------------------- /R/LoadEpisodesAscii.R: -------------------------------------------------------------------------------- 1 | LoadEpisodesAscii <- 2 | function(HRVData, FileName, RecordPath=".", Tag="", InitTime="0:0:0", verbose=NULL, header = TRUE) { 3 | #------------------------------- 4 | # Loads episodes from ascii file 5 | #------------------------------- 6 | # FileName -> file containing episodes 7 | # RecordPath -> path to the file containing episodes 8 | # Tag -> specifies type of episodes 9 | # InitTime -> time (HH:MM:SS) absolute time of beginning of the record (subtracted from time of episodes) 10 | 11 | # Example of file containing episodes: 12 | 13 | # Init_Time Resp_Events Durat SaO2 14 | # 00:33:00 GEN_HYPO 120.0 82.9 15 | # 01:30:00 OBS_APNEA 60.0 81.0 16 | # ... 17 | 18 | # First line of file is discarded if the header argument is set to TRUE 19 | # Duration in seconds 20 | 21 | dir = getwd() 22 | on.exit(setwd(dir)) 23 | setwd(RecordPath) 24 | 25 | HRVData = HandleVerboseArgument(HRVData, verbose) 26 | 27 | 28 | VerboseMessage(HRVData$Verbose, paste("Loading episodes file:", FileName)) 29 | VerboseMessage(HRVData$Verbose, paste("Path:", RecordPath)) 30 | 31 | if (header) { 32 | # skip first line 33 | x = read.table(FileName, skip = 1) 34 | } else{ 35 | # Do not skip the first line, 36 | x = read.table(FileName, skip = 0) 37 | } 38 | 39 | 40 | VerboseMessage(HRVData$Verbose, 41 | ifelse(Tag == "", "No tag specified", paste("Tag:", Tag)) 42 | ) 43 | 44 | # obtaining time 45 | options(digits.secs=3) 46 | timeaux = strptime(InitTime,"%H:%M:%OS") 47 | if (is.na(timeaux)) { 48 | stop("Time format is HH:MM:SS") 49 | } 50 | 51 | VerboseMessage(HRVData$Verbose, 52 | paste0("Initial time: ",sprintf("%02d",timeaux$hour),":", 53 | sprintf("%02d",timeaux$min),":", 54 | sprintf("%02.3f",timeaux$sec)) 55 | ) 56 | 57 | 58 | # calculating time in seconds, considering the initial time for the register 59 | 60 | EpisodeTimeAbs=strptime(x$V1,"%H:%M:%OS") 61 | EpisodeTimeRel=difftime(EpisodeTimeAbs,timeaux, units="secs") 62 | x$V1=as.numeric(EpisodeTimeRel) 63 | 64 | if (Tag=="") { 65 | y=x 66 | } else { 67 | y=subset(x,x$V2==Tag) 68 | } 69 | 70 | added=length(y$V1) 71 | 72 | VerboseMessage(HRVData$Verbose, 73 | ifelse(is.null(y$V4), 74 | "Data does not include values associated to episodes", 75 | "Data includes values associated to episodes") 76 | ) 77 | 78 | if (added==0) { 79 | VerboseMessage(HRVData$Verbose, "No episode was loaded") 80 | } else { 81 | if (is.null(y$V4)) { 82 | HRVData$Episodes=rbind(HRVData$Episodes,data.frame(InitTime=y$V1,Type=y$V2,Duration=y$V3)) 83 | } else { 84 | HRVData$Episodes=rbind(HRVData$Episodes,data.frame(InitTime=y$V1,Type=y$V2,Duration=y$V3,Value=y$V4)) 85 | } 86 | 87 | HRVData$Episodes=HRVData$Episodes[order(HRVData$Episodes$InitTime),] # Sorts episodes by InitTime 88 | HRVData$Episodes=HRVData$Episodes[!duplicated(HRVData$Episodes),] # Removes duplicated episodes 89 | 90 | VerboseMessage(HRVData$Verbose, 91 | paste("Loaded", added, "episodes from file")) 92 | 93 | } 94 | 95 | VerboseMessage(HRVData$Verbose, 96 | paste("Number of episodes:",length(HRVData$Episodes$InitTime)) 97 | ) 98 | 99 | return(HRVData) 100 | } 101 | 102 | -------------------------------------------------------------------------------- /R/LoadHeaderWFDB.R: -------------------------------------------------------------------------------- 1 | LoadHeaderWFDB <- 2 | function(HRVData, RecordName, RecordPath=".", verbose=NULL) { 3 | #------------------------------------ 4 | # Loads header info from an wfdb file 5 | #------------------------------------ 6 | # RecordName -> record containing beat positions 7 | # RecordPath -> path 8 | 9 | HRVData = HandleVerboseArgument(HRVData, verbose) 10 | 11 | dir=getwd() 12 | on.exit(setwd(dir)) 13 | 14 | VerboseMessage(HRVData$Verbose, paste("Path:", RecordPath)) 15 | 16 | setwd(RecordPath) 17 | 18 | # Extracts time and date information from wfdb header 19 | headerfile=paste(RecordName,".hea",sep="") 20 | VerboseMessage(HRVData$Verbose, paste("Opening header file:", headerfile)) 21 | headerinfo=scan(headerfile,what=character(0),nlines=1,quiet=TRUE) 22 | 23 | regexptime="[[:digit:]]{2}:[[:digit:]]{2}:[[:digit:]]{2}" 24 | if (length(headerinfo[regexpr(regexptime,headerinfo)==1])) { 25 | timeinfo=headerinfo[regexpr(regexptime,headerinfo)==1] 26 | VerboseMessage(HRVData$Verbose, 27 | paste("Time information in header:",timeinfo)) 28 | } else { 29 | timeinfo="00:00:00" 30 | VerboseMessage(HRVData$Verbose, 31 | paste("No time information in header:", timeinfo)) 32 | } 33 | 34 | regexpdate="[[:digit:]]{2}/[[:digit:]]{2}/[[:digit:]]{4}" 35 | if (length(headerinfo[regexpr(regexpdate,headerinfo)==1])) { 36 | dateinfo=headerinfo[regexpr(regexpdate,headerinfo)==1] 37 | VerboseMessage(HRVData$Verbose, 38 | paste("Date information in header:",dateinfo)) 39 | } else { 40 | dateinfo="01/01/1900" 41 | VerboseMessage(HRVData$Verbose, 42 | paste("No date information in header:", dateinfo)) 43 | } 44 | 45 | datetimeinfo = paste(dateinfo,timeinfo) 46 | datetimeaux = strptime(datetimeinfo,"%d/%m/%Y %H:%M:%S") 47 | 48 | VerboseMessage(HRVData$Verbose, 49 | paste0("Date: ", sprintf("%02d",datetimeaux$mday), "/", 50 | sprintf("%02d",1 + datetimeaux$mon), "/", 51 | 1900 + datetimeaux$year)) 52 | VerboseMessage(HRVData$Verbose, 53 | paste0("Time: ", sprintf("%02d",datetimeaux$hour),":", 54 | sprintf("%02d",datetimeaux$min),":", 55 | sprintf("%02d",datetimeaux$sec))) 56 | 57 | HRVData$datetime=datetimeaux 58 | 59 | return(HRVData) 60 | 61 | } 62 | 63 | -------------------------------------------------------------------------------- /R/ModifyEpisodes.R: -------------------------------------------------------------------------------- 1 | ModifyEpisodes <- 2 | function(HRVData, Tags=NULL, Indexes=NULL, NewInitTimes=NULL, NewTags=NULL, NewDurations=NULL ,NewValues=NULL) { 3 | #----------------- 4 | # Changes episodes 5 | #----------------- 6 | # Tags -> Vector containing types of episodes to change 7 | # Indexes -> Vector containing indexes of episodes to change 8 | # NewInitTimes -> Vector containing new initial times in seconds 9 | # NewTags -> Vector containing new types of episodes 10 | # NewDurations -> Vector containing new durations in seconds 11 | # NewValues -> Vector containing new numerical values for episodes 12 | 13 | VerboseMessage(HRVData$Verbose, "Modifying episodes") 14 | 15 | if (is.null(NewInitTimes) & is.null(NewTags) & 16 | is.null(NewDurations) & is.null(NewValues)) { 17 | VerboseMessage(HRVData$Verbose, "No change made") 18 | return(HRVData) 19 | } 20 | 21 | HRVData$Episodes <- selectEpisodes(HRVData$Episodes,Tags,Indexes) 22 | 23 | epToMod <- length(HRVData$Episodes$InitTime[HRVData$Episodes$selected]) 24 | 25 | VerboseMessage(HRVData$Verbose, 26 | paste("Number of episodes to modify:",epToMod)) 27 | 28 | if (epToMod == 0) { 29 | HRVData$Episodes$selected <- NULL 30 | return(HRVData) 31 | } 32 | 33 | if (!is.null(NewTags)) { 34 | HRVData$Episodes$Type <- as.character(HRVData$Episodes$Type) 35 | HRVData$Episodes$Type[HRVData$Episodes$selected] <- NewTags 36 | HRVData$Episodes$Type <- factor(HRVData$Episodes$Type) 37 | } 38 | 39 | if (!is.null(NewInitTimes)) { 40 | HRVData$Episodes$InitTime[HRVData$Episodes$selected] <- NewInitTimes 41 | } 42 | 43 | if (!is.null(NewDurations)) { 44 | HRVData$Episodes$Duration[HRVData$Episodes$selected] <- NewDurations 45 | } 46 | 47 | 48 | if (!is.null(NewValues)) { 49 | HRVData$Episodes$Value[HRVData$Episodes$selected] <- NewValues 50 | } 51 | 52 | HRVData$Episodes$selected <- NULL 53 | 54 | HRVData$Episodes <- HRVData$Episodes[order(HRVData$Episodes$InitTime),] # Sort episodes by InitTime 55 | 56 | EpBeforeMod <- length(HRVData$Episodes$InitTime) 57 | HRVData$Episodes <- HRVData$Episodes[!duplicated(HRVData$Episodes),] # Remove duplicated episodes 58 | EpAfterMod <- length(HRVData$Episodes$InitTime) 59 | 60 | if (EpBeforeMod != EpAfterMod) { 61 | VerboseMessage(HRVData$Verbose, 62 | paste("Removing", EpBeforeMod - EpAfterMod, 63 | "duplicated episodes")) 64 | VerboseMessage(HRVData$Verbose, 65 | paste("Number of episodes:", EpAfterMod)) 66 | } 67 | 68 | return(HRVData) 69 | } 70 | 71 | -------------------------------------------------------------------------------- /R/ReadFromFile.R: -------------------------------------------------------------------------------- 1 | ReadFromFile <- 2 | function(name, verbose=FALSE) { 3 | # --------------------------- 4 | # Reads data model from a file 5 | # --------------------------- 6 | 7 | HRVData = CreateHRVData(Verbose = verbose) 8 | nameext = sprintf("%s.%s", name, HRVData$Ext) 9 | 10 | VerboseMessage(HRVData$Verbose, paste("Reading file:",nameext)) 11 | if (!file.exists(nameext)) { 12 | stop("File does not exist!") 13 | } 14 | HRVData = dget(nameext) 15 | VerboseMessage(HRVData$Verbose, 16 | paste(file.info(nameext)$size," bytes read")) 17 | 18 | return(HRVData) 19 | } 20 | 21 | -------------------------------------------------------------------------------- /R/RemoveEpisodes.R: -------------------------------------------------------------------------------- 1 | RemoveEpisodes <- 2 | function(HRVData, Tags=NULL, Indexes=NULL) { 3 | #----------------------------- 4 | # Removes Episodes from record 5 | #----------------------------- 6 | # Tags -> Vector containing types of episodes 7 | # Indexes -> Vector containing indexes of episodes 8 | 9 | 10 | 11 | VerboseMessage(HRVData$Verbose, paste("Removing episodes")) 12 | 13 | 14 | noEpBefore <- length(HRVData$Episodes$InitTime) 15 | VerboseMessage(HRVData$Verbose, 16 | paste("Number of episodes before removal:", noEpBefore)) 17 | 18 | 19 | HRVData$Episodes <- selectEpisodes(HRVData$Episodes,Tags,Indexes) 20 | HRVData$Episodes <- HRVData$Episodes[!HRVData$Episodes$selected,] # Removal happens here 21 | HRVData$Episodes$selected <- NULL 22 | 23 | HRVData$Episodes <- HRVData$Episodes[order(HRVData$Episodes$InitTime),] # Sort episodes by InitTime 24 | 25 | 26 | noEpAfter <- length(HRVData$Episodes$InitTime) 27 | VerboseMessage(HRVData$Verbose, 28 | paste("Number of episodes after removal: ", noEpAfter)) 29 | 30 | 31 | VerboseMessage(HRVData$Verbose, 32 | ifelse(noEpAfter == noEpBefore, 33 | "No episode was removed", 34 | paste("Number of episodes removed:", noEpBefore - noEpAfter)) 35 | ) 36 | 37 | 38 | if (length(HRVData$Episodes$InitTime) == 0) { 39 | HRVData$Episodes <- NULL 40 | VerboseMessage(HRVData$Verbose, "All episodes were removed from data") 41 | } 42 | 43 | return(HRVData) 44 | } 45 | 46 | -------------------------------------------------------------------------------- /R/SetVerbose.R: -------------------------------------------------------------------------------- 1 | SetVerbose <- 2 | function(HRVData,Verbose) { 3 | # --------------------------- 4 | # Sets verbose mode on or off 5 | # --------------------------- 6 | HRVData$Verbose=Verbose 7 | 8 | return(HRVData) 9 | } 10 | 11 | -------------------------------------------------------------------------------- /R/SplitHRbyEpisodes.R: -------------------------------------------------------------------------------- 1 | SplitHRbyEpisodes <- 2 | function(HRVData, Tag="", verbose=NULL) { 3 | # ------------------------------------------------- 4 | # Splits Heart Rate Data using Episodes information 5 | # ------------------------------------------------- 6 | # Tag -> specifies tag of episodes 7 | # Returns a list with two vectors: InEpisodes and OutEpisodes 8 | 9 | HRVData = HandleVerboseArgument(HRVData, verbose) 10 | 11 | VerboseMessage(HRVData$Verbose, 12 | paste("Splitting heart rate signal using episodes")) 13 | 14 | 15 | CheckEpisodes(HRVData) 16 | CheckInterpolation(HRVData) 17 | VerboseMessage(HRVData$Verbose, 18 | ifelse(Tag == "", "No tag was specified", 19 | paste("Using episodes with tag:", Tag))) 20 | 21 | # Select episodes to split signal 22 | if (Tag == "") { 23 | ActiveEpisodes = HRVData$Episodes 24 | } else { 25 | ActiveEpisodes = subset(HRVData$Episodes,HRVData$Episodes$Type==Tag) 26 | } 27 | 28 | VerboseMessage(HRVData$Verbose, 29 | paste("Number of episodes:", length(ActiveEpisodes$InitTime))) 30 | 31 | Beg=ActiveEpisodes$InitTime 32 | End=ActiveEpisodes$InitTime+ActiveEpisodes$Duration 33 | 34 | npoints = length(HRVData$HR) 35 | first = head(HRVData$Beat$Time,1) 36 | last = tail(HRVData$Beat$Time,1) 37 | x=seq(first,last,length.out=npoints) 38 | 39 | # Auxiliary signal used to mark points inside episodes 40 | Aux=rep(0,times=npoints) 41 | for (i in 1:length(Beg)) { 42 | Aux[x>=Beg[i] & x<=End[i]] = 1 43 | } 44 | 45 | l=list(InEpisodes=HRVData$HR[Aux==1],OutEpisodes=HRVData$HR[Aux==0]) 46 | 47 | VerboseMessage(HRVData$Verbose, 48 | paste("Inside episodes:", length(l$InEpisodes),"points")) 49 | VerboseMessage(HRVData$Verbose, 50 | paste("Outside episodes:",length(l$OutEpisodes),"points")) 51 | 52 | return(l) 53 | } 54 | 55 | -------------------------------------------------------------------------------- /R/WriteToFile.R: -------------------------------------------------------------------------------- 1 | WriteToFile <- 2 | function(HRVData, name, overwrite=TRUE, verbose=NULL) { 3 | # --------------------------- 4 | # Writes data model to a file 5 | # --------------------------- 6 | # overwrite: if true, overwrites previously existing file 7 | 8 | HRVData = HandleVerboseArgument(HRVData, verbose) 9 | 10 | nameext=sprintf("%s.%s",name,HRVData$Ext) 11 | 12 | VerboseMessage(HRVData$Verbose, paste("Writing file:",nameext)) 13 | 14 | 15 | if (file.exists(nameext)) { 16 | VerboseMessage(HRVData$Verbose, paste("File", nameext, "already exists")) 17 | if (!overwrite) { 18 | stop("File exists... Not overwriting it!") 19 | } 20 | } 21 | 22 | dput(HRVData,file=nameext) 23 | VerboseMessage(HRVData$Verbose, 24 | paste(file.info(nameext)$size,"bytes written")) 25 | 26 | } 27 | 28 | -------------------------------------------------------------------------------- /R/easyTimeAnalysis.R: -------------------------------------------------------------------------------- 1 | # Creating time analysis data frames 2 | # @importFrom RHRV CreateTimeAnalysis 3 | # @importFrom foreach foreach 4 | # @importFrom foreach %dopar% %do% 5 | easyTimeAnalysis <- 6 | function(format, files, groups, paths, easyOptions, ...) { 7 | # opts <- NULL 8 | # if (easyOptions$verbose) { 9 | # opts <- list("progress" = updateProgressFactory("Time analysis", files)) 10 | # } 11 | dataFrame <- suppressPackageStartupMessages({ 12 | foreach( 13 | file = files, 14 | itcounter = seq_along(files), 15 | group = groups, 16 | path = paths, 17 | .combine = rbind.data.frame, 18 | #.export = c("prepareAnalysis", "easyCall"), 19 | # .packages = "RHRV", 20 | # .options.snow = opts, 21 | .errorhandling = "pass" 22 | ) %dopar% { 23 | hrv.data <- prepareAnalysis(file = file, rrs = path, format = format, 24 | easyOptions = easyOptions) 25 | hrv.data <- easyCall(hrv.data, CreateTimeAnalysis, ...) 26 | results <- hrv.data$TimeAnalysis[[1]] 27 | results$size <- NULL 28 | rowList <- c( 29 | list("file" = file), 30 | list("group" = group), 31 | results 32 | ) 33 | # if (easyOptions$verbose && !easyOptions$parallel) { 34 | # opts$progress(itcounter) 35 | # } 36 | if (easyOptions$verbose) { 37 | message(paste("Time analysis of", file, "done")) 38 | } 39 | as.data.frame(rowList) 40 | } 41 | }) 42 | dataFrame 43 | } 44 | -------------------------------------------------------------------------------- /R/getC.r: -------------------------------------------------------------------------------- 1 | # vector c attached to each node in the modwpt transform (Percival and Walden, page 215) 2 | # vector c will be used to align LA wavelet coefficients 3 | getC=function(j,n) 4 | { 5 | vectorC=c(); 6 | if (j==1) 7 | { 8 | if (n==0) vectorC=0 9 | else vectorC=1 10 | return(vectorC) 11 | 12 | } 13 | else 14 | { 15 | if (((n%%4)==0)||((n%%4)==3)) 16 | return(c(getC(j-1,floor(n/2)),0)) 17 | else 18 | return(c(getC(j-1,floor(n/2)),1)) 19 | } 20 | 21 | } 22 | 23 | # Auxiliary function used to calculate time shifts for wavelets(Percival and walden,229-230) 24 | # This function will return c(Sjn0,Sjn1) 25 | getSc=function(j,n) 26 | { 27 | vectorC=getC(j,n) 28 | Sjn1=(sum(vectorC*2^(0:(j-1)))) 29 | Sjn0=2^j-1-Sjn1 30 | return (c(Sjn0,Sjn1)) 31 | 32 | 33 | } 34 | # Auxiliary function used to calculate time shifts for LA wavelets(Percival and walden,229-230) 35 | getLj=function(j,wf) 36 | { 37 | #length of the wave filter 38 | L=length(wave.filter(wf)$lpf) 39 | Lj=(2^j-1)*(L-1)+1 40 | return(Lj) 41 | } 42 | 43 | #getVjnLA returns time shifts for la8,la16 and la20 wavelets in modwpt 44 | getVjnLA=function(j,n,wf) 45 | { 46 | aux=getSc(j,n); 47 | Sjn1=aux[2]; 48 | return(abs(-getLj(j,wf)/2+(2^(j-1)-Sjn1))) 49 | } 50 | 51 | #performs left circular shift 52 | circularShift=function(x,n) 53 | { 54 | l=length(x) 55 | if ((n==0)||(n==l)) return(x) 56 | if ((n<0)||(n>l)) {n=n%%l} 57 | return(c(x[(n+1):l],x[1:n])) 58 | } 59 | # aligns <> wavelet coefficients from modwpt using <> wavelet. <> are the 60 | # (j.n) node wavelet coefficients. <> should be "l8","l16" or "l20". If not, not 61 | # alignment is perform 62 | align=function(x,j,n,wf) 63 | { 64 | #return(x) 65 | if ((wf!="la8")&&(wf!="la16")&&(wf!="la20")) 66 | { 67 | #general method 68 | return(circularShift(x,CenterOfEnergyAdvances(j,n,wf))) 69 | } 70 | else 71 | { #specific method for LA wavelets 72 | return(circularShift(x,getVjnLA(j,n,wf))) 73 | } 74 | } 75 | 76 | 77 | #shift applicable to (almost) every filter using the notion of the 'center of 78 | #energy' by Hess-Nielsen and Wickerhauser. 79 | # Walden page 231 80 | 81 | # gets the appropiate advance for the (j.n) node of the <> wavelet. 82 | CenterOfEnergyAdvances=function(j,n,wf) 83 | { 84 | #variables for the computation 85 | S=getSc(j,n) 86 | E=CenterEnergies(wf) 87 | advance=round( S[1]*E[1]+S[2]*E[2] ) 88 | 89 | 90 | return (advance) 91 | } 92 | 93 | # gets the center of energy for both wf filters 94 | CenterEnergies=function(wf) 95 | { 96 | waveletFilter=wave.filter(wf) 97 | #Center ofEnergy of the scaling filter 98 | cesf=computeCenterEnergy(waveletFilter$length,waveletFilter$lpf); 99 | #Center ofEnergy of the wavelet filter 100 | cewf=computeCenterEnergy(waveletFilter$length,waveletFilter$hpf); 101 | return (c(cesf,cewf)) 102 | 103 | } 104 | 105 | #auxiliar function: gets the center of energy of coefs. length(coefs)=l 106 | computeCenterEnergy=function(l,coefs){ 107 | auxVector=0:(l-1) 108 | coefs2=(coefs)^2 109 | a=coefs2%*%auxVector 110 | b=sum(coefs2) 111 | return (a/b) 112 | } -------------------------------------------------------------------------------- /R/getError.r: -------------------------------------------------------------------------------- 1 | getError=function(f,interval,type,delta,relative){ 2 | 3 | 4 | if (type=="lower") 5 | { 6 | if (relative){ 7 | error=abs((f-interval[1])/delta)*100 8 | }else{ 9 | error=abs((f-interval[1])) 10 | } 11 | } 12 | else 13 | { if (relative){ 14 | error=abs((f-interval[2])/delta)*100 15 | }else{ 16 | error=abs((f-interval[2])) 17 | } 18 | } 19 | 20 | return(error) 21 | 22 | } -------------------------------------------------------------------------------- /R/getNodes.r: -------------------------------------------------------------------------------- 1 | getNodes=function(lowerf,upperf,sampling,error,relative){ 2 | tol=10^-7 3 | 4 | 5 | if (abs(upperf-lowerf)the level of the node1 must be greater than the level of the node2 53 | if (node1[[1]]>node2[[1]]){ 54 | c1=getC(node1[[1]],node1[[2]]) 55 | c2=getC(node2[[1]],node2[[2]]) 56 | #the parent of node1 at the level of node2 is codified with the first node2[[1]](level of node2) numbers of c1 57 | parentc1=c1[1:length(c2)] 58 | auxBool=prod(c2==parentc1) 59 | ischild=(auxBool==1) 60 | }else{ #node1 is not child of node2 61 | ischild=FALSE 62 | } 63 | return (ischild) 64 | } -------------------------------------------------------------------------------- /R/getNodesAux.r: -------------------------------------------------------------------------------- 1 | 2 | getNodesAux=function(f,sampling,error,type,deltaOriginalInterval,relative) 3 | { # auxliary variables 4 | found=FALSE; 5 | i=1; 6 | n_interval_in=0; 7 | # Iterate until the node is found 8 | while(found==FALSE) 9 | { 10 | bj=n_interval_in 11 | # width of the interval 12 | delta = sampling/(2^(i+1)); 13 | # searching 14 | for (j in (bj*2):(bj*2+1)) 15 | { 16 | interval= c(j*delta,(j+1)*delta); 17 | if (f %rhrv_in% interval) 18 | n_interval_in=j 19 | found = getError(f,interval,type,deltaOriginalInterval,relative)= interval[1] && x <=interval[2]) -------------------------------------------------------------------------------- /R/selectEpisodes.R: -------------------------------------------------------------------------------- 1 | selectEpisodes <- 2 | function(Episodes, Tags, Indexes) { 3 | #----------------------------- 4 | # select Episodes from record 5 | #----------------------------- 6 | # Tags -> Vector containing types of episodes 7 | # Indexes -> Vector containing indexes of episodes 8 | # It adds a new column Episodes$selected 9 | # After using remove the column with HRVData$Episodes$selected <- NULL 10 | 11 | if (!is.null(Tags)) { 12 | if (Tags[1]=="all") { 13 | Episodes$selected <- TRUE 14 | return(Episodes) 15 | } 16 | } 17 | 18 | if (!is.null(Indexes)) { 19 | if (Indexes[1]=="all") { 20 | Episodes$selected <- TRUE 21 | return(Episodes) 22 | } 23 | } 24 | 25 | 26 | Episodes$selected <- FALSE 27 | 28 | if (!is.null(Tags)) { 29 | Tags <- Tags[is.element(Tags,Episodes$Type)] 30 | if (length(Tags) != 0) { 31 | Episodes[is.element(Episodes$Type,Tags),]$selected <- TRUE 32 | } 33 | } 34 | if (!is.null(Indexes)) { 35 | Indexes <- Indexes[Indexes<=length(Episodes$Type)] 36 | if (length(Indexes) != 0) { 37 | Episodes[Indexes,]$selected <- TRUE 38 | } 39 | } 40 | 41 | 42 | 43 | return(Episodes) 44 | } 45 | 46 | -------------------------------------------------------------------------------- /R/stringToIntList.R: -------------------------------------------------------------------------------- 1 | stringToIntList <- function(string) { 2 | #------------------------------- 3 | # convert one string in a list with the numbers in the string 4 | # example: "111 222 333" -> c(111,222,333) 5 | #------------------------------- 6 | 7 | limit = nchar(string) 8 | aux="" 9 | final=c() 10 | for(i in 1:limit) 11 | { 12 | if(substr(string,i,i) == " ") 13 | { 14 | if(nchar(aux) > 0) 15 | { 16 | final=c(final,as.integer(aux)) 17 | aux="" 18 | } 19 | } 20 | else 21 | { 22 | aux = paste(aux,substr(string,i,i),sep="") 23 | } 24 | } 25 | return(final) 26 | } 27 | -------------------------------------------------------------------------------- /R/stringToStringList.R: -------------------------------------------------------------------------------- 1 | stringToStringList <- function(string) { 2 | #------------------------------- 3 | # convert one string in a list with the single strings 4 | # each string is 16 characters long, and trailing whitespaces are removed 5 | # this function is used in LoadBeatEDFPlus 6 | #------------------------------- 7 | 8 | limit = nchar(string) 9 | num=limit/16 10 | final=c() 11 | for (i in 1:num) { 12 | start=(i-1)*16+1 13 | # message(paste("String no.",i,"\n")) 14 | substring = substr(string,start,start+15) 15 | # message(paste(" ..",substring,"..\n",sep="")) 16 | substring2 = gsub(" *$","", substring, perl=T) 17 | # message(paste(" ..",substring2,"..\n",sep="")) 18 | final=c(final,substring2) 19 | } 20 | 21 | return(final) 22 | } 23 | -------------------------------------------------------------------------------- /R/zzz.R: -------------------------------------------------------------------------------- 1 | # Add foreach global variables to avoid R CMD check warnings 2 | utils::globalVariables(c("path", "group", "itcounter", "column", "indexTest")) 3 | -------------------------------------------------------------------------------- /build/vignette.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cran/RHRV/81e6e62185c20ba841ace0e934cbd2eabdf453a3/build/vignette.rds -------------------------------------------------------------------------------- /data/HRVData.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cran/RHRV/81e6e62185c20ba841ace0e934cbd2eabdf453a3/data/HRVData.rda -------------------------------------------------------------------------------- /data/HRVProcessedData.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cran/RHRV/81e6e62185c20ba841ace0e934cbd2eabdf453a3/data/HRVProcessedData.rda -------------------------------------------------------------------------------- /inst/COPYRIGHT: -------------------------------------------------------------------------------- 1 | This R package is copyright A. Mendez, L. Rodriguez-Linares, A. Otero, 2 | C.A. Garcia, X. Vila, M. Lado and I.Garcia with the exception of the 3 | following file: 4 | 5 | *The pmodwpt.c functionality under the src directory file is a based on the 6 | C modwpt function of the waveslim package version 1.6.4, which is copyright 7 | Brandon Whitcher. 8 | -------------------------------------------------------------------------------- /inst/doc/RHRVEasy.R: -------------------------------------------------------------------------------- 1 | ## ----setup, include=FALSE----------------------------------------------------- 2 | knitr::opts_chunk$set(echo = TRUE) 3 | knitr::opts_chunk$set(warning = FALSE, message = FALSE) 4 | 5 | ## ----eval=FALSE--------------------------------------------------------------- 6 | # library("RHRV") 7 | # 8 | # basePath <- "book_data" # adjust as needed 9 | # NSR_DB <- file.path(basePath, "normal") 10 | # CHF_DB <- file.path(basePath, "chf") 11 | # HEALTHY_DB <- file.path(basePath, "healthy") 12 | 13 | ## ----eval=FALSE--------------------------------------------------------------- 14 | # spreadsheetPath <- basePath 15 | 16 | ## ----eval=FALSE, results=FALSE------------------------------------------------ 17 | # easyAnalysis <- RHRVEasy(folders = c(NSR_DB, CHF_DB), nJobs = -1) 18 | 19 | ## ----eval=FALSE--------------------------------------------------------------- 20 | # print(easyAnalysis) 21 | 22 | ## ----eval=FALSE--------------------------------------------------------------- 23 | # # HRVIndices 24 | # head(easyAnalysis$HRVIndices) 25 | 26 | ## ----eval=FALSE--------------------------------------------------------------- 27 | # # Statistical analysis 28 | # head(easyAnalysis$stats) 29 | 30 | ## ----results=FALSE, eval=FALSE------------------------------------------------ 31 | # easyAnalysisWavelet <- RHRVEasy( 32 | # folders = c(NSR_DB, CHF_DB), 33 | # typeAnalysis = 'wavelet', 34 | # n_jobs = -1 35 | # ) 36 | 37 | ## ----eval=FALSE--------------------------------------------------------------- 38 | # easyAnalysisFDR <- RHRVEasyStats(easyAnalysis, correctionMethod = 'fdr') 39 | # pValues <- merge( 40 | # easyAnalysis$stats, 41 | # easyAnalysisFDR$stats, 42 | # by = setdiff(names(easyAnalysis$stats), "adj.p.value"), 43 | # suffixes = c(".bonf", ".fdr") 44 | # ) 45 | # #Let us compare the p-values obtained with different correction methods 46 | # print( 47 | # head( 48 | # pValues[, c("HRVIndex", "p.value", "adj.p.value.bonf", "adj.p.value.fdr")] 49 | # ) 50 | # ) 51 | 52 | ## ----eval=FALSE--------------------------------------------------------------- 53 | # easyAnalysis <- RHRVEasy(folders = c(NSR_DB, CHF_DB), 54 | # saveHRVIndicesInPath = spreadsheetPath) 55 | 56 | ## ----eval=FALSE--------------------------------------------------------------- 57 | # SaveHRVIndices(easyAnalysis, saveHRVIndicesInPath = spreadsheetPath) 58 | 59 | ## ----eval=FALSE--------------------------------------------------------------- 60 | # #Comparison of the three databases 61 | # easyAnalysis3 <- RHRVEasy( 62 | # folders = c(NSR_DB, CHF_DB, HEALTHY_DB), 63 | # nJobs = -1 64 | # ) 65 | # print(easyAnalysis3) 66 | 67 | ## ----eval=FALSE--------------------------------------------------------------- 68 | # print(head(easyAnalysis3$stats)) 69 | 70 | ## ----eval=FALSE--------------------------------------------------------------- 71 | # # Let's print the post-hoc comparisons for "SDNN" 72 | # print(head(easyAnalysis3$stats$pairwise[[1]])) 73 | 74 | ## ----results=FALSE, eval=FALSE------------------------------------------------ 75 | # easyAnalysisOverwritten <- RHRVEasy(folders = c(NSR_DB, CHF_DB), 76 | # freqhr = 2, 77 | # ULFmin = 0, ULFmax = 0.02, 78 | # VLFmin = 0.02, VLFmax = 0.07, 79 | # LFmin = 0.07, LFmax = 0.20, 80 | # HFmin = 0.20, HFmax = 0.5) 81 | 82 | ## ----eval=FALSE--------------------------------------------------------------- 83 | # fullAnalysis <- RHRVEasy( 84 | # folders = c(NSR_DB, CHF_DB, HEALTHY_DB), 85 | # nJobs = -1, 86 | # nonLinear = TRUE, 87 | # doRQA = TRUE, 88 | # saveHRVIndicesInPath = spreadsheetPath 89 | # ) 90 | 91 | -------------------------------------------------------------------------------- /inst/doc/rhrv.index.html: -------------------------------------------------------------------------------- 1 | 2 | R: RHRV vignettes 3 | 4 |

RHRV Vignettes

5 | 8 | 9 |

RHRV Online Documentation

10 | 11 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /man/AddEpisodes.Rd: -------------------------------------------------------------------------------- 1 | \name{AddEpisodes} 2 | \alias{AddEpisodes} 3 | \title{ Adds new episodes manually} 4 | \description{ 5 | Adds information of episodes manually, or annotated physiological events, and stores it into the data structure containing the beat positions 6 | } 7 | \usage{ 8 | AddEpisodes(HRVData, InitTimes, Tags, Durations, Values, verbose=NULL) 9 | } 10 | \arguments{ 11 | \item{HRVData}{ Data structure that stores the beats register and information related to it } 12 | \item{InitTimes}{ Vector containing init times in seconds } 13 | \item{Tags}{ Vector containing types of episodes } 14 | \item{Durations}{ Vector containing durations in seconds } 15 | \item{Values}{ Vector containing numerical values for episodes } 16 | \item{verbose}{ Deprecated argument maintained for compatibility, use SetVerbose() instead } 17 | } 18 | \value{ 19 | Returns HRVData, the structure that contains beat positions register and new episodes information 20 | } 21 | \references{ 22 | L. Rodriguez-Linares, A. Mendez, M. Lado, D. Olivieri, X. Vila, I. Gomez-Conde, "An open source tool for heart rate variability spectral analysis", Computer Methods and Programs in Biomedicine 103, 39-50, doi:10.1016/j.cmpb.2010.05.012 (2011) 23 | } 24 | \author{ 25 | M. Lado, A. Mendez, D. Olivieri, L. Rodriguez, X. Vila 26 | } 27 | \keyword{ misc } 28 | -------------------------------------------------------------------------------- /man/AnalyzeHRbyEpisodes.Rd: -------------------------------------------------------------------------------- 1 | \name{AnalyzeHRbyEpisodes} 2 | \alias{AnalyzeHRbyEpisodes} 3 | \title{ Analyzes Heart Rate using episodes information } 4 | \description{ 5 | Analyzes Heart Rate allowing to evaluate the application of a desired function inside and outside episodes 6 | } 7 | \usage{ 8 | AnalyzeHRbyEpisodes(HRVData, Tag="", func, ..., verbose=NULL) 9 | } 10 | \arguments{ 11 | \item{HRVData}{ Data structure that stores the beats register and information related to it } 12 | \item{Tag}{ Type of episode } 13 | \item{func}{ Function to be applied to Heart Rate Data inside and outside episodes } 14 | \item{...}{optional arguments to func} 15 | \item{verbose}{ Deprecated argument maintained for compatibility, use SetVerbose() instead } 16 | } 17 | \value{ 18 | Returns a list with two objects, that is, the values of the application of the selected function inside and outside episodes 19 | } 20 | \references{ 21 | L. Rodriguez-Linares, A. Mendez, M. Lado, D. Olivieri, X. Vila, I. Gomez-Conde, "An open source tool for heart rate variability spectral analysis", Computer Methods and Programs in Biomedicine 103, 39-50, doi:10.1016/j.cmpb.2010.05.012 (2011) 22 | } 23 | \author{ 24 | M. Lado, A. Mendez, D. Olivieri, L. Rodriguez, X. Vila 25 | } 26 | \seealso{ 27 | \code{\link{SplitHRbyEpisodes}} for splitting in two parts Heart Rate Data using an specific episode type 28 | } 29 | \keyword{ misc } 30 | -------------------------------------------------------------------------------- /man/AnalyzePowerBandsByEpisodes.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/AnalyzePowerBandsByEpisodes.R 3 | \name{AnalyzePowerBandsByEpisodes} 4 | \alias{AnalyzePowerBandsByEpisodes} 5 | \title{Analyze power band by episodes} 6 | \usage{ 7 | AnalyzePowerBandsByEpisodes( 8 | HRVData, 9 | indexFreqAnalysis = length(HRVData$FreqAnalysis), 10 | Tag = "", 11 | verbose = NULL, 12 | func, 13 | ... 14 | ) 15 | } 16 | \arguments{ 17 | \item{HRVData}{Data structure that stores the beats register and information related to it.} 18 | 19 | \item{indexFreqAnalysis}{Integer value denoting which frequency analysis is going to be analyzed using func. Default: 1} 20 | 21 | \item{Tag}{Type of episode} 22 | 23 | \item{verbose}{Deprecated argument maintained for compatibility, use SetVerbose() instead} 24 | 25 | \item{func}{Function to be applied to each power band inside and outside episodes} 26 | 27 | \item{...}{Optional arguments for func.} 28 | } 29 | \value{ 30 | Returns a list with two objects, that is, the values of the application of the selected function 31 | inside ("resultIn") and outside ("resultOut") episodes in the given indexFreqAnalysis. Each of these 32 | list has another set of lists: the "ULF", "VLF", "LF" and "HF" lists. 33 | } 34 | \description{ 35 | Analyzes the ULF, VLF, LF and HF bands from a given indexFreqAnalysis allowing 36 | to evaluate the application of a desired function inside and outside each episode. 37 | } 38 | \examples{ 39 | \dontrun{ 40 | hrv.data = CreateHRVData() 41 | hrv.data = SetVerbose(hrv.data, TRUE) 42 | hrv.data = LoadBeat(hrv.data, fileType = "WFDB", "a03", RecordPath ="beatsFolder/", 43 | annotator = "qrs") 44 | hrv.data = LoadApneaWFDB(hrv.data, RecordName="a03",Tag="Apnea", 45 | RecordPath="beatsFolder/") 46 | hrv.data = BuildNIHR(hrv.data) 47 | hrv.data = InterpolateNIHR (hrv.data, freqhr = 4) 48 | hrv.data = CreateFreqAnalysis(hrv.data) 49 | hrv.data = CalculatePowerBand( hrv.data , indexFreqAnalysis= 1, 50 | type = "wavelet", wavelet = "la8", 51 | bandtolerance = 0.01, relative = FALSE) 52 | results = AnalyzePowerBandsByEpisodes(hrv.data,indexFreqAnalysis=1, 53 | Tag="Apnea",func=mean)} 54 | } 55 | -------------------------------------------------------------------------------- /man/AvgIntegralCorrelation.Rd: -------------------------------------------------------------------------------- 1 | \name{AvgIntegralCorrelation} 2 | \alias{AvgIntegralCorrelation} 3 | \title{ Calculates the average of the Integral Correlations } 4 | \description{ 5 | WARNING: \bold{deprecated} function. 6 | The Integral correlation is calculated for every vector of the m-dimensional space, and then the average of all these values is calculated 7 | } 8 | \usage{ 9 | AvgIntegralCorrelation(HRVData, Data, m, tau, r) 10 | } 11 | \arguments{ 12 | \item{HRVData}{ Data structure that stores the beats register and information related to it } 13 | \item{Data}{ Portion of HRVData to be analyzed } 14 | \item{m}{ Value of the dimension of the expansion of data } 15 | \item{tau}{ Delay of the expansion of data } 16 | \item{r}{ Distance for calculating correlation } 17 | } 18 | \value{ 19 | Returns the value of the average of IntegralCorrelations 20 | } 21 | \references{ 22 | L. Rodriguez-Linares, A. Mendez, M. Lado, D. Olivieri, X. Vila, I. Gomez-Conde, "An open source tool for heart rate variability spectral analysis", Computer Methods and Programs in Biomedicine 103, 39-50, doi:10.1016/j.cmpb.2010.05.012 (2011) 23 | } 24 | \author{ 25 | M. Lado, A. Mendez, D. Olivieri, L. Rodriguez, X. Vila 26 | } 27 | \seealso{ \code{\link{IntegralCorrelation}} } 28 | \keyword{ misc } 29 | 30 | \note{ 31 | This function is used in the \code{\link{CalculateApEn}} function, which is 32 | \bold{deprecated}. We suggest the use of the \code{\link{CalculateSampleEntropy}} 33 | function instead of \code{\link{CalculateApEn}}. 34 | } 35 | -------------------------------------------------------------------------------- /man/BuildNIHR.Rd: -------------------------------------------------------------------------------- 1 | \name{BuildNIHR} 2 | \alias{BuildNIHR} 3 | \title{ Builds the instantaneous heart rate signal from a beat position array } 4 | \description{ 5 | The instantaneous heart rate can be defined as the inverse of the time separation between two consecutive heart beats. Once the beats have been identified, and since the only valid values contributing to the heart rate signal are the corresponding to normal beats preceded by other normal beats, a further operation should be performed for the calculation of the instantaneous heart rate. 6 | } 7 | \usage{ 8 | BuildNIHR(HRVData, verbose=NULL) 9 | } 10 | \arguments{ 11 | \item{HRVData}{ Data structure that stores the beats register and information related to it } 12 | \item{verbose}{ Deprecated argument maintained for compatibility, use SetVerbose() instead } 13 | } 14 | \value{ 15 | Returns HRVData, the structure that contains beat positions register and now associated heart rate instantaneous values also 16 | } 17 | \references{ 18 | L. Rodriguez-Linares, A. Mendez, M. Lado, D. Olivieri, X. Vila, I. Gomez-Conde, "An open source tool for heart rate variability spectral analysis", Computer Methods and Programs in Biomedicine 103, 39-50, doi:10.1016/j.cmpb.2010.05.012 (2011) 19 | } 20 | \author{ 21 | M. Lado, A. Mendez, D. Olivieri, L. Rodriguez, X. Vila 22 | } 23 | \keyword{ misc } 24 | -------------------------------------------------------------------------------- /man/BuildTakens.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/BuildTakensVector.R 3 | \name{BuildTakens} 4 | \alias{BuildTakens} 5 | \title{Build the Takens' vectors} 6 | \usage{ 7 | BuildTakens(HRVData, embeddingDim, timeLag) 8 | } 9 | \arguments{ 10 | \item{HRVData}{Data structure that stores the beats register and information related to it} 11 | 12 | \item{embeddingDim}{Integer denoting the dimension in which we shall embed the RR series.} 13 | 14 | \item{timeLag}{Integer denoting the number of time steps that will be use to construct the 15 | Takens' vectors.} 16 | } 17 | \value{ 18 | A matrix containing the Takens' vectors (one per row). 19 | } 20 | \description{ 21 | This function builds the Takens' vectors of the Non Interpolated RR intervals. 22 | The set of Takens' vectors is the result of embedding the time series in 23 | a m-dimensional space. That is, the \eqn{n^{th}} Takens' vector is defined as 24 | \deqn{T[n]=\{niRR[n], niRR[n+ timeLag],..., niRR[n+m*timeLag]\}.} 25 | Taken's theorem states that we can then reconstruct an equivalent dynamical 26 | system to the original one (the 27 | dynamical system that generated the observed time series) by using the Takens' vectors. 28 | } 29 | \note{ 30 | This function is based on the \code{\link[nonlinearTseries]{buildTakens}} function from the 31 | nonlinearTseries package. 32 | } 33 | \references{ 34 | H. Kantz and T. Schreiber: Nonlinear Time series Analysis (Cambridge university press) 35 | } 36 | -------------------------------------------------------------------------------- /man/BuildTakensVector.Rd: -------------------------------------------------------------------------------- 1 | \name{BuildTakensVector} 2 | \alias{BuildTakensVector} 3 | \title{ Calculates Takens expanded vectors } 4 | \description{ 5 | WARNING: \bold{deprecated} function. 6 | In order to calculate de Fractal Dimension and Approximate Entropy (or others properties of the data) a representation of the data in a space m-dimensional is needed 7 | } 8 | \usage{ 9 | BuildTakensVector(HRVData, Data, m, tau) 10 | } 11 | \arguments{ 12 | \item{HRVData}{ Data structure that stores the beats register and information related to it } 13 | \item{Data}{ Portion of HRVData to be analyzed } 14 | \item{m}{ Value of the dimension of the expansion of data } 15 | \item{tau}{ Delay of the expansion of data } 16 | } 17 | \value{ 18 | Returns a matrix with the Expanded Data with N-(m-1)*tau rows (N is the length of the Data to be analyzed) and m columns 19 | } 20 | \references{ 21 | L. Rodriguez-Linares, A. Mendez, M. Lado, D. Olivieri, X. Vila, I. Gomez-Conde, "An open source tool for heart rate variability spectral analysis", Computer Methods and Programs in Biomedicine 103, 39-50, doi:10.1016/j.cmpb.2010.05.012 (2011) 22 | } 23 | \author{ 24 | M. Lado, A. Mendez, D. Olivieri, L. Rodriguez, X. Vila 25 | } 26 | \keyword{ misc } 27 | 28 | \note{ 29 | This function is \bold{deprecated}. Please use \code{\link{BuildTakens}} instead. 30 | } 31 | -------------------------------------------------------------------------------- /man/CalculateApEn.Rd: -------------------------------------------------------------------------------- 1 | \name{CalculateApEn} 2 | \alias{CalculateApEn} 3 | \title{ Calculates Approximate Entropy } 4 | \description{ 5 | WARNING: \bold{deprecated} function. 6 | Calculates Approximate Entropy as indicated by Pincus 7 | } 8 | \usage{ 9 | CalculateApEn(HRVData, 10 | indexNonLinearAnalysis = length(HRVData$NonLinearAnalysis), 11 | m = 2, tau = 1, 12 | r = 0.2, N = 1000, verbose=NULL) 13 | } 14 | \arguments{ 15 | \item{HRVData}{ Data structure that stores the beats register and information 16 | related to it } 17 | \item{indexNonLinearAnalysis}{ Reference to the data structure that will 18 | contain the non linear analysis } 19 | \item{m}{ Value of the dimension of the expansion of data } 20 | \item{tau}{ Delay of the expansion of data } 21 | \item{r}{ Distance for calculating correlation } 22 | \item{N}{ Number of points of the portion of signal to be analyzed } 23 | \item{verbose}{ Deprecated argument maintained for compatibility, use 24 | SetVerbose() instead } 25 | } 26 | \value{ 27 | Returns HRVData, the structure that contains beat positions register and now 28 | associated heart rate instantaneous values also, including the value of the 29 | Approximate Entropy 30 | } 31 | \references{ 32 | L. Rodriguez-Linares, A. Mendez, M. Lado, D. Olivieri, X. Vila, I. Gomez-Conde, "An open source tool for heart rate variability spectral analysis", Computer Methods and Programs in Biomedicine 103, 39-50, doi:10.1016/j.cmpb.2010.05.012 (2011) 33 | S. M. Pincus, "Approximate entropy as a measure of system complexity," 34 | Mathematics 88, 2297-2301 (1991) 35 | } 36 | \author{ 37 | M. Lado, A. Mendez, D. Olivieri, L. Rodriguez, X. Vila 38 | } 39 | \seealso{ 40 | \code{\link{BuildTakensVector}} for expand data \cr 41 | \code{\link{IntegralCorrelation}} for correlation calculations \cr 42 | \code{\link{AvgIntegralCorrelation}} for averaging correlation calculations\cr 43 | } 44 | \keyword{ misc } 45 | \note{ 46 | This function is \bold{deprecated}. We suggest the use of the 47 | \code{\link{CalculateSampleEntropy}} function instead, which is faster. 48 | } 49 | -------------------------------------------------------------------------------- /man/CalculateEmbeddingDim.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/CalculateNonLinearParameters.R 3 | \name{CalculateEmbeddingDim} 4 | \alias{CalculateEmbeddingDim} 5 | \title{Estimate the proper embedding dimension for the RR time series} 6 | \usage{ 7 | CalculateEmbeddingDim( 8 | HRVData, 9 | numberPoints = 5000, 10 | timeLag = 1, 11 | maxEmbeddingDim = 15, 12 | threshold = 0.95, 13 | maxRelativeChange = 0.05, 14 | doPlot = TRUE 15 | ) 16 | } 17 | \arguments{ 18 | \item{HRVData}{Data structure that stores the beats register and information related to it} 19 | 20 | \item{numberPoints}{Number of points from the time series that will be used to estimate 21 | the embedding dimension. By default, 5000 points are used.} 22 | 23 | \item{timeLag}{Time lag used to build the Takens' vectors needed to estimate the 24 | embedding dimension (see \link[nonlinearTseries]{buildTakens}). Default: 1.} 25 | 26 | \item{maxEmbeddingDim}{Maximum possible embedding dimension for the time series. Default: 15.} 27 | 28 | \item{threshold}{Numerical value between 0 and 1. The embedding dimension is 29 | estimated using the E1(d) function. E1(d) stops changing when d is greater 30 | than or equal to embedding dimension, staying close to 1. This value 31 | establishes a threshold for considering that E1(d) is close to 1. 32 | Default: 0.95} 33 | 34 | \item{maxRelativeChange}{Maximum relative change in E1(d) with respect to 35 | E1(d-1) in order to consider that the E1 function has been stabilized and it 36 | will stop changing. Default: 0.05.} 37 | 38 | \item{doPlot}{Logical value. If TRUE (default value), a plot of E1(d) and E2(d) is shown.} 39 | } 40 | \description{ 41 | This function determines the minimum embedding dimension from a scalar time 42 | series using the algorithm proposed by L. Cao (see references). 43 | } 44 | \details{ 45 | The Cao's algorithm uses 2 functions in order to estimate the embedding dimension 46 | from a time series: the E1(d) and the E2(d) functions, where d denotes the dimension. 47 | 48 | E1(d) stops changing when d is greater than or equal to the embedding dimension, staying close to 1. 49 | On the other hand, E2(d) is used to distinguish deterministic signals from stochastic signals. For 50 | deterministic signals, there exists some d such that E2(d)!=1. For stochastic signals, 51 | E2(d) is approximately 1 for all the values. 52 | } 53 | \note{ 54 | The current implementation of this function is fully written in R, based on the 55 | \code{\link[nonlinearTseries]{estimateEmbeddingDim}} function from the 56 | nonlinearTseries package. Thus it requires 57 | heavy computations and may be quite slow. The \emph{numberPoints} parameter can be used 58 | for controlling the computational burden. 59 | 60 | Future versions of the package will solve this issue. 61 | } 62 | \examples{ 63 | \dontrun{ 64 | data(HRVProcessedData) 65 | HRVData = HRVProcessedData 66 | HRVData = SetVerbose(HRVData,T) 67 | timeLag = CalculateTimeLag(HRVData,technique = "ami") 68 | embeddingDim = CalculateEmbeddingDim(HRVData, 69 | timeLag = timeLag, 70 | maxEmbeddingDim = 15) 71 | } 72 | } 73 | \references{ 74 | Cao, L. Practical method for determining the minimum embedding dimension of a scalar time series. Physica D: Nonlinear Phenomena, 75 | 110,1, pp. 43-50 (1997). 76 | } 77 | \seealso{ 78 | \code{\link[nonlinearTseries]{estimateEmbeddingDim}}. 79 | } 80 | -------------------------------------------------------------------------------- /man/CalculateEnergyInPSDBands.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/StationaryFrequencyAnalysis.R 3 | \name{CalculateEnergyInPSDBands} 4 | \alias{CalculateEnergyInPSDBands} 5 | \title{CalculateSPDBandsEnergy} 6 | \usage{ 7 | CalculateEnergyInPSDBands( 8 | HRVData, 9 | indexFreqAnalysis = length(HRVData$FreqAnalysis), 10 | ULFmin = 0, 11 | ULFmax = 0.03, 12 | VLFmin = 0.03, 13 | VLFmax = 0.05, 14 | LFmin = 0.05, 15 | LFmax = 0.15, 16 | HFmin = 0.15, 17 | HFmax = 0.4 18 | ) 19 | } 20 | \arguments{ 21 | \item{HRVData}{Data structure that stores the beats register and information 22 | related to it.} 23 | 24 | \item{indexFreqAnalysis}{An integer referencing the data structure that contains 25 | the PSD analysis.} 26 | 27 | \item{ULFmin}{Lower limit ULF band used for distinguish the ULF band.} 28 | 29 | \item{ULFmax}{Upper limit ULF band used for distinguish the ULF band.} 30 | 31 | \item{VLFmin}{Lower limit VLF band.} 32 | 33 | \item{VLFmax}{Upper limit VLF band.} 34 | 35 | \item{LFmin}{Lower limit LF band.} 36 | 37 | \item{LFmax}{Upper limit LF band.} 38 | 39 | \item{HFmin}{Lower limit HF band.} 40 | 41 | \item{HFmax}{Upper limit HF band.} 42 | } 43 | \value{ 44 | A vector containing the energy of the ULF, VLF, LF and HF bands in the 45 | PSD. 46 | } 47 | \description{ 48 | Calculates the Energy in the bands of the Power Spectral Density 49 | (PSD). 50 | } 51 | \examples{ 52 | \dontrun{ 53 | data(HRVData) 54 | HRVData=BuildNIHR(HRVData) 55 | HRVData=FilterNIHR(HRVData) 56 | # Frequency analysis requires interpolated data (except Lomb) 57 | HRVData=InterpolateNIHR(HRVData) 58 | HRVData=CreateFreqAnalysis(HRVData) 59 | HRVData=CalculatePSD(HRVData,1,"pgram",doPlot = F) 60 | # get Energy in the default ULF, VLF and LF frequency bands. 61 | # We modify the limits for the HF band 62 | CalculateEnergyInPSDBands(HRVData, 1, HFmin = 0.15, HFmax = 0.3) 63 | } 64 | } 65 | \seealso{ 66 | \code{\link{PlotPSD}}, \code{\link{CalculatePSD}}. 67 | } 68 | -------------------------------------------------------------------------------- /man/CalculateFracDim.Rd: -------------------------------------------------------------------------------- 1 | \name{CalculateFracDim} 2 | \alias{CalculateFracDim} 3 | \title{ Calculates Fractal Dimension } 4 | \description{ 5 | WARNING: \bold{deprecated} function. 6 | Calculates Fractal Dimension as indicated by Pincus 7 | } 8 | \usage{ 9 | CalculateFracDim(HRVData, indexNonLinearAnalysis = length(HRVData$NonLinearAnalysis), 10 | m = 10, tau = 3, Cra = 0.005, Crb = 0.75, N = 1000, verbose=NULL) 11 | } 12 | \arguments{ 13 | \item{HRVData}{ Data structure that stores the beats register and information related to it } 14 | \item{indexNonLinearAnalysis}{ Reference to the data structure that will contain the non linear analysis } 15 | \item{m}{ Value of the dimension of the expansion of data } 16 | \item{tau}{ Delay of the expansion of data } 17 | \item{Cra}{ Minimum value of correlation for calculating Fractal Dimension } 18 | \item{Crb}{ Maximum value of correlation for calculating Fractal Dimension } 19 | \item{N}{ Number of points of the portion of signal to be analyzed } 20 | \item{verbose}{ Deprecated argument maintained for compatibility, use SetVerbose() instead } 21 | } 22 | \value{ 23 | Returns HRVData, the structure that contains beat positions register and now associated heart rate instantaneous values also, including the value of the Fractal Dimension 24 | } 25 | \references{ 26 | L. Rodriguez-Linares, A. Mendez, M. Lado, D. Olivieri, X. Vila, I. Gomez-Conde, "An open source tool for heart rate variability spectral analysis", Computer Methods and Programs in Biomedicine 103, 39-50, doi:10.1016/j.cmpb.2010.05.012 (2011) 27 | S. M. Pincus, "Approximate entropy as a measure of system complexity," Mathematics 88, 2297-2301 (1991) 28 | } 29 | \author{ 30 | M. Lado, A. Mendez, D. Olivieri, L. Rodriguez, X. Vila 31 | } 32 | \seealso{ 33 | \code{\link{CalculateRfromCorrelation}} for finding r distance at which the correlation has a certain value 34 | } 35 | \keyword{ misc } 36 | \note{ 37 | This function is \bold{deprecated}. We suggest the use of the 38 | \code{\link{CalculateCorrDim}} function instead, which is faster. 39 | } 40 | -------------------------------------------------------------------------------- /man/CalculatePSD.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/StationaryFrequencyAnalysis.R 3 | \name{CalculatePSD} 4 | \alias{CalculatePSD} 5 | \title{Spectral Density Estimation} 6 | \usage{ 7 | CalculatePSD( 8 | HRVData, 9 | indexFreqAnalysis = length(HRVData$FreqAnalysis), 10 | method = c("pgram", "ar", "lomb"), 11 | doPlot = T, 12 | ... 13 | ) 14 | } 15 | \arguments{ 16 | \item{HRVData}{Data structure that stores the beats register and information 17 | related to it.} 18 | 19 | \item{indexFreqAnalysis}{An integer referencing the data structure that will contain 20 | the frequency analysis.} 21 | 22 | \item{method}{String specifying the method used to estimate the spectral 23 | density. Allowed methods are "pgram" (the default), "ar" and "lomb".} 24 | 25 | \item{doPlot}{Plot the periodogram?} 26 | 27 | \item{...}{Further arguments to specific PSD estimation methods or 28 | \code{\link[RHRV]{PlotPSD}}.} 29 | } 30 | \value{ 31 | The \emph{CalculatePSD} returns the \emph{HRVData} structure 32 | containing a \emph{periodogram} field storing and PSD estimation 33 | of the RR time series. When the "pgram" and "ar" methods are used the 34 | \emph{periodogram} field is an object of class "spec". If "lomb" is used, 35 | the \emph{periodogram} field is just a list. In any case the 36 | \emph{periodogram} field will contain: 37 | \itemize{ 38 | \item{freq: vector of frequencies at which the spectral density is estimated.} 39 | \item{spec: spectral density estimation } 40 | \item{series: name of the series} 41 | \item{method: method used to calculate the spectrum} 42 | } 43 | } 44 | \description{ 45 | Estimate the Power Spectral Density (PSD) of the RR time series. 46 | } 47 | \details{ 48 | The "pgram" and "ar" methods use the \code{\link[stats]{spec.pgram}} 49 | and \code{\link[stats]{spec.ar}} functions. Thus, the same arguments used 50 | in \code{\link[stats]{spec.pgram}} or \code{\link[stats]{spec.ar}} 51 | can be used when method is "pgram" or "ar", respectively. 52 | The "lomb" is based in the \code{\link[lomb]{lsp}} and thus it accepts the 53 | same parameters as this function. 54 | } 55 | \examples{ 56 | \dontrun{ 57 | data(HRVData) 58 | HRVData=BuildNIHR(HRVData) 59 | HRVData=FilterNIHR(HRVData) 60 | # Frequency analysis requires interpolated data (except Lomb) 61 | HRVData=InterpolateNIHR(HRVData) 62 | # Create a different freqAnalysis for each method 63 | HRVData=CreateFreqAnalysis(HRVData) 64 | HRVData=CalculatePSD(HRVData,1,"pgram",doPlot = F) 65 | 66 | HRVData=CreateFreqAnalysis(HRVData) 67 | HRVData=CalculatePSD(HRVData,2,"pgram",spans=9, doPlot = F) 68 | 69 | HRVData=CreateFreqAnalysis(HRVData) 70 | HRVData=CalculatePSD(HRVData,3,"ar",doPlot = F) 71 | 72 | HRVData=CreateFreqAnalysis(HRVData) 73 | HRVData=CalculatePSD(HRVData,4,"lomb",doPlot = F) 74 | # Plot the results 75 | layout(matrix(c(1,2,3,4), 2, 2, byrow = TRUE)) 76 | PlotPSD(HRVData,1) 77 | PlotPSD(HRVData,2) 78 | PlotPSD(HRVData,3) 79 | PlotPSD(HRVData,4) 80 | } 81 | } 82 | \seealso{ 83 | \code{\link[stats]{spectrum}}, \code{\link[RHRV]{PlotPSD}}. 84 | } 85 | -------------------------------------------------------------------------------- /man/CalculateRfromCorrelation.Rd: -------------------------------------------------------------------------------- 1 | \name{CalculateRfromCorrelation} 2 | \alias{CalculateRfromCorrelation} 3 | \title{ Calculates ra and rb from Correlation } 4 | \description{ 5 | WARNING: \bold{deprecated} function. 6 | Calculates ra and rb distances that verify that their correlation values are Cra and Crb 7 | } 8 | \usage{ 9 | CalculateRfromCorrelation(HRVData, Data, m, tau, Cra, Crb) 10 | } 11 | \arguments{ 12 | \item{HRVData}{ Data structure that stores the beats register and information related to it } 13 | \item{Data}{ Portion of HRVData to be analyzed } 14 | \item{m}{ Value of the dimension of the expansion of data } 15 | \item{tau}{ Delay of the expansion of data } 16 | \item{Cra}{ Minimum value of correlation for calculating Fractal Dimension } 17 | \item{Crb}{ Maximum value of correlation for calculating Fractal Dimension } 18 | } 19 | \value{ 20 | Returns a 2 by 2 matrix containing ra and rb distance in the first row and their exact correlation values in the second row 21 | } 22 | \references{ 23 | L. Rodriguez-Linares, L., A.J. Mendez, M.J. Lado, D.N. Olivieri, X.A. Vila, and I. Gomez-Conde, "An open source tool for heart rate variability spectral analysis", Computer Methods and Programs in Biomedicine 103(1):39-50, july 2011. 24 | S. M. Pincus, "Approximate entropy as a measure of system complexity," Mathematics 88, 2297-2301 (1991) 25 | } 26 | \author{ 27 | M. Lado, A. Mendez, D. Olivieri, L. Rodriguez, X. Vila 28 | } 29 | \seealso{ 30 | \code{\link{CalculateFracDim}} 31 | } 32 | \keyword{ misc } 33 | 34 | 35 | \note{ 36 | This function is used in the \code{\link{CalculateFracDim}} function, which is 37 | \bold{deprecated}. We suggest the use of the \code{\link{CalculateCorrDim}} function 38 | instead of \code{\link{CalculateFracDim}}. 39 | } -------------------------------------------------------------------------------- /man/CalculateSampleEntropy.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/CalculateSampleEntropy.R 3 | \name{CalculateSampleEntropy} 4 | \alias{CalculateSampleEntropy} 5 | \alias{EstimateSampleEntropy} 6 | \alias{PlotSampleEntropy} 7 | \title{Sample Entropy (also known as Kolgomorov-Sinai Entropy)} 8 | \usage{ 9 | CalculateSampleEntropy( 10 | HRVData, 11 | indexNonLinearAnalysis = length(HRVData$NonLinearAnalysis), 12 | doPlot = TRUE 13 | ) 14 | 15 | EstimateSampleEntropy( 16 | HRVData, 17 | indexNonLinearAnalysis = length(HRVData$NonLinearAnalysis), 18 | regressionRange = NULL, 19 | useEmbeddings = NULL, 20 | doPlot = TRUE 21 | ) 22 | 23 | PlotSampleEntropy( 24 | HRVData, 25 | indexNonLinearAnalysis = length(HRVData$NonLinearAnalysis), 26 | ... 27 | ) 28 | } 29 | \arguments{ 30 | \item{HRVData}{Data structure that stores the beats register and information related to it} 31 | 32 | \item{indexNonLinearAnalysis}{Reference to the data structure that will contain the nonlinear analysis} 33 | 34 | \item{doPlot}{Logical value. If TRUE (default), a plot of the correlation sum is shown} 35 | 36 | \item{regressionRange}{Vector with 2 components denoting the range where the function will perform linear regression} 37 | 38 | \item{useEmbeddings}{A numeric vector specifying which embedding dimensions should the algorithm use to compute 39 | the sample entropy.} 40 | 41 | \item{...}{Additional plot parameters.} 42 | } 43 | \value{ 44 | The \emph{CalculateSampleEntropy} returns a HRVData structure containing the sample entropy computations of the 45 | RR time series under the \emph{NonLinearAnalysis} list. 46 | 47 | The \emph{EstimateSampleEntropy} function estimates the sample entropy of the 48 | RR time series by performing a linear regression 49 | over the radius' range specified in \emph{regressionRange}. If \emph{doPlot} is TRUE, 50 | a graphic of the regression over the data is shown. In order to run \emph{EstimateSampleEntropy}, it 51 | is necessary to have performed the sample entropy computations before with \emph{ComputeSampleEntropy}. The 52 | results are returned into the \emph{HRVData} structure, under the \emph{NonLinearAnalysis} list. 53 | 54 | \emph{PlotSampleEntropy} shows a graphic of the sample entropy computations. 55 | } 56 | \description{ 57 | These functions measure the complexity of the RR time series. Large values of 58 | the Sample Entropy indicate high complexity whereas that smaller values characterize 59 | more regular signals. 60 | } 61 | \details{ 62 | The sample entropy is computed using: 63 | \deqn{h_q(m,r) = log(C_q(m,r)/C_{q}(m+1,r))}{hq(m,r) = log(Cq(m,r)/Cq(m+1,r)),} 64 | where \emph{m} is the embedding dimension and \emph{r} is the radius of the neighbourhood. When 65 | computing the correlation dimensions we use the linear regions from the correlation 66 | sums in order to do the estimates. Similarly, the sample entropy \eqn{h_q(m,r)}{hq(m,r)} 67 | should not change for both various \emph{m} and \emph{r}. 68 | } 69 | \note{ 70 | In order to run this functions, it is necessary to have used the \emph{CalculateCorrDim} function. 71 | 72 | This function is based on the \code{\link[nonlinearTseries]{sampleEntropy}} function from the 73 | nonlinearTseries package. 74 | } 75 | \examples{ 76 | \dontrun{ 77 | # ... 78 | hrv.data = CreateNonLinearAnalysis(hrv.data) 79 | hrv.data = CalculateCorrDim(hrv.data,indexNonLinearAnalysis=1,minEmbeddingDim=2, 80 | maxEmbeddingDim=8,timeLag=1,minRadius=1,maxRadius=15, 81 | pointsRadius=20,theilerWindow=10,corrOrder=2,doPlot=FALSE) 82 | hrv.data = CalculateSampleEntropy(hrv.data,indexNonLinearAnalysis=1,doPlot=FALSE) 83 | PlotSampleEntropy(hrv.data,indexNonLinearAnalysis=1) 84 | hrv.data = EstimateSampleEntropy(hrv.data,indexNonLinearAnalysis=1,regressionRange=c(6,10)) 85 | } 86 | } 87 | \references{ 88 | H. Kantz and T. Schreiber: Nonlinear Time series Analysis (Cambridge university press) 89 | } 90 | \seealso{ 91 | \code{\link[nonlinearTseries]{sampleEntropy}} 92 | } 93 | -------------------------------------------------------------------------------- /man/CalculateSpectrogram.Rd: -------------------------------------------------------------------------------- 1 | \name{CalculateSpectrogram} 2 | \alias{CalculateSpectrogram} 3 | \title{ Calculates the spectrogram of a signal } 4 | \description{ 5 | Calculates the spectrogram of the heart rate signal after filtering and 6 | interpolation in a window of a certain size 7 | } 8 | \usage{ 9 | CalculateSpectrogram(HRVData, size, shift, sizesp = 1024, verbose=NULL) 10 | } 11 | \arguments{ 12 | \item{HRVData}{ Data structure that stores the beats register and information 13 | related to it } 14 | \item{size}{ Size of window for calculating spectrogram (seconds) } 15 | \item{shift}{ Displacement of window for calculating spectrogram (seconds) } 16 | \item{sizesp}{ Points for calculating spectrogram (zero padding) } 17 | \item{verbose}{ Deprecated argument maintained for compatibility, use 18 | SetVerbose() instead } 19 | } 20 | \value{ 21 | Returns the spectrogram of the heart rate signal 22 | } 23 | \references{ 24 | L. Rodriguez-Linares, A. Mendez, M. Lado, D. Olivieri, X. Vila, I. Gomez-Conde, "An open source tool for heart rate variability spectral analysis", Computer Methods and Programs in Biomedicine 103, 39-50, doi:10.1016/j.cmpb.2010.05.012 (2011) 25 | } 26 | \author{ 27 | M. Lado, A. Mendez, D. Olivieri, L. Rodriguez, X. Vila 28 | } 29 | 30 | \note{ 31 | An example including all the necessary steps to obtain the spectrogram\cr 32 | of a wfdb register is giving below:\cr 33 | 34 | ##Reading a wfdb register and storing into a data structure:\cr 35 | md = CreateHRVData(Verbose = TRUE)\cr 36 | md = LoadBeatWFDB(md, RecordName = "register_name", \cr 37 | RecordPath = "register_path", verbose = TRUE)\cr 38 | 39 | ##Calculating heart rate signal:\cr 40 | md = BuildNIHR(md)\cr 41 | 42 | ##Filtering heart rate signal:\cr 43 | md = FilterNIHR(md)\cr 44 | 45 | ##Interpolating heart rate signal:\cr 46 | md = InterpolateNIHR(md)\cr 47 | 48 | ##Calculating spectrogram:\cr 49 | CalculateSpectrogram(md, size = 120, shift = 10, sizesp = 1024)\cr 50 | } 51 | \keyword{ misc } 52 | 53 | -------------------------------------------------------------------------------- /man/CreateFreqAnalysis.Rd: -------------------------------------------------------------------------------- 1 | \name{CreateFreqAnalysis} 2 | \alias{CreateFreqAnalysis} 3 | \title{ Creates data analysis structure for frequency analysis calculations } 4 | \description{ 5 | Creates data analysis structure that stores the information extracted from a variability analysis of heart rate signal and joins it to HRVData as a member of a list 6 | } 7 | \usage{ 8 | CreateFreqAnalysis(HRVData, verbose=NULL) 9 | } 10 | \arguments{ 11 | \item{HRVData}{ Data structure that stores the beats register and information related to it } 12 | \item{verbose}{ Deprecated argument maintained for compatibility, use SetVerbose() instead } 13 | } 14 | \value{ 15 | Returns HRVData, the structure that contains beat positions register, associated heart rate instantaneous values, filtered heart rate signal equally spaced, and a new analysis structure as a member of a list 16 | } 17 | \references{ 18 | L. Rodriguez-Linares, A. Mendez, M. Lado, D. Olivieri, X. Vila, I. Gomez-Conde, "An open source tool for heart rate variability spectral analysis", Computer Methods and Programs in Biomedicine 103, 39-50, doi:10.1016/j.cmpb.2010.05.012 (2011) 19 | } 20 | \author{ 21 | M. Lado, A. Mendez, D. Olivieri, L. Rodriguez, X. Vila 22 | } 23 | \seealso{ \code{\link{CreateHRVData}} } 24 | \keyword{ misc } 25 | -------------------------------------------------------------------------------- /man/CreateHRVData.Rd: -------------------------------------------------------------------------------- 1 | \name{CreateHRVData} 2 | \alias{CreateHRVData} 3 | \title{ Creates data structure for all the calculations } 4 | \description{ 5 | Creates data structure that stores the beats register and all the information obtained from it 6 | } 7 | \usage{ 8 | CreateHRVData(Verbose = FALSE) 9 | } 10 | \arguments{ 11 | \item{Verbose}{ Boolean argument that allows to specify if the function returns additional information } 12 | } 13 | \value{ 14 | Returns HRVData, the structure that will contain beat positions register, associated heart rate instantaneous values, filtered heart rate signal equally spaced, and one or more analysis structures 15 | } 16 | \references{ 17 | L. Rodriguez-Linares, A. Mendez, M. Lado, D. Olivieri, X. Vila, I. Gomez-Conde, "An open source tool for heart rate variability spectral analysis", Computer Methods and Programs in Biomedicine 103, 39-50, doi:10.1016/j.cmpb.2010.05.012 (2011) 18 | } 19 | \author{ 20 | M. Lado, A. Mendez, D. Olivieri, L. Rodriguez, X. Vila 21 | } 22 | \seealso{ \code{\link{CreateFreqAnalysis}}, \code{\link{CreateTimeAnalysis}}, \code{\link{CreateNonLinearAnalysis}} } 23 | \keyword{ misc } 24 | 25 | -------------------------------------------------------------------------------- /man/CreateNonLinearAnalysis.Rd: -------------------------------------------------------------------------------- 1 | \name{CreateNonLinearAnalysis} 2 | \alias{CreateNonLinearAnalysis} 3 | \title{ Creates data analysis structure for non linear analysis calculations } 4 | \description{ 5 | Creates data analysis structure that stores the information extracted from a non linear analysis of ECG signal and joins it to HRVData as a member of a list} 6 | \usage{ 7 | CreateNonLinearAnalysis(HRVData, verbose=NULL) 8 | } 9 | \arguments{ 10 | \item{HRVData}{ Data structure that stores the beats register and information related to it } 11 | \item{verbose}{ Deprecated argument maintained for compatibility, use SetVerbose() instead } 12 | } 13 | \value{ 14 | Returns HRVData, the structure that contains beat positions register, associated heart rate instantaneous values, filtered heart rate signal equally spaced, and a new analysis structure as a member of a list 15 | } 16 | \references{ 17 | L. Rodriguez-Linares, A. Mendez, M. Lado, D. Olivieri, X. Vila, I. Gomez-Conde, "An open source tool for heart rate variability spectral analysis", Computer Methods and Programs in Biomedicine 103, 39-50, doi:10.1016/j.cmpb.2010.05.012 (2011) 18 | } 19 | \author{ 20 | M. Lado, A. Mendez, D. Olivieri, L. Rodriguez, X. Vila 21 | } 22 | \seealso{ \code{\link{CreateHRVData}} } 23 | \keyword{ misc } 24 | -------------------------------------------------------------------------------- /man/CreateTimeAnalysis.Rd: -------------------------------------------------------------------------------- 1 | \name{CreateTimeAnalysis} 2 | \alias{CreateTimeAnalysis} 3 | \title{ Creates data analysis structure for time analysis calculations } 4 | \description{ 5 | Creates data analysis structure that stores the information extracted from a time analysis of ECG signal and joins it to HRVData as a member of a list} 6 | \usage{ 7 | CreateTimeAnalysis(HRVData, size=300, numofbins=NULL, interval=7.8125, verbose=NULL ) 8 | } 9 | \arguments{ 10 | \item{HRVData}{ Data structure that stores the beats register and information related to it } 11 | \item{size}{ Size of window (seconds) } 12 | \item{numofbins}{ Number of bins in histogram. If it is not specified, the interval parameter is used (default)} 13 | \item{interval}{ Width of bins in histogram (milliseconds)} 14 | \item{verbose}{ Deprecated argument maintained for compatibility, use SetVerbose() instead } 15 | } 16 | \value{ 17 | Returns HRVData, the structure that contains beat positions register, associated heart rate instantaneous values, filtered heart rate signal equally spaced, and a new analysis structure as a member of a list 18 | } 19 | \references{ 20 | L. Rodriguez-Linares, A. Mendez, M. Lado, D. Olivieri, X. Vila, I. Gomez-Conde, "An open source tool for heart rate variability spectral analysis", Computer Methods and Programs in Biomedicine 103, 39-50, doi:10.1016/j.cmpb.2010.05.012 (2011) 21 | } 22 | \author{ 23 | M. Lado, A. Mendez, D. Olivieri, L. Rodriguez, X. Vila 24 | } 25 | \seealso{ \code{\link{CreateHRVData}} } 26 | \keyword{ misc } 27 | -------------------------------------------------------------------------------- /man/EditNIHR.Rd: -------------------------------------------------------------------------------- 1 | \name{EditNIHR} 2 | \alias{EditNIHR} 3 | \title{ Manually edition of non-interpolated instantaneous heart rate } 4 | \description{ 5 | Plots non-interpolated instantaneous heart rate for manual removing of outliers 6 | } 7 | \usage{ 8 | EditNIHR(HRVData, scale = 1, verbose=NULL) 9 | } 10 | \arguments{ 11 | \item{HRVData}{ Data structure that stores the beats register and information related to it } 12 | \item{scale}{ Allows scaling for small screens } 13 | \item{verbose}{ Deprecated argument maintained for compatibility, use SetVerbose() instead } 14 | } 15 | \value{ 16 | Returns Data, the structure that contains beat positions register, and manually edited associated heart rate instantaneous values 17 | } 18 | \references{ 19 | L. Rodriguez-Linares, A. Mendez, M. Lado, D. Olivieri, X. Vila, I. Gomez-Conde, "An open source tool for heart rate variability spectral analysis", Computer Methods and Programs in Biomedicine 103, 39-50, doi:10.1016/j.cmpb.2010.05.012 (2011) 20 | } 21 | \author{ 22 | M. Lado, A. Mendez, D. Olivieri, L. Rodriguez, X. Vila 23 | } 24 | \keyword{ iplot } 25 | -------------------------------------------------------------------------------- /man/EstimatePSDSlope.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/StationaryFrequencyAnalysis.R 3 | \name{EstimatePSDSlope} 4 | \alias{EstimatePSDSlope} 5 | \title{Estimate the slope of the Power Spectral Density (PSD).} 6 | \usage{ 7 | EstimatePSDSlope( 8 | HRVData, 9 | indexFreqAnalysis = length(HRVData$FreqAnalysis), 10 | indexNonLinearAnalysis = length(HRVData$NonLinearAnalysis), 11 | regressionRange = NULL, 12 | doPlot = T, 13 | main = "PSD power law", 14 | xlab = "Frequency (Hz)", 15 | ylab = "Spectrum", 16 | pch = NULL, 17 | log = "xy", 18 | ... 19 | ) 20 | } 21 | \arguments{ 22 | \item{HRVData}{Data structure that stores the beats register and information 23 | related to it.} 24 | 25 | \item{indexFreqAnalysis}{An integer referencing the periodogram that will be 26 | used for estimating the spectral index.} 27 | 28 | \item{indexNonLinearAnalysis}{An integer referencing the structure that will 29 | store the resulting estimations.} 30 | 31 | \item{regressionRange}{Range of frequencies in which the regression will be 32 | performed. Default is c(1e-4, 1e-2) Hz.} 33 | 34 | \item{doPlot}{Plot the periodogram and the least-squares fit?} 35 | 36 | \item{main}{Title for the plot.} 37 | 38 | \item{xlab}{Title for the x axis.} 39 | 40 | \item{ylab}{Title for the y axis.} 41 | 42 | \item{pch}{Symbol for the plotting points.} 43 | 44 | \item{log}{A character string which contains "x" if the x axis is to be 45 | logarithmic, "y" if the y axis is to be logarithmic and "xy" or "yx" if 46 | both axes are to be logarithmic (default).} 47 | 48 | \item{...}{Other arguments for the plotting function.} 49 | } 50 | \value{ 51 | The \emph{EstimatePSDSlope} returns the \emph{HRVData} structure 52 | containing a \emph{PSDSlope} field storing the spectral index and the 53 | proper Hurst exponent. 54 | } 55 | \description{ 56 | Estimate the slope of the Power Spectral Density (PSD) of the 57 | RR time series. 58 | } 59 | \details{ 60 | The power spectrum of most physiological signals fulfils 61 | \eqn{S(f)=Cf^{-\beta}}{S(f)=C*f^-B} (1/f spectrum). This function estimates 62 | the \eqn{\beta}{B} exponent, which is usually referred to as the spectral 63 | index. 64 | } 65 | \note{ 66 | It should be noted that the PSD must be estimated prior to the 67 | use of this function. We do not recommend the use of the AR spectrum when 68 | estimating the spectral index. 69 | } 70 | \examples{ 71 | \dontrun{ 72 | data(HRVProcessedData) 73 | # use other name for convenience 74 | HRVData=HRVProcessedData 75 | # Estimate the periodogram 76 | HRVData=CreateFreqAnalysis(HRVData) 77 | HRVData=CalculatePSD(HRVData,1,"pgram",doPlot = T,log="xy") 78 | HRVData=CreateNonLinearAnalysis(HRVData) 79 | HRVData=SetVerbose(HRVData,T) 80 | HRVData=EstimatePSDSlope(HRVData,1,1, 81 | regressionRange=c(5e-4,1e-2)) 82 | } 83 | } 84 | \references{ 85 | Voss, Andreas, et al. "Methods derived from nonlinear dynamics 86 | for analysing heart rate variability." Philosophical Transactions of the 87 | Royal Society A: Mathematical, Physical and Engineering Sciences 367.1887 88 | (2009): 277-296. 89 | 90 | Eke, A., Herman, P., Kocsis, L., & Kozak, L. R. (2002). Fractal 91 | characterization of complexity in temporal physiological signals. 92 | Physiological measurement, 23(1), R1. 93 | } 94 | \seealso{ 95 | \code{\link[stats]{spectrum}},\code{\link[lomb]{lsp}}, 96 | \code{\link[RHRV]{CalculatePSD}}. 97 | } 98 | -------------------------------------------------------------------------------- /man/ExtractTimeSegment.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ExtractTimeSegment.R 3 | \name{ExtractTimeSegment} 4 | \alias{ExtractTimeSegment} 5 | \title{Time windows of HR record} 6 | \usage{ 7 | ExtractTimeSegment(HRVData, starttime, endtime) 8 | } 9 | \arguments{ 10 | \item{HRVData}{Data structure that stores the beats register and information 11 | related to it. This function calls \emph{Window} to perform the extraction.} 12 | 13 | \item{starttime}{The start time of the period of interest.} 14 | 15 | \item{endtime}{The end time of the period of interest.} 16 | } 17 | \value{ 18 | A new \emph{HRVData} structure containing the temporal data 19 | within the specified range. 20 | } 21 | \description{ 22 | Extracts a temporal subset between the times starttime and endtime. 23 | } 24 | \details{ 25 | If the \emph{HRVData} contains episodes, beats or RR time series, 26 | these will be also extracted into the new HRV structure. On the other hand, 27 | all the analysis stored in the original structure will be lost. 28 | } 29 | \examples{ 30 | \dontrun{ 31 | data(HRVProcessedData) 32 | # Rename for convenience 33 | HRVData <- HRVProcessedData 34 | PlotNIHR(HRVData) 35 | newHRVData <- ExtractTimeSegment(HRVData,2000,4000) 36 | PlotNIHR(newHRVData) 37 | } 38 | } 39 | \author{ 40 | Leandro Rodriguez-Linares 41 | } 42 | -------------------------------------------------------------------------------- /man/FilterNIHR.Rd: -------------------------------------------------------------------------------- 1 | \name{FilterNIHR} 2 | \alias{FilterNIHR} 3 | \title{ Artefact filter based in an adaptive threshold } 4 | \description{ 5 | An algorithm that uses adaptive thresholds for rejecting those beats different from the given threshold more than a certain value. The rule for beat acceptation or rejection is to compare with previous, following and with the updated mean. We apply also a comparison with acceptable physiological values (default values 25 and 200 bpm). 6 | } 7 | \usage{ 8 | FilterNIHR(HRVData, long=50, last=13, minbpm=25, maxbpm=200, mini=NULL, 9 | maxi=NULL, fixed=NULL, verbose=NULL) 10 | } 11 | \arguments{ 12 | \item{HRVData}{ Data structure that stores the beats register and information related to it } 13 | \item{long}{ Number of beats to calculate the updated mean } 14 | \item{last}{ Initial threshold } 15 | \item{minbpm}{ Minimum physiologically acceptable value for HR } 16 | \item{maxbpm}{ Maximum physiologically acceptable value for HR } 17 | \item{mini}{ Deprecated argument maintained for compatibility } 18 | \item{maxi}{ Deprecated argument maintained for compatibility } 19 | \item{fixed}{ Deprecated argument maintained for compatibility } 20 | \item{verbose}{ Deprecated argument maintained for compatibility, use SetVerbose() instead } 21 | } 22 | \value{ 23 | Returns HRVData, the structure that contains beat positions register, associated heart rate instantaneous values also, and now filtered heart rate signal 24 | } 25 | \references{ 26 | X. Vila, F. Palacios, J. Presedo, M. Fernandez-Delgado, P. Felix, S. Barro, "Time-Frequency analysis of heart-rate variability," IEEE Eng. Med. Biol. Magazine 16, 119-125 (1997) 27 | L. Rodriguez-Linares, A. Mendez, M. Lado, D. Olivieri, X. Vila, I. Gomez-Conde, "An open source tool for heart rate variability spectral analysis", Computer Methods and Programs in Biomedicine 103, 39-50, doi:10.1016/j.cmpb.2010.05.012 (2011) 28 | } 29 | \author{ 30 | M. Lado, A. Mendez, D. Olivieri, L. Rodriguez, X. Vila 31 | } 32 | \keyword{ misc } 33 | -------------------------------------------------------------------------------- /man/GenerateEpisodes.Rd: -------------------------------------------------------------------------------- 1 | \name{GenerateEpisodes} 2 | \alias{GenerateEpisodes} 3 | \title{ Creates new episodes from old ones } 4 | \description{ 5 | Creates new episodes, or annotated physiological events, from existing ones and stores them into the data structure containing the beat positions 6 | } 7 | \usage{ 8 | GenerateEpisodes(HRVData, NewBegFrom, NewEndFrom, DispBeg, DispEnd, 9 | OldTag = "", NewTag = "", verbose=NULL) 10 | } 11 | \arguments{ 12 | \item{HRVData}{ Data structure that stores the beats register and information related to it } 13 | \item{NewBegFrom}{ Source of new beginning of episodes ("Beg" for indicating the beginning as the beginning of the old episode, "End" for end)} 14 | \item{NewEndFrom}{ Source of new end of episodes ("Beg" for indicating the end as the beginning of the old episode, "End" for end)} 15 | \item{DispBeg}{ Absolute displacement from the beginning for new episodes in seconds } 16 | \item{DispEnd}{ Absolute displacement from the end for new episodes in seconds } 17 | \item{OldTag}{ Tag of old episodes } 18 | \item{NewTag}{ Tag for new episodes (if empty, copies OldTag) } 19 | \item{verbose}{ Deprecated argument maintained for compatibility, use SetVerbose() instead } 20 | } 21 | \value{ 22 | Returns HRVData, the structure that contains beat positions register and new episodes information 23 | } 24 | \references{ 25 | L. Rodriguez-Linares, A. Mendez, M. Lado, D. Olivieri, X. Vila, I. Gomez-Conde, "An open source tool for heart rate variability spectral analysis", Computer Methods and Programs in Biomedicine 103, 39-50, doi:10.1016/j.cmpb.2010.05.012 (2011) 26 | } 27 | \author{ 28 | M. Lado, A. Mendez, D. Olivieri, L. Rodriguez, X. Vila 29 | } 30 | \note{ 31 | ##Example of arguments for creating episodes displaced one \cr 32 | minute before old ones:\cr 33 | ##NewBegFrom = "Beg", NewEndFrom = "End", DispBeg = -60, \cr 34 | DispEnd = -60\cr 35 | ##Example of arguments for creating episodes just after previous\cr 36 | ones of 1 minute length:\cr 37 | ##NewBegFrom = "End", NewEndFrom = "End", DispBeg = 0, \cr 38 | DispEnd = 60\cr 39 | } 40 | \keyword{ misc } 41 | -------------------------------------------------------------------------------- /man/HRVData.Rd: -------------------------------------------------------------------------------- 1 | \name{HRVData} 2 | \docType{data} 3 | \alias{HRVData} 4 | \title{HRVData} 5 | \description{ 6 | HRVData structure containing the occurrence times of the hearbeats of patient suffering from 7 | paraplegia and hypertension. The subject from whom the HR was obtained is a patient suffering 8 | from paraplegia and hypertension (systolic blood pressure above 200 mmHg). During 9 | the recording, he is supplied with prostaglandin E1 (a vasodilator that is rarely 10 | employed) and systolic blood pressure fell to 100 mmHg for over an hour. Then, the 11 | blood pressure was slowly recovering until 150 mmHg, more or less 12 | } 13 | \usage{data(HRVData)} 14 | \format{A HRVData structure containing the occurrence times of the heartbeats} 15 | \seealso{\link{HRVProcessedData}} 16 | \keyword{datasets} 17 | -------------------------------------------------------------------------------- /man/HRVProcessedData.Rd: -------------------------------------------------------------------------------- 1 | \name{HRVProcessedData} 2 | \docType{data} 3 | \alias{HRVProcessedData} 4 | \title{HRVProcessedData} 5 | \description{ 6 | HRV data containing the heart rhythm of patient suffering from 7 | paraplegia and hypertension. The subject from whom the HR was obtained is a patient suffering 8 | from paraplegia and hypertension (systolic blood pressure above 200 mmHg). During 9 | the recording, he is supplied with prostaglandin E1 (a vasodilator that is rarely 10 | employed) and systolic blood pressure fell to 100 mmHg for over an hour. Then, the 11 | blood pressure was slowly recovering until 150 mmHg, more or less} 12 | \usage{data(HRVProcessedData)} 13 | \format{A HRVData structure containing the interpolated and filtered HR series} 14 | \seealso{\link{HRVData}} 15 | \keyword{datasets} 16 | -------------------------------------------------------------------------------- /man/IntegralCorrelation.Rd: -------------------------------------------------------------------------------- 1 | \name{IntegralCorrelation} 2 | \alias{IntegralCorrelation} 3 | \title{ Calculates the Integral Correlation } 4 | \description{ 5 | WARNING: \bold{deprecated} function. 6 | The Integral correlation is calculated for every vector of the m-dimensional space 7 | } 8 | \usage{ 9 | IntegralCorrelation(HRVData, Data, m, tau, r) 10 | } 11 | \arguments{ 12 | \item{HRVData}{ Data structure that stores the beats register and information related to it } 13 | \item{Data}{ Portion of HRVData to be analyzed } 14 | \item{m}{ Value of the dimension of the expansion of data } 15 | \item{tau}{ Delay of the expansion of data } 16 | \item{r}{ Distance for calculating correlation } 17 | } 18 | \value{ 19 | Returns the value of the average of IntegralCorrelations 20 | } 21 | \references{ 22 | L. Rodriguez-Linares, A. Mendez, M. Lado, D. Olivieri, X. Vila, I. Gomez-Conde, "An open source tool for heart rate variability spectral analysis", Computer Methods and Programs in Biomedicine 103, 39-50, doi:10.1016/j.cmpb.2010.05.012 (2011) 23 | } 24 | \author{ 25 | M. Lado, A. Mendez, D. Olivieri, L. Rodriguez, X. Vila 26 | } 27 | \seealso{ \code{\link{BuildTakensVector}} } 28 | \keyword{ misc } 29 | \note{ 30 | This function is used in the \code{\link{CalculateApEn}} function, which is 31 | \bold{deprecated}. We suggest the use of the \code{\link{CalculateSampleEntropy}} 32 | function instead of \code{\link{CalculateApEn}}. 33 | } -------------------------------------------------------------------------------- /man/InterpolateNIHR.Rd: -------------------------------------------------------------------------------- 1 | \name{InterpolateNIHR} 2 | \alias{InterpolateNIHR} 3 | \title{ Linear or Spline interpolator for build the sample heart rate signal } 4 | \description{ 5 | An algorithm to obtain a heart rate signal with equally spaced values at a certain sampling frequency 6 | } 7 | \usage{ 8 | InterpolateNIHR(HRVData, freqhr = 4, method = c("linear", "spline"), verbose=NULL) 9 | } 10 | \arguments{ 11 | \item{HRVData}{ Data structure that stores the beats register and information related to it } 12 | \item{freqhr}{ Sampling frequency } 13 | \item{method}{ "linear" interpolation or "spline" monotone interpolation } 14 | \item{verbose}{ Deprecated argument maintained for compatibility, use SetVerbose() instead } 15 | } 16 | \value{ 17 | Returns HRVData, the structure that contains beat positions register, associated heart rate instantaneous values also, and filtered heart rate signal equally spaced 18 | } 19 | \references{ 20 | L. Rodriguez-Linares, A. Mendez, M. Lado, D. Olivieri, X. Vila, I. Gomez-Conde, "An open source tool for heart rate variability spectral analysis", Computer Methods and Programs in Biomedicine 103, 39-50, doi:10.1016/j.cmpb.2010.05.012 (2011) 21 | } 22 | \author{ 23 | M. Lado, A. Mendez, D. Olivieri, L. Rodriguez, X. Vila 24 | } 25 | \keyword{ misc } 26 | -------------------------------------------------------------------------------- /man/ListEpisodes.Rd: -------------------------------------------------------------------------------- 1 | \name{ListEpisodes} 2 | \alias{ListEpisodes} 3 | \title{ Episodes listing } 4 | \description{ 5 | Lists episodes included in a RHRV record 6 | } 7 | \usage{ 8 | ListEpisodes(HRVData, TimeHMS = FALSE) 9 | } 10 | \arguments{ 11 | \item{HRVData}{ Data structure that stores the beats register and information related to it } 12 | \item{TimeHMS}{ Boolean argument to print times in H:M:S format } 13 | } 14 | \references{ 15 | L. Rodriguez-Linares, A. Mendez, M. Lado, D. Olivieri, X. Vila, I. Gomez-Conde, "An open source tool for heart rate variability spectral analysis", Computer Methods and Programs in Biomedicine 103, 39-50, doi:10.1016/j.cmpb.2010.05.012 (2011) 16 | } 17 | \author{ 18 | M. Lado, A. Mendez, D. Olivieri, L. Rodriguez, X. Vila 19 | } 20 | \keyword{ Episodes } 21 | \keyword{ Tags } 22 | -------------------------------------------------------------------------------- /man/LoadApneaWFDB.Rd: -------------------------------------------------------------------------------- 1 | \name{LoadApneaWFDB} 2 | \alias{LoadApneaWFDB} 3 | \title{ Loads apnea episodes for WFDB record } 4 | \description{ 5 | Loads the information of apnea episodes and stores it into the data structure containing the beat positions and other related information 6 | } 7 | \usage{ 8 | LoadApneaWFDB(HRVData, RecordName, RecordPath = ".", Tag = "APNEA", 9 | verbose=NULL) 10 | } 11 | \arguments{ 12 | \item{HRVData}{ Data structure that stores the beats register and information related to it } 13 | \item{RecordName}{ The WFDB file to be used } 14 | \item{RecordPath}{ The path of the WFDB file } 15 | \item{Tag}{ to include APNEA episodes } 16 | \item{verbose}{ Deprecated argument maintained for compatibility, use SetVerbose() instead } 17 | } 18 | \value{ 19 | Returns HRVData, the structure that contains beat positions register and other related information and apnea episodes information 20 | } 21 | \note{ 22 | An example including all the steps to download a record from Physionet and load its content and the Apnea annotations is included below:\cr\cr 23 | dirorig <- "http://www.physionet.org/physiobank/database/apnea-ecg/"\cr 24 | files <- c("a01.hea", "a01.apn", "a01.qrs")\cr 25 | filesorig <- paste(dirorig, files, sep = "")\cr 26 | for (i in 1:length(files))\cr 27 | download.file(filesorig[i], files[i])\cr 28 | hrv.data <- CreateHRVData()\cr 29 | hrv.data <- LoadBeatWFDB(hrv.data, "a01")\cr 30 | hrv.data <- LoadApneaWFDB(hrv.data, "a01")\cr 31 | } 32 | \references{ 33 | L. Rodriguez-Linares, A. Mendez, M. Lado, D. Olivieri, X. Vila, I. Gomez-Conde, "An open source tool for heart rate variability spectral analysis", Computer Methods and Programs in Biomedicine 103, 39-50, doi:10.1016/j.cmpb.2010.05.012 (2011) 34 | } 35 | \author{ 36 | M. Lado, A. Mendez, D. Olivieri, L. Rodriguez, X. Vila 37 | } 38 | \keyword{ IO } 39 | \keyword{ connection } 40 | -------------------------------------------------------------------------------- /man/LoadBeat.Rd: -------------------------------------------------------------------------------- 1 | \name{LoadBeat} 2 | \alias{LoadBeat} 3 | \title{ Builds an array of beats positions from different type of files } 4 | \description{ 5 | Reads the specific file with data of beat positions and stores the values in a data structure 6 | } 7 | \usage{ 8 | LoadBeat(fileType, HRVData, Recordname, RecordPath = ".", 9 | annotator = "qrs", scale = 1, datetime = "1/1/1900 0:0:0", 10 | annotationType = "QRS", verbose = NULL) 11 | } 12 | \arguments{ 13 | \item{fileType}{ The format of the file to be used: WFDB, Ascii, RR, Polar, Suunto, EDFPlus, Ambit } 14 | \item{HRVData}{ Data structure that stores the beats register and information related to it } 15 | \item{Recordname}{ The file to be used } 16 | \item{RecordPath}{ The path of the file } 17 | \item{annotator}{ The extension of the file, only if we are working with a WFDB file } 18 | \item{scale}{ 1 if beat positions in seconds or 0.001 if beat positions in milliseconds, only if we are working with a RR or an Ascii file } 19 | \item{datetime}{ Date and time (DD/MM/YYYY HH:MM:SS), only if we are working with a RR or an Ascii file } 20 | \item{annotationType}{ The type of annotation wished, only if we are working with an EDF+ file } 21 | \item{verbose}{ Deprecated argument maintained for compatibility, use SetVerbose() instead } 22 | } 23 | \value{ 24 | Returns HRVData, the structure that contains beat positions register 25 | } 26 | \references{ 27 | L. Rodriguez-Linares, L., A.J. Mendez, M.J. Lado, D.N. Olivieri, X.A. Vila, and I. Gomez-Conde, "An open source tool for heart rate variability spectral analysis", Computer Methods and Programs in Biomedicine 103(1):39-50, july 2011. 28 | } 29 | \author{ 30 | I. Garcia 31 | } 32 | \keyword{ IO } 33 | \keyword{ connection } 34 | -------------------------------------------------------------------------------- /man/LoadBeatAmbit.Rd: -------------------------------------------------------------------------------- 1 | \name{LoadBeatAmbit} 2 | \Rdversion{1.1} 3 | \alias{LoadBeatAmbit} 4 | \title{ Imports data from a record in Suunto Ambit XML format } 5 | \description{ 6 | Reads a Suunto Ambit XML file with data of beat positions and stores the values in a data structure 7 | } 8 | \usage{ 9 | LoadBeatAmbit(HRVData, RecordName, RecordPath = ".", verbose = NULL) 10 | } 11 | \arguments{ 12 | \item{HRVData}{ Data structure that stores the beats register and information related to it } 13 | \item{RecordName}{ The Suunto Ambit XML file to be read } 14 | \item{RecordPath}{ The path of the file } 15 | \item{verbose}{ Deprecated argument maintained for compatibility, use SetVerbose() instead } 16 | } 17 | \value{ 18 | Returns HRVData, the structure that contains beat positions register 19 | } 20 | \references{ 21 | L. Rodriguez-Linares, X. Vila, A. Mendez, M. Lado, D. Olivieri, "RHRV: An R-based software package for heart rate variability analysis of ECG recordings," 3rd Iberian Conference in Systems and Information Technologies (CISTI 2008), Proceedings I, 565-573, ISBN: 978-84-612-4476-8 (2008) 22 | } 23 | \author{ 24 | Matti Lassila 25 | } 26 | \keyword{ IO } 27 | \keyword{ connection } 28 | -------------------------------------------------------------------------------- /man/LoadBeatAscii.Rd: -------------------------------------------------------------------------------- 1 | \name{LoadBeatAscii} 2 | \alias{LoadBeatAscii} 3 | \title{ Builds an array of beats positions from an ascii file } 4 | \description{ 5 | Reads an ascii file with data of beat positions and stores the values in a data structure. A segment of a file can be loaded making use of the "starttime" and "endtime" arguments. 6 | } 7 | \usage{ 8 | LoadBeatAscii(HRVData, RecordName, RecordPath=".", scale = 1, starttime=NULL, 9 | endtime=NULL, datetime = "1/1/1900 0:0:0", verbose = NULL) 10 | } 11 | \arguments{ 12 | \item{HRVData}{ Data structure that stores the beats register and information related to it } 13 | \item{RecordName}{Ascii file containing the beats to be loaded } 14 | \item{RecordPath}{ The path of the file } 15 | \item{scale}{ 1 if beat positions in seconds or 0.001 if beat positions in milliseconds } 16 | \item{starttime}{Beginning of the segment of file to load} 17 | \item{endtime}{End of the segment of file to load} 18 | \item{datetime}{ Date and time (DD/MM/YYYY HH:MM:SS) } 19 | \item{verbose}{ Deprecated argument maintained for compatibility, use SetVerbose() instead } 20 | } 21 | \value{ 22 | Loads beats positions into the structure that contains RHRV information. The 23 | file containing the heartbeats positions must be a single column file with 24 | no headers. Each line should denote the occurrence time of each heartbeat. An 25 | example of a valid file could be the following:\cr 26 | \emph{0}\cr 27 | \emph{0.3280001}\cr 28 | \emph{0.7159996}\cr 29 | \emph{1.124}\cr 30 | \emph{1.5}\cr 31 | \emph{1.88}\cr 32 | (...) 33 | } 34 | \references{ 35 | L. Rodriguez-Linares, L., A.J. Mendez, M.J. Lado, D.N. Olivieri, X.A. Vila, and I. Gomez-Conde, "An open source tool for heart rate variability spectral analysis", Computer Methods and Programs in Biomedicine 103(1):39-50, july 2011. 36 | } 37 | \author{ 38 | A. Mendez, L. Rodriguez, A. Otero, C.A. Garcia, X. Vila, M. Lado 39 | } 40 | \keyword{ IO } 41 | \keyword{ connection } 42 | -------------------------------------------------------------------------------- /man/LoadBeatEDFPlus.Rd: -------------------------------------------------------------------------------- 1 | \name{LoadBeatEDFPlus} 2 | \alias{LoadBeatEDFPlus} 3 | \title{ Imports data from a record in EDF+ format } 4 | \description{ 5 | Basically, this algorithm reads the annotation file for the ECG register, and stores the information obtained in a data structure. 6 | } 7 | \usage{ 8 | LoadBeatEDFPlus(HRVData, RecordName, RecordPath = ".", 9 | annotationType ="QRS", verbose = NULL) 10 | } 11 | \arguments{ 12 | \item{HRVData}{ Data structure that stores the beats register and information related to it } 13 | \item{RecordName}{ The EDF+ file to be used } 14 | \item{RecordPath}{ The path of the file } 15 | \item{annotationType}{ The type of annotation wished } 16 | \item{verbose}{ Deprecated argument maintained for compatibility, use SetVerbose() instead } 17 | } 18 | \value{ 19 | Returns HRVData, the structure that contains beat positions register 20 | } 21 | \references{ 22 | L. Rodriguez-Linares, L., A.J. Mendez, M.J. Lado, D.N. Olivieri, X.A. Vila, and I. Gomez-Conde, "An open source tool for heart rate variability spectral analysis", Computer Methods and Programs in Biomedicine 103(1):39-50, july 2011. 23 | } 24 | \author{ 25 | I. Garcia 26 | } 27 | \keyword{ IO } 28 | \keyword{ connection } 29 | -------------------------------------------------------------------------------- /man/LoadBeatPolar.Rd: -------------------------------------------------------------------------------- 1 | \name{LoadBeatPolar} 2 | \alias{LoadBeatPolar} 3 | \title{ Imports data from a record in Polar format } 4 | \description{ 5 | Reads a Polar file with data of beat positions and stores the values in a data structure 6 | } 7 | \usage{ 8 | LoadBeatPolar(HRVData, RecordName, RecordPath=".", verbose = NULL) 9 | } 10 | \arguments{ 11 | \item{HRVData}{ Data structure that stores the beats register and information related to it } 12 | \item{RecordName}{ The Polar file to be used } 13 | \item{RecordPath}{ The path of the file } 14 | \item{verbose}{ Deprecated argument maintained for compatibility, use SetVerbose() instead } 15 | } 16 | \value{ 17 | Returns HRVData, the structure that contains beat positions register 18 | } 19 | \references{ 20 | L. Rodriguez-Linares, A. Mendez, M. Lado, D. Olivieri, X. Vila, I. Gomez-Conde, "An open source tool for heart rate variability spectral analysis", Computer Methods and Programs in Biomedicine 103, 39-50, doi:10.1016/j.cmpb.2010.05.012 (2011) 21 | } 22 | \author{ 23 | I. Garcia 24 | } 25 | \keyword{ IO } 26 | \keyword{ connection } 27 | -------------------------------------------------------------------------------- /man/LoadBeatRR.Rd: -------------------------------------------------------------------------------- 1 | \name{LoadBeatRR} 2 | \alias{LoadBeatRR} 3 | \title{ Builds an array of beats positions from an ascii file } 4 | \description{ 5 | Reads an ascii file containing RR values, i.e. distances between two successive beats. 6 | } 7 | \usage{ 8 | LoadBeatRR(HRVData, RecordName, RecordPath=".", scale = 1, 9 | datetime = "1/1/1900 0:0:0", verbose = NULL) 10 | } 11 | \arguments{ 12 | \item{HRVData}{ Data structure that stores the beats register and information related to it } 13 | \item{RecordName}{ The Ascii file to be used } 14 | \item{RecordPath}{ The path of the file } 15 | \item{scale}{ 1 if beat positions in seconds or 0.001 if beat positions in milliseconds } 16 | \item{datetime}{ Date and time (DD/MM/YYYY HH:MM:SS) } 17 | \item{verbose}{ Deprecated argument maintained for compatibility, use SetVerbose() instead } 18 | } 19 | \value{ 20 | Returns HRVData, the structure that contains beat positions register 21 | } 22 | \references{ 23 | L. Rodriguez-Linares, L., A.J. Mendez, M.J. Lado, D.N. Olivieri, X.A. Vila, and I. Gomez-Conde, "An open source tool for heart rate variability spectral analysis", Computer Methods and Programs in Biomedicine 103(1):39-50, july 2011. 24 | } 25 | \author{ 26 | I. Garcia 27 | } 28 | \keyword{ IO } 29 | \keyword{ connection } 30 | -------------------------------------------------------------------------------- /man/LoadBeatSuunto.Rd: -------------------------------------------------------------------------------- 1 | \name{LoadBeatSuunto} 2 | \Rdversion{1.1} 3 | \alias{LoadBeatSuunto} 4 | \title{ Imports data from a record in Suunto format } 5 | \description{ 6 | Reads a Suunto file with data of beat positions and stores the values in a data structure 7 | } 8 | \usage{ 9 | LoadBeatSuunto(HRVData, RecordName, RecordPath = ".", verbose = NULL) 10 | } 11 | \arguments{ 12 | \item{HRVData}{ Data structure that stores the beats register and information related to it } 13 | \item{RecordName}{ The Suunto file to be read } 14 | \item{RecordPath}{ The path of the file } 15 | \item{verbose}{ Deprecated argument maintained for compatibility, use SetVerbose() instead } 16 | } 17 | \value{ 18 | Returns HRVData, the structure that contains beat positions register 19 | } 20 | \references{ 21 | L. Rodriguez-Linares, A. Mendez, M. Lado, D. Olivieri, X. Vila, I. Gomez-Conde, "An open source tool for heart rate variability spectral analysis", Computer Methods and Programs in Biomedicine 103, 39-50, doi:10.1016/j.cmpb.2010.05.012 (2011) 22 | } 23 | \author{ 24 | I. Garcia 25 | } 26 | \keyword{ IO } 27 | \keyword{ connection } 28 | -------------------------------------------------------------------------------- /man/LoadBeatVector.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/LoadBeatVector.R 3 | \name{LoadBeatVector} 4 | \alias{LoadBeatVector} 5 | \title{Loads beats positions from an R vector} 6 | \usage{ 7 | LoadBeatVector(HRVData, beatPositions, scale = 1, datetime = "1/1/1900 0:0:0") 8 | } 9 | \arguments{ 10 | \item{HRVData}{Data structure that stores the beats recording and information 11 | related to it} 12 | 13 | \item{beatPositions}{Numeric vector with the heartbeats occurrence's times since 14 | the beginning of the recording. See \emph{scale} parameter to specify the 15 | units} 16 | 17 | \item{scale}{Numeric value identifying the temporal units in which 18 | the beat positions are specified: 1 if beat positions is specified in seconds, 19 | 0.001 if beat positions in milliseconds, etc.} 20 | 21 | \item{datetime}{Date and time (DD/MM/YYYY HH:MM:SS) of the beginning of the 22 | recording} 23 | } 24 | \value{ 25 | A \emph{HRVData} structure containing the heartbeat positions 26 | from the \emph{beatPositions} vector. 27 | } 28 | \description{ 29 | Stores the beat positions from an R vector under the 30 | \emph{HRVData} data structure. 31 | } 32 | \examples{ 33 | \dontrun{ 34 | hd = CreateHRVData() 35 | hd = LoadBeatVector(hd, 36 | c(0.000, 0.328, 0.715, 0.124, 1.50,1.880, 2.268, 2.656)) 37 | hd = BuildNIHR(hd) 38 | # ... continue analyzing the recording 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /man/LoadBeatWFDB.Rd: -------------------------------------------------------------------------------- 1 | \name{LoadBeatWFDB} 2 | \alias{LoadBeatWFDB} 3 | \title{ Imports data from a record in WFDB format } 4 | \description{ 5 | Basically, this algorithm reads the annotation file for the ECG register, and stores the information obtained in a data structure. 6 | } 7 | \usage{ 8 | LoadBeatWFDB(HRVData, RecordName, RecordPath = ".", annotator = "qrs", 9 | verbose=NULL) 10 | } 11 | \arguments{ 12 | \item{HRVData}{ Data structure that stores the beats register and information related to it } 13 | \item{RecordName}{ The WFDB file to be used } 14 | \item{RecordPath}{ The path of the file } 15 | \item{annotator}{ The extension of the file } 16 | \item{verbose}{ Deprecated argument maintained for compatibility, use SetVerbose() instead } 17 | } 18 | \value{ 19 | Returns HRVData, the structure that contains beat positions register 20 | } 21 | \references{ 22 | L. Rodriguez-Linares, A. Mendez, M. Lado, D. Olivieri, X. Vila, I. Gomez-Conde, "An open source tool for heart rate variability spectral analysis", Computer Methods and Programs in Biomedicine 103, 39-50, doi:10.1016/j.cmpb.2010.05.012 (2011) 23 | } 24 | \author{ 25 | I. Garcia 26 | } 27 | \keyword{ IO } 28 | \keyword{ connection } 29 | -------------------------------------------------------------------------------- /man/LoadEpisodesAscii.Rd: -------------------------------------------------------------------------------- 1 | \name{LoadEpisodesAscii} 2 | \alias{LoadEpisodesAscii} 3 | \title{ Loads episodes file } 4 | \description{ 5 | Loads the information of episodes, or annotated physiological events, and stores it into the data structure containing the beat positions 6 | } 7 | \usage{ 8 | LoadEpisodesAscii(HRVData, FileName, RecordPath=".", Tag="", InitTime="0:0:0", 9 | verbose=NULL,header = TRUE) 10 | } 11 | \arguments{ 12 | \item{HRVData}{ Data structure that stores the beats register and information related to it } 13 | \item{FileName}{ The episodes file to be used } 14 | \item{RecordPath}{ The path of the file } 15 | \item{Tag}{ Type of episode } 16 | \item{InitTime}{ Time (HH:MM:SS) } 17 | \item{verbose}{ Deprecated argument maintained for compatibility, use SetVerbose() instead } 18 | \item{header}{Logical value. If TRUE, then the first line of the file is skipped. Default: TRUE.} 19 | } 20 | \value{ 21 | Returns HRVData, the structure that contains beat positions register and episodes information 22 | } 23 | \references{ 24 | L. Rodriguez-Linares, A. Mendez, M. Lado, D. Olivieri, X. Vila, I. Gomez-Conde, "An open source tool for heart rate variability spectral analysis", Computer Methods and Programs in Biomedicine 103, 39-50, doi:10.1016/j.cmpb.2010.05.012 (2011) 25 | } 26 | \author{ 27 | M. Lado, A. Mendez, D. Olivieri, L. Rodriguez, X. Vila 28 | } 29 | \keyword{ IO } 30 | \keyword{ connection } 31 | -------------------------------------------------------------------------------- /man/LoadHeaderWFDB.Rd: -------------------------------------------------------------------------------- 1 | \name{LoadHeaderWFDB} 2 | \alias{LoadHeaderWFDB} 3 | \title{ Imports header information from a record in wfdb format } 4 | \description{ 5 | Reads the header file for the ECG register, and stores the information obtained in a data structure 6 | } 7 | \usage{ 8 | LoadHeaderWFDB(HRVData, RecordName, RecordPath = ".", verbose=NULL) 9 | } 10 | \arguments{ 11 | \item{HRVData}{ Data structure that stores the beats register and information related to it } 12 | \item{RecordName}{ The ECG file to be used } 13 | \item{RecordPath}{ The path of the ECG file } 14 | \item{verbose}{ Deprecated argument maintained for compatibility, use SetVerbose() instead } 15 | } 16 | \value{ 17 | Returns Data, the structure that contains beat positions register and data extracted from header file 18 | } 19 | \references{ 20 | L. Rodriguez-Linares, A. Mendez, M. Lado, D. Olivieri, X. Vila, I. Gomez-Conde, "An open source tool for heart rate variability spectral analysis", Computer Methods and Programs in Biomedicine 103, 39-50, doi:10.1016/j.cmpb.2010.05.012 (2011) 21 | } 22 | \author{ 23 | M. Lado, A. Mendez, D. Olivieri, L. Rodriguez, X. Vila 24 | } 25 | \keyword{ IO } 26 | \keyword{ connection } 27 | 28 | -------------------------------------------------------------------------------- /man/ModifyEpisodes.Rd: -------------------------------------------------------------------------------- 1 | \name{ModifyEpisodes} 2 | \alias{ModifyEpisodes} 3 | \title{ Modifies values of episodes} 4 | \usage{ 5 | ModifyEpisodes(HRVData, Tags=NULL, Indexes=NULL, NewInitTimes=NULL, 6 | NewTags=NULL, NewDurations=NULL ,NewValues=NULL) 7 | } 8 | \arguments{ 9 | \item{HRVData}{ Data structure that stores the beats register and information related to it } 10 | \item{Tags}{ Vector containing types of episodes to remove } 11 | \item{Indexes}{ Vector containing indexes of episodes to remove (see ListEpisodes()) } 12 | \item{NewInitTimes}{ Vector containing new init times in seconds } 13 | \item{NewTags}{ Vector containing new tags for episodes } 14 | \item{NewDurations}{ Vector containing new durations in seconds } 15 | \item{NewValues}{ Vector containing new numerical values for episodes } 16 | } 17 | \value{ 18 | Returns HRVData, the structure that contains beat positions register and new episodes information 19 | } 20 | \description{ 21 | This function allow users to modify the parameters that define episodes: Tags, InitTimes, Durations and Values. 22 | 23 | Episodes can be selected by Tags or Indexes (or both) and more than one episodes' characteristics can be modified within the same call. 24 | 25 | When modifying more than one episode, vectors of new parameters are recycled. 26 | 27 | After the modification has been made, duplicate episodes are removed and they are reordered by increasing InitTimes. 28 | } 29 | \references{ 30 | L. Rodriguez-Linares, A. Mendez, M. Lado, D. Olivieri, X. Vila, I. Gomez-Conde, "An open source tool for heart rate variability spectral analysis", Computer Methods and Programs in Biomedicine 103, 39-50, doi:10.1016/j.cmpb.2010.05.012 (2011) 31 | } 32 | \author{ 33 | M. Lado, A. Mendez, D. Olivieri, L. Rodriguez, X. Vila 34 | } 35 | \keyword{ misc } 36 | -------------------------------------------------------------------------------- /man/NonlinearityTests.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/NonlinearityTest.R 3 | \name{NonlinearityTests} 4 | \alias{NonlinearityTests} 5 | \title{Nonlinearity tests} 6 | \usage{ 7 | NonlinearityTests( 8 | HRVData, 9 | indexNonLinearAnalysis = length(HRVData$NonLinearAnalysis) 10 | ) 11 | } 12 | \arguments{ 13 | \item{HRVData}{Structure containing the RR time series.} 14 | 15 | \item{indexNonLinearAnalysis}{Reference to the data structure that will contain the nonlinear analysis} 16 | } 17 | \value{ 18 | A \emph{HRVData} structure containing a \emph{NonlinearityTests} field storing the results of each of the tests. 19 | The \emph{NonlinearityTests} list is stored under the \emph{NonLinearAnalysis} structure. 20 | } 21 | \description{ 22 | Nonlinearity tests 23 | } 24 | \details{ 25 | This function runs a set of nonlinearity tests on the RR time series 26 | implemented in other R packages including: 27 | \itemize{ 28 | \item Teraesvirta's neural metwork test for nonlinearity (\code{\link[tseries]{terasvirta.test}}). 29 | \item White neural metwork test for nonlinearity (\code{\link[tseries]{white.test}}). 30 | \item Keenan's one-degree test for nonlinearity (\code{\link[TSA]{Keenan.test}}). 31 | \item Perform the McLeod-Li test for conditional heteroscedascity (ARCH). (\code{\link[TSA]{McLeod.Li.test}}). 32 | \item Perform the Tsay's test for quadratic nonlinearity in a time series. (\code{\link[TSA]{Tsay.test}}). 33 | \item Perform the Likelihood ratio test for threshold nonlinearity. (\code{\link[TSA]{tlrt}}). 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /man/OverplotEpisodes.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/OverplotEpisodes.R 3 | \name{OverplotEpisodes} 4 | \alias{OverplotEpisodes} 5 | \title{OverplotEpisodes} 6 | \usage{ 7 | OverplotEpisodes( 8 | HRVData, 9 | Tags = NULL, 10 | Indexes = NULL, 11 | epColorPalette = NULL, 12 | eplim, 13 | lty = 2, 14 | markEpisodes = T, 15 | ymark, 16 | showEpLegend = T, 17 | epLegendCoords = NULL, 18 | Tag = NULL, 19 | ... 20 | ) 21 | } 22 | \arguments{ 23 | \item{HRVData}{Data structure that stores the beats register and information 24 | related to it.} 25 | 26 | \item{Tags}{List of tags to specify which episodes, as apnoea or oxygen 27 | desaturation, are included in the plot. \emph{Tags}="all" plots all episodes present 28 | in the data.} 29 | 30 | \item{Indexes}{List of indexes of episodes (see \code{\link{ListEpisodes}}) 31 | to specify which episodes are included in the plot. 32 | \emph{Indexes}="all" plots all episodes present in the data.} 33 | 34 | \item{epColorPalette}{Vector specifying the color of each of the episodes that 35 | will be plotted. The length of epColorPalette should be equal or greater than 36 | the number of different episodes to be plotted.} 37 | 38 | \item{eplim}{Two-component vector specifying the y-range (min,max) for the 39 | vertical lines limiting each episode.} 40 | 41 | \item{lty}{The line type for the vertical lines limiting each episode.} 42 | 43 | \item{markEpisodes}{Boolean specyfing if a horizontal mark should be included 44 | for each of the episodes.} 45 | 46 | \item{ymark}{Two-component vector specifying the y-range (min,max) for 47 | the horizontal marks. Only used if markEpisodes = TRUE.} 48 | 49 | \item{showEpLegend}{Boolean argument. If TRUE, a legend of the episodes is 50 | included.} 51 | 52 | \item{epLegendCoords}{Two-component vector specifiying the coordinates where 53 | the legend should be placed. By defaul, the legend is placed on top of 54 | the plot.} 55 | 56 | \item{Tag}{Deprecated argument maintained for 57 | compatibility, use Tags instead.} 58 | 59 | \item{...}{Other graphical parameters for the vertical lines limiting each 60 | episode. See \code{\link[graphics]{plot.default}}.} 61 | } 62 | \description{ 63 | Add episodic information to the current plot 64 | } 65 | \examples{ 66 | \dontrun{ 67 | # Read file "a03" from the physionet apnea-ecg database 68 | library(RHRV) 69 | HRVData <- CreateHRVData() 70 | HRVData <- LoadBeatWFDB(HRVData,RecordName="test_files/WFDB/a03") 71 | HRVData <- LoadApneaWFDB(HRVData,RecordName="test_files/WFDB/a03") 72 | # Add other type of episode for a more complete example (this episode does 73 | # not have any physiological meaning) 74 | HRVData <- AddEpisodes(HRVData,InitTimes=c(4500),Durations=c(1000), 75 | Tags="Other", Values = 1) 76 | HRVData <- BuildNIHR(HRVData) 77 | HRVData <- FilterNIHR(HRVData) 78 | HRVData <- InterpolateNIHR(HRVData) 79 | 80 | 81 | PlotHR(HRVData) 82 | OverplotEpisodes(HRVData,ymark=c(150,151),eplim=c(20,150)) 83 | 84 | # Change some default parameters 85 | PlotHR(HRVData) 86 | OverplotEpisodes(HRVData,ymark=c(150,151),eplim=c(20,150), 87 | epLegendCoords=c(25000,150), lty=5, 88 | epColorPalette=c("blue","green")) 89 | 90 | # Use episodic information with the spectrogram... In order to obtain a proper 91 | # representation of the episodes we need to avoid the use of the spectrogram 92 | # legend 93 | sp <- PlotSpectrogram(HRVData, size=600, shift=60, freqRange=c(0,0.05), 94 | showLegend=F); 95 | OverplotEpisodes(HRVData, markEpisodes=T, ymark=c(0.04,0.0401), 96 | eplim=c(0,0.04), Tags="APNEA", 97 | epColorPalette = c("white"), lwd=3) 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /man/PlotHR.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/PlotHR.R 3 | \name{PlotHR} 4 | \alias{PlotHR} 5 | \title{Simple plot of interpolated heart rate} 6 | \usage{ 7 | PlotHR( 8 | HRVData, 9 | Tags = NULL, 10 | Indexes = NULL, 11 | main = "Interpolated instantaneous heart rate", 12 | xlab = "time (sec.)", 13 | ylab = "HR (beats/min.)", 14 | type = "l", 15 | ylim = NULL, 16 | Tag = NULL, 17 | verbose = NULL, 18 | ... 19 | ) 20 | } 21 | \arguments{ 22 | \item{HRVData}{Data structure that stores the beats register and information 23 | related to it.} 24 | 25 | \item{Tags}{List of tags to specify which episodes, as apnoea or oxygen 26 | desaturation, are included in the plot. \emph{Tags}="all" plots all episodes present 27 | in the data.} 28 | 29 | \item{Indexes}{List of indexes of episodes (see \code{\link{ListEpisodes}}) 30 | to specify which episodes are included in the plot. 31 | \emph{Indexes}="all" plots all episodes present in the data.} 32 | 33 | \item{main}{A main title for the plot.} 34 | 35 | \item{xlab}{A label for the x axis.} 36 | 37 | \item{ylab}{a label for the y axis} 38 | 39 | \item{type}{1-character string giving the type of plot desired. See 40 | \code{\link[graphics]{plot.default}}.} 41 | 42 | \item{ylim}{The y limits of the plot.} 43 | 44 | \item{Tag}{Deprecated argument maintained for 45 | compatibility, use \emph{Tags} instead.} 46 | 47 | \item{verbose}{Deprecated argument maintained for compatibility, 48 | use SetVerbose() instead} 49 | 50 | \item{...}{Other graphical parameters. See 51 | \code{\link[graphics]{plot.default}}.} 52 | } 53 | \description{ 54 | Plots in a simple way the interpolated instantaneous heart 55 | rate signal. 56 | } 57 | \details{ 58 | PlotHR 59 | } 60 | \references{ 61 | L. Rodriguez-Linares, L., A.J. Mendez, M.J. Lado, D.N. Olivieri, 62 | X.A. Vila, and I. Gomez-Conde, "An open source tool for heart rate 63 | variability spectral analysis", Computer Methods and Programs in 64 | Biomedicine 103(1):39-50, july 2011. 65 | } 66 | \author{ 67 | M. Lado, A. Mendez, D. Olivieri, L. Rodriguez, X. Vila, C.A. Garcia 68 | } 69 | \keyword{aplot} 70 | -------------------------------------------------------------------------------- /man/PlotNIHR.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/PlotNIHR.R 3 | \name{PlotNIHR} 4 | \alias{PlotNIHR} 5 | \title{Simple plot of non-interpolated heart rate} 6 | \usage{ 7 | PlotNIHR( 8 | HRVData, 9 | Tags = NULL, 10 | Indexes = NULL, 11 | main = "Non-interpolated instantaneous heart rate", 12 | xlab = "time (sec.)", 13 | ylab = "HR (beats/min.)", 14 | type = "l", 15 | ylim = NULL, 16 | Tag = NULL, 17 | verbose = NULL, 18 | ... 19 | ) 20 | } 21 | \arguments{ 22 | \item{HRVData}{Data structure that stores the beats register and information 23 | related to it} 24 | 25 | \item{Tags}{List of tags to specify which episodes, as apnoea or oxygen 26 | desaturation, are included in the plot. \emph{Tags}="all" plots all episodes present 27 | in the data.} 28 | 29 | \item{Indexes}{List of indexes to specify which episodes (see ListEpisodes), 30 | are included in the plot. Indexes="all" plots all episodes present 31 | in the data.} 32 | 33 | \item{main}{A main title for the plot.} 34 | 35 | \item{xlab}{A label for the x axis.} 36 | 37 | \item{ylab}{a label for the y axis} 38 | 39 | \item{type}{1-character string giving the type of plot desired. See 40 | \code{\link[graphics]{plot.default}}.} 41 | 42 | \item{ylim}{The y limits of the plot.} 43 | 44 | \item{Tag}{Deprecated argument maintained for 45 | compatibility, use \emph{Tags} instead.} 46 | 47 | \item{verbose}{Deprecated argument maintained for compatibility, 48 | use SetVerbose() instead} 49 | 50 | \item{...}{Other graphical parameters. See 51 | \code{\link[graphics]{plot.default}}.} 52 | } 53 | \description{ 54 | Plots in a simple way the non-interpolated instantaneous heart 55 | rate signal 56 | } 57 | \details{ 58 | PlotNIHR 59 | } 60 | \references{ 61 | L. Rodriguez-Linares, L., A.J. Mendez, M.J. Lado, D.N. Olivieri, 62 | X.A. Vila, and I. Gomez-Conde, "An open source tool for heart rate 63 | variability spectral analysis", Computer Methods and Programs in Biomedicine 64 | 103(1):39-50, july 2011. 65 | } 66 | \author{ 67 | M. Lado, A. Mendez, D. Olivieri, L. Rodriguez, X. Vila, C.A. Garcia 68 | } 69 | \keyword{aplot} 70 | -------------------------------------------------------------------------------- /man/PlotPSD.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/StationaryFrequencyAnalysis.R 3 | \name{PlotPSD} 4 | \alias{PlotPSD} 5 | \title{Plot Spectral Density Estimation} 6 | \usage{ 7 | PlotPSD( 8 | HRVData, 9 | indexFreqAnalysis = length(HRVData$FreqAnalysis), 10 | ULFmin = 0, 11 | ULFmax = 0.03, 12 | VLFmin = 0.03, 13 | VLFmax = 0.05, 14 | LFmin = 0.05, 15 | LFmax = 0.15, 16 | HFmin = 0.15, 17 | HFmax = 0.4, 18 | log = "y", 19 | type = "l", 20 | xlab = "Frequency (Hz) ", 21 | ylab = "Spectrum", 22 | main = NULL, 23 | xlim = c(min(ULFmin, ULFmax, VLFmin, VLFmax, LFmin, LFmax, HFmin, HFmax), max(ULFmin, 24 | ULFmax, VLFmin, VLFmax, LFmin, LFmax, HFmin, HFmax)), 25 | ylim = NULL, 26 | addLegend = TRUE, 27 | addSigLevel = TRUE, 28 | usePalette = c("#000000", "#E69F00", "#56B4E9", "#009E73", "#F0E442"), 29 | ... 30 | ) 31 | } 32 | \arguments{ 33 | \item{HRVData}{Data structure that stores the beats register and information 34 | related to it.} 35 | 36 | \item{indexFreqAnalysis}{An integer referencing the data structure that contains 37 | the PSD analysis.} 38 | 39 | \item{ULFmin}{Lower limit ULF band used for distinguish the ULF band.} 40 | 41 | \item{ULFmax}{Upper limit ULF band used for distinguish the ULF band.} 42 | 43 | \item{VLFmin}{Lower limit VLF band.} 44 | 45 | \item{VLFmax}{Upper limit VLF band.} 46 | 47 | \item{LFmin}{Lower limit LF band.} 48 | 49 | \item{LFmax}{Upper limit LF band.} 50 | 51 | \item{HFmin}{Lower limit HF band.} 52 | 53 | \item{HFmax}{Upper limit HF band.} 54 | 55 | \item{log}{a character string which contains "x" if the x axis is to be 56 | logarithmic, "y" if the y axis is to be logarithmic and "xy" or "yx" if 57 | both axes are to be logarithmic. Default: "y".} 58 | 59 | \item{type}{1-character string giving the type of plot desired. See \code{\link[graphics]{plot.default}}.} 60 | 61 | \item{xlab}{a label for the x axis. See \code{\link[graphics]{plot.default}}.} 62 | 63 | \item{ylab}{a label for the y axis. See \code{\link[graphics]{plot.default}}.} 64 | 65 | \item{main}{a main title for the plot. See \code{\link[graphics]{plot.default}}.} 66 | 67 | \item{xlim}{the x limits (x1, x2) of the plot. See \code{\link[graphics]{plot.default}}.} 68 | 69 | \item{ylim}{the y limits of the plot.} 70 | 71 | \item{addLegend}{add a simple legend? Default: True.} 72 | 73 | \item{addSigLevel}{Logical value (only used with the lomb method). If true an 74 | horizontal line limiting the significance level is included ( Powers > 75 | sig.level can be considered significant peaks). See \code{\link[lomb]{lsp}}.} 76 | 77 | \item{usePalette}{A new palette of colors for plotting the frequency bands.} 78 | 79 | \item{...}{graphical parameters. See \code{\link[graphics]{plot.default}}.} 80 | } 81 | \description{ 82 | Plot the PSD estimate of the RR time series distinguishing 83 | the different frequency bands with different colurs. 84 | } 85 | \examples{ 86 | \dontrun{ 87 | data(HRVData) 88 | HRVData=BuildNIHR(HRVData) 89 | HRVData=FilterNIHR(HRVData) 90 | # Frequency analysis requires interpolated data (except Lomb) 91 | HRVData=InterpolateNIHR(HRVData) 92 | # Create a different freqAnalysis for each method 93 | HRVData=CreateFreqAnalysis(HRVData) 94 | HRVData=CalculatePSD(HRVData,1,"pgram",doPlot = F) 95 | 96 | HRVData=CalculatePSD(HRVData,2,"pgram",spans=9,doPlot = F) 97 | 98 | HRVData=CreateFreqAnalysis(HRVData) 99 | HRVData=CalculatePSD(HRVData,3,"ar",doPlot = F) 100 | 101 | HRVData=CreateFreqAnalysis(HRVData) 102 | HRVData=CalculatePSD(HRVData,4,"lomb",doPlot = F) 103 | # Plot the results 104 | layout(matrix(c(1,2,3,4), 2, 2, byrow = TRUE)) 105 | PlotPSD(HRVData,1) 106 | PlotPSD(HRVData,2) 107 | PlotPSD(HRVData,3) 108 | PlotPSD(HRVData,4) 109 | } 110 | } 111 | \seealso{ 112 | \code{\link[stats]{spectrum}}, \code{\link[lomb]{lsp}}, \code{\link[RHRV]{CalculatePSD}}. 113 | } 114 | -------------------------------------------------------------------------------- /man/PlotPowerBand.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/PlotPowerBand.R 3 | \name{PlotPowerBand} 4 | \alias{PlotPowerBand} 5 | \title{Plots power determined by CalculatePowerBand function} 6 | \usage{ 7 | PlotPowerBand( 8 | HRVData, 9 | indexFreqAnalysis = length(HRVData$FreqAnalysis), 10 | normalized = FALSE, 11 | hr = FALSE, 12 | ymax = NULL, 13 | ymaxratio = NULL, 14 | ymaxnorm = 1, 15 | Tags = NULL, 16 | Indexes = NULL, 17 | Tag = NULL, 18 | verbose = NULL 19 | ) 20 | } 21 | \arguments{ 22 | \item{HRVData}{Data structure that stores the beats register and 23 | information related to it} 24 | 25 | \item{indexFreqAnalysis}{Numeric parameter used to reference a particular 26 | frequency analysis} 27 | 28 | \item{normalized}{Plots normalized powers if TRUE} 29 | 30 | \item{hr}{Plots heart rate signal if TRUE} 31 | 32 | \item{ymax}{Maximum value for y axis (unnormalized plots)} 33 | 34 | \item{ymaxratio}{Maximum value for y axis in LF/HF band (normalized and 35 | unnormalized plots)} 36 | 37 | \item{ymaxnorm}{Maximum value for y axis (normalized plots)} 38 | 39 | \item{Tags}{List of tags to specify which episodes, as apnoea or oxygen 40 | desaturation, are included in the plot. Tags = "all" plots all episodes present 41 | in the data.} 42 | 43 | \item{Indexes}{List of indexes to specify which episodes (see ListEpisodes), 44 | are included in the plot. Indexes = "all" plots all episodes present 45 | in the data.} 46 | 47 | \item{Tag}{Deprecated argument, use Tags instead} 48 | 49 | \item{verbose}{Deprecated argument maintained for compatibility, use 50 | setVerbose() instead} 51 | } 52 | \description{ 53 | Plots the power of the heart rate signal at different bands 54 | of physiological interest. 55 | } 56 | \details{ 57 | PlotPowerBand 58 | } 59 | \note{ 60 | See \code{\link{PlotSinglePowerBand}} for a more flexible 61 | function for plotting power bands. 62 | } 63 | \examples{ 64 | \dontrun{ 65 | # Reading a wfdb register and storing into a data structure: 66 | md = CreateHRVData(Verbose = TRUE) 67 | md = LoadBeatWFDB(md, RecordName = "register_name", 68 | RecordPath = "register_path") 69 | 70 | # Calculating heart rate signal:md = BuildNIHR(md) 71 | 72 | # Filtering heart rate signal: 73 | md = FilterNIHR(md) 74 | # Interpolating heart rate signal: 75 | md = InterpolateNIHR(md) 76 | # Calculating spectrogram and power per band: 77 | md = CreateFreqAnalysis(md) 78 | md = CalculatePowerBand(md, indexFreqAnalysis = 1, size = 120, 79 | shift = 10, sizesp = 1024) 80 | # Plotting Power per Band 81 | PlotPowerBand(md, hr = TRUE, ymax = 700000, ymaxratio = 4) 82 | } 83 | } 84 | \references{ 85 | L. Rodriguez-Linares, L., A.J. Mendez, M.J. Lado, D.N. Olivieri, 86 | X.A. Vila, and I. Gomez-Conde, "An open source tool for heart rate 87 | variability spectral analysis", Computer Methods and Programs in 88 | Biomedicine 103(1):39-50, july 2011. 89 | } 90 | \seealso{ 91 | \code{\link{CalculatePowerBand}} for power calculation 92 | and \code{\link{PlotSinglePowerBand}} 93 | } 94 | \author{ 95 | M. Lado, A. Mendez, D. Olivieri, L. Rodriguez, X. Vila 96 | } 97 | \keyword{hplot} 98 | -------------------------------------------------------------------------------- /man/PoincarePlot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/poincarePlot.R 3 | \name{PoincarePlot} 4 | \alias{PoincarePlot} 5 | \title{Poincare Plot} 6 | \usage{ 7 | PoincarePlot( 8 | HRVData, 9 | indexNonLinearAnalysis = length(HRVData$NonLinearAnalysis), 10 | timeLag = 1, 11 | confidenceEstimation = FALSE, 12 | confidence = 0.95, 13 | doPlot = FALSE, 14 | main = "Poincare plot", 15 | xlab = "RR[n]", 16 | ylab = paste0("RR[n+", timeLag, "]"), 17 | pch = 1, 18 | cex = 0.3, 19 | type = "p", 20 | xlim = NULL, 21 | ylim = NULL, 22 | ... 23 | ) 24 | } 25 | \arguments{ 26 | \item{HRVData}{Data structure that stores the beats register and information related to it} 27 | 28 | \item{indexNonLinearAnalysis}{Reference to the data structure that will contain the nonlinear analysis} 29 | 30 | \item{timeLag}{Integer denoting the number of time steps that will be use to construct the 31 | dependance relation: \eqn{RR_{j+timeLag}}{RR_(j+timeLag)} as a function of \eqn{RR_j}.} 32 | 33 | \item{confidenceEstimation}{Logical value. If TRUE, the covariance matrix is 34 | used for fitting the ellipse and computing the \eqn{SD_1} and 35 | \eqn{SD_2} parameters (see details). Default: FALSE.} 36 | 37 | \item{confidence}{The confidence used for plotting the confidence ellipse.} 38 | 39 | \item{doPlot}{Logical value. If TRUE (default), the PoincarePlot is shown.} 40 | 41 | \item{main}{An overall title for the Poincare plot.} 42 | 43 | \item{xlab}{A title for the x axis.} 44 | 45 | \item{ylab}{A title for the y axis.} 46 | 47 | \item{pch}{Plotting character (symbol to use).} 48 | 49 | \item{cex}{Character (or symbol) expansion.} 50 | 51 | \item{type}{What type of plot should be drawn. See \code{\link[graphics]{plot.default}}.} 52 | 53 | \item{xlim}{x coordinates range. If not specified, a proper x range is selected.} 54 | 55 | \item{ylim}{y coordinates range. If not specified, a proper y range is selected.} 56 | 57 | \item{...}{Additional parameters for the Poincare plot figure.} 58 | } 59 | \value{ 60 | A \emph{HRVData} structure containing a \emph{PoincarePlot} field storing 61 | the \eqn{SD_1} and \eqn{SD_2} parameters. The \emph{PoincarePlot} field is 62 | stored under the \emph{NonLinearAnalysis} list. 63 | } 64 | \description{ 65 | The Poincare plot is a graphical representation of the dependance 66 | between successive RR intervals obtained by plotting the \eqn{RR_{j+\tau}}{RR_(j+tau)} 67 | as a function of \eqn{RR_j}. This dependance is often quantified by fitting an 68 | ellipse to the plot. In this way, two parameters are obtained: 69 | \eqn{SD_1} and \eqn{SD_2}. 70 | \eqn{SD_1} characterizes short-term variability 71 | whereas that \eqn{SD_2} characterizes long-term variability. 72 | } 73 | \details{ 74 | In the HRV literature, when \emph{timeLag = 1}, the \eqn{SD_1} and \eqn{SD_2} 75 | parameters are computed using time domain measures. This is the default approach in this 76 | function if \emph{timeLag=1}. This function also allows the user to fit a ellipse 77 | by computing the covariance matrix of 78 | (\eqn{RR_{j}}{RR_(j)},\eqn{RR_{j+\tau}}{RR_(j+tau)}) 79 | (by setting \emph{confidenceEstimation = TRUE}). In most cases, both approaches 80 | yield similar results. 81 | } 82 | \examples{ 83 | \dontrun{ 84 | data(HRVProcessedData) 85 | # rename for convenience 86 | hd = HRVProcessedData 87 | hd = CreateNonLinearAnalysis(hd) 88 | hd = PoincarePlot(hd, doPlot = T) 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /man/RHRV-package.Rd: -------------------------------------------------------------------------------- 1 | \name{RHRV-package} 2 | \alias{RHRV-package} 3 | \alias{RHRV} 4 | \docType{package} 5 | \title{ 6 | RHRV: An R-based software package for the heart rate variability analysis of ECG recordings 7 | } 8 | \description{ 9 | RHRV offers functions for performing power spectral analysis of heart rate data. We will use this package for the study of several diseases, such as obstructive sleep apnoea or chronic obstructive pulmonary disease. 10 | } 11 | \details{ 12 | This is a package for developing heart rate variability studies of ECG records. Data are read from an ascii file containing a column with beat positions in seconds. A function is included in order to build this file from an ECG record in WFDB format (visit the site http://www.physionet.org for more information). 13 | } 14 | \author{ 15 | A. Mendez, L. Rodriguez, A. Otero, C.A. Garcia, X. Vila, M. Lado 16 | 17 | Maintainer: Leandro Rodriguez-Linares 18 | } 19 | \note{ 20 | An example including all the necessary steps to obtain and to \cr 21 | analyze by episodes the power bands of a wfdb register is \cr 22 | giving below:\cr 23 | 24 | ##Reading a wfdb register and storing into a data structure:\cr 25 | md = CreateHRVData(Verbose = TRUE)\cr 26 | md = LoadBeatWFDB(md, RecordName = "register_name", \cr 27 | RecordPath = "register_path")\cr 28 | 29 | ##Loading information of episodes of apnea:\cr 30 | md = LoadApneaWFDB(md, RecordName = "register_name", \cr 31 | RecordPath = "register_path", Tag = "APN")\cr 32 | 33 | ##Generating new episodes before and after previous episodes of \cr 34 | apnea:\cr 35 | md = GenerateEpisodes(md, NewBegFrom = "Beg", NewEndFrom = "Beg", \cr 36 | DispBeg = -600, DispEnd = -120, OldTag = "APN", \cr 37 | NewTag = "PREV_APN")\cr 38 | md = GenerateEpisodes(md, NewBegFrom = "End", NewEndFrom = "End", \cr 39 | DispBeg = 120, DispEnd = 600, OldTag = "APN", \cr 40 | NewTag = "POST_APN")\cr 41 | 42 | ##Calculating heart rate signal:\cr 43 | md = BuildNIHR(md)\cr 44 | 45 | ##Filtering heart rate signal:\cr 46 | md = FilterNIHR(md)\cr 47 | 48 | ##Interpolating heart rate signal:\cr 49 | md = InterpolateNIHR(md)\cr 50 | 51 | ##Calculating spectrogram and power per band:\cr 52 | md = CreateFreqAnalysis(md)\cr 53 | md = CalculatePowerBand(md, indexFreqAnalysis = 1, size = 120, \cr 54 | shift = 10, sizesp = 1024)\cr 55 | 56 | ##Plotting power per band, including episodes information:\cr 57 | PlotPowerBand(md, indexFreqAnalysis = 1, hr = TRUE, ymax = 2400000, \cr 58 | ymaxratio = 3, Tag = "all")\cr 59 | 60 | ##Splitting power per band using episodes before and after \cr 61 | episodes of apnea:\cr 62 | PrevAPN = SplitPowerBandByEpisodes(md, indexFreqAnalysis = 1, \cr 63 | Tag = "PREV_APN")\cr 64 | PostAPN = SplitPowerBandByEpisodes(md, indexFreqAnalysis = 1, \cr 65 | Tag = "POST_APN")\cr 66 | 67 | ##Performing Student's t-test:\cr 68 | result = t.test(PrevAPN$InEpisodes$ULF, PostAPN$InEpisodes$ULF)\cr 69 | print(result)\cr 70 | } 71 | \references{ 72 | L. Rodriguez-Linares, L., A.J. Mendez, M.J. Lado, D.N. Olivieri, X.A. Vila, and I. Gomez-Conde, "An open source tool for heart rate variability spectral analysis", Computer Methods and Programs in Biomedicine 103(1):39-50, july 2011. 73 | } 74 | \keyword{ package } 75 | -------------------------------------------------------------------------------- /man/RHRVEasy.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RHRVEasy.R 3 | \name{RHRVEasy} 4 | \alias{RHRVEasy} 5 | \title{Run a full HRV analysis including indices computation and statistical analysis} 6 | \usage{ 7 | RHRVEasy( 8 | folders, 9 | correctionMethod = c("bonferroni", "holm", "hochberg", "hommel", "BH", "BY", "fdr", 10 | "none"), 11 | verbose = FALSE, 12 | format = "RR", 13 | typeAnalysis = c("fourier", "wavelet"), 14 | significance = 0.05, 15 | nonLinear = FALSE, 16 | doRQA = FALSE, 17 | nJobs = 1, 18 | saveHRVIndicesInPath = NULL, 19 | ... 20 | ) 21 | } 22 | \arguments{ 23 | \item{folders}{A character vector with the paths to the folders containing 24 | the HRV files. Each folder should contain the HRV files of a group.} 25 | 26 | \item{correctionMethod}{The method to correct for multiple comparisons. Can 27 | be one of "bonferroni", "holm", "hochberg", "hommel", "BH", "BY", "fdr" and 28 | "none". Default is "bonferroni".} 29 | 30 | \item{verbose}{Logical. If TRUE, the function will show a progress bar and 31 | print additional information to the console.} 32 | 33 | \item{format}{The format of the HRV files. Can be one of "WFDB", "Ascii", 34 | "RR", "Polar", "Suunto", "EDFPlus" and "Ambit".} 35 | 36 | \item{typeAnalysis}{The type of frequency analysis to perform. Can be one of 37 | "fourier" or "wavelet".} 38 | 39 | \item{significance}{The significance level to use in the statistical 40 | analysis. By default, it is set to 0.05.} 41 | 42 | \item{nonLinear}{Logical. If TRUE, the function will compute non-linear 43 | indices. It should be noted that this process is computationally expensive.} 44 | 45 | \item{doRQA}{Logical. If TRUE, the function will compute Recurrence 46 | Quantification Analysis (RQA) indices. This parameter is ignored if 47 | `nonLinear` is set to FALSE.It should be noted that this process is 48 | computationally expensive.} 49 | 50 | \item{nJobs}{The number of parallel jobs to use. `nJobs <= 0` uses all cores 51 | available. By default, it is set to 1.} 52 | 53 | \item{saveHRVIndicesInPath}{The path where the HRV indices will be saved as 54 | an excel file. If NULL, the indices will not be saved. See [SaveHRVIndices()] 55 | for more details.} 56 | 57 | \item{...}{Additional arguments for the HRV analysis. For further details, 58 | see the `RHRV` package.} 59 | } 60 | \value{ 61 | An object of class `RHRVEasyResult` containing the HRV indices 62 | (slot `$HRVIndices`) and the statistical analysis results (slot `$stats`) 63 | } 64 | \description{ 65 | Run a full HRV analysis including indices computation and statistical analysis 66 | } 67 | -------------------------------------------------------------------------------- /man/RHRVEasyStats.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RHRVEasy.R 3 | \name{RHRVEasyStats} 4 | \alias{RHRVEasyStats} 5 | \title{Rerun the statistical analysis from a previous `RHRVEasy()` call} 6 | \usage{ 7 | RHRVEasyStats( 8 | RHRVEasyResultObject, 9 | correctionMethod = c("bonferroni", "holm", "hochberg", "hommel", "BH", "BY", "fdr", 10 | "none"), 11 | significance = 0.05 12 | ) 13 | } 14 | \arguments{ 15 | \item{RHRVEasyResultObject}{An object of class `RHRVEasyResult` as returned 16 | by `RHRVEasy()`} 17 | 18 | \item{correctionMethod}{The method to correct for multiple comparisons. Can 19 | be one of "bonferroni", "holm", "hochberg", "hommel", "BH", "BY", "fdr" and 20 | "none". Default is "bonferroni".} 21 | 22 | \item{significance}{The significance level to use in the statistical 23 | analysis. By default, it is set to 0.05.} 24 | } 25 | \value{ 26 | An object of class `RHRVEasyResult` containing the HRV indices 27 | (slot `$HRVIndices`) and the statistical analysis results (slot `$stats`) 28 | } 29 | \description{ 30 | Rerun the statistical analysis from a previous `RHRVEasy()` call 31 | } 32 | \seealso{ 33 | [RHRVEasy()] 34 | } 35 | -------------------------------------------------------------------------------- /man/RQA.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RQA.R 3 | \name{RQA} 4 | \alias{RQA} 5 | \title{Recurrence Quantification Analysis (RQA)} 6 | \usage{ 7 | RQA( 8 | HRVData, 9 | indexNonLinearAnalysis = length(HRVData$NonLinearAnalysis), 10 | numberPoints = NULL, 11 | embeddingDim = NULL, 12 | timeLag = NULL, 13 | radius = 1, 14 | lmin = 2, 15 | vmin = 2, 16 | distanceToBorder = 2, 17 | doPlot = FALSE 18 | ) 19 | } 20 | \arguments{ 21 | \item{HRVData}{Data structure that stores the beats register and information related to it} 22 | 23 | \item{indexNonLinearAnalysis}{Reference to the data structure that will contain the nonlinear analysis} 24 | 25 | \item{numberPoints}{Number of points from the RR time series to be used in the RQA computation. If the number of 26 | points is not specified, the whole RR time series is used.} 27 | 28 | \item{embeddingDim}{Integer denoting the dimension in which we shall embed the RR time series.} 29 | 30 | \item{timeLag}{Integer denoting the number of time steps that will be use to construct the 31 | Takens' vectors.} 32 | 33 | \item{radius}{Maximum distance between two phase-space points to be considered a recurrence.} 34 | 35 | \item{lmin}{Minimal length of a diagonal line to be considered in the RQA. Default \emph{lmin} = 2.} 36 | 37 | \item{vmin}{Minimal length of a vertical line to be considered in the RQA. Default \emph{vmin} = 2.} 38 | 39 | \item{distanceToBorder}{In order to avoid border effects, the \emph{distanceToBorder} points near the 40 | border of the recurrence matrix are ignored when computing the RQA parameters. Default, \emph{distanceToBorder} = 2.} 41 | 42 | \item{doPlot}{Logical. If TRUE, the recurrence plot is shown. However, plotting the recurrence matrix is computationally 43 | expensive. Use with caution.} 44 | } 45 | \value{ 46 | A HRVData structure that stores an \emph{rqa} field under the NonLinearAnalysis list. 47 | The \emph{rqa} field consist of a list with the most important RQA parameters: 48 | \itemize{ 49 | \item \emph{REC}: Recurrence. Percentage of recurrence points in a Recurrence Plot. 50 | \item \emph{DET}: Determinism. Percentage of recurrence points that form diagonal lines. 51 | \item \emph{LAM}: Percentage of recurrent points that form vertical lines. 52 | \item \emph{RATIO}: Ratio between \emph{DET} and \emph{RR}. 53 | \item \emph{Lmax}: Length of the longest diagonal line. 54 | \item \emph{Lmean}: Mean length of the diagonal lines. The main diagonal is not taken into account. 55 | \item \emph{DIV}: Inverse of \emph{Lmax}. 56 | \item \emph{Vmax}: Longest vertical line. 57 | \item \emph{Vmean}: Average length of the vertical lines. This parameter is also referred to as the Trapping time. 58 | \item \emph{ENTR}: Shannon entropy of the diagonal line lengths distribution 59 | \item \emph{TREND}: Trend of the number of recurrent points depending on the distance to the main diagonal 60 | \item \emph{diagonalHistogram}: Histogram of the length of the diagonals. 61 | \item \emph{recurrenceRate}: Number of recurrent points depending on the distance to the main diagonal. 62 | } 63 | } 64 | \description{ 65 | The Recurrence Quantification Analysis (RQA) is an advanced technique for the nonlinear 66 | analysis that allows to quantify the number and duration of the recurrences in the 67 | phase space. This function computes the RQA of the RR time series. 68 | } 69 | \note{ 70 | This function is based on the \code{\link[nonlinearTseries]{rqa}} function from the 71 | nonlinearTseries package. 72 | } 73 | \references{ 74 | Zbilut, J. P. and C. L. Webber. Recurrence quantification analysis. Wiley Encyclopedia of Biomedical Engineering (2006). 75 | } 76 | \seealso{ 77 | \code{\link[nonlinearTseries]{rqa}}, \code{\link{RecurrencePlot}} 78 | } 79 | -------------------------------------------------------------------------------- /man/ReadFromFile.Rd: -------------------------------------------------------------------------------- 1 | \name{ReadFromFile} 2 | \alias{ReadFromFile} 3 | \title{ Reads data structure from file } 4 | \description{ 5 | Reads the data structure containing beat positions and all derived calculations from file 6 | } 7 | \usage{ 8 | ReadFromFile(name, verbose=FALSE) 9 | } 10 | \arguments{ 11 | \item{name}{ The name of the file to be used (without the .hrv extension)} 12 | \item{verbose}{Logical value that sets the verbose mode on or off} 13 | } 14 | \value{ 15 | Returns the HRVData structure previously stored in the given file. 16 | } 17 | \references{ 18 | L. Rodriguez-Linares, A. Mendez, M. Lado, D. Olivieri, X. Vila, I. Gomez-Conde, "An open source tool for heart rate variability spectral analysis", Computer Methods and Programs in Biomedicine 103, 39-50, doi:10.1016/j.cmpb.2010.05.012 (2011) 19 | } 20 | \author{ 21 | M. Lado, A. Mendez, D. Olivieri, L. Rodriguez, X. Vila 22 | } 23 | \keyword{ IO } 24 | \keyword{ connection } 25 | 26 | -------------------------------------------------------------------------------- /man/RecurrencePlot.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RQA.R 3 | \name{RecurrencePlot} 4 | \alias{RecurrencePlot} 5 | \title{Recurrence Plot} 6 | \usage{ 7 | RecurrencePlot( 8 | HRVData, 9 | numberPoints = 1000, 10 | embeddingDim = NULL, 11 | timeLag = NULL, 12 | radius = 1, 13 | ... 14 | ) 15 | } 16 | \arguments{ 17 | \item{HRVData}{Data structure that stores the beats register and information related to it} 18 | 19 | \item{numberPoints}{Number of points from the RR time series to be used in the RQA computation. Default: 1000 heartbeats.} 20 | 21 | \item{embeddingDim}{Integer denoting the dimension in which we shall embed the RR time series.} 22 | 23 | \item{timeLag}{Integer denoting the number of time steps that will be use to construct the 24 | Takens' vectors.} 25 | 26 | \item{radius}{Maximum distance between two phase-space points to be considered a recurrence.} 27 | 28 | \item{...}{Additional plotting parameters.} 29 | } 30 | \description{ 31 | Plot the recurrence matrix of the RR time series. 32 | } 33 | \details{ 34 | WARNING: This function is computationally very expensive. Use with caution. 35 | } 36 | \note{ 37 | This function is based on the \code{\link[nonlinearTseries]{recurrencePlot}} function from the 38 | nonlinearTseries package. 39 | } 40 | \references{ 41 | Zbilut, J. P. and C. L. Webber. Recurrence quantification analysis. Wiley Encyclopedia of Biomedical Engineering (2006). 42 | } 43 | \seealso{ 44 | \code{\link[nonlinearTseries]{recurrencePlot}}, \code{\link{RQA}} 45 | } 46 | -------------------------------------------------------------------------------- /man/RemoveEpisodes.Rd: -------------------------------------------------------------------------------- 1 | \name{RemoveEpisodes} 2 | \alias{RemoveEpisodes} 3 | \title{ Remove episodes by indexes or tags} 4 | \description{ 5 | Removes episodes from the data. Episodes can be specified using indexes or tags 6 | } 7 | \usage{ 8 | RemoveEpisodes(HRVData, Tags = NULL, Indexes = NULL) 9 | } 10 | \arguments{ 11 | \item{HRVData}{ Data structure that stores the beats register and information related to it } 12 | \item{Tags}{ Vector containing types of episodes to remove } 13 | \item{Indexes}{ Vector containing indexes of episodes to remove (see ListEpisodes()) } 14 | } 15 | \value{ 16 | Returns HRVData, without the removed episodes 17 | } 18 | \references{ 19 | L. Rodriguez-Linares, A. Mendez, M. Lado, D. Olivieri, X. Vila, I. Gomez-Conde, "An open source tool for heart rate variability spectral analysis", Computer Methods and Programs in Biomedicine 103, 39-50, doi:10.1016/j.cmpb.2010.05.012 (2011) 20 | } 21 | \author{ 22 | M. Lado, A. Mendez, D. Olivieri, L. Rodriguez, X. Vila 23 | } 24 | \keyword{ Episodes } 25 | \keyword{ Tags } 26 | \keyword{ Indexes } 27 | 28 | -------------------------------------------------------------------------------- /man/SaveHRVIndices.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/RHRVEasy.R 3 | \name{SaveHRVIndices} 4 | \alias{SaveHRVIndices} 5 | \title{Save the HRV indices as an excel file} 6 | \usage{ 7 | SaveHRVIndices( 8 | RHRVEasyResultObject, 9 | saveHRVIndicesInPath = ".", 10 | filename = NULL 11 | ) 12 | } 13 | \arguments{ 14 | \item{RHRVEasyResultObject}{An object of class `RHRVEasyResult` as returned 15 | by `RHRVEasy()`} 16 | 17 | \item{saveHRVIndicesInPath}{The path where the HRV indices will be saved as 18 | an excel file. The name of the file is automatically created based on the 19 | groups being compared.} 20 | 21 | \item{filename}{Filename of the excel file. If not provided, the name of the file 22 | is built using the names of the groups being compared.} 23 | } 24 | \description{ 25 | Save the HRV indices as an excel file 26 | } 27 | -------------------------------------------------------------------------------- /man/SetVerbose.Rd: -------------------------------------------------------------------------------- 1 | \name{SetVerbose} 2 | \alias{SetVerbose} 3 | \title{ Sets verbose mode on or off } 4 | \description{ 5 | Sets verbose mode on or off, verbose is a boolean component of the data structure HRVData that allows to specify if all the functions return additional information } 6 | \usage{ 7 | SetVerbose(HRVData, Verbose) 8 | } 9 | \arguments{ 10 | \item{HRVData}{ Data structure that stores the beats register and information related to it } 11 | \item{Verbose}{ Boolean argument that allows to specify if the function returns additional information } 12 | } 13 | \value{ 14 | Returns HRVData, the structure that will contain beat positions register, associated heart rate instantaneous values, filtered heart rate signal equally spaced, and one or more analysis structures 15 | } 16 | \references{ 17 | L. Rodriguez-Linares, A. Mendez, M. Lado, D. Olivieri, X. Vila, I. Gomez-Conde, "An open source tool for heart rate variability spectral analysis", Computer Methods and Programs in Biomedicine 103, 39-50, doi:10.1016/j.cmpb.2010.05.012 (2011) 18 | } 19 | \author{ 20 | M. Lado, A. Mendez, D. Olivieri, L. Rodriguez, X. Vila 21 | } 22 | \keyword{ misc } 23 | -------------------------------------------------------------------------------- /man/SplitHRbyEpisodes.Rd: -------------------------------------------------------------------------------- 1 | \name{SplitHRbyEpisodes} 2 | \alias{SplitHRbyEpisodes} 3 | \title{ Splits Heart Rate Data using Episodes information } 4 | \description{ 5 | Splits Heart Rate Data in two parts using an specific episode type: data inside episodes and data outside episodes 6 | } 7 | \usage{ 8 | SplitHRbyEpisodes(HRVData, Tag = "", verbose=NULL) 9 | } 10 | \arguments{ 11 | \item{HRVData}{ Data structure that stores the beats register and information related to it } 12 | \item{Tag}{ Type of episode } 13 | \item{verbose}{ Deprecated argument maintained for compatibility, use SetVerbose() instead } 14 | } 15 | \value{ 16 | Returns a list with two vectors that is, the values of Heart Rate Data inside and outside episodes 17 | } 18 | \references{ 19 | L. Rodriguez-Linares, A. Mendez, M. Lado, D. Olivieri, X. Vila, I. Gomez-Conde, "An open source tool for heart rate variability spectral analysis", Computer Methods and Programs in Biomedicine 103, 39-50, doi:10.1016/j.cmpb.2010.05.012 (2011) 20 | } 21 | \author{ 22 | M. Lado, A. Mendez, D. Olivieri, L. Rodriguez, X. Vila 23 | } 24 | \seealso{ 25 | \code{\link{AnalyzeHRbyEpisodes}} for processing Heart Rate Data using an specific episode type 26 | } 27 | \keyword{ misc } 28 | -------------------------------------------------------------------------------- /man/SplitPowerBandByEpisodes.Rd: -------------------------------------------------------------------------------- 1 | \name{SplitPowerBandByEpisodes} 2 | \alias{SplitPowerBandByEpisodes} 3 | \title{ Splits Power Per Band using Episodes information } 4 | \description{ 5 | Splits Power per Band in two lists using an specific episode type: data inside 6 | episodes and data outside episodes 7 | } 8 | \usage{ 9 | SplitPowerBandByEpisodes(HRVData, indexFreqAnalysis = 10 | length(HRVData$FreqAnalysis), Tag = "", 11 | verbose=NULL) 12 | } 13 | \arguments{ 14 | \item{HRVData}{ Data structure that stores the beats register and information 15 | related to it } 16 | \item{indexFreqAnalysis}{ Reference to the data structure that will contain 17 | the variability analysis } 18 | \item{Tag}{ Type of episode } 19 | \item{verbose}{ Deprecated argument maintained for compatibility, use 20 | SetVerbose() instead } 21 | } 22 | \value{ 23 | Returns a list with two lists: InEpisodes and OutEpisodes, both lists include 24 | ULF, VLF, LF and HF bands 25 | } 26 | \references{ 27 | L. Rodriguez-Linares, A. Mendez, M. Lado, D. Olivieri, X. Vila, I. Gomez-Conde, "An open sourcetool for heart rate variability spectral analysis", Computer Methods and Programs in Biomedicine 103, 39-50, doi:10.1016/j.cmpb.2010.05.012 (2011) 28 | } 29 | \author{ 30 | M. Lado, A. Mendez, D. Olivieri, L. Rodriguez, X. Vila 31 | } 32 | \seealso{ 33 | \code{\link{CalculatePowerBand}} for power calculation 34 | } 35 | \keyword{ misc } 36 | -------------------------------------------------------------------------------- /man/Window.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/ExtractTimeSegment.R 3 | \name{Window} 4 | \alias{Window} 5 | \title{Time windows of RR intervals} 6 | \usage{ 7 | Window(HRVData, start, end) 8 | } 9 | \arguments{ 10 | \item{HRVData}{Data structure that stores the beats register and information 11 | related to it.} 12 | 13 | \item{start}{The start time of the period of interest.} 14 | 15 | \item{end}{The end time of the period of interest.} 16 | } 17 | \value{ 18 | A new \emph{HRVData} structure containing the subset of RR intervals 19 | within the specified range. 20 | } 21 | \description{ 22 | Extracts a temporal subset between the times start and end. 23 | } 24 | \details{ 25 | If the \emph{HRVData} episodes, beats or RR time series, 26 | these will be also extracted into the new HRV structure. On the other hand, 27 | all the analysis stored in the original structure will be lost. 28 | } 29 | \examples{ 30 | \dontrun{ 31 | data(HRVProcessedData) 32 | # Rename for convenience 33 | HRVData <- HRVProcessedData 34 | PlotNIHR(HRVData) 35 | newHRVData <- Window(HRVData,2000,4000) 36 | PlotNIHR(newHRVData) 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /man/WriteToFile.Rd: -------------------------------------------------------------------------------- 1 | \name{WriteToFile} 2 | \alias{WriteToFile} 3 | \title{ Writes data structure to a file } 4 | \description{ 5 | Writes the data structure containing beat positions and all derived calculations to a file 6 | } 7 | \usage{ 8 | WriteToFile(HRVData, name, overwrite = TRUE, verbose=NULL) 9 | } 10 | \arguments{ 11 | \item{HRVData}{ Data structure that stores the beats register and information related to it } 12 | \item{name}{ The name of the file to be used } 13 | \item{overwrite}{ Boolean argument for indicating what to do if the file already exists } 14 | \item{verbose}{ Deprecated argument maintained for compatibility, use SetVerbose() instead } 15 | } 16 | \references{ 17 | L. Rodriguez-Linares, A. Mendez, M. Lado, D. Olivieri, X. Vila, I. Gomez-Conde, "An open source tool for heart rate variability spectral analysis", Computer Methods and Programs in Biomedicine 103, 39-50, doi:10.1016/j.cmpb.2010.05.012 (2011) 18 | } 19 | \author{ 20 | M. Lado, A. Mendez, D. Olivieri, L. Rodriguez, X. Vila 21 | } 22 | \keyword{ IO } 23 | \keyword{ connection } 24 | -------------------------------------------------------------------------------- /man/getNormSpectralUnits.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/CalculatePowerBand.R 3 | \name{getNormSpectralUnits} 4 | \alias{getNormSpectralUnits} 5 | \title{Normalized Spectral Units} 6 | \usage{ 7 | getNormSpectralUnits( 8 | HRVData, 9 | indexFreqAnalysis = length(HRVData$FreqAnalysis), 10 | VLFnormalization = T 11 | ) 12 | } 13 | \arguments{ 14 | \item{HRVData}{Data structure that stores the beats register and information related to it} 15 | 16 | \item{indexFreqAnalysis}{Reference to the data structure that contains the spectrogram analysis} 17 | 18 | \item{VLFnormalization}{Logical value. If TRUE (default), the function 19 | normalizes LF and HF power series by its sum. If FALSE, the function computes 20 | VLF, LF and HF power series by its sum.} 21 | } 22 | \value{ 23 | The \emph{getNormSpectralUnits} returns a list storing the resulting 24 | normalized power-band series. Note that this list is not stored in the 25 | \emph{HRVData} structure. 26 | } 27 | \description{ 28 | Calculates the spectrogram bands in normalized units 29 | } 30 | \details{ 31 | The default behaviour of this function computes the normalized power 32 | time series in the LF and HF bands following the Task Force recommendations: 33 | 34 | \deqn{normalized\_LF = LF\_power / (total\_power - VLF\_power - ULF\_power)}{ 35 | normalized_LF = LF_power / (total_power - VLF_power - ULF_power)} 36 | \deqn{normalized\_HF = HF\_power / (total\_power - VLF\_power -ULF\_power)}{ 37 | normalized_HF = HF_power / (total_power - VLF_power -ULF-power)} 38 | 39 | If \emph{VLFnormalization} is set to FALSE, the functions computes: 40 | \deqn{normalized\_VLF = VLF\_power / (total\_power - ULF\_power)}{ 41 | normalized_VLF = VLF_power / (total_power - ULF_power)} 42 | \deqn{normalized\_LF = LF\_power / (total\_power - ULF\_power)}{ 43 | normalized_LF = LF_power / (total_power - ULF_power)} 44 | \deqn{normalized\_HF = HF\_power / (total\_power - ULF\_power)}{ 45 | normalized_HF = HF_power / (total_power - ULF_power)} 46 | 47 | The resulting time series are returned in a list. Note that before using this 48 | function, the spectrogram should be computed with the \emph{CalculatePowerBand} 49 | function. 50 | } 51 | \examples{ 52 | \dontrun{ 53 | # load some data... 54 | data(HRVProcessedData) 55 | hd = HRVProcessedData 56 | # Perform some spectral analysis and normalize the results 57 | hd = CreateFreqAnalysis(hd) 58 | hd = CalculatePowerBand(hd,indexFreqAnalysis = 1,shift=30,size=60) 59 | normUnits = getNormSpectralUnits(hd) 60 | # plot the normalized time series 61 | par(mfrow=c(2,1)) 62 | plot(normUnits$Time, normUnits$LF, xlab="Time", ylab="normalized LF", 63 | main="normalized LF",type="l") 64 | plot(normUnits$Time, normUnits$HF, xlab="Time", ylab="normalized HF", 65 | main="normalized HF",type="l") 66 | par(mfrow=c(1,1)) 67 | 68 | } 69 | } 70 | \references{ 71 | Camm, A. J., et al. "Heart rate variability: standards of measurement, physiological interpretation and clinical use. 72 | Task Force of the European Society of Cardiology and the North American Society of 73 | Pacing and Electrophysiology." Circulation 93.5 (1996): 1043-1065. 74 | } 75 | -------------------------------------------------------------------------------- /man/nonLinearNoiseReduction.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/NonLinearNoiseReduction.R 3 | \name{NonLinearNoiseReduction} 4 | \alias{NonLinearNoiseReduction} 5 | \title{Nonlinear noise reduction} 6 | \usage{ 7 | NonLinearNoiseReduction( 8 | HRVData, 9 | embeddingDim = NULL, 10 | radius = NULL, 11 | ECGsamplingFreq = NULL 12 | ) 13 | } 14 | \arguments{ 15 | \item{HRVData}{Data structure that stores the beats register and information 16 | related to it} 17 | 18 | \item{embeddingDim}{Integer denoting the dimension in which we shall embed 19 | the RR time series.} 20 | 21 | \item{radius}{The radius used to looking for neighbours in the phase space 22 | (see details). If the radius is not specified, a radius depending on the 23 | resolution of the RR time series is used. The resolution depends 24 | on the \emph{ECGsamplingFreq} parameter. When selecting 25 | the radius it must be taken into account that the RR series is specified in 26 | milliseconds.} 27 | 28 | \item{ECGsamplingFreq}{The sampling frequency of the ECG from which the RR 29 | time series was derived. Although it is not necessary, if it is provided it 30 | may improve the noise reduction. If the \emph{ECGsamplingFreq} is 31 | not supplied, the sampling frequency is derived from the RR data.} 32 | } 33 | \value{ 34 | A HRVData structure containing the denoised RR time series. 35 | } 36 | \description{ 37 | Function for denoising the RR time series using nonlinear analysis techniques. 38 | } 39 | \details{ 40 | This function takes the RR time series and denoises it. The denoising 41 | is achieved by averaging each Takens' vector in an m-dimensional space 42 | with his neighbours (time lag=1). Each neighbourhood is specified with balls 43 | of a given radius 44 | (max norm is used). 45 | } 46 | \note{ 47 | This function is based on the \code{\link[nonlinearTseries]{nonLinearNoiseReduction}} function from the 48 | nonlinearTseries package. 49 | } 50 | \references{ 51 | H. Kantz and T. Schreiber: Nonlinear Time series Analysis (Cambridge university press) 52 | } 53 | \seealso{ 54 | \code{\link[nonlinearTseries]{nonLinearNoiseReduction}} 55 | } 56 | -------------------------------------------------------------------------------- /src/filterhr.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void filterhr(double *hr, int *n, int *lon, int *last, int *minbpm, int *maxbpm, 5 | int *index) { 6 | int i, ulast, umean; 7 | double *buffer, med, desv(double *, double, int), tmp; 8 | buffer = (double *) malloc((*lon) * sizeof(double)); 9 | ulast = *last; 10 | umean = 1.5 * (*last); 11 | med = buffer[0] = hr[0]; 12 | index[0] = 1; 13 | for (i = 1; i < (*n) - 1; i++) { 14 | if (i < (*lon)) { 15 | med = (med * i + hr[i]) / (i + 1); 16 | buffer[i] = hr[i]; 17 | } else { 18 | med = (med * (*lon) + (hr[i] - buffer[i % (*lon)])) / (*lon); 19 | buffer[i % (*lon)] = hr[i]; 20 | } 21 | if ((100 * fabs(hr[i] - hr[i - 1]) / hr[i - 1] < ulast || 22 | 100 * fabs(hr[i] - hr[i + 1]) / hr[i + 1] < ulast || 23 | 100 * fabs(hr[i] - med) / med < umean) && hr[i] > (*minbpm) && hr[i] < (*maxbpm)) { 24 | index[i] = 1; 25 | } else 26 | index[i] = 0; 27 | if (i % (*lon) == 0 && i >= (*lon)) { 28 | tmp = 10 + desv(buffer, med, (*lon)); 29 | if (tmp < 12) 30 | tmp = 12; 31 | if (tmp > 20) 32 | tmp = 20; 33 | ulast = (int) tmp; 34 | umean = (int) (1.5 * ulast); 35 | } 36 | } 37 | free(buffer); 38 | } 39 | 40 | double desv(double *data, double med, int n) { 41 | int i; 42 | double v; 43 | v = 0; 44 | for (i = 0; i < n; i++) { 45 | v += pow((data[i] - med), 2.0); 46 | } 47 | return sqrt((double) (v / (double) n)); 48 | } 49 | -------------------------------------------------------------------------------- /src/pmodwpt.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | 9 | void modwtLP(double *Vin, int *N, int *j, int *L, double *ht, double *gt, 10 | double *Wout, double *Vout){ 11 | int k, n, t; 12 | for(t = 0; t < *N; t++) { 13 | k = t; 14 | Vout[t] = gt[0] * Vin[k]; 15 | for(n = 1; n < *L; n++) { 16 | k -= (int) pow(2.0, (double) *j - 1.0); 17 | if(k < 0) k += *N; 18 | Vout[t] += gt[n] * Vin[k]; 19 | } 20 | } 21 | } 22 | 23 | 24 | 25 | void modwtHP(double *Vin, int *N, int *j, int *L, double *ht, double *gt, 26 | double *Wout, double *Vout){ 27 | int k, n, t; 28 | for(t = 0; t < *N; t++) { 29 | k = t; 30 | Wout[t] = ht[0] * Vin[k]; 31 | for(n = 1; n < *L; n++) { 32 | k -= (int) pow(2.0, (double) *j - 1.0); 33 | if(k < 0) k += *N; 34 | Wout[t] += ht[n] * Vin[k]; 35 | } 36 | } 37 | } 38 | 39 | 40 | 41 | 42 | void modwtBoth(double *Vin, int *N, int *j, int *L, double *ht, double *gt, 43 | double *Wout, double *Vout){ 44 | int k, n, t; 45 | 46 | for(t = 0; t < *N; t++) { 47 | k = t; 48 | Wout[t] = ht[0] * Vin[k]; 49 | Vout[t] = gt[0] * Vin[k]; 50 | for(n = 1; n < *L; n++) { 51 | k -= (int) pow(2.0, (double) *j - 1.0); 52 | if(k < 0) k += *N; 53 | Wout[t] += ht[n] * Vin[k]; 54 | Vout[t] += gt[n] * Vin[k]; 55 | } 56 | } 57 | } 58 | 59 | 60 | 61 | void pmodwpt(double *Vin, int *N, int *j,int *code, int *L, double *ht, double *gt, 62 | double *Wout, double *Vout) 63 | { 64 | //Rprintf("Complete brunch...\n"); 65 | if (*code==0){//just the low pass filter 66 | modwtLP(Vin,N,j,L,ht,gt,Wout,Vout); 67 | return; 68 | } 69 | if (*code==1){//just the high pass filter 70 | modwtHP(Vin,N,j,L,ht,gt,Wout,Vout); 71 | return; 72 | } 73 | if (*code==2){//both filters 74 | modwtBoth(Vin,N,j,L,ht,gt,Wout,Vout); 75 | return; 76 | } 77 | 78 | 79 | } 80 | 81 | 82 | -------------------------------------------------------------------------------- /src/rhrv_init.c: -------------------------------------------------------------------------------- 1 | // Output generated with tools::package_native_routine_registration_skeleton(".") 2 | #include // for NULL 3 | #include 4 | 5 | /* .C calls */ 6 | extern void filterhr(void *, void *, void *, void *, void *, void *, void *); 7 | extern void pmodwpt(void *, void *, void *, void *, void *, void *, void *, void *, void *); 8 | 9 | static const R_CMethodDef CEntries[] = { 10 | {"filterhr", (DL_FUNC) &filterhr, 7}, 11 | {"pmodwpt", (DL_FUNC) &pmodwpt, 9}, 12 | {NULL, NULL, 0} 13 | }; 14 | 15 | void R_init_RHRV(DllInfo *dll) { 16 | R_registerRoutines(dll, CEntries, NULL, NULL, NULL); 17 | R_useDynamicSymbols(dll, FALSE); 18 | } 19 | -------------------------------------------------------------------------------- /vignettes/figures/basicHRVData.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cran/RHRV/81e6e62185c20ba841ace0e934cbd2eabdf453a3/vignettes/figures/basicHRVData.pdf -------------------------------------------------------------------------------- /vignettes/figures/basicHRVData.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cran/RHRV/81e6e62185c20ba841ace0e934cbd2eabdf453a3/vignettes/figures/basicHRVData.png --------------------------------------------------------------------------------