Butterworth lowpass filtering without signal processing toolbox
이전 댓글 표시
Hi,
I'm trying to accomplish butterworth lowpass filtering but do not have the signal processing toolbox. Is it possible to do this type of filtering without this toolbox?
답변 (3개)
This is a fair method to determine the coefficients for a Butterworth filter:
function [Z, P, G] = myButter(n, W, pass)
% Digital Butterworth filter, either 2 or 3 outputs
% Jan Simon, 2014, BSD licence
% See docs of BUTTER for input and output
% Fast hack with limited accuracy: Handle with care!
% Until n=15 the relative difference to Matlab's BUTTER is < 100*eps
V = tan(W * 1.5707963267948966);
Q = exp((1.5707963267948966i / n) * ((2 + n - 1):2:(3 * n - 1)));
nQ = length(Q);
switch lower(pass)
case 'stop'
Sg = 1 / prod(-Q);
c = -V(1) * V(2);
b = (V(2) - V(1)) * 0.5 ./ Q;
d = sqrt(b .* b + c);
Sp = [b + d, b - d];
Sz = sqrt(c) * (-1) .^ (0:2 * nQ - 1);
case 'bandpass'
Sg = (V(2) - V(1)) ^ nQ;
b = (V(2) - V(1)) * 0.5 * Q;
d = sqrt(b .* b - V(1) * V(2));
Sp = [b + d, b - d];
Sz = zeros(1, nQ);
case 'high'
Sg = 1 ./ prod(-Q);
Sp = V ./ Q;
Sz = zeros(1, nQ);
case 'low'
Sg = V ^ nQ;
Sp = V * Q;
Sz = [];
otherwise
error('user:myButter:badFilter', 'Unknown filter type: %s', pass)
end
% Bilinear transform:
P = (1 + Sp) ./ (1 - Sp);
Z = repmat(-1, size(P));
if isempty(Sz)
G = real(Sg / prod(1 - Sp));
else
G = real(Sg * prod(1 - Sz) / prod(1 - Sp));
Z(1:length(Sz)) = (1 + Sz) ./ (1 - Sz);
end
% From Zeros, Poles and Gain to B (numerator) and A (denominator):
if nargout == 2
Z = G * real(poly(Z'));
P = real(poly(P));
end
댓글 수: 2
erico vale
2018년 6월 20일
Could you comment the code ?
Eduardo Rey
2020년 3월 14일
Jan, I tried using this code to get coefficents for a low-pass response using n=1, w = 0.04 since fs=2K and fc = 40Hz but it gave me -1. Am I doing something wrong?
Anastasios
2014년 6월 26일
0 개 추천
Hi John,
You can download a 30-day free trial if you want to do something for now
https://www.mathworks.com/programs/trials/trial_request.html?prodcode=SG&eventid=616177282&s_iid=main_trial_SG_cta2
Tasos
댓글 수: 2
John
2014년 6월 26일
Anastasios
2014년 6월 26일
Check the following webpage at Rice University. Hopefully you can find your answer there. 2D Frequency Domain Filtering and the 2D DFT
Fiza
2020년 9월 8일
0 개 추천
Hi,
Under what license can i use this code?
카테고리
도움말 센터 및 File Exchange에서 Analog Filters에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!