title: How to make FIR filter with Parks-McClellan method in python
body: <p>I am trying to make a FIR filter in python with Parks-McClellan method.But I couldn't find how to make.These are the specifications of filter ,i need to change the code Matlab to python,</p>
  
  <pre><code>fs = 10000; % sampling frequency fCut1=2000; % cuting frequency fCut2=3000;
  fCut3=4000;
  df=50;
  w=[0 fCut1-df fCut1+df fCut2-df fCut2+df fCut3-df fCut3+df fs/2]/(fs/2); % normalized frequencies
  A=[0 0 0 1 1 0 0 0 ];% amplitudes
  n=50;
  a = 1; % FIR Filter
  % Find the characteristics for LP with Parks-McClellan algorithm b = firpm(n,w,A);
  titleString = ['Custom Filter, Parks-McClellan optimal FIR, order ' num2str(n)];
     plotFreqPhaseResp(b,a,fs,titleString,[fCut1 fCut2 fCut3])
  </code></pre>
  
  <p>So far i came up with this:</p>
  
  <pre><code>import numpy.linalg as lin
  import numpy as np
  import scipy.signal as sp
  import matplotlib.pyplot as plt
  fs = 10000
  fCut1=2000
  fCut2=3000
  fCut3=4000
  df=50
  w=np.true_divide([0,fCut1-df,fCut1+df,fCut2-df,fCut2+df,fCut3-df,fCut3+df,fs/2],(fs/2))
  A=[0 ,0 ,0 ,1, 1, 0, 0, 0 ]
  N=50
  
  b=sp.firwin(N,w,pass_zero=True)
  a=np.array(1.)
  w,H=sp.freqz(b,a,worN=512,plot=None)
  f=w/(np.pi)
  
  plt.figure()
  plt.close('all')
  plt.plot(f,abs(H))
  plt.grid(True)
  </code></pre>
  
  <p>But it gives an error which is  File "/Users/burakmacbook/Documents/Documents - Burak’s MacBook Air/Uni/3/3:2/DSP/LAB-RO/untitled11.py", line 21, in 
      b=sp.firwin(N,w,pass_zero=True)</p>
  
  <p>File "/Users/burakmacbook/opt/anaconda3/lib/python3.7/site-packages/scipy/signal/fir_filter_design.py", line 400, in firwin
      raise ValueError("Invalid cutoff frequency: frequencies must be "</p>
  
  <p>ValueError: Invalid cutoff frequency: frequencies must be greater than 0 and less than fs/2.
  I have to see this <a href="https://i.stack.imgur.com/P73zE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/P73zE.png" alt="plot"></a>.</p>