Main Content

whdlFramesToSamples

Convert frame-based data to sample stream

Description

[samples,ctrl,len] = whdlFramesToSamples(frames) serializes frame-based data into a stream of samples and accompanying control signals. The control signals indicate the validity of the samples and the boundaries of the frames. The function also returns a vector, len, of the frame size corresponding to each sample.

[samples,ctrl,len] = whdlFramesToSamples(frames,postsampleidles,postframeidles) inserts idle cycles in the sample stream, samples. Specify the number of idle cycles to insert between input samples, postsampleidles, and the number of idle cycles between frames, postframeidles.

example

[samples,ctrl,len] = whdlFramesToSamples(frames,postsampleidles,postframeidles,samplesize) creates a sample stream where each sample is represented by samplesize values. The function inserts samplesize zeros for each idle cycle requested. The ctrl and len vectors are the same size as when samplesize is 1.

example

[samples,ctrl,len] = whdlFramesToSamples(frames,postsampleidles,postframeidles,samplesize,interleaved) orders the sample stream, assuming the input samples are interleaved, when interleaved is 1 (true). The interleaved argument is valid only when samplesize is greater than 1.

example

Examples

collapse all

This example shows how to use the LTE Turbo Encoder block to encode data, and how to compare the hardware-friendly design with the results from LTE Toolbox™. The workflow follows these steps:

  1. Generate frames of random input samples in MATLAB®.

  2. Encode the data using the LTE Toolbox function lteTurboEncode.

  3. Convert framed input data to a stream of samples and import the stream into Simulink®.

  4. To encode the samples using a hardware-friendly architecture, run the Simulink model, which contains the Wireless HDL Toolbox™ block LTE Turbo Encoder.

  5. Export the stream of encoded samples to the MATLAB workspace.

  6. Convert the sample stream back to framed data, and compare the frames with the reference data.

Generate input data frames. Generate reference encoded data using lteTurboEncode.

rng(0);
turboframesize = 40;
numframes = 2;

txBits    = cell(1,numframes);
codedData = cell(1,numframes);

for ii = 1:numframes
    txBits{ii} = logical(randi([0 1],turboframesize,1));
    codedData{ii} = lteTurboEncode(txBits{ii});
end

Serialize input data for the Simulink model. Leave enough time between frames for each frame to be fully encoded before the next one starts. The LTE Turbo Encoder block takes inframesize + 16 cycles to complete encoding of a frame.

inframes = txBits;

inframesize = size(inframes{1},1);

idlecyclesbetweensamples = 0;
idlecyclesbetweenframes = inframesize+16;

[sampleIn,ctrlIn] = ...
    whdlFramesToSamples(inframes, ...
                          idlecyclesbetweensamples, ...
                          idlecyclesbetweenframes);

Run the Simulink model. The simulation time equals the number of input samples. Because of the added idle cycles between frames, the streaming input data includes enough cycles for the model to complete encoding of both frames.

sampletime = 1;
samplesizeIn = 1;
simTime = size(ctrlIn,1);
modelname = 'ltehdlTurboEncoderModel';
open_system(modelname);
sim(modelname);

The Simulink model exports sampleOut_ts and ctrlOut_ts back to the MATLAB workspace. Deserialize the output samples, and compare the framed data to the reference encoded frames.

The output samples of the LTE Turbo Encoder block are interleaved with the parity bits.

Hardware-friendly output: S_1 P1_1 P2_1 S2 P1_2 P2_2 ... Sn P1_n P2_n

LTE Toolbox output: S_1 S_2 ... S_n P1_1 P1_2 ... P1_n P2_1 P2_2 ... P2_n

Reorder the samples using the interleave option of the whdlSamplesToFrames function. Compare the reordered output frames with the reference encoded frames.

sampleOut = sampleOut';
interleaveSamples = true;
outframes = whdlSamplesToFrames(sampleOut(:),ctrlOut,[],interleaveSamples);

fprintf('\nLTE Turbo Encoder\n');
for ii = 1:numframes
    numBitsDiff = sum(outframes{ii} ~= codedData{ii});
    fprintf(['  Frame %d: Behavioral and ' ...
        'HDL simulation differ by %d bits\n'],ii,numBitsDiff);
end
Maximum frame size computed to be 132 samples.

LTE Turbo Encoder
  Frame 1: Behavioral and HDL simulation differ by 0 bits
  Frame 2: Behavioral and HDL simulation differ by 0 bits

Input Arguments

collapse all

Frames of input samples, specified as a column vector or a cell array of column vectors. The frames in the cell array can be different sizes.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical | fi

Number of idle cycles to insert between samples, specified as an integer. The function inserts samplesize zeros for each idle cycle, and sets all control signals to 0 (false).

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Number of idle cycles to insert between frames, specified as an integer. The function inserts samplesize zeros for each idle cycle, and sets all control signals to 0 (false).

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Number of values representing each sample, specified as a positive integer. The function returns one set of control signals for each samplesize values.

For example, in the LTE standard, the turbo code rate is 1/3, so each turbo-encoded sample is represented by one systematic, and two parity values: Sn, Pn1, and Pn2. In this case, set samplesize to 3.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Order of output samples relative to input order, when more than one value represents each sample, specified as a logical scalar.

For example, for 1/3 turbo-encoded samples, the input frame can be ordered [S_1 P1_1 P2_1 S_2 P1_2 P2_2] or [S_1 S_2 P1_1 P1_2 P2_1 P2_2]. In the first case, the default output would be the same order as the input. To achieve that output order for the second input, set interleaved to 1 (true).

Data Types: logical

Output Arguments

collapse all

Stream of samples, returned as a column vector. For N samples in an input frame, the output is N + samplesize×(N×idlecyclesbetweensamples + idlecyclesbetweenframes) values per frame.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical | fi

Control signals accompanying sample stream, returned as an M-by-3 matrix. The matrix includes three control signals, start, end, and valid, for each samplesize elements in samples. For N input samples in F frames, M is N + N×idlecyclesbetweensamples + F×idlecyclesbetweenframes. When you import this variable into Simulink®, use a Sample Control Bus Creator block to convert the signals into the bus type used by the Wireless HDL Toolbox™ blocks.

Data Types: logical

Frame length, returned as a column vector of integers. This value is the number of valid samples in the corresponding frame for each samplesize elements in samples. This vector is the same length as ctrl.

Data Types: double

Version History

Introduced in R2017b