0

I've real-time signal, I need to check if the signal crosses a threshold and set a delay for about 1 second. How do I implement that?

if(a_vertical> onThreshold) //what's the expression to set a time delay?
    {
        ui->rdo_btn_vertical->setStyleSheet(StyleSheetOn1); // On  LED
    }
    else
    {
        ui->rdo_btn_vertical->setStyleSheet(StyleSheetOff1); // Off LED
    }
  • What does it mean for a signal to "cross a threshold"? What's a "real-time signal"? At any rate, there is no sane notion of a time delay in a logical test. Please explain what you want to achieve instead. – gspr Jul 08 '20 at 10:21
  • What if the signal goes below the threshold during that second? – Thomas Weller Jul 08 '20 at 10:25
  • 1
    https://en.cppreference.com/w/cpp/thread/sleep_for - but will make your UI unresponsive for that time – Thomas Weller Jul 08 '20 at 10:26
  • 2
    You've already asked what appears to be the [same question](https://stackoverflow.com/questions/62635623/algorithm-for-masking-time-when-the-signal-is-above-a-threshold). What was wrong with the answer you accepted there? – G.M. Jul 08 '20 at 10:27
  • 1
    Your approach may not work well if you have a noisy signal, like an electronics signal. You might not detect the pulse, but detect a random spike instead, then wait a second and accidentally consider a positive pulse as a negative one. Like so:https://i.stack.imgur.com/VzPcJ.png – Thomas Weller Jul 08 '20 at 10:29

1 Answers1

0

The easy and dumb solution is to start QTimer in single shot mode and check if it's running (should not be) while detecting the pulse. "Easy and dumb" doesn't mean "good". Depending on the nature of the signal, filtering it might be a viable option.

alagner
  • 3,448
  • 1
  • 13
  • 25