实时绘图示波器 UDP

发布于 2025-01-16 18:32:09 字数 809 浏览 1 评论 0原文

我目前正在用 C++ 实现一个简单的示波器,它通过 UDP 接收数据。首先,我实现了一个生成 30 kSps 正弦波(高达 10 kHz)的函数,该函数通过 UDP 在本地传输此数据。另一方面,有一个 (QWT) 图。 UDP 客户端在线程中运行,将接收到的值(并删除第一个值)附加到 Qlist,同时绘图通过计时器每 30 毫秒更新一次。

现在的问题是,如何实现一个简单的示波器,以原始频率绘制信号,而与接收到的样本数量无关(实现时基)?你能给我一些一般性的想法吗?提前致谢。

解决方案:

解决方案是将接收到的项目的 Qlist 复制(每次更新绘图,此处为 30 毫秒)到临时变量并删除 Qlist。然后,为这个临时变量创建一个时间向量。时间向量是通过此函数创建的:

QVector<double> make_vector(double start, double end, double size)
{
    QVector<double> vec;
    double step = abs((abs(start) - abs(end)))/size;

    while (start <= end)
    {
        vec.push_back(start);
        start += step;
    }
    return vec;
}

例如,为了将值缩放到 1 秒,我调用此函数,如下所示:make_vector(-1.0, 0.0,temporaryvariable.size())。 通过此过程,绘图与收到的样本数量无关。您只需确保在您的时间段(此处为 30 毫秒)内收到足够的值。

I am currently working on implementing a simple oscilloscope in C++, which is receiving data via UDP. First, I have implemented a function to generate a sine wave (up to 10 kHz) with 30 kSps, which is transferring this data via UDP locally. On the other side, there is a (QWT) plot. The UDP client is running in a thread appending the received values (and delete the first one) to a Qlist, while the plot is updated every 30 ms via a timer.

The question is now, how can I implement a simple oscilloscope which plots the signal with its original frequency, independent of the number of samples it receives (implement a time base)? Could you give me some general ideas? Thanks in advance.

Solution:

The solution is to copy (every time the plot is updated, here 30 ms) the Qlist of the received items to a temporary variable and delete the Qlist. Then, create a time vector for this temporary variable. The time vector is created via this function:

QVector<double> make_vector(double start, double end, double size)
{
    QVector<double> vec;
    double step = abs((abs(start) - abs(end)))/size;

    while (start <= end)
    {
        vec.push_back(start);
        start += step;
    }
    return vec;
}

For example, to scale the value to 1 second I am calling this function like: make_vector(-1.0, 0.0, temporary variable.size()).
By this procedure, the plot is independent of the number of sample received. You only have to make sure that you receive enough values in your time period (here 30 ms).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文