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
Featured Product
Data Acquisition Toolbox
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)