6

Using MATLAB I apply Matching Pursuit to approximate a signal. My problem is that I struggle to visualize the time-frequency representation of the selected atoms. I'm trying to produce a Wigner plot similar to the following image (source).

enter image description here

I have looked into the Wavelet Toolbox, Signal Processing Toolbox as well as the open source Time-Frequency Toolbox, but I'm possibly just using the wrong parameters, since my experience with signal processing is quite limited.

Example

Using this data my goal is to reproduce the plot from above.

% fit the signal using MP
itermax = 50;
signal = load('signal.txt');
dict = wmpdictionary(length(signal));
[signal_fit, r, coeff, iopt, qual, X] = wmpalg('OMP', signal, dict, ...
                                               'itermax', itermax);

% wigner plot of the simulated signal
tfrwv(signal_fit)  % wigner-ville function from time-frequency toolbox

% wigner plot of each atom
atoms = full(dict(:, iopt))  % selected atoms
for i = 1:itermax
    tfrwv(atoms(:, i))
end

Unfortunately, none of the resulting plots comes close to the target visualization. Note, that in the example I use tfrwv with standard parameters which I tweak with the GUI that it opens.

I'd greatly appreciate your help.

Update

I think I have now understood that one needs to use Gabor atoms to get blobs with shapes resembling stretched gaussians. Unfortunately, there are no Gabor functions in the predefined dicts of the Signal Processing Toolbox. However, this question helped me in implementing the needed dictionaries, such that I get atoms which look quite similar to the example:

tf-representation of selected of atoms

Since my plots come close but are not perfect, there are still two questions open:

  • Can all of the blobs that we see in the first example be modeled by Gabor atoms alone, or do I need another dictionary of functions?
  • How can I combine the indidividual imagesc plots into a single visualization?
Community
  • 1
  • 1
imant
  • 597
  • 5
  • 15
  • Maybe you can use the caption of the image to write your own visualization code, instead of using `tfrwv`. "Each pixel in the heat map (top) represents an atom (a wavelet centered in time according to the horizontal position and with frequency corresponding to height). The color of the pixel gives the inner product of the corresponding wavelet atom with the signal (bottom)." You've got your atoms, so now you just need to take the inner-product. – Cecilia Mar 07 '17 at 00:32
  • Thanks for your comment. Plotting the atoms is not the main problem I believe. Please see the update for my current state. – imant Mar 07 '17 at 22:05

2 Answers2

3

To answer your second question 'How can I combine the indidividual imagesc plots into a single visualization?'

If you have multiple 2d matrices that you want to superimpose and display using imagesc, I would suggest taking the element-wise maximum.

For example, I generate two 31x31 grids with gaussians with different mean and variance.

function F = generate2dGauss(mu, Sigma)
    x1 = -3:.2:3; x2 = -3:.2:3;
    [X1,X2] = meshgrid(x1,x2);
    F = mvnpdf([X1(:) X2(:)],mu,Sigma);
    F = reshape(F,length(x2),length(x1));
end

F1 = generate2dGauss([1 1], [.25 .3; .3 1]);
F2 = generate2dGauss([-1 -1], [.1 .1; .1 1]);

I can plot them with subplots as in your example,

figure; 
subplot(1,2,1);
title('Atom 1');
imagesc(F1);

subplot(1,2,2);
title('Atom 2');
imagesc(F2);

Two subplots with a gaussian distribution in each

Or I can plot the per element maximum of the two grids.

figure;
title('Both Atoms');
imagesc(max(F1, F2));

The per element maximum of the two gaussian distributions

You can also experiment with element-wise means, sums, etc, but based on the example you give, I think maximum will give you the cleanest looking result.

Possible pros and cons of different functions:

  1. Maximum will work best if your atoms always have zero-valued backgrounds and no negative values. If the background is zero-valued, but the atoms also contain negative values, the negative values may be covered up by the background of other atoms. If your atom's overlap, the higher value will of course dominate.
  2. Mean will make your peaks less high, but may be more intuitive where you have overlap between atoms.
  3. Sum will make overlapping areas larger valued.
  4. If you have non-zero backgrounds, you could also try using logical indexing. You would have to make some decisions about what to do in overlapping areas, but it would make it easy to filter out backgrounds.
Cecilia
  • 4,512
  • 3
  • 32
  • 75
  • Thank you, element-wise maxima work well if I set up color limits that map negative values to zero. Do you have an idea how I could prevent the "squeezed" display of atoms at the boarders of the plot as seen in the top left and bottom right panels of my update? – imant Mar 12 '17 at 21:30
  • I'm sorry that I do not know enough about gabor atoms to give advice about the "squeezed" atoms. I imagine that for certain values of the *a*, *b*, *g* parameters, the [gabor function](https://en.wikipedia.org/wiki/Gabor_atom) simply shows this behavior. – Cecilia Mar 13 '17 at 15:32
  • Since you helped me significantly with the visualization in Matlab I accept your answer, which, together with the update of my question, solves my problem almost completely. Thanks again. – imant Mar 14 '17 at 07:13
  • Thank you, sorry I couldn't be more help with the actual matching pursuit side of the question. – Cecilia Mar 14 '17 at 15:49
-2

Q. How can I combine the indidividual imagesc plots into a single visualization?

A. Use subplot to draw multiple plots, find below sample with 2 by 2 plots in a figure. Change your equations in code

x = linspace(-5,5);
y1 = sin(x);
subplot(2,2,1)
plot(x,y1)
title('First subplot')

y2 = sin(2*x);
subplot(2,2,2)
plot(x,y2)
title('Second subplot')

y3 = sin(4*x);
subplot(2,2,3)
plot(x,y3)
title('Third subplot')

y4 = sin(6*x);
subplot(2,2,4)
plot(x,y4)
title('Fourth subplot')
SACn
  • 1,862
  • 1
  • 14
  • 29
  • If you look closely you notice that I did that already. Instead, I want to show all atoms in one plot, as in the first example. – imant Mar 08 '17 at 10:04
  • You can use `hold on` then draw all four plots in single figure. `hold on` will keep previous plot. Once all are plotted use `hold off`. Twin sine wave example [here](https://in.mathworks.com/help/matlab/ref/hold.html?requestedDomain=www.mathworks.com) – SACn Mar 09 '17 at 08:44
  • 1
    Unfortunately it's not that easy with imagesc plots I suppose. – imant Mar 09 '17 at 11:17
  • For images use can combine them using AND, OR, XOR operations and plot. Or use raw [RGB] array and then plot. – SACn Mar 10 '17 at 07:41