fs=8000; % Sampling rate
filterOrder=5; % Order of filter
% ====== low-pass filter
cutOffFreq=1000;
[b, a]=butter(filterOrder, cutOffFreq/(fs/2), 'low');
[h, w]=freqz(b, a);
subplot(2,2,1);
plot(w/pi*fs/2, abs(h), '.-');
xlabel('Freq (Hz)'); title('Freq. response of a low-pass filter'); grid on
% ====== high-pass filter
cutOffFreq=2000;
[b, a]=butter(filterOrder, cutOffFreq/(fs/2), 'high');
[h, w]=freqz(b, a);
subplot(2,2,2);
plot(w/pi*fs/2, abs(h), '.-');
xlabel('Freq (Hz)'); title('Freq. response of a high-pass filter'); grid on
% ====== band-pass filter
passBand=[1000, 2000];
[b, a]=butter(filterOrder, passBand/(fs/2));
[h, w]=freqz(b, a);
subplot(2,2,3);
plot(w/pi*fs/2, abs(h), '.-');
xlabel('Freq (Hz)'); title('Freq. response of a band-pass filter'); grid on
% ====== band-stop filter
stopBand=[1000, 2000];
[b, a]=butter(filterOrder, stopBand/(fs/2), 'stop');
[h, w]=freqz(b, a);
subplot(2,2,4);
plot(w/pi*fs/2, abs(h), '.-');
xlabel('Freq (Hz)'); title('Freq. response of a band-stop filter'); grid on

本文详细介绍了如何使用MATLAB实现不同类型的滤波器,包括低通、高通、带通与带阻滤波器。通过设置采样率、滤波器阶数和截止频率,展示了滤波器频率响应的绘制过程。
882

被折叠的 条评论
为什么被折叠?



