06-05-2019 10:15 AM
Hi all,
I am currently working on a project for which I need a DAQ system that is able to sample at a minimum rate of 1KHz, visualise the data and store it in a file.
I managed to build the program using producer/consumer structure, where the visualisation and data storage are placed in two different loops.
Since there is no need to visualise the data at the same rate as the sample rate (also the program would crash), I just want to visualise it at a sample rate of 10Hz.
However, I am not sure how to implement this part into my code.
I have read about someone with a similar problem who solved it with a notifier. However, I don't know how to use them and I am also not sure if that could be used in my code.
Another option might be to use the index array, and get the values for every 100th row when 1000 samples are acquired. But I have not managed to program this so far.
I have attached my current code.
Thank you!
Solved! Go to Solution.
06-05-2019 10:35 AM
Suppose you sample at 1 kHz, and take 100 samples at a time (so your Producer and Consumer loops run at 10 Hz). Instead of plotting the 100 samples, plot their average (there is a "Mean" function on the Mathematics Palette). Since you are plotting to a Chart, the Chart will update at 10 Hz. Problem solved.
Bob Schor
06-05-2019 10:53 AM
You have a few options:
-Plot every 100th point (simple, but you miss lots of data)
-Plot the average of every 100 points (smoother data, but you lose peaks/valleys)
-Plot the max and min out of every 200 points (least smooth data, but you're guaranteed to catch teeny max and min values)
It all depends on what you're doing with the data. Usually I do the averaging method, but I've done the max and min version before.
As for the actual method, first come up with a way to trigger "something" at 10 Hz. I'd go with your producer firing something every 100th sample. When you have that figured out, you can use a queue (preferred) or a notifier to send the data to a plotting loop, which can use a chart or graph or whatever. I prefer a queue, as notifiers are lossy- if you miss a notification, you just miss it. Since you're pulling data out piecemeal and compiling it elsewhere, you want something lossless, like a queue.
06-05-2019 11:10 AM - edited 06-05-2019 11:29 AM
Thank you for the comments, I am going to try and implement it in the code tomorrow.
For the visualisation it is OK to loose data points.
However, they need to be stored at 1KHz.
06-05-2019 12:33 PM
@fcappon wrote:
You need to fix up your code.
Some Suggestions:
Other problems with your code:
You are continuously creating a task until you hit the start button. This will cause a memory leak, along with a bunch of open tasks. Use an Event Structure or move the creation of the task outside the while loop and just have the start button in the while loop. (Recommend the former.) If you end up using a while loop then put a delay in it, do not spin the loop as fast as you can.
You are splitting your queue here, no good. You don't know which loop is going to dequeue, that is, you have a race condition. (The save data may dequeue and save the data or the indicator loop may dequeue and display the data but not save it.) You need two queues if you want to use this method.
Your DAQ will also start before file saving is ready, is this what you want?
Please look at the examples, specifically the one I mentioned. You can have the Event update every 100ms to display data while saving it concurrently. If your sample rate is at 1kSa/s, you will not need to decimate your data, when you go to a higher rate you may have to change the way you are displaying data.
mcduff
06-06-2019 04:03 AM
Thank you, by removing the split in the queue the data is stored and visualised correctly.
Unfortunately, I cannot open any of the LabVIEW examples from a University computer.
Is it possible to upload it here?
06-06-2019 08:03 AM
If LabVIEW is (correctly) installed on a University Computer, then the Examples should be installed, as well. They are in an "Examples" folder underneath the folder for the specific LabVIEW Version you are running.
Bob Schor
06-06-2019 10:16 AM
Thank you, I managed to find it via the program files.