Clear Filters
Clear Filters

Saving Raw IQ data in file type .dat

40 views (last 30 days)
Mohamed Jamal
Mohamed Jamal on 16 Aug 2020
Answered: Walter Roberson on 19 Aug 2020
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 Comment
Image Analyst
Image Analyst on 19 Aug 2020
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.

Sign in to comment.

Answers (2)

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

Walter Roberson
Walter Roberson on 19 Aug 2020
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 .

Categories

Find more on Introduction to Installation and Licensing 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!