CMP EMBEDDED.COM

Login | Register     Welcome Guest  
HOME DESIGN PRODUCTS COLUMNS E-LEARNING CONFERENCES CODE FORUMS/BLOGS NEWSLETTERS CONTACT FEATURES RSS RSS

Using object-oriented MATLAB for DSP
This hands-on how-to demonstrates how to use object-oriented programming features of Matlab 2008a to model C++ digital signal processing solutions.



Embedded.com

A model for signal processing
Equipped with these new language features, casting the proposed signal-processing architecture becomes straightforward. First, we define a set of MATLAB classes that will constitute an abstract layer: Module, Data and Event (Listings 1, 2, and 3 respectively). The first two are derived from the handle class, which gives objects reference behavior. Without this inheritance, such things like an access method to set an object's state would not work: once returning from the method the state of the object would be as it was before the access method was called. Event is derived from the event.EventData class ordinarily used in the event-listener model. This allows us to customize the event object normally passed to listeners. In this case, we want to pass a time value or any other information associated with an event.

For Module, we define virtual functions Apply, Notification, and Reset. By default all functions in object-oriented MATLAB are virtual; in other words, they can be redefined in derived classes. To make a function pure virtual (one only defined in a derived class) the attribute Abstract can be set to true as it is for the Apply method which embodies the operation of the module on given input Data.

Type casting is weak in MATLAB. Even though one defines a virtual function with a certain argument signature, there is no enforcement on what type of objects can be used when actually calling the method. Remember that MATLAB is an interpreted language designed to be flexible and convenient. If the argument type is incorrect, one will know soon enough when the script is executed.

The special sauce of the abstract layer is the Module's RegisterEvent method, which uses the new MATLAB 2008a event-listener model. In this design pattern, Modules can register themselves to receive notification of another Module's events. When the event occurs, the recipient module will have its Notification method called, presumably to change some state of the notified module. With reference behavior, Notification can be called as soon as the event is posted and any changes to the recipient module's state have retention. This was not the case in my old pass-by-value architecture in which event handling was delayed until any object that was in use had to be returned to an unlocked state before being notified.

With the abstract set of classes so defined, any number of concrete classes can be derived. In this example we define a general Vector class from Data followed by a Signal class that has notions of time, frequency, and sample rate (Listing 4). Signal will be the coin of the realm by which our derived Modules transact information. Note also that the constructor of the Signal class illustrates how a super class constructor is used to initialize inherited properties.

View all of Listing 4 code

1 | 2 | 3 | 4 | 5 | 6

Rate this article: Low High
Current rating
  • .
Embedded.com Career Center
Looking for a new job?
SEARCH JOBS

Browse all jobs

SPONSOR
RECENT JOB POSTINGS





 :