1.1 Binary Data MATLAB Function
This function will import all the channel data files (.CHN) in a DTS test folder and output the data in unfiltered EU. The EU data will be zeroed based on the zero method selected for the channel in SLICEWare or DataPRO.
When executed, the function will present the user with a ‘select folder’ dialog. The user will then choose the DTS test folder and the function will open the .DTS file in that folder and begin to collect information about proportionality, excitation values, inversion, initial EU, and zeroing method. Then the function will begin to iterate through all the .CHN files in that folder. The header information from the .CHN files includes the mV per ADC value, the mV/EU or mV/V/EU value, and the offset in ADC. This data along with the aforemented data from the .DTS file is used to scale and offset the raw ADC values that are read from the .CHN file to convert to Engineering Units. Once the iteration of all .CHN files is complete, the data is output in an array (npnts, nchan) along with the sample rate and path name.
Download the .m file at the bottom of this post.
1.2 Function Definition
[data, sampleRate, path, channelInfoMetadata, timeOfFirstSamples, ADC] = read_dts_folder;
• dataEU
- Will contain the EU data from the folder selected by the dialog in the form (number of points, number of channels)
- To access the first channel in the array the user would use:
data(:,1)
• sampleRate
- Will contain the sample rate for the test
• path
- Will contain the path of the test
• channelInfoMetadata
- Will contain SerialNumber, Description, and EU for each channel of the test
• timeOfFirstSamples
- Will contain an array of Time in seconds of the first Sample for each channel of the test
• dataADC
- Will contain ADC data
• dataMV
- Will contain MV data
1.3 Function Example 1
The following code sample will execute read_dts_folder and plot the first channel.
% read all files from DTS folder
[dataEU, sampleRate, pn, channelInfoMetadata, timeOfFirstSamples, dataADC, dataMV] = read_dts_folder();
% plot channel 2 by referencing return index 2
returnChannelToPlot = 2;
Y = dataEU(:,returnChannelToPlot);
t = linspace(timeOfFirstSamples(returnChannelToPlot),(length(Y)/sampleRate)+timeOfFirstSamples(returnChannelToPlot),length(Y));
plot(t,Y);
grid on;
1.4 Function Example 2
The following code sample will execute read_dts_folder and plot the second channel.
% request channel index 2 and 3 to be returned
channelIndexesToReturn = [2,3];
% read and return 2 files from DTS folder
[dataEU, sampleRate, pn, channelInfoMetadata, timeOfFirstSamples, dataADC, dataMV] = read_dts_folder(channelIndexesToReturn);
% plot channel 2 by referencing return index 1
returnChannelToPlot = 1;
Y = dataEU(:,returnChannelToPlot);
t = linspace(timeOfFirstSamples(returnChannelToPlot),(length(Y)/sampleRate)+timeOfFirstSamples(returnChannelToPlot),length(Y));
plot(t,Y);
grid on;
Comments
3 comments
Can you clarify how zeroing is handled and the data is imported unfiltered?
This is great! In the link below, I have adapted this function to batch convert binary dts data files to binary mat files. I have also made a few modifications to my personal preference, including the exporting of a downsampled data preview.
https://www.mathworks.com/matlabcentral/fileexchange/63802-dts-binary-data-reader
And Steve, to answer your question, I have found this function to be equivalent to exporting an UNFILTERED csv file from the data tab in sliceware.
***99% of readers can stop reading here***
With that said, I did notice two (unimportant) differences:
1. Sliceware's csv export gives me one more data point at the end of the file. I can't imagine anybody caring about this.
2. Sliceware's csv export has fewer significant digits. This is relatively insignificant and . For example, a data point from this csv file is 5.527232000000000, whereas the same data point from the binary converted mat file is 5.527231503749619. This difference is only on the order of 10^-7, so it's hard to imagine a scenario where this error is greater than the bit resolution of the hardware anyways.
Please sign in to leave a comment.