Calculating Programaticaly the Frequency of a Channel in Diadem

Updated Aug 23, 2024

Environment

Software

  • DIAdem

When working with timed bound channels in DIAdem, such as waveform channels or timed channels, there will always be interest in knowing the characteristics of the channels such as period and frequency. 

This article explains how you can calculate programmatically the frequency of a waveform channel or a timed channel, using Visual Basic Scripting in DIAdem. This article assumes knowledge of:
  • DIAdem Visual Basic Scripting. If you are not familiar with this topic visit the Programming Reference section of the DIAdem documentation. 

To determine the frequency of a channel it is required to have a channel associated with time, it could be either a Time Channel or a Waveform Channel. Other types of channels such as Numerics, XY or Text Channels will not have enough information that would let determine the frequency.

Follow the next steps to determine the frequency based on its type:

Waveform Channel 

Use the "wf_increment" property of the Waveform channel to determine the Waveform Step Width or Period of the function. Then the Frequency will be Calculated with the reciprocate of the period as shown below:
Dim XStep
Dim Frequency
Dim groupNum
Dim xChnName 
groupNum = 1
xChnName = "Channel Name"
XStep=Data.Root.ChannelGroups(groupNum).Channels(xChnName).Properties("wf_increment").Value
MsgBox "The Waveform x-step width is: "& XStep&" s"
Frequency= 1/XStep
MsgBox "The Waveform Frequency is: "& Frequency &" Hz"

Time Channel 

The step width used in the Waveform channel will need to be calculated by subtracting 2 consecutive values. Then the ConvertTimeType() function will convert the timestamps to subtractable values for the Frequency calculation. 
Dim X2, X1, groupNum, xChnNum, XStep1, XStep2, Frequency
groupNum = 1
xChnNum = 1

X1=Data.Root.ChannelGroups(groupNum).Channels(xChnNum).Values(1)
X2=Data.Root.ChannelGroups(groupNum).Channels(xChnNum).Values(2) 
X1=ConvertTimeType(XStep1, eConvertDIAdemDateTime)
X2=ConvertTimeType(XStep2, eConvertDIAdemDateTime)

msgbox("X2-X1: "& (X2-X1)&" s")
msgbox("Frequency: "& 1/(X2-X1)&" Hz")