How to read frequency domain signals from CI Data Files in C#, Python, and Matlab
Introduction
The CI Data File Reader API consists of two DLL files that can be integrated with custom software to directly read and extract data from an ATFX file. This article will demonstrate how to read frequency domain signals in C#, Python and Matlab. There will be similarities to reading time domain signals as the only difference is passing in the spectrum type parameter.
For a simple way to import the C# dll files and open an ATFX file in Python & Matlab, please refer to the How to Read CI Data Files in Python and/or How to Read CI Data Files in Matlab article.
For more detailed information on how to implement the following code sections and properties in a class, please refer to the CI Data File Reader manual and the provided C#, Python & Matlab Demo code. The package can be downloaded from our Programming Corner.
The following Python script uses two packages, numpy and matplotlib, that can be installed by the following commands in the operating system command prompt or integrated development environment software terminal.
pip install numpy
pip install matplotlib
Obtaining Frequency Domain Signal Frame Data in C#
The following is a very short code example of obtaining a frequency signal frame data in C#. The ISignal.GetFrame(int index, _SpectrumScalingType spectrum, string engineeringUnit) method is used to obtain a signal frame from an ATFX file.
The index specifies the starting index of the frame. The data will convert to a scaling spectrum type and is identical for the engineeringUnit string.
The engineering unit string can be left blank, “” to use the default engineering unit the signal was saved as. The spectrum must be specified, but if it is unspecified, the default is (EU)rms2 since the spectrum was not saved in the signal.
To obtain the exact engineering unit string that the CI Data File Reader API can read in, it is recommended to use the Utility.GetSignalQuantityEngiUnitStrings(ISignal) to return a string array that contains the engineering unit strings.
string recordingPath = "C:\Sig001.atfx"; ISignal frequencySig = rec.Signals[10]; string[] engiUnits = Utility.GetSignalQuantityEngiUnitStrings(frequencySig); double[][] frame = frequencySig.GetFrame(0, _SpectrumScalingType.EURMS2, engiUnits[3]); |
Obtaining Frequency Domain Signal Frame Data in Python
The following python script can be found in Reading_FrequencyDomain_Data.py.
The following are the import modules for the script.
#---Pythonnet clr import clr.AddReference(parentPath + "CI.ATFX.Reader.dll") import numpy as np from EDM.Recording import * from EDM.RecordingInterface import * from ASAM.ODS.NVH import * from EDM.Utils import * from Common import * from Common import _SpectrumScalingType from Common.Spider import * from System import * from System.Diagnostics import * from System.Reflection import * from System.Text import * from System.IO import * |
The following is the open recording method for the ATFX file.
# Change file path here to whereever signal or recording files are #OpenRecording(string, out IRecording) |
Then from the extracted IRecording object, the script will obtain the list of signals, obtain a specific frequency domain signal, and obtain the signal frame.
# Get a list of signals # Get the frame of a frequency signal depending on where it is in the list |
The signal GetFrame will return as a System.Double[], which can be used as is, but sometimes it may be better to convert to a more readable Python object such as a numpy array.
print("X: ", frame[0][0]) # Convert System.Double[] to numpy array |
Obtaining Frequency Domain Signal Frame Data in Matlab
The following python script can be found in Reading_FrequencyDomain_Data.m.
The following is the script import the C# DLL files use for the Matlab built-in NET.addAssembly() method. After that, the script will create the IRecording object and then obtain a frequency domain signal.
% Load common and reader dll % Create a atfx recording instance % Use item function to get a time signal instance |
Then the script will proceed to display certain signal properties and obtain signal frame data.
% Display signal properties % Assign the engineering unit disp("display signal frame data"); |
Then it will convert the frame .Net double[][] object to matlab cell to start plotting the signal frame data.
% Convert .Net double[][] array to matlab cell %plot the signal |