title: How to find envelope of uneven waveform
body: <p>I have a waveform which contains the phase shift information obtained from RF transceiver. It is not a regular waveform, but instead it is uneven as shown in the picture below. I have illustrate the envelope using paint, and how can I do that in MATLAB?
  <a href="https://i.stack.imgur.com/WkZSO.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WkZSO.png" alt="enter image description here"></a></p>
  
  <p>I also attached the waveform.csv. In my MATLAB code, I already used an averaging filter to smooth out the raw signal.</p>
  
  <p><a href="https://www.dropbox.com/s/2cgu78da612fxfp/waveform_ch1.csv?dl=0" rel="nofollow noreferrer">Waveform csv file</a></p>
  
  <p><a href="https://www.dropbox.com/s/5sudrgsvmmzxii8/envelope.m?dl=0" rel="nofollow noreferrer">envelope.m</a>:</p>
  
  <pre><code>clc; clear all; close all;
  
  %% Extract data from .csv
  file = '150825_px6_human_rotcw_0to60cm_Ch1.csv';
  data = csvread(file, 0, 3);
  
  %% Shift time
  shift = data(1,1);
  for i = 1:length(data)
      t(i) = data(i,1) - shift;
  end
  
  %% Low pass filter
  filterlen = 500;
  y = myfilter(data(:,2), filterlen);
  
  %% Plot
  figure;
  plot(data(:,1), data(:,2));
  title('Raw signal');
  
  figure;
  plot(t(1:end-filterlen+1), y);
  title('After low pass filter');
  </code></pre>
  
  <p><a href="https://www.dropbox.com/s/gzwqv6ypwhlnzix/myfilter.m?dl=0" rel="nofollow noreferrer">myfilter.m (simple averaging filter)</a>:</p>
  
  <pre><code>function y = myfilter(x,a) 
      for i = 1:(length(x)-(a-1))
          y(i) = sum(x(i:(i+a-1)))/a;
      end
      y = y';
  end
  </code></pre>