Saving Raw IQ data in file type .dat
조회 수: 60 (최근 30일)
how do I save in matlab data in file type .dat?
I have a file and it's type dat, it has RAW IQ SAMPLES so I open it in matlab, but in matlab command I write specific delimiters of my data and I want to store them (the specified data) in other file type .dat .
I mean by an example:
I have wrote a function called loadFile:
function y = loadFile(filename)
% y = loadFile(filename)
% reads complex samples from the rtlsdr file
fid = fopen(filename,'rb');
y = fread(fid,'uint8=>double');
y = y-127;
y = y(1:2:end) + i*y(2:2:end);
so once I load my file by writting in command window in matlab:
>>y=loadFile('frequency.dat'); %file name is frequency.
so after I have the data loaded from file name frequency.dat I want to save just y(2:6000) in another file file type .dat , how can I save the data of y(2:6000) in another file type .dat?
lets assume that y(2:6000) is stored in variable x, so
>> x=y(2:6000) ;
how can I save in matlab the data of x (specified data of y from 2 to 6000 y(2:6000)) in another file type .dat? thanks alot!
Walter Roberson 2020년 8월 19일
Assuming it has to be written in the same order, and as integer data:
sel_y = reshape(y(2:6000), 1, ); %row vector
sel_iq = reshape([real(sel_y); imag(sel_y)], 1, );
fid = fopen('newfile.dat', 'w');
fwrite(fid, sel_iq, 'int8');
y = y-127;
usually if you have uint8 data, you would be subtracting 128 rather than 127. The range of int8 is -128 to +127. If your input was +255 and you subtracted 127 you would get +128 which would be out of range for int8 .