Butterworth lowpass filtering without signal processing toolbox

67 visualizzazioni (ultimi 30 giorni)
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?

Risposte (3)

Jan
Jan il 26 Giu 2014
Modificato: Jan il 7 Lug 2014
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 Commenti
Eduardo Rey
Eduardo Rey il 14 Mar 2020
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?

Accedi per commentare.


Anastasios
Anastasios il 26 Giu 2014
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 Commenti
John
John il 26 Giu 2014
That's not an option for now, and that decision doesn't come from me. Is there another option you can think of?
Anastasios
Anastasios il 26 Giu 2014
Check the following webpage at Rice University. Hopefully you can find your answer there. 2D Frequency Domain Filtering and the 2D DFT

Accedi per commentare.


Fiza
Fiza il 8 Set 2020
Hi,
Under what license can i use this code?

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by