Test and Measurement Forum

Plot libraries

Post your .Net discussions here

Plot libraries

Postby lyurealm » Thu May 19, 2016 11:33 am

Hi everyone, I'm developing a software which uses the PicoScope 4262. I'd like to plot my results in real time, so the user can see what's being captured by the oscilloscope. So far, I've done it using the open source oxyplot library, which delivers nice results, but they're far from optimum performance-wise.

At this moment, I'm capturing a signal at a sample rate of 10 kS. I don't pretend to plot all the data, because it's pointless. So what I've done is to implement a decimator that takes away samples for reducing the cpu demand. This way, the decimator method substract more or less samples depending on how zoomed the user has the plot. By Nyquist criterion, the minimum points that the plot will need while showing the full time axis (0-500 seconds) is, for a 50 Hz signal:

500*100 = 50.000 points.

This way, the plot shows a "fat line" that represents the signal while totally zoomed out. The problem is that that "fat line", which doesn't provide any useful information other than let the user know that the signal is between +- some value, has 50.000 points and of course, it requires some cpu power.

I've noticed that the official PicoScope application needs only 1-2 % of cpu power to capture and plot, while my software needs up to 20%, depending on how many times I want the plot to be redrawn per second. I understand that PicoScope engineers have implemented their own plot library, and that's what my question is about. Does anyone know which approach did they use?

Their plot isn't detailed until you stop capturing, but you can clearly see a "fat line" that represents the signal. Furthermore, I'm pretty sure they did use directx/direct3d/direct2d/opengl, so they take full advantage of the gpu, right?

Can anyone give me some advice? Thank you in advance! :)
lyurealm
Newbie
 
Posts: 0
Joined: Wed Nov 11, 2015 1:10 pm

Re: Plot libraries

Postby davidpruitt » Thu May 19, 2016 1:44 pm

In all of my C# development, I typically use oxyplot as well. It seems like the most fully-featured plotting library out there for .NET. There is ONE more, however, and I hear it is super fast (from what I have read). It apparently doesn't work natively with WPF (if that matters to you), but rather it is built for Windows Forms.

It is the Microsoft Chart Control, found here:

https://msdn.microsoft.com/en-us/library/dd456753.aspx

Obviously, it also doesn't work on other non-Windows platforms. I have read you can get it to work for WPF (if you are doing WPF development) if you have your WPF app "host" a Windows form.

Otherwise, if you want to go the C++ route, you can use QWT. QWT is a plotting library available that primarily works with the QT development system. It is very cross-platform, but a pain to install correctly (just as a fair warning). I've done some sample plotting with it, but nothing too crazy. People tell me it is very fast.
davidpruitt
Advanced User
Advanced User
 
Posts: 21
Joined: Tue May 17, 2016 6:45 pm

Re: Plot libraries

Postby lyurealm » Fri May 20, 2016 8:00 am

Hello David! First of all, thank you for your answer, I will definitely take a look at those.

I'd like to say, though, that I'm very pleased with Oxyplot's performance. It doesn't takes too long to plot 100.000 points, when I have both models (one per channel) zoomed out completely (showing the full 0-500 seconds capture range).

Thing is, I feel as wasting cpu power. The only reason for me to plot 50.000 points per plot is because I'm capturing a 50 Hz signal and I need 100 points per seconds according to Nyquist Criterion. However, what I'm seeing on the screen is, obviously, just a fat line which doesn't give much information to the final user unless he zooms in.

I think that the approach PicoScope official software uses is something like calculating the positive and negative envelope of the signal and then filling it with a color.

By doing that, you can in fact decimate the envelope itself, I think.

I need to think more about this, but it may me a possibility. Or maybe they're just using gpu-code, who knows...
lyurealm
Newbie
 
Posts: 0
Joined: Wed Nov 11, 2015 1:10 pm

Re: Plot libraries

Postby davidpruitt » Fri May 20, 2016 12:17 pm

So are you just wanting to reduce the number of points you're plotting while keeping the same shape of waveform that is plotted? You should be able to use Linq within C# to do that fairly easily.
davidpruitt
Advanced User
Advanced User
 
Posts: 21
Joined: Tue May 17, 2016 6:45 pm

Re: Plot libraries

Postby lyurealm » Fri May 20, 2016 1:37 pm

Yes, in fact, that's exactly what I'd like to do. When I plot 500 secs of a 50 Hz sin, all I'm going to see is just a mess, so what's the point of ploting so many points? At this moment, I've a decimator that only will plot 100 plots per second, so I keep the same shape, but that still a lot of points if I'm in the 0-500 secs range.

My idea is to plot a simplified graph with the same shape than the original signal has, much less detailed, when I'm zoomed out. And then switch to a detailed representation of the signal (100 points per second) when I'm enough zoomed in.

Can you give some hints about Linq so I can investigate?

Thank you very much!
lyurealm
Newbie
 
Posts: 0
Joined: Wed Nov 11, 2015 1:10 pm

Re: Plot libraries

Postby hexamer » Fri May 20, 2016 9:11 pm

I apologize if this is off-base, because I'm not sure where your bottlenecks really are so ...

Since your talking about decimation, did you know that the kind of downsamipling (min,max point calculation) you're referring to is available in many SDK drivers (including PS4000) and the process is performed in the scope hardware for some scopes - I'm not sure about 4262, but even if it's not, I'd bet the driver SW is well optimized. They refer to it as peak detection and aggregation. Heres a good explanation: https://www.picotech.com/download/artic ... eaming.pdf

I cant offer much advice on plotting software because AFAIK what I use (PLplot) is not really designed for real time plotting.
hexamer
Advanced User
Advanced User
 
Posts: 62
Joined: Tue Aug 12, 2014 10:09 pm

Re: Plot libraries

Postby lyurealm » Tue May 24, 2016 7:32 am

Hello hexamer, first of all, thank you for your answer and sorry for my late answer.

In fact, the bottleneck isn't the decimation itself. The idea is: I want to capture 10.000 samples per second, but, as my capture interval is 500 seconds, I want to plot a decimated version of the waveform, to keep the cpu power required as low as possible.

If I plot 100 samples per second, I can keep the waveform of a signal up to 50 Hz. But 100 samples/s is too much if I want to plot 500 seconds, because I will have to plot up to 50.000 points / channel at the end.

So let's say that what I want to do is to plot some kind of envelope of the signal (just as the official PicoScope software does) while zoomed out, and a detailed version of the signal when I zoom in, so the user can actually see the waveform shape.

Thank you for your help anyway! Much appreciated.
lyurealm
Newbie
 
Posts: 0
Joined: Wed Nov 11, 2015 1:10 pm

Re: Plot libraries

Postby davidpruitt » Tue May 24, 2016 1:52 pm

lyurealm,

Sorry about the late reply. Linq is a useful tool in C# to select and filter datasets. If you want to simply downsample your data before plotting it, you could do something like this:

Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;

namespace test2
{
    class Program
    {
        static void Main(string[] args)
        {
            List<double> k = new List<double>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            var filtered_list = k.Where((d, index) => index % 2 == 0).ToList();
            foreach (double v in filtered_list)
            {
                Console.WriteLine(v);
            }

            Console.ReadKey();
        }
    }
}


The above code simply takes every-other sample from the array (or, more precisely, all even-indexed samples) and filters them into a new list. You can then plot that new list. You could of course do every 10th sample by simply modifying one line:

Code: Select all
var filtered_list = k.Where((d, index) => index % 10 == 0).ToList();


If you would prefer to do a running average of the samples before plotting, rather than just a simple downsample, you could do something like this:

Code: Select all
using System;
using System.Collections.Generic;
using System.Linq;

namespace test2
{
    class Program
    {
        static void Main(string[] args)
        {
            List<double> k = new List<double>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
            int periodLength = 4;
            var filtered_array = Enumerable.Range(0, k.Count - periodLength).Select(
                n => k.Skip(n).Take(periodLength).Average()).ToList();
            foreach (double v in filtered_array)
            {
                Console.WriteLine(v);
            }

            Console.ReadKey();
        }
    }
}


For more information on Linq, there are plenty of tutorials online.
davidpruitt
Advanced User
Advanced User
 
Posts: 21
Joined: Tue May 17, 2016 6:45 pm


Return to .Net Languages (C#, VB.Net, .)

Who is online

Users browsing this forum: No registered users and 0 guests