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
2014 年 12 月 11 日
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
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
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
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
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
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
2014 年 12 月 15 日
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!Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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)
