Main Content

MATLAB Performance Improvements

Vector-Based Processing

  • When you use vector-based processing, the program processes multiple samples during a single execution call to a System object™. Consider using vectors from roughly 366 to several thousand. The default is 3660, which represents 10 Ethernet packets.

  • Use large vectors of data to minimize function call overhead.

MATLAB Code Generation

You can accelerate your MATLAB® algorithms by generating a MEX function using the MATLAB Coder™ function codegen (MATLAB Coder).

Performance analysis for SDRu Transmitter System object

This example generates a MEX file called sdruTransmitMex from the function sdruTransmitData. You can observe a speedup (in megasamples per second (MS/s)) with no underruns at 10000 samples per frame when you run the MEX file of this code.

function[transmitTime,underrunCount] = sdruTransmitData()
       Duration = 10;
       SamplesPerFrame = 1e4;
       MasterClockRate = 20e6;
       InterpolationFactor = 1;
 
       SampleRate = masterClockRate/interp;
       FrameDuration = SamplesPerFrame/SampleRate;
       Iterations = Duration/FrameDuration;

       sinGen = dsp.SineWave('Frequency',100e3,'SampleRate',SampleRate, ...
                       'SamplesPerFrame',SamplesPerFrame, ...
                       'ComplexOutput',true);
       data = sinGen();
       tx = comm.SDRuTransmitter('Platform','B210','SerialNum','30F59A1', ...
                          'CenterFrequency',2.45e9, ...
                          'MasterClockRate',MasterClockRate, ...
                          'InterpolationFactor',InterpolationFactor);
       tx(data);
       disp('Started Transmission...');
       underrunCount = 0;
       tic
       for i = 1:Iterations
           underrun = tx(data);
           if underrun
              underrunCount = underrunCount+1;
           end
       end
       transmitTime = toc;
       release(tx);
end

Run this command to generate a MEX file called sdruTransmitMex from the function sdruTransmitData.

codegen sdruTransmitData -o sdruTransmitMex;

Run this MEX file to transmit data using the generated MEX, and observe the transmission time and number of underruns.

[transmitTime,underrunCount] = sdruTransmitMex()

Performance analysis for SDRu Receiver System object

This example generates a MEX file called sdruReceiveMex from the function sdruReceiveData. You can observe a speedup (in megasamples per second (MS/s)) with no overruns at 10000 samples per frame when you run the MEX file of this code.

function [receiveTime,overrunCount] = sdruReceiveData()
        Duration = 10;
        MasterClockRate = 35e6;
        DecimationFactor = 1;
        SamplesPerFrame = 10000;

        SampleRate = MasterClockRate/DecimationFactor;
        FrameDuration = SamplesPerFrame/SampleRate;
        Iterations = Duration/FrameDuration;

        rx = comm.SDRuReceiver('Platform','B210','SerialNum','30F59A1', ...
                       'MasterClockRate',MasterClockRate, ...
                       'DecimationFactor',DecimationFactor, ...
                       'OutputDataType','double');
        count = 0;
        rx();
        disp('Started Reception...');
        tic
        for i = 1:Iterations
            [data,~,overrun] = rx();
            if overrun
            count = count+1;
            end
        end
        receiveTime = toc;
        overrunCount = count;
        release(rx);
        end

Run this command to generate a MEX file called sdruReceiveMex from the function sdruReceiveData.

codegen sdruReceiveData -o sdruReceiveMex;

Run this MEX file to receive data using the generated MEX, and observe the reception time and number of overruns.

[ReceiveTime,overrunCount] = sdruReceiveMex()

Note

These codes were timed on a Windows® 10, Intel® Xeon® CPU E5-1650 v4 @ 3.60 GHz test system.

Related Topics