Reading and Writing TDMS-Files in MATLAB
TDMS is a binary file format structured in three levels of hierarchy called file, channel group, and channel. The data is recorded in each channel and metadata can be added to each level of the hierarchy. Learn how to inspect and read TDMS-files in MATLAB® using Data Acquisition Toolbox™, how a datastore can be used to analyze a collection of TDMS-files, and finally, how to write data to a TDMS-file and update its metadata.
The example showcases the vibrational analysis of a rotating shaft. On the rotating shaft, there are two displacement sensors—X and Y—that measure changes in distance between the machine’s rotating element and its stationary frame. There is a key phasor signal that provides a reference point in the machine’s rotation to correlate other vibration signals and measure shaft rotational speed.
The 'tdmsinfo' function provides an overview of the file, while the 'ChannelList' field shows the channel groups and channels in the file. The 'tdmsreadprop' function provides the channel properties such as 'wf_increment', which displays the timestamp in seconds. The data is first read using the 'tdmsread' function and then plotted. Next, a frequency domain analysis is performed on the signals to determine where the machine is out of balance; this is based on the phase shift between the vibration sinusoidal peak and the phase reference pulse.
Datastores in MATLAB allow the user to iterate over a single large file or a collection of files that have the same layout. The 'tdmsDatastore' function is used to iterate over a collection of vibration measurement. The 'transform' function is then run to take in a datastore and function handle, returning a transformed datastore object. Here, a custom function is applied to each of the recorded TDMS-files.
The results of the analysis are written to a new TDMS-file, and data is read back to validate the results. The 'tdmsreadprop' function is used to update TDMS channel properties, such as ChannelGroupName, ChannelName, and unit_string.
Published: 30 Jun 2023