Reading int16 from a file and writing as int8 to another file
4 views (last 30 days)
Show older comments
Bugrahan Ustundag on 30 Aug 2022
Edited: Bugrahan Ustundag on 4 Sep 2022
I want to read an I/Q sampled binary file and write it to another file.
I have a binary file consisting of signals stored as complex 16- bit samples at a rate of 25 Msps.
I want to write this file to another file with 8-bit samples and I want to execute that in a loop since sizes of the files are enormous.
But when I try to write to another file, I could not adjust its starting point.
I share my code below, where do I get wrong?
duration = 20; % seconds to be read
fid=fopen('/home/read.bin','r'); % open the file
fseek(fid, point_to_begin+sample_rate*c, 'bof');% position the start
s_int16=fread(fid,sample_rate,'int16')';% read in Is and Qs
s_int8=typecast(s_int16,'int8'); %typecast int16 to int8
fileID = fopen('/home/write.bin','w');
dpb on 30 Aug 2022
Don't open/close the files inside the loop -- just read/write them sequentially...
fidi=fopen('/home/read.bin','r'); % open the file
fido = fopen('/home/write.bin','w');
More Answers (0)
Find more on Low-Level File I/O 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!