low pass filter in matlab

To design a low pass Butterworth filter in MATLAB, you can use the butter function. You need to specify the filter order and the 3dB cutoff frequency as inputs to the function. Then you can pass your signal through the filter using the filter function.

main.m
% define the parameters
order = 4; % filter order
fc = 1000; % cutoff frequency (Hz)
fs = 20000; % sampling frequency (Hz)

% design the filter
[b, a] = butter(order, fc/(fs/2), 'low');

% apply the filter to a signal
signal = randn(1,10000); % example signal to filter
filtered_signal = filter(b, a, signal);

% plot the signals in time domain
t = (0:length(signal)-1)/fs; % time vector
figure
plot(t, signal)
hold on
plot(t, filtered_signal)
xlabel('Time (s)')
ylabel('Signal Amplitude')
legend('Original signal', 'Filtered signal')
535 chars
22 lines

In this example, we apply a 4th order Butterworth low pass filter with a 1000 Hz cutoff frequency to a white noise signal with a sampling frequency of 20 kHz. The resulting filtered signal is then plotted along with the original signal.

gistlibby LogSnag