title: Multiresolution Discrete Wavelet 3D Plot in Matlab
body: <p>I'm trying to perform DWT and make a 3D plot using Wavelet Analysis with Multi-resolution analysis (MRA) on a 1-D signal.</p>
  
  <p>In short, MRA will take a discrete sampled set of data and run wavelet analysis on it.</p>
  
  <p>Each pass produces 1/2 the samples of the previous run. I end up with an X by Y matrix with an amplitude stored in each value. X is the number of samples (or time), and Y is the "detail" wavelet result. The matrix of data might look something like this:</p>
  
  <pre><code>[ 1 1 1 1 2 4 8 2 1 1 1 1 2 1 1 2 ]
  [ 1 . 1 . 3 . 6 . 1 . 1 . 2 . 1 . ]
  [ 1 . . . 3 . . . 1 . . . 2 . . . ]
  [ 1 . . . . . . . 1 . . . . . . . ]
  </code></pre>
  
  <p>The '.' would be NaN or 0 or possible something else (I assume I'm doing something wrong).</p>
  
  <p>I want to produce a plot like so:</p>
  
  <p><img src="https://i.stack.imgur.com/MxRQj.gif" alt="enter image description here"></p>
  
  <p>It doesn't seem like Matlab can interpolate that much data in a graph. I've tried meshgrid, surf, ribbon, plot3, etc - but it requires all vectors to be the same length. Putting NaN or 0 results in un-reliable results.</p>
  
  <p>The best I've done so far is to use ribbon to represent the data as strips - but that also has issues in the data it is representing.</p>
  
  <p>I've done my best to read through the help pages in Matlab but haven't made much progress.
  Can someone push me in the correct direction?</p>
  
  <p><strong>Another update for November 2012</strong>
  High-density surf plot will appear entirely black due to the meshgrid edge color.
  To disable it, use the following function:
  surf(zi, 'EdgeColor', 'none');</p>
  
  <p><strong>Update with adjustment</strong>
  I'm still not convinced this is the final solution, but here is my best effort at producing a heatwave like 3D plot of random data. Whether this will help me realize my signal data is another story.</p>
  
  <pre><code>% initialize the matrix of sampled data
  indx = 1;
  data = NaN(5, 128);
  for row=1:5
      for col=1:128
          if ( mod(col-1, indx) == 0)
              data(row, col) = rand();
          end
      end
      indx = power(2, row);
  end
  
  % Linearize the data in each row to overcome NaN entries
  for row=1:5
      fprintf('Linear interpolation for row %d\n', row); 
      indx = NaN;
      for col=1:128
          if (data(row, col) ~= NaN) || (col == 128)
              if isnan(indx)
                  % initalize first point
                  indx = col;
              elseif isnan(data(row,col)) &amp;&amp; (col ~= 128)
                  % ignore NaN values between 1 and N-1
              elseif ((col-1) ~= indx)
                  fprintf('Creating linspace from col=%d to indx=%d\n', col, indx)
                  if (col == 128)
                      % first row will always contain all points
                      v = linspace(data(row, indx), data(1, col), col+1-indx);
                  else
                      v = linspace(data(row, indx), data(row, col), col+1-indx);
                  end
                  i=1;
                  for j=indx:col
                      data(row,j) = v(i); % update our data
                      i = i + 1; % increment counter
                  end
                  indx = col;
              elseif ((col-1) == indx)
                  indx = NaN;
              end
          end
      end
  end
  
  % Populate the X and Y vectors, X is columns, Y is rows, Z is data
  xmin = 1;
  ymin = 1;
  xmax = 128;
  ymax = 5
  [X, Y] = meshgrid(1:5, 1:128);
  
  [xi, yi] = meshgrid(.1:.1:5, 0:.5:128);
  zi = griddata(X, Y, data.', xi, yi);
  surf(zi);
  % disable edge color for high density plots (or it will look solid black)
  surf(zi, 'EdgeColor', 'none');
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/xCwe8.jpg" alt="Random Discrete 3D Plot using linearization"></p>