Jump to content
Taylorh140

A simple method to buffer input

Recommended Posts

I find myself frequently looking for a good pattern for collecting a pool of array elements until they reach a certain size and then removing the oldest elements first. I have used very stupid methods like a bunch of feedback nodes being fed into an build array node. But today I thought up one that I really enjoyed and I thought that I'd share it. Its a simple pattern and no crossing wires :). Perhaps someone has thought of something better, if so don't hesitate to share.

Example_VI_BD.png

Share this post


Link to post
Share on other sites

I've never done performance testing but I've always used rotate and replace to avoid the build array. It should be very easy to make a malleable VI out of it to further reduce block diagram clutter.

For example:

new last.png

Edited by infinitenothing
  • Like 1

Share this post


Link to post
Share on other sites

There is also the Data Queue VI in the PtByPt palettes.  Personally, I found a fixed sized lossy queue to work very well as a circular buffer.

Share this post


Link to post
Share on other sites

Very neat and postage stamp sized.  There are apparently lots of different ways to perform this and I have yet another way that I've been doing.  This is part of my Force 1D Array Min or Max Size VIM that is part of my array package found here.  I am curious what is the fastest, and under what conditions one works better than another.

Force 1D Array Min or Max Size.png

 

Also somewhat relevant is my Circular Buffer XNodes I made here.  This one uses the shifting method, but tried to be a little more efficient with things like not shifting if it wasn't needed, and if a shift was needed to keep the shifted data so a consecutive read wouldn't require a shift or split and build.

Share this post


Link to post
Share on other sites

So I did a quick run, and I probably need to state that the above methods cannot really be compared apples to apples. Partially for the following reasons:

  • Some methods only support one element at a time input. If you need to enter 1000 pts at once these methods will probably be slower and involve more operations.
  • Some methods like the circular buffer are much more useful in certain situations like where the buffer is needed in different loops or are acquired at different rates. 

here are numbers for single point(one element at a time) inputs:

How long does it take to process 10000 input samples with a buffer size of 1000 on my computer?: 

  • Taylorh140 => 8.28579 ms 
  • infinitenothing => 2.99063 ms  (looks like shifting wins)
  • Data Queue Pt-by-pt => 9.03695 ms (I expected that this would beat mine)
  • hooovahh Circular Buffer => 8.7936 ms (Nearly as good as mine and uses DVR)

I would consider all these to be winners, except maybe the Data Queue pt-by-pt (but it is available by default which gives it a slight edge), Perhaps ill have to do another test where inputs are more than one sample.

Note: if you want to try the source you'll need the circular buffer xnodes installed.

buffer.zip

  • Like 1

Share this post


Link to post
Share on other sites

How often you write new elements versus how often you have to read the whole array may also skew the preference given to one scheme. For example, if you write often a single element, just replacing it in place at (i mod N) may be efficient, whereas the readout which involves an array copy may be left with a more expensive solution. This is my go at it, not double checked, may be bugged.

w.pngr.png

  • Like 1

Share this post


Link to post
Share on other sites
On ‎11‎/‎14‎/‎2017 at 7:08 PM, crossrulz said:

Personally, I found a fixed sized lossy queue to work very well as a circular buffer.

That is what I typically use... Generally I wrap in a class.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Similar Content

    • By David Akinpelu
      I am implementing a TCP connection between MyRio(client) and Python(server). The goal is to send data from the server to the client, perform some calculations, and send the result to the server. I need to keep changing the data being sent to the client. I noticed the first data works fine and the result returned to the server, but the client could not read subsequent data. I debugged and was able to detect that the error is coming from the first read function is the "Reading values subvi"  but I don't know how to correct it. How do I go about it?
      I have attached the files below.
      Reading Unknown Bytes from TCP.vi Second_client.vi SimpleServer.py
    • By Deon
      The Threshold Hysteresis VI allows an input (for example, a sensor) to drift out of an inner limit without generating an invalid flag, but if it drifts outside an outer limit it then becomes invalid. For the reverse, when the input crosses back into the outer limit it remains invalid until the value falls inside the inner limit.
      For simplicity, only one input parameter is provided for both the inner & outer limits, and is negated for the lower limit, as generally tolerance limits are equidistant from the nominal.
    • By Deon
      View File Threshold Hysteresis v1.0 LV8.6.1
      The Threshold Hysteresis VI allows an input (for example, a sensor) to drift out of an inner limit without generating an invalid flag, but if it drifts outside an outer limit it then becomes invalid. For the reverse, when the input crosses back into the outer limit it remains invalid until the value falls inside the inner limit.
      For simplicity, only one input parameter is provided for both the inner & outer limits, and is negated for the lower limit, as generally tolerance limits are equidistant from the nominal.
      Submitter Deon Submitted 11/10/2014 Category General LabVIEW Version License Type  
    • By jossie
      Hello I am quite new to labview and I have some questions regarding labview. We have came up with a simulation build in labview as shown in the folder. However, we will be making use of Myrio to connect current and voltage sensors to send the data to labview when labview is running. We are currently having difficulties trying to search if it is possible to send the wave files and the popout messages ( messagebox.vi and Player2Wins.vi) to NI Dashboard for Labview in Ipad by using myrio. Is it possible for myrio to store wave files and the additional VIs and sending these to NI Dashboard for Labview? 
       
      Otherwise, it is possible for Labview to send the entire program.vi, messagebox.vi and Player2Wins.vi to cloud and people are able to see the GUI in program.vi remotely? ( We have found information like Labview web services etc. We hope that people are able to view our GUI and press the " Press start" button as well as closing the popout messages in a website not from our local network). 
       
      I sincerely apologize if what I am asking does not make sense to people who are reading this. I hope that someone will help me with this as it is very difficult for me to do and I need some guidance from people who are familiar with these. Thanks for taking your time to read and your reply. 
      Simulation_Build_(3).zip Pop-up_Message.vi Player2Wins.vi
    • By edupezz
      Hello, i created a new tips repository in:
      https://edupez.com/
      English and Portuguese
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.