Saving Raw IQ data in file type .dat

51 次查看(过去 30 天)
Hi guys,
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!
  1 个评论
Image Analyst
Image Analyst 2020-8-19
You forgot to attach 'frequency.dat'.
Why not just do
fid = fopen(filename,'rb');
fwrite('%f', y(2:6000));
fclose(fid);
or something like that.

请先登录,再进行评论。

回答(2 个)

yuval
yuval 2020-8-17
There are several answers on how to save to a .dat file, for example:

Walter Roberson
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');
fclose(fid)
Note:
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 .

类别

Help CenterFile Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by