# Attenuating peaks of a signal in a specific direction

Consider a segment of a time-domain signal shown in the following graph and the two marked peaks, the first one facing downwards (in red) and the second one facing upwards (in black).

I would like to attenuate the peak facing downwards only. Unfortunately, both peaks seem to have the same frequency, so a linear filter that attenuates that frequency will attenuate both peaks. Is there a kind of a filter (perhaps a non-linear filter) that can attenuate peaks that face downward and keep peaks that faces upward (or vice-versa)?

• "both peaks seem to have the same frequency" What frequency does a peak have? – endolith Aug 28 '17 at 21:15
• As I said, I have only presented a small segment of the signal. I meant that these peaks both repeat at a certain frequency, which is similar. Furthermore, the shape of the peak itself has certain frequencies that are dominant, for instance , read about the QRS complex of an ECG signal that in most papers is said to be around 10-25 Hz. – D.Cohen Sep 7 '17 at 6:46

My immediate approach to this: try something that I'd call a running-minimum filter:

Look at a fixed amount of $N$ samples around the current sample. If the current sample is significantly below that, modify the sample to be closer to a low-pass variant of the original signal.

• (+1) and that's a threshold based output decision nonlinear filter... – Fat32 Aug 27 '17 at 13:03
• indeed, extremely nonlinear! I wonder whether one could "rephrase" / approximate that principle by using a continuous function of the signal (so that we can analytically derive spectral properties of this operation), but I can't think of a clever nonlinear function that would do this. – Marcus Müller Aug 27 '17 at 13:04
• I like nonlinear and/or time-varying filters (things), eventhough they lack some mathematical tractability, they can perform magical things that you can't get even close by linear ones. That's why I call linear filers as boring... :-) – Fat32 Aug 27 '17 at 13:13
• hehe, nice :) I wish I felt proficient enough in the design of linear filters to call them boring; to me, there's a lot of things where I am on the level of someone just applying recipes. – Marcus Müller Aug 27 '17 at 15:01

You're signal's peaks seem to be very sharp so as another option you can calculate derivative of your signal and peaks($d[n] = x[n]-x[n-1]$). Set a negative threshold and wherever the derivative is less than that threshold, is most likely downward peak.