Removing the noise/filter
2 views (last 30 days)
Show older comments
Abdullah Alsayegh
on 26 Oct 2023
Edited: Star Strider
on 26 Oct 2023
So I am trying to remove the noise or fillter the data to reduce/remove the unnecessary noise.
This is the code that I am using. I tried different method of filltering but it doesn't work.

% Load the data
data = importdata('default.txt'); % Load data from the file
% Time vs Channel
time = data(:, 1); % Extract the time column
channel = data(:, 2); % Extract the channel column
% Plot the data
figure;
plot(time, channel);
xlabel('Time (s)');
ylabel('Channel (V)');
title('Data Plot');
grid on;
legend('Channel Data');
0 Comments
Accepted Answer
Star Strider
on 26 Oct 2023
The signal has broadband noise, so ffrequency-selective filters will not work well to limit that noise. The best approach fro broadband noise is to use the Savitzky-Golay filter (sgolayfilt) or wavelket denoising.
Using sgolayfilt —
T1 = readtable('default.txt')
t = T1{:,1};
s = T1{:,2};
figure
plot(t, s)
xlabel('Time')
ylabel('Amplitude')
title('Original')
Ts = mean(diff(t))
Fs = 1/Ts;
Fn = Fs/2
% Tstd = std(diff(t))
L = size(T1,1);
NFFT = 2^nextpow2(L);
FTs = fft((s - mean(s)).*hann(L), NFFT)/L;
Fv = linspace(0, 1, NFFT/2+1)*Fn;
Iv = 1:numel(Fv);
figure
plot(Fv, abs(FTs(Iv))*2)
grid
xlabel('Frequency')
ylabel('Magnitude')
title('Original')
sf = sgolayfilt(s, 3, 101);
figure
plot(t, sf)
xlabel('Time')
ylabel('Amplitude')
title('Filtered')
FTsf = fft((sf - mean(sf)).*hann(L), NFFT)/L;
figure
plot(Fv, abs(FTsf(Iv))*2)
grid
xlabel('Frequency')
ylabel('Magnitude')
title('Filtered')
Experiment to get the result you want.
.
2 Comments
Star Strider
on 26 Oct 2023
Edited: Star Strider
on 26 Oct 2023
Probably not, because no filter is that selective. The best you could hope for is to use the envelope function to identify the ‘peaks’ (or whatever you want to call them), and then force everything else between them to zero. This is artificial, however it is possible —
T1 = readtable('default.txt')
t = T1{:,1};
s = T1{:,2};
[et,eb] = envelope(s, 35, 'peaks');
threshold = 0.01; % Set 'threshold' To Produce The Desired Result
Lv = (et >= threshold) & (eb <= -threshold);
% Q = nnz(Lv)
figure
plot(t, s, 'DisplayName','Signal')
hold on
plot(t, et, 'DisplayName','Upper Envelope')
plot(t, eb, 'DisplayName','Lower Envelope')
hold off
grid
xl = xlim;
yl = ylim;
% xlim([-1.25 -0.5]*1E-4)
% ylim([-0.05 0.05])
xlabel('Time')
ylabel('Amplitude')
title('Original')
sf = s; % Duplicate Signal Vector
sf(~Lv) = 0; % Imposae 'threshold' Filter
figure
plot(t, sf)
grid
xlim(xl)
ylim(yl)
xlabel('Time')
ylabel('Amplitude')
title('Threshold Filtered')
This is not the sort of filtering I generally recommend.
EDIT — Cleaned code.
.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!





