SCM

Forum: help

Monitor Forum | Start New Thread Start New Thread
RE: frequency domain analysis parameters and other stuff [ Reply ]
By: Constantino Antonio on 2019-08-28 17:55
[forum:46929]

freq_episodes.R (25) downloads
Dear Adeline,

Please find attached an example for analyzing several band frequencies in different temporal episodes.

Hope this helps

RE: frequency domain analysis parameters and other stuff [ Reply ]
By: Adeline Lacroix on 2019-07-17 12:40
[forum:46861]
Dear Constantino,

Once again, I thank you very much.

The script for the time domain analysis works perfectly.

However, I'm still struggling with the frequency domain analysis. As for the time domain, I would like a data frame with each row corresponding to a subject and each column corresponding to one power band (like ULF_1, VLF_1,LF_1, HF_1, ULF_2 etc). I tried to start from the other code you gave me, but it does not work.

I tried this:
analyze_freq = function(file, max_tags = 10) {
hdFreq = CreateHRVData()
hdFreq = LoadBeatAscii(hdFreq, "1A_CHANI_lab.csv", RecordPath =".")
hdFreq = BuildNIHR(hdFreq)
beg = seq(hdFreq$Beat$Time[[1]], tail(hdFreq$Beat$Time, 1), by = 180)
n = length(beg)
hdFreq = AddEpisodes(hdFreq,
InitTimes = beg,
Durations = rep(180, n),
Tags = 1:n,
Values = rep("", n))
hdFreq = FilterNIHR(hdFreq)
hdFreq = InterpolateNIHR (hdFreq, freqhr = 4)

tags = as.character(1:max_tags)

for (tag in tags) {
hdFreq = CreateFreqAnalysis(hdFreq, Tag = tag)
hdFreq =CalculatePSD(hdFreq , 1, "pgram", spans = 9)
delta1 = median(diff(hdFreq $FreqAnalysis[[1]]$periodogram$freq))
results2 =CalculateEnergyInPSDBands(hdFreq, 1)*delta3

if (tag == tags[[1]]) {
all_results2 = results2
} else {
all_results2 = cbind(all_results2, results2)
}
}

all_results2$file = file
return(all_results2)
}


But I assume it doesn't work because of the middle part of the code...
I also tried to replace this middle part with this:

hdFreq = CreateFreqAnalysis(hdFreq)
hdFreq =CalculatePowerBand (hdFreq,indexFreqAnalysis= 1, type =
+"wavelet", wavelet = "la8", bandtolerance = 0.01, relative = FALSE)
splitting.data = SplitPowerBandByEpisodes(hdFreq, indexFreqAnalysis = 1, Tag = tag)
results2 = as.data.frame (splitting.data$resultIn)

But this doesn't work neither. If you could still help me with this problem, it would be very appreciated.

Best,

Adeline




RE: frequency domain analysis parameters and other stuff [ Reply ]
By: Constantino Antonio on 2019-05-06 13:47
[forum:46671]

script.R (25) downloads
Dear Adeline,

Sorry for the late reply.

1) Please find attached an script that illustrates how to obtain the desired data.frame with the time domain analysis (with each row corresponding to a subject and each column corresponding to one parameter).

2) I think it is fine to set the size to 60 (a minute). The interval is used for constructing histograms (using this interval as bindwidth). It is a nice default value and therefore I wouldn't change it unless there is a good reason for it.

3) The CalculatePowerBand should work. There is an example illustrating how to apply it with the episodes information in page 94 of http://rhrv.r-forge.r-project.org/tutorial/tutorial.pdf

Hope this helps

RE: frequency domain analysis parameters and other stuff [ Reply ]
By: Adeline Lacroix on 2019-04-24 17:15
[forum:46657]

CHANI.csv (15) downloads
Hi,

I progressed a little bit but any further help would be really appreciated...

1/ I downloaded the function CreateTimeAnalysisByEpisode but its obective is to analyse "in" and "out" episodes. Consequently, I don't know how to do time domain analysis not just for "in" and "out" episodes but for each of my label (In other words: in my code below, when I use the CreateTimeAnalysisByEpisodes, I have Time analysis for R1 and for every episodes out of R1 taken together; is there a simple way to have the analysis for R1, R2, R3 etc, and to have all of them in the same data structure?)

2/ When I try to do Frequency analysis, I have an error message: "Error in if (verbose) { : argument is of length zero"
How can I do the frequency domain analysis on each of my 10 "episodes" (I would like to have all the results in the same data structure as well because I have to do the same with a lot of participants and my first task is to have all the result in the same spreadshit).

Best regards,

Adeline

hrv.CHANIall = CreateHRVData ()
hrv.CHANIall = SetVerbose(hrv.CHANIall, TRUE)
hrv.CHANIall = LoadBeatAscii(hrv.CHANIall,"CHANI.csv",RecordPath =".")
plot(hrv.CHANIall$Beat$Time)

#adding info about episode
hrv.CHANIall = AddEpisodes(hrv.CHANIall, InitTimes = c(9468, 9648,9828, 10008,10188,10368, 10548,10728,10908,11088),
Tags = c("R1", "R2","R3","R4","R5","S","R6","R7","R8","R9"),
Durations =c(180, 180,180, 180,180, 180,180, 180,180, 180),
Values = c(0,0,0,0,0,0,0,0,0,0))

#instantaneous heart rate
hrv.CHANIall= BuildNIHR(hrv.CHANIall)

#removing artifacts
hrv.CHANIall= FilterNIHR(hrv.CHANIall)
PlotNIHR(hrv.CHANIall, Tag = "all")

#interpolation
hrv.CHANIall = InterpolateNIHR (hrv.CHANIall,freqhr = 4)
PlotHR(hrv.CHANIall,Tag = "all")


#ANALYSIS
#TIME-DOMAIN ANALYSIS
hrv.CHANIall = CreateTimeAnalysisByEpisodes(hrv.CHANIall, size=60, interval = 7.8125, Tag= "R1")

#FREQUENCY-DOMAIN ANALYSIS
hrv.CHANIall = CreateFreqAnalysis(hrv.CHANIall)
hrv.CHANIall = CalculatePowerBand(hrv.CHANIall, indexFreqAnalysis = 1, size = 120, shift = 10, sizesp= 2048,type = "fourier", ULFmin = 0, ULFmax = 0.03, VLFmin = 0.03,VLFmax = 0.05,LFmin = 0.05,LFmax = 0.15,HFmin = 0.15,HFmax = 0.4)

PlotPowerBand(hrv.CHANIall, indexFreqAnalysis = 1, ymax = 2500, ymaxratio = 1.4)

hrv.data = CreateFreqAnalysis(hrv.CHANIall) # for creating a second frequency analysis
hrv.data = CalculatePowerBand(hrv.CHANIall,indexFreqAnalysis = 2,type = "wavelet", wavelet = "la8", bandtolerance=0.01, relative = FALSE, ULFmin = 0, ULFmax = 0.03, VLFmin = 0.03,VLFmax = 0.05,LFmin = 0.05,LFmax = 0.15,HFmin = 0.15,HFmax = 0.4)
#model used = less asymetric8 and band tolerance = 0.01 hz

PlotPowerBand(hrv.CHANIall, indexFreqAnalysis = 2, ymax=200, ymaxratio = 50)
spectrogram = PlotSpectrogram(HRVData = hrv.CHANIall, size = 300, shift = 60, sizesp = 2048,
freqRange = c(0,0.2))

frequency domain analysis parameters and other stuff [ Reply ]
By: Adeline Lacroix on 2019-04-15 12:51
[forum:46656]

essai2.csv (17) downloads
Hello,

I have 24hrs heart records from 2 population that I will compare: autistic and control.
During this 24 hours, there are 30 minutes in a laboratory.
During this 30 minutes, subjects are relaxing, but there is a stressfull noise during 30 seconds.

For each subject, I have to calculate time domain and frequency domain parameters for the 10 intervals of 3 minutes during the 30 minutes.
Then I have to store them in a spreadsheet with each row corresponding to each subject and each column corresponding to one parameter (like rmssd_1, rmssd_2....., rmssd_10, pnn50_1, pnn50_2...).

1/ Is it possible to do that with RHRV? (I think yes but I would like to be sure).
Obviously, it is possible to "cut" each record and add tag (I saw this in the manual and here: https://r-forge.r-project.org/forum/forum.php?thread_id=31948&forum_id=2952&group_id=919). However, I wonder if I will then be able to export all parameters calculated in a spreadsheet?
I also saw (here: http://r-forge.r-project.org/forum/forum.php?thread_id=32071&forum_id=2952&group_id=919) that we can't analyse multiple subjects in the same analysis but obviously, I can do it in another manner. Am I right?

2/ My second question is related to the parameters setting of each function.
For the moment, I just try to calculate parameters for one subject, for a 3 minutes record.
- The time analysis domain seems to work (I found quite similar results to Kubios...not exactly the same but I think it's normal), but I'm full of doubts with my settings when I used the CreatTimeAnalysis function.
I fixed size to 60, because it analyses short segments and my record is only 180 s. Thus, I thought that I have to fix a shorter size. However, is there a kind of rule to fix the size regarding the size of our record?
I didn't change the interval parameter (7.8 ms), but I don't really understand to what it corresponds: when do we have to change it? why?

- the frequency domain analysis seems to work when I look in the data structure (I didn't try yet the wavelet), but I can't plot power band.
I saw there: http://r-forge.r-project.org/forum/forum.php?thread_id=32071&forum_id=2952&group_id=919, that with short time series, I should use CalculatePSD function.
Nevertheless, I'm till struggling to understand "the rule" to fix parameters of the function.Is there a way to plot power band if I change some settings?

Below, you can find my code and the parameters I used. My short data are attached.

Any answer would be appreciate.
Thank you very much for your help,

Best regards.

Adeline

#load data
hrv.data = LoadBeatAscii(hrv.data,"essai2.csv",RecordPath =".")
plot(hrv.data$Beat$Time)

#instantaneous heart rate
hrv.data= BuildNIHR(hrv.data)
PlotNIHR(hrv.data)

#removing artifacts
hrv.data= FilterNIHR(hrv.data)
PlotNIHR(hrv.data)

#interpolation
hrv.data = InterpolateNIHR (hrv.data,freqhr = 4)
PlotHR(hrv.data)

#ANALYSIS
#TIME-DOMAIN ANALYSIS
hrv.data = CreateTimeAnalysis(hrv.data, size=60, interval = 7.8125)


#FREQUENCY-DOMAIN ANALYSIS
hrv.data = CreateFreqAnalysis(hrv.data)
hrv.data = CalculatePowerBand(hrv.data, indexFreqAnalysis = 1, size = 180, shift = 20, sizesp= 1024,type = "fourier", ULFmin = 0, ULFmax = 0.03, VLFmin = 0.03,VLFmax = 0.05,LFmin = 0.05,LFmax = 0.15,HFmin = 0.15,HFmax = 0.4)

PlotPowerBand(hrv.data, indexFreqAnalysis = 1, ymax = 2500, ymaxratio = 1.4)

#saving results
timedata <- as.data.frame(hrv.data$TimeAnalysis)
write.table(timedata, "time.txt")
freqdata <- as.data.frame(hrv.data$FreqAnalysis)
write.table(freqdata, "freq.txt")

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