0

I have a signal that looks like the blue one, and I want to obtain the red one, while knowing there are exactly 2 minimums within the range (0, 255).

enter image description here

To obtain the red signal, I have done

@staticmethod
def _smooth_curve(curve, kernel_size=5):
    kernel = np.ones((kernel_size,)) / kernel_size
    smooth = np.convolve(curve, kernel, mode='same')
    return smooth

sig= self._smooth_curve(sig, 20)
sig= self._smooth_curve(sig, 14)
sig= self._smooth_curve(sig, 10)
sig= self._smooth_curve(sig, 6)

This is far from robust.

I want to make sure I get 2 minimums, and that they come out between the 3 peaks.

The peaks are not necessarily at the shown amplitudes, but they are separable, meaning they don't overlap in a way that finding minima makes no sense.

Gulzar
  • 23,452
  • 27
  • 113
  • 201
  • Does this answer your question? [find peaks location in a spectrum numpy](https://stackoverflow.com/questions/24656367/find-peaks-location-in-a-spectrum-numpy) – norok2 Jun 06 '20 at 08:26

1 Answers1

1

Using the envelope of the signal would be a better start.

The idea is described here and a function that you could use is scipy.signal.hilbert() .

You might have to apply a filter to the envelope, but it should be more robust.

On your comment with the minimum around 40: Then you need to use something like a max-pooling window or rolling maximum. That's like your convolution, but instead of sum and divide it does just max.

The idea is shown here.

There is scipy.ndimage.filters.maximum_filter which works on images. The docs state it's for multi-dimensions, so it might work on 1d arrays if you set the keyword size to maybe 3.

There are also other possibilities that might be even easier

Of course it is also possible to combine envelope and rolling maximum.

Joe
  • 6,758
  • 2
  • 26
  • 47
  • On the above signel, an envelope would create a new minimum at around 40. I would get a smoother signel, but still how would I get the seperation I need? – Gulzar Jun 07 '20 at 10:08