IIR butter filter is not stable

6 ビュー (過去 30 日間)
Alex sinWave
Alex sinWave 2022 年 5 月 29 日
コメント済み: Star Strider 2022 年 5 月 30 日
Hi,
I am trying to make an IIR filter to a sound wave using butter(); , but the output worked in the first time I started the code then never run correctly after.
I have searched and found that makeing IIR using buttur(); sometimes gives unstable outpot and to overcome this problem I have to use z p k way ([z,p,k] = butter()) but I really do not know how to apply them to my sound signal if anyone can help m I will be thankful.
here is the part of the filters that is not working correctly in my code
[X,Fs] = audioread(filename);
temp = Fs/2;
[num2 , denum2] = butter(50, 170/temp, 'low');
y2 = filter(num2, denum2, X);
[num3 , denum3] = butter(50,[171 310]/temp, 'bandpass');
y3 = filter(num3, denum3, X);
[num4 , denum4] = butter(50,[311 600]/temp, 'bandpass');
y4 = filter(num4, denum4, X);
[num5 , denum5] = butter(50,[601 1000]/temp, 'bandpass');

採用された回答

Star Strider
Star Strider 2022 年 5 月 30 日
Use second-order-section representation for stability and filtfilt to do the actual filtering —
[X,Fs] = audioread(filename);
temp = Fs/2;
[z2,p2,k2] = butter(50, 170/temp, 'low');
[sos2,g2] = zp2sos(z2,p2,k2);
y2 = filtfilt(sos2,g2, X);
[z3,p3,k3] = butter(50,[171 310]/temp, 'bandpass');
[sos3,g3] = zp2sos(z3,p3,k3);
y3 = filtfilt(sos3,g3, X);
[z4,p4,k4] = butter(50,[311 600]/temp, 'bandpass');
[sos4,g4] = zp2sos(z4,p4,k4);
y4 = filtfilt(sos4,g4, X);
[z5,p5,k5] = butter(50,[601 1000]/temp, 'bandpass');
[sos4,g4] = zp2sos(z5,p5,k5);
y5 = filtfilt(sos5,g5, X);
.
  2 件のコメント
Alex sinWave
Alex sinWave 2022 年 5 月 30 日
thank you very much I really appreciate your help.
It worked fine but is there is a way to get the best order I am using 50 randomly and it works fine but for my knowledge curiosity I just want to know if there is a way
Star Strider
Star Strider 2022 年 5 月 30 日
As always, my pleasure!
Yes. Use the buttord function.
Depending on what you want to do, elliptic filters might be a better option, since they are computationally more efficient. For those, begin with ellipord and then ellip. The rest of the steps and the filtering are essentially the same as for the Butterworth filters here.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDigital Filter Design についてさらに検索

製品


リリース

R2015a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by