04-11-2017 04:37 AM
Hi all,
I'm looking to include in my script the calculation of the average of a channel (sys_power) based on conditions of 2 other channels (engine_RPM & comp_temperature). I am setting the engine conditions at [795 < RPM < 805], and [-21 < T < -19].
Whenever these conditions are met, I would like to take the values of sys_power at these conditions, and take an average.
I've been playing around with a few functions, such as ChnEventStatArithMean and For loops, but to no success so far! Any help appreciated.
Andrew
Solved! Go to Solution.
04-11-2017 05:14 AM - edited 04-11-2017 05:15 AM
Hi,
You will find a very detailed example already installed with DIAdem called "Test Rig Analysis".
It basically includes everything you need to get mean values for specific channel events:
http://zone.ni.com/reference/en-XX/help/370858M-01/exploff/examples/expl_valve_analysis/
As this is very detailed, I created a more simple example for you based on the DIAdem example_data.tdm file.
It should be ready for direct use:
dim i, MeanVals() call Data.Root.Clear() call DataFileLoad(ProgramDrv & "Examples\Data\example_data.tdm") 'find all events for speed between 20 and 100 ChnEventList1 = ChnEventDetectionWindow( , "[1]/Speed", 20, 100, 0, 0) 'find all events for Revs between 4500 and 5000 ChnEventList2 = ChnEventDetectionWindow( , "[1]/Revs", 4500, 5000, 0, 0) 'combine events with logical AND ChnEventResultList = ChnEventOperationAND(ChnEventList1, ChnEventList2) 'resize array for mean values redim MeanVals(ubound(ChnEventResultList,1)) 'calculate mean values for all events for i=0 to ubound(ChnEventResultList,1) MeanVals(i) = ChnEventStatArithMean("[1]/Torque",ChnEventResultList,i) call LogfileWrite(MeanVals(i)) next
In DIAdem 2017 this will become more easy as you can directly select characteristic values in the analysis dialog:
Regards
04-11-2017 06:26 AM
Hi Christian, that's great thanks.
One final question, instead of showing the Mean Values in the log file, its more use to me if I write them to a channel. What is the best way of doing that?
Thanks,
Andrew
04-11-2017 06:36 AM
Here's one possible way:
dim i, oMeanChn
call Data.Root.Clear()
call DataFileLoad(ProgramDrv & "Examples\Data\example_data.tdm")
'find all events for speed between 20 and 100
ChnEventList1 = ChnEventDetectionWindow( , "[1]/Speed", 20, 100, 0, 0)
'find all events for Revs between 4500 and 5000
ChnEventList2 = ChnEventDetectionWindow( , "[1]/Revs", 4500, 5000, 0, 0)
'combine events with logical AND
ChnEventResultList = ChnEventOperationAND(ChnEventList1, ChnEventList2)
'create channel for mean valuen
set oMeanChn = Data.Root.ChannelGroups(1).Channels.Add("Mean Values", DataTypeChnFloat64)
'calculate mean values for all events
for i=0 to ubound(ChnEventResultList,1)
oMeanChn(i+1) = ChnEventStatArithMean("[1]/Torque",ChnEventResultList,i)
next
04-11-2017 08:07 AM
Hi Christian,
That's great, I've just tested it with my script and it works perfectly.
Many thanks for your help,
Andrew