02-28-2011 02:17 PM
I am running the same code in Excel and Diadem.
Here is the Diadem version:
Sub HIC_Calc_EventClick(ByRef This) 'Created Event Handler Dim Timestart, Timestop Dim i,j,k ' counters Dim HCMax ' max hic during calc loop Dim IT11 ' temporary T1 of max hic in loop Dim HIC_36, HIC_15, T1_36,T2_36, T1_15, T2_15 ' HIC and Times start Dim SampFreq ' sample frequency input value Dim PreED ' ms of pre event data Dim Imax ' interval length for HIC calc (number of samples -> 15*freq/1000) Dim IntArray() ' integral of the acceleration array Dim DEL1, Dmax, DA, hc Dim oElem Dim GrpName ' name of group Dim GrpRefNum ' Group reference number Dim ChnRefNum ' Channel referenc number in group Dim NumDpts ' number of data points Dim DC_in ' input data Dim DC_inGN ' input data global channel number Timestart = Timer DC_in = "" oElem = "" SampFreq = LB_SampFreq.Value PreED = EB_PreData.Text Del1 = 1/SampFreq For Each oElem in Portal.Structure.Selection If oElem.IsKindOf(eDataChannel) Then DC_in = oElem.GetReference(ExtendChnName) ' loop to make the groupname i=0 j="" while j <> "/" i=i+1 j=mid(DC_in,i+1,1) wend GrpName = Left(DC_in,i) GrpRefNum = GroupIndexGet(GrpName) ChnRefNum = ChnPropValGet(DC_in, "groupindex") NumDpts = ChnPropValGet(DC_in, "length") DC_inGN = CNo(DC_in) Redim IntArray(NumDpts-1) i=0 j=0 k=0 IntArray(0) = 0 for i = 0 to NumDpts-2 IntArray(i+1) = IntArray(i) + 0.5*(CHdX(i+1,DC_inGN)+ChDX(i+2,DC_inGN)) Next 'HIC36 loop Imax = 0.036 / Del1 HCmax = 0 For k = 1 To imax + 1 Dmax = 0 For j = 0 To NumDpts -1 - k DA = IntArray(j + k) - IntArray(j) If DA > Dmax Then Dmax = DA IT11 = j End If Next hc = Dmax * k ^ (-0.6) If hc > HCmax Then HCmax = hc T1_36 = IT11 T2_36 = IT11 + k End If Next HIC_36 = DEL1*HCmax^(2.5) HIC_36 = Round(HIC_36,1) Timestop = Timer Call MsgBoxDisp("HIC 36 = " & HIC_36 & " over the range of time " & T1_36*1000*DEL1 & "ms to " & T2_36*1000*DEL1 & "ms" & " it took " & Timestop - Timestart &" to calculate the HIC") 'Call MsgBoxDisp("it took " & Timestart - Timestop &" to calculate the HIC") 'HIC15 loop End If Next End Sub
the excell takes 0.86 seconds and Diadem takes 2.98. In this example I am calculating the HIC from data with 6000 samples.
I initially thought that reading the channel into the integral array was the slow part, but it actually seems to be looping calculation.
Any help speeding this up will be appreciated.
Thanks alot,
--matt
02-28-2011
03:11 PM
- last edited on
02-07-2024
08:18 AM
by
migration-bot
Hello Matt,
Since I am not the greatest of programmers, I'll leave the actual execution speed improvement advice to someone who is better at that kind of thing.
I am not sure if you are aware of the fact that the HIC calculation is actually part of the DIAdem Crash Analysis Toolkit and is thus available "natively" (programmed in C++ vs VB) to users who have access to this toolkit.
Here is the ink to a brief description of the toolkit: https://www.ni.com/en-us/shop/product/diadem-crash-analysis-toolkit.html
The toolkit adds all the CFC filters in addition to the HIC and many other crash analysis related functions.
I thought I might just point that out to you in case you weren't aware of that functionality.
Sorry if I pointed out the obvious ...
Otmar
02-28-2011 03:44 PM
We currently only have one license for the crash analysis package. It is not always available. I have used the package and it is much faster.
My problem with the built in functions is that the Dialog boxes are cumbersome and tend to cut-off the longer channel names. I really want to do all my analysis functions from the VIEW tab.
This is what I am working towards...
I am not happy with the speed of the DIAdem VBS. I had hoped it would be as fast as excel.
03-01-2011 09:51 AM
Hi Matt,
I believe your code can be significantly accelerated by moving away from cell-by-cell reads and towards a Channel Calculation. I would be happy to help with this, but in order to test execution speed I would need an example data set of yours. Please post or email (brad.turpin@ni.com) one or more data sets, and I'll see what I can do to speed things up.
Brad Turpin
DIAdem Product Support Engineer
National Instruments
03-01-2011 10:06 AM
I had the same thought initially and added a pop-up msg after the data was read into the array. It popped very quickly. I will email the SUD and CSV file with the resultant G data.