ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

Averaging data on specified pattern

Solved!
Go to solution

Hi. I need some help with an script. I am doing 360° with a pattern(+1° ; -0.5 °; +1° ...) and the frequency is 1.6 kHz. I want to do an arithmetic mean on every 4000 Hz samples and to store the values in another channel. I have attached a graph with how the data looks like. Regards 

 

 

Mean value.JPG

0 Kudos
Message 1 of 3
(2,424 Views)
Solution
Accepted by topic author Emilian.M
Option Explicit  'Forces the explicit declaration of all the variables in a script.

'''''''''''''''''''''''''''''''''''''''''''''' * GENERATE FAKE DATA - START * ''''''''''''''''''''''''''''''''''''''''''''''
Call Data.Root.Clear()
Data.Root.Name = "Example"
Dim DataGrp, DataChnl, i, j
Set DataGrp =  Data.Root.ChannelGroups.Add("Data")
Set DataChnl = DataGrp.Channels.Add("360", DataTypeChnFloat64)
DataChnl.Values(1) = 0

For i = 0 To 999999 Step 1
  If DataChnl.Values(DataChnl.Size) >= 360 Then
    Exit For
  Else
    For j = 1 To 1600 Step 1
      DataChnl.Values(DataChnl.Size + 1) = DataChnl.Values(DataChnl.Size) + 0.000625
    Next
    For j = 1 To 800 Step 1
      DataChnl.Values(DataChnl.Size + 1) = DataChnl.Values(DataChnl.Size)
    Next
    For j = 1 To 800 Step 1
      DataChnl.Values(DataChnl.Size + 1) = DataChnl.Values(DataChnl.Size) - 0.0003125
    Next
    For j = 1 To 800 Step 1
      DataChnl.Values(DataChnl.Size + 1) = DataChnl.Values(DataChnl.Size)
    Next
  End If
Next
'''''''''''''''''''''''''''''''''''''''''''''' * GENERATE FAKE DATA - END * ''''''''''''''''''''''''''''''''''''''''''''''

' Generate the mean channel
For i = 1 To DataChnl.Size Step 4000
  Call ChnStatisticsChannelCalc("" & DataGrp.Name & "/" & DataChnl.Name, 32, i, i + 4000, False, True, False, "NameName")
  If DataGrp.Channels.Exists("ArithmeticMean1") Then
    DataGrp.Channels("ArithmeticMean").Values(DataGrp.Channels("ArithmeticMean").Size + 1) = DataGrp.Channels("ArithmeticMean1").Values(1)
    Call DataGrp.Channels.Remove("ArithmeticMean1")
  End If
Next
Message 2 of 3
(2,384 Views)

Thanks a lot @gsklyr. Its doing exactly what I need it. Best regards

0 Kudos
Message 3 of 3
(2,368 Views)