# butterworth filter gain higher than zero

91 views (last 30 days)
Chocola on 14 Aug 2022
Commented: Star Strider on 15 Aug 2022
Matlab R2021b
fs = 30000; %sampling freq
fn=fs/2;
n = 10; %order
Wn_Low = 3000;
Wn_High = 300;
[a,b,c] = butter(n, Wn_Low/fn, 'low');
[soslow,glow] = zp2sos(a,b,c);
fvtool(soslow, Analysis="freq")
This functionality is not available on remote platforms. [d,e,f] = butter(n, Wn_High/fn, 'high');
[soshigh,ghigh] = zp2sos(d,e,f);
fvtool(soshigh, Analysis="freq") Running these codes, which is sos filter, at low pass filter, the gain (db) of the filter at 0~0.2 (normalized) is much higher than zero (above 100).
Running high pass filter, it also shows higher than zero (about 1).
Could you help us to solve this problem?
(This phenomena happens even though when we lowered the filter order 'n')
However, when using Tf filter code (same parameters used at sos),
fs = 30000; %sampling freq
fn=fs/2;
n = 10; %order
Wn_Low = 3000;
Wn_High = 300;
[p,q] = butter(n, Wn_Low/fn, 'low');
fvtool(p,q, Analysis="freq")
[r,s] = butter(n, Wn_High/fn, 'high');
fvtool(r,s, Analysis="freq")
the gain was all below zero...

Star Strider on 14 Aug 2022
The problem is that the plots provided by either fvtool or freqz do not use the scaling factor (‘glow’ here).
Plot them separately and incorporate that, and it works correctly —
fs = 30000; %sampling freq
fn=fs/2;
n = 10; %order
Wn_Low = 3000;
Wn_High = 300;
[a,b,c] = butter(n, Wn_Low/fn, 'low');
[soslow,glow] = zp2sos(a,b,c);
[h,fv] = freqz(soslow, 2^16, fs);
figure
subplot(2,1,1)
plot(fv, mag2db(abs(h)*glow)) % Multiply By 'g'
grid
xlabel('Frequency (Hz)')
ylabel('Magnitude (dB)')
subplot(2,1,2)
grid
xlabel('Frequency (Hz)')
ylabel('Phase (degrees)') The approach in your code is correct, and preferred over the transfer function realisation. It is simply necessary to adjust the plots provided by freqz to get the correct result.
.
Star Strider on 15 Aug 2022
As always, my pleasure!

R2021b

### Community Treasure Hunt

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

Start Hunting!