How do you count oscillations?

hello everyone
I want to determine the number of times the value reverses (passes 0) ? please
there:
bluetooth_pot5

My idea is:
create
list COUNT
list A= a1, a2, a3, ... ; if a1a2<0 then get a1a2 to list COUNT
then length of COUNT

??

what if a1 or a2 = 0 ?

1 Like

It depends partially on how you record the oscillations. You might just count the the occurrences of zero ( 0 ) in your List if the inflections points are captured.

Else your pseudo code might work. Did you try it?

1 Like

we can filter that value in the list before comparing them ( remove 0)
it is a damping oscillation

i think the recorded value can ignore the value 0, so i cant count the value 0

so you'd better make it clear that how you record the value, by a clock or by some events?

On second thought, your pseudo code probably won't work unless you are only recording the peaks and troughs.

Record a listing of your (filtered ? )data stream values and share. Someone might have a more specific recommendation if they could visualize the actual data you graphed.

here is values ​​I drew:

If your data's running average is not 0, counting zero crossings might throw you off.

If x1 and x2 are consecutive readings adjusted for the running average, you could count the number of times sign(x1) <> sign(x2)
where sign(x) = one value if x > 0 and another value if x <= 0.

1 Like

Your graph is pretty. I would like to see is a listing of the values that were input to draw the curve. Perhaps a csv file. Your data starts at almost 2 goes to -6, rebounds to 1 1/2 after 10 (seconds ??) until damping to 0 at about 58 seconds.

It appears you could count the peaks (or troughs) over an 60 second interval.

What is an oscillation? A complete cycle or the interval peak to peak or trough to trough?
Perhaps this search will help you decide determine number of oscillation of a curve - Google Search

1 Like

Counting sign changes is a good option...

Based on this extension...
https://community.appinventor.mit.edu/t/extension-dynamic-graph-shift-left-graph-sinusoidal-wave-bluetooth/46140/4

p299H_GraficoDinamico_2_CriuceCero.aia (11.9 KB)

1 Like

whether i can remove the value 0 from the list when i do the calculation with block?
this is my Block:

and this error when i run it:

Export your .aia file and upload it here.
export_and_upload_aia

here:
MyProject.aia (29.8 KB)

Here is how to skip 0 readings when you count zero-crossings ...


blocks (2)

blocks
(draggable blocks)

I added a new global variable to skip duplicate extractions and conversions from TinyDB.

Removing zeroes required a separate pass over the list, in decreasing index order, because the indexes collapse as removals happen.

1 Like

Thank you, it worked fine.