Pulse counting from a noisy ADC value

Hello,
I am reading a dial that can move in the range very quickly to very slow by using a IR sensor an reading the analog voltage out with ADC pins in the arduino (ESP32).

An example of the raw data is shown in the attachement.

I want to increase a counter for each "pulse" in the graph

What would be a good strategy for detecting the puses? I guess a good strart could be to make a moveing average to reduce the noice?

I want to increase a counter for each "pulse" in the graph

Please define "pulse".

This doesn't make much sense:

I am reading a dial that can move in the range very quickly to very slow by using a IR sensor

Please post a circuit diagram and illustration to explain what you are doing. There may be a much better way to get the readings you want.

A typical way of cleaning up an analog signal is by feeding it through a Schmitt trigger.

About your graph (posted here so others don't have to download it):


It is completely meaningless without units at the axis, nor an indication of what in this graph would constitute "pulse".

The unit on the other axis is time. The idea is to trigger each puls and send a message to an MQTT broker. If the pulses are to frequent, it may be more suitable to send every 10:th or 100 pulse by MQTT

The unit on the other axis is time.

Please try to make some sense! 2500 to 5000 seconds, minutes, hours or days?

WHAT IS A PULSE?

Hint: if you can't explain to humans what you are trying to do, you will have no luck at all teaching the computer to do it.

A pulse would be every time the curve changes from a positive derivate to a negative with respect to time.
I only need to know when this happens and send a MQTT message. I want to have an algoritm that can identify when this happens, and the algoritm must be able to work with really slow changes, like one change from positive to negative derivate every 30 minutes, as well as when this change will happen 10 or 100 times per second.

A pulse would be every time the curve changes from a positive derivate to a negative with respect to time.

That is true for all the narrow spikes in the graph.

patikpatrik:
The unit on the other axis is time. The idea is to trigger each puls and send a message to an MQTT broker. If the pulses are to frequent, it may be more suitable to send every 10:th or 100 pulse by MQTT

How many pulses do you see in the picture, 15, 100, 300?

I am reading a dial

Use a shaft encoder instead.

Between time ~ 2700 and time ~ 4200 I would say that there are 13 pulses

I can not phyically change the meter, so the available mesurement technologies are very limited. It is possible to use an image analysing technology - this works OK, but is slow and require recalibration if the camera is just slightly moved

A median filter is good for removing extreme values.
Load your dataset into Python or whatever and play around with some filters.

What is the time scale, really?

To clean up a signal like this there are two options: software and hardware. It's pretty noisy so I think your best bet is starting the cleanup in hardware and finishing up in software.

Also what is the y axis? Some kind of voltage level? If so, how much? What is the difference between the high and the low value? What is this "dial" exactly? Any offset/bias voltage in the signal?

Maybe you can clean up the signal by connecting a small cap - or a large RC value, depending on the time scale (milliseconds, hours? Makes a big difference). Or a cap to take care of most spikes, then a Schmitt trigger to make it a nice square wave, and finally software to filter out the very narrow peaks.

Now if you start answering ALL the questions we have posed, plus images of your mysterious installation and a complete circuit diagram of it, we'd be getting a lot further much faster.

The Y value is a 3.3V sensor connected to the arduino analog in (ESP32) -> so the Y values are in integer (~3,3V/4095)

It is a black dial on a white background, and I simply put an IR line tracker on top of the dial - the voltage out from the tracker is connected to the analog in on hte ESP32

Is it possible to make a hardware clean up of the signal, when the "pulse" time can vary from say 100 mS to 30 minutes?

As long as you can define what voltage is to be seen as "high" and what voltage as "low" you can use a Schmitt trigger or comparator to count pulses.

First of all you should ask yourself, where does all the noise come from, and how can I possibly prevent it from coming into my system in the first place?

Secondly, it seems that the signal varies over just about 30 ADC points, so about 25 mV between a high and low, on a bias of about 2.7V. That's an awfully small signal, and something that you seriously have to improve upon to stand a chance of reliable detection.