1 year ago

#325508

test-img

Sebastian90

Real-Time Plot Oscilloscope UDP

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).

c++

qt

qwt

oscilloscope

0 Answers

Your Answer

Accepted video resources