Saving Raw IQ data in file type .dat

조회 수: 48 (최근 30일)
Mohamed Jamal
Mohamed Jamal 2020년 8월 16일
답변: Walter Roberson 2020년 8월 19일
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