Archive for the ‘MATLAB’ Category

STFT and ISTFT

Wednesday, September 17th, 2008

Problem: I need to invert a spectrogram to listen to the signal. And I want to do it the best way possible.

Solution: It isn’t all that sophisticated. Here’s a limited implementation of Yang’s ICASSP 2008 solution; which is — surprise surprise — quite nearly the same as the ubiquitous heuristic overlap and add istft.

It’s limited in the following ways:

  • The least-squares solution is not implemented. This means that LS solution is available only for regularly spaced frequency bands since in that case LS solution reduces to p=2 solution.
  • MATLAB fft/ifft routines are used; and they take care of the P matrix (excess zeros to round to powers of 2).
  • The matrix algebra is not exploited — this is a quick and dirty test run.

(more…)

Scalescape

Sunday, August 24th, 2008

scalescape

Frequency Glides

Friday, May 30th, 2008

Problem I want to generate a sound with frequency glides.

Wild frequency glides!

Solution A frequency glide is a sound whose frequency evolves with time. Once the frequency is characterized, i.e. frequency at any point in time is known, a signal can be generated using a co/sine function.
(more…)

Fast Cross-correlogram

Monday, May 26th, 2008

Problem I want to compute cross-correlogram. Fast. Can it not be done quick and dirty in the spectral domain?

Solution Cross-correlation is straightforward to compute in spectral domain as ft(sig1)*conj(ft(sig2)). Computing the cross-correlogram requires successive windowed cross-correlation. MATLAB specgram does just that: can we leverage it?
(more…)

MATLAB Cloud Overlay

Friday, December 28th, 2007

Problem I want to compare two surfaces pixel by pixel. Putting them side by side is distracting and exact comparison is difficut (I’m not overlaying a grid on it). Is there some way I can lay one map translucent over the other?

A surface with another surface overlaid

Briefly Turn surface A into RGB image, and darken pixels based on surface B. The figure shows surface A with points lying in [0, 1]. A mask to highlight points lying above 0.5 is overlaid in the lower figure.
(more…)

MATLAB docked figures

Wednesday, December 12th, 2007

Problem I’m forced into windows-land, and MATLAB spits out figures all over the place. I do I swat the gnats?

Solution Dock those pests.

[[code]]DQpmdW5jdGlvbiBmaWc9ZmlndXJlX2RvY2tlZCh2YXJhcmdpbikNCmlmKGlzcGMoKSksDQogICAgICAgIGZpZz1maWd1cmUoJ1dpbmRvd1N0eWxlJywnZG9ja2VkJywnUmVuZGVyZXInLCdwYWludGVycycsdmFyYXJnaW57On0pOw0KZWxzZSwNCiAgICAgICAgZmlnPWZpZ3VyZSgnUmVuZGVyZXInLCAncGFpbnRlcnMnLCB2YXJhcmdpbns6fSk7DQplbmQ7DQo=[[/code]]

MATLAB Code in LaTeX

Wednesday, December 12th, 2007

Problem I write decent prototypes in MATLAB. How do I include it in a report so it doesn’t look too bad?

Demonstration of lstlisting code

Solution The latex listings package does a pretty good job. And you want some heavy customization. TODO.
(more…)

MATLAB surf plots: One more thing!

Friday, November 30th, 2007

Problem I spent my entire childhood over this research and when I finally get a cool graph, matlab throws in some ugly white blotches in it. Who hates me, and why?

Solution This might help: set(gcf, 'Renderer', 'painters'); or figure('Renderer', 'painters') while beginning on a new figure. MATLAB chooses a renderer each time it displays an image (or prints one), balancing memory size with processor load, so a surface plot may be rendered or saved as a bitmap (even in an eps file!). To ensure that MATLAB renders the plot for the best display, set the renderer to ‘painters.’

Save MATLAB Images with appropriate size

Thursday, November 22nd, 2007

Problem MATLAB figures saved as eps or jpg need to be scaled to put on page, but text gets skewed on scaling, and text size is *always* messed up.

Solution A function that takes figure placement constraints in terms of fraction of page width/height and computes appropriate dimensions of image and saves it.

If the image covers half the page width and quarter of the page height, we can place such 2 figures horizontally, and 4 such figures vertically. To save file with such dimensions in eps format, we call:


    savefigure(gcf, 'figures/coolgraph.eps', 4, 2, 'epsc2');

(more…)

Rude MATLAB Amusement

Thursday, November 22nd, 2007

amusement movie
(more…)