LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Averaging input over time interval?

This might be trivially easy for a lot of you, but it's something I've been struggling with for the past several hours. Basically I want to write a VI that will take an input in response to a square wave, then display within x ms before the first step of the square wave and around y ms after. Additionally, I want to display a running average of all of the waveforms acquired so far.

 

So basically the square wave is alternating between two values, let's say -1 and 1. When it switches from -1 to 1, the VI will take x ms before and display that up until y ms after the change. It will also display an average between all of the waveforms that will be updated after each recording.

 

Right now I'm trying to do this by using case structures in conjuction with reading/writing to files, but it's not working very well. I keep getting an error saying that I'm reading the end of the file when reading from the file, and I'm not sure why this is. Either way, I feel like there has to be a better way to do this.

 

Thanks in advance.

0 Kudos
Message 1 of 4
(2,205 Views)

Hi tim,

 

your "VI" is no VI, it's just a PNG…

 

Please clean up your VI before re-attaching the real VI instead of a picture!

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 4
(2,199 Views)

I can't edit my original post, but I'm currently cleaning up my VI and continuing to struggle with it for a little bit. Having just been introduced to NI Labview, this has been a daunting first task in the world of graphical "programming". I guess until I fix up my VI, any advice on what I might be able to look into to fulfill the requirements listed would be amazing. I just feel like I'm stuck at a brick wall.

0 Kudos
Message 3 of 4
(2,189 Views)

You are using Express VIs to do your data acquisition.  This lets you get data very easily, but doesn't give you much control over things.  Look into DAQmx (do a search for "The Ten Things you need to know about DAQmx", or a similar title).

 

The problem of averaging data that occurs before the trigger is easily solved using a Lossy Queue.  Suppose you are sampling at 1 KHz, and want to save data from 100 msec before the trigger until 200 msec after.  In a 1 msec Timed Loop, take a Sample and put in on a 100-point Lossy Queue.  This conveniently holds the last 100 samples you have taken (I'm skipping over the case where the Trigger comes on, say, the 3rd sample ...).

 

When you get the trigger, switch your samples to a second queue.  In a parallel loop, begin by dequeuing the "before" points from your Lossy Queue into an array, and continue adding points dequeued from the "After" queue until you have added the next 200 points.  You now have 300 points, 100 from before the trigger, and 200 after.  Do with them what you will.

 

A State Machine is a good way to handle "switching states" from "waiting for the event" (where you fill the Lossy Queue), "recognizing the Event" (where you start building your output array with "before" points, "collecting post-Event data", and "handing the data to someone else" (whereupon you return to the "waiting for the Event" state).

 

I realize some of these techniques might sound foreign, but you should be able to find Examples in LabVIEW that discuss some of these ideas.  Find a local LabVIEW guru and don't be afraid to ask her questions!

 

BS

0 Kudos
Message 4 of 4
(2,166 Views)