Removing the noise/filter

9 visualizzazioni (ultimi 30 giorni)
Abdullah Alsayegh
Abdullah Alsayegh il 26 Ott 2023
Modificato: Star Strider il 26 Ott 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');

Risposta accettata

Star Strider
Star Strider il 26 Ott 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')
T1 = 16384×2 table
Var1 Var2 ___________ __________ -0.00011384 0.0042297 -0.00011382 0.0053817 -0.0001138 0.0064339 -0.00011378 0.0064667 -0.00011376 0.0056993 -0.00011374 0.0075507 -0.00011372 0.0086688 -0.0001137 0.0057182 -0.00011368 0.0031314 -0.00011366 0.0021281 -0.00011364 0.00099381 -0.00011362 -0.0027928 -0.0001136 -0.0059469 -0.00011358 -0.0033796 -0.00011356 0.00092691 -0.00011354 0.0045465
t = T1{:,1};
s = T1{:,2};
figure
plot(t, s)
xlabel('Time')
ylabel('Amplitude')
title('Original')
Ts = mean(diff(t))
Ts = 2.0000e-08
Fs = 1/Ts;
Fn = Fs/2
Fn = 2.5000e+07
% 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 Commenti
Abdullah Alsayegh
Abdullah Alsayegh il 26 Ott 2023
Is there possibility of making the noise almost a stright line and having the presented rised Amplitude be presented at the same level.
Star Strider
Star Strider il 26 Ott 2023
Modificato: Star Strider il 26 Ott 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')
T1 = 16384×2 table
Var1 Var2 ___________ __________ -0.00011384 0.0042297 -0.00011382 0.0053817 -0.0001138 0.0064339 -0.00011378 0.0064667 -0.00011376 0.0056993 -0.00011374 0.0075507 -0.00011372 0.0086688 -0.0001137 0.0057182 -0.00011368 0.0031314 -0.00011366 0.0021281 -0.00011364 0.00099381 -0.00011362 -0.0027928 -0.0001136 -0.0059469 -0.00011358 -0.0033796 -0.00011356 0.00092691 -0.00011354 0.0045465
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.
.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by