Examples

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.

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

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

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.

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

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 "SystemLibraries" option is set to {}: this makes sure that the Wolfram Symbolic Transfer Protocol (WSTP) libraries are not included in the link stage.

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.

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

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

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

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

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

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

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.

Standalone Lifting Wavelet Transforms

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