12-15-2011 03:57 PM
I'm trying to implement a moving average calculation in DIAdem.
The smoothing function won't work for my application since it does not lag changes in the data the way a moving average does.
Can someone recommend the best way to do this? I don't really know any VBS.
I have a VI to do the moving average but I don't know how to pass all the data from a channel to the VI.
Should I save the channel data to a .tdm file, call the VI and pass in the path to the .tdm file, do my calcs in the VI, save the results to a new .tdm file, and then import the .tdm file back into a new channel?
Is this really the best way to do it?
If so, any pointers on how to create a dialog for selecting the channel to be passed would be helpful.
Thanks,
Erik
12-16-2011 12:09 PM
Hi Erik,
You can call your VI with the LVRuntime object in a DIAdem VBScript. In general the best approach for array passing between DIAdem and LabVIEW is file I/O with TDMS files. You can call DataFileSaveSel() and specify the "TDMS" DataPlugin and the channel or channels to save from the Data Portal, then pass the TDMS file path to the VI input using the VI object you get from the LVRuntime object (check out the Bessel function example in DIAdem).
Actually, though, the Smoothing function in DIAdem ANALYSIS is a running average. I'm not sure what you mean by "lagging", are you perhaps particularly interested in a one-sided moving average? The DIAdem function is always symmetric at the middle of the array and can either stay symmetric or use as many points as fits in your moving window size at the beginning and end of the array.
Brad Turpin
DIAdem Product Support Engineer
National Instruments
12-16-2011 12:26 PM
Yes, I need a one-sided moving average.
I'm trying to replicate a process in which a temperature monitor is calculating a continuously running average of the past 30 minutes.
So far I'm able to bring up a dialog box for selecting the channel and then save this channel as a .tdm file.
My vi will open this file and do it's thing and then write the new data to a new .tdm file.
Can you give me some pointers on opening a .tdm file and loading it into the data portal via a script?
Also, is TDMS prefered over TDM for this?
Thanks,
Erik
12-16-2011
12:33 PM
- last edited on
05-09-2025
11:56 AM
by
Content Cleaner
Hi Erik,
Have you taken a look at the document How Can I Calculate a Moving Average in DIAdem? If not, I would definitely suggest taking a look here. While it does use smoothing to calculate the moving average, I believe that you will find it suitable for your application since, as the article explains, the smoothing width looks at points on both sides of the point of interest. If this isn't an option for your application then if you could provide additional details as to what you need the moving average to accomplish that the smoothing function cannot provide, I might be able to offer additional suggestions.
Edit: Sorry, I wrote this before I saw your response Erik.
Regards,
Trey C.
Applications Engineer
National Instruments
12-16-2011
02:37 PM
- last edited on
05-09-2025
11:59 AM
by
Content Cleaner
Another resource you can use to understand the steps required to call a LabVIEW subVI from DIAdem are outlined in this paper: Calling a LabVIEW SubVI from DIAdem. This paper will walk you step-by-step through the process and it also provides a sample script for you to use and learn from.
12-16-2011
02:48 PM
- last edited on
05-09-2025
12:04 PM
by
Content Cleaner
You can also use this command to load data into the data portal from a script. You can enter a path to your file here.
Call DataFileLoad("C:\Example.TDM")
Here is a help article if you want more information about this function.
12-16-2011 04:00 PM
Thanks.
I'm able to call my vi without any trouble.
The vi calculates the moving average, writes a new tdms file, and passes the path to this new file back to the DIAdem script.
In the DIAdem script I use
Call DataFileLoad(PathTo2ndFile,"TDMS","Load")
This all works ok.
But when I run the script a 2nd time, passing a new channel to the vi, the vi writes to the same "new tdms file" but with a new channel name.
Calling DataFileLoad again opens the "new tdms file" but loads the old channel again (under a new group), even though that channels isn't in the file anymore.
I get the same results loading the file from Navigator.
If I delete the group before running the script the second time the new channel loads ok.
It seems like the data store is not being refreshed so Call DataFileLoad isn't really reading the new file.
Calling DataFileSelDlg(PathTo2ndFile,"TDMS") works ok but then I'm having to select the channel each time, even though there is only 1 channel in the file.
I might be rambling. Here's the concise version.
Loading the same .tdms file multiple times loads the same channel under a new group each time, even though the channel name and data in that file change before I open it each time.
Here is my script:
Dim PathtoVI, VI, PathTo1stFile, PathTo2ndFile, Size 'Set up variables
PathTo1stFile = "C:\WIP\temp.tdms"
Call GlobalDim("NumPoints")
Call GlobalDim("ChName")
If SUDDlgShow("Selection","C:\NI\DIAdem\Scripts\Selection.sud") = "IDOk" Then
Call DataFileSaveSel(PathTo1stFile,"TDMS",ChName)
End If
PathtoVI = CurrentScriptPath + "MovingAverage_TDMS.vi"
LVRuntime.Init "10.0"
Set VI = LVRuntime.LoadVI (PathtoVI)
VI.SetControlValue "1stFile", PathTo1stFile
VI.SetControlValue "Size", NumPoints
VI.Run False
PathTo2ndFile = VI.GetControlValue ("2ndFile")
LVRuntime.DeInit
Call DataFileLoad(PathTo2ndFile,"TDMS","Load")
'Call DataFileSelDlg(PathTo2ndFile,"TDMS")
Thanks for the help,
Erik
12-19-2011 04:22 PM
Hi Erik -
What is your desired behavior here? Are you trying overwrite the TDMS file/channel each time, or append to the TDMS file each time? Are you trying to load only the most recent set of data, or the entire [if appended] data set?
If interactively clearing the Data Portal works for you, then you can programmatically do the same thing (Call Data.Root.Clear()).
If loading a channel selectively works for you, then you can use the DataFileLoadSel() command instead of the DataFileSelDlg() to selectively load a channel without the use of the dialog.
For some more personalized advice, feel free to post your files (script, VI) and your desired behavior and I'll try to pinpoint where things are going wrong; I'm having trouble following along with the Desired vs. Actual behavior using the description provided.
12-19-2011 10:29 PM
Hi Erik,
Most people think TDMS files are easier to read and write from LabVIEW than TDM files-- DIAdem doesn't care. In both cases the VBScript command to load a data file is the same, with the second parameter differing depending on which DataPlugin to use:
Call DataFileLoad(DataFilePath, "TDM")
Call DataFileLoad(DataFilePath, "TDMS")
Brad Turpin
DIAdem Product Support Engineer
National Instruments
12-20-2011 01:14 PM
I am overwriting the TDMS file each time.
This was the sequence:
VI creates a TDMS file: Filename = MyFile.tdms, Group = MvgAvg, Channel = Channel1Data
DIAdem script loads channel from MyFile.tdms. Data Portal shows: Group = MvgAvg, Channel = Channel1Data
VI creates another TDMS file: Filename = MyFile.tdms (same file name), Group = MvgAvg (same group name), Channel = Channel2Data (new channel)
DIAdem script loads channel from MyFile.tdms. Data Portal shows: Group = MvgAvg, Channel = Channel1Data1 (same data, just appended name)
Today I'm seeing slightly different results.
The new channel data is loaded but DIAdem is creating a new group each time.
1st import: Group = MvgAvg, Channel = Channel1Data
2nd import: Group = MvgAvg2, Channel = Channel2Data
3rd import: Group = MvgAvg3, Channel = ChannelxData ...
This is still not exactly what I'm expecting but I think I can fix it. The issue I was having on Friday was that it wasn't loading the new file. It seemed as though it was reloading the previous data.
If anyone has any insight, I'd love to understand what exactly is/was happening. Otherwise I'll work on having my VI write several channels to 1 file and then import only the one file.
Thanks,
Erik