I'm encountering a challenge in MATLAB related to signal processing using the Signal Processing Toolbox. I have a noisy signal that I need to filter to extract meaningful information. The signal contains both high-frequency noise and low-frequency drift. My goal is to design a filter that effectively removes the noise while preserving the underlying signal characteristics. I've attempted to use standard filtering techniques, but I'm not satisfied with the results due to either over-smoothing or residual noise. Can someone provide guidance on how to design an optimal filter for this scenario, considering both the high-frequency noise and low-frequency drift present in the signal?
John Williams answered .
2025-11-20
% Generate noisy signal (example)
fs = 1000; % Sampling frequency
t = 0:1/fs:5; % Time vector
signal = sin(2*pi*10*t) + 0.5*sin(2*pi*50*t) + 2*randn(size(t)); % Noisy signal
% Design high-pass filter to remove low-frequency drift
highpass_cutoff = 0.5; % Cutoff frequency for high-pass filter (adjust as needed)
hp_filter = designfilt('highpassfir', 'FilterOrder', 50, 'CutoffFrequency', highpass_cutoff, 'SampleRate', fs);
% Design low-pass filter to attenuate high-frequency noise
lowpass_cutoff = 30; % Cutoff frequency for low-pass filter (adjust as needed)
lp_filter = designfilt('lowpassfir', 'FilterOrder', 50, 'CutoffFrequency', lowpass_cutoff, 'SampleRate', fs);
% Apply high-pass filter
filtered_signal = filtfilt(hp_filter, signal);
% Apply low-pass filter
filtered_signal = filtfilt(lp_filter, filtered_signal);
% Plot original and filtered signals
figure;
plot(t, signal, 'b', 'LineWidth', 1.5); hold on;
plot(t, filtered_signal, 'r', 'LineWidth', 1.5);
xlabel('Time (s)');
ylabel('Amplitude');
legend('Original Signal', 'Filtered Signal');
title('Cascaded High-pass and Low-pass Filtering');
grid on;
