MatLab filter design vs. Python

306 views Asked by At

I'm working on converting a MatLab code to Python and I see that they are not very compatible, so I have to use some new parameters on the Python side to be able to get the same results as MatLab. Still, there is a filter that I've tried hard to achieve the same result: fdesign.highpass and design in MatLab:

    hp = fdesign.highpass('N, Fc',order, FC, Fs);
    Hd = design(hp,'butter');
    Data(n,:)=filtfilt(Hd.sosMatrix,Hd.ScaleValues,Data(n,:)); 

I'm using signal.butter on the Python side but I couldn't get the same filter:

    b, a = signal.butter(10, FC, 'highpass', analog=False, 
fs=config.sampling_rate, output="ba")
    data7 = signal.filtfilt(b, a, data6) 

Do you have any idea what the equivalence of the code given in Python is?

  • Order = 10
  • FC = 10
  • Sampling frequency = 256
  • Hd.sosMatrix :

1.0000 -2.0000 1.0000 1.0000 -1.8690 0.9268; 1.0000 -2.0000 1.0000 1.0000 -1.7473 0.8013; 1.0000 -2.0000 1.0000 1.0000 -1.6556 0.7068; 1.0000 -2.0000 1.0000 1.0000 -1.5948 0.6441; 1.0000 -2.0000 1.0000 1.0000 -1.5646 0.6129;

  • Hd.ScaleValues:

0.9489; 0.8872; 0.8406; 0.8097; 0.7944; 1.0000;

  • b:

[ 0.4551791 -4.55179104 20.48305968 -54.62149247 95.58761182 -114.70513418 95.58761182 -54.62149247 20.48305968 -4.55179104 0.4551791 ]

  • a:

[ 1. -8.43131806 32.09602996 -72.63325918 108.1914843 -110.82458397 79.0501498 -38.76564753 12.50684932 -2.39689227 0.20718802]

  • Data used in both MatLab and Python:

[-4.52524570e-04 -4.15547277e-04 -3.69618477e-04 -3.54294378e-04 -3.49118638e-04 -3.32459161e-04 -2.81526419e-04 -2.27654353e-04 -1.99580728e-04 -1.95510797e-04 -1.61056741e-04 -1.11072974e-04 -5.32648681e-05 -2.46667403e-05 -5.41950912e-06 -2.31557119e-08 4.65967628e-05 1.15442535e-04 1.45564054e-04 1.41258639e-04 1.42186569e-04 1.86131459e-04 2.58602602e-04 2.98376655e-04 2.91488956e-04 2.84846883e-04 3.28808363e-04 4.04729607e-04 4.05485650e-04 3.03873916e-04 1.87973179e-04]

  • Result in MatLab: enter image description here
  • Result in Python: enter image description here

I appreciate your help.

0

There are 0 answers