design lowpass butterworth filter
106 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
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
0 comentarios
Respuestas (1)
Umeshraja
el 13 de Ag. de 2024
Editada: Umeshraja
el 21 de Sept. de 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);
% 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
0 comentarios
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!