# LabVIEW

cancel
Showing results for
Did you mean:

Solved!
Go to solution

## Timed Average

Hello,

I'm trying to average signals collected every 200 ms for 5 mins. I already know how to setup a for loop and get an average of N iternations, but that's basically just noise filtering...I want to take all values over 5 mins and then average them to get a 5 min average of my signal.

What I'm ultimately trying to do is to get a 5min average of my signal and use a shift register to hold than average value to use as my "initial value" or starting pressure in my case. I would then use that starting pressure as and calculate the percent pressure increase over time. After say 30% increase from the averaged 5 min pressure I would run a filter cleaning sequence, and repeat the process and get another 5 min average to use as my new initial value. I basically know how to do all that, but I'm just struggling with averaging the values...and I tried all sort of array stuff and looked at examples for hours and still couldn't figure it out..

I'm first  trying to make it work on a simple labview program (attached image) and once I figured it out I'll make it work on my actual program..

I'm using labview 8...

Message 1 of 10
(3,490 Views)

## Re: Timed Average

Is this VI ok with you to some extent. If not then what problem you think with this VI

Let me know.

Thanks

--------------------------------------------------------------------------------------------------------
Kudos are always welcome if you got solution to some extent.

I need my difficulties because they are necessary to enjoy my success.
--Ranjeet
Message 2 of 10
(3,483 Views)

## Re: Timed Average

Hey Ranjeet,

Thanks for your help, but I can't open the labview file because I have labview 8, is there a way you can save it as labview 8 file.

Thanks,

Amir.

Message 3 of 10
(3,462 Views)

## Re: Timed Average

Why do you feel your simple example does not work?  Other than the never ending while loop it looks like it should calculate the average of the array you are generating.  Just out of curiosity what is your n value/

Herrlin

Just trying to spread the LabVIEW love.
Message 4 of 10
(3,452 Views)

## Re: Timed Average

The mean that is going to be generated in my simple example is the mean of my voltage analog input, meaning the average voltage of 200 iterations. That is going to my voltage at time t. What I want to do is basically somehow log those mean valvues for 5 mins and then spit out an average. So if you look at the table below, I would time the average of all value at 5 mins or 300s...

Makes sense?

Message 5 of 10
(3,447 Views)

## Re: Timed Average

Your wording is still not 100% clear to me.  I put some code together to demo what I think you are looking for, see attached.  The code produces 20 samples every second then at the end of the second they are averaged together and stored in an array.  Let me know if this is close to what you are looking to do.

Herrlin

Just trying to spread the LabVIEW love.
Message 6 of 10
(3,439 Views)

## Re: Timed Average

I'm sorry but I can't open the file you attached beacause I have labview 8.0

What I am trying to say is, every second I'm going to get an average of 200 interations from the for loop..so as soon as I run the program

I would get something like:

T=1s  Average = 41

T=2s  Average = 12

T=3s  Average = 52

T=4s  Average = 53

.

.

.

T= 299s Average = 15

T= 300s Average = 62

So I want to calculate the average of all the averages over 300s...basically sum the averages and divde by the number of points which is going to be 300..

Message 7 of 10
(3,430 Views)
Solution
Accepted by Aquaman89

## Re: Timed Average

I thought I saved it for version 8.0 but may not have.  Try this one.  I think it is close to what you are looking for.

Herrlin

Just trying to spread the LabVIEW love.
Message 8 of 10
(3,427 Views)

## Re: Timed Average

Thank you for your help herrlin.

It was pretty much what I was trying to do. I had to add a 3rd shift register because I really needed the mean of the values in the second column of arrays that.

If you don't mind looking at my program...I'm having another problem and would grealty appreciate your help, again..

I'm trying to reset the array values back to defualt, i.e. 0, after a specified time and I tried to use an "invoke node" but that didn't help. So I put everything in a case structure, but for some reason the elapsed time would not work, so I don't know if what I'm trying to do would work...

If you look at my program it would make sense I hope..

Thanks Again.

Message 9 of 10
(3,393 Views)

## Re: Timed Average

One major issue with your VI is that fact that you are wiring false to while loops that terminate only on true.  So you have created infinite loops.  Also the average you added appears to be a running average just as a FYI this maybe what you want.  Running average means average of all available samples.

I have attached an example of what I would do to have a reset function on a given time.  I created a basic timer VI as I generally try to steer away from express VIs.  The timer VI is a functional global that is initialized to a given timeout time and then is polled to see if time has elapsed.  Once time has elapsed I use this info to reset the array values and the running average.

I am not sure how you will be using this so you may want to tweak it a bit if it will be a top-level VI or a subVI.  Also you should look to improve error handling. Currently the loop won’t stop on an error.  There currently aren’t any VI in it that will generate an error but most likely your sample generation code will.

Herrlin

Just trying to spread the LabVIEW love.
Message 10 of 10
(3,368 Views)