Read Physical and Raw Data from MDF Files
This example shows you how to read channel data from an MDF file as physical values and raw values.
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 value with an engineering unit using a conversion rule. 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
Value to Value 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
Value 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 Value Conversions
CC_Type 9: Text to value tabular look-up
Text to Text Conversions
CC_Type 10: Text to text tabular look-up
Other Conversion
CC_Type 11: Bitfield text table
The mdfRead function by default reads physical values from an MDF file, but it also provides the capability to read raw values via the ReadRaw option.
ReadRawisfalse(default) — Apply all numeric and text conversions (CC_Type 1-10). All data are read as physical values.ReadRawistrue— Do not apply any conversion. All data are read as raw 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 the ReadRaw option specified.
View Channel Details
Use the mdfChannelInfo function to view details about all the channels in MDF_Conversion_Example.mf4. Specify the AdditionalMetadata option as true to include the additional metadata, which contains information about the raw data type in DataType and NumBits, as well as conversion rule in ConversionType.
chanInfo = mdfChannelInfo("MDF_Conversion_Example.mf4", AdditionalMetadata=true)chanInfo=6×25 table
Name GroupNumber GroupNumSamples GroupAcquisitionName GroupComment GroupSourceName GroupSourcePath DisplayName Unit Comment ExtendedNamePrefix SourceName SourcePath Type SyncType DataType NumBits ComponentType CompositionType ConversionType SourceComment SourceType SourceBusType SourceBusChannelNumber SourceSimulated
______________________________ ___________ _______________ _______________________ ____________ _______________________ _______________________ ___________ ___________ ___________ _______________________ _______________________ _______________________ ______________ ________ ___________________________ _______ _____________ _______________ ______________ _____________ ___________ _____________ ______________________ _______________
"Ambient temperature" 1 5 Signal with conversions <undefined> Signal with conversions Signal with conversions "" °F <undefined> <undefined> <undefined> <undefined> FixedLength None RealLittleEndian 64 None None Unspecified "" Unspecified Unspecified 0 false
"Engine temperature" 1 5 Signal with conversions <undefined> Signal with conversions Signal with conversions "" °C <undefined> <undefined> <undefined> <undefined> FixedLength None IntegerSignedLittleEndian 32 None None Linear "" Unspecified Unspecified 0 false
"Fault code" 1 5 Signal with conversions <undefined> Signal with conversions Signal with conversions "" <undefined> <undefined> <undefined> <undefined> <undefined> VariableLength None StringUTF8 64 None None TextToText "" Unspecified Unspecified 0 false
"Gear position" 1 5 Signal with conversions <undefined> Signal with conversions Signal with conversions "" <undefined> <undefined> <undefined> <undefined> <undefined> FixedLength None IntegerUnsignedLittleEndian 8 None None ValueToText "" Unspecified Unspecified 0 false
"Windshield wiper speed level" 1 5 Signal with conversions <undefined> Signal with conversions Signal with conversions "" <undefined> <undefined> <undefined> <undefined> <undefined> VariableLength None StringUTF8 64 None None TextToValue "" Unspecified Unspecified 0 false
"time" 1 5 Signal with conversions <undefined> Signal with conversions Signal with conversions "" s <undefined> Signal with conversions Signal with conversions Signal with conversions Master Time RealLittleEndian 64 None None Unspecified "" Tool None 0 false
Display only a few relevant variables in the returned table, including Name, GroupNumber, GroupNumSamples, Unit, DataType, NumBits, and ConversionType.
chanInfo(:, ["Name", "GroupNumber", "GroupNumSamples", "Unit", "DataType", "NumBits", "ConversionType"])
ans=6×7 table
Name GroupNumber GroupNumSamples Unit DataType NumBits ConversionType
______________________________ ___________ _______________ ___________ ___________________________ _______ ______________
"Ambient temperature" 1 5 °F RealLittleEndian 64 Unspecified
"Engine temperature" 1 5 °C IntegerSignedLittleEndian 32 Linear
"Fault code" 1 5 <undefined> StringUTF8 64 TextToText
"Gear position" 1 5 <undefined> IntegerUnsignedLittleEndian 8 ValueToText
"Windshield wiper speed level" 1 5 <undefined> StringUTF8 64 TextToValue
"time" 1 5 s RealLittleEndian 64 Unspecified
Read Data from a Channel with Value to Value Conversion
The channel named "Engine temperature" contains Linear conversion (CC_Type 1).
chanInfo.ConversionType(chanInfo.Name == "Engine temperature")ans =
ChannelConversionType enumeration
Linear
Read data from "Engine temperature". By default, physical values of data type double are returned.
engTempPhy = mdfRead("MDF_Conversion_Example.mf4", Channel="Engine temperature"); engTempPhy{1}
ans=5×1 timetable
time Engine temperature
________ __________________
0 sec 35
0.25 sec 35.556
0.5 sec 36.111
0.75 sec 36.667
1 sec 37.222
class(engTempPhy{1}.("Engine temperature"))ans = 'double'
Set option ReadRaw set to true to read data from "Engine temperature" as raw values of data type int32. The raw data type is defined in DataType as IntegerSignedLittleEndian (2) and NumBits as 32.
engTempRaw = mdfRead("MDF_Conversion_Example.mf4", Channel="Engine temperature", ReadRaw=true); engTempRaw{1}
ans=5×1 timetable
time Engine temperature
________ __________________
0 sec 95
0.25 sec 96
0.5 sec 97
0.75 sec 98
1 sec 99
class(engTempRaw{1}.("Engine temperature"))ans = 'int32'
Read Data from a Channel with Value to Text Conversion
The channel named "Gear position" contains ValueToText conversion (CC_Type 7).
chanInfo.ConversionType(chanInfo.Name == "Gear position")ans =
ChannelConversionType enumeration
ValueToText
Read data from "Gear position". By default, physical values of data type string are returned.
gearPosPhy = mdfRead("MDF_Conversion_Example.mf4", Channel="Gear position"); gearPosPhy{1}
ans=5×1 timetable
time Gear position
________ _________________
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(gearPosPhy{1}.("Gear position"))ans = 'string'
Set option ReadRaw set to true to read data from "Gear position" as raw values of data type uint8. The raw data type is defined in DataType as IntegerUnsignedLittleEndian (0) and NumBits as 8.
gearPosRaw = mdfRead("MDF_Conversion_Example.mf4", Channel="Gear position", ReadRaw=true); gearPosRaw{1}
ans=5×1 timetable
time Gear position
________ _____________
0 sec 2
0.25 sec 3
0.5 sec 0
0.75 sec 2
1 sec 1
class(gearPosRaw{1}.("Gear position"))ans = 'uint8'
Read Data from a Channel with No Conversion
The channel named "Ambient temperature" contains no conversion.
chanInfo.ConversionType(chanInfo.Name == "Ambient temperature")ans =
ChannelConversionType enumeration
Unspecified
Read data from "Ambient temperature" both as physical values and raw values. Because the channel has no conversion, the returned physical values are identical to the returned raw values.
Note that the physical values have the same data type, double, as the raw values. The raw data type is defined in DataType as RealLittleEndian (4) and NumBits as 64.
ambTempPhy = mdfRead("MDF_Conversion_Example.mf4", Channel="Ambient temperature"); ambTempPhy{1}
ans=5×1 timetable
time Ambient temperature
________ ___________________
0 sec 81.7
0.25 sec 81.9
0.5 sec 82
0.75 sec 81.8
1 sec 81.9
class(ambTempPhy{1}.("Ambient temperature"))ans = 'double'
ambTempRaw = mdfRead("MDF_Conversion_Example.mf4", Channel="Ambient temperature", ReadRaw=true); ambTempRaw{1}
ans=5×1 timetable
time Ambient temperature
________ ___________________
0 sec 81.7
0.25 sec 81.9
0.5 sec 82
0.75 sec 81.8
1 sec 81.9
class(ambTempRaw{1}.("Ambient temperature"))ans = 'double'
Other Conversion Examples
Two other channels are present in the MDF file.
The channel named "Windshield wiper speed level" contains TextToValue conversion (CC_Type 9).
chanInfo.ConversionType(chanInfo.Name == "Windshield wiper speed level")ans =
ChannelConversionType enumeration
TextToValue
The channel named "Fault code" contains TextToText conversion (CC_Type 10).
chanInfo.ConversionType(chanInfo.Name == "Fault code")ans =
ChannelConversionType enumeration
TextToText
You can try reading data from these channels with different ReadRaw options.