LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

running average for 20 sec multiples

Hello, 

 

I am completely new to labview and have a data accqusition/running average question. 

Goal: Record data of every 50 transitions of a square pulse (Frequency 1Hz, 1 full cycle = 800ms), Have a running average of the data collected for over 20ms. 

 

My trigger is a square pulse, I am recording an analog signal and using the NI USB-6009 DAQ hardware. I want to average the data collected for alternating 50 transitions of the square pulse. That is, average 0-50, do not average data from 51-100, average data from the 101th transition to the 150th transition and so on.

 

 

Sampling rate = 2.5 hz. 

number of samples = n 

 

Once the average is obtained, I would like to plot the average after every 50th transitions and also store the averages in a spreadsheet. I have a rough idea of how to go about it, but need a proper direction. 

 

Please help. 

 

Thank You

 

 

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

Welcome to the Forums.

 

Some of your data is not clear. A frequency of 1 Hz means that a full cycle is 1000 ms, not 800. In the subject line you specify a running average oer 20 seconds but in the text you say 20 milliseconds. Since 20 ms is meaningless for a 1 Hz signal, I presume that is a typographical error.  50 transitions represents 25 seconds, which is inconsistent with your 20 second requirement.  The average for 50 transitions, do not average, average ... is not what is usually considered a running average.

 

With the sampling rate as slow as 2.5 Hz you may not get very good averaging. This shows the samples from a 1 Hz signal sampled at 2.5 Hz over a 10 second interval.

 

Samples.png

 

This shows the original signal plus the samples.

 

Signal plus samples.png

 

 

Note that in this data set some cycles of the 1 Hz signal get 2 samples during the high portion of the pulse and others get 1 while all the low portions get 1 sample. At other phases the ratios will change.

 

You should probably sample much faster, perhaps 100 or 1000 Hz. The amount of data you collect will still be quite small.

 

Lynn

0 Kudos
Message 2 of 7
(2,978 Views)

Sorry About the errors, I can try to state it more clearly, 

 

I have a continous square pulse of frequency 1 Hz, 5V amplititute and a sampling rate of 2.5. I want to average the data obtained in response to the leading and lagging edge of the square pulse. (pertaining to my experiment). The average of the first 50 transitions, i intend to store in a file along with the respective time stamps. I do not want to average the next fifty transitions (51-100) but would like to average the fifty after that i.e 101 to 150.  (And store the average against time stamps in a new file/excel column) As 50 transitions at 1hz and 2.5 sampling rate is 25 seconds of data, how do i go about average and storing alternating 25 seconds of data??

0 Kudos
Message 3 of 7
(2,965 Views)

Your comments do not make much sense. With 2.5 Hz sampling, you will almost never capture the transitions on your 1 Hz square wave.

 

If the pulse frequency  and amplitude are fixed, what, exactly, will you be measuring? Do you have some type of pulse width modulation occuring?

 

I understand exactly what you are saying about the 25 seconds alternations. What I do not understand is what you are actually trying to measure.

 

Lynn

0 Kudos
Message 4 of 7
(2,959 Views)

The square pulse is used to turn LED's on and off. I am measuring retinal potentials obtained as a result of turning on and off an LED. The retinal potentials collected for 50 ON and OFF transitions of the LED should be averaged. (For alternating 25Seconds) I hope this works. 

 

Thank You, 

 

0 Kudos
Message 5 of 7
(2,957 Views)

OK. That makes more sense.

 

What you probably should do is use 2 analog input channels. One will measure the square pulse. The other will measure the retinal potentials.  The sampling rate should probably be at least 100 Hz or higher. Then compare the pulse channel to a threshold. When the pulse is above the threshold the LED is on. Separate the retinal signals according to when the LED is on or off. Also count the transitions and do your averaging accordingly. 

 

Lynn

0 Kudos
Message 6 of 7
(2,940 Views)

The Retinal response is  due to a collective pattern of  a bunch of LEDs going on and off (This is triggered by a square pulse coming from the function generator as mentioned earlier). I have attached a flow chart of the setup/idea I have.

 

I have attached a  mock VI with simulated signals (for starters)  is written in order to separately identify the signals (retinal, for example) when the LED's  are on and off (based on the case structure). However the data that I obtain is exported to matlab where it matches the time stamp and organises the signals (for both on and off LED's) based on time elapsed (code not included). Once i get this data, I manually transfer the time versus amp (retinal signal responses) to excel and average it. 

Is there any way, I can use just labview to do it? if so could you please guide me. I hope this helped. 

In my search, I found another VI where n data points are averaged every 10 seconds (http://forums.ni.com/t5/LabVIEW/how-to-average-n-datapoints-every-10-seconds/td-p/1060978). I figured this would give me a good direction as well, is there any way instead of averaging data every 10 seconds (25 in my case)i can average alternatingly (that is every0-10, 20-30, 40-50...). if not is there any way I can write only the needed averaged data to a file or make a file for every average and discard the files with the average of random noise. (that is 10-20, 30-40....) ??

 

Thank You

Download All
0 Kudos
Message 7 of 7
(2,922 Views)