Hello, I've been trying to perform spectral analysis for hrv for some time already but there all the time problems with it.
I'm using such code:
%Spectral Analysis - WELCH metod
odstepRR=odstepRR.*1000; %odstepRR it an array with NN intervals
fs = 400;
maxF=fs/2;
odstepRR=detrend(odstepRR,'linear');
odstepRR=odstepRR-mean(odstepRR);
%Calculate PSD
[PSD,F] = pwelch(odstepRR,128,64,[],fs); %uses a hamming window
VLF = [0.0033 0.04];
LF = [0.04 0.15];
HF = [0.15 0.4];
% find the indexes corresponding to the VLF, LF, and HF bands
iVLF= (F>=VLF(1)) & (F<=VLF(2));
iLF = (F>=LF(1)) & (F<=LF(2));
iHF = (F>=HF(1)) & (F<=HF(2));
% calculate areas, within the freq bands (ms^2)
aVLF=trapz(F(iVLF),PSD(iVLF));
set(handles.vlf, 'string', num2str(aVLF));
aLF=trapz(F(iLF),PSD(iLF));
set(handles.lf, 'string', num2str(LF));
aHF=trapz(F(iHF),PSD(iHF));
set(handles.hf, 'string', num2str(aHF));
aTotal=aVLF+aLF+aHF;
set(handles.tp, 'string', num2str(aTotal));
% calculate areas relative to the total area (%)
% pVLF=(aVLF/aTotal)*100;
% pLF=(aLF/aTotal)*100;
% pHF=(aHF/aTotal)*100;
%calculate LF/HF ratio
lfhf =aLF/aHF;
axes(handles.axes5);
set(handles.text45, 'visible', 'on')
set(handles.axes5, 'visible', 'on')
%plot area under PSD curve
area(F(:),PSD(:),'FaceColor',[.6 .6 .6]);
grid on;
What am I doing wrong? The program doesn't count the spectral parameters (TP, HF, LF) and the plot is in different freq bands than it should be (on X axis freq should be 0.0-0.5 Hz). Shall be grateful for any help. ;)

3 commentaires

NICOLE MIN
NICOLE MIN le 30 Nov 2020
hi
i just want to know is there any solution to tour code above?
NICOLE MIN
NICOLE MIN le 30 Nov 2020
im stuck at calculating aLF onwards . please help
thanks
Apoorva Gangula
Apoorva Gangula le 24 Mai 2021
What is odstepRR here?
I'm doing a project for fetal heart rate analysis and need to do spectral analysis as a part of it
please answer this

Connectez-vous pour commenter.

 Réponse acceptée

Wayne King
Wayne King le 14 Mar 2012

0 votes

Hi Olga, I think your problem is that your frequency resolution is too poor.
You are only obtaining PSD estimates at steps of 1.5625 Hz. Look at:
diff(F)
This is based on your sampling frequency and window (segment) length.
Therefore the code:
VLF = [0.0033 0.04];
LF = [0.04 0.15];
HF = [0.15 0.4];
iVLF= (F>=VLF(1)) & (F<=VLF(2));
iLF = (F>=LF(1)) & (F<=LF(2));
iHF = (F>=HF(1)) & (F<=HF(2));
Is going to return a vector of zeros for iVLF, iLF, and iHF. Look at the output for
nnz(iVLF)
nnz(iLF)
nnz(iHF)
You are trying to obtain power estimates on a grid that is much finer than your frequency resolution.

6 commentaires

Olga
Olga le 15 Mar 2012
Maybe it is possibe to change my frequency resolution so that it'd be possible to obtain power estimates on level that I need?
Wayne King
Wayne King le 15 Mar 2012
You would have to increase the length of the data vector. I have asked you this question before in other similar posts. How many samples are in odstepRR?
Olga
Olga le 15 Mar 2012
The are 6672 bytes in odstepRR, that is 834 samples
Wayne King
Wayne King le 15 Mar 2012
Olga, unfortunately that is not enough samples to get the kind of frequency resolution you are after.
Olga
Olga le 15 Mar 2012
That's too bad. Thanks a lot for your help ;)
Bach
Bach le 27 Juil 2012
you can increase the number of FFT to improve the resolution. The frequency resolution = fs / nfft.

Connectez-vous pour commenter.

Plus de réponses (3)

Pradeep Kumar R
Pradeep Kumar R le 23 Fév 2016

1 vote

hi guys i'm doing a project of fetal heart rate variability analysis i'm finding difficult to find and plot the heart rate of fetal i've extracted the fetal signal but only heart rate part i'm not able to come to a solution please help me with that.i've attached my code please help me out
KYAW KYAW
KYAW KYAW le 26 Juil 2012

0 votes

Dear Wayne King,
I am facing problem for optimizing the peak frequency location in frequency domain analysis for normal and low respiratory rate.
Theoretically, the highest peak frequency must occured at 0.16667 Hz but in pratical is 0.164 to 0.1799(mostly 0.176 above).
My frequency resolution in X axis is 0.0078 which is in FFT only and I optimized then I got the wrost results.
The low frequency lower than 0.10 Hz(low respiratory rate) has issue for spectral analysis that is can't get the peak frequency in 0.10 Hz around there.
Please advise me why theoretical and experimental results are different and can't achieve for very low frequency.
In addition, why the peak frequeny occured in FFT is not same as AR Burg in some of the cases.
Thanks and best regards

1 commentaire

Wayne King
Wayne King le 26 Juil 2012
please post a separate question for this.

Connectez-vous pour commenter.

Pradeep Kumar R
Pradeep Kumar R le 23 Fév 2016

0 votes

hi guys i'm doing a project of fetal heart rate variability analysis i'm finding difficult to find and plot the heart rate of fetal i've extracted the fetal signal but only heart rate part i'm not able to come to a solution please help me with that.i've attached my code please help me out

Catégories

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by