Introduction
For signal processing algorithm developers, MATLAB from The MathWorks is an essential tool. Its vector semantics and powerful visualization capabilities are a necessity for algorithm development. However, since algorithm development is often separate from product development, MATLAB programmers generally need to create a C-code model of their algorithm. This C-code model of the algorithm can have a number uses, including:
- Algorithm prototyping: The ubiquity of C-code platforms makes it a popular choice for prototyping algorithms before they are implemented. With C-code, algorithms can be easily run on multiple platforms and server farms to ease the testing burden. In addition, it is easier to connect C code to existing input and output sources, such as video streamers.
- Integration into a system model: DSP systems typically contain many components, and different components are often modeled in different languages. Thus, it is often necessary to create a C-code system model to integrate these disparate models together. Having C-code for an algorithm makes it easy to integrate it into a larger system model.
- As the core of a software application: If the final target of the algorithm is a software application, then the C-code model of the algorithm can simply be integrated with a small bit of hand-written code and compiled into the application.
Creating the C-code model requires developers to temporarily freeze algorithm changes and manually translate their algorithms into C. Manually translating the algorithmic model to C code can be a laborious task. As a result, developers tend to avoid making this translation until late in the design process. This increases the length of the development process and increases the cost of fixing bugs. Manual translation is also an error-prone process. This makes it difficult to determine if functional bugs are the result of a poor algorithm or a translation error.
These challenges can be addressed by using a tool such as Catalytic MCS that automatically generates C-code from MATLAB. This automation also enables developers to continue using MATLAB to modify their algorithms and generate a reference model as needed.
In this article, we describe how to use Catalytic MCS to greatly ease the task of integrating MATLAB algorithms into existing C-code. Throughout the article, we use a vertical image scaling algorithm as a running example.
Example: Vertical Image Scaler
For this example, we have developed a vertical image scaler in MATLAB. The scaler algorithm takes a single image and a scaling ratio as input and computes a scaled image, using a simple linear interpolation between pixel rows. Eventually, our goal is to integrate this algorithm with a video decoder to scale an input video stream to a variety of display types. For example, the algorithm could be used to scale an HDTV video (720 scan lines) to an NTSC video display (480 scan lines).
The video decoding application has already been developed using Microsoft's DirectShow, a C++-based environment for developing audio and video applications. We have created a skeleton DirectShow image transform filter, into which we will integrate the vertical scaling code. The resulting application will open an input video file, scale each frame, and play the resulting video stream on the screen.
Figure 1. Overview of Algorithm and Testbench in MATLAB and DirectShow