이 질문을 팔로우합니다.
- 팔로우하는 게시물 피드에서 업데이트를 확인할 수 있습니다.
- 정보 수신 기본 설정에 따라 이메일을 받을 수 있습니다.
Designfilt and crossover filters?
조회 수: 6 (최근 30일)
이전 댓글 표시
Can anybody help me with an alternative function for DesignFilt and crossover filters. These functions work only with matlab 2016. it doesn't work in matlab 2013. What is the alternative function?
채택된 답변
Star Strider
2017년 3월 16일
댓글 수: 8
Darsana P M
2017년 3월 16일
Thanks for this. But my problem is that an error occurs for 'designfilt' in the code, since i am using matlab 2013 version. What should i do?
if true
% [A,B,C,D] = cheby2(10,40,[500 560]/750);
d = designfilt('bandpassiir','FilterOrder',20, ...
'StopbandFrequency1',500,'StopbandFrequency2',560, ...
'StopbandAttenuation',40,'SampleRate',1500);
sos = ss2sos(A,B,C,D);
fvt = fvtool(sos,d,'Fs',1500);
legend(fvt,'cheby2','designfilt')
end
Star Strider
2017년 3월 16일
I no longer have access to those functions (in R2017a). Since you want to design a bandpass filter, one option is the fdesign.bandpass function.
You can also design it yourself.
Example (using your design criteria):
Fs = 1500; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
Wp = [500 560]/Fn; % Passband Frequencies (Normalised)
Ws = [495 565]/Fn; % Stopband Frequencies (Normalised)
Rp = 5; % Passband Ripple (dB)
Rs = 50; % Stopband Ripple (dB)
[n,Ws] = cheb2ord(Wp,Ws,Rp,Rs); % Calculate Filter Order
[z,p,k] = cheby2(n,Rs,Ws); % Design Filter
[sos,g] = zp2sos(z,p,k); % Convert To Second-Order-Section For Stability
figure(1)
freqz(sos, 2^16, Fs)
set(subplot(2,1,1), 'XLim',[0 700]) % ‘Zoom’ X-Axis
set(subplot(2,1,1), 'YLim',[-50 100]) % ‘Zoom’ Y-Axis (Amplitude)
set(subplot(2,1,2), 'XLim',[0 700]) % ‘Zoom’ X-Axis
Darsana P M
2017년 3월 17일
편집: Star Strider
2017년 3월 17일
That really helped me.Thanks a lot. But a small doubt,
freqz(sos, 2^16, Fs)
set(subplot(2,1,1), 'XLim',[0 700]) % ‘Zoom’ X-Axis
set(subplot(2,1,1), 'YLim',[-50 100]) % ‘Zoom’ Y-Axis (Amplitude)
set(subplot(2,1,2), 'XLim',[0 700]) % ‘Zoom’ X-Axis
Why are these functions used??
Star Strider
2017년 3월 17일
My pleasure.
Those let you see that the filter design is what you want. They are not necessary for the code or for the actual filtering, but very helpful and will save you significant time because you can see what your filter is actually doing in frequency space.
Darsana P M
2017년 3월 17일
Thanks a lot. In a similar fashion if i want to design it for a bank of filters in the same graph itself, what will i do?
If suppose an audio signal is given, i have to design a band pass filter. The audio signal must be divided into sub bands ie 10-20Khz,20-30khz and so on. What can i do??
Star Strider
2017년 3월 17일
My pleasure.
See the techniques in How to shape the spectrum of an audio waveform?. It will be straightforward to adapt that code to your specifications. It designs a bank of Butterworth filters, and you can easily adapt it to Chebyshev Type II filters. It will probably be worthwhile to use the cheb2ord function in the loop to arrive at the correct order.
Remember to save your ‘sos’ and ‘g’ filter coefficients cell arrays to a ‘.mat’ file so you can simply load them rather than having to recalculate them when you are satisfied with their design and performance.
Darsana P M
2017년 3월 17일
편집: Star Strider
2017년 3월 17일
Can you please explain it once again. Is this the code that i must use?? But i got an error in the for loop part??
Fs = 8200; % Samping Frequency (Hz)
Fn = Fs/2; % Nyquist Frequency
pf = linspace(20,4000,17); % Passband Frequencies
cf = pf(1:end-1)+(pf(2)-pf(1))/2; % Centre Frequencies
for k1 = 1:length(cf)
[z(k1,:),p(k1,:),k(k1)] = butter(7, [pf(k1) pf(k1+1)]/Fn);
[sos{k1},g{k1}] = zp2sos(z(k1,:),p(k1,:),k(k1));
[h(k1,:),w(k1,:)] = freqz(sos{k1},512,Fs);
end
figure(1)
plot(w([1 16],:), abs(h([1 16],:)))
grid
% axis([0 0.2 ylim])
figure(2)
freqz(sos{1})
hold on
for k1 = 2:16
freqz(sos{k1})
end
hold off
Star Strider
2017년 3월 17일
You will need to change the code to design the filters that meet your requirements. Use your own sampling frequency, and define your filter passband frequencies in a vector and assign them to the ‘pf’ variable. You might be able to use the linspace call with only minor modifications. The rest of my code should work without any need to change it.
I ran that code just now and it ran for me without error (in R2017a, the code was written in R2015a). What error did you see? Please copy the entire red text of the error from the Command Window and paste it to a comment here.
추가 답변 (2개)
Darsana P M
2017년 3월 17일
Error using vertcat Dimensions of matrices being concatenated are not consistent.
Error in zp2sos>orderp (line 247) new_p = [p_conj;p_real];
Error in zp2sos (line 94) [new_p,p_conj,p_real] = orderp(p_conj,p_real);
Error in band8 (line 7) [sos{k1},g{k1}] = zp2sos(z(k1,:),p(k1,:),k(k1));
This is the error that i obtained. I tried it in matlab 2013a
댓글 수: 10
Star Strider
2017년 3월 17일
I no longer have access to R2013a. There should be no problem with the cell array assignments.
There could be differences in how the vectors are output. See if these changes work:
[z(:,k1),p(:,k1),k(k1)] = butter(7, [pf(k1) pf(k1+1)]/Fn);
[sos{k1},g{k1}] = zp2sos(z(:,k1),p(:,k1),k(k1));
It changes the row vectors to column vectors. This is a guess on my part as to how the R2013a butter (and other) functions format their outputs.
If that does not work, I am out of ideas.
Darsana P M
2017년 3월 18일
Wow that really worked!!!!!!!!! Thanks a lot. I got the output. In this, the 16 bandpass filters, has its starting and ending point at 0 and 1. Which parameter should i change? I have attached an image. To obtain the graph, should i change the pf parameter??
And also, can i do give an audio signal as input?? Will i be able to get the output??
Star Strider
2017년 3월 18일
‘Wow that really worked!!!!!!!!! Thanks a lot.’
Thank you! My pleasure!
‘Which parameter should i change?’
I am not certain what you want. You cannot have any of the passbands or stopbands exactly at 0 or 1 (actually normalised frequencies of 0 or pi or 0 and your Nyquist frequency) because those are the limits of the frequency space for your sampled signal. You can get close to them (you have to experiment with your filters to determine how close you can get, depending on the other filter parameters) but you cannot by definition include them. (They are included by default in lowpass and highpass filters that do not specifically include them. You cannot specify filter band limits that include them.)
So if you want a filter that goes from (and includes) 0 Hz to the lower passband of your lowest bandpass filter, use a lowpass filter design with the passband approaching the lower passband of your lowest filter. If you want a filter that goes from the upper passband of your highest filter to the Nyquist frequency, use a highpass filter with the passband just above the upper passband of your highest filter. That is a long reply to a short question. I wanted to provide background.
You can definitely filter your audio signal. If it is a (Nx2) stereo matrix, filter it as you would filter any other signal. Both channels will be filtered at the same time, and the output will be a (Nx2) array of your filtered signal.
It is easiest to filter your signal through each filter in a loop similar to the way you created them. Use the filtfilt function to do the actual filtering.
Example code to do the filtering:
for k1 = 1:length(cf)
filt_sig{k1} = filtfilt(sos{k1}, g{k1}, sig);
end
where ‘sig’ is the signal you are filtering. I use a cell array for ‘filt_sig’ because I do not know anything about your signal. The cell array will work for ‘sig’ being either a vector or a matrix (for example an (Nx2) stereo sound signal). You can use a double array, and assign the output to the appropriate rows or columns, but here, the cell array is easier. It is easy to recover your filtered signal from the cell array. The filtered output signal will be in the cell array.
Darsana P M
2017년 3월 18일
Thanks a lot for the answer. I actually want to design a bandpass filter for a chochlear implant. ie 20hz -20khz must be divided into bank of filters. 100-200hz; 200-300hz and so on. I got confused as to which method to apply. What should I do?? I think that a graph similar to the image I have sent must be obtained.
Star Strider
2017년 3월 18일
My pleasure.
All you need to do is to supply a vector of band-edge frequencies that meet your requirements.
This will design 200 filters matching your requirements:
pf = [20 100:100:2E+4];
Note — The length (number of elements) in ‘pf’ must be odd. The length of this ‘pf’ vector is 201, so it will work.
Darsana P M
2017년 3월 18일
So, if I give pf = [20 100:100:2E+4]; in the above code, will i be able to get the result??
Star Strider
2017년 3월 18일
Yes, providing that your sampling frequency is at least 44.1 kHz (the standard audio sampling frequency). That gives enough frequency space on the high end (from 20 kHz to 22.05 kHz) to allow the highest filter to have a complete passband, including the transition region from the passband to stopband.
Darsana P M
2017년 3월 22일
Fs = 8200; % Samping Frequency (Hz)
Fn = Fs/2; % Nyquist Frequency
pf = [20 100:100:2E+4] % Passband Frequencies
cf = pf(1:end-1)+(pf(2)-pf(1))/2; % Centre Frequencies
for k1 = 1:length(cf)
[z(k1,:),p(k1,:),k(k1)] = butter(7, [pf(k1) pf(k1+1)]/Fn);
[sos{k1},g{k1}] = zp2sos(z(k1,:),p(k1,:),k(k1));
[h(k1,:),w(k1,:)] = freqz(sos{k1},512,Fs);
end
figure(1)
plot(w([1 16],:), abs(h([1 16],:)))
grid
% axis([0 0.2 ylim])
figure(2)
freqz(sos{1})
hold on
for k1 = 2:16
freqz(sos{k1})
end
hold off
I wrote the pf command as you said. pf=[20 100:100:2E+4]. But i got an error saying
the cut off frequencies must be within the interval (0,1); line 57
[z(k1,:),p(k1,:),k(k1)] = butter(7, [pf(k1) pf(k1+1)]/Fn); line 7
This was done to get a similar graph as shown in figure?? What will i do?
댓글 수: 4
Star Strider
2017년 3월 22일
As I mentioned before, your sampling frequency, ‘Fs’ is assumed to be the standard audio sampling frequency of 44100 Hz, giving a Nyquist frequency, ‘Fn’ of 22050 Hz. If you use that sampling frequency, you can design your filters with no problems.
You cannot design your filters with those passbands with a sampling frequency of 8200 Hz. It is simply not possible.
참고 항목
카테고리
Help Center 및 File Exchange에서 Digital Filter Design에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!오류 발생
페이지가 변경되었기 때문에 동작을 완료할 수 없습니다. 업데이트된 상태를 보려면 페이지를 다시 불러오십시오.
웹사이트 선택
번역된 콘텐츠를 보고 지역별 이벤트와 혜택을 살펴보려면 웹사이트를 선택하십시오. 현재 계신 지역에 따라 다음 웹사이트를 권장합니다:
또한 다음 목록에서 웹사이트를 선택하실 수도 있습니다.
사이트 성능 최적화 방법
최고의 사이트 성능을 위해 중국 사이트(중국어 또는 영어)를 선택하십시오. 현재 계신 지역에서는 다른 국가의 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)
아시아 태평양
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)