有没有人研究过力科示波器的二进制文件(.trc)怎么读取?
mathematica吧
全部回复
仅看楼主
吧务
level 15
xzcyr 楼主
如题……这个.trc文件好像是依照LECROY_2_3模板排列的,读取的时候需要专门的解析。在网上找了找,python版(github.com/yetifrisstlama/readTrc)和MATLAB版(ww2.mathworks.cn/matlabcentral/fileexchange/2114-readlecroybinarywaveform-m)的都有人写过,不知有没有人写过Mathematica版?
2018年06月02日 08点06分 1
吧务
level 15
xzcyr 楼主
自个儿搞清楚了……不算很难,就是略繁。重点是参照
forums.ni.com/attachments/ni/60/4652/2/LeCroyWaveformTemplate_2_3.pdf
中的格式说明。以下给出代码(其实可以进一步整理成函数的,我懒得弄了……):
str = OpenRead[(*文件地址*), BinaryFormat -> True];
byte = "Integer8";
word = "Integer16";
long = "Integer32";
string = "TerminatedString";
float = "Real32";
double = "Real64";
SetStreamPosition[str, 0];
lengthofwavedesc = 8;
headlength = StringLength@BinaryRead[str, string] - lengthofwavedesc;
l@wavedesc = read[36, long];
l@usertext = read[40, long];
l@trigtimearray = read[48, long];
l@ristimearray = read[52, long];
l@wavearray = read[116, long];
read[pos_, type_] := (SetStreamPosition[str, headlength + pos]; BinaryRead[str, type])
readlist[pos_, type_, length_] := (SetStreamPosition[str, headlength + pos];
BinaryReadList[str, type, length])
raw = readlist[l@wavedesc + l@usertext + l@trigtimearray + l@ristimearray, byte,
l@dataarray@1];
{vertical@gain, vertical@offset} = readlist[156, float, 2];
data = vertical@gain * raw - vertical@offset;
horizon@interval = read[176, float];
horizon@offset = read[180, double];
rightboundary = horizon@interval (l@wavearray - 1) + horizon@offset;
Close@str;
ListLinePlot[data[[;; ;; 10]], DataRange -> {horizon@offset, rightboundary}]
顺便,那个MATLAB的.m文件其实是bug,它在算文件位置的时候丢了一项。(当然这项一般是空的所以通常不会引发问题。)
2018年06月02日 13点06分 2
后来想了想还是做了进一步的整理。参看5楼的链接。
2018年07月07日 07点07分
吧务
level 15
xzcyr 楼主
2018年06月02日 13点06分 5
1