Algorithm for masking time when the signal is above a threshold

让人想犯罪 __ 提交于 2021-02-11 15:37:34

问题


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:

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.


回答1:


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();
}


来源:https://stackoverflow.com/questions/62635623/algorithm-for-masking-time-when-the-signal-is-above-a-threshold

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!