title: Scipy welch and MATLAB pwelch does not provide same answer
body: <p>I'm having trouble in python with the scipy.signal method called welch (<a href="https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.signal.welch.html" rel="noreferrer">https://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.signal.welch.html</a>), which estimates the frequency spectrum of a time signal, because it does not (at all) provide the same output as MATLAB's method called pwelch, given the same parameters (window size, overlap, etc.). Beneath is my code in each language, and the input files and output files are in the link here:</p>
  
  <p><a href="https://www.dropbox.com/s/2ch36phbbmjfhqg/inputs_outputs.zip?dl=0" rel="noreferrer">https://www.dropbox.com/s/2ch36phbbmjfhqg/inputs_outputs.zip?dl=0</a></p>
  
  <p>The input is a 2D array with rows being time steps and each column is a signal segment. The columns in the output is the spectrum from the corresponding  columns in the input. </p>
  
  <p>Python:</p>
  
  <pre><code>import numpy as np
  from scipy.signal import welch, get_window
  input = np.genfromtxt('python_input.csv', delimiter=',')
  fs = 128
  
  window = get_window('hamming', fs*1)
  ff,yy = welch(input, fs=fs, window = window, noverlap = fs/2, nfft=fs*2, 
  axis=0, scaling="density", detrend=False)
  np.savetxt("python_spectrum.csv", 10*np.log10(yy), delimiter=",")
  </code></pre>
  
  <p>MATLAB:</p>
  
  <pre><code>input       = csvread('matlab_input.csv');
  fs          = 128
  win         = hamming(fs);
  [pxx,f]     = pwelch(input ,win,[],[],fs,'psd');
  csvwrite('matlab_spectrum.csv',pxx);
  </code></pre>
  
  <p>I suspect scipy to be the problem, since it's output does not make sense in terms of reflecting the filters I have used (4'th order butterworth bandpass from 0.3 to 35 Hz with filtfilt) beforehand - MATLAB's output, however, does:</p>
  
  <p><a href="https://i.stack.imgur.com/NvHvy.png" rel="noreferrer">Each methods output using imagesc in MATLAB</a></p>
  
  <p>And some plots of the elementwise differences are here</p>
  
  <p><a href="https://i.stack.imgur.com/CuBAk.png" rel="noreferrer">Elementwise differences (y-axis should be 0-64!) (the third plot I have excluded the most extreme values)</a></p>
  
  <p>I did try with a simple sinusoid and it worked well in both programming languages - so I am completely lost.</p>