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!