Sum, then filter, then re-separate data

3 views (last 30 days)
Hi all,
Trying to get some help with a problem I'm having:
I have two vectors that, when summed together, create a signal that has noise (spikes) that I'm wanting to filter out.
I need to filter the summed signal and then revert it back to the two vectors such that they can be re-summed without any noise.
Not sure if this is possible or if anyone has any ideas? I've attached some images and a .mat file with the data contained.

Accepted Answer

Star Strider
Star Strider on 1 Oct 2022
Edited: Star Strider on 2 Oct 2022
It would help to have the sampling frequency.
I am not certain what you want to filter, however for now I am assuming that is the noise in the valley between the summed signals —
LD = load(websave('data','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1141660/data.mat'))
LD = struct with fields:
front: [20000×1 double] rear: [20000×1 double]
front = LD.front;
rear = LD.rear;
Fs = 2000; % Default Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
L = numel(front);
t = linspace(0, L-1, L)/Fs; % Time Vector
NFFT = 2^nextpow2(L); % For Efficiency
FTfr = fft([front rear]-mean([front rear]),NFFT)/L; % Fourier Transform
Fv = linspace(0, 1, NFFT/2+1)*Fn; % Frequency Vector
Iv = 1:numel(Fv); % Index Vector (One-Sided Fourier Transform)
figure
plot(Fv, abs(FTfr(Iv,:))*2)
grid
xlabel('Frequency (Units)')
ylabel('Magnitude (Units)')
title('Fourier Transform')
xlim([0 Fs/100])
lim1 = [min([front rear]); max([front rear])]; % Signal Limits
Fco = 5; % Cutoff Frequency
fr_filt = lowpass([front rear], Fco, Fs, 'ImpulseResponse','iir'); % Filter Signals
lim2 = [min(fr_filt); max(fr_filt)]; % Signal Limits
fr_filt = max(fr_filt-9, 0); % Eliminate Baseline Transients
lim3 = [min(fr_filt); max(fr_filt)]; % Signal Limits
fr_filt = fr_filt .* lim1(2,:)./lim3(2,:); % Rescale Data
lim3 = [min(fr_filt); max(fr_filt)]; % Check Signal Limits
figure
plot(t, fr_filt)
grid
xlabel('Time')
ylabel('Amplitude')
title('Filtered Signals')
figure
plot(t, sum(fr_filt,2))
grid
xlabel('Time')
ylabel('Amplitude')
title('Summed Filtered Signals')
This lowpass filter eliminates the noise reasonably well, at the expense of eliminating some other high-frequency information. That can be fine-tuned (to an extent) by changing the cutoff frequency ‘Fco’ in the lowpass call. Since I am not certain what you want to filter out, I leave that fine-tuning to you. I will help as necessary to get the desired result.
NOTE — Since I do not have the actual sampling frequency, I have scaled everything here in terms of it so this code should work with a different sampling frequency without alteration.
EDIT — (2 Oct 2022 at 03:34)
Added known sampling frequency, adjusted ‘Fco’ and thresholded the result to attenuate the baseline transients after filtering.
.
  4 Comments
LukeJes
LukeJes on 2 Oct 2022
Exactly what I was looking for! Thanks again for your time.

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!