How to plot .bin file?
Show older comments
I make some binary file .bin files by connectiong an active GPS antenna to USRP 2900, now can any one help me how to plot those files using MATLAB to check that satellites are acquired or not on a given gain?
12 Comments
dpb
on 16 May 2023
Need to know how the files are structured to have any klew how to read them -- what's the word length/numeric format/endianness/????
Rizwan
on 16 May 2023
Walter Roberson
on 16 May 2023
The USRP 2900 has a 12 bit analog to digital convertor.
There are three common methods of returning data in such cases:
- packed binary, 3 bytes holds the information for two samples; these numbers may need to be scaled to appropriate units;
- unpacked binary, usually with the 12 bits as the first 12 bits of a 16 bit integer, with the bottom filled in with 0; these numbers may need to be scaled to appropriate units;
- single precision numbers, having already been scaled to appropriate units
There is also the possibility of 12 bits as the bottom 12 bits of a 16 bit integer, but that is less common.
You need to know how the data was read, and whether it needs to be unpacked, and whether it needs to be scaled.
Rizwan
on 17 May 2023
dpb
on 17 May 2023
That's all up to what/how LabView writes the data, then; not MATLAB. That's in the doc's for it, not a MATLAB question, per se.
fread() will read bytes and interpret them how it is told to do so; what the bytes are and how they are to be interpreted is up to the application that wrote them; you'll have to ferret that out of the LabView doc's.
I used it some 30+ years ago, but that's ancient history, now...
Walter Roberson
on 17 May 2023
I would suggest replacing that for loop with a call to stem
Rizwan
on 18 May 2023
dpb
on 18 May 2023
>> x=randn(10000,1);tic;stem(x);toc
Elapsed time is 1.003551 seconds.
>> tic;stem(x);toc
Elapsed time is 0.040224 seconds.
>> tic;stem(x);toc
Elapsed time is 0.028222 seconds.
>> tic;stem(x);toc
Elapsed time is 0.023083 seconds.
>> tic;stem(x);toc
Elapsed time is 0.072088 seconds.
>> tic;stem(x);toc
Elapsed time is 0.014547 seconds.
Would have to see the code; sounds like you still left it in the loop???
stem is decent performer although as shows, there's a cache miss the first time to load the function itself...
Walter Roberson
on 18 May 2023
Replace
for i = 1:numel(locs)
line([locs(i) locs(i)], [0 peaks(i)], 'Color', 'r', 'LineWidth', 2);
end
with
stem(locs, 'r', 'LineWidth', 2);
with no loop.
dpb
on 18 May 2023
stem(locs, 'r', 'LineWidth', 2);
should be
stem(locs,peaks, 'r', 'LineWidth', 2);
Walter Roberson
on 18 May 2023
@dpb is right, the peaks are needed as well.
Answers (1)
Diwakar Diwakar
on 22 May 2023
I can help you with plotting the data from your .bin files using MATLAB. To get started, you'll need to read the binary file and extract the relevant data. Since you haven't provided the specific format of your .bin files, I'll assume that the data is stored as a series of numerical values representing satellite acquisition information.
Here's an example MATLAB code that demonstrates how you can read the binary file, extract the data, and plot it:
% Specify the path to your .bin file
file_path = 'path/to/your/file.bin';
% Open the binary file for reading
file_id = fopen(file_path, 'rb');
% Read the binary data into a numerical array
data = fread(file_id, 'double');
% Close the file
fclose(file_id);
% Specify the gain threshold for satellite acquisition
gain_threshold = 10; % Adjust this value as needed
% Plot the data
figure;
plot(data, 'b');
hold on;
plot(find(data >= gain_threshold), data(data >= gain_threshold), 'ro');
hold off;
% Set plot labels and title
xlabel('Sample Index');
ylabel('Gain');
title('Satellite Acquisition');
% Display a legend
legend('Gain', 'Acquired Satellites');
% Adjust plot settings if needed
grid on;
Make sure to replace 'path/to/your/file.bin' with the actual file path of your .bin file. Also, adjust the gain_threshold value according to the gain level at which you consider a satellite to be acquired.
This code reads the binary file using fread, stores the data in the data array, and then plots the entire data as a blue line. It also marks the points where the gain exceeds the specified threshold with red circles.
Feel free to customize the code further based on your specific requirements or the structure of your binary file.
Categories
Find more on Communications Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!