How to read data file in batch until end of file and write results in an array
2 views (last 30 days)
Show older comments
I need to read a large bin file in batches. Assuming the batch size is 5000 and will take an average over K (100 in this case) bin. At the end of process, I will have a number of averages to plot.
Have the basic code (first 5000 batch) below and now I have a couple of questions to proceed:
%%Process and Plot rf.bin
filename='rf.bin'; % filename='./rf.bin';
fid=fopen(filename,'r');
dataHeader=fread(fid,123,'uint8'); %skipping the header for .bin
NsperBatch = 0.5e4; % number of sample per batch
magSpectrum=0;
for k=1:100 % There are roughly 13243 sets
data=fread(fid,NsperBatch*2,'int16','b'); %16 bit integer big endian
dataIQ=data(1:2:end)+1i*data(2:2:end); %convert to complex IQ
dataSpectrum=fftshift(fft(dataIQ)); %convert to frequency domain
magSpectrum = magSpectrum + abs(dataSpectrum).^2;
end
magSpectrum = magSpectrum/100;
z=pow2db(magSpectrum); %convert magnitude to DB
fclose all;
1. How do I continue to read until end of file. Roughly, there are about 13243 sets/batches until end of file
2. How do I store all end results in an array (like Z=[5000, 13243]), so they can support the 3D plot later.
thanks!
0 Comments
Answers (0)
See Also
Categories
Find more on Data Type Conversion 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!