Filtering Analog input to only show variations


I'm trying to figure how I could filter an analog input going from 0 to any values every cycles and only read the top values each cycles "Not the zeros"

Here is a screen shot of the data I get (Image 1). The idea would be to get rid of ANYTHING that goes to 0 but unfortunately, I can't just tell Arduino to not log if i equal 0 (Image 2) because I still get a "saw" pattern which is not what I need.

Generally analog filters are defined for s specific frequency range, anything is not valid. You might consider a DSP solution but there is also limits to max frequency. You might explain a bit about what the signal source is, the frequency, the amplitude, etc. and of course how fast/slow it needs to operate. Since you say zero you might want to define it, to some people less than 1 volt is zero to others a Pico volt is a lot.

I have an idea, what if you put the last 4 values in a buffer, lets call this “a,b,c and d”. Then you can have an if statement that says if b-a>=0 and d-c<0 then print b. Would that work?

Edit: or last 3 values; a,b and c. and say if b-a>=0 and c-b<0 then print b.

A top detector is easy.
Just read the analogue input constantly, and overwrite a value if the new one is higher.

Clearing that value must be done periodically, but I don't see a 'cycle' in your images.
Or is each peak a cycle. Then you can clear when the A/D returns (near) zero.

int rawValue, peakValue;

void setup() {

void loop() {
  rawValue = analogRead(A0);
  if (rawValue > peakValue) peakValue = rawValue;
  if (rawValue == 0) {
    // use peakValue
    // reset peakValue