title: Matlab/Python: Power spectral density of non-uniform time series
body: <p>I am trying to find the power spectral density of a signal measured at uneven times. The data looks something like this:</p>
  
  <pre><code>0 1.55
  755 1.58
  2412256 2.42
  2413137 0.32
  2497761 1.19
  ...
  </code></pre>
  
  <p>where the first column is the time since the first measurement (in seconds) and the second column is the value of the measurement.</p>
  
  <p>Currently, using the <em>periodogram</em> function in Matlab, I have been able to estimate the power spectral density by using:</p>
  
  <pre><code>nfft = length(data(:,2));
  pxx = periodogram(data(:,2),[],nfft);
  </code></pre>
  
  <p>Now at the moment, to plot this I have been using</p>
  
  <pre><code>len = length(pxx);
  num = 1:1:len;
  plot(num,pxx)
  </code></pre>
  
  <p>Which clearly does not place the correct x-axis on the power spectral density (and yields something like the plot below), which needs to be in frequency space. I am confused about how to go about this given the uneven sampling of the data.</p>
  
  <p><img src="https://i.stack.imgur.com/pVPwT.png" alt="example"></p>
  
  <p>What is the correct way to convert to (and then plot in) frequency space when estimating the power spectral density for data that has been unevenly sampled? I am also interested in tackling this from a python/numpy/scipy perspective but have so far only looked at the Matlab function.</p>