Trying to Filer Baseline Signal Noise - Getting Additional Peaks at High Frequencies

14 次查看(过去 30 天)
I am currently right now trying to filter out a baseline voltage drift in my voltage signal. I applied a high pass filter transform function to remove the noiseat 0 Hz. However, when I do this I then get new spikes at higher voltages that occur in the frequency domain that were not there in the frequency domain before I filtered my data. I am able to filter out 60 Hz noise without seeing peaks in graphs but not the 0 Hz noise. I saw online someone say that you need to make a decay from your transfer function because a sharp change can cause additional issues (I think what I am seeing), but I am unsure how to go about doing that and if that is what is happening with my data.
I included images below of my graphs (see attached screenshot). Figure 3 is my unfiltered data (note that I have code not shown below that sucessfully removes teh 60 Hz nosie with no issues). Figure 4 is then my graph from trying to remove the baseline noise than then results in the additinoal peaks.
%%Loading Data
close all
trial_data = readtable("trial_data.csv");
Error using readtable (line 517)
Unable to find or open 'trial_data.csv'. Check the path and filename or file permissions.
%%
%%Assigning Vectors
time_vector = table2array(trial_data(:,1));
channel_1_unprocessed = table2array(trial_data(:,3));%differntial
channel_2_unprocessed = table2array(trial_data(:,4));%non_pulse
channel_3_unprocessed = table2array(trial_data(:,5));%pulse
%%Filtering out 0 Hz Noise
% Define parameters
fs = 1000; % Sampling rate (Hz)
f_target = 0; % Target frequency (Hz) for the notch filter
harmonics = 1; % Number of harmonics to include in the filter
% Frequency axis centered at 0
N = length(time_vector);
f = (-N/2:N/2-1) * (fs / N); % Frequency vector centered at zero
% Initialize the filter to 1 everywhere
bandwidth = 1; % Width around each notch frequency to block
filter_0Hz = ones(1, N); % Filter set to 1 everywhere initially
% Create notches at 60 Hz and its harmonics up to the specified limit
for k = 1:harmonics
f_harmonic = f_target * k;
% Set filter to 0 around each harmonic band
filter_0Hz((f >= f_harmonic - bandwidth) & (f <= f_harmonic + bandwidth)) = 0;
filter_0Hz((f >= -f_harmonic - bandwidth) & (f <= -f_harmonic + bandwidth)) = 0;
end
filter_0Hz = filter_0Hz';
% Plot the filter centered around f = 0
figure(2)
plot(f, filter_0Hz)
xlabel('Frequency (Hz)')
ylabel('Filter Response')
title('Notch Filter around 60 Hz and Harmonics')
hold off

回答(1 个)

Star Strider
Star Strider 2024-11-9,21:39
The problem may be your filter design.
If you have R2018a or later and the Signal Processing Toolbox, use the highpass function with the additional name-value pair arguments 'ImpulseResponse','iir' to design and implement an efficient elliptic fiilter that should do what you want.
If you do not have that function, the next best way to do this is in the frequency domain using the fft function.
Other ways are too use the detrend function in the time domain, and there are still other options.

Community Treasure Hunt

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

Start Hunting!

Translated by