designfilt error in loop

8 views (last 30 days)
S
S on 24 Jan 2024
Commented: S on 25 Jan 2024
So I am using a total of 32 filters and trying to observe their cascaded outputs using the code below to design the bandpass filters. But I cant input filter_number 32 without getting the error included in the bottom. I thought by setting numFilts to 32 I could set filter_number from 0 to 32? Thank you for your time!
fs = 16e3;
numFilts = 32;
BW = 100; %Filter Bandwidth
filter_number = 30;
%range = [50 8000];
CenterFreqs = linspace(50, 8000, numFilts);
CF1 = CenterFreqs - BW/2; %Lower cutoff frequency
CF2 = CenterFreqs + BW/2; %Upper cutoff frequency
for ii = 1:filter_number
bpfilt{ii} = designfilt( ...
'bandpassfir', ...
'FilterOrder',20, ...
'CutoffFrequency1',CF1(ii+1), ...
'CutoffFrequency2',CF2(ii+1), ...
'SampleRate',fs);
end
[h{ii},f] = freqz(bpfilt{ii}.Coefficients,1,4*8192,fs); %4*8192 points, fir filt denom
Error (I do not have a line 189? I also didnt use the function parseAndDesignFilter, or is that what designfilt is?):
Error using designfilt>parseAndDesignFilter
Frequency specifications must be between 0 and 8000.
Error in designfilt (line 189)
[err,requestedResponse,parseParams,h] = parseAndDesignFilter(inputParamValueNames, varargin{:});
Error in test1 (line 13)
bpfilt{ii} = designfilt( ...

Answers (1)

Paul
Paul on 25 Jan 2024
Edited: Paul on 25 Jan 2024
In this messsage "Error in designfilt (line 189)," the "line 189" is refering to the line number in designfilt, not your code. Your code had an error on line 13 of test1.m, which is the location of the call to designfilt.
Running the first part of your code:
fs = 16e3;
numFilts = 32;
BW = 100; %Filter Bandwidth
filter_number = 30;
%range = [50 8000];
CenterFreqs = linspace(50, 8000, numFilts);
CF1 = CenterFreqs - BW/2; %Lower cutoff frequency
CF2 = CenterFreqs + BW/2; %Upper cutoff frequency
Check the endpoints of CF1 and CF2
CF1(1)
ans = 0
CF2(end)
ans = 8050
Now look at the error message:
"Frequency specifications must be between 0 and 8000."
I'm not sure if CF1(1) = 0 is considered to be "between 0 and 8000" but CF2(end) = 8050 is outside the allowable range in the error message.
  1 Comment
S
S on 25 Jan 2024
So would I change the range to fix this do you think? Or is my CF1 and CF2 the issue?
I tried making the range 8050 instead of 8000, but I got the same issue, Im thinking becuase now CF2(end) would now be 8100
I'm not sure how else I could fix this

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!