現在この質問をフォロー中です
- フォローしているコンテンツ フィードに更新が表示されます。
- コミュニケーション基本設定に応じて電子メールを受け取ることができます。
Designfilt and crossover filters?
2 ビュー (過去 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!エラーが発生しました
ページに変更が加えられたため、アクションを完了できません。ページを再度読み込み、更新された状態を確認してください。
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の 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 (한국어)