DSP System Toolbox

Using System Objects with MATLAB® Compiler™

This is a demonstration of using the MATLAB Compiler to create a standalone application from a MATLAB function file that uses System objects.

Introduction

In this example, you compile the linear predictive coder MATLAB function file dspLinearPredictiveCoderFcn.mdspLinearPredictiveCoderFcn.m using the MATLAB compiler, and then run the generated standalone application. This linear predictive coder function contains LPC analysis and synthesis (LPC coding) of a speech signal.

Note that compilation is supported only for System objects used inside MATLAB functions. MATLAB scripts using System objects are not supported by MATLAB compiler.

LPC Analysis and Synthesis of Speech

This linear predictive coding function contains two steps: analysis and synthesis. The analysis section extracts the reflection coefficients from the signal and uses them to compute the residual signal. The synthesis section reconstructs the signal using the residual signal and the reflection coefficients. The function also plots the signal spectrum and the spectrum estimated from the LPC coefficients.

Run the MATLAB Code

dspLinearPredictiveCoderFcn
close all;

Create a Temporary Directory for Compilation

To compile the MATLAB function to create the standalone application, you use a temporary directory. You copy the MATLAB function to compile and the required helper files into this temporary directory.

compilerDir = [tempdir 'compilerDir']; % Name of temporary directory
if ~exist(compilerDir,'dir')
    mkdir(compilerDir); % Create temporary directory
end
curdir = cd(compilerDir);
copyfile(which('dspLinearPredictiveCoderFcn'));
copyfile(which('hfigslpc'));
copyfile(which('plotlpcdata'));
copyfile(which('speech_dft.avi'));

Compile the MATLAB Function Into a Standalone Application

You use the mcc function to compile the dspLinearPredictiveCoderFcn into a standalone application. You specify the '-m' option to generate a standalone application, and the '-N' option to include only the directories specified via the '-p' option in the path. This step takes a few minutes to complete.

mcc('-mN', 'dspLinearPredictiveCoderFcn', '-p', [matlabroot '/toolbox/dsp']);

Run the Deployed Application

You use the system command to run the generated standalone application. Note that running the standalone application using the system command uses the current MATLAB environment and any library files needed from this installation of MATLAB. To deploy this application to end users see the 'Deployment Process' section in the MATLAB CompilerMATLAB Compiler product User's Guide.

system(['.' filesep 'dspLinearPredictiveCoderFcn']);

Clean up Generated Files

cd(curdir);
rmdir(compilerDir,'s');