Texo Data Processing Prior to 6.0.x

Data representation
The data in the CINE-Buffer and respectively in the output files of the console example program is stored in the following manner:



Each block represents one byte. The number of samples in one line can be derived by:

MATLAB method to read data-file
To display the results of Texo data capture, the MATLAB code below provides a simple example. It is a function that will take in raw RF values outputted from Texo, and create a large matrix that will hold all RF lines organized into frames.


 * filename: Name of the raw RF data file, including all the directory information.
 * eg. \\D:\Data\Texo\RF\output.raw
 * w: Number of scanlines per frame. This information is determined by counting the times the function texo::addLine was called for the sequence
 * h: Size of each line in bytes. This value can be calculated by dividing the frame size in bytes by the number of scanlines per frame (w). However, the header of each file takes up 4 bytes, so it is necessary to get rid of first 4 bytes header which is used as a time-stamp for each frame collected from the cine buffer. The value of frame size is obtained by the function texo::getFrameSize.
 * frame_no: Number of frames acquired. This information is obtained by calling texo::getCollectedFrameCount.

A known error on the Sonix hardware is the fact that the first RF line on the first frame captured will be distorted. The easiest way to deal with this problem is to ignore the very first frame. Therefore it is advised to acquire one extra frame than actually necessary and discard the first frame.

fid = fopen(filename,'r'); frame_no*(w*h/2+2); [v,count] = fread(fid,inf,'short'); count; images = []; BigMatrix=[]; for frame_count = 1:frame_no, BigMatrix(frame_count,:) = v(((frame_count-1)*(h/2*w+2)+3) : ((frame_count)*(h/2*w+2)))'; end; for i=1:frame_no, A = reshape(BigMatrix(i,:),h/2,w); images(:,:,i) = A;   plot(A);%,axis([0 xmax ymin ymax  ]);%imagesc(A);colormap gray; end; fclose(fid);

The following MATLAB code provides an alternative method to read RF-data from a file. It will create a 3d-matrix containing the single scanlines sorted by frames.

clear; %Constants filename = 'frames.rf'; %Filename of the RF-file headerSize = 4;        %Size of frame header in bytes (constant if not changed by a new version of Texo) frameSize = 124676;     %Size of a single frame in bytes numberOfFrames = 10; linesPerFrame = 4;     %Number of scanlines per frame

%Read RF-file fid = fopen(filename,'r'); [dataFromFile] = fread(fid,inf,'short'); fclose(fid);           %Close the file, we have what we needed

%Sort frames numberOfFrames = numberOfFrames-1;          %drop first frame as invalid, as described in forum frames = zeros(frameSize/2,numberOfFrames); %create empty matrix (speeds up copying) for i = 1:numberOfFrames,                   %copy whole frames in matrix frames(:,i) = dataFromFile(i*frameSize/2+1:(i+1)*frameSize/2); end; clear dataFromFile;                          %Delete data to free memory

%Split up frames into scanlines samplesPerLine = ((frameSize-headerSize)/2)/linesPerFrame; frames(1:2,:) = [];                                        %delete frame headers linesByFrame = zeros(samplesPerLine,linesPerFrame,numberOfFrames); %empty 3d-matrix to hold lines for i = 1:numberOfFrames, for j = 1:linesPerFrame, linesByFrame(:,j,i) = frames((j-1)*samplesPerLine+1:j*samplesPerLine,i); end; end; clear frames;  %Delete data to free memory

%Example of how to extract a single frame (frame 2 in this case) frame1 = linesByFrame(:,:,2);