MATLAB Answers

0

Can 'cascade' be used on bandstop filters created with 'designfilt'?

Anne Bennett さんによって質問されました 2019 年 7 月 9 日
最新アクティビティ Star Strider
さんによって コメントされました 2019 年 7 月 10 日
I'm having issues using 'cascade' on some 'bandstopfir' filters I created using 'designfilt'. Does cascade not support bandstopfir filters created this way? The error says "cascades must be of discrete-time filter objects." Mine seem to be 'digitalFilters' - is that different? The list of supported objects is unfamiliar to me- are these older filter types prior to designfilt?
clear; clc;
Fs = .25;
Apass1 = 2; % First Passband Ripple (dB)
Astop = 50; % Stopband Attenuation (dB)
Apass2 = 2; % Second Passband Ripple (dB)
% first notch - Hd_1
Fpass1 = 1E-3; % First Passband Frequency
Fstop1 = 1.1E-3; % First Stopband Frequency
Fstop2 = 1.2E-3; % Second Stopband Frequency
Fpass2 = 1.3E-3; % Second Passband Frequency
Hd_1 = designfilt('bandstopfir', 'PassbandFrequency1', Fpass1, ...
'StopbandFrequency1', Fstop1, 'StopbandFrequency2', Fstop2, ...
'PassbandFrequency2', Fpass2, 'PassbandRipple1', Apass1, ...
'StopbandAttenuation', Astop, 'PassbandRipple2', Apass2, ...
'SampleRate', Fs);
% second notch - Hd_2
Fpass1 = 2.15E-3; % First Passband Frequency
Fstop1 = 2.25E-3; % First Stopband Frequency
Fstop2 = 2.45E-3; % Second Stopband Frequency
Fpass2 = 2.55E-3; % Second Passband Frequency
Hd_2 = designfilt('bandstopfir', 'PassbandFrequency1', Fpass1, ...
'StopbandFrequency1', Fstop1, 'StopbandFrequency2', Fstop2, ...
'PassbandFrequency2', Fpass2, 'PassbandRipple1', Apass1, ...
'StopbandAttenuation', Astop, 'PassbandRipple2', Apass2, ...
'SampleRate', Fs);
Hd_all = cascade(Hd_1, Hd_2);

  0 件のコメント

サインイン to comment.

製品


リリース

R2019a

1 件の回答

Star Strider
回答者: Star Strider
2019 年 7 月 9 日
 採用された回答

If you want to design a filter with multiple stopbands, it is likely easier to do this with a FIR filter.
For example:
Fs = 1000; % Sampling Frequency (Hz)
fcuts = [56 58 62 64 116 118 122 124 176 178 182 184]; % Frequencies
mags = [1 0 1 0 1 0 1]; % Passbands & Stopbands
devs = [0.05 0.01 0.05 0.01 0.05 0.01 0.05]; % Tolerances
[n,Wn,beta,ftype] = kaiserord(fcuts,mags,devs,Fs); % Kaiser Window FIR Specification
n = n + rem(n,2);
hh = fir1(n,Wn,ftype,kaiser(n+1,beta),'noscale'); % Filter Realisation
figure
freqz(hh,1,2^14,Fs)
set(subplot(2,1,1), 'XLim',[0 200]); % Zoom Frequency Axis
set(subplot(2,1,2), 'XLim',[0 200]); % Zoom Frequency Axis
FIR filters are not the most computationally efficient (this one has a length of 1119) however that they lack in efficiency they make up for in ease-of-design, especially for more complicated filters. This one has a linear phase characteristic, so you can use filter with it. (You can also use filtfilt, however that may not be necessary.) See the documentation for the various functions to understand how they work.

  5 件のコメント

Star Strider
2019 年 7 月 10 日
I don’t have the DSP System Toolbox, so I can’t experiment with the cascade function.
I suspect that cascading your filters would be less efficient than a single FIR filter that does the same operation in one call.
This filter reasonably meets your specifications:
Fs = 0.25; % Sampling Frequency (Hz)
fcuts = [1 1.1 1.2 1.3 2.15 2.25 2.45 2.55]*1E-3; % Frequencies
mags = [1 0 1 0 1]; % Passbands & Stopbands
devs = [0.05 0.01 0.05 0.01 0.05]; % Tolerances
[n,Wn,beta,ftype] = kaiserord(fcuts,mags,devs,Fs); % Kaiser Window FIR Specification
n = n + rem(n,2);
hh = fir1(n,Wn,ftype,kaiser(n+1,beta),'noscale'); % Filter Realisation
figure
freqz(hh,1,2^14,Fs)
set(subplot(2,1,1), 'XLim',[0 3]*1E-3); % Zoom Frequency Axis
set(subplot(2,1,2), 'XLim',[0 3]*1E-3); % Zoom Frequency Axis
I would use filtfilt with it, since it does not have a uniformly linear phase response.
Anne Bennett 2019 年 7 月 10 日
That does nicely! Thanks for your assistance! (I missed that the fcuts variable needed all the edges and didn't have enough)
Star Strider
2019 年 7 月 10 日
As always, my pleasure!

サインイン to comment.



Translated by