简体   繁体   中英

How to calculate the areas under the spikes (interference) of a curve in Python

What I'm trying to do

I got an np.array with frequencies (x) and an np.array with the signal strength / power spectral density (y). The signal without any noise looks similar to a logarithmic curve, but might have a slightly different form, depending on the data.

The signal has different interferences that are visible as spikes, some of those spikes are overlapping each other. I do need to calculate the area under each spike. If they are overlapping I need to calculate the area of each of them individually. (Ideally adjusting for the constructive interference of two overlapping spikes, or splitting the areas where the spikes intersect.)

What I've tried so far:

I've tried to get the peaks and the "bottom" width of each spike. However this quite often failed if the spikes where too wide or overlapped with each other.

I've tried to use different curve fitting algorithms or filters to get a second curve that represent the signal without interference, I wanted to overlay this curve below the original curve and try to get the areas under the spikes that way. But I didn't get a curve that would look similar to the original signal without the interference.

Example Curve

In the image you can see the data curve, and a model1 curve, which is a curve that I tried to fit to the data curve. I drew a yellow curve which is how a clean signal should look like in this example. I also shaded one of the spike areas pink which represents one of the areas I need to calculate.

在此处输入图像描述

What my data looks like

The frequency array looks similar to this (starting from 0.5):

  [ 0.5 ...  79.5  80.   80.5  81.   81.5  82.   82.5  83.   83.5  84.
  84.5  85.   85.5  86.   86.5  87.   87.5  88.   88.5  89.   89.5  90.
  90.5  91.   91.5  92.   92.5  93.   93.5  94.   94.5  95.   95.5  96.
  96.5  97.   97.5  98.   98.5  99.   99.5 100. ]

The signal array looks like this, with the same length as the frequency array.

[6.83248573e-27 6.38424451e-27 4.40532611e-27 2.46641238e-27
 2.79056227e-27 1.91667602e-27 2.01585530e-27 2.81595644e-27
 1.63137469e-27 2.36510624e-27 1.76637075e-27 1.42336105e-27
 1.94134643e-27 1.63569180e-27 1.92916964e-27 1.74853657e-27
 1.70866416e-27 1.82414861e-27 1.99505505e-27 3.18429811e-27
 5.40618755e-27 6.03726511e-27 4.78220246e-27 3.56407711e-27
 2.82165848e-27 2.21870589e-27 2.08558649e-27 2.05153813e-27
 2.26220532e-27 2.51639647e-27 2.72401400e-27 3.03959512e-27
 3.20637304e-27 3.25169369e-27 3.14399482e-27 3.22505547e-27
 3.04244374e-27 3.05644526e-27 2.75377037e-27 2.66384664e-27
 2.54582065e-27 2.45122798e-27 2.33501355e-27 2.39223261e-27
 2.31744742e-27 2.15909503e-27 2.13473052e-27 1.97037169e-27
 1.66287056e-27 1.39650886e-27 1.35749479e-27 1.36925484e-27
 1.23080761e-27 1.18806584e-27 1.00880561e-27 8.49857372e-28
 8.69180125e-28 8.00455124e-28 7.64146873e-28 7.44351180e-28
 6.12306196e-28 5.61151389e-28 5.61148340e-28 5.29198214e-28
 4.65031278e-28 4.39371596e-28 3.87900481e-28 3.66667907e-28
 3.19346926e-28 2.70416144e-28 2.55537042e-28 2.52633398e-28
 2.46481657e-28 2.17053812e-28 2.01982726e-28 1.90483387e-28
 1.61632370e-28 1.55358436e-28 1.59321060e-28 1.60793279e-28
 1.52695766e-28 1.55288957e-28 1.59405042e-28 1.53165367e-28
 1.36278544e-28 1.57511344e-28 1.36641270e-28 1.33813492e-28
 1.30800335e-28 1.32748995e-28 1.30747468e-28 1.16701156e-28
 1.12717963e-28 1.22763995e-28 1.17056892e-28 1.13689662e-28
 1.06267063e-28 1.18968941e-28 1.12967908e-28 ...            ]

Questions?

Please let me know if you need further clearification or code examples. I did not include further code examples as none of what I've tried has given the right results.

i think these links would help

https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.cumulative_trapezoid.html

https://docs.scipy.org/doc/scipy/reference/generated/scipy.integrate.simpson.html

mostly looks like a numeric integrate to me.

mathematically every delta x has delta y and we can estimate the whole area then subtract from the yellow one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM