Results 1 to 5 of 5

Thread: Oscilloscope emulator

  1. #1
    Join Date
    Jan 2015
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Oscilloscope emulator

    First of all, this is not another thread asking for help with the example scope application. The example scope application does not behave the way a real oscilloscope would. Take an analog oscilloscope for example, the trace reaches the end of the 'plot' and wraps back to the left hand side and begins drawing again; the example oscilloscope will continue scrolling and increment the time scale to the right infinitely.

    So what am I getting at, what am I trying to do? I'm developing a scope emulator with a normalized time scale; one similar to a hardware oscilloscope. The behavior I'm looking for is best described as one you would see with a digital hardware oscilloscope (analog doesn't do large time/div well) where the traces sweep from left to right and do what I call the snake eating its tail. When the head reaches the right side of the plot, it should appear on the left and begin drawing over the oldest points.

    I've been experimenting with a qwt_plot and a qwt_plot_curve but what I've found is a few new unwanted behaviors when I manipulate the data I'm putting into the plot curve:
    -If I treat the samples as a vector, when I try to wrap the data points to start back at the beginning of the plot, I end up with a line between the last point on the right side of the screen and the latest point on the left side of the screen.
    -If I treat the samples as a ring buffer, I reach the right side of the plot and 'wrap' I pop the first sample off from the vector and pre-pend the next, I end up with an undesired line between the latest point and the 'second' point which is 1 time scale behind the latest point. I think that might be wordy; I don't want a line between the head and the tail.

    I've been looking through the qwt documentation for a module that I could re-implement to behave the way I want it to but I've come up empty. The documentation is great, but there descriptions of each class is a little lacking to truly understand what I could expand the classes to do.


    Thanks for taking the time to read this,

    Jay

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,313
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Oscilloscope emulator

    Quote Originally Posted by jayriordan View Post
    The behavior I'm looking for is best described as one you would see with a digital hardware oscilloscope (analog doesn't do large time/div well) where the traces sweep from left to right and do what I call the snake eating its tail. When the head reaches the right side of the plot, it should appear on the left and begin drawing over the oldest points.
    You always need to have 2 curves: one for the previous interval and one for the current. With each update you have to remove points from the previous one and add points to the second one. You could implement it using a single buffer with a cursor ( index of the current point ), but you need to implement 2 QwtSeriesData<QPointF> bridges, wher the first one returns the points <= cursor index and the second one returns all points behind. When reachin the end you simply swap the QwtSeriesData<QPointF> objects ( or the curves ).

    So far this should be a no-brainer - only when you need to avoid full replots for each update ( too many points + high refresh rates + slow embedded device ) things become more tricky. In opposite to the oscilloscope example it is not enough to draw incrementally ( no replot ! ) as you always have to erase a section of the previous curve. How to do this best depends on what else is visible on your plot.

    To be honest I would be interested in adding an example for such an osci to the Qwt package. So if you send me some implementation - without optimized drawing - per Email I would do the rest. Maybe you also have a good idea how to generate synthetic points, that look realistic - at least we would need to have 2 different cycles.

    Uwe

  3. #3
    Join Date
    Jan 2015
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Oscilloscope emulator

    Quote Originally Posted by Uwe View Post
    You always need to have 2 curves: one for the previous interval and one for the current. With each update you have to remove points from the previous one and add points to the second one. You could implement it using a single buffer with a cursor ( index of the current point ), but you need to implement 2 QwtSeriesData<QPointF> bridges, wher the first one returns the points <= cursor index and the second one returns all points behind. When reachin the end you simply swap the QwtSeriesData<QPointF> objects ( or the curves ).

    So far this should be a no-brainer - only when you need to avoid full replots for each update ( too many points + high refresh rates + slow embedded device ) things become more tricky. In opposite to the oscilloscope example it is not enough to draw incrementally ( no replot ! ) as you always have to erase a section of the previous curve. How to do this best depends on what else is visible on your plot.

    Fortunately for my application the intended target is a desktop computer; however I can see the inefficiencies in too many points with a high refresh rate even on a desktop PC.

    I had thought to use two buffers like you're suggesting, but I was hoping there was a simpler way. With this implementation, you must keep in mind that you may have more or less data points / fraction of a second in either buffer. The behavior for what I feel like I'm failing to describe here is the case where the two curves overlap in the x axis. I'll do my best attempt at drawing the scope output in ascii art:


    Qt Code:
    1. ###############
    2. # #
    3. # _______#
    4. # #
    5. #________ #
    6. # #
    7. ###############
    To copy to clipboard, switch view to plain text mode 



    This could be avoided by eliminating samples based on the x coordinate instead of just popping off the first element from the buffer.

    I'll do my best to come up with something that I could send you to contribute towards qwt!

    Thanks for taking the time to read and respond!

    Jay



    Edit: Trying to get the formatting correct on the ascii art.
    Last edited by jayriordan; 8th January 2015 at 19:20.

  4. #4
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,313
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Oscilloscope emulator

    Quote Originally Posted by jayriordan View Post
    I had thought to use two buffers like you're suggesting, but I was hoping there was a simpler way..
    No I was suggesting 2 curves - connected to the same buffer !

    Uwe

  5. #5
    Join Date
    Jan 2015
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Oscilloscope emulator

    Quote Originally Posted by Uwe View Post
    No I was suggesting 2 curves - connected to the same buffer !

    Uwe

    I re-read your first post, yes a single buffer to store data and plot two curves based on the current x value.

Similar Threads

  1. Oscilloscope
    By P@u1 in forum Qwt
    Replies: 1
    Last Post: 1st July 2011, 15:21
  2. QWT oscilloscope example
    By Pablo220372 in forum Qwt
    Replies: 2
    Last Post: 10th June 2011, 08:19
  3. oscilloscope example bug
    By umituzun84 in forum Qwt
    Replies: 1
    Last Post: 17th March 2010, 19:03
  4. Qwt-5.3.0-svn: oscilloscope
    By PaceyIV in forum Qwt
    Replies: 2
    Last Post: 14th June 2009, 18:56
  5. use qt for oscilloscope
    By dycjiaoda in forum Qt Programming
    Replies: 1
    Last Post: 9th June 2009, 19:46

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.