巴特沃斯低通滤波器matlab代码
时间: 2023-11-16 18:07:23 浏览: 147
基于MATLAB设计巴特沃斯低通滤波器.pdf
5星 · 资源好评率100%
function [y,t] = butterworth_lowpass_filter(x, fs, cutoff_freq, order)
% Butterworth lowpass filter implementation in MATLAB
% x - input signal
% fs - sampling frequency
% cutoff_freq - cutoff frequency
% order - filter order
% Design the filter
Wn = cutoff_freq / (fs/2);
[b,a] = butter(order, Wn, 'low');
% Filter the signal
y = filter(b,a,x);
% Time vector
t = 0:1/fs:(length(x)-1)/fs;
% Plot the input and filtered signals
figure;
subplot(2,1,1);
plot(t,x);
xlabel('Time (s)');
ylabel('Amplitude');
title('Input Signal');
subplot(2,1,2);
plot(t,y);
xlabel('Time (s)');
ylabel('Amplitude');
title('Filtered Signal');
end
阅读全文