Multiple Bandpass Filter Creation
이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
이전 댓글 표시
0 개 추천
I am trying to make a cascade of bandpass filters. I want there to be 32 total filters covering the range of 50 to 8000. I am trying to do this efficiently by creating a variable for the upper and lower cutoff frequencies. How would I fix this so that the bpfilt cycles through all my CF1/CF2s in order? The goal would be to then put an input signal in and have it run through all the 32 filters in cascade. Thank you for your time!
close all
fs = 16e3;
range = [50 8000];
CF1=linspace(50, 8000, 32) -50;
CF2=linspace(50, 8000, 32) +50;
bpfilt = designfilt('bandpassfir', ...
'FilterOrder',20,'CutoffFrequency1',CF1, ...
'CutoffFrequency2',CF2,'SampleRate',fs);
freqz(bpfilt.Coefficients,1,[],fs)
채택된 답변
fs = 16e3;
%range = [50 8000];
CF1=linspace(50, 8000, 32) -50;
CF2=linspace(50, 8000, 32) +50;
Can't use the first and last elements of CF1 and CF2 respectively. CF1(1) = 0, which is not a valid input for CutOffFrequency1. This issue could be dealt with by making the first filter a low pass. CF2(end) is greater than the Nyquist frequecy.
for ii = 1:numel(CF1)-2
bpfilt{ii} = designfilt( ...
'bandpassfir', ...
'FilterOrder',20, ...
'CutoffFrequency1',CF1(ii+1), ...
'CutoffFrequency2',CF2(ii+1), ...
'SampleRate',fs);
[h{ii},f] = freqz(bpfilt{ii}.Coefficients,1,4*8192,fs);
end
Frequency responsee of each filter
figure
subplot(211)
plot(f,db(abs([h{:}])));
subplot(212);
plot(f,180/pi*(angle([h{:}])));

Frequency response of cascaded filters in series; this doesn't look like very useful.
Edit: In fact, the values on the magnitude plot on are so small that they are probably rounding error and are effectively zero (in absolute value). Are you sure you want the filters cascaded?
figure
subplot(211)
plot(f,db(abs(prod([h{:}],2))));
subplot(212);
plot(f,180/pi*(angle(prod([h{:}],2))));

Unfortunately, digitalFilter objects can't be mulitplied.
In theory, the coefficients of each filter can be combined as follows into a single filter
b = 1;
for ii = 1:numel(bpfilt)
b = conv(b,bpfilt{ii}.Coefficients);
end
Compare the frequency response of the cascade to the cascade of the frequency responses
hcascade = freqz(b,1,f,fs);
figure
subplot(211)
hold on
plot(f,db(abs(prod([h{:}],2))));
plot(f,db(abs(hcascade)));
subplot(212);
hold on
plot(f,180/pi*(angle(prod([h{:}],2))));
plot(f,180/pi*angle(hcascade))

In practice, that doesn't look like such a good idea.
If going to pursue this path, it's probabably best to use a loop and filter the input in stages. That will work, in theory, for forward filtering. Not sure if that's appropriate for forward/backward filtering.
댓글 수: 13
S
2024년 1월 21일
Thank you for your time! If I was to take an impulse/ signal and put it through the first image could I do it like this? Additionally where is the 8192 value from in the freqz line?
impulse_input = 0*fs;
impulse_input(1) = 1;
y=filter(impulse_input)
Paul
2024년 1월 21일
I don't know what you mean by "the first image."
Do you want the impulse response of each filter?
Or do you want the impulse response of the cascade of all the filters in series?
S
2024년 1월 21일
The second one! I want the impulse response of the cascade of all the filters in series. Then to be able to input a filter number and be able to see the output after that specfic filter in the cascade. Like
filter_number = 10;
Paul
2024년 1월 21일
Define the impulse input.
Write a loop to filter the input and use the output of the n-1th filter as the input to the nth filter.
filter only returns as many elements in the output as there are in the input, so make sure to include enough elements in the original impulse input to capture all of the elements of the output at the end of the cascade.
In the loop you can sequentially store the output of each successive filter for post-processing.
If still having problems after putting in some effort, feel free to post your code and explain what's going wrong or what you don't understand.
S
2024년 1월 21일
so by following: https://www.mathworks.com/help/matlab/ref/filter.html#d126e499602
I was trying to use the last option, but it says i do not have enough input arguments. Is this the correct way to get it to use the designed filter? Or is this not what you meant by use filter
impulse_input = 0*fs;
impulse_input(1) = 1;
for ii = 1:numel(CF1)-1
[y,zf]=filter(impulse_input)
end
Paul
2024년 1월 21일
impulse_input is the input to the filter, but you also have to tell filter what filter it needs to apply to the input. You can use the coefficients of each filter in the bpfilt cell array (assuming you used code that's posted above or something similar), or you can directly use each filter in the bpfilt cell array as the input to filter. For either case, see the Tips section of the doc page you linked.
As stated above, you'll need to design your loop so that the output of filter on one iteration is the input to filter on the next iteration.
If you want to continue the discussion, post your entire code that shows how your're building the array of filters and how you're trying to develop the impulse response of the cascade. It's difficult to help without seeing all that you're doing.
Paul
2024년 1월 22일
Are you sure you want the filters cascaded in series? Cascading all them makes the frequency response of the cascade effectively zero.
Paul
2024년 1월 22일
S
2024년 1월 22일
Where is the 8192 coming from in this line?
[h{ii},f] = freqz(bpfilt{ii}.Coefficients,1,4*8192,fs);
Paul
2024년 1월 23일
In that usage of freqz, the third argument is the number of frequency points at which to evalute the response. I just picked a number. Probably started with 8192 to see what it looked like, and then reran after multiplying by 4 to see if the additional points revealed anything interesting. 8192 and 4*8192 are both powers of 2, which might make freqz run a bit more efficiently.
S
2024년 1월 24일
oh ok that makes sense! I though that was zero padding
So it is following this format correct?
If so why is there a 1 in our statement when the maximum allowed looks like its 3 items in the () based on this page:
https://www.mathworks.com/help/signal/ref/freqz.html
Paul
2024년 1월 24일
The convention used by the documentation for that underbar is sometimes hard to understand (I get confused myself sometimes). In this case, that underbar means that you can replace the underbar with any of the arguments to freqz that precede n in any of the syntax cases above it. So I was using the syntax
[h,f] = freqz(b,a,n,fs)
In this problem, each bpfilt is a FIR filter. For the bpfilt FIR filter, the denominator is 1, hence the entry of 1 in the second argument in the call to freqz.
S
2024년 1월 24일
OH! That makes sense! Thank you for explaining!
추가 답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Digital Filter Design에 대해 자세히 알아보기
참고 항목
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 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)
