This hands-on how-to demonstrates how to use object-oriented programming features of Matlab 2008a to model C++ digital signal processing solutions.
By James Metzger, SPARTA, Inc.
Finally, we define a number of concrete classes from Module. The ContainerModule (Listing 5) contains a set of subordinate modules to coordinate a chain of signal processing such as convolution, automatic line integration followed by tone detection (TDModule Listing 6). In the Apply method of the TDModule, a number of calculations are made to estimate frequency, frequency deviation, and power level. Together these are used to evaluate a set of criteria that determines the presence of a tone. When this detection occurs, the module calls notify to inform any listening modules.
View all of Listing 5 code
View all of Listing 6 code
Using RegisterEvent in its constructor, the ContainerModule registers itself to be notified when the TDModule posts the detection event. When this event occurs, the ContainerModule's Notification method is automatically invoked upon which it displays a simple message to MATLAB's command line interface.
Comparisons to other object-oriented languages
For those familiar with other object-oriented languages such as C++ and Java, some of the features found in those languages will be noticeably absent:
• Multiple constructors cannot be defined. The only method for defining different constructors is to check the number of arguments in the one and only constructor and invoke different behavior based on that clue. In this way one may initialize default values for arguments not specified in the original call.
• Static properties are handled differently. One can use the persistent keyword to create a static variable in a static function, but there is no concept of a persistent property in the class definition.
• Member methods require incessant dereferencing. The first argument of each member method is a handle to the class instance, usually called "obj". This might be viewed as the "this" pointer used in C++ and is required for accessing member data in member methods.
• MATLAB is weakly typed and what method to call is not based on argument signature.
Overall, the important new features of object-oriented programming in the MATLAB environment make it much more possible to model a software solution as a system of objects as it may appear in a final implementation.