How to read and compare two signals from separate ATFX files
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 provides an example of a simple Python script that reads and compares two different Sine spectrum signals.
For a simple way to import 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 using the following commands in the operating system command prompt or integrated development environment software terminal.
pip install numpy
pip install matplotlib
Reading & Comparing Two Sine Signals
The following code example can be found in: Read_And_Compare_Two_Signals_Diff_ATFX_Files.py.
Import modules for the script are below.
#---Pythonnet clr import clr.AddReference(parentPath + "CI.ATFX.Reader.dll") import numpy as np #---C# .NET imports & dll imports |
The open recording method for two Sine signals is below.
# Change file path here to whereever signal or recording files are #OpenRecording(string, out IRecording) |
After obtaining the IRecording object, the script will receive a list of signals from both IRecording objects and obtain the frame of a specific Sine spectrum signal.
# Get a list of signals # Get the frame of a frequency signal depending on where it is in the list |
The frame in the C# System.Double[] array object must be converted to a usable array that Python can read. This is where the numpy package is used to iterate through the System.Double[] array and convert to a numpy array.
A readable numpy array in Python can be used in the matplotlib package to plot signal graphs.
# Convert System.Double[] to numpy array frame2X = np.fromiter(frame2[0], float) # Plot the signal frames |