Extract Tabular Data From Frequency Response Result

In this example script we extract the tabular data from a frequency response result named Frequency Response. In addition to Frequency / Amplitude data we also get Phase, Real and Imaginary data through InternalObject.CreateTabbedFile(‘’). Then, from the tabular data, the peaks are extracted. The values are stored in a dictionary (keys = Frequency(peak), values = Amplitude(peak)) and finally we create and sort a list based on highest -> lowest amplitudes(peak).

Transparent

# RESULT OBJECT BY NAME
resObj = DataModel.GetObjectsByName('Frequency Response')[0]
#------------------------------------------------------------#
import collections
freqAmpDict = {}
tabbedFile_init = resObj.InternalObject.CreateTabbedFile('')
tabbedFile_replace_tab = tabbedFile_init.Replace('\t',',')
tabbedFile = tabbedFile_replace_tab.Replace('\n',',')
tabbedFile = tabbedFile.Split(',')
tabbedFile = tabbedFile[5:]
freq    = [float(tabbedFile[i]) for i in range(0,tabbedFile.Count-1,5)]
amp     = [float(tabbedFile[j]) for j in range(1,tabbedFile.Count-1,5)]
phase   = [float(tabbedFile[k]) for k in range(2,tabbedFile.Count-1,5)]
real    = [float(tabbedFile[l]) for l in range(3,tabbedFile.Count-1,5)]
imag    = [float(tabbedFile[m]) for m in range(4,tabbedFile.Count-1,5)]
for index, ampMag in enumerate(amp):
    if index != 0 and index < freq.Count - 1:
        if (amp[index+1] < ampMag and amp[index-1] < ampMag):
            freqAmpDict.Add(float(freq[index]),amp[index])
sortedFreqAmpDict = collections.OrderedDict(sorted(freqAmpDict.items(), key = lambda index_: index_[0]))
#------------------------------------------------------------#

# EXTRACT AMPLITUDES LIST

# SORTED AMPLITUDES MAX ---> MIN
# ampliutudes[0] = HIGHEST
# ampliutudes[1] = SECOND HIGHEST
# ampliutudes[2] = THIRD HIGHEST
# ....

amplitudes = sorted(list(sortedFreqAmpDict.values()), reverse=True)