LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Producer Consumer - acquire and analyse different number of samples

Solved!
Go to solution

Hello,

 

I'm making application which use Producer-Consumer loops to acquire data with DAQmx with sample rate 50000 samples/sec.

 

In producer loop i have DAQmx Read function which reads 2500 samples in each loop literation. I send this data to consumer loop via queues.

 

In consumer loop i need to analyze data, but to do this i need one second portion od data (50000 samples). Unfortunately queue gives only 2500 samples in one literation of producer loop, and in next literation queue fills with another 2500 samples.

 

I want to read only 2500 samples from DAQ, because in producer loop i have graph which shows me actual acquiring signal, and i have fast refresh of graph (50000/2500=20 times per second). But in consumer loop i need 50000 samples to analyze. I can't lose any data, everything must be analyzed.

 

What i have to do?

 

Regards

Kacper

0 Kudos
Message 1 of 7
(3,145 Views)

In your consumer loop, take the 2500 samples and build it into an array that you maintain in a shift register.  Once you have acquired 50,000 samples, then analyze it.  When the next 2500 samples comes in delete the oldest 2500 samples from the array and had the newest 2500 samples.

Message 2 of 7
(3,139 Views)

OK, but where i have to do shift registers? In a while consumer loop? Or i must build for loop inside consumer loop?

0 Kudos
Message 3 of 7
(3,131 Views)

Yes, in the consumer loop, because that is where you are dequeueing the smaller, 2500 sample size data packets.  You don't need to put any smaller For loops inside of that.

0 Kudos
Message 4 of 7
(3,114 Views)

I did what you can see on attached picture. There is a shift register in consumer while loop, and graphs outside. When 50000 samples are wrote to array, the loop stops and i can see this 50000 samples on graphs. And this's OK. But this loop executes only once.

 

What i have to do to run this loop again?

Consumer Loop

0 Kudos
Message 5 of 7
(3,084 Views)
Solution
Accepted by topic author kacperek

Don't stop the loop based on 50,000 samples.  Only stop it when the program is supposed to stop.

 

Use a case structure in the loop based on whether 50,000 samples have been acquired to determine whether to just add to the array, or to add the new data to the array and remove the oldest data from the array.

0 Kudos
Message 6 of 7
(3,076 Views)

Ok. Big thanks Ravens Fan. Finally it works.

0 Kudos
Message 7 of 7
(3,026 Views)