Garmin FIT files for RHRV analysis

4. Wevlet analysis

Author

Kizen Sasaki

First version

2023 November 30

Modified

2023 December 04

Fourier analysis and Plotting Fourier analysis
Code
library(readr)
library(RHRV)
Code
FileNo <- 1
FileName <- paste0("time_HR_", FileNo, ".csv")

data <- read.table(file.path("csv_xls", FileName), header = TRUE, sep = ",", 
                   colClasses = c("character", "numeric"))
Code
hr <- data[,2]
rr <- 1/hr
rr = rr*60*1000
Code
hrv.data <- CreateHRVData()
hrv.data <- SetVerbose(hrv.data, TRUE)
hrv.data$Beat$RR = rr
hrv.data$Beat$niHR = hr
hrv.data$Beat$Time = cumsum(rr)/1000
hrv.data <- BuildNIHR(hrv.data)
hrv.data <- FilterNIHR(hrv.data)
hrv.data <- InterpolateNIHR(hrv.data, freqhr = 4)

hrv.data <- CreateFreqAnalysis(hrv.data)
hrv.data <- SetVerbose(hrv.data, TRUE)
Code
hrv.data <- CalculatePowerBand(hrv.data, 
                               indexFreqAnalysis = 1,
                               type = "wavelet", wavelet = "la8",
                               bandtolerance = 0.01, relative = FALSE)

When using wavelet analysis with the CalculatePowerBand function, the user may specify:

  • Wavelet: mother wavelet used to calculate the spectrogram. Some of the most widely used wavelets are available: Haar (“haar”), extremal phase (“d4”, “d6”, “d8” and “d16”) and the least asymmetric Daubechies (“la8”, “la16” and “la20”) and the best localized Daubechies (“bl14” and “bl20”) wavelets among others. The default value is “d4”. The name of the wavelet specifies the “family” (the family determines the shape of the wavelet and its properties) and the length of the wavelet. For example, “la8” belongs to the Least Asymmetric family and has a length of 8 samples. We may give a simple advice for wavelet selection based on the wavelet’s length: shorter wavelets usually have better temporal resolution, but worse frequency resolution. On the other hand, longer wavelets usually have worse temporal resolution, but they provide better frequency resolution. Better temporal resolution means that we can study shorter time intervals. On the other hand, a better frequency resolution means better “frequency discrimination”. That is, shorter wavelets will tend to fail when discriminating close frequencies.
  • Bandtolerance: maximum error allowed when the wavelet-based analysis is performed [12], [13]. It can be specified as either an absolute or a relative error depending on the “relative” parameter value. Default value is 0.01.
  • Relative: logic value specifying which type of band tolerance shall be used: relative (in percentage) or absolute (default value)
    Let [fl, fu] be any frequency band specified by the user and let [f1, f2] be a frequency interval associated with some node in the Maximal Overlap Discrete Wavelet Packet Transform (MODWPT) tree [29]. The relative error ϵr of fl over the [f1, f2] interval is computed as   ϵr ≡ \frac{\lvert fl - f1 \rvert}{\lvert fu - fl \rvert} \cdot 100\% Similarly, we may define the error ϵr of the upper frequency fu as
    ϵr ≡ \frac{ \lvert fu - f2 \rvert}{ \lvert fu - fl \rvert} \cdot 100\% The relative error can be used to avoid introducing large errors at small frequency bands (usually both ULF and VLF bands).

The absolute value ϵ is defined as usual: ϵ =|f2 − fu| for the upper frequency and ϵ = |f1 − fl| for the lower frequency.

Plotting Wevelet analysis

Figure 1 Wevelet analysis ymax = 700, ymaxratio = 50

Figure 1: Plot obtained with the PlotPowerBand for the wavelet analysis.