10-05-2020 10:31 PM
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.
10-06-2020 02:42 AM - edited 10-06-2020 02:44 AM
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...
10-06-2020 10:19 AM
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