LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

averaging

Solved!
Go to solution

Hello every one,

 

I have a question about signal averaging in labview. Please help me.

 

I have two signal inputs to my LabView code, one is coming from a function generator (sawtooth with frequancy of 10Hz and amplitude of 0.4V) and the other one from a detector. For each voltage coming from the function generator, there is a response from the detector so I can have a graph on my code that vertical axes is detector response and horizontal axes is voltage of the generator (the graph is a linear signal passing from the origin).

The frequency of the generator is 10Hz and I have 10 signals per second (as time passes, a lot of signals can be seen on each other). Now, how can I tell LabView that update the graph each 5 seconds, when 50 signals has been averaged? Actually I need to see only the final signal which is an average of 50 raw signals.

 

Your help will be really appreciated

 

Thanks

Soran

0 Kudos
Message 1 of 12
(4,303 Views)

Hi Soran,

 

Do you have a VI which I can take a look at? One way to start is to use a combination of shift registers and compound arithmetic. 

 

For the example below, I'll be using a random number as my data acquisition signal value:
,Capture.JPG

So then the code runs at the first time, I would like to initialize the value with the first value received from the random number. After that I'll divide them by 5. Noticed that I have connected the random number value inside the while loop to the right side of the shift register. This is to replace the one of the stack of the stacked shift registers with the updated value (everything outside the while loop runs once). I would like to think of stacked shift register almost like a FIFO buffer. 

 

Shift registers: http://www.ni.com/gettingstarted/labviewbasics/shiftregisters.htm

 

Else, you can do somethink like below:
Capture2.JPG

Where I'm running the For loop 50 times to store the value from the signal into an array of 50 elements. Sum up all the elements and average them. 

 

 

Or you can you queues to make something like a producer consumer architecture: http://www.ni.com/white-paper/3023/en/

 

Hope that helps

 

Warmest regards,

Lennard.C

Learning new things everyday...
Message 2 of 12
(4,270 Views)

Hello Lennard,

 

Thank you for your reply and suggestions. I am working on the solutions you have provided me.

I am attaching the code. You see thee is a XY graph that illustrates the detector response in Y and generator voltage in X. Please inform me if you have any other points that can help me.

 

Again, I do appreciate your help.

 

Soran

0 Kudos
Message 3 of 12
(4,229 Views)

Hello Lennard,

 


I tried to use "Flat Sequence Structure" just like attached capture. I was wondering when the voltage (from function generator) goes in to the first Structure, X1 array gets the data in 100ms (which is the period of the function generator) and after this time X2 array starts to get new data from the second period and next for the third, fourth, and fifth one so that after 0.5s I can average all the X1,X2,X3,X4, and X5 arrays and do the same for Y1,Y2,Y3,Y4,and Y5 arrays (and so each 0.5s I can have a plot which is the average of 5 different data). But it did not work as the all the Xis get exactly the same numbers and it means that the data that second Structure gets is exactly the same one that 1st, 3rd, 4th, and 5th one get. Do you know what the problem is here and why this idea does not work?

 

Thank you,

Soran

0 Kudos
Message 4 of 12
(4,196 Views)

@Soran wrote:

But it did not work as the all the Xis get exactly the same numbers and it means that the data that second Structure gets is exactly the same one that 1st, 3rd, 4th, and 5th one get. Do you know what the problem is here and why this idea does not work?

 



This is normal dataflow. All your indicators will get the same value, because they are reading the same wire. There will only be new data on the wire after the outer while loop has advanced to the next iteration and the data source has been read again.

 

You really should do a few basic LabVIEW tutorials first.

Message 5 of 12
(4,180 Views)

Hi Soran,

 

As mentioned by altenbach, this is a normal dataflow. Currently in one iteration, Xi (where i = 1-5) is getting its value from the same source (X source) and Yi (where i = 1-5) is getting its value from the same source (Y source). There will only be new data on the wire after the outer while loop has advanced to the next iteration and the data source has been read again.

 

Here is some info on dataflow:
http://www.ni.com/gettingstarted/labviewbasics/dataflow.htm

 

As you can see from my previous post (first screenshot), what I have done is that for every new value I received from DAQ assistant at each iterations is transfered to the next iteration via shift register and it is stored inside the stack (since I'm using stacked shift registers). You can just use the solutions which I suggested in my previous post (replace the random number with the DAQ Assistant) but I suggest that you should try to build exactly what I have build in my previous post and try to run it under highlight execution (https://www.ni.com/gettingstarted/labviewbasics/debug.htm) for you to see what is going on. 

 

Here is some info on shift registers:

http://www.ni.com/gettingstarted/labviewbasics/shiftregisters.htm

 

http://zone.ni.com/reference/en-XX/help/371361G-01/lvconcepts/shift_registers_feedback_node/

http://zone.ni.com/reference/en-XX/help/371361H-01/lvhowto/using_shift_registers_to_r/

 

Warmest regards,

Lennard.C 

Learning new things everyday...
Message 6 of 12
(4,142 Views)

Thank you Lennard, your comments were was really helpful.

I used the shift register and a "Elapsed time.vi" (attached) to tell the prograam get data after each specified time. Now, my problem is that this vi does not work for the times less than 1 second. In my case, I need the loop get data each 100ms (and after 10 times average them). Do you have any other suggestions to get data after 100ms?

 

Thank you very much,

Soran

 

 

 

 

 

0 Kudos
Message 7 of 12
(4,073 Views)

Can you attach the VI instead of a picture please. Thanks!

0 Kudos
Message 8 of 12
(4,065 Views)

For sure. Attache is the VI.

Thank you very much for your help.

 

Soran

0 Kudos
Message 9 of 12
(4,054 Views)
Solution
Accepted by topic author Soran

Hi Soran,

 

I believe the problem is that when the time has elapsed, you stopped the program and plot the thing at the XY graph. Problem is that when you stop the code, the graph clears (of course there is that uninitialized shift registers which holds the value of your latest past run results). The easiest way is to use queues via Producer Consumer architecture (http://www.ni.com/white-paper/3023/en/).

 

From the block diagram below, you can see that I have 2 while loops. One is the producer where I store the values from DAQ assistant in a queue while the lower loop is my consumer which I extract the data stored in the queue. So for every 100ms, Elapsed Time will send a True value to the case structure which stores the value to the queue (you'll need to play around with the DAQ Assistant settings). If not, the producer while loop runs the false case shown in the second screenshot. At the consumer while loop, there is a Get Queue Status.vi which checks for the status of the queues. Once there is 10 elements in the queue, I flush them out (true case structure runs) which gives you an array of 10 elements. I sum the array of 10 elements and divide them by their array size (should be 10) and plot it to a waveform chart. Else, the consumer while loop runs the false case (meaning no elements is flushed out and let the data to be buffered).

producer consume.JPG

 

producer consume 2.JPG

 

Just take the above screenshots as for your own reference. I'll leave the rest to you on how you want to adapt that concept in your code. 

 

Hope that helps

 

Warmest regards,

Lennard.C

Learning new things everyday...
Message 10 of 12
(4,019 Views)