Cascade of discrete filters in MATLAB

7 ビュー (過去 30 日間)
Juan
Juan 2016 年 5 月 8 日
コメント済み: Star Strider 2016 年 5 月 8 日
Hello everyone. I'm trying to make a band-reject filter but I can't put 2 filters in cascade.
This:
lp = fir1(100, 0.77, 'low', rectwin(101));
hp = fir1(100, 0.83, 'high', rectwin(101));
dfilt.cascade(lp,hp)
gives the following error: Error using dfilt.cascade (line 43) Numeric section in a cascade must be a nonempty scalar.
Thanks!

採用された回答

Star Strider
Star Strider 2016 年 5 月 8 日
To use dfilt.cascade, you have to create the correct dfilt filter objects from your filters first:
lp = fir1(100, 0.77, 'low', rectwin(101));
hp = fir1(100, 0.83, 'high', rectwin(101));
lpf = dfilt.df2(lp,1);
hpf = dfilt.df2(hp,1);
ntch = dfilt.cascade(lpf,hpf);
figure(1)
freqz(ntch)
You may want to reconsider your filter designs.
  2 件のコメント
Juan
Juan 2016 年 5 月 8 日
編集済み: Juan 2016 年 5 月 8 日
Thanks! But it doesn't work. This is my code:
original_audio = 'audio.wav';
[mono Fs] = audioread(original_audio);
lp = fir1(100, 0.77, 'low', rectwin(101));
hp = fir1(100, 0.83, 'high', rectwin(101));
lpf = dfilt.df2(lp,1);
hpf = dfilt.df2(hp,1);
sb = dfilt.cascade(lpf,hpf);
fvtool(sb)
filtered_audio = filter(sb,1,mono); % *HERE I HAVE THE ERROR*
f=0:Fs/n:Fs;
fn = f*(2*pi)/Fs;
n=length(filtered_audio)-1;
figure;
plot(filtered_audio)
fftfiltered_audio = abs(fftshift(fft(filtered_audio)));
figure;
plot(fn/pi,fftfiltered_audio);
axis([0 1 -inf inf]);
And I have this error: Error using dfilt.cascade/filter Dimension argument must be a positive integer scalar in the range 1 to 2^31.
And this: Error in document (line 16) filtered_audio = filter(sb,1,mono);
Star Strider
Star Strider 2016 年 5 月 8 日
You are not calling filter correctly.
Try this:
filtered_audio = filter(sb,mono);

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

その他の回答 (1 件)

CS Researcher
CS Researcher 2016 年 5 月 8 日
You would have to convert the filters to dfilt type. Try this:
lp = fir1(100, 0.77, 'low', rectwin(101));
hp = fir1(100, 0.83, 'high', rectwin(101));
h1 = dfilt.df2t(lp,1);
h2 = dfilt.df2t(hp,1);
h = dfilt.cascade(h1,h2);
However, Mathworks documentation states:
"Note that with the DSP System Toolbox installed, one usually does not construct cascade filters explicitly. Instead, one obtains these filters as a result from a design using FDESIGN." You should look into this.

カテゴリ

Help Center および File ExchangeMultirate and Multistage Filters についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by