LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Number of elements in queue increasing during signal processing

Solved!
Go to solution

In producer loop I am acquiring data from 110 sensors at sample rate 1612.9 

In consumer loop I am using sample compression vi to down sample the data to 100 Hz.

But the number of elements in the queue gradually increasing and leading to not enough memory error. I tried with flush queue option but no luck. Please help.

Data Processing Loop.JPG

0 Kudos
Message 1 of 8
(3,884 Views)
Solution
Accepted by topic author smai

3 possibilities that I see:

 

(1) The producer side (not shown) of Data Queue 1 is running at a higher rate than its consumer side (Data Processing Loop).  This will cause Data Queue 1 to overflow.

 

(2) The consumer side (not shown) for Resample Slow Queue is running at a lower rate than its producer side (Data Processing Loop).  This will cause Resample Slow Queue to overflow.

 

(3) Both (1) and (2) are occurring.

 

You can try to put loop iteration timers to measure the loops rates to give you some insight into the source of the overflow.  My guess would be that the sample compression express VI is being taxed pretty heavily (177,419 datapoints being processed per iteration) and could be slowing down the Data Processing Loop causing Data Queue 1 to overflow.  Its hard to say without knowing what is going on inside of the express VI.  You may have to do the downsampling yourself if it needs to be sped up; this would be a good use case for a parallel for loop.

 

 

Message 2 of 8
(3,825 Views)

As has been mentioned, it is obvious that your processing cannot keep up with the sampling.

 

You really don't show much of your code, but 110 channels at 1600Hz (I assume Hz, but you did not give units) is quite a bit. I have the suspicion that most of the rest of your code also consists of express VIs and dynamic data, which carries a lot of baggage! You know that the sampling rate is fixed across all data and probably that the chunks are of equal size (?), so a simple piece-wise averaging could be done with 1% of the computing efforts. You are trying to enter a canoe race using an aircraft carrier!

 

I think you need to take a step back and intelligently design your system using lower level tools. Shouldn't be too hard.

 

Is this running on a PC or on a RT system? What's the hardware?

Message 3 of 8
(3,808 Views)

Thanks for the reply. I attached the vi. Pardon me the code is not very clean and I am also not an expert. This is because of the sample compression express vi as I can see the number of elements in the queue is gradually increasing

0 Kudos
Message 4 of 8
(3,750 Views)

Thanks for the reply. Total number of channel is 151. It is running on IC-3173 Industrial
Controller.

0 Kudos
Message 5 of 8
(3,745 Views)

Please attach a .zip file.  Don't force people to download 3rd party applications to open .7z file.

0 Kudos
Message 6 of 8
(3,727 Views)

Sorry. Please find the attached

0 Kudos
Message 7 of 8
(3,720 Views)
Solution
Accepted by topic author smai

Your bandwidth (151 channels at 1.6 kHz) needs aren't trivial but they also seem manageable with some strategic coding changes.  Exactly which ones matter most I am not sure, but here are the places I'd explore (in "dataflow" order, not priority order).

 

1. In your DAQ producer loop, you're reading 101 samples at a time from all tasks.  Thus you expect to iterate this loop at about 16 Hz.  That's not bad, but I would consider reading *more* samples at a time, reducing the loop rate so that any overhead happens less frequently.

 

2. Ah, overhead!  The use of "Merge Signals" jumps out as a primary suspect.  All the forum experts agree that the Dynamic Data wire should be avoided whenever possible.  And it's almost always possible.  And in your case it's most definitely possible.

   I would try other methods to collect all your arrays of waveforms together and try to test which one is most efficient for both CPU (your main issue now) and memory (which can have CPU impact).  Here are 3 candidate methods:

  • use Build Array in "concatenate" mode (right click the node for this option) to produce a single 1D array of all your waveforms.    (My gut feel is that this is likeliest to support the most optimizations downstream).
  • use "Bundle by Name" to populate a typedef'ed cluster where each named field is a 1D array of waveforms from a single device.
  • use Build Array in regular mode to produce a 2D array of waveforms.  (With this method, I'd probably find it a little confusing to keep track of what the rows and columns mean.)

3. A smaller contributor to overhead may be all the queries for "available samples per channel".  Even if it's just for troubleshooting purposes, all the tasks should be telling you pretty much the same thing.  I would conditionally query only 1 task, I would do the query *after* the read (when the # ought to be quite low), and I would base the condition on something like the Elapsed Time vi with 1 second intervals.

 

4. In your "Task Starter" vi, your calculation of actual sample rate looks to be probably correct, but it's simpler to query the property SampleClock.Rate which I *know* will be correct.  This is just FYI, not part of the problem you're solving.

 

5. Now let's start looking at your primary consumer, "Slow Write Final".  I certainly agree with others to avoid the Express VI, many of them are known to be somewhat to very inefficient, and thus *all* of them fall under immediate suspicion.  This will serve the additional purpose of getting rid of the also-troubling Dynamic Data wire.

 

6. I assume you *want* a fairly low sample rate but your hardware has a 1.6 kHz minimum, thus the inline data reduction where the full-rate data never goes anywhere.  To really speed things up, I would use a Decimation function with averaging turned OFF.  (You can also experiment with it turned ON, but OFF will be faster.)

 

7. As suggested earlier, I'd try to make use of For Loop Parallelization to put more CPU cores to work on this data reduction.  The independence of each waveform makes this an *excellent* candidate for parallel processing.

 

8. Your feedback node equality comparison is probably hurting you more than it's helping.  With real world signals and double-precision floating point values, it's very unlikely you'll ever get a perfect equality match.  And all you stand to save is 1 slow-rate write operation.

    It's possible the comparison function has enough smarts to exit early at the first inequality out of the large # of potential comparisons it needs to do.  But I don't know that for sure, and I don't think the reward is worth the risk of extra CPU.

   I'd reduce the data, probably via decimation without averaging, and send it off to be written every time.  This has the further advantage of producing an output file with constant time intervals between samples.

 

I'd suggest you try ALL these things at once, not just one at a time.  Assuming your backlog goes away, you could revisit some of these efficiency enhancements.  I think the only one worth messing with is to try decimation *with* averaging, which will have the effect of filtering out some of your signal noise.  The other efficiency enhancements shouldn't have any appreciable downside to trade off.

 

 

-Kevin P

 

ALERT! LabVIEW's subscription-only policy came to an end (finally!). Unfortunately, pricing favors the captured and committed over new adopters -- so tread carefully.
Message 8 of 8
(3,675 Views)