title: MATLAB fftfilt equivalent for Python
body: <p>I am trying to traslate the following function created in MATLAB into Python, </p>
  
  <pre><code>function output_phase = fix_phasedata180(phase_data_degrees, averaging_length)
  
  x = exp(sqrt(-1)*phase_data_degrees*2/180*pi);
  N = averaging_length;
  b = 1/sqrt(N)*ones(1,N);
  y = fftfilt(b,x);y = fftfilt(b,y(end:-1:1));y = y(end:-1:1); # This is a quick implementation of filtfilt using fftfilt instead of filter
  output_phase = (phase_data_degrees-(round(mod(phase_data_degrees/180*pi-unwrap(angle(y))/2,2*pi)*180/pi/180)*180));
  temp = mod(output_phase(1),90);
  output_phase = output_phase-output_phase(1)+temp;
  output_phase = mod(output_phase,360);
  s = find(output_phase&gt;= 180);
  output_phase(s) = output_phase(s)-360;
  </code></pre>
  
  <p>So, I am trying to implement this function defined in MATLAB into Python here</p>
  
  <pre><code>def fix_phasedata180(data_phase, averaging_length):
      x = np.exp(1j*data_phase*2./180.*np.pi)
      N = averaging_length
      b = 1./np.sqrt(N)*np.ones(N)
      y = fftfilt(b,x)          
      y = fftfilt(b,y[::-1])
      y = y[::-1]
      output_phase = data_phase - np.array(map(round,((data_phase/180.*np.pi-np.unwrap(np.angle(y))/2.)%(2.*np.pi))*180./np.pi/180.))*180
      temp = output_phase[0]%90
      output_phase = output_phase-output_phase[0]+temp
      s = output_phase[output_phase &gt;= 180]
      for s in range(len(output_phase)):
          output_phase[s] = output_phase[s]-360
      return output_phase
  </code></pre>
  
  <p>I was thinking that the function <a href="http://projects.scipy.org/scipy/attachment/ticket/837/fftfilt.py" rel="nofollow noreferrer">fftfilt</a> was a clone of fftfilt in MATLAB, when I run I have the following error</p>
  
  <pre><code>ValueError                                Traceback (most recent call last)
  &lt;ipython-input-40-eb6944fd1053&gt; in &lt;module&gt;()
        4 N = averaging_length
        5 b = 1./np.sqrt(N)*np.ones(N)
  ----&gt; 6 y = fftfilt(b,x)
  
  D:/folder/fftfilt.pyc in fftfilt(b, x, *n)
       66         k = min([i+N_fft,N_x])
       67         yt = ifft(fft(x[i:il],N_fft)*H,N_fft) # Overlap..
  ---&gt; 68         y[i:k] = y[i:k] + yt[:k-i]            # and add
       69         i += L
       70     return y
  
  ValueError: could not broadcast input array from shape (0,0) into shape (0)
  </code></pre>
  
  <p>So, my question is: are there any equivalent to MATLAB fftfilt in Python? The aim of my function <code>output_phase</code> is to correct the fast variations in a phase signal and then correct n*90 degrees shifts, showed bellow
  <a href="https://i.stack.imgur.com/pnQ67.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pnQ67.png" alt="enter image description here"></a></p>