tf2sos of iirnotch giving different results

Hi,
I am trying to use iirnotch() for filtering, I noticed that if I ran the coefficients from iirnotch (2nd order) through tf2sos (still comes out to be the exact same numbers), the frequency response of (b,a) and (sos) showed in freqz() or fvtool() gives very different results.
eg: [b,a] = iirnotch(wo,bw); [sos1] = tf2sos(b,a); freqz (b, a, Fs); freqz (sos, Fs);
I was wondering how come there is a difference?

 採用された回答

Star Strider
Star Strider 2014 年 12 月 11 日

0 投票

You didn’t post the details of your code so I can only provide a general reply. As the documentation states, the second-order-section (‘sos’) implementation of a filter characteristically produces the most stable version of the filter. The transfer function (‘tf’) is usually less stable. Therefore, the plotted filter passband-stopband characteristics may be different between the two implementations. (I convert to and use the ‘sos’ implementation whenever I design a filter.)

6 件のコメント

Daoyuan
Daoyuan 2014 年 12 月 12 日
Thanks for the answer, my code is similar to the eg I gave, so for example, I was testing the notch filter for power line interference.
%60 Hz noise, at 300Hz sampling frequency
wo = 60/(300/2); bw = wo/35;
[b,a] = iirnotch(wo,bw);
fvtool(b,a);
sos = tf2sos(b,a);
fvtool(sos);
From the result of this code, the first and second graph looks completely different, the first graph having around -80dB notch with a flat band everywhere else, and the second has a wide notch of only -40dB, and with a non-flatband after the notch. However I am confused because if you look at the values in b & a versus the values in SOS, they are the exact same values:
sos = 0.98236277 -0.607133581 0.98236277 1 -0.607133581 0.96472554
b = 0.98236277 -0.607133581 0.98236277
a = 1 -0.607133581 0.96472554
However, the graph in the fvtool or freqz shows very different results. I was wondering since the notch provides a second order iir filter, and the sos is a second order iir filter, both with the same values, how are they producing different results. To my knowledge I thought the sos should produce the same results as the original iir filter if both are second order, since the tf2sos converts high order into cascaded second order filters.
Daoyuan
Daoyuan 2014 年 12 月 12 日
Just to update, I realized that I think the mistake I made is that when I used: fvtool(sos); I should have used: fvtool(sos(1, 1:3), sos(1, 4:6)); which would place the second half of the sos as the denominator. So I guess if I use when sos is used with freqz or fvtool, the matrix should be manually separated between numerator and denominator of IIR?
Star Strider
Star Strider 2014 年 12 月 12 日
I get the same results when I plot your data with freqz. I don’t have the DSP System Toolbox so I can’t experiment with it.
I get good results with this code for your filter in both tf and sos implementations (Signal Processing Toolbox):
Fs = 300; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
Ws = [59 61]/Fn; % Stopband Limits
Wp = [57 63]/Fn; % Passband Limits
[n,Wn] = buttord(Wp, Ws, 1, 10);
[b,a] = butter(n, Wn, 'stop'); % Design Stopband Filter
[sos,g] = tf2sos(b,a);
figure(3)
freqz(b,a)
figure(4)
freqz(sos)
The filter coefficients here are:
b = [949.9142e-003 -1.1746e+000 2.2629e+000 -1.1746e+000 949.9142e-003];
a = [1.0000e+000 -1.2047e+000 2.2604e+000 -1.1444e+000 902.3386e-003];
sos = [1.0000e+000 -618.2445e-003 1.0000e+000 1.0000e+000 -554.5812e-003 949.5072e-003;
1.0000e+000 -618.2445e-003 1.0000e+000 1.0000e+000 -650.1666e-003 950.3231e-003];
g = 949.9142e-003;
Daoyuan
Daoyuan 2014 年 12 月 12 日
perhaps it is because the iirnotch gives a second order filter. I edited my code, and I think it is because if the sos shows a 1 row matrix, it will take the code as 1 row of 3rd order fir filter with "a" being 1? I added this code at the end of my mine and it yields the same results as fvtool(sos) or freqz(sos).
b1 = sos;
a = 1;
fvtool (b1, a);
figure
freqz (b1, a);
Star Strider
Star Strider 2014 年 12 月 12 日
Your previous Comment seems to have solved the problem. Still, there seems something anomalous about the results you’re getting with the SOS implementation. Something is wrong somewhere, and it isn’t in your code.
I suggest you mention your findings to The MathWorks in a bug report. Copy and paste the URL for your Question here to your bug report so you don’t have to repeat everything.
Daoyuan
Daoyuan 2014 年 12 月 15 日
OK, thanks for the advice, I will try to send a bug report.
=D

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

その他の回答 (0 件)

カテゴリ

質問済み:

2014 年 12 月 11 日

コメント済み:

2014 年 12 月 15 日

Community Treasure Hunt

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

Start Hunting!

Translated by