LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to contentiously build upon a 2D array, but limit the array length.

Greetings! I am working with the NI-USRP and I am trying to make a spectrum analyzer that keeps a history in an intensity graph. I am following this tutorial [http://www.ni.com/tutorial/13882/en/]. My program seems to be only recording one frame at a time. I tried running a shift register from the output of my array back into the input and that kind of worked, except it eventually made the array so big I ran out of memory. Can I continuously add on to my array until it reaches a certain length, then start over? Thank you for your time.  

 
 

 

 

Download All
0 Kudos
Message 1 of 3
(806 Views)

Do you want to fill your array and then start over (with an empty array)?  Or fill the array and when it's full, overwrite at the beginning?

 

The first is quite simple. Simply check the array size, and if it's beyond a limit, use an empty array.

 

The second is a bit trickier. But it helps to know how this is called: a circular buffer. They come in different forms, each with benefits (fast write vs fast read vs low memory). The principle is this. Allocate an array once (allocation is expensive). Write a sample, keep the 'pointer'. Once the pointer overflows (quotient & remainder), you're overwriting the beginning. Reading is a matter of getting the two parts (or one if there hasn't been an overflow yet) and stitching them together. This makes a fast write, and a slower read. Other schemes make a slower write and fast read (rotating the array), or memory could be doubled to make a fast write and fast read.

 

You'd usually put either solution in a GFV or a class. In a class hierarchy, you can even implement both methods, and choose a child during runtime...

0 Kudos
Message 2 of 3
(754 Views)

Nowadays when I want a circular buffer, I often try to make use of the "Lossy Enqueue" function with a fixed-size queue.  It's always a fast write, then it's a slow read if you "Preview" without dequeueing or it can be a fast read if you read all elements while removing them from the queue.

 

I've kinda liked the double-memory fast write fast read approach too, because I've usually been able to spare the extra memory.in the apps where I used it.

 

 

-Kevin P

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
0 Kudos
Message 3 of 3
(731 Views)