0
$\begingroup$

I have a sensor that produces values over time (appr. 50/sec). I visualized these values (X axis is the time), this can be seen on the picture, measurement A and B - these are two independent measurements.

I'm a total beginner, I don't even know how to phrase the question. I just need to get... I don't know... "discrete" (?) values from this noisy data set.

I need something like this (this is happening say under 10 seconds):

Up... Up... Up... Up - I'm only interested in the "ups".

I was thinking of summarizing the values and when it's positive that's an up and when it's negative that's a down. But I don't know where to start and until when do I have to summarize the values...

or if is there (I'm sure there is) any other methodology that is used for this kind of problems.

raw output values

UPDATE:

After talking with Dan Boschen and applying what he recommended (moving average), I got lot smoother result:

moving average smoother result

Still got difficulties to ignore the false movements, but this is a one-step-forward. I'll continue this topic in a different question.

$\endgroup$
4
  • $\begingroup$ Well for starters it looks like you want to set y to 0 whenever y < 0 (is it that simple?). Also what are you actually interested in- the complete positive waveform as you have circled, or one data point from each interval? Or possibly the rate of each? It would help if you added some details as to your purpose with the results and the big picture of what you are trying to do and why. $\endgroup$ Dec 23, 2019 at 22:07
  • $\begingroup$ Unfortunately it's not that simple, because under the circled area you can see some negative values too. I don't want to differentiate between ups and downs based on when it's going negative from positive and positive from negative, that would be too easy. By the way this is a cell phone's gyroscope and I'm doing some biological work with them. $\endgroup$ Dec 23, 2019 at 23:12
  • $\begingroup$ To answer your question: I need to get somehow the 'intervals' you mentioned. Or the rate. So if I can tell how many 'ups' there are under 10 seconds that would be perfect. $\endgroup$ Dec 23, 2019 at 23:15
  • $\begingroup$ Ok- so you'll want to filter, a simple moving average will reveal the trend but the more you know about the signal of interest the better you can filter. Are you counting ups or do you need more information beyond number of general ups? OK we crossed threads, I see your answer now. $\endgroup$ Dec 23, 2019 at 23:16

1 Answer 1

0
$\begingroup$

From the comments you are most interested in counting the number of clear up areas over a certain duration of time, and you point out that you will have occasional erroneous negative spikes even during the up intervals.

You obviously want to filter but you also suggested little knowledge in this space so I will keep it very simple in what should provide a reasonable result.

My suggestion is to do a moving average over the minimum duration you ever expect for an up interval. Pass your waveform through the moving average, and then on the filtered output set a threshold detector with hysteresis (two thresholds) such that you increment your Up counter when passing the upper threshold and then allow your counter to trigger again once your lower threshold is set. Adjust your threshold levels for best results based on your actual signal cases.

$\endgroup$
12
  • $\begingroup$ Thanks for your answer! In that case how would I figure out the position from where the averaging should start? If it starts from e.g. the middle of an "up" area and ends in the middle of the next "down" area the average would approach zero. $\endgroup$ Dec 25, 2019 at 18:11
  • $\begingroup$ A moving average is a continuous average over a given sample size: consider the average of a FIFO buffer where each new sample is added and the last sample is removed— this is why I suggested a sample size that is the minimum duration of your up interval. The output of the moving average will be a smoothed version of the input. $\endgroup$ Dec 25, 2019 at 18:31
  • $\begingroup$ Yes, I implemented it (in some way). It was much more discrete than the picture above and I could easily differentiate between the ups and downs. In some cases it even worked well although only If I calibrate this sample size well. Unfortunately the measurement will vary from human to human. I feel this is not the way to detect the "ups" (or the downs). By the way, it not a secret: it will be a breath rate counter. $\endgroup$ Dec 25, 2019 at 18:38
  • $\begingroup$ In that case you could set "reset" threshold negative such as to detect the negative and you can adaptively adjust the averaging windows and the thresholds for each subject (track the longer term average durations to adapt the averaging window, and the average of the filtered positive and negative peaks to adapt the thresholds). $\endgroup$ Dec 25, 2019 at 18:45
  • $\begingroup$ I think I misunderstood the whole thing. I made average from the first x values and then the second x values and so on... Now I think I'm doing it right. The graph is a lot more smoother. I'll be experimenting with this in the next day. Thank you. $\endgroup$ Dec 25, 2019 at 20:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.