# Convert matlab line to scipy signal processing line

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

wheelFilt=designfilt('lowpassiir','FilterOrder',15,'PassbandFrequency',1000,'PassbandRipple',0.0001,'SampleRate',2000);
Filtered(:,q)=filtfilt(wheelFilt,TrainPassData(:,q));


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.

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);


Running

impz(wheelFilt,50);


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