Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue running toolbox #25

Open
nthanapaisal opened this issue Jun 1, 2020 · 4 comments
Open

Issue running toolbox #25

nthanapaisal opened this issue Jun 1, 2020 · 4 comments

Comments

@nthanapaisal
Copy link

Describe the bug
Hello, so I have tested the demo and it works but I'm having a problem where when I try to run the tool box using raw ECG signal, I couldn't get the time domain indicators from the toolbox. .csv file were empty but only show the window t_start and t_end. The only way for me to do this is to pass in raw signal using 'ECGWaveform', get the RR intervals and it's time from your toolbox, save it into a file then run the toolbox again using 'RRIntervals' and it gave me the indicators just fine. I'm not sure if this is the ideal way to run this.

I wrote a new script containing these code for getting rr intervals and its time

  1. run([pwd filesep 'startup.m'])
  2. Fs = 128;
  3. HRVparams = InitializeHRVparams('Demo');
  4. HRVparams.Fs = Fs;
  5. [HRVout1, ResultsFileName1] = Main_HRV_Analysis(ekgSignal,[],'ECGWaveform',HRVparams,'1');

then there's another script after I saved rr intervals and its time from your toolbox

  1. HRVparams = InitializeHRVparams('Demo');
  2. Fs = 128;
  3. HRVparams.Fs = Fs;
  4. [HRVOUTpn, ResultsFileNamePn ] = Main_HRV_Analysis(physionetRR,physionetT,'RRIntervals',HRVparams,'1');

I want to be able to just run the toolbox once and generate the indicators for me without me having to save rr intervals and its time. I wonder what is the correct way to do this? Also for InitializeHRVparams('Demo'), I want to use the default values and not change anything is this correct?

  • Matlab version: MATLAB2019a
@monaelsayed
Copy link

monaelsayed commented Jun 9, 2020

I seem to be having similar issues - I get empty results when I run raw ECG. But even when I input my own RR data it does not work properly/I am not able to obtain the RR peaks from the toolbox using raw ECG.

I keep getting this error:
*** Warning!***
The signal is shorter than the analysis window length
HRV analyis can fail!

AF analysis completed for subject 1

In Main_HRV_Analysis (line 194)
HRVoutput =
NaN
Results =
0×0 empty char array

Not sure what is wrong here. What does your RR output look like, does it capture the whole QRS complex (I have seen this in the Basic demo?) and does it have to be a specific length? For example, is 100 RR data points too short to be analyzed by the toolbox?

Also What does your t variable look like? I am confused by this because RR data is not uniformly sampled so how is there a time value/how is that obtained?

At one point it worked but it gave a mostly empty csv file with a column of 3's under tdflag and fdflag? Not sure what these even mean.

Any ideas?

Thanks!!

@nthanapaisal
Copy link
Author

Hello,

I apologized if my English is a little hard to understand but..

I'm not really sure if the length matter..but I know that in the toolbox code, it does take in the length to generate the number of windows needed.

Using raw ECG signal as an input:
I have been trying to insert my raw ECG signal and hoping for it to generate my time domain indicators. Not sure if it's something wrong with my signal or it's a bug?

Using RR intervals + time as an input:
I got my RR and time from ConvertRawDataToRRIntervals() function. So this happens to me a couple times, depending on the RR intervals, some of the results is an empty file with columns. So I traced the code for ONE of the signal ( I can't guarantee it's the same for the others) and noticed that after the code analyzed and calculated the number of windows needed, it use Atrial Fibrillation Detection to remove beginning point of the windows containing AF segments. This causes the toolbox to remove those segments (windows) for this signal.

Example:
I have 3 windows total:
0-300: results
30-330: results
60-360: empty because AF detection

If I figured something out or found the way to fix this, I'll let you know.

@GiuliaDAP
Copy link
Contributor

GiuliaDAP commented Jun 10, 2020

Hello,

I keep getting this error:
*** Warning!***
The signal is shorter than the analysis window length
HRV analyis can fail!

Length of the signals matter: if it is shorter than the length of the analysis window it will result in an error
If you read the InitializeHRVparams.m you will understand that ECG is analyzed in windows of a length equal to:

HRVparams.windowlength = 300;	      % Default: 300, seconds
HRVparams.increment = 30;             % Default: 30, seconds increment

Thus, if your ECG signal is short this will result in not enough points to compute the parameters within the window. (Window length can be changes as all the other parameters)

Also What does your t variable look like? I am confused by this because RR data is not uniformly sampled so how is there a time value/how is that obtained?

At one point it worked but it gave a mostly empty csv file with a column of 3's under tdflag and fdflag? Not sure what these even mean.

Readme file contains the description of each output parameter including tdflg and fdflg.

Using raw ECG signal as an input:
I have been trying to insert my raw ECG signal and hoping for it to generate my time domain indicators. Not sure if it's something wrong with my signal or it's a bug?

Using RR intervals + time as an input:
I got my RR and time from ConvertRawDataToRRIntervals() function. So this happens to me a couple times, depending on the RR intervals, some of the results is an empty file with columns. So I traced the code for ONE of the signal ( I can't guarantee it's the same for the others) and noticed that after the code analyzed and calculated the number of windows needed, it use Atrial Fibrillation Detection to remove beginning point of the windows containing AF segments. This causes the toolbox to remove those segments (windows) for this signal.

The reason why the output file has empty column values is that for that analysis window the SQI (signal quality) was to low (on average) or AF was detected. If you use directly the RR intervals without also using the SQI (which are generated by ConvertRawDataToRRIntervals()) then you will bypass the SQI control. Using the raw ECG as input will always include the SQI check.

Note that: empty values when SQI is too low (or AF is present) is intentional, do not try to modify the code. If you like to set a different threshold for the SQI then change the corresponding parameters in InitializeHRVparams.m
You can also disable the AF check (NOT recommended)
HRVparams.af.on = 1; % Default: 1, AF Detection On or Off

Please, read the README file, paper, and comments in the InitializeHRVparams

@monaelsayed
Copy link

Thank you both for your input, help, and advice!

Because the demo data was working fine for me, I came to realize that the issue was with my raw data.
When I compared the two, I realized that my raw data was somewhat too noisy compared to the DemoRawDataICU.
When I filtered my raw data (by detrending/bandpass filtering), the toolbox worked and I got results. For my data, I did not have to turn off AF detection or change the SQI.
I'm not sure if this is the correct way to solve the problem but I compared the results with some of my own analyses and they were quite similar.

When my data was not filtered I would get 2's in my td and flag columns meaning:

  • tdflag : 2 = not enough high SQI data in the window to process
    (amount of data above threshold1 is greater than threshold2)

Thus, changing the threshold may also help, but I don't know how much you can play around with this without influencing the accuracy of the results? Any guidance/guidelines (I don't think I see an in the README)?

It seems that empty results also occur when the data is not long enough, so you have to play around a little bit with the window size parameters.
Any guidance on this? I have checked the README but I do not see guidelines for this?
Does it vary based on the sampling rate?
For example, when I had 1700 datapoint (250 sampling rate) ~about a minute of data, the default window size parameters give me empty results. I think Fs would influence the results since even though the data length is >300, there may not be enough RR peaks/QRS complexes detected ?
When I changed the window length and increment to 30 and 10, respectively, I got results.

Please let me know if you have any questions/additional suggestions!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants