DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Calculate channel average over a specific window

I have a data set that sweeps through a range of test conditions. During this process it dwells at each individual condition for some period. Progress is tracked in a channel where the test starts at 7 and increments up to 256 in steps of 1. Starting at 7 I search for 8 (start of next test condition) using FIND then store that value in ModeX. I know the sampling rate is 0.25hz so I then need to go back -20 and store this in ModeX_y. I need to then use these indexes to define the range where the average values are calculated for each channel. Lastly, increment up to next step 8 to 9 and so on. Appreciate any help.  

 

 

0 Kudos
Message 1 of 9
(3,687 Views)

Hey Phil

 

The statistics function for calculating mean allows you to select a start and end index. If you're writing your index values to a variable, you should be able to pass the variables into the mean function:

 

Call ChnStatisticsChannelCalc("[1]/Time",32,10,1000,0,0,0,"NameName")

0 Kudos
Message 2 of 9
(3,655 Views)

Thank you for the prompt reply. Not sure if this is an issue, I should have mentioned I am working with Diadem ver 2012. I do not see ChnStatisticsChannelCalc but I do see ChnAverage. You are correct to say I am working towards a loop that will find the indexes to set the averaging range. So rookie question here... when I break down ChnStatisticsChannelCalc("[1]/Time",32,10,1000,0,0,0,"NameName") I see:

ChnStatisticsChannelCalc - a diadem function

("[1]/Time", - channel to be averaged

32, - not sure, some channel property?

10, start index, or variable I am storing that in

1000, end index

0,0,0,"NameName") - Something, Something, Something, NewAvgVariableName.

Question, where to I read about the order of formatting for each instance of a , ?

0 Kudos
Message 3 of 9
(3,652 Views)

I am trying to use ChnFind in Diadem2012 to identify the index when a variable steps up.

The dataset is already entered in Dataportal as TDM.

I get an error message that suggests ChnFind is not functioning and creating a value in ModeX.

Error in <DataChannelAVGperMode_03_05_2019.VBS> (Line: 20, Column: 5):
Invalid channel number in "ChnAverage("[1]/Engine_Speed",-26,0,"[1]/AvgEngSpd")" command.

The scriot is intended to sweep through each increment of numSysTestStep starting where it equals 7, then back calculate 26 postions anda use the range for insertion into the ChnAverage function. - appreciate any help - phil

 

Option Explicit

dim x, ModeX,ModeX_y, numSTS, y1

const y2=256, N=26

numSTS = True
for x =1 to 1
y1=7
Do While numSTS
If CNo("["&x&"]/numSysTestStep") > 6 Then
ModeX= ChnFind("Ch(""["&x&"]/numSysTestStep"") >y1")

ModeX_y=ModeX-N

Call ChnAverage("["&x&"]/Engine_Speed", ModeX_y, ModeX, "["&x&"]/AvgEngSpd")
y1=y1+1
End If
If y1>256 then
numSTS = False
End If
Loop
Next

0 Kudos
Message 4 of 9
(3,618 Views)

What does the [1]/numSysTestStep look like? A zero return value from ChnFind indicates that it didn't find any data in the channel that met the condition. I'm also curious--are you looking for the first time it's seven, or the first time it's greater than seven? The code right now will succeed at the first eight, whereas setting y1 to 6 would give you the first seven.

 

To troubleshoot, I would probably make a copy of your code and pare it down to exclude the loop and potentially the if statement, and just work with the ChnFind function until we're getting good data each time, and then add the loop and if back in. Let us know what you find!

Claire M.
Technical Support
National Instruments
Certified LabVIEW Developer
0 Kudos
Message 5 of 9
(3,599 Views)

Hi Phil,

 

Yeah, "-26" is an invalid channel number.  The ChnAverage() function takes 2 parameters, and you're trying to pass more than that.  What version of DIAdem are you using?  All versions will support the StatBlockCalc() command, which you can use to run statistical calculations on just the data in an explicit row range.  Newer DIAdem versions also offer ChnStatisticsBlockCalc(), which is a little easier to use.  

 

Brad Turpin

DIAdem Product Support Engineer

National Instruments

 

0 Kudos
Message 6 of 9
(3,557 Views)

Hi Brad;

My apologies for some of the confusion, angst over this. Yes, I believe you hit the head by asking what version of Diadem I am using; it is 2012. Yes, I read ChnAverage() same as you and thought it only allowed 2 parameters. What I am slow to pick up on is those can only be whole length channels. To be fair, it is the format of ChnStatisticBlockCalc() I was hoping for in ChnAverage(), just wishful thinking on my side. 

Moving forward, I am adding StatBlockCalc() code and the most important consideration is being able to reference the channel indices, or rows to complete each instance of averaging. I am reading where ( ) vs [ ]  is used for channel references but have not absorbed, if or how these may weave into the needs to the code.

Lastly, I cant thank you enough for getting me over the hump here, helping set up ChnFind by inventing Variables was/is key to identifying the channel row indexes. 

  

0 Kudos
Message 7 of 9
(3,510 Views)

This is all in Diadem 2012

[1]/numSysTestStep ranges from 1 to 259 in increments of 1. Each time it gains 1 a new test mode (TestStep) is entered. B/c this is a long test the sampling rate is turned down to 0.25hz. There are 74 data sample entries per TestStep. When I look over the data I settled on 26 being under stable conditions. So the script looks for numSysTestStep to increment by one starting at 6  then uses ChnFind("Ch(T1) => R1" b/c that's when warm-up ends and the true test begins. It then stores this row id in ModeX. Mode X_y is just row id from the end of TestStep 7 - 26. this sets the sample range I want to average . I was trying to pass the row values into ChnAverage; possibly newer versions of Diadem allow that. I now appreciate I cannot do that with my version of Diadem (2012). In its place I tried to use StatBlockCalc, still has odd errors. Interestingly, if I used auto generated script no issues. However, obviously this is without using ChnFind to draw out the proper row range ids. At this instant I 'm struggling to understand if its data type error, i.e I should be calling a string and I'm not or?

0 Kudos
Message 8 of 9
(3,496 Views)

Hi Phil,

 

I think the main issue is that you were trying to pass 4 parameters to the StatBlockCalc() function, when it only takes 3.  Do you know how to look up the function prototype from the DIAdem Help system?  If you highlight the function, then hit F1, DIAdem will take you to the Help page for that function.  The top part of the Help page shows each parameter and describes its function.  At the bottom of the Help page there is example codes showing how to use the function.

 

Anyway, I created a quick DataPlugin to read the CSV data file you sent.  It does the best it can with your "0019" and "0020" date strings, and it ignores the initial "1" column.  I also included the resulting TDM/TDX data file that results form loading the CSV file this way.  Finally, I'm including the VBSscript I created to analyze one group of test channels, which is what is in that CSV file, and produce a new group with average values for each of the channels in each of the row ranges.

 

Brad Turpin

DIAdem Product Support Engineer

National Instruments

Download All
0 Kudos
Message 9 of 9
(3,473 Views)