reading file in matlab

1 次查看(过去 30 天)
ali hassan
ali hassan 2020-9-21
how to read an data file and what it actually do?
function [ iq_signal ] = read_file_iq( filename )
%read_file_tdoa reads a file with IQ data (e.g. from rtl_sdr)
disp('read_file_iq');
% daten vom 1. RX
disp(['IQ read from data file = ' filename]);
fileID = fopen(filename);
a = fread(fileID);
fclose(fileID);
inphase1 = a(1:2:end) -128;
quadrature1 = a(2:2:end) -128;
disp(['successfully read ' int2str(length(inphase1)) ' samples']);
% complex representation
iq_signal = inphase1 + 1i.*quadrature1;
end
  3 个评论
ali hassan
ali hassan 2020-9-21
where to put questions then??
Rik
Rik 2020-9-21
编辑:Rik 2020-9-21
Have a read here and here. It will greatly improve your chances of getting an answer. I'll edit your question for you this time. You can put questions in the question body. You can use the editing tools to format your code as code, and make clear what your question is.
Your current question is not clear. What kind of data file are you trying to read? How did you get this code? Can you attach an example file? What kind of output do you expect? Remember that we can't read your mind, so you will have to explain your question to us.
A quick Google search suggests this function is from this Git repository.

请先登录,再进行评论。

回答(1 个)

Walter Roberson
Walter Roberson 2020-9-21
The code is intended to read binary files containing quadrature data.
The code reads the entire file as a series of uint8 values, and automatically converts them to double() [that is the default for fread()] .
The odd-numbered bytes have 128 subtracted from them, and are assigned to inphase1 . So bytes that were stored as 0 become -128, bytes that were stored as 128 become 0, bytes that were stored as 255 become +127 .
The even-numbered bytes have 128 subtracted from them, and are assigned to quadrature1 .
Then a series of complex number are formed by pairing up the inphase1 values with corresponding quadrature1 locations.
Quadrature data is represented as complex values by convention.

类别

Help CenterFile Exchange 中查找有关 File Operations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by