
Problem with plotting filter characteristics using 'freqz()' function in matlab
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I want to design a high-pass digital filter at cutoff frequency 0.5 Hz. Sampling frequency of the input signal is 500 Hz.
I tried this code:
Fs = 500; % Hz
fc = 0.5; % Hz
[b,a] = butter(12,fc/(Fs/2), "high");
[h,w] = freqz(b,a);
plot(w/pi*Fs/2, abs(h))
After running the code, I get this plot as the magnitude of the filter:

Please help me to fix this problem. Thanks.
0 Kommentare
Antworten (1)
Mathieu NOE
am 3 Jan. 2023
hello
I have already had that problem with high order filters designed with butter
butter will have numerical problems and the coefficients are wrong
I usually don't go beyong order 5 (always plot the result to double check)
if you really need a 12th order filter, simply put three 4th order filters in serie or use another filter design tool
Order 4 (ok)

Fs = 500; % Hz
fc = 0.5; % Hz
[b,a] = butter(4,fc/(Fs/2), "high"); % order 5 MAX !
N = 5000;
[h,w] = freqz(b,a,N);
f = w/pi*Fs/2;
ind = (f>0);
f = f(ind);
H_dB = 20*log10(abs(h));
H_dB = H_dB(ind);
semilogx(f, H_dB)
xlabel(' Hz ');
ylabel(' gain (dB) ');
title('HPF plot');
3 Kommentare
Siehe auch
Kategorien
Mehr zu Digital Filter Analysis finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!