I really like examples that involve hardware because they are flashy and you can physically see things happening. The MathWorks
provides several toolboxes for connecting to various types of hardware, ranging from data and image acquisition boards to
stand alone instruments.
What I like about this nifty demo is that it combines both Data Acquisition Toolbox and Image Acquisition Toolbox to do motion and noise detection. Once the program detects some motion or noise, it starts recording video and audio for
a specified number of seconds. It's also very simple to try out, because it only requires an off-the-shelf webcam (I'm using
a Logitech USB webcam) and a soundcard which is already installed on my laptop.
Take a look at this short recording I made. I tested this out at a hotel in Kalamazoo, MI (I was there for a seminar).
Comments?
Anybody doing hardware interfaces? Tell me about it here. I would be interested in hearing about simple examples that you can do with a webcam or a sound card (so that I can try
it out!). And please post them on the File Exchange!
Even though I have moved over to the Video blog [click here] I wanted to give a quick update on the winner of the data exploration puzzler we did a while back.
It turns out that the winner, Arthur, already had a t-shirt from when Loren visited MIT. So instead, he sent me a resume, applied and got a job at The MathWorks. He started Monday.
Being active on MATLAB Central is beneficial in and of itself, but it can also lead to careers with us. Jiro and Brett were already well known for their MATLAB cleverness through MATLAB Central before they started here.
If you want a job at The MathWorks click here and send your favorite blogger your resume.
Be sure to visit the new video blog and subscribe so that you know when I put up new videos, tutorials and puzzlers.
I recall fondly being an undergrad engineering student, and being required to learn Morse code as a prerequisite to throwing
my name into contention to drive a solar-powered car in a long-distance race. I never got very good at it (Morse code, that
is), and have forgotten everything I once knew. (Except for S's and O's...we all seem to know them!)
Fahad's MORSE is pretty cool; it renders a string of characters as an audible series of dots and dashes, making translating
words into Morse code trivially easy. Now if someone would just write a MATLAB program that listens to a series of dots and
dashes and translates it back to text. Any takers?
Oh, and there's a t-shirt in it for the first person to post in the comments to this blog the (exact!) message encoded in
the video above!
Today, Brett, Bob and Jiro have completed their inheritance of Pick of the Week blog. There is a fine heritage of Applications Engineers running the Pick of the Week blog. Scott Hirsch and I started it nearly five years ago with this post. [click here]
With the three amigos taking over, I am now freed up to dedicate time to this new blog. Doug's MATLAB Video Tutorials. You can expect the same content with original videos, puzzlers, tutorials and answers to user questions.
The first video is about memory allocation in MATLAB. In this two minute video, I show that a statement like Y = X; does not increase MATLAB's memory usage, even for large variables.
Brett's Pick this week focuses on functionality rather than on a single file.
For a project I'm currently playing around with, I recently decided that I wanted to make my computer talk, and to use MATLAB
to control it. A brief search of documentation didn't return any hits that looked promising--MATLAB doesn't really provide
any mechanism for generating speech. Looking at the File Exchange (keyword "speech"), though, proved fruitful. In fact, selecting
which of the several submissions to use was the most difficult part of the problem.
Chronologically, the first "speak" mfile I found was from Fahad Al Mahmood, submitted back in 2004. (Indeed, Fahad's file was selected as a Pick of the Week, back in '04.) But that file uses a call to Excel, and doesn't provide for a lot of control over the
generated speech.
Fahad's submission was closely followed by Iari-Gabriel Marino's no-frills ActiveX version of TTS (text-to-speech).
Wolfgang Garn's 2006 submission includes a function called text2speech that allows a user to control pitch, to insert pauses, and to add emphasis to words.
And Siyi Deng followed up in 2007 with another version of TTS that optionally allows the user to write WAV files, to control the speed of the voice, and to list available voices.
You gotta love the File Exchange--thanks for these great submissions, Fahad, Iari-Gabriel, Wolfgang, and Siyi!
Anyone have any good stories to share about using MATLAB to speak, or doing speech recognition in MATLAB? We'd love to hear
from you.
Advanced MATLAB: File name processing from directory listing
Very often MATLAB users want to be able to process a set of files from a directory. In this video, I show how you can look through a directory seeking files of the form “data###.dat” and then returning the “###” as a number with any leading zeros removed. This makes use of regular expressions, but does not explain their theory much at all.
Video Content
This is not the first time this kind of thing has been discussed. Check out Loren’s take, or Steve’s take from their blogs.
The data source is Wikipedia, which Bill references. I find his plots much more interesting than staring at tabular data.
His approach to coding this example underscores how many ways there can be to solve a problem. I know my own approaches have varied widely
over the years, usually dictated by time spent and knowledge level at the time.
Comments?
How do you approach analysis problems like this? Tell us about it here.
Last week, we had a Puzzler [click here] that could be developed faster and easier by using the Image Processing Toolbox. Some people used the toolbox, and some did not. As the conversation in the comments continued [click here] we scaled the problem up by solving the problem thousands of times. At this scale, a bottleneck in RMFIELD, which is used by REGIONPROPS, noticeably slowed the Image Processing based code.
It did not take long for Steve Eddins, of Image Processing fame, to notice this conversation. Soon, one of the developers on the team, Inpakala, worked up a solution that speed up the code 70%!
It is too late for this speed optimization to make the 2008b release of MATLAB, but it should make 2009a once all testing is done. This is a case of writing code clean and clear at first and only then doing optimization where the bottlenecks appear. I would like to talk about this solution, and use some MATLAB tools to explore it.
Here is the crux of the problem, in its simplest form:
im = round(rand(100));
for i = 1:1000
old = regionprops(im,'area');
end
we can quickly find the slowest part of each m-file until we hit the culprit.
By looking at the slowest line each time, Inpakala found that the slow line of code was from the use of STRMATCH, which is called by RMFIELD. Since that file is not something she can easily modify, just like any other MATLAB user, she needed to find a different way of writing the code she could control.
Lets look at her modified code using the file comparison tool:
We find that around the trouble line, Inpakala mde the following changes.
The analysis of the actual code changes made is really beyond the scope of this entry, but basically she changed two lines of code (in red) and added three others (in green) along with a new ten line subfunction (not shown).
In the final analysis: the code got longer, more complicated and faster. Notice the code started with the simplest code that would work, and only when optimization was needed was it attempted. In the end, this optimization knocked 70% off of the runtime for REGIONPROPS.
Do you find bottlenecks with the profiler? If you find a bottleneck in MATLAB code that could be improved, don’t be shy! Tell us about it!
Several people have asked about how I make these MATLAB videos. Recently the folks that make Camtasia interviewed me about the videos making process. Those of you that are interested in a look behind the curtain can read the full interview and video making tips here:
A few months ago, I wrote a post for Loren's Art of MATLAB blog about creating publication-quality graphics. That post was about controlling various properties of graphics objects to make the visualization a higher quality.
Another way of making better-looking graphics is to use anti-aliasing. Anti-aliasing provides a smoother look to the lines
drawn on the screen. PCs use anti-aliasing to make the fonts smoother. With MYAA, you can easily anti-alias your MATLAB graphics. This is great for both on-screen presentation as well as MATLAB publishing (this blog post is a published document).
Original Plot
With the regular screen resolution, you can see the aliasing. It is most apparent with diagonal lines.
membrane
Anti-Aliased Plot
Anti-aliased plot looks much smoother. MYAA supersamples the plot (as an image) and then resizes it (via a filtering method), giving an anti-aliased look.
myaa
If we take a closer look at the two images, you can see the anti-aliasing effect.
MYAA has additional features that make it a very handy tool. For example, you can specify the supersampling factor to provide
an even smoother look. The tool also has a nice interactive feature where you can refresh the graphics (after zooming or rotating
the original plot) or zoom in and out with the anti-aliased plot.
Finally, I like how Anders has been quickly updating his entry in response to the user feedback. He posted this file early
this month, and he has already updated several times, making this tool more user-friendly.
Comments
Do you ever make presentations directly from MATLAB? What are some tricks you employ to make MATLAB a presentation tool? As
a starter, I once created a MATLAB animation player for displaying animations. Tell us about your stories here.
Recent Comments