Python Spectrum Analysis

后端 未结 1 995
醉酒成梦
醉酒成梦 2021-02-08 13:22

I am trying to estimate the PSD of the heart rate variability of an ECG signal. To test my code,I have extracted the R-R interval from from the fantasia ECG database. I have ext

相关标签:
1条回答
  • 2021-02-08 13:29

    The problem here is that you do not handle correctly the sampeling of your signal. In your welsch call, you consider a regularly sampled signal with sample frequency 4Hz. If you look at the time vector t

    In [1]: dt = t[1:]-t[:-1]
    
    In [2]: dt.mean(), np.median(dt)
    Out[2]: 0.76693059125964014, 0.75600000000000023
    
    In [3]: dt.min(), dt.max()
    Out[3]: (0.61599999999998545, 1.0880000000000081)
    

    Your signal is thus not regularly sampled. You thus need to take that into acount, else you do not estimate correctly the PSD and this gives you bad estimates.

    A first correction should be to use correctly the parameter fs in welsch. This parameter indicates the sampling frequency of the given signal. Putting it ot 4 means that your time vector should be a regular [0, .25, .5, .75, .1, ....]. A better estimate would be either the median of dt or len(t)/(t.max()-t.min()), so around 4/3. This gives better PSD estimate and correct order for some of the constant but it is still different compared to Kubios values.

    To get correct estimate of the PSD, you should use a non uniform DFT. A package that implement such transform can be found here. The documentation is quite cryptic for this package but you need to use the adjoint method to get the Fourier Transform without scaling issue:

    N = 128    # Number of frequency you will get
    M = len(t) # Number of irregular samples you have
    plan = NFFT(N, M)
    
    # Give the sample times and precompute variable for 
    # the NFFT algorithm.
    plan.x = t
    plan.precompute()
    
    # put your signal in `plan.f` and use the `plan.adjoint`
    # to compute the Fourier transform of your signal
    plan.f = ibi
    Fxx = plan.adjoint()
    plt.plot(abs(Fxx))
    

    Here the estimates do not seems to be in line with the one from Kubios. It is possible the estimation is probably of because you do a psd estimate on the whole signal. You can try to use the welch technique combined with this nfft by averaging estimates on windowed signals as it do not rely on FFT but on any estimation of the PSD.

    0 讨论(0)
提交回复
热议问题