I want to show the Magnitude response of three filters, as one response
15 ビュー (過去 30 日間)
古いコメントを表示
So, I am to design three butter filters, a low pass, band pass, and a high pass, with the biggest wrinkle being that they must each have a different order (other wise, I'd just create a band stop filter with two stops). (Technically 7, 8, and 10, but I'll get to that later.) I have no problem with that, but I want to get the freq response as a single line that shows what happens when all three filters are inline with one another. (Right now I can just show how each one campares, which is mostly useless, from my perspective. Below is where I am so far. Thank you for the help.
clear;
freqSample = 10000;
freqCutoffLow = 100;
bandPassLower = 500;
bandPassUpper = 1000;
freqCutoffHigh = 2000;
%as = [1/(freqCutoff*2*pi),1];
nLow = 8; % orderOfFilter;
nBandPass = 8;
nHighPass = 10;
wNLow= freqCutoffLow / (freqSample/2); %normalizedCutOffFreq
[lowA,lowB] = butter(nLow, wNLow);
[passA,passB] = butter(nBandPass,[bandPassLower bandPassUpper]/(freqSample/2));
[highA, highB] = butter(nHighPass, freqCutoffHigh/(freqSample/2),'high');
fvt = fvtool(lowA, lowB, passA, passB, highA, highB);
legend(fvt,'butterLow', 'butterHigh', 'butterPass')
0 件のコメント
回答 (3 件)
Max Murphy
2019 年 12 月 6 日
Could you use freqz and take the product of the frequency responses, assuming the filters will be cascaded in a linear system?
H_low = freqz(lowA,lowB,512);
H_pass = freqz(passA,passB,512);
H_high = freqz(highA,highB,512);
freqz will return the frequency response at a specified number of points, but since you have already determined your filter coefficients, the filter order will not be affected. Then, you can take the element-wise product of those responses.
0 件のコメント
Star Strider
2019 年 12 月 6 日
It’s always worth experimenting.
It seems that convolving the numerators and denominators of the individual filters is appropriate:
freqSample = 10000;
freqCutoffLow = 100;
bandPassLower = 500;
bandPassUpper = 1000;
freqCutoffHigh = 2000;
%as = [1/(freqCutoff*2*pi),1];
nLow = 8; % orderOfFilter;
nBandPass = 8;
nHighPass = 10;
wNLow= freqCutoffLow / (freqSample/2); %normalizedCutOffFreq
[lowA,lowB] = butter(nLow, wNLow);
[passA,passB] = butter(nBandPass,[bandPassLower bandPassUpper]/(freqSample/2));
[highA, highB] = butter(nHighPass, freqCutoffHigh/(freqSample/2),'high');
Av = conv(conv(lowA,passA),highA); % Convolve
Bv = conv(conv(lowB,passB),highB); % Convolve
figure
freqz(Av, Bv, 2^14, freqSample)
title('Convolved')
figure
freqz(lowA, lowB, 2^14, freqSample)
title('Low')
figure
freqz(passA, passB, 2^14, freqSample)
title('Bandpass')
figure
freqz(highA, highB, 2^14, freqSample)
title('High')
s = zeros(1,10001);
s(5000) = 1;
LowOut = filtfilt(lowA, lowB, s); % First Filter
BandOut = filtfilt(passA, passB, LowOut); % Cascade
AllOut = filtfilt(highA, highB, BandOut); % Cascade
FTs = fft(s);
FTA = fft(AllOut);
H = FTA ./ FTs; % Transfer Function
Fv = linspace(0, 1, fix(numel(s)/2)+1)*(freqSample/2);
Iv = 1:numel(Fv);
figure
plot(Fv, 20*log10(abs(H(Iv))/max(abs(H(Iv)))))
grid
The serial output of the three filters (the last figure) appears to give essentially the same result as the convolution (the first figure).
4 件のコメント
Star Strider
2019 年 12 月 10 日
My pleasure.
No worries.
If my Answer helped you solve your problem, please Accept it!
Carl Eranio
2019 年 12 月 8 日
1 件のコメント
Max Murphy
2019 年 12 月 8 日
No problem. Looks like the filters were in parallel, apologies for the misleading answer! Star strider's comment below is the correct answer.
参考
カテゴリ
Help Center および File Exchange で Filter Analysis についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!