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?
采纳的回答
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 个评论
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.
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?
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;
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);
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.
OK, thanks for the advice, I will try to send a bug report.
=D
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Digital Filter Design 的更多信息
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
