design lowpass butterworth filter

95 visualizzazioni (ultimi 30 giorni)
Steven
Steven il 17 Nov 2022
Modificato: Umeshraja il 21 Set 2024
I am just a beginner, I want to design an IIR low-pass filter butterworth. when I use function Butterord and butter, it always has frequency response from 0db.
Here is my code and result
fpass = 2500; fstop = 4000; As = 95; Rp=3; fs=44100; %Data
wp=(fpass*2)/fs; ws=(fstop*2)/fs;
[n,Wn] = buttord(wp,ws,Rp,As);
[b,a,k] = butter(n,Wn);
fprintf('\n Bac cua bo loc = %2.0f \n',n)
sos = zp2sos(b,a,k);
freqz(sos,1024,fs)
Ripple of pass-band is 3db and I want to design from 40db instead of from 0db like this. How can i do it ? please help me

Risposte (1)

Umeshraja
Umeshraja il 13 Ago 2024
Modificato: Umeshraja il 21 Set 2024
To achieve a gain other than 0 dB in the low-frequency region, you can multiply the linear gain with the frequency response. This will shift the entire graph, so ensure that the attenuation in the stopband is relative to 0 dB to achieve the desired attenuation. For a band-pass filter, careful selection of attenuation in both the stopband and passband is essential.
Below is an example code:
% Butterworth Filter Design
fpass = 2500; % Passband Frequency in Hz
fstop = 4000; % Stopband Frequency in Hz
As = 135; % Stopband Attenuation in dB relative to 0 dB (95 dB+40 dB)
Rp = 3; % Passband Ripple in dB, insignificant in this butterworth filter design due to maximally flat frequency response.
fs = 44100; % Sampling Frequency in Hz
gain = 40; % Expected gain in passband in dB
% Normalized Frequencies
wp = (fpass * 2) / fs;
ws = (fstop * 2) / fs;
% Determine the Order of the Filter
[n, Wn] = buttord(wp, ws, Rp, As);
[z, p, k] = butter(n, Wn);
k = k * 10^(gain / 20); % Converting gain to linear scale
fprintf('\n Filter Order = %2.0f \n', n);
Filter Order = 32
% Convert to Second-Order Sections
sos = zp2sos(z, p, k);
% Frequency Response
[h, f] = freqz(sos, 1024, fs);
h = 20 * log10(abs(h));
% Find the closest frequency to fstop
[~, idx] = min(abs(f - fstop));
h_fstop = h(idx);
% Plot Frequency Response
figure();
plot(f, h);
hold on;
xline(fpass, '--g', 'Passband Frequency');
xline(fstop, '--r', 'Stopband Frequency');
yline(40, '--b', '40 dB');
yline(h_fstop, '--k', sprintf('%.2f dB at %.2f Hz', h_fstop, f(idx)));
hold off;
% Set Plot Limits
xlim([0 fstop + 1000]);
ylim([-100 50]);
% Add Labels and Title
xlabel('Frequency (Hz)');
ylabel('Magnitude (dB)');
title('Butterworth Filter Frequency Response');
grid on;
Alternatively, you can design filter using ‘fdesign’ function. To know more, please refer to the Lowpass Butterworth Filter Specification and Design example in MATLAB R2024a documentation

Community Treasure Hunt

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

Start Hunting!

Translated by