09-03-2023 01:27 AM
it seems like as the shift register content increases the graph plotting becomes slower and slower. for that i have reset the shift register but it deletes the previous data. what i want to do is reset my shift register to increase graph speed to display data but i also want to retain the lastly stored data in array and keep it displayed on the graph but not stored in shift register once reset.
09-03-2023 10:08 AM
Have you taken any of the tutorials (such as those listed on the first page of this Forum) and learned about the difference between LabVIEW Charts and LabVIEW Graphs? When to use one, and when to use the other?
You need to think about how much data do you want to show in your graph. For example, if you are sampling a signal at 100 points/second, and you want to sample (and look at) data for 10 minutes, that works out to 100 points/second * 600 seconds = 60,000 points.
First of all, you probably don't have a screen large enough to show all 10 minutes of data, but you could easily show the last 10 seconds, as this would only require showing 1000 points. Think about how you might (as an engineer) look at a "signal" -- you might use an oscilloscope, or a strip-chart recorder, right? Each takes the "most recent part of the signal" and puts it as a "point" on paper or on a cathode-ray tube -- LabVIEW does this by putting the latest point on a "Chart" (it only needs the Y value, as the X values are assumed to be at regular intervals, such as 0.01" in my made-up example). If you learn about LabVIEW Charts, you can see that they can be like a "Strip Chart", a "Scope Chart", or a "Sweep Chart" (look up the difference between the last two).
Graphs, on the other hand, plot the entire graph each time (which is what you are doing). So if you start with an empty array and put in 1 points, you plot one point. Now you put in a second point -- you end up plotting two points. Then three points, then 4 points, ... As you accumulate points, you are "growing the array" (and you have to keep all those points around.
Now consider the 10-minute example. With a Chart, inside the While loop, you get a sample, write it to disk, and plot it on a chart. You have (at a sampling rate of 100 Hz) 10 msec to do this, no problem at all. You won't see all 10 minutes on your chart, but will see the last 10 seconds (and depending on the Chart type, it might display as a moving waveform going right-to-left, or as a fixed "screen" with new points being added left-to-right). With a Graph, you have to keep all of the data in memory (in order to plot it), so you'll have an array that constantly grows, which means the computer needs to allocate more and more memory, the Graph has to redraw itself with more and more points, so everything slows down.
Bob Schor
09-03-2023 10:52 AM
You are prepending instead of appending new data in each array, meaning the first instead of the last element contains the newest data. This causes serious performance issues because the memory manager needs to work extra hard, requiring constantly to allocate new memory and copying all that to a new locations.
The burden is less (but not zero) of you would append instead.
Do you have a reasonable upper limit in final size?
You could use a chart to only display the last N values and stream all data to disk for post processing.
I assume you don't have a monitor with a billion horizontal pixels, so keeping all data in memory seems a bit silly.
Both your booleans have the wrong mechanical action.
Your loop currently runs as fast as it can, potentially adding millions of points in a short time. Ultimately, you'll run out of memory. Seems obvious. What is a typical loop rate (probably determined by your IO)? Add a reasonable wait to the loop to make things more realistic.