フィルターのクリア

How to make a plot from one signal out of a CAN trace (blfread)?

38 ビュー (過去 30 日間)
Bernhard Müller
Bernhard Müller 2019 年 7 月 29 日
編集済み: Thomas Kotwal 2020 年 8 月 7 日
I have a CAN trace with several messages and singals in it. I read in the trace with blfread and sellect the a specific channel and message. The message includes several signals. These signals are in a structure.
I need a plot of one of these signals.
e.g. The speed signal is one of the signals in the message "MFG". The MFG message is on the CAN channel 1. I want to read in the BLF and crate a plot of the speed signal over time.
How can I access the speed signal?
Thanks!

採用された回答

Bernhard Müller
Bernhard Müller 2019 年 8 月 20 日
Hello!
I have prepared a sample which I can share. I the attached ZIP-file you will find a DBC-database, a BLF-trace and two scripts.
The first script (test.m) does not work.
candb = canDatabase('TestDBC.dbc');
Data = blfread('Test_002.blf',1, "Database", candb);
plot(Data.Time);
plot(Data.Signals.Speed);
The last command is like suggested, but will be denied.
The second script (test2.m) is my workaround.
candb = canDatabase('TestDBC.dbc');
Data = blfread('Test_002.blf',1, "Database", candb, "CANStandardFilter", 291);
for i=1:size(Data,1)
stest(i)=Data.Signals{i,1}.Speed;
end
test=timetable(Data.Time,stest.');
plot(test.Time,test.Var1);
This script works, but is there no shorter way to get the same result?
Thanks
  2 件のコメント
Mahesh Taparia
Mahesh Taparia 2019 年 8 月 23 日
編集済み: Mahesh Taparia 2019 年 8 月 23 日
Hi,
The 1st script is not working because the signal is in the form of structure. You can use the below code to reduce 1 line.
candb = canDatabase('TestDBC.dbc');
Data = blfread('Test_002.blf',1, "Database", candb, "CANStandardFilter", 291);
for i=1:size(Data,1)
stest(i)=Data.Signals{i,1}.Speed;
end
plot(Data.Time,stest)
Thomas Kotwal
Thomas Kotwal 2020 年 8 月 7 日
編集済み: Thomas Kotwal 2020 年 8 月 7 日
Bernhard, did you ever find a better way to do what you showed in your example?
Previously, I had used Vector tools to convert a .blf file to a .mat file which contains a N x 2 matrix for each signal defined in my .dbc files, where one column of the matrix is time and the other is data. Then I used Matlab to load the .mat and plot the signals. That works fine, but it would be nicer if I didn't have to convert from .blf to .mat.
Your example works, but if I had to do that for every signal it would be cumbersome and I'd be better off just sticking with my previous method.
Thank you.

サインインしてコメントする。

その他の回答 (3 件)

Mahesh Taparia
Mahesh Taparia 2019 年 8 月 2 日
Hi,
Function ‘blfread’ returns the timetable which contains the message data from the specified channel. Timetable contains the data in the form of a structure, which we can plot using plot function.
You can read the required channel using:
File= blfread(filename, channel Number);
plot(File.time,File.data)
For better understanding of the function, you can go through the documentation here.

Bernhard Müller
Bernhard Müller 2019 年 8 月 7 日
Hi!
I think the VariableNames start with capital letters. So the plot command looks like "plot(File.Time,File.Data)". The variables time and data do not exist.
But also with capital letters this command will not work. The Data contains 1x8 arrays. Therfore it is not possible to plot the data this way.
I use the dbc-file to get the Signals. Then the variable 'Signals' contains a structure of values. I need to plot the one of this signals.
I need something like this
"plot(File.Time,File.Signals.Speed)"
but this do not work. How can I do this?
Thanks!
  1 件のコメント
Mahesh Taparia
Mahesh Taparia 2019 年 8 月 8 日
Hi
Capital/small letters depends on the name of the subfield the structure have.
Try this if there is no time signal.
plot(File.Signals.Speed)
In general it will be
plot(File.Signals.variable1,File.Signals.variable2)

サインインしてコメントする。


Bernhard Müller
Bernhard Müller 2019 年 8 月 8 日
Hi!
I think there is somewhere a misunderstanding.
I am able to adress one value of one message. But I want a plot of one signal over the whole trace.
I get the error message "Dot indexing is not supported for variables of this type."
My workaround is to build a new array with the signal. But my question is, is it possible to address one signal directly.
Thanks!
  1 件のコメント
Mahesh Taparia
Mahesh Taparia 2019 年 8 月 8 日
Hi,
Can you share your file/ file and code which contains the data?
Or else, try to takeout the samples from the structure/ sub-structure as per your file format and plot it.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeVehicle Network Toolbox についてさらに検索

タグ

製品


リリース

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by