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