Bode diagram for a Butterworth filter

Hi,
I want help in doing a Bode diagram for a 8th order Butterworth passband with passband between 2 and 12 Hz. Sampling frequency of 60 Hz,
I tried using the following function: https://www.mathworks.com/help/control/ref/lti.bode.html.
Can you help?
Thank you!

Risposte (2)

What specific problems or errors are you getting? Here is an example that maybe you can adapt to your situation
fs = 1000; % sampling frequency Hz
fn = fs/2; % Nyquist frequency Hz
fp = [2,12] % passband Hz
fp = 1×2
2 12
fpn = fp/fn % normalized passband (fraction of Nyquist Frequency)
fpn = 1×2
0.0040 0.0240
N = 8; % filter order
% calculate butterwork filter
[A,B,C,D] = butter(N,fpn,"bandpass")
A = 16×16
0.8817 -0.0591 0 0 0 0 0 0 0.0290 -0.0009 0 0 0 0 0 0 0.0591 0.9977 0 0 0 0 0 0 0.0009 0.0308 0 0 0 0 0 0 0.0018 0.0596 0.8984 -0.0597 0 0 0 0 0.0000 0.0009 0.0292 -0.0009 0 0 0 0 0.0001 0.0019 0.0597 0.9977 0 0 0 0 0.0000 0.0000 0.0009 0.0308 0 0 0 0 0.0000 0.0001 0.0018 0.0606 0.9302 -0.0607 0 0 0.0000 0.0000 0.0000 0.0009 0.0297 -0.0009 0 0 0.0000 0.0000 0.0001 0.0019 0.0607 0.9976 0 0 0.0000 0.0000 0.0000 0.0000 0.0009 0.0308 0 0 0.0000 0.0000 0.0000 0.0001 0.0019 0.0620 0.9734 -0.0620 0.0000 0.0000 0.0000 0.0000 0.0000 0.0010 0.0304 -0.0010 0.0000 0.0000 0.0000 0.0000 0.0001 0.0019 0.0620 0.9976 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0010 0.0308 -0.0290 0.0009 0 0 0 0 0 0 0.9996 0.0000 0 0 0 0 0 0 -0.0009 -0.0308 0 0 0 0 0 0 -0.0000 0.9995 0 0 0 0 0 0
B = 16×1
0.0836 0.0026 0.0001 0.0000 0.0000 0.0000 0.0000 0.0000 -0.0013 -0.0000
C = 1×16
0.0000 0.0000 0.0000 0.0000 0.0000 0.0007 0.0219 0.7063 0.0000 0.0000 0.0000 0.0000 0.0000 0.0000 0.0003 0.0109
D = 8.0983e-13
% define linear system
sys = ss(A,B,C,D,1/fs);
% make bode plot
bode(sys)
Use the freqz function —
Fs = 60; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
[z,p,k] = butter(8, [2 12]/Fn); % Design Filter, Return [Zero, Pole, Gain] Output
[sos,g] = zp2sos(z,p,k); % Convert To Second-Order-Section Representation For Stability
figure
freqz(sos, 2^16, Fs) % Plot Filter Bode Plot
A better way to determine the filter order is to begin with the buttord funciton, since it allows other arguments (for example the stopband limits and and stopband attenuation) to be defined as well. (I generally prefer elliptic filters, since they are computationally more efficient.)
.

2 Commenti

So I guess if you have the signal processing toolbox but not the control system toolbox this would be an alternative. If the OP has the control system toolbox, is there any reason not to use bode (as I outlined previously)
Convenience.
The freqz function requires only the code necessary to call it with the zp2sos output. No other code is required.

Accedi per commentare.

Prodotti

Release

R2021a

Richiesto:

il 28 Lug 2022

Commentato:

il 28 Lug 2022

Community Treasure Hunt

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

Start Hunting!

Translated by