designfilt error in loop

8 次查看(过去 30 天)
S
S 2024-1-24
评论: S 2024-1-25
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( ...

回答(1 个)

Paul
Paul 2024-1-25
编辑:Paul 2024-1-25
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 个评论
S
S 2024-1-25
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

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Specialized Power Systems 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by