问题描述
我有来自传感器的实时信号.一旦信号高于阈值,我需要逻辑来实现屏蔽时间.如下图:
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)
查看下面的代码:
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);
}
我不确定 IF 语句中的表达式是否是实现屏蔽时间的正确方法.欢迎提出任何想法/建议.
I'm not sure if the expression inside IF statement is a correct way for implementing a masking time.Any thoughts/suggestions are welcome.
编辑
屏蔽时间:这是为任何阈值检查屏蔽的时间段.以此来区分正负脉冲.见下文,在正脉冲期间存在负向侧但不应检测为负脉冲".这就是我实施屏蔽时间的原因.
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.
推荐答案
您可以定义 2 个信号槽,负责启动、停止已用计时器,幸运的是,Qt 有一个类可以为您执行此操作,请阅读 此处 并注意可能的溢出,并在需要时设置 QElapsedTimer::MonotonicClock
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";
并触发信号
if(sensorSignal>THRESHOLD_K)
emit startTimer();
else
emit stopTimer();
void startTimer()
{
timer.start();
}
void stopTimer()
{
timer.elapsed();
}
这篇关于信号高于阈值时的屏蔽时间算法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!