Examples
This feature is not supported on the Wolfram Cloud.

The C code generator can be used to create standalone executables that link to the Wolfram runtime library.

Lowpass Filter

This example creates a standalone C executable for a lowpass filter.

Building the Executable

First, you need to create a target directory for the output.

In[8]:=
Click for copyable input
Out[8]=

Now a compiled function that implements a discrete lowpass filter is defined.

In[2]:=
Click for copyable input

This uses the code generator to save the C source file and header file in the target directory.

In[3]:=
Click for copyable input
Out[5]=

To run the code you need to embed it in a main program. The following is a suitable C function that calls the generated code.

In[21]:=
Click for copyable input

Here, the main program is written into the target directory.

In[7]:=
Click for copyable input
Out[8]=

Now you can build the standalone executable as in the following. Notice how it links in the static minimal library: this avoids a need to set up library paths. Since it uses a platform-independent name, this should work on all platforms. Note how the option is set to : this makes sure that the Wolfram Symbolic Transfer Protocol (WSTP) libraries are not included in the link stage.

In[9]:=
Click for copyable input
Out[8]=

This standalone executable can be used by itself, distributed to others, and incorporated into other systems.

Running the Standalone Program

Now you can run the standalone program. In a real application you would not run it from the Wolfram Language as is done here. The following is really for the purpose of demonstration.

First, you need to make an input signal with several frequency components.

In[11]:=
Click for copyable input
Out[14]=

The standalone program reads from its input in the following format.

nelems
elem #1
...
elem #n
dt
RC

Now you can create an input file of the appropriate format from the signal. This is shown below.

In[15]:=
Click for copyable input
Out[8]=

This runs the standalone executable and loads back the result into the Wolfram Language.

In[19]:=
Click for copyable input

The result can be converted into a Wolfram Language expression and verified. Finally, you can extract the actual numbers.

In[21]:=
Click for copyable input

Here the filtered signal is plotted in red along with the original input signal in blue.

In[23]:=
Click for copyable input
Out[23]=

The standalone program does not have to be run from the Wolfram Language; you can run it any way you wish. But you can test it from the Wolfram Language and illustrate its output conveniently this way.

Finally, you can remove the example directory, if desired.

In[24]:=
Click for copyable input

Standalone Lifting Wavelet Transforms

Examples of using standalone code generation are demonstrated in the documentation for LiftingFilterData. You can find these in "Applications".