Reading int16 from a file and writing as int8 to another file
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Bugrahan Ustundag
am 30 Aug. 2022
Bearbeitet: Bugrahan Ustundag
am 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?
clear all;
clc;
tic;
duration = 20; % seconds to be read
start_time =0;
sample_rate=25000000;
point_to_begin=0;
for c=0:duration
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
fclose(fid);
s_int8=typecast(s_int16,'int8'); %typecast int16 to int8
fileID = fopen('/home/write.bin','w');
fwrite(fileID,s_int8,'int8',point_to_begin+sample_rate*c);
fclose(fileID);
end
toc;
0 Kommentare
Akzeptierte Antwort
dpb
am 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');
for c=0:duration
s_int16=fread(fidi,sample_rate,'int16')';
s_int8=typecast(s_int16,'int8');
fwrite(fido,s_int8,'int8');
end
fclose('all')
clear fid*
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Data Import and Analysis finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!