Thursday, October 4, 2012

Matlab fread optimization


The problem statement is to read in-phase and quadrature binary data from a file in which they are alternated:
I1
Q1
I2
Q2
...
In
Qn

each value is a 32-bit integer.

the trivial way to do it is as follow using fread function:

fid=fopen(filepath);
for k=1:n
    I(k)=fread(fid,1,'int','l');
    Q(k)=fread(fid,1,'int','l');
end

An other possibility with minimizing the access to fread function:


temp=fread(fid,IQA_sz/4,'int','l');
I(:)=temp(1:2:end);
Q(:)=temp(2:2:end);

The result is similar much the execution time is speedup by a factor 5 to 6