0

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

  • What do you mean by "received signal is much slower than the send signal", you cannot recieve samples as fast as they produced? – mugiseyebrows Mar 23 '22 at 11:05
  • I try to made a plotter with qml/js/cpp and communicate over bluetooth. The main problem was not the reading part, but the time to update the chart. I don't solve the problème, but I think it's better to move the points instead of removing/adding them. To format them, just send a config command with timebase + the number of point per time. – Antoine Laps Mar 23 '22 at 13:39
  • In my sine wave generator, I am using the adding/removing procedure, which works perfectly. But the problem is on the receiving side. How can I create a time base for a different number of samples per time coming in? – Sebastian90 Mar 23 '22 at 13:48

0 Answers0