main content

get started reading a tdms-凯发k8网页登录

this example shows how to read data from a tdms-file into matlab® for analysis.

the example tdms-file contains measurement data of a sine wave amplitude and phase. the measurements are in two channels, in the same channel group.

inspect the tdms-file contents

use the function to obtain channel group and channel names in the tdms-file.

filename = "sinewave.tdms";
info = tdmsinfo(filename);
info.channellist
ans=2×8 table
    channelgroupnumber    channelgroupname    channelgroupdescription       channelname       channeldescription    unit    datatype    numsamples
    __________________    ________________    _______________________    _________________    __________________    ____    ________    __________
            1             "measured data"               ""               "amplitude sweep"            ""             ""     "double"       3500   
            1             "measured data"               ""               "phase sweep"                ""             ""     "double"       3500   

read data properties from the tdms-file

use the function to view data properties from the file.

tdmsreadprop(filename)
ans=1×7 table
       name       description              datetime               author                title                datestring     timestring
    __________    ___________    _____________________________    _______    ___________________________    ____________    __________
    "sinewave"        ""         2022-01-12 23:33:31.000000000    "admin"    "amplitude and phase sweep"    "01/13/2022"    "10:03:31"

specify a channelgroupname and channelname arguments to view properties of a specific channel.

group = "measured data";
channel = "amplitude sweep";
tdmsreadprop(filename, channelgroupname=group, channelname=channel)
ans=1×19 table
          name           description    unit_string     datatype      displaytype        monotony        ni_channelname    ni_expisrelativetime        ni_expstarttimestamp                ni_exptimestamp           ni_expxdimension       novaluekey       wf_increment    wf_samples    wf_start_offset            wf_start_time            wf_time_pref    wf_xname    wf_xunit_string
    _________________    ___________    ___________    ___________    ___________    ________________    ______________    ____________________    _____________________________    _____________________________    ________________    ________________    ____________    __________    _______________    _____________________________    ____________    ________    _______________
    "amplitude sweep"        ""             ""         "dt_double"     "numeric"     "not calculated"        "sine"                 1              2022-01-12 22:08:35.674852848    2022-01-12 22:08:35.674852848          "t"           "not calculated"       0.001           3500              0           1903-12-31 19:00:00.000000000     "relative"      "time"           "s"      

read timetable data from the tdms-file into matlab

to read data into a timetable, derive the start time and time step, typically contained in the channel properties.

timestep = tdmsreadprop(filename, channelgroupname=group, channelname=channel, propertynames="wf_increment")
timestep=table
    wf_increment
    ____________
       0.001    
starttime = tdmsreadprop(filename, channelgroupname=group, channelname=channel, propertynames="wf_start_time")
starttime=table
            wf_start_time        
    _____________________________
    1903-12-31 19:00:00.000000000

using the start time and time step as arguments to the function, read the data into matlab as a cell array of timetables. view some of the data from first channel group.

data = tdmsread(filename, starttime=starttime.wf_start_time, timestep=seconds(timestep.wf_increment));
ttdata = data{1};
head(ttdata)
ans=8×2 timetable
                time                 amplitude sweep    phase sweep
    _____________________________    _______________    ___________
    1903-12-31 19:00:00.000000000           0                   0  
    1903-12-31 19:00:00.001000000           0            0.063418  
    1903-12-31 19:00:00.002000000           0             0.12658  
    1903-12-31 19:00:00.003000000           0             0.18923  
    1903-12-31 19:00:00.004000000           0             0.25112  
    1903-12-31 19:00:00.005000000           0               0.312  
    1903-12-31 19:00:00.006000000           0             0.37163  
    1903-12-31 19:00:00.007000000           0             0.42975  

use a stacked plot to visualize the relationship between the data of different channels.

stackedplot(ttdata);

网站地图