Electronic Design

Making Math Magic

Matlab is one of the main products from The Mathworks. The other is Simulink, a complementary package to Matlab. Simulink tackles multidomain simulation via graphical model-based designs while Matlab concentrates on numerical computation and analysis. Matlab algorithms are often incorporated into Simulink models but both Matlab and Simulink are quite useful by themselves. This time around we concentrate on Matlab 7.4. Matlab and Simulink are large, complex systems and there are a number of books available for both so this article is designed to give a taste of Matlab. Matlab comes with a range of tutorials, documentation plus extensive web-based support including a very active user community. Check out the latter and its extensive library of shared applications and algorithms like the Image Acquisition Toolbox 2 (Imaging Tools Now Work With Wider Range Of Cameras, ED Online ID #15754).

What Matlab Is and Isn’t

Basically Matlab is an IDE (integrated development environment) with it own programming language called m-code. The latter has the same root as an open source programming language project called Octave but Matlab’s power also comes from its encompassing environment and extensive third party support. One of the Matlab programming language’s claim to fame is its support for the vector and matrix operations. These are especially useful in DSP (digital signal processing) algorithms and it is not surprising that a significant amount of DSP development starts in Matlab. Matlab is also utilized extensively in science and engineering. Matlab supports object oriented programming (OOP). Key to Matlab’s success is the optimization of its vector and matrix support. The Matlab interface interprets Matlab programs but this is of little consequence because most of the computational work is done in the multithreaded, cache-aware libraries and runtime support. Still, Matlab’s just-in-time (JIT) compiler optimizes program scripts and the environment can take advantage of the latest 64-bit multicore PC platforms (Numerical Analysis Tool Goes Multicore, ED Online ID #14939) allowing Matlab to handle very large projects.

Getting Started With Matlab

Many will be familiar with Matlab from college. It is often used in classes because it eliminates a great deal of the grunt work when dealing with data while learning about algorithms. Often a Matlab class is a precursor to many other courses. One key advantage of the Matlab interface is its interactive nature. Its command line window mirrors many other interactive platforms like APL, Lisp and Smalltalk where typing a programming expression evaluates that expression and prints out the result. It makes experimentation easy and encouraged. The environment revolves around the current workspace and it is possible to create new variables within the workspace. One of the most common data types in Matlab applications are arrays, often multidimensional. This is where the array editor comes in handy. Drag and drop a variable from the workspace into the editor and change values as necessary or watch them change in response to applications or expressions evaluated in the command window. This makes the environment very useful for testing What If Scenarios as well as incremental testing of functions since any function can be called from the command line. This includes built-in functions as well as user defined functions. The command window can present hyperlinked text that can invoke Matlab expressions. It is also possible to copy the contents and put it into a Matlab script file if your latest experimental expressions have proven interesting. Matlab’s graphical presentation of data is many other programming environments tend to fall short. They can often provide basic plotting support as does Matlab where scaling is handled automatically based upon the data provided. Matlab can also provide more sophisticated user interface like one in the teapot demo. Matlab’s graphics are also capable of videos as well. This allows animation of results that can be exported and incorporated in multimedia presentations.

Matlab’s graphics are a two way street especially since Matlab applications are often used to analyze multimedia input. Matlab is often used to develop DSP algorithms and displaying the inputs and outputs in a graphical form is often the best way to analyze the results of the algorithm.

Matlab Data And Deployment

Matlab is often used simply to crunch data. The result may be something like a graphic plot or a spreadsheet file that is exported to another application. It is possible to automate this process. Standalone applications can be created using the Matlab Compiler (available separately). The compiler can create standalone applications, Windows DLLs or Linux shared libraries that can be called by Fortran, C or C++ code, or software components like Java classes and .NET assemblies. The system can create applications that incorporate C or C++ code as well. It is also possible to create a Windows runtime package that is accessible by Windows COM applications including applications like Microsoft Excel. An m-code program can also be incorporated into a Simulink model. These models can in turn be converted into applications using the Real-Time Workshop and Real-Time Workshop Embedded Coder (available separately).

Helping Others

I found working with Matlab to be interesting but like most programming environments there is a large learning curve depending upon what you intend to do with it. Its interactive nature makes learning significantly easier in addition to being more productive in general. One place to turn if you are not learning about Matlab in school is the plethora of online resources. As with most open source material, you need to be aware of any licensing restrictions. Sometimes there are limits on commercial use. Still, almost all of these resources are useful in learning Matlab or about algorithms in general.

Another Octave

Trail versions of Matlab are available but there is another way to check out the programming model of Matlab. The Octave programming language is an open source project that is “mostly compatible with Matlab.” A majority of the core functionality is usable across both but there is enough difference to make transition between the two difficult in large projects. Likewise, moving from Octave to Matlab will usually be easier than the converse because of the built-in features and extensive support that Matlab provides. Octave lacks an advanced IDE but it can be used with IDEs like Eclipse. It can utilize graphing packages like gnuplot but this interface will be different than Matlab’s graphics interface. Octave is an active project that is covered by GPL (general public license). Obviously, source is available.

TAGS: Digital ICs
Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish