Analyzing Saleae Logic Analyse Data in MATLAB

19 views (last 30 days)
Hello!! Everyone I am using Saleae Logic Analyzer to capture signals from the PS2 Keypad, and it works perfectly. But i want to save these signals for future analysis, so i saw export option in which we can export data in MATLAB. Channel-0 is connected to Clock and Channel-1 is connected to Data Pin of PS2 Keyboard. Sampling Frequency is 1MS/s and Sampling Time is used is 1second, on Logic Analyzer. Then i export the data to Matlab *.mat File. Can anyone help me, in plotting the signal in MATLAB as done by logic analyzer software. I am sharing my *.mat file When i load this file in MATLAB using load command. I saw the following variables in my work-space.
digital_sample_rate_hz this means the sampling rate i set which is 1MS/s Rest i am not getting, please help me in understanding this and how can i plot the same in MATLAB. Thanks in Advance.

Accepted Answer

Gergely Takács
Gergely Takács on 27 Nov 2016
The data format exported by Saleae Logic is quite interesting. To plot a signal, you need two variables from the export: ``digital_channel_initial_bitstates'' and ``digital_channel_X'' where X is the channel you need and we start from 0.
The idea to plot a single channel is, that first you must know the initial state of the signal, this is saved in ``digital_channel_initial_bitstates''. The first element belongs to the first channel, etc. If the bit is zero, your signal starts with a zero; if its one, then the signal starts with a one.
Now, the ``digital_channel_0'' does not contain your signal in a format you are usually working in Matlab, instead these are state encoded. Say, the format contains the numbers 23,32,27,100... This would mean, that the signal was the initial state for 23 samples, then flipped to the other state for 32 samples, than flipped again for 27 samples and so on. That is exactly you want to do: create a vector of 23 ones and multiply it by the initial state. Flip the state. Augment it by 32 samples and multiply it by the fliped state again... And so on and so on.
So, to plot the singal (vs. sample index) you can use the following piece of code:
load untitled.mat % Saleae Logic export
j=1; % Channel index (1 belongs to ch0)
ch=digital_channel_0; % Channel to extract (0 is the first)
for i=1:1:length(ch);
CH=[CH; digital_channel_initial_bitstates(j)*ones(ch(i),1)];
If you want to plot the data against time, you need to determine the sampling period from the sampling frequency, then you can create a time vector according to the length of the samples. So to plot your capture vs. time, you can use:
If you want to overlay the output of the Analyzer that is also exportable to CSV format, well... that's not so easy to do. The main problem is, that the export format from the Saleae Logic is not the best, the guys at Saleae could improve it. The way it is exported is, that it contains time markers, which I guess belong to the beginning of frames (like the start bit in serial) and it has a bit of text assigned to it. But the issue is, that the beginning of the timer (0) is not in a clear relashionship with the capture data frames (you don't know where it begins), frame ends are not exported etc... It is usable in some cases, but convoluted.

More Answers (0)


Community Treasure Hunt

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

Start Hunting!