0

I have a realtime signal from a sensor. I need logic to implement a masking time once the signal is above a threshold. As shown below:

enter image description here

Here the signal (in blue) crosses a threshold. And I need to mask for any checks for the threshold for a period (masking time). (In this way I can detect only the positive pulse, similarly, I have another check for negative pulse)

See the code below:

static QTime time(QTime::currentTime());
// calculate two new data points:
double key = time.elapsed()/1000.0; // time elapsed since start of demo, in seconds
static double lastKey;

if(a_vertical> onThreshold && key-lastKey >0.2) // is this check correct for masking time?
    {
        ui->rdo_btn_vertical->show();
        ui->rdo_btn_vertical->setStyleSheet(StyleSheetOn1);
        lastKey = key;
    }
    else
    {
        ui->rdo_btn_vertical->setStyleSheet(StyleSheetOff1);
    }


I'm not sure if the expression inside IF statement is a correct way for implementing a masking time. Any thoughts/suggestions are welcome.

EDIT

Masking time: it's a time period masked for any threshold checking. This to differentiate positive and negative pulse. See below, during a postive pulse there is a negative-going side but it should not detect as a "negative pulse". That's why I implemented a masking time.

enter image description here

1 Answers1

0

you can define 2 signal-slots that take care of starting, stopping the elapsed timer, fortunately, Qt has a class doing this for you, read the doc here and be aware of possible overflows and if required set QElapsedTimer::MonotonicClock

QElapsedTimer timer;
timer.start();
slowOperation1();
qDebug() << "The slow operation took" << timer.elapsed() << "milliseconds";

and to trigger the signals

if(sensorSignal>THRESHOLD_K)
    emit startTimer();
else
    emit stopTimer();
    
void startTimer()
{   
    timer.start();
}

void stopTimer()
{

    timer.elapsed();
}
ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97
  • 1
    Thanks for your answer. I edited the post to add more on masking time. My question is. Once the threshold is reached I need to stop checking for any threshold until the masking time is elapsed (say 0.5 seconds). How do I implement that? –  Jun 29 '20 at 10:38
  • then u can 1. set a timer for the period "t" and disable the signals until the timer expires :) – ΦXocę 웃 Пepeúpa ツ Jun 29 '20 at 11:10
  • would you like a refernce code for that or are you familiar with QTimers? – ΦXocę 웃 Пepeúpa ツ Jun 29 '20 at 11:10
  • Thanks a lot. I'm not much familiar with QTimer , It will be really helpful if you could share a reference code for that. –  Jun 29 '20 at 13:09