I am converting some legacy matlab code to Python and I'm struggling to find the right function in python from the legacy code. The matlab filter is


TrainPassData is a nxn matrix and was an iterating variable.

Using scipy, I am confused as to which filter would fit this since butter doesn't seem to output the same values. For example, I have raw data as a list in X and I want the filtered values to be saved in a list called Y. Any and all help is appreciated.


1 Answer 1


Matlab comes up with a 15th order Chebycheff Type 1 filter so can probably poke the same filter specs into https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.cheby1.html

If the filter spec never changes you simply hardwire the coefficients.

This being said this highly questionable code, so before blindly porting it, I recommend taking a serious look at what it's trying to do and why

  1. The cutoff of frequency is the Nyquist frequency. So this is actually not filtering anything.
  2. The bandpass ripple target is extremely aggressive which makes the filter order very high (for an IIR)
  3. The use of filtfilt() makes this also non-causal with severe post and pre ringing (for any reasonable cutoff frequency).
  4. Scipy filtfilt() only seems to support transfer function representation of the filter (instead of poles & zeros or second order sections). This can lead to severe numerical or stability problems for high order IIRs

As written, the code doesn't really do anything so you could replace it with

Filtered(:,q)= TrainPassData(:,q);



to obtain the impulse response of the filter produces the plot below, which confirms that the filter does nothing.

Impulse response of wheelFilt


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.