IIR butter filter is not stable

7 次查看(过去 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 CenterFile Exchange 中查找有关 Digital Filter Design 的更多信息

产品


版本

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by