Continue to Site

Welcome to

Welcome to our site! is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

how to plot binary files?

Not open for further replies.


Advanced Member level 3
Oct 24, 2005
Reaction score
Trophy points
Florida, USA
Activity points

I have designed an analog-to-digital converter (data acquisition) card. It samples data and I can save it into a binary file (32kS) where every byte (8-bit) represents a sample. There is nothing else in the file but samples, no header, no coordinates, no sample numbering, no x-axis markings. I need to be able to make a 2D plot where the x axis is the sample number (or byte position) and the y axis is the sample value. Not much to ask, I think.

How do i plot this using scilab (matlab) or gnuplot or any other free program? Or maybe with excel?

I spent hours in trying to make these programs to display my data without much success. Scilab doesnt like by binary files, gnuplot wants to think that the coordinate information is also embedded into the file.

what exact commands do i need to type in?

Check WAV format.
I may be wrong but think that format only records ackquired analog value.
Sample rate is implicit and constant.
There are a lot tools ( JAVA / C++ ) that show audio files.

Another option is append a coordinate to each line ( incremental ascending numeric value ) in order to use at GNUPLOT or other kind of program.


so, you suggest to manually create file format specific headers and write programs to display data?
i dont want to do a development project just for this.
Appending coordinates and converting the binary to hex or decimal would also be difficoult on a 32768-entry data file.
with existing programs like gnuplot or scilab it should be possible in a few seconds if someone knows the right commands to use.


I already used an proprietary WAV format; not really the Windows WAV format.

What is separator for each sample ?
Could you attach some example of your file in order to try simulate here ?


In scilab you can open a binary file using the function "mopen" and specifying the mode as 'rb' that means read binary.

f.i.: [fd,error] = mopen(filename,'rb')

then you can access the data using the function "mfscanf"

the file open seems to work:
file1 =

but how do i get a vector of 8-BIT values out of it?
mfscanf doesnt return anthing, just an empty matrix, so i have tried mgeti but it complains about the format string. how do i specify 8-bit data in the format string? the help doesnt mention 8-bit.
!--error 9991
Incorrect integer type: %uc

it should display my a-vector, then i would be able to plot(a).

Could you, please, post your file or part of it ?

here is a file.
it has a rubbish waveform, i have to fix something in my circuit, but the file format will remain the same.


    5.2 KB · Views: 139

I think you can try this code:

  • Like
Reactions: buenos


    Points: 2
    Helpful Answer Positive Rating
in case of the new attached file, it doesnt display what is in the file, it displays something else.
i have edited it with XVI32 hex editor. basically there has to be 56 samples then zeroes until the end of file then the last 3 bytes are 55-aa-ff. Instead of this, it displays 72 samples only, and the samples from 56-72 should be zero they dont seem to be.


    275 bytes · Views: 135


    Points: 2
    Helpful Answer Positive Rating
you mean that they are not zero. OK, but thats not the problem.
1. at the beginning of the file it shows 76 samples instead of 56. 20extra, which 20 is the extra?
2. it should display 32768 samples, regardless of the values of the samples.

---------- Post added at 21:16 ---------- Previous post was at 21:02 ----------

ok, if i zero those left over bytes at address 0x2FC8, then it displays 49 samples.
it looks like it has one big problem:
it has skipped all the zero samples.
how to prevent it from doing that?

You are right, the problem is the ascii function. I think the procedure I suggested you is not correct. Please try the following:

while(meof(fd) == 0)
x = [x mget(1,'uc',fd)];
x = x(2:length(x));

In this case we are considering unsigned numbers. If you have to recover signed numbers use x = [x mget(1,'c',fd)];


    Points: 2
    Helpful Answer Positive Rating
thank you, it worked.
Normally I have to use matlab/scilab once every few years, its not my area.

There's no need to read byte to byte, mget stop when reach the eof().
Just put as argument the filesize or an arbitrary value many times greater.

x = mget(100000,'c',fd) ;
  • Like
Reactions: buenos


    Points: 2
    Helpful Answer Positive Rating
thanks for you too.
what i do, is to modify the suggested text (with file path/name) in notepad then copy/paste it into scilab, then it generates the plot. If it is 2 more lines, it doesnt matter for the copy/paste. maybe it takes 3 seconds instead of 1 to generate it.

Not open for further replies.

Part and Inventory Search

Welcome to