Plot .csv data from logic analyzer

13 views (last 30 days)
Jonas Meyer
Jonas Meyer on 22 Feb 2022
Answered: Sudarsanan A K on 20 Oct 2023
Hey, I got a .csv file from my logic analyzer that I would like to process. The data contains a timestamp and the digital channels. My problem is that the timestamp is not constant but only updates when a channel changes. The sample rate for the data was 200 MHz.
The data should look like this.
But I get this when I use the plot command. X is the timestamp and Y is one channel (row "6").
The data I used.
I would like to plot the data and later do a spectrum analyzes to see variation in my sqaure wave. I already did this but with data at a fixed time interval. What is the the best way to convert the timestamp to the fixed 200 MHz sample frequency in Matlab?

Answers (1)

Sudarsanan A K
Sudarsanan A K on 20 Oct 2023
Hello Jonas,
I understand that you have a .CSV file from a logic analyzer that contains timestamp information and digital channel data. The issue you're facing is that the timestamp updates only when a channel changes, resulting in an irregular time interval between samples. You want to convert this irregular timestamp data to a fixed sample frequency of 200 MHz in MATLAB.
To convert the timestamp to a fixed sample frequency in MATLAB, you can use the "interp1()" function. This function performs interpolation to resample your data at the desired sample rate. Here's how you can do it:
  • Read the .CSV file into MATLAB using the "readtable()" function. Assuming your timestamp is in the first column and the digital channels are in the subsequent columns, you can use the following code:
data = readtable('Test-online.csv', 'HeaderLines', 5);
timestamps = data{:, 1}; % Extract numeric values from the first column of the table
channels = data{:, 2:end}; % Extract numeric values from the remaining columns of the table
  • Create a new time vector with the desired sample rate using the "linspace()" function. Assuming your data starts at time "t0" and ends at time "t1", you can generate the new time vector as follows:
t0 = timestamps(1);
t1 = timestamps(end);
newSampleRate = 200e6; % 200 MHz
newTime = linspace(t0, t1, round((t1 - t0) * newSampleRate));
  • Use the "interp1()" function to resample the digital channels at the new time vector:
resampledChannels = interp1(timestamps, channels, newTime, 'nearest')
The 'nearest' option in "interp1()" performs nearest-neighbour interpolation, which is suitable for digital signals. To know more about the "interp1()" function, you can additionally refer to the MathWorks documentation in the link:
Now you have the resampled channels at a fixed 200 MHz sample rate in the "resampledChannels" variable. You can proceed to plot the data and perform spectrum analysis using MATLAB's plotting and signal processing functions.
I hope this helps!

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!