signal threshold

Working with OpenViBE signal processing scenarios and doing scenario/BCI design
Post Reply
Posts: 3
Joined: Fri Apr 23, 2021 9:23 am

signal threshold

Post by npavailler »


We are facing a problem that seems pretty simple (and potentially a second one), but we cannot find a way to fix it. Here is the background:
We are currently reading emg signal and trying to calculate a threshold in order to detect emg bursts. In fine, we would like to get a stimulation each time the signal exceeds the threshold.
To start with, we simply want to detect when the (pre-processed) signal exceed the mean plus 3 standard deviations. But, this is where things are getting problematic..., the mean and std are calculated/updated on every trial during a baseline period (and are hence variable and updated).
To do so, we were thinking of (The picture below shows to intended scenario):
- making a stimulation based epoching, extract the mean and the std from the baseline, and feed them into a simple DSP box (this DSP box can either subtract the mean + 3std, to later detect a sign change, or directly check when we exceed mean + 3std, we'll comment on that later). The inputs of this simple DSP would then be:
- the signal (A)
- the mean (B)
- the std (C)
The problem is that when we want to compute (e.g.) A - (B + 3*C) we have a dimension mismatch: A is of dimension 64 (size of the chunk, we have one single channel), while B and C are of dimension 1. The equation works perfectly well if B and C are hard written in the equation (as done for example in the "Use the force" scenario"). But we need to update them... So the question is how to make the simple DSP box performing simple operations between a signal (a matrix) and floats as variables?

Once this is solved (hopefully, it can...), we would like an openvibe stimulation to be triggered when the condition is fulfilled. If we subtract the mean + 3std to the signal, one can use the Sign change detector box that issues a stimulation. But this is suboptimal, as only one stimulation is triggered, and we would like to use to the Stimulation validator to be sure that it is not a false alarm. This does not work for a simple sign change detector (or one needs to ensure that there is not a another sign change..., not easy). So the question is: is it possible to have a simple DSP box to trigger a stimulation, instead of a transformed signal? Or is there another box/way to do so?

Thank you very much for you help


Posts: 67
Joined: Wed Mar 04, 2020 3:38 pm

Re: signal threshold

Post by Thomas »


I agree with you, it would feel quite natural if the Simple DSP box could see a single sample signal entry as a float. Unfortunately, as you experienced, this is not implemented this way. It is potentially an upgrade that could be done (given some time and investigation).

The other issue you are having to create the logic and output a stimulation is not straight forward either. As you said, it would require a box (similar to simple DSP) that could be configured with a logical expression (returning true or false) and output a stimulation accordingly.

I take note of these boxes/upgrades for future developments.

Until then, you have two options to perform the maths you want and output the stimulations:
  1. Write a C++ box to do what is needed. This involves recompiling OpenViBE.
    • Instructions on how to build compile OV can be found here.
    • Instructions on how to create a new box can be found there.
  • Write a python script to do what is needed, running it with the Python box available in OpenViBE.
    • Instructions on how to use python scripts in OpenVibe can be found here.
    • You can also look at the python box-tutorials provided with OpenViBE to see how they are written and used
I hope this helps. Don't hesitate if you have more questions.


Posts: 225
Joined: Wed Oct 31, 2018 9:14 am

Re: signal threshold

Post by Thibaut »

I have already make that and 2 solution can be used :
as thomas say you can implement a box c++ or python or an other possibility.
If you HAve a simple DSP with only A - (B + 3*C). If you use an xml setting (you can save box option in an xml) You have to make a python script to modify the B and C in XMl. in my case during compute of mean and std the python script create automaticely the xml config file (or replace if exist)

Post Reply