Problem with plotting filter characteristics using 'freqz()' function in matlab

2 vues (au cours des 30 derniers jours)
meysam
meysam le 3 Jan 2023
Commenté : Mathieu NOE le 31 Jan 2023
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.

Réponses (1)

Mathieu NOE
Mathieu NOE le 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 commentaires
Mathieu NOE
Mathieu NOE le 9 Jan 2023
hello
problem solved ?
Mathieu NOE
Mathieu NOE le 31 Jan 2023
hello
Problem solved ?

Connectez-vous pour commenter.

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by