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

조회 수: 34 (최근 30일)
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 CenterFile Exchange에서 Vehicle Network Toolbox에 대해 자세히 알아보기

태그

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by