Read Data from MDF-Files with Applied Conversion Rules
This example shows you how to read channel data applying conversion rules from an MDF-file and configure different reading options in MATLAB.
Introduction to ASAM MDF Conversion Rules
According to the ASAM MDF standard, a data value encoded in the MDF channel is denoted as a raw value. It can be converted to a physical, engineering unit value using a conversion rule that describes the data. Conversion rules are the methods defined at the channel level to convert raw values to physical values.
ASAM MDF V4.2.0 supports the following conversion rules:
No Conversion
CC_Type 0: Identity (“1:1”) conversion
Numeric to Numeric Conversions
CC_Type 1: Linear conversion
CC_Type 2: Rational conversion formula
CC_Type 3: Algebraic conversion
CC_Type 4: Value to value tabular look-up with interpolation
CC_Type 5: Value to value tabular look-up without interpolation
CC_Type 6: Value range to value tabular look-up
Numeric to Text Conversions
CC_Type 7: Value to text/scale conversion tabular look-up
CC_Type 8: Value range to text/scale conversion tabular look-up
Text to Numeric Conversion
CC_Type 9: Text to value tabular look-up
Text to Text Conversion
CC_Type 10: Text to text tabular look-up
Other Conversion
CC_Type 11: Bitfield text table
Vehicle Network Toolbox™ provides the functionality to read your desired data from the MDF-file with different Conversion
options. The allowed options are:
Numeric
— Apply only numeric to numeric conversions (CC_Type 1-6). Data with other conversion rules are read as raw values.None
— Do not apply any conversion. All data are read as raw values.All
— Apply all numeric and text conversions (CC_Type 1-10). All data are read as physical values.
Note that if there is an identity conversion (CC_Type 0), or a none conversion (no conversion rule) in the channel, the data are read as raw values regardless of which Conversion
option is specified.
Open the MDF-File
Open access to an MDF-file using the mdf
function. The object mdfObj
has the property Conversion
with the default value Numeric
.
mdfObj = mdf("MDF_Conversion_Example.mf4")
mdfObj = MDF with properties: File Details Name: 'MDF_Conversion_Example.mf4' Path: '/tmp/Bdoc22a_1891349_156950/tp07074cff/vnt-ex96016136/MDF_Conversion_Example.mf4' Author: '' Department: '' Project: '' Subject: '' Comment: '' Version: '4.10' DataSize: 185 InitialTimestamp: 1980-01-01 05:00:00.000000000 Creator Details ProgramIdentifier: 'amdf5206' Creator: [1x1 struct] File Contents Attachment: [0x1 struct] ChannelNames: {{6x1 cell}} ChannelGroup: [1x1 struct] Options Conversion: Numeric
Use the channelList
function to view the list of channels available in mdfObj
.
channelList(mdfObj)
ans=6×18 table
ChannelName ChannelGroupNumber ChannelGroupNumSamples ChannelGroupAcquisitionName ChannelGroupComment ChannelGroupSourceInfo ChannelDisplayName ChannelUnit ChannelComment ChannelDescription ChannelExtendedNamePrefix ChannelType ChannelDataType ChannelNumBits ChannelComponentType ChannelCompositionType ChannelConversionType ChannelSourceInfo
______________________________ __________________ ______________________ ___________________________ ___________________ ______________________ __________________ ___________ ______________ __________________ _________________________ ______________ ___________________________ ______________ ____________________ ______________________ _____________________ _________________
"Ambient temperature" 1 5 Signal with conversions <undefined> 1x1 struct "" °F <undefined> "" <undefined> FixedLength RealLittleEndian 64 None None None 1x1 struct
"Engine temperature" 1 5 Signal with conversions <undefined> 1x1 struct "" °C <undefined> "" <undefined> FixedLength IntegerSignedLittleEndian 32 None None Linear 1x1 struct
"Fault code" 1 5 Signal with conversions <undefined> 1x1 struct "" <undefined> <undefined> "" <undefined> VariableLength StringUTF8 64 None None TextToText 1x1 struct
"Gear position" 1 5 Signal with conversions <undefined> 1x1 struct "" <undefined> <undefined> "" <undefined> FixedLength IntegerUnsignedLittleEndian 8 None None ValueToText 1x1 struct
"time" 1 5 Signal with conversions <undefined> 1x1 struct "" s <undefined> "" Signal with conversions Master RealLittleEndian 64 None None None 1x1 struct
"Windshield wiper speed level" 1 5 Signal with conversions <undefined> 1x1 struct "" <undefined> <undefined> "" <undefined> VariableLength StringUTF8 64 None None TextToValue 1x1 struct
Conversion
Property and Conversion
Name-Value Pair
You can choose a Conversion
option to apply when reading data from an MDF-file in MATLAB. You specify the option in either of the following ways:
Set the
Conversion
property of the MDF object and call theread
function.Specify a
Conversion
name-value pair when calling theread
function.
View the details about the channel Engine temperature
in channel group 1. The output shows that it has Linear
conversion (CC_Type 1).
mdfObj.ChannelGroup(1).Channel(2)
ans = struct with fields:
Name: 'Engine temperature'
DisplayName: ''
ExtendedNamePrefix: ''
Description: ''
Comment: ''
Unit: '°C'
Type: FixedLength
DataType: IntegerSignedLittleEndian
NumBits: 32
ComponentType: None
CompositionType: None
ConversionType: Linear
SourceInfo: [1x1 struct]
You can set the Conversion
property of the mdfObj
to be Numeric
and read data from channel Engine temperature
in channel group 1.
mdfObj.Conversion = "Numeric"
mdfObj = MDF with properties: File Details Name: 'MDF_Conversion_Example.mf4' Path: '/tmp/Bdoc22a_1891349_156950/tp07074cff/vnt-ex96016136/MDF_Conversion_Example.mf4' Author: '' Department: '' Project: '' Subject: '' Comment: '' Version: '4.10' DataSize: 185 InitialTimestamp: 1980-01-01 05:00:00.000000000 Creator Details ProgramIdentifier: 'amdf5206' Creator: [1x1 struct] File Contents Attachment: [0x1 struct] ChannelNames: {{6x1 cell}} ChannelGroup: [1x1 struct] Options Conversion: Numeric
dataPropNum = read(mdfObj, 1, "Engine temperature")
dataPropNum=5×1 timetable
Time EngineTemperature
________ _________________
0 sec 35
0.25 sec 35.556
0.5 sec 36.111
0.75 sec 36.667
1 sec 37.222
You can also read data with the name-value pair Conversion,
None
. Note that the Conversion
name-value pair has a higher priority than the Conversion
property, which means the name-value pair is applied when the values are different.
dataNameValueNone = read(mdfObj, 1, "Engine temperature", "Conversion", "None")
dataNameValueNone=5×1 timetable
Time EngineTemperature
________ _________________
0 sec 95
0.25 sec 96
0.5 sec 97
0.75 sec 98
1 sec 99
Using the Conversion
name-value pair does not change the Conversion
property of mdfObj
. The Conversion
property value of mdfObj
after reading data with a name-value pair is still Numeric
.
mdfObj.Conversion
ans = Conversion enumeration Numeric
Read Data with Different Conversion
Options on Numeric to Numeric Conversions
The following code shows how to read your desired data from a channel with a numeric to numeric conversion. The channel Engine temperature
has Linear
conversion (CC_Type 1) and it is chosen to represent the reading behavior of numeric to numeric conversions (CC_Type 1-6).
Read data with the name-value pair Conversion
, Numeric
. In this case, Linear
conversion is applied when reading data because the Numeric
option supports numeric to numeric conversions. The physical data are returned and the physical numeric data have data type double
.
dataLinearNum = read(mdfObj, 1, "Engine temperature", "Conversion", "Numeric")
dataLinearNum=5×1 timetable
Time EngineTemperature
________ _________________
0 sec 35
0.25 sec 35.556
0.5 sec 36.111
0.75 sec 36.667
1 sec 37.222
class(dataLinearNum.EngineTemperature)
ans = 'double'
Read data with the name-value pair Conversion
, None
. In this case, Linear
conversion is not applied when reading data because the None
option does not apply any conversion. Raw data are returned with the original data type, which is an int32
.
dataLinearNone = read(mdfObj, 1, "Engine temperature", "Conversion", "None")
dataLinearNone=5×1 timetable
Time EngineTemperature
________ _________________
0 sec 95
0.25 sec 96
0.5 sec 97
0.75 sec 98
1 sec 99
class(dataLinearNone.EngineTemperature)
ans = 'int32'
Read data with the name-value pair Conversion
, All
. In this case, Linear
conversion is applied when reading data because the All
option supports all numeric and text conversions. The physical data are returned and the physical numeric data have data type double
.
dataLinearAll = read(mdfObj, 1, "Engine temperature", "Conversion", "All")
dataLinearAll=5×1 timetable
Time EngineTemperature
________ _________________
0 sec 35
0.25 sec 35.556
0.5 sec 36.111
0.75 sec 36.667
1 sec 37.222
class(dataLinearAll.EngineTemperature)
ans = 'double'
Read Data with Different Conversion
Options on Numeric to Text Conversions
The following code shows how to read your desired data from a channel with a numeric to text conversion. The channel Gear position
has ValueToText
conversion (CC_Type 7) and it is chosen to represent the reading behavior of numeric to text conversions (CC_Type 7-8).
View the details about the channel Gear position
in channel group 1. The output shows that it has ValueToText
conversion.
mdfObj.ChannelGroup(1).Channel(3)
ans = struct with fields:
Name: 'Gear position'
DisplayName: ''
ExtendedNamePrefix: ''
Description: ''
Comment: ''
Unit: ''
Type: FixedLength
DataType: IntegerUnsignedLittleEndian
NumBits: 8
ComponentType: None
CompositionType: None
ConversionType: ValueToText
SourceInfo: [1x1 struct]
Read data with the name-value pair Conversion
, Numeric
. In this case, ValueToText
conversion is not applied when reading data because the Numeric
option supports only numeric to numeric conversions. The raw data are returned with the original data type, which is an int8
.
dataV2TNum = read(mdfObj, 1, "Gear position", "Conversion", "Numeric")
dataV2TNum=5×1 timetable
Time GearPosition
________ ____________
0 sec 2
0.25 sec 3
0.5 sec 0
0.75 sec 2
1 sec 1
class(dataV2TNum.GearPosition)
ans = 'uint8'
Read data with the name-value pair Conversion
, None
. In this case, ValueToText
conversion is not applied when reading data because the None
option does not apply any conversion. Raw data are returned with the original data type, which is an int8
.
dataV2TNone = read(mdfObj, 1, "Gear position", "Conversion", "None")
dataV2TNone=5×1 timetable
Time GearPosition
________ ____________
0 sec 2
0.25 sec 3
0.5 sec 0
0.75 sec 2
1 sec 1
class(dataV2TNone.GearPosition)
ans = 'uint8'
Read data with the name-value pair Conversion
, All
. In this case, ValueToText
conversion is applied when reading data because the All
option supports all numeric and text conversions. The physical data are returned and the physical text data have data type char
.
dataV2TAll = read(mdfObj, 1, "Gear position", "Conversion", "All")
dataV2TAll=5×1 timetable
Time GearPosition
________ ___________________
0 sec {'Gear position 2'}
0.25 sec {'Gear position 3'}
0.5 sec {'Invalid' }
0.75 sec {'Gear position 2'}
1 sec {'Gear position 1'}
class(dataV2TAll.GearPosition{1})
ans = 'char'
Other Conversion Examples
There are some other channels in the mdfObj
. The channels Ambient temperature
, Windshield wiper speed level
, and Fault code
have conversions None
, TextToValue
, and TextToText
, respectively. You can try to read these channels with different Conversion
options.
View the details about the channel Ambient temperature
in channel group 1. The output shows that it has None
conversion.
mdfObj.ChannelGroup(1).Channel(1)
ans = struct with fields:
Name: 'Ambient temperature'
DisplayName: ''
ExtendedNamePrefix: ''
Description: ''
Comment: ''
Unit: '°F'
Type: FixedLength
DataType: RealLittleEndian
NumBits: 64
ComponentType: None
CompositionType: None
ConversionType: None
SourceInfo: [1x1 struct]
View the details about the channel Windshield wiper speed level
in channel group 1. The output shows that it has TextToValue
conversion.
mdfObj.ChannelGroup(1).Channel(4)
ans = struct with fields:
Name: 'Windshield wiper speed level'
DisplayName: ''
ExtendedNamePrefix: ''
Description: ''
Comment: ''
Unit: ''
Type: VariableLength
DataType: StringUTF8
NumBits: 64
ComponentType: None
CompositionType: None
ConversionType: TextToValue
SourceInfo: [1x1 struct]
View the details about the channel Fault code
in channel group 1. The output shows that it has TextToText
conversion.
mdfObj.ChannelGroup(1).Channel(5)
ans = struct with fields:
Name: 'Fault code'
DisplayName: ''
ExtendedNamePrefix: ''
Description: ''
Comment: ''
Unit: ''
Type: VariableLength
DataType: StringUTF8
NumBits: 64
ComponentType: None
CompositionType: None
ConversionType: TextToText
SourceInfo: [1x1 struct]
Close the File
Close access to the MDF-file by clearing the variable from the workspace.
clear mdfObj