How do I import and read a large binary file?

12 ビュー (過去 30 日間)
arakis arakis
arakis arakis 2019 年 1 月 13 日
編集済み: Guillaume Baptist 2022 年 9 月 28 日
I have a 1.5GB binary file that was created via recording in GNURadio with an SDR. GNURadio documentation says this is a "pure" binary file and consists of 32 bits for the real part followed by 32 for the imaginary (complex float). My intent is to use fread if I can get the file opened.
Upon trying to open the file using uiimport MATLAB hangs with "opening a large text file" message and eventually errors with "out of memory". Machine has 16GB of RAM and there are no other significant processes running.
I only need a second or two of this data (if that) it's a BPSK signal and I'd like to be able to visualize the modulation.
I'm very new to MATLAB, using R2018. Thanks for any help!
  1 件のコメント
Rik
Rik 2019 年 1 月 13 日
If you only need a small portion, it might be better to avoid 'smarter' tools like uiimport, and use fopen and fscanf to read your data.

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2019 年 1 月 14 日
filename = 'MySDRFile.bin'; %as appropriate
seconds_to_read = 1;
%{
Fs = 997990000*2; %sampling frequency... needed to know how much "one second" is.
%99.8 MHz is the middle of the FM band
%}
Fs = 1E6*2; %1 megabit/s data rate for basic DPSK ?
samples_to_read = floor(seconds_to_read * Fs);
filename = 'MySDRFile.bin'; %as appropriate
[fid, msg] = fopen(filename, 'r');
if fid < 0
error('Failed to open file "%s" because "%s"', filename, msg);
end
%data is interleaved real then complex. When we fread into two rows
%then the top row becomes the reals and the bottom row becomes the imag
data = fread(fid, [2 samples_to_read], '*float32');
fclose(fid);
%reformulate as complex
data = complex(data(1, :), data(2,:));
  2 件のコメント
arakis arakis
arakis arakis 2019 年 1 月 15 日
Extremely helpful thank you.
Guillaume Baptist
Guillaume Baptist 2022 年 9 月 28 日
編集済み: Guillaume Baptist 2022 年 9 月 28 日
Yes, it also works well for me. Thanks. For those who don't need the imaginary part and want to plot only the real part, I simply did :
plot(real(data));

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeBPSK についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by