reading file in matlab

1 view (last 30 days)
ali hassan
ali hassan on 21 Sep 2020
Answered: Walter Roberson on 21 Sep 2020
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 Comments
ali hassan
ali hassan on 21 Sep 2020
where to put questions then??
Rik
Rik on 21 Sep 2020
Edited: Rik on 21 Sep 2020
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.

Sign in to comment.

Answers (1)

Walter Roberson
Walter Roberson on 21 Sep 2020
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.

Categories

Find more on File Operations 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!